Update STM32 gpio and pinctrl drivers
Subsystems (5)
cover Update STM32 gpio and pinctrl drivers
This series adds:
- Add gpio holes management in gpio and pinctrl drivers
- Remove useless CONFIG_CLK flag from gpio driver
- Move code outside pinctrl probe()
There is a dependency with http://patchwork.ozlabs.org/project/uboot/list/?series=78259
which must be applied first.
Patrice Chotard (5):
pinctrl: stm32: Move gpio_dev list filling outside probe()
gpio: stm32f7: Add gpio bank holes management
gpio: stm32f7: Move STM32_GPIOS_PER_BANK into gpio.h
gpio: stm32f7: Remove CONFIG_CLK flag.
pinctrl: stm32: Update stm32_pinctrl_get_gpio_dev()
arch/arm/include/asm/arch-stm32/gpio.h | 5 ++ arch/arm/mach-stm32mp/include/mach/gpio.h | 6 ++ drivers/gpio/stm32f7_gpio.c | 104 ++++++++++++++++++++++++----- drivers/pinctrl/pinctrl_stm32.c | 105 ++++++++++++++++++------------ 4 files changed, 159 insertions(+), 61 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/5 pinctrl: stm32: Move gpio_dev list filling outside probe()
Move gpio_dev list filling outside probe() to speed-up U-boot boot sequence execution. This list is populated only when needed.
---
drivers/pinctrl/pinctrl_stm32.c | 63 +++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 25 deletions(-)
drivers/pinctrl/pinctrl_stm32.c +38 -25
@@ -54,6 +54,39 @@ static int stm32_pinctrl_get_af(struct udevice *dev, unsigned int offset)return af; } +static int stm32_populate_gpio_dev_list (struct udevice *dev) +{ +struct stm32_pinctrl_priv *priv =dev_get_priv (dev); +struct udevice *gpio_dev; +struct udevice *child; +struct stm32_gpio_bank *gpio_bank; +int ret; + +/* +* parse pin-controller sub-nodes (ie gpio bank nodes) and fill +* a list with all gpio device reference which belongs to the +* current pin-controller. This list is used to find pin_name and +* pin muxing +*/ +list_for_each_entry (child, &dev->child_head, sibling_node) { + ret =uclass_get_device_by_name (UCLASS_GPIO , child->name, + &gpio_dev); +if (ret <0 ) +continue ; + + gpio_bank =malloc (sizeof (*gpio_bank)); +if (!gpio_bank) { +dev_err (dev,"Not enough memory\n" ); +return -ENOMEM ; + } + + gpio_bank->gpio_dev = gpio_dev; +list_add_tail (&gpio_bank->list, &priv->gpio_dev); + } + +return 0 ; +} +static int stm32_pinctrl_get_pins_count (struct udevice *dev) {struct stm32_pinctrl_priv *priv =dev_get_priv (dev);
@@ -67,6 +100,8 @@ static int stm32_pinctrl_get_pins_count(struct udevice *dev)if (priv->pinctrl_ngpios)return priv->pinctrl_ngpios; +if (list_empty (&priv->gpio_dev)) +stm32_populate_gpio_dev_list (dev);/* * walk through all banks to retrieve the pin-controller * pins number
@@ -88,6 +123,9 @@ static struct udevice *stm32_pinctrl_get_gpio_dev(struct udevice *dev,struct gpio_dev_priv *uc_priv;int first_pin =0 ; +if (list_empty (&priv->gpio_dev)) +stm32_populate_gpio_dev_list (dev); +/* look up for the bank which owns the requested pin */ list_for_each_entry (gpio_bank, &priv->gpio_dev, list) { uc_priv =dev_get_uclass_priv (gpio_bank->gpio_dev);
@@ -174,35 +212,10 @@ static int stm32_pinctrl_get_pin_muxing(struct udevice *dev,int stm32_pinctrl_probe (struct udevice *dev) {struct stm32_pinctrl_priv *priv =dev_get_priv (dev); -struct udevice *gpio_dev; -struct udevice *child; -struct stm32_gpio_bank *gpio_bank;int ret;INIT_LIST_HEAD (&priv->gpio_dev); -/* -* parse pin-controller sub-nodes (ie gpio bank nodes) and fill -* a list with all gpio device reference which belongs to the -* current pin-controller. This list is used to find pin_name and -* pin muxing -*/ -list_for_each_entry (child, &dev->child_head, sibling_node) { - ret =uclass_get_device_by_name (UCLASS_GPIO , child->name, - &gpio_dev); -if (ret <0 ) -continue ; - - gpio_bank =malloc (sizeof (*gpio_bank)); -if (!gpio_bank) { -dev_err (dev,"Not enough memory\n" ); -return -ENOMEM ; - } - - gpio_bank->gpio_dev = gpio_dev; -list_add_tail (&gpio_bank->list, &priv->gpio_dev); - } -/* hwspinlock property is optional, just log the error */ ret =hwspinlock_get_by_index (dev,0 , &priv->hws);if (ret)
Signature · 1 line
1.9.1
PATCH 1/5 pinctrl: stm32: Move gpio_dev list filling outside probe()
Quoted 4 lines · Patrice Chotard
Move
gpio_devlist filling outsideprobe()to speed-up U-boot boot sequence execution. This list is populated only when needed.Signed-off-by Patrice Chotard <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181207/59817b6c/attachment.sig>
PATCH 2/5 gpio: stm32f7: Add gpio bank holes management
In reply to Patrice ChotardIn some STM32 SoC packages, GPIO bank has not always 16 gpios. Several cases can occur, gpio hole can be located at the beginning, middle or end of the gpio bank or a combination of these 3 configurations.
For that, gpio bindings offer the gpio-ranges DT property which described the gpio bank mapping.
---
arch/arm/include/asm/arch-stm32/gpio.h | 3 + arch/arm/mach-stm32mp/include/mach/gpio.h | 4 ++ drivers/gpio/stm32f7_gpio.c | 99 ++++++++++++++++++++++++++----- 3 files changed, 92 insertions(+), 14 deletions(-)
arch/arm/include/asm/arch-stm32/gpio.h +3 -0
@@ -109,6 +109,9 @@ struct stm32_gpio_regs {struct stm32_gpio_priv {struct stm32_gpio_regs *regs; +unsigned int gpio_range; }; +int stm32_offset_to_index (struct udevice *dev,unsigned int offset); +#endif /* _GPIO_H_ */
arch/arm/mach-stm32mp/include/mach/gpio.h +4 -0
@@ -110,5 +110,9 @@ struct stm32_gpio_regs {struct stm32_gpio_priv {struct stm32_gpio_regs *regs; +unsigned int gpio_range; }; + +int stm32_offset_to_index (struct udevice *dev,unsigned int offset); +#endif /* _STM32_GPIO_H_ */
drivers/gpio/stm32f7_gpio.c +85 -14
157 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 2/5 gpio: stm32f7: Add gpio bank holes management
Quoted 9 lines · Patrice Chotard
In some STM32 SoC packages, GPIO bank has not always 16 gpios. Several cases can occur, gpio hole can be located at the beginning, middle or end of the gpio bank or a combination of these 3 configurations.
For that, gpio bindings offer the gpio-ranges DT property which described the gpio bank mapping.
Signed-off-by Patrice Chotard <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181207/f7f2c306/attachment.sig>
PATCH 3/5 gpio: stm32f7: Move STM32_GPIOS_PER_BANK into gpio.h
In reply to Patrice ChotardTo allow access to this define by other driver, move it into gpio.h
---
arch/arm/include/asm/arch-stm32/gpio.h | 2 ++ arch/arm/mach-stm32mp/include/mach/gpio.h | 2 ++ drivers/gpio/stm32f7_gpio.c | 1 - 3 files changed, 4 insertions(+), 1 deletion(-)
arch/arm/include/asm/arch-stm32/gpio.h +2 -0
@@ -7,6 +7,8 @@#ifndef _GPIO_H_#define _GPIO_H_ +#define STM32_GPIOS_PER_BANK 16 +enum stm32_gpio_port {STM32_GPIO_PORT_A =0 , STM32_GPIO_PORT_B,
arch/arm/mach-stm32mp/include/mach/gpio.h +2 -0
@@ -8,6 +8,8 @@#define _STM32_GPIO_H_#include <asm/gpio.h> +#define STM32_GPIOS_PER_BANK 16 +enum stm32_gpio_port {STM32_GPIO_PORT_A =0 ,STM32_GPIO_PORT_B ,
drivers/gpio/stm32f7_gpio.c +0 -1
@@ -15,7 +15,6 @@#include <linux/errno.h> #include <linux/io.h> -#define STM32_GPIOS_PER_BANK 16#define MODE_BITS (gpio_pin) (gpio_pin * 2)#define MODE_BITS_MASK 3#define BSRR_BIT (gpio_pin, value) BIT(gpio_pin + (value ? 0 : 16))
Signature · 1 line
1.9.1
PATCH 3/5 gpio: stm32f7: Move STM32_GPIOS_PER_BANK into gpio.h
Quoted 4 lines · Patrice Chotard
To allow access to this define by other driver, move it into
gpio.hSigned-off-by Patrice Chotard <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181207/5c8e680b/attachment.sig>
PATCH 4/5 gpio: stm32f7: Remove CONFIG_CLK flag.
In reply to Patrice ChotardAs all STM32 SoCs supports CONFIG_CLK flag,
it becomes useless in this driver, remove it.
---
drivers/gpio/stm32f7_gpio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpio/stm32f7_gpio.c +1 -3
@@ -151,6 +151,7 @@ static int gpio_stm32_probe(struct udevice *dev)struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);struct stm32_gpio_priv *priv =dev_get_priv (dev);struct ofnode_phandle_args args; +struct clk clk;fdt_addr_t addr;const char *name;int ret;
@@ -184,8 +185,6 @@ static int gpio_stm32_probe(struct udevice *dev) (u32 *)priv->regs, uc_priv->bank_name, uc_priv->gpio_count, priv->gpio_range); -#ifdef CONFIG_CLK -struct clk clk; ret =clk_get_by_index (dev,0 , &clk);if (ret <0 )return ret;
@@ -197,7 +196,6 @@ static int gpio_stm32_probe(struct udevice *dev)return ret; }debug ("clock enabled for device %s\n" , dev->name); -#endif return 0 ; }
Signature · 1 line
1.9.1
PATCH 4/5 gpio: stm32f7: Remove CONFIG_CLK flag.
Quoted 4 lines · Patrice Chotard
As all STM32 SoCs supports
CONFIG_CLKflag,
it becomes useless in this driver, remove it.Signed-off-by Patrice Chotard <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181207/eec70d6c/attachment.sig>
PATCH 5/5 pinctrl: stm32: Update stm32_pinctrl_get_gpio_dev()
In reply to Patrice ChotardDue to gpio holes management, stm32_pinctrl_get_gpio_dev() must be updated.
stm32_pinctrl_get_gpio_dev() returns from a given pin selectors the corresponding bank gpio device and the gpio_offset inside this gpio bank.
Update also all functions which makes usage of stm32_pinctrl_get_gpio_dev.
---
drivers/pinctrl/pinctrl_stm32.c | 42 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-)
drivers/pinctrl/pinctrl_stm32.c +24 -18
@@ -28,8 +28,6 @@ struct stm32_gpio_bank {#ifndef CONFIG_SPL_BUILD -#define MAX_PIN_PER_BANK 16 -static char pin_name[PINNAME_SIZE ];#define PINMUX_MODE_COUNT 5 static const char * const pinmux_mode[PINMUX_MODE_COUNT] = {
@@ -116,12 +114,13 @@ static int stm32_pinctrl_get_pins_count(struct udevice *dev) }static struct udevice *stm32_pinctrl_get_gpio_dev (struct udevice *dev, -unsigned int selector) +unsigned int selector, +unsigned int *idx) {struct stm32_pinctrl_priv *priv =dev_get_priv (dev);struct stm32_gpio_bank *gpio_bank;struct gpio_dev_priv *uc_priv; -int first_pin =0 ; +int pin_count =0 ;if (list_empty (&priv->gpio_dev))stm32_populate_gpio_dev_list (dev);
@@ -130,11 +129,19 @@ static struct udevice *stm32_pinctrl_get_gpio_dev(struct udevice *dev,list_for_each_entry (gpio_bank, &priv->gpio_dev, list) { uc_priv =dev_get_uclass_priv (gpio_bank->gpio_dev); -if (selector < (first_pin + uc_priv->gpio_count)) -/* we found the bank */ -return gpio_bank->gpio_dev; +if (selector < (pin_count + uc_priv->gpio_count)) { +/* +* we found the bank, convert pin selector to +* gpio bank index +*/ + *idx =stm32_offset_to_index (gpio_bank->gpio_dev, + selector - pin_count); +if (*idx <0 ) +return NULL ; - first_pin += uc_priv->gpio_count; +return gpio_bank->gpio_dev; + } + pin_count += uc_priv->gpio_count; }return NULL ;
@@ -145,9 +152,10 @@ static const char *stm32_pinctrl_get_pin_name(struct udevice *dev, {struct gpio_dev_priv *uc_priv;struct udevice *gpio_dev; +unsigned int gpio_idx;/* look up for the bank which owns the requested pin */ - gpio_dev =stm32_pinctrl_get_gpio_dev (dev, selector); + gpio_dev =stm32_pinctrl_get_gpio_dev (dev, selector, &gpio_idx);if (!gpio_dev) {snprintf (pin_name,PINNAME_SIZE ,"Error" ); }else {
@@ -155,7 +163,7 @@ static const char *stm32_pinctrl_get_pin_name(struct udevice *dev,snprintf (pin_name,PINNAME_SIZE ,"%s%d" , uc_priv->bank_name, - selector %MAX_PIN_PER_BANK ); + gpio_idx); }return pin_name;
@@ -168,23 +176,21 @@ static int stm32_pinctrl_get_pin_muxing(struct udevice *dev, {struct udevice *gpio_dev;const char *label; -int gpio_pin;int mode;int af_num; +unsigned int gpio_idx;/* look up for the bank which owns the requested pin */ - gpio_dev =stm32_pinctrl_get_gpio_dev (dev, selector); + gpio_dev =stm32_pinctrl_get_gpio_dev (dev, selector, &gpio_idx);if (!gpio_dev)return -ENODEV ; -/* translate pin-controller pin number to gpio pin number */ - gpio_pin = selector %MAX_PIN_PER_BANK ; + mode =gpio_get_raw_function (gpio_dev, gpio_idx, &label); - mode =gpio_get_raw_function (gpio_dev, gpio_pin, &label); +dev_dbg (dev,"selector = %d gpio_idx = %d mode = %d\n" , + selector, gpio_idx, mode); -dev_dbg (dev,"selector = %d gpio_pin = %d mode = %d\n" , - selector, gpio_pin, mode);switch (mode) {case GPIOF_UNKNOWN :
@@ -194,7 +200,7 @@ static int stm32_pinctrl_get_pin_muxing(struct udevice *dev,snprintf (buf, size,"%s" , pinmux_mode[mode]);break ;case GPIOF_FUNC : - af_num =stm32_pinctrl_get_af (gpio_dev, gpio_pin); + af_num =stm32_pinctrl_get_af (gpio_dev, gpio_idx);snprintf (buf, size,"%s %d" , pinmux_mode[mode], af_num);break ;case GPIOF_OUTPUT :
Signature · 1 line
1.9.1
PATCH 5/5 pinctrl: stm32: Update stm32_pinctrl_get_gpio_dev()
Quoted 10 lines · Patrice Chotard
Due to gpio holes management,
stm32_pinctrl_get_gpio_dev()must be updated.
stm32_pinctrl_get_gpio_dev()returns from a given pin selectors the corresponding bank gpio device and thegpio_offsetinside this gpio bank.Update also all functions which makes usage of
stm32_pinctrl_get_gpio_dev.Signed-off-by Patrice Chotard <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181207/e8cd2761/attachment.sig>