131-pinctrl-at91-pio4-add-support-for-fewer-lines-on-las.patch 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. From 7cb1dad7a7dfe4cfe55ebe86930dd6aef0de66b4 Mon Sep 17 00:00:00 2001
  2. From: Eugen Hristev <[email protected]>
  3. Date: Fri, 13 Nov 2020 15:24:29 +0200
  4. Subject: [PATCH 131/247] pinctrl: at91-pio4: add support for fewer lines on
  5. last PIO bank
  6. Some products, like sama7g5, do not have a full last bank of PIO lines.
  7. In this case for example, sama7g5 only has 8 lines for the PE bank.
  8. PA0-31, PB0-31, PC0-31, PD0-31, PE0-7, in total 136 lines.
  9. To cope with this situation, added a data attribute that is product dependent,
  10. to specify the number of lines of the last bank.
  11. In case this number is different from the macro ATMEL_PIO_NPINS_PER_BANK,
  12. adjust the total number of lines accordingly.
  13. This will avoid advertising 160 lines instead of the actual 136, as this
  14. product supports, and to avoid reading/writing to invalid register addresses.
  15. Signed-off-by: Eugen Hristev <[email protected]>
  16. Acked-by: Ludovic Desroches <[email protected]>
  17. Link: https://lore.kernel.org/r/[email protected]
  18. Signed-off-by: Linus Walleij <[email protected]>
  19. ---
  20. drivers/pinctrl/pinctrl-at91-pio4.c | 18 ++++++++++++++++--
  21. 1 file changed, 16 insertions(+), 2 deletions(-)
  22. --- a/drivers/pinctrl/pinctrl-at91-pio4.c
  23. +++ b/drivers/pinctrl/pinctrl-at91-pio4.c
  24. @@ -71,8 +71,15 @@
  25. /* Custom pinconf parameters */
  26. #define ATMEL_PIN_CONFIG_DRIVE_STRENGTH (PIN_CONFIG_END + 1)
  27. +/**
  28. + * struct atmel_pioctrl_data - Atmel PIO controller (pinmux + gpio) data struct
  29. + * @nbanks: number of PIO banks
  30. + * @last_bank_count: number of lines in the last bank (can be less than
  31. + * the rest of the banks).
  32. + */
  33. struct atmel_pioctrl_data {
  34. unsigned nbanks;
  35. + unsigned last_bank_count;
  36. };
  37. struct atmel_group {
  38. @@ -980,11 +987,13 @@ static const struct dev_pm_ops atmel_pct
  39. * We can have up to 16 banks.
  40. */
  41. static const struct atmel_pioctrl_data atmel_sama5d2_pioctrl_data = {
  42. - .nbanks = 4,
  43. + .nbanks = 4,
  44. + .last_bank_count = ATMEL_PIO_NPINS_PER_BANK,
  45. };
  46. static const struct atmel_pioctrl_data microchip_sama7g5_pioctrl_data = {
  47. - .nbanks = 5,
  48. + .nbanks = 5,
  49. + .last_bank_count = 8, /* sama7g5 has only PE0 to PE7 */
  50. };
  51. static const struct of_device_id atmel_pctrl_of_match[] = {
  52. @@ -1025,6 +1034,11 @@ static int atmel_pinctrl_probe(struct pl
  53. atmel_pioctrl_data = match->data;
  54. atmel_pioctrl->nbanks = atmel_pioctrl_data->nbanks;
  55. atmel_pioctrl->npins = atmel_pioctrl->nbanks * ATMEL_PIO_NPINS_PER_BANK;
  56. + /* if last bank has limited number of pins, adjust accordingly */
  57. + if (atmel_pioctrl_data->last_bank_count != ATMEL_PIO_NPINS_PER_BANK) {
  58. + atmel_pioctrl->npins -= ATMEL_PIO_NPINS_PER_BANK;
  59. + atmel_pioctrl->npins += atmel_pioctrl_data->last_bank_count;
  60. + }
  61. atmel_pioctrl->reg_base = devm_platform_ioremap_resource(pdev, 0);
  62. if (IS_ERR(atmel_pioctrl->reg_base))