Add pinmux command
Subsystems (3)
v4 cover Add pinmux command
For debug purpose, it's useful to know the pins muxing
to check if a pin is configured as a GPIO or as an alternate function and to get information about this alternate function configuration. For this purpose a new command pinmux is implemented.
This series adds:
- Add get_pin_muxing ops to UCLASS pinctrl
- Add pinmux command
- Add get_function() support to stm32 gpio driver
- Add get_pins_count() support to stm32 pinctrl driver
- Add get_pin_name() support to stm32 pinctrl driver
- Add get_pin_muxing() support to stm32 pinctrl driver
- Add pinmux command test
Changes in v4:
- Update get_pin_muxing() prototype by adding buffer and buffer's size parameters.
- Replace respectively uclass_first_device() and uclass_next_device() by uclass_first_device_err() and uclass_next_device_err()
- Update test return value of pinctrl_get_pin_muxing() due to ops get_pin_muxing() prototype update
- Move defines PINNAME_SIZE and PINMUX_SIZE into include/dm/pinctrl.h in order to be used by pinctrl driver
- Hardened test on argc value to avoid core dump during sandbox testing
- Fix check of uclass_get_device_by_name() return value, in any error case, continue with the next child.
- Use define PINNAME_SIZE from include/dm/pinctrl.h instead of driver's local one
- Update get_pin_muxing() prototype by adding buffer and buffer's size as parameters
- Update sandbox_get_pin_muxing() due to get_pin_muxing()
prototype changes
Changes in v3:
- Replace const char **buf parameter by char *buf, int size parameters for pinctrl_get_pin_muxing()
- Replace const char **buf parameter by char *buf, int size parameters for pinctrl_get_pin_name()
- Update calls to pinctrl_get_pin_name() and pinctrl_get_pin_muxing due to prototype update.
- Fix typo
Changes in v2:
- Replace pinmux_show ops which displayed the complete pin-controller muxing by get_pin_muxing ops which displays the muxing of one pin
- In order to make pin muxing display less SoC specific, use pinctrl_pins_count(), pinctrl_get_pin_name() and pinctrl_get_pin_muxing() methods instead of
previous pinctrl_pinmux_show() method.
Patrice Chotard (11):
dm: pinctrl: Add get_pin_muxing() ops
dm: pinctrl: Add pinctrl_get_pin_name and pinctrl_get_pins_count
dm: uclass: Add uclass_next_device_err() to return a valid device
dm: uclass: Add uclass_foreach_dev_probe
cmd: pinmux: Add pinmux command
pinctrl: stm32: Add get_pins_count() ops
pinctrl: stm32: Add get_pin_name() ops
pinctrl: stm32: Add get_pin_muxing() ops
gpio: stm32f7: Add ops get_function
pinctrl: sandbox: Add get_pin_muxing ops support test/py: test pinmux command
arch/sandbox/dts/test.dts | 4 + cmd/Kconfig | 8 ++ cmd/Makefile | 1 + cmd/pinmux.c | 146 +++++++++++++++++++++++++++ drivers/core/uclass.c | 13 +++ drivers/gpio/stm32f7_gpio.c | 20 ++++ drivers/pinctrl/pinctrl-sandbox.c | 18 ++++ drivers/pinctrl/pinctrl-uclass.c | 34 +++++++ drivers/pinctrl/pinctrl_stm32.c | 207 +++++++++++++++++++++++++++++++++++++- include/dm/pinctrl.h | 59 +++++++++++ include/dm/uclass.h | 28 ++++++ test/py/tests/test_pinmux.py | 62 ++++++++++++ 12 files changed, 595 insertions(+), 5 deletions(-) create mode 100644 cmd/pinmux.c create mode 100644 test/py/tests/test_pinmux.py
Signature · 1 line
1.9.1
PATCH v4 1/11 dm: pinctrl: Add get_pin_muxing() ops
Add get_pin_muxing() which allows to display the muxing of a given pin belonging to a pin-controller.
---
Changes in v4:
- Update get_pin_muxing() prototype by adding buffer and buffer's size parameters.
Changes in v3:
- Replace const char **buf parameter by char *buf, int size parameters for pinctrl_get_pin_muxing()
Changes in v2:
- Replace pinmux_show ops which displayed the complete pin-controller muxing by get_pin_muxing ops which displays the muxing of one pin
drivers/pinctrl/pinctrl-uclass.c | 11 +++++++++++ include/dm/pinctrl.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
drivers/pinctrl/pinctrl-uclass.c +11 -0
@@ -249,6 +249,17 @@ int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index)return ops->get_gpio_mux (dev, banknum, index); } +int pinctrl_get_pin_muxing (struct udevice *dev,int selector,char *buf, +int size) +{ +struct pinctrl_ops *ops =pinctrl_get_ops (dev); + +if (!ops->get_pin_muxing) +return -ENOSYS ; + +return ops->get_pin_muxing (dev, selector, buf, size); +} +/** * pinconfig_post_bind() - post binding for PINCTRL uclass * Recursively bind child nodes as pinconfig devices in case of full pinctrl.
include/dm/pinctrl.h +34 -0
@@ -66,6 +66,7 @@ struct pinconf_param {* pointing a config node. (necessary for pinctrl_full) * @set_state_simple: do needed pinctrl operations for a peripherl @periph. * (necessary for pinctrl_simple) +* @get_pin_muxing: display the muxing of a given pin. */ struct pinctrl_ops {int (*get_pins_count)(struct udevice *dev);
@@ -129,6 +130,24 @@ struct pinctrl_ops {* @return mux value (SoC-specific, e.g. 0 for input, 1 for output) */ int (*get_gpio_mux)(struct udevice *dev,int banknum,int index); + +/** +* get_pin_muxing() - show pin muxing +* +* This allows to display the muxing of a given pin. It's useful for +* debug purpose to know if a pin is configured as GPIO or as an +* alternate function and which one. +* Typically it is used by a PINCTRL driver with knowledge of the SoC +* pinctrl setup. +* +* @dev: Pinctrl device to use +* @selector: Pin selector +* @buf Pin's muxing description +* @size Pin's muxing description length +* return 0 if OK, -ve on error +*/ +int (*get_pin_muxing)(struct udevice *dev,unsigned int selector, +char *buf,int size); };#define pinctrl_get_ops (dev) ((struct pinctrl_ops *)(dev)->driver->ops)
@@ -348,4 +367,19 @@ int pinctrl_decode_pin_config(const void *blob, int node);*/ int pinctrl_get_gpio_mux (struct udevice *dev,int banknum,int index); +/** +* pinctrl_get_pin_muxing() - Returns the muxing description +* +* This allows to display the muxing description of the given pin for +* debug purpose +* +* @dev: Pinctrl device to use +* @selector Pin index within pin-controller +* @buf Pin's muxing description +* @size Pin's muxing description length +* @return 0 if OK, -ve on error +*/ +int pinctrl_get_pin_muxing (struct udevice *dev,int selector,char *buf, +int size); +#endif /* __PINCTRL_H */
Signature · 1 line
1.9.1
PATCH v4 1/11 dm: pinctrl: Add get_pin_muxing() ops
Quoted 14 lines · Patrice Chotard
Add
get_pin_muxing()which allows to display the muxing of a given pin belonging to a pin-controller.Signed-off-by Patrice Chotard <[email protected]>---
Changes in v4:
- Updateget_pin_muxing()prototype by adding buffer and buffer's size parameters.Changes in v3:
- Replace const char **buf parameter by char *buf, int size parameters forpinctrl_get_pin_muxing()
Quoted 7 lines
Changes in v2:
- Replacepinmux_showops which displayed the complete pin-controller muxing byget_pin_muxingops which displays the muxing of one pindrivers/pinctrl/pinctrl-uclass.c | 11 +++++++++++ include/dm/pinctrl.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
PATCH v4 1/11 dm: pinctrl: Add get_pin_muxing() ops
In reply to Patrice ChotardQuoted 5 lines · Patrice Chotard
Add
get_pin_muxing()which allows to display the muxing of a given pin belonging to a pin-controller.Signed-off-by Patrice Chotard <[email protected]>Reviewed-by Simon Glass <[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/20181117/3d5a0823/attachment.sig>
PATCH v4 2/11 dm: pinctrl: Add pinctrl_get_pin_name and pinctrl_get_pins_count
In reply to Patrice ChotardAdd pinctrl_get_pin_name() and pinctrl_get_pins_count() methods to obtain pin's name and pin's muxing given a pin reference.
This will be used by the new pinmux command.
---
Changes in v4: None
Changes in v3:
- Replace const char **buf parameter by char *buf, int size parameters for pinctrl_get_pin_name()
Changes in v2: None
drivers/pinctrl/pinctrl-uclass.c | 23 +++++++++++++++++++++++ include/dm/pinctrl.h | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+)
drivers/pinctrl/pinctrl-uclass.c +23 -0
@@ -249,6 +249,29 @@ int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index)return ops->get_gpio_mux (dev, banknum, index); } +int pinctrl_get_pins_count (struct udevice *dev) +{ +struct pinctrl_ops *ops =pinctrl_get_ops (dev); + +if (!ops->get_pins_count) +return -ENOSYS ; + +return ops->get_pins_count (dev); +} + +int pinctrl_get_pin_name (struct udevice *dev,int selector,char *buf, +int size) +{ +struct pinctrl_ops *ops =pinctrl_get_ops (dev); + +if (!ops->get_pin_name) +return -ENOSYS ; + +snprintf (buf, size, ops->get_pin_name (dev, selector)); + +return 0 ; +} +int pinctrl_get_pin_muxing (struct udevice *dev,int selector,char *buf,int size) {
include/dm/pinctrl.h +22 -0
@@ -382,4 +382,26 @@ int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);int pinctrl_get_pin_muxing (struct udevice *dev,int selector,char *buf,int size); +/** +* pinctrl_get_pins_count() - display pin-controller pins number +* +* This allows to know the number of pins owned by a given pin-controller +* +* @dev: Pinctrl device to use +* @return pins number if OK, -ve on error +*/ +int pinctrl_get_pins_count (struct udevice *dev); + +/** +* pinctrl_get_pin_name() - Returns the pin's name +* +* This allows to display the pin's name for debug purpose +* +* @dev: Pinctrl device to use +* @selector Pin index within pin-controller +* @buf Pin's name +* @return 0 if OK, -ve on error +*/ +int pinctrl_get_pin_name (struct udevice *dev,int selector,char *buf, +int size);#endif /* __PINCTRL_H */
Signature · 1 line
1.9.1
PATCH v4 2/11 dm: pinctrl: Add pinctrl_get_pin_name and pinctrl_get_pins_count
Quoted 7 lines · Patrice Chotard
Add
pinctrl_get_pin_name()andpinctrl_get_pins_count()methods to obtain pin's name and pin's muxing given a pin reference.This will be used by the new pinmux command.
Signed-off-by Patrice Chotard <[email protected]>Reviewed-by Simon Glass <[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/20181117/d24e7f69/attachment.sig>
PATCH v4 3/11 dm: uclass: Add uclass_next_device_err() to return a valid device
In reply to Patrice ChotardSimilarly to uclass_first_device_err(), add uclass_next_device_err() which returns an error if there are no next devices in that uclass.
---
Changes in v4: None
Changes in v3: None
Changes in v2: None
drivers/core/uclass.c | 13 +++++++++++++ include/dm/uclass.h | 12 ++++++++++++ 2 files changed, 25 insertions(+)
drivers/core/uclass.c +13 -0
@@ -562,6 +562,19 @@ int uclass_next_device(struct udevice **devp)return uclass_get_device_tail (dev, ret, devp); } +int uclass_next_device_err (struct udevice **devp) +{ +int ret; + + ret =uclass_next_device (devp); +if (ret) +return ret; +else if (!*devp) +return -ENODEV ; + +return 0 ; +} +int uclass_first_device_check (enum uclass_id id,struct udevice **devp) {int ret;
include/dm/uclass.h +12 -0
@@ -306,6 +306,18 @@ int uclass_first_device_err(enum uclass_id id, struct udevice **devp);int uclass_next_device (struct udevice **devp);/** +* uclass_next_device_err() - Get the next device in a uclass +* +* The device returned is probed if necessary, and ready for use +* +* @devp: On entry, pointer to device to lookup. On exit, returns pointer +* to the next device in the uclass if no error occurred, or -ENODEV if +* there is no next device. +* @return 0 if found, -ENODEV if not found, other -ve on error +*/ +int uclass_next_device_err (struct udevice **devp); + +/** * uclass_first_device_check() - Get the first device in a uclass * * The device returned is probed if necessary, and ready for use
Signature · 1 line
1.9.1
PATCH v4 3/11 dm: uclass: Add uclass_next_device_err() to return a valid device
Quoted 6 lines · Patrice Chotard
Similarly to
uclass_first_device_err(), adduclass_next_device_err()which returns an error if there are no next devices in that uclass.Signed-off-by Patrice Chotard <[email protected]>---
Quoted 7 lines
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/core/uclass.c | 13 +++++++++++++ include/dm/uclass.h | 12 ++++++++++++ 2 files changed, 25 insertions(+)
We probably should have something that calls it for testing purposes, but I suspect that comes in a future patch.
PATCH v4 3/11 dm: uclass: Add uclass_next_device_err() to return a valid device
In reply to Patrice ChotardQuoted 5 lines · Patrice Chotard
Similarly to
uclass_first_device_err(), adduclass_next_device_err()which returns an error if there are no next devices in that uclass.Signed-off-by Patrice Chotard <[email protected]>Reviewed-by Simon Glass <[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/20181117/2cb95c35/attachment.sig>
PATCH v4 4/11 dm: uclass: Add uclass_foreach_dev_probe
In reply to Patrice ChotardAdd uclass_foreach_dev_probe() which iterates through devices of a given uclass. Devices are probed if necessary and are ready to use.
---
Changes in v4:
- Replace respectively uclass_first_device() and uclass_next_device() by uclass_first_device_err() and uclass_next_device_err()
Changes in v3: None
Changes in v2: None
include/dm/uclass.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
include/dm/uclass.h +16 -0
@@ -391,4 +391,20 @@ int uclass_resolve_seq(struct udevice *dev);#define uclass_foreach_dev_safe (pos, next, uc) \ list_for_each_entry_safe(pos, next, &uc->dev_head, uclass_node) +/** +* uclass_foreach_dev_probe() - Helper function to iteration through devices +* of given uclass +* +* This creates a for() loop which works through the available devices in +* a uclass in order from start to end. Devices are probed if necessary, +* and ready for use. +* +* @id: Uclass ID +* @dev: struct udevice * to hold the current device. Set to NULL when there +* are no more devices. +*/ +#define uclass_foreach_dev_probe (id, dev) \ + for (int _ret = uclass_first_device_err(id, &dev); !_ret && dev; \ + _ret = uclass_next_device_err(&dev)) +#endif
Signature · 1 line
1.9.1
PATCH v4 4/11 dm: uclass: Add uclass_foreach_dev_probe
Quoted 11 lines · Patrice Chotard
Add
uclass_foreach_dev_probe()which iterates through devices of a given uclass. Devices are probed if necessary and are ready to use.Signed-off-by Patrice Chotard <[email protected]>---
Changes in v4:
- Replace respectivelyuclass_first_device()anduclass_next_device()byuclass_first_device_err()anduclass_next_device_err()
Quoted 5 lines
Changes in v3: None
Changes in v2: Noneinclude/dm/uclass.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
PATCH v4 4/11 dm: uclass: Add uclass_foreach_dev_probe
In reply to Patrice ChotardQuoted 6 lines · Patrice Chotard
Add
uclass_foreach_dev_probe()which iterates through devices of a given uclass. Devices are probed if necessary and are ready to use.Signed-off-by Patrice Chotard <[email protected]>Reviewed-by Simon Glass <[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/20181117/e065d2a3/attachment.sig>
PATCH v4 5/11 cmd: pinmux: Add pinmux command
In reply to Patrice Chotardpinmux command allows to :
- list all pin-controllers available on platforms
- select a pin-controller
- display the muxing of all pins of the current pin-controller or all pin-controllers depending of given options
cmd: pinmux: Fix pinmux command
if "pinmux status" command is used without having set dev using "pinmux dev", print pinmux usage
---
Changes in v4:
- Update test return value of pinctrl_get_pin_muxing() due to ops get_pin_muxing() prototype update
- Move defines PINNAME_SIZE and PINMUX_SIZE into include/dm/pinctrl.h in order to be used by pinctrl driver
- Hardened test on argc value to avoid core dump during sandbox testing
Changes in v3:
- Update calls to pinctrl_get_pin_name() and pinctrl_get_pin_muxing due to prototype update.
Changes in v2:
- In order to make pin muxing display less SoC specific, use pinctrl_pins_count(), pinctrl_get_pin_name() and pinctrl_get_pin_muxing() methods instead of previous pinctrl_pinmux_show() method.
cmd/Kconfig | 8 +++ cmd/Makefile | 1 + cmd/pinmux.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/dm/pinctrl.h | 3 ++ 4 files changed, 158 insertions(+) create mode 100644 cmd/pinmux.c
cmd/Kconfig +8 -0
@@ -953,6 +953,14 @@ config CMD_PCMCIA about 1990. These devices are typically removable memory or network cards using a standard 68-pin connector. +config CMD_PINMUX + bool "pinmux - show pins muxing" + default y if PINCTRL + help + Parse all available pin-controllers and show pins muxing. This + is useful for debug purpoer to check the pin muxing and to know if + a pin is configured as a GPIO or as an alternate function. + config CMD_POWEROFF bool "poweroff" help
cmd/Makefile +1 -0
@@ -104,6 +104,7 @@ ifdef CONFIG_PCI obj-$(CONFIG_CMD_PCI) += pci.o endif obj-y += pcmcia.o +obj-$(CONFIG_CMD_PINMUX) += pinmux.o obj-$(CONFIG_CMD_PXE) += pxe.o obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_CMD_QFW) += qfw.o
cmd/pinmux.c new file +146 -0
146 lines not on this page · raw message
include/dm/pinctrl.h +3 -0
@@ -6,6 +6,9 @@#ifndef __PINCTRL_H#define __PINCTRL_H +#define PINNAME_SIZE 10 +#define PINMUX_SIZE 40 +/** * struct pinconf_param - pin config parameters *
Signature · 1 line
1.9.1
PATCH v4 5/11 cmd: pinmux: Add pinmux command
Quoted 31 lines · Patrice Chotard
pinmux command allows to :
- list all pin-controllers available on platforms
- select a pin-controller
- display the muxing of all pins of the current pin-controller or all pin-controllers depending of given optionsSigned-off-by Patrice Chotard <[email protected]>cmd: pinmux: Fix pinmux command
if "pinmux status" command is used without having
set dev using "pinmux dev", print pinmux usage---
Changes in v4:
- Update test return value ofpinctrl_get_pin_muxing()due to opsget_pin_muxing()prototype update
- Move definesPINNAME_SIZEandPINMUX_SIZEintoinclude/dm/pinctrl.hin order to be used by pinctrl driver
- Hardened test on argc value to avoid core dump during sandbox testingChanges in v3:
- Update calls topinctrl_get_pin_name()andpinctrl_get_pin_muxingdue to prototype update.Changes in v2:
- In order to make pin muxing display less SoC specific, usepinctrl_pins_count(),pinctrl_get_pin_name()andpinctrl_get_pin_muxing()methods instead of previouspinctrl_pinmux_show()method.
Quoted 6 lines
cmd/Kconfig | 8 +++ cmd/Makefile | 1 + cmd/pinmux.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/dm/pinctrl.h | 3 ++ 4 files changed, 158 insertions(+) create mode 100644 cmd/pinmux.c
PATCH v4 5/11 cmd: pinmux: Add pinmux command
In reply to Patrice ChotardQuoted 6 lines · Patrice Chotard
pinmux command allows to :
- list all pin-controllers available on platforms
- select a pin-controller
- display the muxing of all pins of the current pin-controller or all pin-controllers depending of given options
Quoted 6 lines
Signed-off-by Patrice Chotard <[email protected]>cmd: pinmux: Fix pinmux command
if "pinmux status" command is used without having set dev using "pinmux dev", print pinmux usage
Reviewed-by Simon Glass <[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/20181117/72c8563b/attachment.sig>
PATCH v4 6/11 pinctrl: stm32: Add get_pins_count() ops
In reply to Patrice ChotardAdd get_pins_count ops to obtain the number of pins owns by a pin-controller.
On STM32 SoCs bindings, each pin-controller owns several gpio banks. Each GPIO bank can own up to 16 pins.
To obtain the total pins count, walk through each sub-nodes (ie GPIO banks) and sum each GPIO banks pins number. For that in probe() we build a list with each GPIO device reference found. This list will also be used with future get_pin_muxing and get_pin_name ops to speed up and optimize walk through all GPIO banks.
As this code is common to all STM32 SoCs, this code is put under SPL_BUILD compilation flag to avoid to increase SPL code size for STM32F7 which is limited to 32Ko.
---
Changes in v4:
- Fix check of uclass_get_device_by_name() return value, in any error case, continue with the next child.
Changes in v3: None
Changes in v2: None
drivers/pinctrl/pinctrl_stm32.c | 90 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-)
drivers/pinctrl/pinctrl_stm32.c +85 -5
@@ -14,6 +14,79 @@ DECLARE_GLOBAL_DATA_PTR;#define OTYPE_MSK 1#define AFR_MASK 0xF +#ifndef CONFIG_SPL_BUILD +struct stm32_pinctrl_priv { +int pinctrl_ngpios; +struct list_head gpio_dev; +}; + +struct stm32_gpio_bank { +struct udevice *gpio_dev; +struct list_head list; +}; + +static int stm32_pinctrl_get_pins_count (struct udevice *dev) +{ +struct stm32_pinctrl_priv *priv =dev_get_priv (dev); +struct gpio_dev_priv *uc_priv; +struct stm32_gpio_bank *gpio_bank; + +/* +* if get_pins_count has already been executed once on this +* pin-controller, no need to run it again +*/ +if (priv->pinctrl_ngpios) +return priv->pinctrl_ngpios; + +/* +* walk through all banks to retrieve the pin-controller +* pins number +*/ +list_for_each_entry (gpio_bank, &priv->gpio_dev, list) { + uc_priv =dev_get_uclass_priv (gpio_bank->gpio_dev); + + priv->pinctrl_ngpios += uc_priv->gpio_count; + } + +return priv->pinctrl_ngpios; +} + +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); + } + +return 0 ; +} +#endif +static int stm32_gpio_config (struct gpio_desc *desc,const struct stm32_gpio_ctl *ctl) {
@@ -182,6 +255,9 @@ static struct pinctrl_ops stm32_pinctrl_ops = {#else /* PINCTRL_FULL */ .set_state_simple = stm32_pinctrl_set_state_simple,#endif /* PINCTRL_FULL */ +#ifndef CONFIG_SPL_BUILD + .get_pins_count = stm32_pinctrl_get_pins_count, +#endif };static const struct udevice_id stm32_pinctrl_ids[] = {
@@ -195,9 +271,13 @@ static const struct udevice_id stm32_pinctrl_ids[] = { };U_BOOT_DRIVER (pinctrl_stm32) = { - .name ="pinctrl_stm32" , - .id =UCLASS_PINCTRL , - .of_match = stm32_pinctrl_ids, - .ops = &stm32_pinctrl_ops, - .bind = dm_scan_fdt_dev, + .name ="pinctrl_stm32" , + .id =UCLASS_PINCTRL , + .of_match = stm32_pinctrl_ids, + .ops = &stm32_pinctrl_ops, + .bind = dm_scan_fdt_dev, +#ifndef CONFIG_SPL_BUILD + .probe = stm32_pinctrl_probe, + .priv_auto_alloc_size =sizeof (struct stm32_pinctrl_priv ), +#endif };
Signature · 1 line
1.9.1
PATCH v4 6/11 pinctrl: stm32: Add get_pins_count() ops
Quoted 22 lines · Patrice Chotard
Add
get_pins_countops to obtain the number of pins owns by a pin-controller.
On STM32 SoCs bindings, each pin-controller owns several gpio banks. Each GPIO bank can own up to 16 pins.To obtain the total pins count, walk through each sub-nodes (ie GPIO banks) and sum each GPIO banks pins number. For that in
probe()we build a list with each GPIO device reference found. This list will also be used with futureget_pin_muxingandget_pin_nameops to speed up and optimize walk through all GPIO banks.As this code is common to all STM32 SoCs, this code is put under
SPL_BUILDcompilation flag to avoid to increase SPL code size for STM32F7 which is limited to 32Ko.Signed-off-by Patrice Chotard <[email protected]>---
Changes in v4:
- Fix check ofuclass_get_device_by_name()return value, in any error case, continue with the next child.
Quoted 5 lines
Changes in v3: None
Changes in v2: Nonedrivers/pinctrl/pinctrl_stm32.c | 90 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-)
PATCH v4 6/11 pinctrl: stm32: Add get_pins_count() ops
In reply to Patrice ChotardQuoted 11 lines · Patrice Chotard
Add
get_pins_countops to obtain the number of pins owns by a pin-controller.
On STM32 SoCs bindings, each pin-controller owns several gpio banks. Each GPIO bank can own up to 16 pins.To obtain the total pins count, walk through each sub-nodes (ie GPIO banks) and sum each GPIO banks pins number. For that in
probe()we build a list with each GPIO device reference found. This list will also be used with futureget_pin_muxingandget_pin_nameops to speed up and optimize walk through all GPIO banks.
Quoted 6 lines
As this code is common to all STM32 SoCs, this code is put under
SPL_BUILDcompilation flag to avoid to increase SPL code size for STM32F7 which is limited to 32Ko.Signed-off-by Patrice Chotard <[email protected]>Reviewed-by Simon Glass <[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/20181117/c7e3210c/attachment.sig>
PATCH v4 7/11 pinctrl: stm32: Add get_pin_name() ops
In reply to Patrice ChotardAdd get_pin_name ops to obtain a pin name given a
pin index of a specified pin-controller.
---
Changes in v4:
- Use define PINNAME_SIZE from include/dm/pinctrl.h instead of driver's local one
Changes in v3: None
Changes in v2: None
drivers/pinctrl/pinctrl_stm32.c | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
drivers/pinctrl/pinctrl_stm32.c +46 -0
@@ -25,6 +25,9 @@ struct stm32_gpio_bank {struct list_head list; }; +#define MAX_PIN_PER_BANK 16 + +static char pin_name[PINNAME_SIZE ];static int stm32_pinctrl_get_pins_count (struct udevice *dev) {struct stm32_pinctrl_priv *priv =dev_get_priv (dev);
@@ -51,6 +54,48 @@ static int stm32_pinctrl_get_pins_count(struct udevice *dev)return priv->pinctrl_ngpios; } +static struct udevice *stm32_pinctrl_get_gpio_dev (struct udevice *dev, +unsigned int selector) +{ +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 ; + +/* 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); + +if (selector < (first_pin + uc_priv->gpio_count)) +/* we found the bank */ +return gpio_bank->gpio_dev; + + first_pin += uc_priv->gpio_count; + } + +return NULL ; +} + +static const char *stm32_pinctrl_get_pin_name (struct udevice *dev, +unsigned int selector) +{ +struct gpio_dev_priv *uc_priv; +struct udevice *gpio_dev; + +/* look up for the bank which owns the requested pin */ + gpio_dev =stm32_pinctrl_get_gpio_dev (dev, selector); +if (!gpio_dev) { +snprintf (pin_name,PINNAME_SIZE ,"Error" ); + }else { + uc_priv =dev_get_uclass_priv (gpio_dev); + +snprintf (pin_name,PINNAME_SIZE ,"%s%d" , + uc_priv->bank_name, + selector %MAX_PIN_PER_BANK ); + } + +return pin_name; +}int stm32_pinctrl_probe (struct udevice *dev) {struct stm32_pinctrl_priv *priv =dev_get_priv (dev);
@@ -256,6 +301,7 @@ static struct pinctrl_ops stm32_pinctrl_ops = { .set_state_simple = stm32_pinctrl_set_state_simple,#endif /* PINCTRL_FULL */ #ifndef CONFIG_SPL_BUILD + .get_pin_name = stm32_pinctrl_get_pin_name, .get_pins_count = stm32_pinctrl_get_pins_count,#endif };
Signature · 1 line
1.9.1
PATCH v4 7/11 pinctrl: stm32: Add get_pin_name() ops
Quoted 10 lines · Patrice Chotard
Add
get_pin_nameops to obtain a pin name given a
pin index of a specified pin-controller.Signed-off-by Patrice Chotard <[email protected]>---
Changes in v4:
- Use definePINNAME_SIZEfrominclude/dm/pinctrl.hinstead of driver's local one
Quoted 6 lines
Changes in v3: None
Changes in v2: Nonedrivers/pinctrl/pinctrl_stm32.c | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
PATCH v4 7/11 pinctrl: stm32: Add get_pin_name() ops
In reply to Patrice ChotardQuoted 5 lines · Patrice Chotard
Add
get_pin_nameops to obtain a pin name given a
pin index of a specified pin-controller.Signed-off-by Patrice Chotard <[email protected]>Reviewed-by Simon Glass <[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/20181117/a8ce14e3/attachment.sig>
PATCH v4 8/11 pinctrl: stm32: Add get_pin_muxing() ops
In reply to Patrice ChotardAdd get_pin_muxing() ops to obtain the pin muxing description a given pin index.
---
Changes in v4:
- Update get_pin_muxing() prototype by adding buffer and buffer's size as parameters
Changes in v3: None
Changes in v2: None
drivers/pinctrl/pinctrl_stm32.c | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
drivers/pinctrl/pinctrl_stm32.c +71 -0
@@ -28,6 +28,29 @@ struct stm32_gpio_bank {#define MAX_PIN_PER_BANK 16static char pin_name[PINNAME_SIZE ]; +#define PINMUX_MODE_COUNT 5 +static const char *const pinmux_mode[PINMUX_MODE_COUNT ] = { +"gpio input" , +"gpio output" , +"analog" , +"unknown" , +"alt function" , +}; + +static int stm32_pinctrl_get_af (struct udevice *dev,unsigned int offset) +{ +struct stm32_gpio_priv *priv =dev_get_priv (dev); +struct stm32_gpio_regs *regs = priv->regs; +u32 af; +u32 alt_shift = (offset %8 ) *4 ; +u32 alt_index = offset /8 ; + + af = (readl (®s->afr[alt_index]) & +GENMASK (alt_shift +3 , alt_shift)) >> alt_shift; + +return af; +} +static int stm32_pinctrl_get_pins_count (struct udevice *dev) {struct stm32_pinctrl_priv *priv =dev_get_priv (dev);
@@ -96,6 +119,53 @@ static const char *stm32_pinctrl_get_pin_name(struct udevice *dev,return pin_name; } + +static int stm32_pinctrl_get_pin_muxing (struct udevice *dev, +unsigned int selector, +char *buf, +int size) +{ +struct udevice *gpio_dev; +const char *label; +int gpio_pin; +int mode; +int af_num; + +/* look up for the bank which owns the requested pin */ + gpio_dev =stm32_pinctrl_get_gpio_dev (dev, selector); + +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_pin, &label); + +dev_dbg (dev,"selector = %d gpio_pin = %d mode = %d\n" , + selector, gpio_pin, mode); + +switch (mode) { +case GPIOF_UNKNOWN : +/* should never happen */ +return -EINVAL ; +case GPIOF_UNUSED : +snprintf (buf, size,"%s" , pinmux_mode[mode]); +break ; +case GPIOF_FUNC : + af_num =stm32_pinctrl_get_af (gpio_dev, gpio_pin); +snprintf (buf, size,"%s %d" , pinmux_mode[mode], af_num); +break ; +case GPIOF_OUTPUT : +case GPIOF_INPUT : +snprintf (buf, size,"%s %s" , + pinmux_mode[mode], label ? label :"" ); +break ; + } + +return 0 ; +} +int stm32_pinctrl_probe (struct udevice *dev) {struct stm32_pinctrl_priv *priv =dev_get_priv (dev);
@@ -303,6 +373,7 @@ static struct pinctrl_ops stm32_pinctrl_ops = {#ifndef CONFIG_SPL_BUILD .get_pin_name = stm32_pinctrl_get_pin_name, .get_pins_count = stm32_pinctrl_get_pins_count, + .get_pin_muxing = stm32_pinctrl_get_pin_muxing,#endif };
Signature · 1 line
1.9.1
PATCH v4 8/11 pinctrl: stm32: Add get_pin_muxing() ops
Quoted 10 lines · Patrice Chotard
Add
get_pin_muxing()ops to obtain the pin muxing description a given pin index.Signed-off-by Patrice Chotard <[email protected]>---
Changes in v4:
- Updateget_pin_muxing()prototype by adding buffer and buffer's size as parameters
Quoted 5 lines
Changes in v3: None
Changes in v2: Nonedrivers/pinctrl/pinctrl_stm32.c | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
PATCH v4 8/11 pinctrl: stm32: Add get_pin_muxing() ops
In reply to Patrice ChotardQuoted 5 lines · Patrice Chotard
Add
get_pin_muxing()ops to obtain the pin muxing description a given pin index.Signed-off-by Patrice Chotard <[email protected]>Reviewed-by Simon Glass <[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/20181117/9fcc8326/attachment.sig>
PATCH v4 9/11 gpio: stm32f7: Add ops get_function
In reply to Patrice ChotardThis patch adds gpio get_function ops support.
This function reports the state of a gpio.
---
Changes in v4: None
Changes in v3: None
Changes in v2: None
drivers/gpio/stm32f7_gpio.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/gpio/stm32f7_gpio.c +20 -0
@@ -65,11 +65,31 @@ static int stm32_gpio_set_value(struct udevice *dev, unsigned offset, int value)return 0 ; } +static int stm32_gpio_get_function (struct udevice *dev,unsigned int offset) +{ +struct stm32_gpio_priv *priv =dev_get_priv (dev); +struct stm32_gpio_regs *regs = priv->regs; +int bits_index =MODE_BITS (offset); +int mask =MODE_BITS_MASK << bits_index; +u32 mode; + + mode = (readl (®s->moder) & mask) >> bits_index; +if (mode ==STM32_GPIO_MODE_OUT ) +return GPIOF_OUTPUT ; +if (mode ==STM32_GPIO_MODE_IN ) +return GPIOF_INPUT ; +if (mode ==STM32_GPIO_MODE_AN ) +return GPIOF_UNUSED ; + +return GPIOF_FUNC ; +} +static const struct dm_gpio_ops gpio_stm32_ops = { .direction_input = stm32_gpio_direction_input, .direction_output = stm32_gpio_direction_output, .get_value = stm32_gpio_get_value, .set_value = stm32_gpio_set_value, + .get_function = stm32_gpio_get_function, };static int gpio_stm32_probe (struct udevice *dev)
Signature · 1 line
1.9.1
PATCH v4 9/11 gpio: stm32f7: Add ops get_function
Quoted 6 lines · Patrice Chotard
This patch adds gpio
get_functionops support.
This function reports the state of a gpio.Signed-off-by Christophe Kerello <[email protected]>Reviewed-by Simon Glass <[email protected]>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/20181117/6da93f66/attachment.sig>
PATCH v4 10/11 pinctrl: sandbox: Add get_pin_muxing ops support
In reply to Patrice ChotardAdd get_pin_mux ops support to display the pin muxing description of the sandbox_pins[]
---
Changes in v4: None
Changes in v3: None
Changes in v2: None
drivers/pinctrl/pinctrl-sandbox.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/pinctrl/pinctrl-sandbox.c +18 -0
@@ -17,6 +17,14 @@ static const char * const sandbox_pins[] = {"W1" }; +static const char *const sandbox_pins_muxing[] = { +"I2C SCL" , +"I2C SDA" , +"Uart TX" , +"Uart RX" , +"1-wire gpio" , +}; +static const char *const sandbox_groups[] = {"i2c" ,"serial_a" ,
@@ -56,6 +64,15 @@ static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector)return sandbox_pins[selector]; } +static int sandbox_get_pin_muxing (struct udevice *dev, +unsigned int selector, +char *buf,int size) +{ +snprintf (buf, size,"%s" , sandbox_pins_muxing[selector]); + +return 0 ; +} +static int sandbox_get_groups_count (struct udevice *dev) {return ARRAY_SIZE (sandbox_groups);
@@ -123,6 +140,7 @@ static int sandbox_pinconf_group_set(struct udevice *dev,const struct pinctrl_ops sandbox_pinctrl_ops = { .get_pins_count = sandbox_get_pins_count, .get_pin_name = sandbox_get_pin_name, + .get_pin_muxing = sandbox_get_pin_muxing, .get_groups_count = sandbox_get_groups_count, .get_group_name = sandbox_get_group_name, .get_functions_count = sandbox_get_functions_count,
Signature · 1 line
1.9.1
PATCH v4 10/11 pinctrl: sandbox: Add get_pin_muxing ops support
Quoted 4 lines · Patrice Chotard
Add
get_pin_muxops support to display the pin muxing description of the sandbox_pins[]Signed-off-by Patrice Chotard <[email protected]>
Quoted 9 lines
---
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/pinctrl/pinctrl-sandbox.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
PATCH v4 10/11 pinctrl: sandbox: Add get_pin_muxing ops support
In reply to Patrice ChotardQuoted 5 lines · Patrice Chotard
Add
get_pin_muxops support to display the pin muxing description of the sandbox_pins[]Signed-off-by Patrice Chotard <[email protected]>Reviewed-by Simon Glass <[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/20181117/42920563/attachment.sig>
PATCH v4 11/11 test/py: test pinmux command
In reply to Patrice ChotardAdd pinmux test which test the following commands:
- pinmux list
- pinmux dev
- pinmux status
---
Changes in v4:
- Update sandbox_get_pin_muxing() due to get_pin_muxing() prototype changes
Changes in v3:
- Fix typo
Changes in v2: None
arch/sandbox/dts/test.dts | 4 +++ test/py/tests/test_pinmux.py | 62 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 test/py/tests/test_pinmux.py
arch/sandbox/dts/test.dts +4 -0
@@ -712,6 +712,10 @@ sandbox_tee { compatible = "sandbox,tee"; }; + + pinctrl { + compatible = "sandbox,pinctrl"; + }; }; #include "sandbox_pmic.dtsi"
test/py/tests/test_pinmux.py new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 11/11 test/py: test pinmux command
Quoted 15 lines · Patrice Chotard
Add pinmux test which test the following commands:
- pinmux list
- pinmux dev
- pinmux statusSigned-off-by Patrice Chotard <[email protected]>---
Changes in v4:
- Updatesandbox_get_pin_muxing()due toget_pin_muxing()prototype changesChanges in v3:
- Fix typo
Quoted 6 lines
Changes in v2: None
arch/sandbox/dts/test.dts | 4 +++ test/py/tests/test_pinmux.py | 62 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 test/py/tests/test_pinmux.py
Nice!
PATCH v4 11/11 test/py: test pinmux command
In reply to Patrice ChotardQuoted 7 lines · Patrice Chotard
Add pinmux test which test the following commands:
- pinmux list
- pinmux dev
- pinmux statusSigned-off-by Patrice Chotard <[email protected]>Reviewed-by Simon Glass <[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/20181117/1376f7d6/attachment.sig>