sh_pfc.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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/stringify.h>
  13. #include <asm-generic/gpio.h>
  14. typedef unsigned short pinmux_enum_t;
  15. #define SH_PFC_MARK_INVALID ((pinmux_enum_t)-1)
  16. enum {
  17. PINMUX_TYPE_NONE,
  18. PINMUX_TYPE_FUNCTION,
  19. PINMUX_TYPE_GPIO,
  20. PINMUX_TYPE_OUTPUT,
  21. PINMUX_TYPE_INPUT,
  22. PINMUX_TYPE_INPUT_PULLUP,
  23. PINMUX_TYPE_INPUT_PULLDOWN,
  24. PINMUX_FLAG_TYPE, /* must be last */
  25. };
  26. struct sh_pfc_pin {
  27. const pinmux_enum_t enum_id;
  28. const char *name;
  29. };
  30. #define SH_PFC_PIN_GROUP(n) \
  31. { \
  32. .name = #n, \
  33. .pins = n##_pins, \
  34. .mux = n##_mux, \
  35. .nr_pins = ARRAY_SIZE(n##_pins), \
  36. }
  37. struct sh_pfc_pin_group {
  38. const char *name;
  39. const unsigned int *pins;
  40. const unsigned int *mux;
  41. unsigned int nr_pins;
  42. };
  43. #define SH_PFC_FUNCTION(n) \
  44. { \
  45. .name = #n, \
  46. .groups = n##_groups, \
  47. .nr_groups = ARRAY_SIZE(n##_groups), \
  48. }
  49. struct sh_pfc_function {
  50. const char *name;
  51. const char * const *groups;
  52. unsigned int nr_groups;
  53. };
  54. struct pinmux_func {
  55. const pinmux_enum_t enum_id;
  56. const char *name;
  57. };
  58. #define PINMUX_GPIO(gpio, data_or_mark) \
  59. [gpio] = { \
  60. .name = __stringify(gpio), \
  61. .enum_id = data_or_mark, \
  62. }
  63. #define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
  64. [gpio - (base)] = { \
  65. .name = __stringify(gpio), \
  66. .enum_id = data_or_mark, \
  67. }
  68. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  69. struct pinmux_cfg_reg {
  70. unsigned long reg, reg_width, field_width;
  71. unsigned long *cnt;
  72. pinmux_enum_t *enum_ids;
  73. 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. .cnt = (unsigned long [r_width / f_width]) {}, \
  78. .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)])
  79. #define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
  80. .reg = r, .reg_width = r_width, \
  81. .cnt = (unsigned long [r_width]) {}, \
  82. .var_field_width = (unsigned long [r_width]) { var_fw0, var_fwn, 0 }, \
  83. .enum_ids = (pinmux_enum_t [])
  84. struct pinmux_data_reg {
  85. unsigned long reg, reg_width;
  86. pinmux_enum_t *enum_ids;
  87. };
  88. #define PINMUX_DATA_REG(name, r, r_width) \
  89. .reg = r, .reg_width = r_width, \
  90. .enum_ids = (pinmux_enum_t [r_width]) \
  91. struct pinmux_irq {
  92. int irq;
  93. unsigned short *gpios;
  94. };
  95. #define PINMUX_IRQ(irq_nr, ids...) \
  96. { .irq = irq_nr, .gpios = (unsigned short []) { ids, 0 } } \
  97. struct pinmux_range {
  98. pinmux_enum_t begin;
  99. pinmux_enum_t end;
  100. pinmux_enum_t force;
  101. };
  102. struct sh_pfc_soc_info {
  103. char *name;
  104. struct pinmux_range input;
  105. struct pinmux_range input_pd;
  106. struct pinmux_range input_pu;
  107. struct pinmux_range output;
  108. struct pinmux_range function;
  109. struct sh_pfc_pin *pins;
  110. unsigned int nr_pins;
  111. const struct pinmux_range *ranges;
  112. unsigned int nr_ranges;
  113. const struct sh_pfc_pin_group *groups;
  114. unsigned int nr_groups;
  115. const struct sh_pfc_function *functions;
  116. unsigned int nr_functions;
  117. struct pinmux_func *func_gpios;
  118. unsigned int nr_func_gpios;
  119. struct pinmux_cfg_reg *cfg_regs;
  120. struct pinmux_data_reg *data_regs;
  121. pinmux_enum_t *gpio_data;
  122. unsigned int gpio_data_size;
  123. struct pinmux_irq *gpio_irq;
  124. unsigned int gpio_irq_size;
  125. unsigned long unlock_reg;
  126. };
  127. enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
  128. /* helper macro for port */
  129. #define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
  130. #define PORT_10(fn, pfx, sfx) \
  131. PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
  132. PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
  133. PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
  134. PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
  135. PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
  136. #define PORT_10_REV(fn, pfx, sfx) \
  137. PORT_1(fn, pfx##9, sfx), PORT_1(fn, pfx##8, sfx), \
  138. PORT_1(fn, pfx##7, sfx), PORT_1(fn, pfx##6, sfx), \
  139. PORT_1(fn, pfx##5, sfx), PORT_1(fn, pfx##4, sfx), \
  140. PORT_1(fn, pfx##3, sfx), PORT_1(fn, pfx##2, sfx), \
  141. PORT_1(fn, pfx##1, sfx), PORT_1(fn, pfx##0, sfx)
  142. #define PORT_32(fn, pfx, sfx) \
  143. PORT_10(fn, pfx, sfx), PORT_10(fn, pfx##1, sfx), \
  144. PORT_10(fn, pfx##2, sfx), PORT_1(fn, pfx##30, sfx), \
  145. PORT_1(fn, pfx##31, sfx)
  146. #define PORT_32_REV(fn, pfx, sfx) \
  147. PORT_1(fn, pfx##31, sfx), PORT_1(fn, pfx##30, sfx), \
  148. PORT_10_REV(fn, pfx##2, sfx), PORT_10_REV(fn, pfx##1, sfx), \
  149. PORT_10_REV(fn, pfx, sfx)
  150. #define PORT_90(fn, pfx, sfx) \
  151. PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
  152. PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
  153. PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
  154. PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
  155. PORT_10(fn, pfx##9, sfx)
  156. #define _PORT_ALL(pfx, sfx) pfx##_##sfx
  157. #define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
  158. #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
  159. #define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
  160. #define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
  161. /* helper macro for pinmux_enum_t */
  162. #define PORT_DATA_I(nr) \
  163. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN)
  164. #define PORT_DATA_I_PD(nr) \
  165. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
  166. PORT##nr##_IN, PORT##nr##_IN_PD)
  167. #define PORT_DATA_I_PU(nr) \
  168. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
  169. PORT##nr##_IN, PORT##nr##_IN_PU)
  170. #define PORT_DATA_I_PU_PD(nr) \
  171. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
  172. PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
  173. #define PORT_DATA_O(nr) \
  174. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT)
  175. #define PORT_DATA_IO(nr) \
  176. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  177. PORT##nr##_IN)
  178. #define PORT_DATA_IO_PD(nr) \
  179. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  180. PORT##nr##_IN, PORT##nr##_IN_PD)
  181. #define PORT_DATA_IO_PU(nr) \
  182. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  183. PORT##nr##_IN, PORT##nr##_IN_PU)
  184. #define PORT_DATA_IO_PU_PD(nr) \
  185. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  186. PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
  187. /* helper macro for top 4 bits in PORTnCR */
  188. #define _PCRH(in, in_pd, in_pu, out) \
  189. 0, (out), (in), 0, \
  190. 0, 0, 0, 0, \
  191. 0, 0, (in_pd), 0, \
  192. 0, 0, (in_pu), 0
  193. #define PORTCR(nr, reg) \
  194. { \
  195. PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
  196. _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
  197. PORT##nr##_IN_PU, PORT##nr##_OUT), \
  198. PORT##nr##_FN0, PORT##nr##_FN1, \
  199. PORT##nr##_FN2, PORT##nr##_FN3, \
  200. PORT##nr##_FN4, PORT##nr##_FN5, \
  201. PORT##nr##_FN6, PORT##nr##_FN7 } \
  202. }
  203. #endif /* __SH_PFC_H */