[PATCH v4 00/16] gpio: Update and simplify the uclass API

Simon Glass sjg at chromium.org
Fri Feb 5 05:21:53 CET 2021


At present the GPIO uclass mirrors what was in U-Boot before driver model.
It works well in most cases but is becoming cumbersome with things like
pull-up/down and drive strength. In those cases it is easier for the
driver to deal with all the flags at one, rather than piece by piece.

In fact the current API does not officially have a method for adjusting
anything other than the direction flags. While set_dir_flags() and
get_dir_flags() do in fact support changing other flags, this is not
documented.

Secondly, set_dir_flags actually ORs the current flags with the new ones
so it is not possible to clear flags. It seems better to use a clr/set
interface (bit clear followed by OR) to provide more flexibility.

Finally, direction_input() and direction_output() are really just the same
thing as set_dir_flags(), with a different name. We currently use the
latter if available, failing back to the former. But it makes sense to
deprecate the old methods.

This series makes the above changes. Existing drivers are mostly left
alone, since they should continue to operate as is. The sandbox driver is
updated to add the required new tests and the x86 driver is switched over
to the new API.

The STM32 driver should be checked to make sure the open source/open drain
features still work as intended.

Changes in v4:
- Update dm_gpio_set_dir_flags() to clear direction flags first

Changes in v3:
- Drop the word 'direction' in comments also
- Drop 'dir' in 'GPIO dir flags' comment
- Start at BIT(31) for sandbox-specific flags
- Add a comment to sandbox_gpio_set_flags() about clearing GPIOD_EXT_HIGH
- Incorporate GPIOD_FLAGS_OUTPUT() changes from Patrick Delaunay
- Use bit 30 for GPIOD_EXT_DRIVEN
- Split out the log-category change to a separate patch
- Use bits 28, 29 for the new flags
- Assert that count parameter is within range
- Redo digit logic to be easier to understand
- Update function comment to explain the meaning of the digits
- Fix 'compare' typo

Changes in v2:
- Use set_flags() instead of update_flags()
- Fix 'provide' typo while we are here
- Make operation of set_flags() deterministic
- Swap newf and flags in sb_gpio_set_flags()

Simon Glass (16):
  gpio: Disable functions not used with of-platdata
  dm: gpio: Rename set_dir_flags() method to update_flags()
  dm: gpio: Rename get_dir_flags() method to get_flags()
  gpio: Rename dm_gpio_get_dir_flags() to dm_gpio_get_flags()
  gpio: Drop dm_gpio_set_dir()
  gpio: sandbox: Rename GPIO dir_flags to flags
  gpio: sandbox: Use a separate flag for the value
  gpio: sandbox: Fully separate pin value from output value
  gpio: sandbox: Make sandbox_gpio_set_flags() set all flags
  dm: gpio: Add a way to update flags
  gpio: Replace direction_input() and direction_output()
  gpio: Use an 'ops' variable everywhere
  gpio: x86: Drop the deprecated methods in intel_gpio
  gpio: sandbox: Track whether a GPIO is driven
  gpio: Define the log category in the uclass
  gpio: Add a way to read 3-way strapping pins

 arch/sandbox/include/asm/gpio.h           |  17 +-
 arch/x86/include/asm/intel_pinctrl_defs.h |   5 +
 drivers/gpio/gpio-uclass.c                | 243 ++++++++++++++------
 drivers/gpio/intel_gpio.c                 |  72 +++---
 drivers/gpio/sandbox.c                    | 138 +++++++----
 drivers/gpio/stm32_gpio.c                 |  17 +-
 drivers/pinctrl/pinctrl-stmfx.c           |  19 +-
 include/asm-generic/gpio.h                | 139 +++++++++--
 test/dm/gpio.c                            | 268 +++++++++++++++++++---
 9 files changed, 690 insertions(+), 228 deletions(-)

-- 
2.30.0.478.g8a0d178c01-goog



More information about the U-Boot mailing list