Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: iop: Use generic GPIO MMIO functions for driver

This patch switches the driver to use the generic GPIO MMIO functions
that removes a bit of redundant and duplicate code.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Alexander Shiyan and committed by
Linus Walleij
6d125412 31963eb0

+24 -94
+2 -1
drivers/gpio/Kconfig
··· 228 228 229 229 config GPIO_IOP 230 230 tristate "Intel IOP GPIO" 231 - depends on ARM && (ARCH_IOP32X || ARCH_IOP33X) 231 + depends on ARCH_IOP32X || ARCH_IOP33X || COMPILE_TEST 232 + select GPIO_GENERIC 232 233 help 233 234 Say yes here to support the GPIO functionality of a number of Intel 234 235 IOP32X or IOP33X.
+22 -93
drivers/gpio/gpio-iop.c
··· 10 10 * your option) any later version. 11 11 */ 12 12 13 - #include <linux/device.h> 14 - #include <linux/init.h> 15 - #include <linux/types.h> 16 - #include <linux/errno.h> 17 - #include <linux/gpio.h> 18 - #include <linux/export.h> 13 + #include <linux/err.h> 14 + #include <linux/module.h> 15 + #include <linux/gpio/driver.h> 19 16 #include <linux/platform_device.h> 20 - #include <linux/bitops.h> 21 - #include <linux/io.h> 22 17 23 - #define IOP3XX_N_GPIOS 8 24 - 25 - #define GPIO_IN 0 26 - #define GPIO_OUT 1 27 - #define GPIO_LOW 0 28 - #define GPIO_HIGH 1 29 - 30 - /* Memory base offset */ 31 - static void __iomem *base; 32 - 33 - #define IOP3XX_GPIO_REG(reg) (base + (reg)) 34 - #define IOP3XX_GPOE IOP3XX_GPIO_REG(0x0000) 35 - #define IOP3XX_GPID IOP3XX_GPIO_REG(0x0004) 36 - #define IOP3XX_GPOD IOP3XX_GPIO_REG(0x0008) 37 - 38 - static void gpio_line_config(int line, int direction) 39 - { 40 - unsigned long flags; 41 - u32 val; 42 - 43 - local_irq_save(flags); 44 - val = readl(IOP3XX_GPOE); 45 - if (direction == GPIO_IN) { 46 - val |= BIT(line); 47 - } else if (direction == GPIO_OUT) { 48 - val &= ~BIT(line); 49 - } 50 - writel(val, IOP3XX_GPOE); 51 - local_irq_restore(flags); 52 - } 53 - 54 - static int gpio_line_get(int line) 55 - { 56 - return !!(readl(IOP3XX_GPID) & BIT(line)); 57 - } 58 - 59 - static void gpio_line_set(int line, int value) 60 - { 61 - unsigned long flags; 62 - u32 val; 63 - 64 - local_irq_save(flags); 65 - val = readl(IOP3XX_GPOD); 66 - if (value == GPIO_LOW) { 67 - val &= ~BIT(line); 68 - } else if (value == GPIO_HIGH) { 69 - val |= BIT(line); 70 - } 71 - writel(val, IOP3XX_GPOD); 72 - local_irq_restore(flags); 73 - } 74 - 75 - static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 76 - { 77 - gpio_line_config(gpio, GPIO_IN); 78 - return 0; 79 - } 80 - 81 - static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level) 82 - { 83 - gpio_line_set(gpio, level); 84 - gpio_line_config(gpio, GPIO_OUT); 85 - return 0; 86 - } 87 - 88 - static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio) 89 - { 90 - return gpio_line_get(gpio); 91 - } 92 - 93 - static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value) 94 - { 95 - gpio_line_set(gpio, value); 96 - } 97 - 98 - static struct gpio_chip iop3xx_chip = { 99 - .label = "iop3xx", 100 - .direction_input = iop3xx_gpio_direction_input, 101 - .get = iop3xx_gpio_get_value, 102 - .direction_output = iop3xx_gpio_direction_output, 103 - .set = iop3xx_gpio_set_value, 104 - .base = 0, 105 - .ngpio = IOP3XX_N_GPIOS, 106 - }; 18 + #define IOP3XX_GPOE 0x0000 19 + #define IOP3XX_GPID 0x0004 20 + #define IOP3XX_GPOD 0x0008 107 21 108 22 static int iop3xx_gpio_probe(struct platform_device *pdev) 109 23 { 110 24 struct resource *res; 25 + struct gpio_chip *gc; 26 + void __iomem *base; 27 + int err; 28 + 29 + gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); 30 + if (!gc) 31 + return -ENOMEM; 111 32 112 33 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 113 34 base = devm_ioremap_resource(&pdev->dev, res); 114 35 if (IS_ERR(base)) 115 36 return PTR_ERR(base); 116 37 117 - return devm_gpiochip_add_data(&pdev->dev, &iop3xx_chip, NULL); 38 + err = bgpio_init(gc, &pdev->dev, 1, base + IOP3XX_GPID, 39 + base + IOP3XX_GPOD, NULL, NULL, base + IOP3XX_GPOE, 0); 40 + if (err) 41 + return err; 42 + 43 + gc->base = 0; 44 + gc->owner = THIS_MODULE; 45 + 46 + return devm_gpiochip_add_data(&pdev->dev, gc, NULL); 118 47 } 119 48 120 49 static struct platform_driver iop3xx_gpio_driver = {