gpio: sunxi: Handle pin configuration flags
Subsystems (5)
Samuel Holland
maintainercover gpio: sunxi: Handle pin configuration flags
This series updates the sunxi GPIO driver to handle pin pull-up/down, so consumer drivers do not need to call the non-DM sunxi_gpio_set_* functions. As an example, the last patch updates the MMC driver to use this functionality. The helpers added here will also be used for the upcoming DM_PINCTRL driver.
Samuel Holland (4):
sunxi: gpio: Return void from setter functions
sunxi: gpio: Add per-bank drive and pull setters
gpio: sunxi: Implement .set_flags
mmc: sunxi: Use DM_GPIO flags to set pull-up
arch/arm/include/asm/arch-sunxi/gpio.h | 6 ++- arch/arm/mach-sunxi/pinmux.c | 28 +++++++----- drivers/gpio/sunxi_gpio.c | 62 +++++++++++--------------- drivers/mmc/sunxi_mmc.c | 8 +--- 4 files changed, 51 insertions(+), 53 deletions(-)
Signature · 1 line
2.32.0
Samuel Holland
maintainerPATCH 1/4 sunxi: gpio: Return void from setter functions
The return values of these functions are always zero, and they are never checked. Since they are not needed, remove them.
---
arch/arm/include/asm/arch-sunxi/gpio.h | 4 ++-- arch/arm/mach-sunxi/pinmux.c | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-)
arch/arm/include/asm/arch-sunxi/gpio.h +2 -2
@@ -226,8 +226,8 @@ void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val);void sunxi_gpio_set_cfgpin (u32 pin,u32 val);int sunxi_gpio_get_cfgbank (struct sunxi_gpio *pio,int bank_offset);int sunxi_gpio_get_cfgpin (u32 pin); -int sunxi_gpio_set_drv (u32 pin,u32 val); -int sunxi_gpio_set_pull (u32 pin,u32 val); +void sunxi_gpio_set_drv (u32 pin,u32 val); +void sunxi_gpio_set_pull (u32 pin,u32 val);int sunxi_name_to_gpio (const char *name);#if !definedCONFIG_SPL_BUILD && definedCONFIG_AXP_GPIO
arch/arm/mach-sunxi/pinmux.c +2 -6
@@ -45,7 +45,7 @@ int sunxi_gpio_get_cfgpin(u32 pin)return sunxi_gpio_get_cfgbank (pio, pin); } -int sunxi_gpio_set_drv (u32 pin,u32 val) +void sunxi_gpio_set_drv (u32 pin,u32 val) {u32 bank =GPIO_BANK (pin);u32 index =GPIO_DRV_INDEX (pin);
@@ -53,11 +53,9 @@ int sunxi_gpio_set_drv(u32 pin, u32 val)struct sunxi_gpio *pio =BANK_TO_GPIO (bank);clrsetbits_le32 (&pio->drv[0 ] + index,0x3 << offset, val << offset); - -return 0 ; } -int sunxi_gpio_set_pull (u32 pin,u32 val) +void sunxi_gpio_set_pull (u32 pin,u32 val) {u32 bank =GPIO_BANK (pin);u32 index =GPIO_PULL_INDEX (pin);
@@ -65,6 +63,4 @@ int sunxi_gpio_set_pull(u32 pin, u32 val)struct sunxi_gpio *pio =BANK_TO_GPIO (bank);clrsetbits_le32 (&pio->pull[0 ] + index,0x3 << offset, val << offset); - -return 0 ; }
Signature · 1 line
2.32.0
Re: [PATCH 1/4] sunxi: gpio: Return void from setter functions
Quoted 4 lines · Samuel Holland
The return values of these functions are always zero, and they are never checked. Since they are not needed, remove them.
Signed-off-by Samuel Holland <[email protected]>
Samuel Holland
maintainerPATCH 2/4 sunxi: gpio: Add per-bank drive and pull setters
In reply to Samuel HollandThe GPIO and pinctrl drivers need these setters for pin configuration. Since they are DM drivers, they should not be using hardcoded base addresses. Factor out variants of the setter functions which take a pointer to the GPIO bank's MMIO registers.
---
arch/arm/include/asm/arch-sunxi/gpio.h | 2 ++ arch/arm/mach-sunxi/pinmux.c | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-)
arch/arm/include/asm/arch-sunxi/gpio.h +2 -0
@@ -227,7 +227,9 @@ void sunxi_gpio_set_cfgpin(u32 pin, u32 val);int sunxi_gpio_get_cfgbank (struct sunxi_gpio *pio,int bank_offset);int sunxi_gpio_get_cfgpin (u32 pin);void sunxi_gpio_set_drv (u32 pin,u32 val); +void sunxi_gpio_set_drv_bank (struct sunxi_gpio *pio,u32 bank_offset,u32 val);void sunxi_gpio_set_pull (u32 pin,u32 val); +void sunxi_gpio_set_pull_bank (struct sunxi_gpio *pio,int bank_offset,u32 val);int sunxi_name_to_gpio (const char *name);#if !definedCONFIG_SPL_BUILD && definedCONFIG_AXP_GPIO
arch/arm/mach-sunxi/pinmux.c +16 -4
@@ -48,19 +48,31 @@ int sunxi_gpio_get_cfgpin(u32 pin)void sunxi_gpio_set_drv (u32 pin,u32 val) {u32 bank =GPIO_BANK (pin); -u32 index =GPIO_DRV_INDEX (pin); -u32 offset =GPIO_DRV_OFFSET (pin);struct sunxi_gpio *pio =BANK_TO_GPIO (bank); +sunxi_gpio_set_drv_bank (pio, pin, val); +} + +void sunxi_gpio_set_drv_bank (struct sunxi_gpio *pio,u32 bank_offset,u32 val) +{ +u32 index =GPIO_DRV_INDEX (bank_offset); +u32 offset =GPIO_DRV_OFFSET (bank_offset); +clrsetbits_le32 (&pio->drv[0 ] + index,0x3 << offset, val << offset); }void sunxi_gpio_set_pull (u32 pin,u32 val) {u32 bank =GPIO_BANK (pin); -u32 index =GPIO_PULL_INDEX (pin); -u32 offset =GPIO_PULL_OFFSET (pin);struct sunxi_gpio *pio =BANK_TO_GPIO (bank); +sunxi_gpio_set_pull_bank (pio, pin, val); +} + +void sunxi_gpio_set_pull_bank (struct sunxi_gpio *pio,int bank_offset,u32 val) +{ +u32 index =GPIO_PULL_INDEX (bank_offset); +u32 offset =GPIO_PULL_OFFSET (bank_offset); +clrsetbits_le32 (&pio->pull[0 ] + index,0x3 << offset, val << offset); }
Signature · 1 line
2.32.0
Re: [PATCH 2/4] sunxi: gpio: Add per-bank drive and pull setters
Quoted 17 lines · Samuel Holland
The GPIO and pinctrl drivers need these setters for pin configuration. Since they are DM drivers, they should not be using hardcoded base addresses. Factor out variants of the setter functions which take a pointer to the GPIO bank's MMIO registers.
Signed-off-by Samuel Holland <[email protected]>---
arch/arm/include/asm/arch-sunxi/gpio.h | 2 ++ arch/arm/mach-sunxi/pinmux.c | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-)arch/arm/include/asm/arch-sunxi/gpio.h +0
-0
arch/arm/include/asm/arch-sunxi/gpio.h void sunxi_gpio_set_cfgpin(u32 pin, u32 val); · line 229
Quoted 3 lines
arch/arm/include/asm/arch-sunxi/gpio.h +0
-0@@ -227,7 +227,9 @@ void sunxi_gpio_set_cfgpin(u32 pin, u32 val);int sunxi_gpio_get_cfgbank (struct sunxi_gpio *pio,int bank_offset);int sunxi_gpio_get_cfgpin (u32 pin);void sunxi_gpio_set_drv (u32 pin,u32 val);
Please, add Sphinx style documentation for the new functions, preferably in the header file. Cf.
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation
Quoted 35 lines
arch/arm/include/asm/arch-sunxi/gpio.h +2
-0+void sunxi_gpio_set_drv_bank (struct sunxi_gpio *pio,u32 bank_offset,u32 val);void sunxi_gpio_set_pull (u32 pin,u32 val); +void sunxi_gpio_set_pull_bank (struct sunxi_gpio *pio,int bank_offset,u32 val);int sunxi_name_to_gpio (const char *name);#if !definedCONFIG_SPL_BUILD && definedCONFIG_AXP_GPIO arch/arm/mach-sunxi/pinmux.c +8
-4@@ -48,19 +48,31 @@ int sunxi_gpio_get_cfgpin(u32 pin)void sunxi_gpio_set_drv (u32 pin,u32 val) {u32 bank =GPIO_BANK (pin); -u32 index =GPIO_DRV_INDEX (pin); -u32 offset =GPIO_DRV_OFFSET (pin);struct sunxi_gpio *pio =BANK_TO_GPIO (bank); +sunxi_gpio_set_drv_bank (pio, pin, val); +} + +void sunxi_gpio_set_drv_bank (struct sunxi_gpio *pio,u32 bank_offset,u32 val) +{ +u32 index =GPIO_DRV_INDEX (bank_offset); +u32 offset =GPIO_DRV_OFFSET (bank_offset); +clrsetbits_le32 (&pio->drv[0 ] + index,0x3 << offset, val << offset); }void sunxi_gpio_set_pull (u32 pin,u32 val) {u32 bank =GPIO_BANK (pin); -u32 index =GPIO_PULL_INDEX (pin); -u32 offset =GPIO_PULL_OFFSET (pin);struct sunxi_gpio *pio =BANK_TO_GPIO (bank);
arch/arm/mach-sunxi/pinmux.c int sunxi_gpio_get_cfgpin(u32 pin) · line 77
Quoted 10 lines
arch/arm/mach-sunxi/pinmux.c +8
-0+sunxi_gpio_set_pull_bank (pio, pin, val); +} + +void sunxi_gpio_set_pull_bank (struct sunxi_gpio *pio,int bank_offset,u32 val) +{ +u32 index =GPIO_PULL_INDEX (bank_offset); +u32 offset =GPIO_PULL_OFFSET (bank_offset); +clrsetbits_le32 (&pio->pull[0 ] + index,0x3 << offset, val << offset);
Please, simplify this:
%s/&pio->pull[0] + index/&pio->pull[index]/
Otherwise the change looks correct to me.
Best regards
Heinrich
Quoted 2 lines
arch/arm/mach-sunxi/pinmux.c +0
-0}
Re: [PATCH 2/4] sunxi: gpio: Add per-bank drive and pull setters
Quoted 13 lines · On Fri, 5 Nov 2021 15:12:16 +0100 Heinrich Schuchardt…
Quoted 12 lines · Samuel Holland
The GPIO and pinctrl drivers need these setters for pin configuration. Since they are DM drivers, they should not be using hardcoded base addresses. Factor out variants of the setter functions which take a pointer to the GPIO bank's MMIO registers.
Signed-off-by Samuel Holland <[email protected]>---
arch/arm/include/asm/arch-sunxi/gpio.h | 2 ++ arch/arm/mach-sunxi/pinmux.c | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-)
Quoted 12 lines
arch/arm/include/asm/arch-sunxi/gpio.h void sunxi_gpio_set_cfgpin(u32 pin, u32 val); · line 229
Quoted 8 lines
arch/arm/include/asm/arch-sunxi/gpio.h +0
-0@@ -227,7 +227,9 @@ void sunxi_gpio_set_cfgpin(u32 pin, u32 val);int sunxi_gpio_get_cfgbank (struct sunxi_gpio *pio,int bank_offset);int sunxi_gpio_get_cfgpin (u32 pin);void sunxi_gpio_set_drv (u32 pin,u32 val);Please, add Sphinx style documentation for the new functions, preferably in the header file. Cf.
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation
I don't think this is necessary or useful, really. Those function are not really an advertised interface, more something we use internally, mostly for our SPL.
Quoted 36 lines
Quoted 36 lines
arch/arm/include/asm/arch-sunxi/gpio.h +2
-0+void sunxi_gpio_set_drv_bank (struct sunxi_gpio *pio,u32 bank_offset,u32 val);void sunxi_gpio_set_pull (u32 pin,u32 val); +void sunxi_gpio_set_pull_bank (struct sunxi_gpio *pio,int bank_offset,u32 val);int sunxi_name_to_gpio (const char *name);#if !definedCONFIG_SPL_BUILD && definedCONFIG_AXP_GPIO arch/arm/mach-sunxi/pinmux.c +8
-4@@ -48,19 +48,31 @@ int sunxi_gpio_get_cfgpin(u32 pin)void sunxi_gpio_set_drv (u32 pin,u32 val) {u32 bank =GPIO_BANK (pin); -u32 index =GPIO_DRV_INDEX (pin); -u32 offset =GPIO_DRV_OFFSET (pin);struct sunxi_gpio *pio =BANK_TO_GPIO (bank); +sunxi_gpio_set_drv_bank (pio, pin, val); +} + +void sunxi_gpio_set_drv_bank (struct sunxi_gpio *pio,u32 bank_offset,u32 val) +{ +u32 index =GPIO_DRV_INDEX (bank_offset); +u32 offset =GPIO_DRV_OFFSET (bank_offset); +clrsetbits_le32 (&pio->drv[0 ] + index,0x3 << offset, val << offset); }void sunxi_gpio_set_pull (u32 pin,u32 val) {u32 bank =GPIO_BANK (pin); -u32 index =GPIO_PULL_INDEX (pin); -u32 offset =GPIO_PULL_OFFSET (pin);struct sunxi_gpio *pio =BANK_TO_GPIO (bank);
Quoted 12 lines
arch/arm/mach-sunxi/pinmux.c int sunxi_gpio_get_cfgpin(u32 pin) · line 77
Quoted 9 lines
arch/arm/mach-sunxi/pinmux.c +8
-0+sunxi_gpio_set_pull_bank (pio, pin, val); +} + +void sunxi_gpio_set_pull_bank (struct sunxi_gpio *pio,int bank_offset,u32 val) +{ +u32 index =GPIO_PULL_INDEX (bank_offset); +u32 offset =GPIO_PULL_OFFSET (bank_offset); +clrsetbits_le32 (&pio->pull[0 ] + index,0x3 << offset, val << offset);Please, simplify this:
%s/&pio->pull[0] + index/&pio->pull[index]/
Fixing this up locally.
Cheers,
Andre
Quoted 10 lines
Otherwise the change looks correct to me.
Best regards
Heinrich
Quoted 2 lines
arch/arm/mach-sunxi/pinmux.c +0
-0}
Samuel Holland
maintainerPATCH 3/4 gpio: sunxi: Implement .set_flags
In reply to Samuel HollandThis, along with gpio_flags_xlate(), allows the GPIO driver to handle pull-up/down flags provided by consumer drivers or in the device tree.
---
drivers/gpio/sunxi_gpio.c | 62 +++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 35 deletions(-)
drivers/gpio/sunxi_gpio.c +27 -35
@@ -139,27 +139,6 @@ int sunxi_name_to_gpio(const char *name)return ret ? ret : gpio; } -static int sunxi_gpio_direction_input (struct udevice *dev,unsigned offset) -{ -struct sunxi_gpio_plat *plat =dev_get_plat (dev); - -sunxi_gpio_set_cfgbank (plat->regs, offset,SUNXI_GPIO_INPUT ); - -return 0 ; -} - -static int sunxi_gpio_direction_output (struct udevice *dev,unsigned offset, -int value) -{ -struct sunxi_gpio_plat *plat =dev_get_plat (dev); -u32 num =GPIO_NUM (offset); - -sunxi_gpio_set_cfgbank (plat->regs, offset,SUNXI_GPIO_OUTPUT ); -clrsetbits_le32 (&plat->regs->dat,1 << num, value ? (1 << num) :0 ); - -return 0 ; -} -static int sunxi_gpio_get_value (struct udevice *dev,unsigned offset) {struct sunxi_gpio_plat *plat =dev_get_plat (dev);
@@ -172,16 +151,6 @@ static int sunxi_gpio_get_value(struct udevice *dev, unsigned offset)return dat &0x1 ; } -static int sunxi_gpio_set_value (struct udevice *dev,unsigned offset, -int value) -{ -struct sunxi_gpio_plat *plat =dev_get_plat (dev); -u32 num =GPIO_NUM (offset); - -clrsetbits_le32 (&plat->regs->dat,1 << num, value ? (1 << num) :0 ); -return 0 ; -} -static int sunxi_gpio_get_function (struct udevice *dev,unsigned offset) {struct sunxi_gpio_plat *plat =dev_get_plat (dev);
@@ -205,18 +174,41 @@ static int sunxi_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,if (ret)return ret; desc->offset = args->args[1 ]; - desc->flags = args->args[2 ] &GPIO_ACTIVE_LOW ?GPIOD_ACTIVE_LOW :0 ; + desc->flags =gpio_flags_xlate (args->args[2 ]); + +return 0 ; +} + +static int sunxi_gpio_set_flags (struct udevice *dev,unsigned int offset, +ulong flags) +{ +struct sunxi_gpio_plat *plat =dev_get_plat (dev); + +if (flags &GPIOD_IS_OUT ) { +u32 value = !!(flags &GPIOD_IS_OUT_ACTIVE ); +u32 num =GPIO_NUM (offset); + +clrsetbits_le32 (&plat->regs->dat,1 << num, value << num); +sunxi_gpio_set_cfgbank (plat->regs, offset,SUNXI_GPIO_OUTPUT ); + }else if (flags &GPIOD_IS_IN ) { +u32 pull =0 ; + +if (flags &GPIOD_PULL_UP ) + pull =1 ; +else if (flags &GPIOD_PULL_DOWN ) + pull =2 ; +sunxi_gpio_set_pull_bank (plat->regs, offset, pull); +sunxi_gpio_set_cfgbank (plat->regs, offset,SUNXI_GPIO_INPUT ); + }return 0 ; }static const struct dm_gpio_ops gpio_sunxi_ops = { - .direction_input = sunxi_gpio_direction_input, - .direction_output = sunxi_gpio_direction_output, .get_value = sunxi_gpio_get_value, - .set_value = sunxi_gpio_set_value, .get_function = sunxi_gpio_get_function, .xlate = sunxi_gpio_xlate, + .set_flags = sunxi_gpio_set_flags, };/**
Signature · 1 line
2.32.0
Re: [PATCH 3/4] gpio: sunxi: Implement .set_flags
Quoted 10 lines · Samuel Holland
This, along with
gpio_flags_xlate(), allows the GPIO driver to handle pull-up/down flags provided by consumer drivers or in the device tree.Signed-off-by Samuel Holland <[email protected]>---
drivers/gpio/sunxi_gpio.c | 62 +++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 35 deletions(-)
Re: [PATCH 3/4] gpio: sunxi: Implement .set_flags
In reply to Samuel HollandQuoted 87 lines · Samuel Holland
This, along with
gpio_flags_xlate(), allows the GPIO driver to handle pull-up/down flags provided by consumer drivers or in the device tree.Signed-off-by Samuel Holland <[email protected]>Reviewed-by Simon Glass <[email protected]>---
drivers/gpio/sunxi_gpio.c | 62 +++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 35 deletions(-)drivers/gpio/sunxi_gpio.c +23
-32@@ -139,27 +139,6 @@ int sunxi_name_to_gpio(const char *name)return ret ? ret : gpio; } -static int sunxi_gpio_direction_input (struct udevice *dev,unsigned offset) -{ -struct sunxi_gpio_plat *plat =dev_get_plat (dev); - -sunxi_gpio_set_cfgbank (plat->regs, offset,SUNXI_GPIO_INPUT ); - -return 0 ; -} - -static int sunxi_gpio_direction_output (struct udevice *dev,unsigned offset, -int value) -{ -struct sunxi_gpio_plat *plat =dev_get_plat (dev); -u32 num =GPIO_NUM (offset); - -sunxi_gpio_set_cfgbank (plat->regs, offset,SUNXI_GPIO_OUTPUT ); -clrsetbits_le32 (&plat->regs->dat,1 << num, value ? (1 << num) :0 ); - -return 0 ; -} -static int sunxi_gpio_get_value (struct udevice *dev,unsigned offset) {struct sunxi_gpio_plat *plat =dev_get_plat (dev);@@ -172,16 +151,6 @@ static int sunxi_gpio_get_value(struct udevice *dev, unsigned offset)return dat &0x1 ; } -static int sunxi_gpio_set_value (struct udevice *dev,unsigned offset, -int value) -{ -struct sunxi_gpio_plat *plat =dev_get_plat (dev); -u32 num =GPIO_NUM (offset); - -clrsetbits_le32 (&plat->regs->dat,1 << num, value ? (1 << num) :0 ); -return 0 ; -} -static int sunxi_gpio_get_function (struct udevice *dev,unsigned offset) {struct sunxi_gpio_plat *plat =dev_get_plat (dev);@@ -205,18 +174,41 @@ static int sunxi_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,if (ret)return ret; desc->offset = args->args[1 ]; - desc->flags = args->args[2 ] &GPIO_ACTIVE_LOW ?GPIOD_ACTIVE_LOW :0 ; + desc->flags =gpio_flags_xlate (args->args[2 ]); + +return 0 ; +} + +static int sunxi_gpio_set_flags (struct udevice *dev,unsigned int offset, +ulong flags) +{ +struct sunxi_gpio_plat *plat =dev_get_plat (dev); + +if (flags &GPIOD_IS_OUT ) { +u32 value = !!(flags &GPIOD_IS_OUT_ACTIVE ); +u32 num =GPIO_NUM (offset); + +clrsetbits_le32 (&plat->regs->dat,1 << num, value << num); +sunxi_gpio_set_cfgbank (plat->regs, offset,SUNXI_GPIO_OUTPUT ); + }else if (flags &GPIOD_IS_IN ) { +u32 pull =0 ; + +if (flags &GPIOD_PULL_UP ) + pull =1 ; +else if (flags &GPIOD_PULL_DOWN ) + pull =2 ;
drivers/gpio/sunxi_gpio.c static int sunxi_gpio_xlate(struct udevice *dev, struct gpio_desc *desc, · line 215
Quoted 10 lines
drivers/gpio/sunxi_gpio.c +3
-2+sunxi_gpio_set_pull_bank (plat->regs, offset, pull); +sunxi_gpio_set_cfgbank (plat->regs, offset,SUNXI_GPIO_INPUT ); + }return 0 ; }static const struct dm_gpio_ops gpio_sunxi_ops = { - .direction_input = sunxi_gpio_direction_input, - .direction_output = sunxi_gpio_direction_output,
Removing these operations is not related to your commit message.
dm_set_gpio_value() seems to be using them.
drivers/gpio/sunxi_gpio.c static int sunxi_gpio_xlate(struct udevice *dev, struct gpio_desc *desc, · line 217
Quoted 2 lines
drivers/gpio/sunxi_gpio.c +0
-1.get_value = sunxi_gpio_get_value, - .set_value = sunxi_gpio_set_value,
Same here.
Best regards
Heinrich
Quoted 7 lines
drivers/gpio/sunxi_gpio.c +1
-0.get_function = sunxi_gpio_get_function, .xlate = sunxi_gpio_xlate, + .set_flags = sunxi_gpio_set_flags, };/**
Samuel Holland
maintainerRe: [PATCH 3/4] gpio: sunxi: Implement .set_flags
Quoted 104 lines · Heinrich Schuchardt
Quoted 90 lines · Samuel Holland
This, along with
gpio_flags_xlate(), allows the GPIO driver to handle pull-up/down flags provided by consumer drivers or in the device tree.Signed-off-by Samuel Holland <[email protected]>Reviewed-by Simon Glass <[email protected]>---
drivers/gpio/sunxi_gpio.c| 62 +++++++++++++++++----------------------1 file changed, 27 insertions(+), 35 deletions(-)drivers/gpio/sunxi_gpio.c +0
-0@@ -139,27 +139,6 @@ int sunxi_name_to_gpio(const char *name) return ret ? ret : gpio; }-static int
sunxi_gpio_direction_input(struct udevice *dev, unsigned offset)drivers/gpio/sunxi_gpio.c +0
-9-{ - struct sunxi_gpio_plat *plat = dev_get_plat(dev); - - sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_INPUT); - - return 0; -} - -static int sunxi_gpio_direction_output(struct udevice *dev, unsignedoffset,
- int value)drivers/gpio/sunxi_gpio.c +0
-10-{ - struct sunxi_gpio_plat *plat = dev_get_plat(dev); - u32 num = GPIO_NUM(offset); - - sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_OUTPUT); - clrsetbits_le32(&plat->regs->dat, 1 << num, value ? (1 << num) : 0); - - return 0; -} -static int
sunxi_gpio_get_value(struct udevice *dev, unsigned offset){
structsunxi_gpio_plat*plat =dev_get_plat(dev);drivers/gpio/sunxi_gpio.c +0
-9@@ -172,16 +151,6 @@ static int sunxi_gpio_get_value(struct udevice *dev, unsigned offset) return dat & 0x1; } -static int sunxi_gpio_set_value(struct udevice *dev, unsigned offset, - int value) -{ - struct sunxi_gpio_plat *plat = dev_get_plat(dev); - u32 num = GPIO_NUM(offset); - - clrsetbits_le32(&plat->regs->dat, 1 << num, value ? (1 << num) : 0); - return 0; -} -static int
sunxi_gpio_get_function(struct udevice *dev, unsigned offset)
{
structsunxi_gpio_plat*plat =dev_get_plat(dev);drivers/gpio/sunxi_gpio.c +21
-1@@ -205,18 +174,41 @@ static int sunxi_gpio_xlate(struct udevice *dev,struct gpio_desc *desc, if (ret) return ret; desc->offset = args->args[1]; - desc->flags = args->args[2] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0; + desc->flags = gpio_flags_xlate(args->args[2]); + + return 0; +} + +static int sunxi_gpio_set_flags (struct udevice *dev,unsigned int offset, + ulong flags) +{ + struct sunxi_gpio_plat *plat = dev_get_plat(dev); + + if (flags & GPIOD_IS_OUT) { + u32 value = !!(flags & GPIOD_IS_OUT_ACTIVE); + u32 num = GPIO_NUM(offset); + + clrsetbits_le32(&plat->regs->dat, 1 << num, value << num); + sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_OUTPUT); + } else if (flags & GPIOD_IS_IN) { + u32 pull = 0; + + if (flags & GPIOD_PULL_UP) + pull = 1;drivers/gpio/sunxi_gpio.c static int sunxi_gpio_xlate(struct udevice *dev, · line 216
Quoted 10 lines
drivers/gpio/sunxi_gpio.c +5
-2+ else if (flags & GPIOD_PULL_DOWN) + pull = 2; + sunxi_gpio_set_pull_bank(plat->regs, offset, pull); + sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_INPUT); + } return 0; } static const struct dm_gpio_ops gpio_sunxi_ops = { - .direction_input = sunxi_gpio_direction_input, - .direction_output = sunxi_gpio_direction_output,Removing these operations is not related to your commit message.
Quoted 1 line
dm_gpio_set_value()seems to be using them.
It does not use any of these operations when set_flags is provided. The same applies to _dm_gpio_set_flags().
asm-generic/gpio.h says about set_flags:
Quoted 3 lines
This method is required and should be implemented by new drivers. At some point, it will supersede
direction_input()anddirection_output(), which wil be removed.
So I believe it is intended to replace the other three operations.
Regards,
Samuel
Quoted 16 lines
drivers/gpio/sunxi_gpio.c static int sunxi_gpio_xlate(struct udevice *dev, struct gpio_desc *desc, · line 217
Quoted 2 lines
drivers/gpio/sunxi_gpio.c +0
-1.get_value = sunxi_gpio_get_value, - .set_value = sunxi_gpio_set_value,Same here.
Best regards
Heinrich
Quoted 6 lines
drivers/gpio/sunxi_gpio.c +1
-0.get_function = sunxi_gpio_get_function, .xlate = sunxi_gpio_xlate, + .set_flags = sunxi_gpio_set_flags, }; /**
Andre Przywara
Reviewed-byRe: [PATCH 3/4] gpio: sunxi: Implement .set_flags
Quoted 110 lines · On Fri, 5 Nov 2021 16:46:07 -0500 Samuel Holland <[email protected]> wrote:
Quoted 104 lines · Heinrich Schuchardt
Quoted 90 lines · Samuel Holland
This, along with
gpio_flags_xlate(), allows the GPIO driver to handle pull-up/down flags provided by consumer drivers or in the device tree.Signed-off-by Samuel Holland <[email protected]>Reviewed-by Simon Glass <[email protected]>---
drivers/gpio/sunxi_gpio.c| 62 +++++++++++++++++----------------------1 file changed, 27 insertions(+), 35 deletions(-)drivers/gpio/sunxi_gpio.c +0
-0@@ -139,27 +139,6 @@ int sunxi_name_to_gpio(const char *name) return ret ? ret : gpio; }-static int
sunxi_gpio_direction_input(struct udevice *dev, unsigned offset)drivers/gpio/sunxi_gpio.c +0
-9-{ - struct sunxi_gpio_plat *plat = dev_get_plat(dev); - - sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_INPUT); - - return 0; -} - -static int sunxi_gpio_direction_output(struct udevice *dev, unsignedoffset,
- int value)drivers/gpio/sunxi_gpio.c +0
-10-{ - struct sunxi_gpio_plat *plat = dev_get_plat(dev); - u32 num = GPIO_NUM(offset); - - sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_OUTPUT); - clrsetbits_le32(&plat->regs->dat, 1 << num, value ? (1 << num) : 0); - - return 0; -} -static int
sunxi_gpio_get_value(struct udevice *dev, unsigned offset){
structsunxi_gpio_plat*plat =dev_get_plat(dev);drivers/gpio/sunxi_gpio.c +0
-9@@ -172,16 +151,6 @@ static int sunxi_gpio_get_value(struct udevice *dev, unsigned offset) return dat & 0x1; } -static int sunxi_gpio_set_value(struct udevice *dev, unsigned offset, - int value) -{ - struct sunxi_gpio_plat *plat = dev_get_plat(dev); - u32 num = GPIO_NUM(offset); - - clrsetbits_le32(&plat->regs->dat, 1 << num, value ? (1 << num) : 0); - return 0; -} -static int
sunxi_gpio_get_function(struct udevice *dev, unsigned offset)
{
structsunxi_gpio_plat*plat =dev_get_plat(dev);drivers/gpio/sunxi_gpio.c +21
-1@@ -205,18 +174,41 @@ static int sunxi_gpio_xlate(struct udevice *dev,struct gpio_desc *desc, if (ret) return ret; desc->offset = args->args[1]; - desc->flags = args->args[2] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0; + desc->flags = gpio_flags_xlate(args->args[2]); + + return 0; +} + +static int sunxi_gpio_set_flags (struct udevice *dev,unsigned int offset, + ulong flags) +{ + struct sunxi_gpio_plat *plat = dev_get_plat(dev); + + if (flags & GPIOD_IS_OUT) { + u32 value = !!(flags & GPIOD_IS_OUT_ACTIVE); + u32 num = GPIO_NUM(offset); + + clrsetbits_le32(&plat->regs->dat, 1 << num, value << num); + sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_OUTPUT); + } else if (flags & GPIOD_IS_IN) { + u32 pull = 0; + + if (flags & GPIOD_PULL_UP) + pull = 1;drivers/gpio/sunxi_gpio.c static int sunxi_gpio_xlate(struct udevice *dev, · line 216
Quoted 10 lines
drivers/gpio/sunxi_gpio.c +5
-2+ else if (flags & GPIOD_PULL_DOWN) + pull = 2; + sunxi_gpio_set_pull_bank(plat->regs, offset, pull); + sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_INPUT); + } return 0; } static const struct dm_gpio_ops gpio_sunxi_ops = { - .direction_input = sunxi_gpio_direction_input, - .direction_output = sunxi_gpio_direction_output,Removing these operations is not related to your commit message.
Quoted 1 line
dm_gpio_set_value()seems to be using them.It does not use any of these operations when
set_flagsis provided. The same applies to_dm_gpio_set_flags().
Quoted 6 lines
asm-generic/gpio.hsays aboutset_flags:Quoted 3 lines
This method is required and should be implemented by new drivers. At some point, it will supersede
direction_input()anddirection_output(), which wil be removed.So I believe it is intended to replace the other three operations.
That's what I get from the code and this header file comment as well.
Cheers,
Andre
Quoted 21 lines
Regards,
SamuelQuoted 16 lines
drivers/gpio/sunxi_gpio.c static int sunxi_gpio_xlate(struct udevice *dev, struct gpio_desc *desc, · line 217
Quoted 2 lines
drivers/gpio/sunxi_gpio.c +0
-1.get_value = sunxi_gpio_get_value, - .set_value = sunxi_gpio_set_value,Same here.
Best regards
Heinrich
Quoted 6 lines
drivers/gpio/sunxi_gpio.c +1
-0.get_function = sunxi_gpio_get_function, .xlate = sunxi_gpio_xlate, + .set_flags = sunxi_gpio_set_flags, }; /**
Samuel Holland
maintainerPATCH 4/4 mmc: sunxi: Use DM_GPIO flags to set pull-up
In reply to Samuel HollandNow that the sunxi_gpio driver handles pull-up/down via the driver model, pin configuration does not need a platform-specific function.
---
drivers/mmc/sunxi_mmc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/mmc/sunxi_mmc.c +2 -6
@@ -700,12 +700,8 @@ static int sunxi_mmc_probe(struct udevice *dev)return ret;/* This GPIO is optional */ -if (!gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, -GPIOD_IS_IN )) { -int cd_pin =gpio_get_number (&priv->cd_gpio); - -sunxi_gpio_set_pull (cd_pin,SUNXI_GPIO_PULL_UP ); - } +gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, +GPIOD_IS_IN |GPIOD_PULL_UP ); upriv->mmc = &plat->mmc;
Signature · 1 line
2.32.0
Re: [PATCH 4/4] mmc: sunxi: Use DM_GPIO flags to set pull-up
Hi,
Quoted 15 lines · Samuel Holland
Now that the
sunxi_gpiodriver handles pull-up/down via the driver model, pin configuration does not need a platform-specific function.Signed-off-by Samuel Holland <[email protected]>---
drivers/mmc/sunxi_mmc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/mmc/sunxi_mmc.c +0
-0@@ -700,12 +700,8 @@ static int sunxi_mmc_probe(struct udevice *dev)return ret;
drivers/mmc/sunxi_mmc.c static int sunxi_mmc_probe(struct udevice *dev) · line 704
Quoted 10 lines
drivers/mmc/sunxi_mmc.c +2
-6/* This GPIO is optional */ -if (!gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, -GPIOD_IS_IN )) { -int cd_pin =gpio_get_number (&priv->cd_gpio); - -sunxi_gpio_set_pull (cd_pin,SUNXI_GPIO_PULL_UP ); - } +gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, +GPIOD_IS_IN |GPIOD_PULL_UP );
Is it right to set the pull-up?
Best Regards,
Jaehoon Chung
Quoted 4 lines
drivers/mmc/sunxi_mmc.c +0
-0upriv->mmc = &plat->mmc;
Re: [PATCH 4/4] mmc: sunxi: Use DM_GPIO flags to set pull-up
On Fri, 22 Oct 2021 06:58:48 +0900
Jaehoon Chung <[email protected]> wrote:
Hi Jaehoon,
thanks for having a look!
Quoted 19 lines
Hi,
Quoted 16 lines · Samuel Holland
Now that the
sunxi_gpiodriver handles pull-up/down via the driver model, pin configuration does not need a platform-specific function.Signed-off-by Samuel Holland <[email protected]>---
drivers/mmc/sunxi_mmc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/mmc/sunxi_mmc.c +0
-0@@ -700,12 +700,8 @@ static int sunxi_mmc_probe(struct udevice *dev)return ret;
Quoted 11 lines
drivers/mmc/sunxi_mmc.c static int sunxi_mmc_probe(struct udevice *dev) · line 704
Quoted 9 lines
drivers/mmc/sunxi_mmc.c +2
-6/* This GPIO is optional */ -if (!gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, -GPIOD_IS_IN )) { -int cd_pin =gpio_get_number (&priv->cd_gpio); - -sunxi_gpio_set_pull (cd_pin,SUNXI_GPIO_PULL_UP ); - } +gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, +GPIOD_IS_IN |GPIOD_PULL_UP );Is it right to set the pull-up?
You mean, unconditionally? I mean it's just copying the current code, which does that (see the "minus" lines just above).
But I think you have a point: I don't see any pull up specified in any DT, and I think most (if not all) boards have a discrete pull up resistor on that line.
But I don't dare to touch that code - at least for this series, as it works (TM) right now.
After the full DM_PINCTRL series this might be another story, though.
Cheers,
Andre
Quoted 9 lines
Best Regards,
Jaehoon ChungQuoted 4 lines
drivers/mmc/sunxi_mmc.c +0
-0upriv->mmc = &plat->mmc;
Re: [PATCH 4/4] mmc: sunxi: Use DM_GPIO flags to set pull-up
Hi Andre,
Quoted 38 lines · Andre Przywara
On Fri, 22 Oct 2021 06:58:48 +0900
Jaehoon Chung <[email protected]> wrote:Hi Jaehoon,
thanks for having a look!
Quoted 19 lines
Hi,
Quoted 16 lines · Samuel Holland
Now that the
sunxi_gpiodriver handles pull-up/down via the driver model, pin configuration does not need a platform-specific function.Signed-off-by Samuel Holland <[email protected]>---
drivers/mmc/sunxi_mmc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/mmc/sunxi_mmc.c +0
-0@@ -700,12 +700,8 @@ static int sunxi_mmc_probe(struct udevice *dev)return ret;Quoted 11 lines
drivers/mmc/sunxi_mmc.c static int sunxi_mmc_probe(struct udevice *dev) · line 704
Quoted 9 lines
drivers/mmc/sunxi_mmc.c +2
-6/* This GPIO is optional */ -if (!gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, -GPIOD_IS_IN )) { -int cd_pin =gpio_get_number (&priv->cd_gpio); - -sunxi_gpio_set_pull (cd_pin,SUNXI_GPIO_PULL_UP ); - } +gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, +GPIOD_IS_IN |GPIOD_PULL_UP );Is it right to set the pull-up?
Quoted 2 lines
You mean, unconditionally? I mean it's just copying the current code, which does that (see the "minus" lines just above).
Yes, it looks like something strange.
AFAIK, It can be changed that cd-gpios has dependent how to consist of H/W. But it's not different with original behavior, as you mentioned.
Quoted 8 lines
But I think you have a point: I don't see any pull up specified in any DT, and I think most (if not all) boards have a discrete pull up resistor on that line.
But I don't dare to touch that code - at least for this series, as it works (TM) right now.
After the fullDM_PINCTRLseries this might be another story, though.
Right. I understood exactly. Thanks for explanation.
P.S: Can I test sunxi patch with NeoPlus2 board(Allwinner H5)?
Best Regards,
Jaehoon Chung
Quoted 15 lines
Cheers,
AndreQuoted 9 lines
Best Regards,
Jaehoon ChungQuoted 4 lines
drivers/mmc/sunxi_mmc.c +0
-0upriv->mmc = &plat->mmc;
Re: [PATCH 4/4] mmc: sunxi: Use DM_GPIO flags to set pull-up
Quoted 53 lines · On Fri, 22 Oct 2021 19:10:20 +0900 Jaehoon Chung <[email protected]> wrote:
Hi Andre,
Quoted 38 lines · Andre Przywara
On Fri, 22 Oct 2021 06:58:48 +0900
Jaehoon Chung <[email protected]> wrote:Hi Jaehoon,
thanks for having a look!
Quoted 19 lines
Hi,
Quoted 16 lines · Samuel Holland
Now that the
sunxi_gpiodriver handles pull-up/down via the driver model, pin configuration does not need a platform-specific function.Signed-off-by Samuel Holland <[email protected]>---
drivers/mmc/sunxi_mmc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/mmc/sunxi_mmc.c +0
-0@@ -700,12 +700,8 @@ static int sunxi_mmc_probe(struct udevice *dev)return ret;Quoted 11 lines
drivers/mmc/sunxi_mmc.c static int sunxi_mmc_probe(struct udevice *dev) · line 704
Quoted 9 lines
drivers/mmc/sunxi_mmc.c +2
-6/* This GPIO is optional */ -if (!gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, -GPIOD_IS_IN )) { -int cd_pin =gpio_get_number (&priv->cd_gpio); - -sunxi_gpio_set_pull (cd_pin,SUNXI_GPIO_PULL_UP ); - } +gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, +GPIOD_IS_IN |GPIOD_PULL_UP );Is it right to set the pull-up?
Quoted 2 lines
You mean, unconditionally? I mean it's just copying the current code, which does that (see the "minus" lines just above).
Yes, it looks like something strange.
AFAIK, It can be changed that cd-gpios has dependent how to consist of H/W. But it's not different with original behavior, as you mentioned.Quoted 5 lines
But I think you have a point: I don't see any pull up specified in any DT, and I think most (if not all) boards have a discrete pull up resistor on that line.
Quoted 7 lines
Quoted 3 lines
But I don't dare to touch that code - at least for this series, as it works (TM) right now.
After the fullDM_PINCTRLseries this might be another story, though.Right. I understood exactly. Thanks for explanation.
P.S: Can I test sunxi patch with NeoPlus2 board(Allwinner H5)?
Yes, please, any testing on any kind of Allwinner board is warmly welcomed. There are 160 supported Allwinner boards in the tree, and even though I have probably more of them than I want, it's only a fraction of them. And experience show that some boards are subtly broken. Also feel free to report any other broken things you see when testing!
Thanks,
Andre
Quoted 20 lines
Best Regards,
Jaehoon ChungQuoted 15 lines
Cheers,
AndreQuoted 9 lines
Best Regards,
Jaehoon ChungQuoted 4 lines
drivers/mmc/sunxi_mmc.c +0
-0upriv->mmc = &plat->mmc;
Re: [PATCH 4/4] mmc: sunxi: Use DM_GPIO flags to set pull-up
In reply to Samuel HollandQuoted 4 lines · Samuel Holland
Now that the
sunxi_gpiodriver handles pull-up/down via the driver model, pin configuration does not need a platform-specific function.Signed-off-by Samuel Holland <[email protected]>
I tested on an OrangePi PC (orangepi_pc_defconfig). The 'mmc rescan' command detects correctly if an SD-card is present with this series applied.
Quoted 25 lines
---
drivers/mmc/sunxi_mmc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/mmc/sunxi_mmc.c +2
-6@@ -700,12 +700,8 @@ static int sunxi_mmc_probe(struct udevice *dev)return ret;/* This GPIO is optional */ -if (!gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, -GPIOD_IS_IN )) { -int cd_pin =gpio_get_number (&priv->cd_gpio); - -sunxi_gpio_set_pull (cd_pin,SUNXI_GPIO_PULL_UP ); - } +gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio, +GPIOD_IS_IN |GPIOD_PULL_UP ); upriv->mmc = &plat->mmc;