0051-gpio-axp-Add-support-for-getting-the-pin-function.patch 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. From 37e19d9b8a23c88413dd845dbb3dd58dd3636a6d Mon Sep 17 00:00:00 2001
  2. From: Samuel Holland <[email protected]>
  3. Date: Sat, 28 Aug 2021 00:36:33 -0500
  4. Subject: [PATCH 51/90] gpio: axp: Add support for getting the pin function
  5. Implement the .get_function operation, so the gpio command can report
  6. the current function. Since the GPIOF_FUNC (versus GPIOF_UNUSED) mux
  7. values vary among the PMICs, report all non-GPIO mux values as UNKNOWN.
  8. Signed-off-by: Samuel Holland <[email protected]>
  9. ---
  10. drivers/gpio/axp_gpio.c | 19 +++++++++++++++++++
  11. 1 file changed, 19 insertions(+)
  12. --- a/drivers/gpio/axp_gpio.c
  13. +++ b/drivers/gpio/axp_gpio.c
  14. @@ -39,6 +39,24 @@ static int axp_gpio_get_value(struct ude
  15. return !!(ret & BIT(desc->status_offset + pin));
  16. }
  17. +static int axp_gpio_get_function(struct udevice *dev, unsigned pin)
  18. +{
  19. + const struct axp_gpio_desc *desc = dev_get_priv(dev);
  20. + int ret;
  21. +
  22. + ret = pmic_reg_read(dev->parent, desc->pins[pin]);
  23. + if (ret < 0)
  24. + return ret;
  25. +
  26. + ret &= AXP_GPIO_CTRL_MASK;
  27. + if (ret == desc->input_mux)
  28. + return GPIOF_INPUT;
  29. + if (ret == AXP_GPIO_CTRL_OUTPUT_HIGH || ret == AXP_GPIO_CTRL_OUTPUT_LOW)
  30. + return GPIOF_OUTPUT;
  31. +
  32. + return GPIOF_UNKNOWN;
  33. +}
  34. +
  35. static int axp_gpio_set_flags(struct udevice *dev, unsigned pin, ulong flags)
  36. {
  37. const struct axp_gpio_desc *desc = dev_get_priv(dev);
  38. @@ -60,6 +78,7 @@ static int axp_gpio_set_flags(struct ude
  39. static const struct dm_gpio_ops axp_gpio_ops = {
  40. .get_value = axp_gpio_get_value,
  41. + .get_function = axp_gpio_get_function,
  42. .xlate = gpio_xlate_offs_flags,
  43. .set_flags = axp_gpio_set_flags,
  44. };