sh_pfc.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * SuperH Pin Function Controller Support
  3. *
  4. * Copyright (c) 2008 Magnus Damm
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #ifndef __SH_PFC_H
  11. #define __SH_PFC_H
  12. #include <linux/bug.h>
  13. #include <linux/stringify.h>
  14. typedef unsigned short pinmux_enum_t;
  15. enum {
  16. PINMUX_TYPE_NONE,
  17. PINMUX_TYPE_FUNCTION,
  18. PINMUX_TYPE_GPIO,
  19. PINMUX_TYPE_OUTPUT,
  20. PINMUX_TYPE_INPUT,
  21. };
  22. #define SH_PFC_PIN_CFG_INPUT (1 << 0)
  23. #define SH_PFC_PIN_CFG_OUTPUT (1 << 1)
  24. #define SH_PFC_PIN_CFG_PULL_UP (1 << 2)
  25. #define SH_PFC_PIN_CFG_PULL_DOWN (1 << 3)
  26. struct sh_pfc_pin {
  27. const pinmux_enum_t enum_id;
  28. const char *name;
  29. unsigned int configs;
  30. };
  31. #define SH_PFC_PIN_GROUP(n) \
  32. { \
  33. .name = #n, \
  34. .pins = n##_pins, \
  35. .mux = n##_mux, \
  36. .nr_pins = ARRAY_SIZE(n##_pins), \
  37. }
  38. struct sh_pfc_pin_group {
  39. const char *name;
  40. const unsigned int *pins;
  41. const unsigned int *mux;
  42. unsigned int nr_pins;
  43. };
  44. #define SH_PFC_FUNCTION(n) \
  45. { \
  46. .name = #n, \
  47. .groups = n##_groups, \
  48. .nr_groups = ARRAY_SIZE(n##_groups), \
  49. }
  50. struct sh_pfc_function {
  51. const char *name;
  52. const char * const *groups;
  53. unsigned int nr_groups;
  54. };
  55. struct pinmux_func {
  56. const pinmux_enum_t enum_id;
  57. const char *name;
  58. };
  59. #define PINMUX_GPIO(gpio, data_or_mark) \
  60. [gpio] = { \
  61. .name = __stringify(gpio), \
  62. .enum_id = data_or_mark, \
  63. }
  64. #define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
  65. [gpio - (base)] = { \
  66. .name = __stringify(gpio), \
  67. .enum_id = data_or_mark, \
  68. }
  69. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  70. struct pinmux_cfg_reg {
  71. unsigned long reg, reg_width, field_width;
  72. const pinmux_enum_t *enum_ids;
  73. const unsigned long *var_field_width;
  74. };
  75. #define PINMUX_CFG_REG(name, r, r_width, f_width) \
  76. .reg = r, .reg_width = r_width, .field_width = f_width, \
  77. .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)])
  78. #define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
  79. .reg = r, .reg_width = r_width, \
  80. .var_field_width = (unsigned long [r_width]) { var_fw0, var_fwn, 0 }, \
  81. .enum_ids = (pinmux_enum_t [])
  82. struct pinmux_data_reg {
  83. unsigned long reg, reg_width;
  84. const pinmux_enum_t *enum_ids;
  85. };
  86. #define PINMUX_DATA_REG(name, r, r_width) \
  87. .reg = r, .reg_width = r_width, \
  88. .enum_ids = (pinmux_enum_t [r_width]) \
  89. struct pinmux_irq {
  90. int irq;
  91. unsigned short *gpios;
  92. };
  93. #define PINMUX_IRQ(irq_nr, ids...) \
  94. { .irq = irq_nr, .gpios = (unsigned short []) { ids, 0 } } \
  95. struct pinmux_range {
  96. pinmux_enum_t begin;
  97. pinmux_enum_t end;
  98. pinmux_enum_t force;
  99. };
  100. struct sh_pfc;
  101. struct sh_pfc_soc_operations {
  102. int (*init)(struct sh_pfc *pfc);
  103. void (*exit)(struct sh_pfc *pfc);
  104. unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
  105. void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
  106. unsigned int bias);
  107. };
  108. struct sh_pfc_soc_info {
  109. const char *name;
  110. const struct sh_pfc_soc_operations *ops;
  111. struct pinmux_range input;
  112. struct pinmux_range output;
  113. struct pinmux_range function;
  114. const struct sh_pfc_pin *pins;
  115. unsigned int nr_pins;
  116. const struct pinmux_range *ranges;
  117. unsigned int nr_ranges;
  118. const struct sh_pfc_pin_group *groups;
  119. unsigned int nr_groups;
  120. const struct sh_pfc_function *functions;
  121. unsigned int nr_functions;
  122. const struct pinmux_func *func_gpios;
  123. unsigned int nr_func_gpios;
  124. const struct pinmux_cfg_reg *cfg_regs;
  125. const struct pinmux_data_reg *data_regs;
  126. const pinmux_enum_t *gpio_data;
  127. unsigned int gpio_data_size;
  128. const struct pinmux_irq *gpio_irq;
  129. unsigned int gpio_irq_size;
  130. unsigned long unlock_reg;
  131. };
  132. /* helper macro for port */
  133. #define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
  134. #define PORT_10(fn, pfx, sfx) \
  135. PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
  136. PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
  137. PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
  138. PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
  139. PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
  140. #define PORT_10_REV(fn, pfx, sfx) \
  141. PORT_1(fn, pfx##9, sfx), PORT_1(fn, pfx##8, sfx), \
  142. PORT_1(fn, pfx##7, sfx), PORT_1(fn, pfx##6, sfx), \
  143. PORT_1(fn, pfx##5, sfx), PORT_1(fn, pfx##4, sfx), \
  144. PORT_1(fn, pfx##3, sfx), PORT_1(fn, pfx##2, sfx), \
  145. PORT_1(fn, pfx##1, sfx), PORT_1(fn, pfx##0, sfx)
  146. #define PORT_32(fn, pfx, sfx) \
  147. PORT_10(fn, pfx, sfx), PORT_10(fn, pfx##1, sfx), \
  148. PORT_10(fn, pfx##2, sfx), PORT_1(fn, pfx##30, sfx), \
  149. PORT_1(fn, pfx##31, sfx)
  150. #define PORT_32_REV(fn, pfx, sfx) \
  151. PORT_1(fn, pfx##31, sfx), PORT_1(fn, pfx##30, sfx), \
  152. PORT_10_REV(fn, pfx##2, sfx), PORT_10_REV(fn, pfx##1, sfx), \
  153. PORT_10_REV(fn, pfx, sfx)
  154. #define PORT_90(fn, pfx, sfx) \
  155. PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
  156. PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
  157. PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
  158. PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
  159. PORT_10(fn, pfx##9, sfx)
  160. #define _PORT_ALL(pfx, sfx) pfx##_##sfx
  161. #define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
  162. #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
  163. #define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
  164. #define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
  165. /* helper macro for pinmux_enum_t */
  166. #define PORT_DATA_IO(nr) \
  167. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  168. PORT##nr##_IN)
  169. /* helper macro for top 4 bits in PORTnCR */
  170. #define _PCRH(in, in_pd, in_pu, out) \
  171. 0, (out), (in), 0, \
  172. 0, 0, 0, 0, \
  173. 0, 0, (in_pd), 0, \
  174. 0, 0, (in_pu), 0
  175. #define PORTCR(nr, reg) \
  176. { \
  177. PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
  178. _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
  179. PORT##nr##_IN_PU, PORT##nr##_OUT), \
  180. PORT##nr##_FN0, PORT##nr##_FN1, \
  181. PORT##nr##_FN2, PORT##nr##_FN3, \
  182. PORT##nr##_FN4, PORT##nr##_FN5, \
  183. PORT##nr##_FN6, PORT##nr##_FN7 } \
  184. }
  185. #endif /* __SH_PFC_H */