808-pinctrl-mtmips-support-requesting-different-function.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. From: Shiji Yang <[email protected]>
  2. Date: Wed, 26 Jul 2023 01:32:55 +0800
  3. Subject: [PATCH] pinctrl: mtmips: support requesting different functions for
  4. same group
  5. Sometimes pinctrl consumers may request different functions for the
  6. same pin group in different situations. This patch can help to reset
  7. the group function flag when requesting a different function.
  8. Signed-off-by: Shiji Yang <[email protected]>
  9. ---
  10. drivers/pinctrl/ralink/pinctrl-ralink.c | 21 +++++++++++++++++----
  11. 1 file changed, 17 insertions(+), 4 deletions(-)
  12. --- a/drivers/pinctrl/ralink/pinctrl-ralink.c
  13. +++ b/drivers/pinctrl/ralink/pinctrl-ralink.c
  14. @@ -123,11 +123,24 @@ static int ralink_pmx_group_enable(struc
  15. int i;
  16. int shift;
  17. - /* dont allow double use */
  18. + /*
  19. + * for the same pin group, if request a different function,
  20. + * then clear the group function flag and continue, else exit.
  21. + */
  22. if (p->groups[group].enabled) {
  23. - dev_err(p->dev, "%s is already enabled\n",
  24. - p->groups[group].name);
  25. - return 0;
  26. + for (i = 0; i < p->groups[group].func_count; i++) {
  27. + if (p->groups[group].func[i].enabled == 1) {
  28. + if (!strcmp(p->func[func]->name,
  29. + p->groups[group].func[i].name))
  30. + return 0;
  31. + p->groups[group].func[i].enabled = 0;
  32. + break;
  33. + }
  34. + }
  35. +
  36. + /* exit if request the "gpio" function again */
  37. + if (i == p->groups[group].func_count && func == 0)
  38. + return 0;
  39. }
  40. p->groups[group].enabled = 1;