gpio: davinci: Remove unused member of davinci_gpio_controller
Subsystems (5)
PATCH 1/5 gpio: davinci: Remove unused member of davinci_gpio_controller
This was added as part of the patch in the fixes below, but was not needed or used, remove this here.
--- include/linux/platform_data/gpio-davinci.h | 1 - 1 file changed, 1 deletion(-)
include/linux/platform_data/gpio-davinci.h +0 -1
@@ -43,7 +43,6 @@ struct davinci_gpio_controller {void __iomem *regs[MAX_REGS_BANKS ];int gpio_unbanked;int irqs[MAX_INT_PER_BANK ]; -unsigned int base; };/*
Signature · 1 line
2.18.0
PATCH 2/5 gpio: davinci: Use dev name for label and automatic base selection
Use dev_name to get a unique label and use -1 for a base to get our selection automatically. We pull in all GPIOs per chip now so this does not have the effect of out of order labels like before.
We do these both together so we can drop all the static data in one patch. This also lets us normalize the return paths as we don't need any cleanup after this change.
--- drivers/gpio/gpio-davinci.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)
drivers/gpio/gpio-davinci.c +4 -18
@@ -41,7 +41,6 @@ struct davinci_gpio_regs {typedef struct irq_chip *(*gpio_get_irq_chip_cb_t )(unsigned int irq);#define BINTEN 0x8/* GPIO Interrupt Per-Bank Enable Register */ -#define MAX_LABEL_SIZE 20static void __iomem *gpio_base;static unsigned int offset_array[5 ] = {0x10 ,0x38 ,0x60 ,0x88 ,0xb0 };
@@ -166,14 +165,12 @@ davinci_gpio_get_pdata(struct platform_device *pdev)static int davinci_gpio_probe (struct platform_device *pdev) { -static int ctrl_num, bank_base;int gpio, bank, i, ret =0 ;unsigned int ngpio, nbank, nirq;struct davinci_gpio_controller *chips;struct davinci_gpio_platform_data *pdata;struct device *dev = &pdev->dev;struct resource *res; -char label[MAX_LABEL_SIZE ]; pdata =davinci_gpio_get_pdata (pdev);if (!pdata) {
@@ -228,10 +225,7 @@ static int davinci_gpio_probe(struct platform_device *pdev) } } -snprintf (label,MAX_LABEL_SIZE ,"davinci_gpio.%d" , ctrl_num++); - chips->chip.label =devm_kstrdup (dev, label,GFP_KERNEL ); -if (!chips->chip.label) -return -ENOMEM ; + chips->chip.label =dev_name (dev); chips->chip.direction_input = davinci_direction_in; chips->chip.get = davinci_gpio_get;
@@ -239,7 +233,7 @@ static int davinci_gpio_probe(struct platform_device *pdev) chips->chip.set = davinci_gpio_set; chips->chip.ngpio = ngpio; - chips->chip.base = bank_base; + chips->chip.base =-1 ;#ifdef CONFIG_OF_GPIO chips->chip.of_gpio_n_cells =2 ;
@@ -252,28 +246,20 @@ static int davinci_gpio_probe(struct platform_device *pdev) }#endif spin_lock_init (&chips->lock); - bank_base += ngpio;for (gpio =0 , bank =0 ; gpio < ngpio; gpio +=32 , bank++) chips->regs[bank] = gpio_base + offset_array[bank]; ret =devm_gpiochip_add_data (dev, &chips->chip, chips);if (ret) - goto err; +return ret;platform_set_drvdata (pdev, chips); ret =davinci_gpio_irq_setup (pdev);if (ret) - goto err; +return ret;return 0 ; - -err: -/* Revert the static variable increments */ - ctrl_num--; - bank_base -= ngpio; - -return ret; }/*--------------------------------------------------------------------------*/
Signature · 1 line
2.18.0
PATCH 3/5 gpio: davinci: Allocate the correct amount of memory for controller
In reply to Andrew F. DavisPreviously we created a controller structure per bank of GPIO pins. This has since been changed to one per controller, but the allocation size was not changed. Fix this here.
This also leaves the variable 'nbank' unused, instead of removing it, move it down and use it to clean up a loop. For loops with multiple initializers and/or iteration expressions, especially ones that don't use those loop counters are quite hard to follow, fix this.
--- drivers/gpio/gpio-davinci.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpio/gpio-davinci.c +4 -6
@@ -165,7 +165,7 @@ davinci_gpio_get_pdata(struct platform_device *pdev)static int davinci_gpio_probe (struct platform_device *pdev) { -int gpio, bank, i, ret =0 ; +int bank, i, ret =0 ;unsigned int ngpio, nbank, nirq;struct davinci_gpio_controller *chips;struct davinci_gpio_platform_data *pdata;
@@ -204,10 +204,7 @@ static int davinci_gpio_probe(struct platform_device *pdev)else nirq =DIV_ROUND_UP (ngpio,16 ); - nbank =DIV_ROUND_UP (ngpio,32 ); - chips =devm_kcalloc (dev, - nbank,sizeof (struct davinci_gpio_controller ), -GFP_KERNEL ); + chips =devm_kzalloc (dev,sizeof (*chips),GFP_KERNEL );if (!chips)return -ENOMEM ;
@@ -247,7 +244,8 @@ static int davinci_gpio_probe(struct platform_device *pdev)#endif spin_lock_init (&chips->lock); -for (gpio =0 , bank =0 ; gpio < ngpio; gpio +=32 , bank++) + nbank =DIV_ROUND_UP (ngpio,32 ); +for (bank =0 ; bank < nbank; bank++) chips->regs[bank] = gpio_base + offset_array[bank]; ret =devm_gpiochip_add_data (dev, &chips->chip, chips);
Signature · 1 line
2.18.0
PATCH 4/5 gpio: davinci: Remove unneeded GPIO macro
In reply to Andrew F. DavisThis macro does nothing and has only one user, remove it.
--- arch/arm/mach-davinci/board-neuros-osd2.c | 8 ++++---- include/linux/platform_data/gpio-davinci.h | 5 ----- 2 files changed, 4 insertions(+), 9 deletions(-)
arch/arm/mach-davinci/board-neuros-osd2.c +4 -4
@@ -130,10 +130,10 @@ static struct platform_device davinci_fb_device = { };static const struct gpio_led ntosd2_leds[] = { - { .name ="led1_green" , .gpio =GPIO (10 ), }, - { .name ="led1_red" , .gpio =GPIO (11 ), }, - { .name ="led2_green" , .gpio =GPIO (12 ), }, - { .name ="led2_red" , .gpio =GPIO (13 ), }, + { .name ="led1_green" , .gpio =10 , }, + { .name ="led1_red" , .gpio =11 , }, + { .name ="led2_green" , .gpio =12 , }, + { .name ="led2_red" , .gpio =13 , }, };static struct gpio_led_platform_data ntosd2_leds_data = {
include/linux/platform_data/gpio-davinci.h +0 -5
@@ -45,11 +45,6 @@ struct davinci_gpio_controller {int irqs[MAX_INT_PER_BANK ]; }; -/* -* basic gpio routines -*/ -#define GPIO (X ) (X)/* 0 <= X <= (DAVINCI_N_GPIO - 1) */ -/* Convert GPIO signal to GPIO pin number */ #define GPIO_TO_PIN (bank, gpio) (16 * (bank) + (gpio))
Signature · 1 line
2.18.0
PATCH 5/5 gpio: davinci: Move driver local definitions to driver
In reply to Andrew F. DavisThese defines, structs and inline functions are used only internally by the driver, they do not belong in platform_data. Move them.
--- drivers/gpio/gpio-davinci.c | 28 ++++++++++++++++++++++ include/linux/platform_data/gpio-davinci.h | 28 ---------------------- 2 files changed, 28 insertions(+), 28 deletions(-)
drivers/gpio/gpio-davinci.c +28 -0
@@ -9,6 +9,7 @@* the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ +#include <linux/gpio/driver.h> #include <linux/errno.h> #include <linux/kernel.h>
@@ -24,6 +25,12 @@#include <linux/platform_device.h> #include <linux/platform_data/gpio-davinci.h> #include <linux/irqchip/chained_irq.h> +#include <linux/spinlock.h> + +#include <asm-generic/gpio.h> + +#define MAX_REGS_BANKS 5 +#define MAX_INT_PER_BANK 32struct davinci_gpio_regs {u32 dir;
@@ -45,6 +52,27 @@ typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq);static void __iomem *gpio_base;static unsigned int offset_array[5 ] = {0x10 ,0x38 ,0x60 ,0x88 ,0xb0 }; +struct davinci_gpio_irq_data { +void __iomem *regs; +struct davinci_gpio_controller *chip; +int bank_num; +}; + +struct davinci_gpio_controller { +struct gpio_chip chip; +struct irq_domain *irq_domain; +/* Serialize access to GPIO registers */ +spinlock_t lock; +void __iomem *regs[MAX_REGS_BANKS ]; +int gpio_unbanked; +int irqs[MAX_INT_PER_BANK ]; +}; + +static inline u32 __gpio_mask (unsigned gpio) +{ +return 1 << (gpio %32 ); +} +static inline struct davinci_gpio_regs __iomem *irq2regs (struct irq_data *d) {struct davinci_gpio_regs __iomem *g;
include/linux/platform_data/gpio-davinci.h +0 -28
@@ -16,40 +16,12 @@#ifndef __DAVINCI_GPIO_PLATFORM_H#define __DAVINCI_GPIO_PLATFORM_H -#include <linux/io.h> -#include <linux/spinlock.h> - -#include <asm-generic/gpio.h> - -#define MAX_REGS_BANKS 5 -#define MAX_INT_PER_BANK 32 -struct davinci_gpio_platform_data {u32 ngpio;u32 gpio_unbanked; }; -struct davinci_gpio_irq_data { -void __iomem *regs; -struct davinci_gpio_controller *chip; -int bank_num; -}; - -struct davinci_gpio_controller { -struct gpio_chip chip; -struct irq_domain *irq_domain; -/* Serialize access to GPIO registers */ -spinlock_t lock; -void __iomem *regs[MAX_REGS_BANKS ]; -int gpio_unbanked; -int irqs[MAX_INT_PER_BANK ]; -}; -/* Convert GPIO signal to GPIO pin number */ #define GPIO_TO_PIN (bank, gpio) (16 * (bank) + (gpio)) -static inline u32 __gpio_mask (unsigned gpio) -{ -return 1 << (gpio %32 ); -}#endif
Signature · 1 line
2.18.0
Keerthy
maintainerRe: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
In reply to Andrew F. DavisQuoted 7 lines · Andrew F. Davis
Use
dev_nameto get a unique label and use -1 for a base to get our selection automatically. We pull in all GPIOs per chip now so this does not have the effect of out of order labels like before.We do these both together so we can drop all the static data in one patch. This also lets us normalize the return paths as we don't need any cleanup after this change.
echo 28 > /sys/class/gpio/export
/ # echo 28 > /sys/class/gpi[ 12.839205] export_store: invalid GPIO 28
o/export
echo 2 > /sys/class/gp[ 22.165728] export_store: invalid GPIO 2
io/export
/ # echo 1 > /sys/class/gp[ 25.961392] export_store: invalid GPIO 1
io/export
/ # echo 3 > /sys/class/gp[ 29.981918] export_store: invalid GPIO 3
io/export
Export fails with this patch. I am testing this on keystone-k2g-evm.
Quoted 86 lines
Signed-off-by Andrew F. Davis <[email protected]>--- drivers/gpio/gpio-davinci.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)drivers/gpio/gpio-davinci.c +4
-18@@ -41,7 +41,6 @@ struct davinci_gpio_regs {typedef struct irq_chip *(*gpio_get_irq_chip_cb_t )(unsigned int irq);#define BINTEN 0x8/* GPIO Interrupt Per-Bank Enable Register */ -#define MAX_LABEL_SIZE 20static void __iomem *gpio_base;static unsigned int offset_array[5 ] = {0x10 ,0x38 ,0x60 ,0x88 ,0xb0 };@@ -166,14 +165,12 @@ davinci_gpio_get_pdata(struct platform_device *pdev)static int davinci_gpio_probe (struct platform_device *pdev) { -static int ctrl_num, bank_base;int gpio, bank, i, ret =0 ;unsigned int ngpio, nbank, nirq;struct davinci_gpio_controller *chips;struct davinci_gpio_platform_data *pdata;struct device *dev = &pdev->dev;struct resource *res; -char label[MAX_LABEL_SIZE ]; pdata =davinci_gpio_get_pdata (pdev);if (!pdata) {@@ -228,10 +225,7 @@ static int davinci_gpio_probe(struct platform_device *pdev) } } -snprintf (label,MAX_LABEL_SIZE ,"davinci_gpio.%d" , ctrl_num++); - chips->chip.label =devm_kstrdup (dev, label,GFP_KERNEL ); -if (!chips->chip.label) -return -ENOMEM ; + chips->chip.label =dev_name (dev); chips->chip.direction_input = davinci_direction_in; chips->chip.get = davinci_gpio_get;@@ -239,7 +233,7 @@ static int davinci_gpio_probe(struct platform_device *pdev) chips->chip.set = davinci_gpio_set; chips->chip.ngpio = ngpio; - chips->chip.base = bank_base; + chips->chip.base =-1 ;#ifdef CONFIG_OF_GPIO chips->chip.of_gpio_n_cells =2 ;@@ -252,28 +246,20 @@ static int davinci_gpio_probe(struct platform_device *pdev) }#endif spin_lock_init (&chips->lock); - bank_base += ngpio;for (gpio =0 , bank =0 ; gpio < ngpio; gpio +=32 , bank++) chips->regs[bank] = gpio_base + offset_array[bank]; ret =devm_gpiochip_add_data (dev, &chips->chip, chips);if (ret) - goto err; +return ret;platform_set_drvdata (pdev, chips); ret =davinci_gpio_irq_setup (pdev);if (ret) - goto err; +return ret;return 0 ; - -err: -/* Revert the static variable increments */ - ctrl_num--; - bank_base -= ngpio; - -return ret; }/*--------------------------------------------------------------------------*/
Re: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
Quoted 19 lines · Keerthy
Quoted 7 lines · Andrew F. Davis
Use
dev_nameto get a unique label and use -1 for a base to get our selection automatically. We pull in all GPIOs per chip now so this does not have the effect of out of order labels like before.We do these both together so we can drop all the static data in one patch. This also lets us normalize the return paths as we don't need any cleanup after this change.
echo 28 >
/sys/class/gpio/export
/ # echo 28 > /sys/class/gpi[ 12.839205]export_store: invalid GPIO 28
o/export
echo 2 > /sys/class/gp[ 22.165728]export_store: invalid GPIO 2
io/export
/ # echo 1 > /sys/class/gp[ 25.961392]export_store: invalid GPIO 1
io/export
/ # echo 3 > /sys/class/gp[ 29.981918]export_store: invalid GPIO 3
io/export
Quoted 1 line
Export fails with this patch. I am testing this on keystone-k2g-evm.
I think the GPIO got a new number didn't it?
Did you check the gpio file in debugfs to see which number it got.
This is sadly the global numberspace that we are tying to get rid of (new apps/scripts should use the chardev).
Are there applications that rely on the sysfs ABI on DaVinci?
In that case base needs to be prerseved.
Yours,
Linus Walleij
Keerthy
maintainerRe: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
Quoted 20 lines · Linus Walleij
Quoted 19 lines · Keerthy
Quoted 7 lines · Andrew F. Davis
Use
dev_nameto get a unique label and use -1 for a base to get our selection automatically. We pull in all GPIOs per chip now so this does not have the effect of out of order labels like before.We do these both together so we can drop all the static data in one patch. This also lets us normalize the return paths as we don't need any cleanup after this change.
echo 28 >
/sys/class/gpio/export
/ # echo 28 > /sys/class/gpi[ 12.839205]export_store: invalid GPIO 28
o/export
echo 2 > /sys/class/gp[ 22.165728]export_store: invalid GPIO 2
io/export
/ # echo 1 > /sys/class/gp[ 25.961392]export_store: invalid GPIO 1
io/export
/ # echo 3 > /sys/class/gp[ 29.981918]export_store: invalid GPIO 3
io/export
Quoted 6 lines
Quoted 1 line
Export fails with this patch. I am testing this on keystone-k2g-evm.
I think the GPIO got a new number didn't it?
Did you check the gpio file in debugfs to see which number it got.
Okay now its numbered differently:
cat /sys/class/gpio/gpiochip340/ngpio
144
cat /sys/class/gpio/gpiochip272/ngpio
68
So gpio bank2 and bank1 have different gpio numbers. Is that acceptable?
Quoted 11 lines
This is sadly the global numberspace that we are tying to get rid of (new apps/scripts should use the chardev).
Are there applications that rely on the sysfs ABI on DaVinci?
In that case base needs to be prerseved.
Yours,
Linus Walleij
Re: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
Quoted 30 lines · Keerthy
Quoted 20 lines · Linus Walleij
Quoted 19 lines · Keerthy
Quoted 7 lines · Andrew F. Davis
Use
dev_nameto get a unique label and use -1 for a base to get our selection automatically. We pull in all GPIOs per chip now so this does not have the effect of out of order labels like before.We do these both together so we can drop all the static data in one patch. This also lets us normalize the return paths as we don't need any cleanup after this change.
echo 28 >
/sys/class/gpio/export
/ # echo 28 > /sys/class/gpi[ 12.839205]export_store: invalid GPIO 28
o/export
echo 2 > /sys/class/gp[ 22.165728]export_store: invalid GPIO 2
io/export
/ # echo 1 > /sys/class/gp[ 25.961392]export_store: invalid GPIO 1
io/export
/ # echo 3 > /sys/class/gp[ 29.981918]export_store: invalid GPIO 3
io/exportQuoted 6 lines
Quoted 1 line
Export fails with this patch. I am testing this on keystone-k2g-evm.
I think the GPIO got a new number didn't it?
Did you check the gpio file in debugfs to see which number it got.
Quoted 7 lines
Okay now its numbered differently:
cat
/sys/class/gpio/gpiochip340/ngpio
144cat
/sys/class/gpio/gpiochip272/ngpio
68
could you or Andrew provide content of /debug/gpio before/after? And ls /sys/class/gpio/?
Quoted 10 lines
So gpio bank2 and bank1 have different gpio numbers. Is that acceptable?
Quoted 7 lines
This is sadly the global numberspace that we are tying to get rid of (new apps/scripts should use the chardev).
Are there applications that rely on the sysfs ABI on DaVinci?
In that case base needs to be prerseved.
Not only base, but label also - /sys/class/gpio/gpiochip0/label, as this is the way to find proper GPIO chip in sysfs using legacy GPIO ABI.
Linus, this platform is old and most of the users do not use new ABI (chardev), so we could try change this, but need to be prepared for regressions reports.
Signature · 2 lines
regards, -grygorii
Keerthy
maintainerRe: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
Quoted 35 lines · Grygorii Strashko
Quoted 32 lines · Keerthy
Quoted 20 lines · Linus Walleij
Quoted 19 lines · Keerthy
Quoted 7 lines · Andrew F. Davis
Use
dev_nameto get a unique label and use -1 for a base to get our selection automatically. We pull in all GPIOs per chip now so this does not have the effect of out of order labels like before.We do these both together so we can drop all the static data in one patch. This also lets us normalize the return paths as we don't need any cleanup after this change.
echo 28 >
/sys/class/gpio/export
/ # echo 28 > /sys/class/gpi[ 12.839205]export_store: invalid GPIO 28
o/export
echo 2 > /sys/class/gp[ 22.165728]export_store: invalid GPIO 2
io/export
/ # echo 1 > /sys/class/gp[ 25.961392]export_store: invalid GPIO 1
io/export
/ # echo 3 > /sys/class/gp[ 29.981918]export_store: invalid GPIO 3
io/exportQuoted 6 lines
Quoted 1 line
Export fails with this patch. I am testing this on keystone-k2g-evm.
I think the GPIO got a new number didn't it?
Did you check the gpio file in debugfs to see which number it got.
Okay now its numbered differently:
Quoted 8 lines
Quoted 5 lines
cat
/sys/class/gpio/gpiochip340/ngpio
144cat
/sys/class/gpio/gpiochip272/ngpio
68could you or Andrew provide content of /debug/gpio before/after? And ls
/sys/class/gpio/?
Output on K2G:
Before
======
cat /debug/gpio
gpiochip1: GPIOs 0-143, parent: platform/2603000.gpio, davinci_gpio.0:
gpiochip2: GPIOs 144-211, parent: platform/260a000.gpio, davinci_gpio.1:
gpio-156 ( |cd ) in lo
gpiochip0: GPIOs 484-511, parent: platform/2620240.keystone_dsp_gpio, 2620240.keystone_dsp_gpio:
ls /sys/class/gpio/
export gpiochip0 gpiochip144 gpiochip484 unexport
cat /sys/class/gpio/gpiochip0/label
davinci_gpio.0
cat /sys/class/gpio/gpiochip144/label
davinci_gpio.1
cat /sys/class/gpio/gpiochip144/ngpio
68
/ # cat /sys/class/gpio/gpiochip0/ngpio
144
After
=====
cat /debug/gpio
gpiochip2: GPIOs 272-339, parent: platform/260a000.gpio, 260a000.gpio:
gpio-284 ( |cd ) in lo
gpiochip1: GPIOs 340-483, parent: platform/2603000.gpio, 2603000.gpio:
gpiochip0: GPIOs 484-511, parent: platform/2620240.keystone_dsp_gpio, 2620240.keystone_dsp_gpio:
ls /sys/class/gpio/
export gpiochip272 gpiochip340 gpiochip484 unexport
cat /sys/class/gpio/gpiochip340/label
2603000.gpio
/ # cat /sys/class/gpio/gpiochip272/label
260a000.gpio
/ # cat /sys/class/gpio/gpiochip272/label
cat /sys/class/gpio/gpiochip272/ngpio
68
/ # cat /sys/class/gpio/gpiochip340/ngpio
144
In the case of SoCs that support multiple instances of Davinci GPIO IPs it is harder to figure out the right gpio number to export.
Quoted 9 lines
Quoted 9 lines
So gpio bank2 and bank1 have different gpio numbers. Is that acceptable?
Quoted 6 lines
This is sadly the global numberspace that we are tying to get rid of (new apps/scripts should use the chardev).
Are there applications that rely on the sysfs ABI on DaVinci?
Quoted 8 lines
Quoted 1 line
Quoted 1 line
In that case base needs to be prerseved.
Not only base, but label also -
/sys/class/gpio/gpiochip0/label, as this is the way to find proper GPIO chip in sysfs using legacy GPIO ABI.Linus, this platform is old and most of the users do not use new ABI (chardev), so we could try change this, but need to be prepared for regressions reports.
Totally agree with this.
Re: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
In reply to Grygorii StrashkoQuoted 9 lines · Grygorii Strashko
Quoted 7 lines · Keerthy
Okay now its numbered differently:
cat
/sys/class/gpio/gpiochip340/ngpio
144cat
/sys/class/gpio/gpiochip272/ngpio
68
(...)
So:
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Are there applications that rely on the sysfs ABI on DaVinci?
In that case base needs to be prerseved.
Not only base, but label also -
/sys/class/gpio/gpiochip0/label, as this is the way to find proper GPIO chip in sysfs using legacy GPIO ABI.Linus, this platform is old and most of the users do not use new ABI (chardev), so we could try change this, but need to be prepared for regressions reports.
So what I'm trying to ask you guys is if there are applications that you are aware of that use the old ABI, and who will upgrade their kernels and be upset.
We must not break userspace, but as you know if a tree falls in the forest and nobody is there to hear it, it doesn't make a sound.
If you're not aware of any such applications I guess we should try changing this.
Yours,
Linus Walleij
Re: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
Quoted 29 lines · Linus Walleij
Quoted 9 lines · Grygorii Strashko
Quoted 7 lines · Keerthy
Okay now its numbered differently:
cat
/sys/class/gpio/gpiochip340/ngpio
144cat
/sys/class/gpio/gpiochip272/ngpio
68(...)
So:
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Are there applications that rely on the sysfs ABI on DaVinci?
In that case base needs to be prerseved.
Not only base, but label also -
/sys/class/gpio/gpiochip0/label, as this is the way to find proper GPIO chip in sysfs using legacy GPIO ABI.Linus, this platform is old and most of the users do not use new ABI (chardev), so we could try change this, but need to be prepared for regressions reports.
So what I'm trying to ask you guys is if there are applications that you are aware of that use the old ABI, and who will upgrade their kernels and be upset.
Quoted 5 lines
We must not break userspace, but as you know if a tree falls in the forest and nobody is there to hear it, it doesn't make a sound.
If you're not aware of any such applications I guess we should try changing this.
Personally I am not really aware of any application which relies on the ABI. I may have some scripts, but I can adjust them. I am also copying some frequent users of DaVinci in mainline for any comments from them.
Thanks,
Sekhar
Re: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
Quoted 36 lines · Sekhar Nori
Quoted 29 lines · Linus Walleij
Quoted 9 lines · Grygorii Strashko
Quoted 7 lines · Keerthy
Okay now its numbered differently:
cat
/sys/class/gpio/gpiochip340/ngpio
144cat
/sys/class/gpio/gpiochip272/ngpio
68(...)
So:
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Are there applications that rely on the sysfs ABI on DaVinci?
In that case base needs to be prerseved.
Not only base, but label also -
/sys/class/gpio/gpiochip0/label, as this is the way to find proper GPIO chip in sysfs using legacy GPIO ABI.Linus, this platform is old and most of the users do not use new ABI (chardev), so we could try change this, but need to be prepared for regressions reports.
So what I'm trying to ask you guys is if there are applications that you are aware of that use the old ABI, and who will upgrade their kernels and be upset.
Quoted 5 lines
We must not break userspace, but as you know if a tree falls in the forest and nobody is there to hear it, it doesn't make a sound.
If you're not aware of any such applications I guess we should try changing this.
Quoted 7 lines
Personally I am not really aware of any application which relies on the ABI. I may have some scripts, but I can adjust them. I am also copying some frequent users of DaVinci in mainline for any comments from them.
Thanks,
Sekhar
It won't break anything that I am aware of.
Re: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
In reply to KeerthyQuoted 98 lines · Keerthy
Quoted 35 lines · Grygorii Strashko
Quoted 32 lines · Keerthy
Quoted 20 lines · Linus Walleij
Quoted 19 lines · Keerthy
Quoted 7 lines · Andrew F. Davis
Use
dev_nameto get a unique label and use -1 for a base to get our selection automatically. We pull in all GPIOs per chip now so this does not have the effect of out of order labels like before.We do these both together so we can drop all the static data in one patch. This also lets us normalize the return paths as we don't need any cleanup after this change.
echo 28 >
/sys/class/gpio/export
/ # echo 28 > /sys/class/gpi[ 12.839205]export_store: invalid GPIO 28
o/export
echo 2 > /sys/class/gp[ 22.165728]export_store: invalid GPIO 2
io/export
/ # echo 1 > /sys/class/gp[ 25.961392]export_store: invalid GPIO 1
io/export
/ # echo 3 > /sys/class/gp[ 29.981918]export_store: invalid GPIO 3
io/exportQuoted 6 lines
Quoted 1 line
Export fails with this patch. I am testing this on keystone-k2g-evm.
I think the GPIO got a new number didn't it?
Did you check the gpio file in debugfs to see which number it got.
Okay now its numbered differently:
Quoted 8 lines
Quoted 5 lines
cat
/sys/class/gpio/gpiochip340/ngpio
144cat
/sys/class/gpio/gpiochip272/ngpio
68could you or Andrew provide content of /debug/gpio before/after? And ls
/sys/class/gpio/?Output on K2G:
Before
======cat /debug/gpio
gpiochip1: GPIOs 0-143, parent: platform/2603000.gpio, davinci_gpio.0:gpiochip2: GPIOs 144-211, parent: platform/260a000.gpio, davinci_gpio.1:
gpio-156 ( |cd ) in logpiochip0: GPIOs 484-511, parent: platform/2620240.keystone_dsp_gpio, 2620240.keystone_dsp_gpio:
ls
/sys/class/gpio/
export gpiochip0 gpiochip144 gpiochip484 unexportcat
/sys/class/gpio/gpiochip0/label
davinci_gpio.0cat
/sys/class/gpio/gpiochip144/label
davinci_gpio.1cat
/sys/class/gpio/gpiochip144/ngpio
68
/ # cat/sys/class/gpio/gpiochip0/ngpio
144After
=====cat /debug/gpio
gpiochip2: GPIOs 272-339, parent: platform/260a000.gpio, 260a000.gpio:
gpio-284 ( |cd ) in logpiochip1: GPIOs 340-483, parent: platform/2603000.gpio, 2603000.gpio:
gpiochip0: GPIOs 484-511, parent: platform/2620240.keystone_dsp_gpio, 2620240.keystone_dsp_gpio:
ls
/sys/class/gpio/
export gpiochip272 gpiochip340 gpiochip484 unexportcat
/sys/class/gpio/gpiochip340/label
2603000.gpio
/ # cat/sys/class/gpio/gpiochip272/label
260a000.gpio
/ # cat/sys/class/gpio/gpiochip272/label
Quoted 8 lines
cat
/sys/class/gpio/gpiochip272/ngpio
68
/ # cat/sys/class/gpio/gpiochip340/ngpio
144In the case of SoCs that support multiple instances of Davinci GPIO IPs it is harder to figure out the right gpio number to export.
Just to clarify above for all:
- for the first registered gpio chip
- if base >= 0 then gpiolib: try allocate gpios [base, base + ngpio] else gpiolib: try allocate gpios [ARCH_NR_GPIOS - ngpio, ARCH_NR_GPIOS]
so for the "after" case we can see gpio chip base allocation in hi to low order
Signature · 2 lines
regards, -grygorii
Quoted 5 lines · Andrew F. Davis
This was added as part of the patch in the fixes below, but was not needed or used, remove this here.
Fixes 8e11047b8f3c ("gpio: davinci: Add support for multiple GPIO controllers")Signed-off-by Andrew F. Davis <[email protected]>
Patch applied.
Yours,
Linus Walleij
Re: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
In reply to Andrew F. DavisQuoted 9 lines · Andrew F. Davis
Use
dev_nameto get a unique label and use -1 for a base to get our selection automatically. We pull in all GPIOs per chip now so this does not have the effect of out of order labels like before.We do these both together so we can drop all the static data in one patch. This also lets us normalize the return paths as we don't need any cleanup after this change.
Signed-off-by Andrew F. Davis <[email protected]>
I have tentatively applied this patch set as we seem to have rough consensus that it will be OK.
We can always pull it out or revert it if things break.
Yours,
Linus Walleij
Keerthy
maintainerRe: [PATCH 2/5] gpio: davinci: Use dev name for label and automatic base selection
Quoted 10 lines · Linus Walleij
Quoted 8 lines · Andrew F. Davis
Use
dev_nameto get a unique label and use -1 for a base to get our selection automatically. We pull in all GPIOs per chip now so this does not have the effect of out of order labels like before.We do these both together so we can drop all the static data in one patch. This also lets us normalize the return paths as we don't need any cleanup after this change.
Quoted 6 lines
Quoted 1 line
Signed-off-by Andrew F. Davis <[email protected]>I have tentatively applied this patch set as we seem to have rough consensus that it will be OK.
We can always pull it out or revert it if things break.
Okay. If that is the case then i have already tested the entire series.
Apart from gpio numbering different, i have tested toggling and interrupts with k2g-evm and omapl138.
Quoted 4 lines
Yours,
Linus Walleij
Re: [PATCH 3/5] gpio: davinci: Allocate the correct amount of memory for controller
In reply to Andrew F. DavisQuoted 9 lines · Andrew F. Davis
Previously we created a controller structure per bank of GPIO pins. This has since been changed to one per controller, but the allocation size was not changed. Fix this here.
This also leaves the variable 'nbank' unused, instead of removing it, move it down and use it to clean up a loop. For loops with multiple initializers and/or iteration expressions, especially ones that don't use those loop counters are quite hard to follow, fix this.
Tested for gpio interrupts on k2g and da850-lcdk
Quoted 41 lines
Signed-off-by Andrew F. Davis <[email protected]>--- drivers/gpio/gpio-davinci.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/gpio/gpio-davinci.c +4
-6@@ -165,7 +165,7 @@ davinci_gpio_get_pdata(struct platform_device *pdev)static int davinci_gpio_probe (struct platform_device *pdev) { -int gpio, bank, i, ret =0 ; +int bank, i, ret =0 ;unsigned int ngpio, nbank, nirq;struct davinci_gpio_controller *chips;struct davinci_gpio_platform_data *pdata;@@ -204,10 +204,7 @@ static int davinci_gpio_probe(struct platform_device *pdev)else nirq =DIV_ROUND_UP (ngpio,16 ); - nbank =DIV_ROUND_UP (ngpio,32 ); - chips =devm_kcalloc (dev, - nbank,sizeof (struct davinci_gpio_controller ), -GFP_KERNEL ); + chips =devm_kzalloc (dev,sizeof (*chips),GFP_KERNEL );if (!chips)return -ENOMEM ;@@ -247,7 +244,8 @@ static int davinci_gpio_probe(struct platform_device *pdev)#endif spin_lock_init (&chips->lock); -for (gpio =0 , bank =0 ; gpio < ngpio; gpio +=32 , bank++) + nbank =DIV_ROUND_UP (ngpio,32 ); +for (bank =0 ; bank < nbank; bank++) chips->regs[bank] = gpio_base + offset_array[bank]; ret =devm_gpiochip_add_data (dev, &chips->chip, chips);
Re: [PATCH 4/5] gpio: davinci: Remove unneeded GPIO macro
In reply to Andrew F. DavisQuoted 1 line · Andrew F. Davis
This macro does nothing and has only one user, remove it.
Tested for gpio interrupts on k2g and da850-lcdk
Quoted 43 lines
Signed-off-by Andrew F. Davis <[email protected]>--- arch/arm/mach-davinci/board-neuros-osd2.c | 8 ++++---- include/linux/platform_data/gpio-davinci.h | 5 ----- 2 files changed, 4 insertions(+), 9 deletions(-)arch/arm/mach-davinci/board-neuros-osd2.c +4
-4@@ -130,10 +130,10 @@ static struct platform_device davinci_fb_device = { };static const struct gpio_led ntosd2_leds[] = { - { .name ="led1_green" , .gpio =GPIO (10 ), }, - { .name ="led1_red" , .gpio =GPIO (11 ), }, - { .name ="led2_green" , .gpio =GPIO (12 ), }, - { .name ="led2_red" , .gpio =GPIO (13 ), }, + { .name ="led1_green" , .gpio =10 , }, + { .name ="led1_red" , .gpio =11 , }, + { .name ="led2_green" , .gpio =12 , }, + { .name ="led2_red" , .gpio =13 , }, };static struct gpio_led_platform_data ntosd2_leds_data = {include/linux/platform_data/gpio-davinci.h +0
-5@@ -45,11 +45,6 @@ struct davinci_gpio_controller {int irqs[MAX_INT_PER_BANK ]; }; -/* -* basic gpio routines -*/ -#define GPIO (X ) (X)/* 0 <= X <= (DAVINCI_N_GPIO - 1) */ -/* Convert GPIO signal to GPIO pin number */ #define GPIO_TO_PIN (bank, gpio) (16 * (bank) + (gpio))
Re: [PATCH 5/5] gpio: davinci: Move driver local definitions to driver
In reply to Andrew F. DavisQuoted 2 lines · Andrew F. Davis
These defines, structs and inline functions are used only internally by the driver, they do not belong in
platform_data. Move them.
Tested for gpio interrupts on k2g and da850-lcdk
Quoted 106 lines
Signed-off-by Andrew F. Davis <[email protected]>--- drivers/gpio/gpio-davinci.c | 28 ++++++++++++++++++++++ include/linux/platform_data/gpio-davinci.h | 28 ---------------------- 2 files changed, 28 insertions(+), 28 deletions(-)drivers/gpio/gpio-davinci.c +28
-0@@ -9,6 +9,7 @@* the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ +#include <linux/gpio/driver.h> #include <linux/errno.h> #include <linux/kernel.h> @@ -24,6 +25,12 @@#include <linux/platform_device.h> #include <linux/platform_data/gpio-davinci.h> #include <linux/irqchip/chained_irq.h> +#include <linux/spinlock.h> + +#include <asm-generic/gpio.h> + +#define MAX_REGS_BANKS 5 +#define MAX_INT_PER_BANK 32struct davinci_gpio_regs {u32 dir;@@ -45,6 +52,27 @@ typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq);static void __iomem *gpio_base;static unsigned int offset_array[5 ] = {0x10 ,0x38 ,0x60 ,0x88 ,0xb0 }; +struct davinci_gpio_irq_data { +void __iomem *regs; +struct davinci_gpio_controller *chip; +int bank_num; +}; + +struct davinci_gpio_controller { +struct gpio_chip chip; +struct irq_domain *irq_domain; +/* Serialize access to GPIO registers */ +spinlock_t lock; +void __iomem *regs[MAX_REGS_BANKS ]; +int gpio_unbanked; +int irqs[MAX_INT_PER_BANK ]; +}; + +static inline u32 __gpio_mask (unsigned gpio) +{ +return 1 << (gpio %32 ); +} +static inline struct davinci_gpio_regs __iomem *irq2regs (struct irq_data *d) {struct davinci_gpio_regs __iomem *g;include/linux/platform_data/gpio-davinci.h +0
-28@@ -16,40 +16,12 @@#ifndef __DAVINCI_GPIO_PLATFORM_H#define __DAVINCI_GPIO_PLATFORM_H -#include <linux/io.h> -#include <linux/spinlock.h> - -#include <asm-generic/gpio.h> - -#define MAX_REGS_BANKS 5 -#define MAX_INT_PER_BANK 32 -struct davinci_gpio_platform_data {u32 ngpio;u32 gpio_unbanked; }; -struct davinci_gpio_irq_data { -void __iomem *regs; -struct davinci_gpio_controller *chip; -int bank_num; -}; - -struct davinci_gpio_controller { -struct gpio_chip chip; -struct irq_domain *irq_domain; -/* Serialize access to GPIO registers */ -spinlock_t lock; -void __iomem *regs[MAX_REGS_BANKS ]; -int gpio_unbanked; -int irqs[MAX_INT_PER_BANK ]; -}; -/* Convert GPIO signal to GPIO pin number */ #define GPIO_TO_PIN (bank, gpio) (16 * (bank) + (gpio)) -static inline u32 __gpio_mask (unsigned gpio) -{ -return 1 << (gpio %32 ); -}#endif