sh_pfc.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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/pinctrl/pinconf-generic.h>
  14. #include <linux/stringify.h>
  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. #define SH_PFC_PIN_CFG_IO_VOLTAGE (1 << 4)
  27. #define SH_PFC_PIN_CFG_NO_GPIO (1 << 31)
  28. struct sh_pfc_pin {
  29. u16 pin;
  30. u16 enum_id;
  31. const char *name;
  32. unsigned int configs;
  33. };
  34. #define SH_PFC_PIN_GROUP(n) \
  35. { \
  36. .name = #n, \
  37. .pins = n##_pins, \
  38. .mux = n##_mux, \
  39. .nr_pins = ARRAY_SIZE(n##_pins), \
  40. }
  41. struct sh_pfc_pin_group {
  42. const char *name;
  43. const unsigned int *pins;
  44. const unsigned int *mux;
  45. unsigned int nr_pins;
  46. };
  47. #define SH_PFC_FUNCTION(n) \
  48. { \
  49. .name = #n, \
  50. .groups = n##_groups, \
  51. .nr_groups = ARRAY_SIZE(n##_groups), \
  52. }
  53. struct sh_pfc_function {
  54. const char *name;
  55. const char * const *groups;
  56. unsigned int nr_groups;
  57. };
  58. struct pinmux_func {
  59. u16 enum_id;
  60. const char *name;
  61. };
  62. struct pinmux_cfg_reg {
  63. u32 reg;
  64. u8 reg_width, field_width;
  65. const u16 *enum_ids;
  66. const u8 *var_field_width;
  67. };
  68. #define PINMUX_CFG_REG(name, r, r_width, f_width) \
  69. .reg = r, .reg_width = r_width, .field_width = f_width, \
  70. .enum_ids = (const u16 [(r_width / f_width) * (1 << f_width)])
  71. #define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
  72. .reg = r, .reg_width = r_width, \
  73. .var_field_width = (const u8 [r_width]) \
  74. { var_fw0, var_fwn, 0 }, \
  75. .enum_ids = (const u16 [])
  76. struct pinmux_data_reg {
  77. u32 reg;
  78. u8 reg_width;
  79. const u16 *enum_ids;
  80. };
  81. #define PINMUX_DATA_REG(name, r, r_width) \
  82. .reg = r, .reg_width = r_width, \
  83. .enum_ids = (const u16 [r_width]) \
  84. struct pinmux_irq {
  85. int irq;
  86. const short *gpios;
  87. };
  88. #ifdef CONFIG_ARCH_MULTIPLATFORM
  89. #define PINMUX_IRQ(irq_nr, ids...) \
  90. { .gpios = (const short []) { ids, -1 } }
  91. #else
  92. #define PINMUX_IRQ(irq_nr, ids...) \
  93. { .irq = irq_nr, .gpios = (const short []) { ids, -1 } }
  94. #endif
  95. struct pinmux_range {
  96. u16 begin;
  97. u16 end;
  98. u16 force;
  99. };
  100. struct sh_pfc;
  101. struct sh_pfc_soc_operations {
  102. int (*init)(struct sh_pfc *pfc);
  103. unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
  104. void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
  105. unsigned int bias);
  106. int (*get_io_voltage)(struct sh_pfc *pfc, unsigned int pin);
  107. int (*set_io_voltage)(struct sh_pfc *pfc, unsigned int pin,
  108. u16 voltage_mV);
  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 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 u16 *gpio_data;
  127. unsigned int gpio_data_size;
  128. const struct pinmux_irq *gpio_irq;
  129. unsigned int gpio_irq_size;
  130. u32 unlock_reg;
  131. };
  132. /* -----------------------------------------------------------------------------
  133. * Helper macros to create pin and port lists
  134. */
  135. /*
  136. * sh_pfc_soc_info gpio_data array macros
  137. */
  138. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  139. #define PINMUX_IPSR_NOGP(ispr, fn) \
  140. PINMUX_DATA(fn##_MARK, FN_##fn)
  141. #define PINMUX_IPSR_DATA(ipsr, fn) \
  142. PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr)
  143. #define PINMUX_IPSR_NOGM(ispr, fn, ms) \
  144. PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ms)
  145. #define PINMUX_IPSR_NOFN(ipsr, fn, ms) \
  146. PINMUX_DATA(fn##_MARK, FN_##ipsr, FN_##ms)
  147. #define PINMUX_IPSR_MSEL(ipsr, fn, ms) \
  148. PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr, FN_##ms)
  149. #define PINMUX_IPSR_MODSEL_DATA(ipsr, fn, ms) \
  150. PINMUX_DATA(fn##_MARK, FN_##ms, FN_##ipsr, FN_##fn)
  151. /*
  152. * GP port style (32 ports banks)
  153. */
  154. #define PORT_GP_1(bank, pin, fn, sfx) fn(bank, pin, GP_##bank##_##pin, sfx)
  155. #define PORT_GP_32(bank, fn, sfx) \
  156. PORT_GP_1(bank, 0, fn, sfx), PORT_GP_1(bank, 1, fn, sfx), \
  157. PORT_GP_1(bank, 2, fn, sfx), PORT_GP_1(bank, 3, fn, sfx), \
  158. PORT_GP_1(bank, 4, fn, sfx), PORT_GP_1(bank, 5, fn, sfx), \
  159. PORT_GP_1(bank, 6, fn, sfx), PORT_GP_1(bank, 7, fn, sfx), \
  160. PORT_GP_1(bank, 8, fn, sfx), PORT_GP_1(bank, 9, fn, sfx), \
  161. PORT_GP_1(bank, 10, fn, sfx), PORT_GP_1(bank, 11, fn, sfx), \
  162. PORT_GP_1(bank, 12, fn, sfx), PORT_GP_1(bank, 13, fn, sfx), \
  163. PORT_GP_1(bank, 14, fn, sfx), PORT_GP_1(bank, 15, fn, sfx), \
  164. PORT_GP_1(bank, 16, fn, sfx), PORT_GP_1(bank, 17, fn, sfx), \
  165. PORT_GP_1(bank, 18, fn, sfx), PORT_GP_1(bank, 19, fn, sfx), \
  166. PORT_GP_1(bank, 20, fn, sfx), PORT_GP_1(bank, 21, fn, sfx), \
  167. PORT_GP_1(bank, 22, fn, sfx), PORT_GP_1(bank, 23, fn, sfx), \
  168. PORT_GP_1(bank, 24, fn, sfx), PORT_GP_1(bank, 25, fn, sfx), \
  169. PORT_GP_1(bank, 26, fn, sfx), PORT_GP_1(bank, 27, fn, sfx), \
  170. PORT_GP_1(bank, 28, fn, sfx), PORT_GP_1(bank, 29, fn, sfx), \
  171. PORT_GP_1(bank, 30, fn, sfx), PORT_GP_1(bank, 31, fn, sfx)
  172. #define PORT_GP_32_REV(bank, fn, sfx) \
  173. PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx), \
  174. PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx), \
  175. PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx), \
  176. PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx), \
  177. PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx), \
  178. PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx), \
  179. PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx), \
  180. PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx), \
  181. PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx), \
  182. PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx), \
  183. PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx), \
  184. PORT_GP_1(bank, 9, fn, sfx), PORT_GP_1(bank, 8, fn, sfx), \
  185. PORT_GP_1(bank, 7, fn, sfx), PORT_GP_1(bank, 6, fn, sfx), \
  186. PORT_GP_1(bank, 5, fn, sfx), PORT_GP_1(bank, 4, fn, sfx), \
  187. PORT_GP_1(bank, 3, fn, sfx), PORT_GP_1(bank, 2, fn, sfx), \
  188. PORT_GP_1(bank, 1, fn, sfx), PORT_GP_1(bank, 0, fn, sfx)
  189. /* GP_ALL(suffix) - Expand to a list of GP_#_#_suffix */
  190. #define _GP_ALL(bank, pin, name, sfx) name##_##sfx
  191. #define GP_ALL(str) CPU_ALL_PORT(_GP_ALL, str)
  192. /* PINMUX_GPIO_GP_ALL - Expand to a list of sh_pfc_pin entries */
  193. #define _GP_GPIO(bank, _pin, _name, sfx) \
  194. { \
  195. .pin = (bank * 32) + _pin, \
  196. .name = __stringify(_name), \
  197. .enum_id = _name##_DATA, \
  198. }
  199. #define PINMUX_GPIO_GP_ALL() CPU_ALL_PORT(_GP_GPIO, unused)
  200. /* PINMUX_DATA_GP_ALL - Expand to a list of name_DATA, name_FN marks */
  201. #define _GP_DATA(bank, pin, name, sfx) PINMUX_DATA(name##_DATA, name##_FN)
  202. #define PINMUX_DATA_GP_ALL() CPU_ALL_PORT(_GP_DATA, unused)
  203. /*
  204. * PORT style (linear pin space)
  205. */
  206. #define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx)
  207. #define PORT_10(pn, fn, pfx, sfx) \
  208. PORT_1(pn, fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx), \
  209. PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx), \
  210. PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx), \
  211. PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx), \
  212. PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx)
  213. #define PORT_90(pn, fn, pfx, sfx) \
  214. PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \
  215. PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \
  216. PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \
  217. PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \
  218. PORT_10(pn+90, fn, pfx##9, sfx)
  219. /* PORT_ALL(suffix) - Expand to a list of PORT_#_suffix */
  220. #define _PORT_ALL(pn, pfx, sfx) pfx##_##sfx
  221. #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
  222. /* PINMUX_GPIO - Expand to a sh_pfc_pin entry */
  223. #define PINMUX_GPIO(_pin) \
  224. [GPIO_##_pin] = { \
  225. .pin = (u16)-1, \
  226. .name = __stringify(GPIO_##_pin), \
  227. .enum_id = _pin##_DATA, \
  228. }
  229. /* SH_PFC_PIN_CFG - Expand to a sh_pfc_pin entry (named PORT#) with config */
  230. #define SH_PFC_PIN_CFG(_pin, cfgs) \
  231. { \
  232. .pin = _pin, \
  233. .name = __stringify(PORT##_pin), \
  234. .enum_id = PORT##_pin##_DATA, \
  235. .configs = cfgs, \
  236. }
  237. /* SH_PFC_PIN_NAMED - Expand to a sh_pfc_pin entry with the given name */
  238. #define SH_PFC_PIN_NAMED(row, col, _name) \
  239. { \
  240. .pin = PIN_NUMBER(row, col), \
  241. .name = __stringify(PIN_##_name), \
  242. .configs = SH_PFC_PIN_CFG_NO_GPIO, \
  243. }
  244. /* PINMUX_DATA_ALL - Expand to a list of PORT_name_DATA, PORT_name_FN0,
  245. * PORT_name_OUT, PORT_name_IN marks
  246. */
  247. #define _PORT_DATA(pn, pfx, sfx) \
  248. PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0, \
  249. PORT##pfx##_OUT, PORT##pfx##_IN)
  250. #define PINMUX_DATA_ALL() CPU_ALL_PORT(_PORT_DATA, , unused)
  251. /* GPIO_FN(name) - Expand to a sh_pfc_pin entry for a function GPIO */
  252. #define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
  253. [gpio - (base)] = { \
  254. .name = __stringify(gpio), \
  255. .enum_id = data_or_mark, \
  256. }
  257. #define GPIO_FN(str) \
  258. PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
  259. /*
  260. * PORTnCR macro
  261. */
  262. #define PORTCR(nr, reg) \
  263. { \
  264. PINMUX_CFG_REG_VAR("PORT" nr "CR", reg, 8, 2, 2, 1, 3) {\
  265. /* PULMD[1:0], handled by .set_bias() */ \
  266. 0, 0, 0, 0, \
  267. /* IE and OE */ \
  268. 0, PORT##nr##_OUT, PORT##nr##_IN, 0, \
  269. /* SEC, not supported */ \
  270. 0, 0, \
  271. /* PTMD[2:0] */ \
  272. PORT##nr##_FN0, PORT##nr##_FN1, \
  273. PORT##nr##_FN2, PORT##nr##_FN3, \
  274. PORT##nr##_FN4, PORT##nr##_FN5, \
  275. PORT##nr##_FN6, PORT##nr##_FN7 \
  276. } \
  277. }
  278. #endif /* __SH_PFC_H */