Implement "to_irq" in the GPIO driver. Some GPIOs in bcm63xx have IRQs. They are known in this target as external IRQs. This patch just adds the function "to_irq" for allowing to use the generic GPIO lib function gpio_to_irq(). This function just returns the IRQ number at the GPIO line.
Signed-off-by: Daniel Gonzalez <dgcb...@gmail.com> diff --git a/target/linux/brcm63xx/patches-4.1/374-gpio-add-a-simple-GPIO-driver-for-bcm63xx.patch b/target/linux/brcm63xx/patches-4.1/374-gpio-add-a-simple-GPIO-driver-for-bcm63xx.patch index f80818d..4beed21 100644 --- a/target/linux/brcm63xx/patches-4.1/374-gpio-add-a-simple-GPIO-driver-for-bcm63xx.patch +++ b/target/linux/brcm63xx/patches-4.1/374-gpio-add-a-simple-GPIO-driver-for-bcm63xx.patch @@ -40,7 +40,7 @@ Signed-off-by: Jonas Gorski <j...@openwrt.org> obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o --- /dev/null +++ b/drivers/gpio/gpio-bcm63xx.c -@@ -0,0 +1,122 @@ +@@ -0,0 +1,189 @@ +/* + * Driver for BCM63XX memory-mapped GPIO controllers, based on + * Generic driver for memory-mapped GPIO controllers. @@ -75,6 +75,69 @@ Signed-off-by: Jonas Gorski <j...@openwrt.org> +#include <linux/of.h> +#include <linux/of_gpio.h> + ++#include <bcm63xx_irq.h> ++ ++static int bcm63xx_gpio_to_irq(struct gpio_chip *chip, unsigned gpio) ++{ ++ switch (bcm63xx_get_cpu_id()) { ++ case BCM6328_CPU_ID: ++ switch(gpio) { ++ case 12: ++ return IRQ_EXT_3; ++ case 15: ++ return IRQ_EXT_2; ++ case 23: ++ return IRQ_EXT_0; ++ case 24: ++ return IRQ_EXT_1; ++ default: ++ return -EINVAL; ++ } ++ ++ case BCM6348_CPU_ID: ++ case BCM63268_CPU_ID: ++ if (!strcmp(chip->label, "bcm63xx-gpio.1")) ++ switch(gpio) { ++ case 0: ++ return IRQ_EXT_0; ++ case 1: ++ return IRQ_EXT_1; ++ case 2: ++ return IRQ_EXT_2; ++ case 3: ++ return IRQ_EXT_3; ++ default: ++ return -EINVAL; ++ } ++ else ++ return -EINVAL; ++ ++ case BCM6358_CPU_ID: ++ case BCM6368_CPU_ID: ++ if (!strcmp(chip->label, "bcm63xx-gpio.1")) ++ switch(gpio) { ++ case 0: ++ return IRQ_EXT_4; ++ case 1: ++ return IRQ_EXT_5; ++ case 2: ++ return IRQ_EXT_0; ++ case 3: ++ return IRQ_EXT_1; ++ case 4: ++ return IRQ_EXT_2; ++ case 5: ++ return IRQ_EXT_3; ++ default: ++ return -EINVAL; ++ } ++ else ++ return -EINVAL; ++ default: ++ return -EINVAL; ++ } ++} ++ +static int bcm63xx_gpio_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; @@ -85,6 +148,7 @@ Signed-off-by: Jonas Gorski <j...@openwrt.org> + int err; + struct bgpio_chip *bgc; + struct bgpio_pdata *pdata = dev_get_platdata(dev); ++ struct gpio_chip *chip; + + dirout_r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + dat_r = platform_get_resource(pdev, IORESOURCE_MEM, 1); @@ -131,8 +195,11 @@ Signed-off-by: Jonas Gorski <j...@openwrt.org> + if (pdata->ngpio > 0) + bgc->gc.ngpio = pdata->ngpio; + } ++ ++ chip = &bgc->gc; ++ chip->to_irq = bcm63xx_gpio_to_irq; + -+ return gpiochip_add(&bgc->gc); ++ return gpiochip_add(chip); +} + +static int bcm63xx_gpio_remove(struct platform_device *pdev) @@ -163,3 +230,24 @@ Signed-off-by: Jonas Gorski <j...@openwrt.org> +MODULE_DESCRIPTION("Driver for BCM63XX memory-mapped GPIO controllers"); +MODULE_AUTHOR("Jonas Gorski <j...@openwrt.org>"); +MODULE_LICENSE("GPL"); +--- a/arch/mips/include/asm/mach-bcm63xx/gpio.h ++++ b/arch/mips/include/asm/mach-bcm63xx/gpio.h +@@ -3,7 +3,7 @@ + + #include <bcm63xx_gpio.h> + +-#define gpio_to_irq(gpio) -1 ++#define gpio_to_irq __gpio_to_irq + + #define gpio_get_value __gpio_get_value + #define gpio_set_value __gpio_set_value +--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_irq.h ++++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_irq.h +@@ -11,5 +11,7 @@ + #define IRQ_EXT_1 (IRQ_EXTERNAL_BASE + 1) + #define IRQ_EXT_2 (IRQ_EXTERNAL_BASE + 2) + #define IRQ_EXT_3 (IRQ_EXTERNAL_BASE + 3) ++#define IRQ_EXT_4 (IRQ_EXTERNAL_BASE + 4) ++#define IRQ_EXT_5 (IRQ_EXTERNAL_BASE + 5) + + #endif /* ! BCM63XX_IRQ_H_ */ diff --git a/target/linux/brcm63xx/patches-4.4/374-gpio-add-a-simple-GPIO-driver-for-bcm63xx.patch b/target/linux/brcm63xx/patches-4.4/374-gpio-add-a-simple-GPIO-driver-for-bcm63xx.patch index 92b0e71..329f3e2 100644 --- a/target/linux/brcm63xx/patches-4.4/374-gpio-add-a-simple-GPIO-driver-for-bcm63xx.patch +++ b/target/linux/brcm63xx/patches-4.4/374-gpio-add-a-simple-GPIO-driver-for-bcm63xx.patch @@ -40,7 +40,7 @@ Signed-off-by: Jonas Gorski <j...@openwrt.org> obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o --- /dev/null +++ b/drivers/gpio/gpio-bcm63xx.c -@@ -0,0 +1,122 @@ +@@ -0,0 +1,189 @@ +/* + * Driver for BCM63XX memory-mapped GPIO controllers, based on + * Generic driver for memory-mapped GPIO controllers. @@ -75,6 +75,69 @@ Signed-off-by: Jonas Gorski <j...@openwrt.org> +#include <linux/of.h> +#include <linux/of_gpio.h> + ++#include <bcm63xx_irq.h> ++ ++static int bcm63xx_gpio_to_irq(struct gpio_chip *chip, unsigned gpio) ++{ ++ switch (bcm63xx_get_cpu_id()) { ++ case BCM6328_CPU_ID: ++ switch(gpio) { ++ case 12: ++ return IRQ_EXT_3; ++ case 15: ++ return IRQ_EXT_2; ++ case 23: ++ return IRQ_EXT_0; ++ case 24: ++ return IRQ_EXT_1; ++ default: ++ return -EINVAL; ++ } ++ ++ case BCM6348_CPU_ID: ++ case BCM63268_CPU_ID: ++ if (!strcmp(chip->label, "bcm63xx-gpio.1")) ++ switch(gpio) { ++ case 0: ++ return IRQ_EXT_0; ++ case 1: ++ return IRQ_EXT_1; ++ case 2: ++ return IRQ_EXT_2; ++ case 3: ++ return IRQ_EXT_3; ++ default: ++ return -EINVAL; ++ } ++ else ++ return -EINVAL; ++ ++ case BCM6358_CPU_ID: ++ case BCM6368_CPU_ID: ++ if (!strcmp(chip->label, "bcm63xx-gpio.1")) ++ switch(gpio) { ++ case 0: ++ return IRQ_EXT_4; ++ case 1: ++ return IRQ_EXT_5; ++ case 2: ++ return IRQ_EXT_0; ++ case 3: ++ return IRQ_EXT_1; ++ case 4: ++ return IRQ_EXT_2; ++ case 5: ++ return IRQ_EXT_3; ++ default: ++ return -EINVAL; ++ } ++ else ++ return -EINVAL; ++ default: ++ return -EINVAL; ++ } ++} ++ +static int bcm63xx_gpio_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; @@ -85,6 +148,7 @@ Signed-off-by: Jonas Gorski <j...@openwrt.org> + int err; + struct bgpio_chip *bgc; + struct bgpio_pdata *pdata = dev_get_platdata(dev); ++ struct gpio_chip *chip; + + dirout_r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + dat_r = platform_get_resource(pdev, IORESOURCE_MEM, 1); @@ -131,8 +195,11 @@ Signed-off-by: Jonas Gorski <j...@openwrt.org> + if (pdata->ngpio > 0) + bgc->gc.ngpio = pdata->ngpio; + } ++ ++ chip = &bgc->gc; ++ chip->to_irq = bcm63xx_gpio_to_irq; + -+ return gpiochip_add(&bgc->gc); ++ return gpiochip_add(chip); +} + +static int bcm63xx_gpio_remove(struct platform_device *pdev) @@ -163,3 +230,24 @@ Signed-off-by: Jonas Gorski <j...@openwrt.org> +MODULE_DESCRIPTION("Driver for BCM63XX memory-mapped GPIO controllers"); +MODULE_AUTHOR("Jonas Gorski <j...@openwrt.org>"); +MODULE_LICENSE("GPL"); +--- a/arch/mips/include/asm/mach-bcm63xx/gpio.h ++++ b/arch/mips/include/asm/mach-bcm63xx/gpio.h +@@ -3,7 +3,7 @@ + + #include <bcm63xx_gpio.h> + +-#define gpio_to_irq(gpio) -1 ++#define gpio_to_irq __gpio_to_irq + + #define gpio_get_value __gpio_get_value + #define gpio_set_value __gpio_set_value +--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_irq.h ++++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_irq.h +@@ -11,5 +11,7 @@ + #define IRQ_EXT_1 (IRQ_EXTERNAL_BASE + 1) + #define IRQ_EXT_2 (IRQ_EXTERNAL_BASE + 2) + #define IRQ_EXT_3 (IRQ_EXTERNAL_BASE + 3) ++#define IRQ_EXT_4 (IRQ_EXTERNAL_BASE + 4) ++#define IRQ_EXT_5 (IRQ_EXTERNAL_BASE + 5) + + #endif /* ! BCM63XX_IRQ_H_ */ _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel