sh_pfc.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. #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_FLAG_TYPE, /* must be last */
  23. };
  24. #define SH_PFC_PIN_CFG_INPUT (1 << 0)
  25. #define SH_PFC_PIN_CFG_OUTPUT (1 << 1)
  26. #define SH_PFC_PIN_CFG_PULL_UP (1 << 2)
  27. #define SH_PFC_PIN_CFG_PULL_DOWN (1 << 3)
  28. struct sh_pfc_pin {
  29. const pinmux_enum_t enum_id;
  30. const char *name;
  31. unsigned int configs;
  32. };
  33. #define SH_PFC_PIN_GROUP(n) \
  34. { \
  35. .name = #n, \
  36. .pins = n##_pins, \
  37. .mux = n##_mux, \
  38. .nr_pins = ARRAY_SIZE(n##_pins), \
  39. }
  40. struct sh_pfc_pin_group {
  41. const char *name;
  42. const unsigned int *pins;
  43. const unsigned int *mux;
  44. unsigned int nr_pins;
  45. };
  46. #define SH_PFC_FUNCTION(n) \
  47. { \
  48. .name = #n, \
  49. .groups = n##_groups, \
  50. .nr_groups = ARRAY_SIZE(n##_groups), \
  51. }
  52. struct sh_pfc_function {
  53. const char *name;
  54. const char * const *groups;
  55. unsigned int nr_groups;
  56. };
  57. struct pinmux_func {
  58. const pinmux_enum_t enum_id;
  59. const char *name;
  60. };
  61. #define PINMUX_GPIO(gpio, data_or_mark) \
  62. [gpio] = { \
  63. .name = __stringify(gpio), \
  64. .enum_id = data_or_mark, \
  65. }
  66. #define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
  67. [gpio - (base)] = { \
  68. .name = __stringify(gpio), \
  69. .enum_id = data_or_mark, \
  70. }
  71. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  72. struct pinmux_cfg_reg {
  73. unsigned long reg, reg_width, field_width;
  74. const pinmux_enum_t *enum_ids;
  75. const unsigned long *var_field_width;
  76. };
  77. #define PINMUX_CFG_REG(name, r, r_width, f_width) \
  78. .reg = r, .reg_width = r_width, .field_width = f_width, \
  79. .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)])
  80. #define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
  81. .reg = r, .reg_width = 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. const 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;
  103. struct sh_pfc_soc_operations {
  104. int (*init)(struct sh_pfc *pfc);
  105. void (*exit)(struct sh_pfc *pfc);
  106. unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
  107. void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
  108. unsigned int bias);
  109. };
  110. struct sh_pfc_soc_info {
  111. const char *name;
  112. const struct sh_pfc_soc_operations *ops;
  113. struct pinmux_range input;
  114. struct pinmux_range output;
  115. struct pinmux_range function;
  116. const struct sh_pfc_pin *pins;
  117. unsigned int nr_pins;
  118. const struct pinmux_range *ranges;
  119. unsigned int nr_ranges;
  120. const struct sh_pfc_pin_group *groups;
  121. unsigned int nr_groups;
  122. const struct sh_pfc_function *functions;
  123. unsigned int nr_functions;
  124. const struct pinmux_func *func_gpios;
  125. unsigned int nr_func_gpios;
  126. const struct pinmux_cfg_reg *cfg_regs;
  127. const struct pinmux_data_reg *data_regs;
  128. const pinmux_enum_t *gpio_data;
  129. unsigned int gpio_data_size;
  130. const struct pinmux_irq *gpio_irq;
  131. unsigned int gpio_irq_size;
  132. unsigned long unlock_reg;
  133. };
  134. enum { GPIO_CFG_REQ, GPIO_CFG_FREE };
  135. /* helper macro for port */
  136. #define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
  137. #define PORT_10(fn, pfx, sfx) \
  138. PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
  139. PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
  140. PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
  141. PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
  142. PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
  143. #define PORT_10_REV(fn, pfx, sfx) \
  144. PORT_1(fn, pfx##9, sfx), PORT_1(fn, pfx##8, sfx), \
  145. PORT_1(fn, pfx##7, sfx), PORT_1(fn, pfx##6, sfx), \
  146. PORT_1(fn, pfx##5, sfx), PORT_1(fn, pfx##4, sfx), \
  147. PORT_1(fn, pfx##3, sfx), PORT_1(fn, pfx##2, sfx), \
  148. PORT_1(fn, pfx##1, sfx), PORT_1(fn, pfx##0, sfx)
  149. #define PORT_32(fn, pfx, sfx) \
  150. PORT_10(fn, pfx, sfx), PORT_10(fn, pfx##1, sfx), \
  151. PORT_10(fn, pfx##2, sfx), PORT_1(fn, pfx##30, sfx), \
  152. PORT_1(fn, pfx##31, sfx)
  153. #define PORT_32_REV(fn, pfx, sfx) \
  154. PORT_1(fn, pfx##31, sfx), PORT_1(fn, pfx##30, sfx), \
  155. PORT_10_REV(fn, pfx##2, sfx), PORT_10_REV(fn, pfx##1, sfx), \
  156. PORT_10_REV(fn, pfx, sfx)
  157. #define PORT_90(fn, pfx, sfx) \
  158. PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
  159. PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
  160. PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
  161. PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
  162. PORT_10(fn, pfx##9, sfx)
  163. #define _PORT_ALL(pfx, sfx) pfx##_##sfx
  164. #define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
  165. #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
  166. #define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
  167. #define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
  168. /* helper macro for pinmux_enum_t */
  169. #define PORT_DATA_IO(nr) \
  170. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  171. PORT##nr##_IN)
  172. /* helper macro for top 4 bits in PORTnCR */
  173. #define _PCRH(in, in_pd, in_pu, out) \
  174. 0, (out), (in), 0, \
  175. 0, 0, 0, 0, \
  176. 0, 0, (in_pd), 0, \
  177. 0, 0, (in_pu), 0
  178. #define PORTCR(nr, reg) \
  179. { \
  180. PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
  181. _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
  182. PORT##nr##_IN_PU, PORT##nr##_OUT), \
  183. PORT##nr##_FN0, PORT##nr##_FN1, \
  184. PORT##nr##_FN2, PORT##nr##_FN3, \
  185. PORT##nr##_FN4, PORT##nr##_FN5, \
  186. PORT##nr##_FN6, PORT##nr##_FN7 } \
  187. }
  188. #endif /* __SH_PFC_H */