pinctrl-common.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2020 TOSHIBA CORPORATION
  4. * Copyright (c) 2020 Toshiba Electronic Devices & Storage Corporation
  5. * Copyright (c) 2020 Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>
  6. */
  7. #ifndef __VISCONTI_PINCTRL_COMMON_H__
  8. #define __VISCONTI_PINCTRL_COMMON_H__
  9. struct pinctrl_pin_desc;
  10. /* PIN */
  11. #define VISCONTI_PINS(pins_name, ...) \
  12. static const unsigned int pins_name ## _pins[] = { __VA_ARGS__ }
  13. struct visconti_desc_pin {
  14. struct pinctrl_pin_desc pin;
  15. unsigned int dsel_offset;
  16. unsigned int dsel_shift;
  17. unsigned int pude_offset;
  18. unsigned int pudsel_offset;
  19. unsigned int pud_shift;
  20. };
  21. #define VISCONTI_PIN(_pin, dsel, d_sh, pude, pudsel, p_sh) \
  22. { \
  23. .pin = _pin, \
  24. .dsel_offset = dsel, \
  25. .dsel_shift = d_sh, \
  26. .pude_offset = pude, \
  27. .pudsel_offset = pudsel, \
  28. .pud_shift = p_sh, \
  29. }
  30. /* Group */
  31. #define VISCONTI_GROUPS(groups_name, ...) \
  32. static const char * const groups_name ## _grps[] = { __VA_ARGS__ }
  33. struct visconti_mux {
  34. unsigned int offset;
  35. unsigned int mask;
  36. unsigned int val;
  37. };
  38. struct visconti_pin_group {
  39. const char *name;
  40. const unsigned int *pins;
  41. unsigned int nr_pins;
  42. struct visconti_mux mux;
  43. };
  44. #define VISCONTI_PIN_GROUP(group_name, off, msk, v) \
  45. { \
  46. .name = __stringify(group_name) "_grp", \
  47. .pins = group_name ## _pins, \
  48. .nr_pins = ARRAY_SIZE(group_name ## _pins), \
  49. .mux = { \
  50. .offset = off, \
  51. .mask = msk, \
  52. .val = v, \
  53. } \
  54. }
  55. /* MUX */
  56. struct visconti_pin_function {
  57. const char *name;
  58. const char * const *groups;
  59. unsigned int nr_groups;
  60. };
  61. #define VISCONTI_PIN_FUNCTION(func) \
  62. { \
  63. .name = #func, \
  64. .groups = func ## _grps, \
  65. .nr_groups = ARRAY_SIZE(func ## _grps), \
  66. }
  67. /* chip dependent data */
  68. struct visconti_pinctrl_devdata {
  69. const struct visconti_desc_pin *pins;
  70. unsigned int nr_pins;
  71. const struct visconti_pin_group *groups;
  72. unsigned int nr_groups;
  73. const struct visconti_pin_function *functions;
  74. unsigned int nr_functions;
  75. const struct visconti_mux *gpio_mux;
  76. void (*unlock)(void __iomem *base);
  77. };
  78. int visconti_pinctrl_probe(struct platform_device *pdev,
  79. const struct visconti_pinctrl_devdata *devdata);
  80. #endif /* __VISCONTI_PINCTRL_COMMON_H__ */