sh_pfc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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. enum {
  14. PINMUX_TYPE_NONE,
  15. PINMUX_TYPE_FUNCTION,
  16. PINMUX_TYPE_GPIO,
  17. PINMUX_TYPE_OUTPUT,
  18. PINMUX_TYPE_INPUT,
  19. };
  20. #define SH_PFC_PIN_CFG_INPUT (1 << 0)
  21. #define SH_PFC_PIN_CFG_OUTPUT (1 << 1)
  22. #define SH_PFC_PIN_CFG_PULL_UP (1 << 2)
  23. #define SH_PFC_PIN_CFG_PULL_DOWN (1 << 3)
  24. #define SH_PFC_PIN_CFG_IO_VOLTAGE (1 << 4)
  25. #define SH_PFC_PIN_CFG_DRIVE_STRENGTH (1 << 5)
  26. #define SH_PFC_PIN_CFG_NO_GPIO (1 << 31)
  27. struct sh_pfc_pin {
  28. u16 pin;
  29. u16 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. /*
  47. * Using union vin_data saves memory occupied by the VIN data pins.
  48. * VIN_DATA_PIN_GROUP() is a macro used to describe the VIN pin groups
  49. * in this case.
  50. */
  51. #define VIN_DATA_PIN_GROUP(n, s) \
  52. { \
  53. .name = #n#s, \
  54. .pins = n##_pins.data##s, \
  55. .mux = n##_mux.data##s, \
  56. .nr_pins = ARRAY_SIZE(n##_pins.data##s), \
  57. }
  58. union vin_data {
  59. unsigned int data24[24];
  60. unsigned int data20[20];
  61. unsigned int data16[16];
  62. unsigned int data12[12];
  63. unsigned int data10[10];
  64. unsigned int data8[8];
  65. unsigned int data4[4];
  66. };
  67. #define SH_PFC_FUNCTION(n) \
  68. { \
  69. .name = #n, \
  70. .groups = n##_groups, \
  71. .nr_groups = ARRAY_SIZE(n##_groups), \
  72. }
  73. struct sh_pfc_function {
  74. const char *name;
  75. const char * const *groups;
  76. unsigned int nr_groups;
  77. };
  78. struct pinmux_func {
  79. u16 enum_id;
  80. const char *name;
  81. };
  82. struct pinmux_cfg_reg {
  83. u32 reg;
  84. u8 reg_width, field_width;
  85. const u16 *enum_ids;
  86. const u8 *var_field_width;
  87. };
  88. /*
  89. * Describe a config register consisting of several fields of the same width
  90. * - name: Register name (unused, for documentation purposes only)
  91. * - r: Physical register address
  92. * - r_width: Width of the register (in bits)
  93. * - f_width: Width of the fixed-width register fields (in bits)
  94. * This macro must be followed by initialization data: For each register field
  95. * (from left to right, i.e. MSB to LSB), 2^f_width enum IDs must be specified,
  96. * one for each possible combination of the register field bit values.
  97. */
  98. #define PINMUX_CFG_REG(name, r, r_width, f_width) \
  99. .reg = r, .reg_width = r_width, .field_width = f_width, \
  100. .enum_ids = (const u16 [(r_width / f_width) * (1 << f_width)])
  101. /*
  102. * Describe a config register consisting of several fields of different widths
  103. * - name: Register name (unused, for documentation purposes only)
  104. * - r: Physical register address
  105. * - r_width: Width of the register (in bits)
  106. * - var_fw0, var_fwn...: List of widths of the register fields (in bits),
  107. * From left to right (i.e. MSB to LSB)
  108. * This macro must be followed by initialization data: For each register field
  109. * (from left to right, i.e. MSB to LSB), 2^var_fwi enum IDs must be specified,
  110. * one for each possible combination of the register field bit values.
  111. */
  112. #define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
  113. .reg = r, .reg_width = r_width, \
  114. .var_field_width = (const u8 [r_width]) \
  115. { var_fw0, var_fwn, 0 }, \
  116. .enum_ids = (const u16 [])
  117. struct pinmux_drive_reg_field {
  118. u16 pin;
  119. u8 offset;
  120. u8 size;
  121. };
  122. struct pinmux_drive_reg {
  123. u32 reg;
  124. const struct pinmux_drive_reg_field fields[8];
  125. };
  126. #define PINMUX_DRIVE_REG(name, r) \
  127. .reg = r, \
  128. .fields =
  129. struct pinmux_data_reg {
  130. u32 reg;
  131. u8 reg_width;
  132. const u16 *enum_ids;
  133. };
  134. /*
  135. * Describe a data register
  136. * - name: Register name (unused, for documentation purposes only)
  137. * - r: Physical register address
  138. * - r_width: Width of the register (in bits)
  139. * This macro must be followed by initialization data: For each register bit
  140. * (from left to right, i.e. MSB to LSB), one enum ID must be specified.
  141. */
  142. #define PINMUX_DATA_REG(name, r, r_width) \
  143. .reg = r, .reg_width = r_width, \
  144. .enum_ids = (const u16 [r_width]) \
  145. struct pinmux_irq {
  146. const short *gpios;
  147. };
  148. /*
  149. * Describe the mapping from GPIOs to a single IRQ
  150. * - ids...: List of GPIOs that are mapped to the same IRQ
  151. */
  152. #define PINMUX_IRQ(ids...) \
  153. { .gpios = (const short []) { ids, -1 } }
  154. struct pinmux_range {
  155. u16 begin;
  156. u16 end;
  157. u16 force;
  158. };
  159. struct sh_pfc_bias_info {
  160. u16 pin;
  161. u16 reg : 11;
  162. u16 bit : 5;
  163. };
  164. struct sh_pfc_pin_range;
  165. struct sh_pfc {
  166. struct device *dev;
  167. const struct sh_pfc_soc_info *info;
  168. void *regs;
  169. struct sh_pfc_pin_range *ranges;
  170. unsigned int nr_ranges;
  171. unsigned int nr_gpio_pins;
  172. struct sh_pfc_chip *gpio;
  173. };
  174. struct sh_pfc_soc_operations {
  175. int (*init)(struct sh_pfc *pfc);
  176. unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
  177. void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
  178. unsigned int bias);
  179. int (*pin_to_pocctrl)(struct sh_pfc *pfc, unsigned int pin, u32 *pocctrl);
  180. };
  181. struct sh_pfc_soc_info {
  182. const char *name;
  183. const struct sh_pfc_soc_operations *ops;
  184. struct pinmux_range input;
  185. struct pinmux_range output;
  186. struct pinmux_range function;
  187. const struct sh_pfc_pin *pins;
  188. unsigned int nr_pins;
  189. const struct sh_pfc_pin_group *groups;
  190. unsigned int nr_groups;
  191. const struct sh_pfc_function *functions;
  192. unsigned int nr_functions;
  193. const struct pinmux_cfg_reg *cfg_regs;
  194. const struct pinmux_drive_reg *drive_regs;
  195. const struct pinmux_data_reg *data_regs;
  196. const u16 *pinmux_data;
  197. unsigned int pinmux_data_size;
  198. const struct pinmux_irq *gpio_irq;
  199. unsigned int gpio_irq_size;
  200. u32 unlock_reg;
  201. };
  202. u32 sh_pfc_read_reg(struct sh_pfc *pfc, u32 reg, unsigned int width);
  203. void sh_pfc_write_reg(struct sh_pfc *pfc, u32 reg, unsigned int width, u32 data);
  204. const struct sh_pfc_bias_info *
  205. sh_pfc_pin_to_bias_info(const struct sh_pfc_bias_info *info,
  206. unsigned int num, unsigned int pin);
  207. int sh_pfc_config_mux_for_gpio(struct udevice *dev, unsigned pin_selector);
  208. extern const struct sh_pfc_soc_info r8a7790_pinmux_info;
  209. extern const struct sh_pfc_soc_info r8a7791_pinmux_info;
  210. extern const struct sh_pfc_soc_info r8a7792_pinmux_info;
  211. extern const struct sh_pfc_soc_info r8a7793_pinmux_info;
  212. extern const struct sh_pfc_soc_info r8a7795_pinmux_info;
  213. extern const struct sh_pfc_soc_info r8a7796_pinmux_info;
  214. extern const struct sh_pfc_soc_info r8a77970_pinmux_info;
  215. extern const struct sh_pfc_soc_info r8a77995_pinmux_info;
  216. /* -----------------------------------------------------------------------------
  217. * Helper macros to create pin and port lists
  218. */
  219. /*
  220. * sh_pfc_soc_info pinmux_data array macros
  221. */
  222. /*
  223. * Describe generic pinmux data
  224. * - data_or_mark: *_DATA or *_MARK enum ID
  225. * - ids...: List of enum IDs to associate with data_or_mark
  226. */
  227. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  228. /*
  229. * Describe a pinmux configuration without GPIO function that needs
  230. * configuration in a Peripheral Function Select Register (IPSR)
  231. * - ipsr: IPSR field (unused, for documentation purposes only)
  232. * - fn: Function name, referring to a field in the IPSR
  233. */
  234. #define PINMUX_IPSR_NOGP(ipsr, fn) \
  235. PINMUX_DATA(fn##_MARK, FN_##fn)
  236. /*
  237. * Describe a pinmux configuration with GPIO function that needs configuration
  238. * in both a Peripheral Function Select Register (IPSR) and in a
  239. * GPIO/Peripheral Function Select Register (GPSR)
  240. * - ipsr: IPSR field
  241. * - fn: Function name, also referring to the IPSR field
  242. */
  243. #define PINMUX_IPSR_GPSR(ipsr, fn) \
  244. PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr)
  245. /*
  246. * Describe a pinmux configuration without GPIO function that needs
  247. * configuration in a Peripheral Function Select Register (IPSR), and where the
  248. * pinmux function has a representation in a Module Select Register (MOD_SEL).
  249. * - ipsr: IPSR field (unused, for documentation purposes only)
  250. * - fn: Function name, also referring to the IPSR field
  251. * - msel: Module selector
  252. */
  253. #define PINMUX_IPSR_NOGM(ipsr, fn, msel) \
  254. PINMUX_DATA(fn##_MARK, FN_##fn, FN_##msel)
  255. /*
  256. * Describe a pinmux configuration with GPIO function where the pinmux function
  257. * has no representation in a Peripheral Function Select Register (IPSR), but
  258. * instead solely depends on a group selection.
  259. * - gpsr: GPSR field
  260. * - fn: Function name, also referring to the GPSR field
  261. * - gsel: Group selector
  262. */
  263. #define PINMUX_IPSR_NOFN(gpsr, fn, gsel) \
  264. PINMUX_DATA(fn##_MARK, FN_##gpsr, FN_##gsel)
  265. /*
  266. * Describe a pinmux configuration with GPIO function that needs configuration
  267. * in both a Peripheral Function Select Register (IPSR) and a GPIO/Peripheral
  268. * Function Select Register (GPSR), and where the pinmux function has a
  269. * representation in a Module Select Register (MOD_SEL).
  270. * - ipsr: IPSR field
  271. * - fn: Function name, also referring to the IPSR field
  272. * - msel: Module selector
  273. */
  274. #define PINMUX_IPSR_MSEL(ipsr, fn, msel) \
  275. PINMUX_DATA(fn##_MARK, FN_##msel, FN_##fn, FN_##ipsr)
  276. /*
  277. * Describe a pinmux configuration for a single-function pin with GPIO
  278. * capability.
  279. * - fn: Function name
  280. */
  281. #define PINMUX_SINGLE(fn) \
  282. PINMUX_DATA(fn##_MARK, FN_##fn)
  283. /*
  284. * GP port style (32 ports banks)
  285. */
  286. #define PORT_GP_CFG_1(bank, pin, fn, sfx, cfg) \
  287. fn(bank, pin, GP_##bank##_##pin, sfx, cfg)
  288. #define PORT_GP_1(bank, pin, fn, sfx) PORT_GP_CFG_1(bank, pin, fn, sfx, 0)
  289. #define PORT_GP_CFG_4(bank, fn, sfx, cfg) \
  290. PORT_GP_CFG_1(bank, 0, fn, sfx, cfg), \
  291. PORT_GP_CFG_1(bank, 1, fn, sfx, cfg), \
  292. PORT_GP_CFG_1(bank, 2, fn, sfx, cfg), \
  293. PORT_GP_CFG_1(bank, 3, fn, sfx, cfg)
  294. #define PORT_GP_4(bank, fn, sfx) PORT_GP_CFG_4(bank, fn, sfx, 0)
  295. #define PORT_GP_CFG_6(bank, fn, sfx, cfg) \
  296. PORT_GP_CFG_4(bank, fn, sfx, cfg), \
  297. PORT_GP_CFG_1(bank, 4, fn, sfx, cfg), PORT_GP_CFG_1(bank, 5, fn, sfx, cfg)
  298. #define PORT_GP_6(bank, fn, sfx) PORT_GP_CFG_6(bank, fn, sfx, 0)
  299. #define PORT_GP_CFG_8(bank, fn, sfx, cfg) \
  300. PORT_GP_CFG_4(bank, fn, sfx, cfg), \
  301. PORT_GP_CFG_1(bank, 4, fn, sfx, cfg), \
  302. PORT_GP_CFG_1(bank, 5, fn, sfx, cfg), \
  303. PORT_GP_CFG_1(bank, 6, fn, sfx, cfg), \
  304. PORT_GP_CFG_1(bank, 7, fn, sfx, cfg)
  305. #define PORT_GP_8(bank, fn, sfx) PORT_GP_CFG_8(bank, fn, sfx, 0)
  306. #define PORT_GP_CFG_9(bank, fn, sfx, cfg) \
  307. PORT_GP_CFG_8(bank, fn, sfx, cfg), \
  308. PORT_GP_CFG_1(bank, 8, fn, sfx, cfg)
  309. #define PORT_GP_9(bank, fn, sfx) PORT_GP_CFG_9(bank, fn, sfx, 0)
  310. #define PORT_GP_CFG_10(bank, fn, sfx, cfg) \
  311. PORT_GP_CFG_9(bank, fn, sfx, cfg), \
  312. PORT_GP_CFG_1(bank, 9, fn, sfx, cfg)
  313. #define PORT_GP_10(bank, fn, sfx) PORT_GP_CFG_10(bank, fn, sfx, 0)
  314. #define PORT_GP_CFG_12(bank, fn, sfx, cfg) \
  315. PORT_GP_CFG_10(bank, fn, sfx, cfg), \
  316. PORT_GP_CFG_1(bank, 10, fn, sfx, cfg), \
  317. PORT_GP_CFG_1(bank, 11, fn, sfx, cfg)
  318. #define PORT_GP_12(bank, fn, sfx) PORT_GP_CFG_12(bank, fn, sfx, 0)
  319. #define PORT_GP_CFG_14(bank, fn, sfx, cfg) \
  320. PORT_GP_CFG_12(bank, fn, sfx, cfg), \
  321. PORT_GP_CFG_1(bank, 12, fn, sfx, cfg), \
  322. PORT_GP_CFG_1(bank, 13, fn, sfx, cfg)
  323. #define PORT_GP_14(bank, fn, sfx) PORT_GP_CFG_14(bank, fn, sfx, 0)
  324. #define PORT_GP_CFG_15(bank, fn, sfx, cfg) \
  325. PORT_GP_CFG_14(bank, fn, sfx, cfg), \
  326. PORT_GP_CFG_1(bank, 14, fn, sfx, cfg)
  327. #define PORT_GP_15(bank, fn, sfx) PORT_GP_CFG_15(bank, fn, sfx, 0)
  328. #define PORT_GP_CFG_16(bank, fn, sfx, cfg) \
  329. PORT_GP_CFG_15(bank, fn, sfx, cfg), \
  330. PORT_GP_CFG_1(bank, 15, fn, sfx, cfg)
  331. #define PORT_GP_16(bank, fn, sfx) PORT_GP_CFG_16(bank, fn, sfx, 0)
  332. #define PORT_GP_CFG_17(bank, fn, sfx, cfg) \
  333. PORT_GP_CFG_16(bank, fn, sfx, cfg), \
  334. PORT_GP_CFG_1(bank, 16, fn, sfx, cfg)
  335. #define PORT_GP_17(bank, fn, sfx) PORT_GP_CFG_17(bank, fn, sfx, 0)
  336. #define PORT_GP_CFG_18(bank, fn, sfx, cfg) \
  337. PORT_GP_CFG_17(bank, fn, sfx, cfg), \
  338. PORT_GP_CFG_1(bank, 17, fn, sfx, cfg)
  339. #define PORT_GP_18(bank, fn, sfx) PORT_GP_CFG_18(bank, fn, sfx, 0)
  340. #define PORT_GP_CFG_20(bank, fn, sfx, cfg) \
  341. PORT_GP_CFG_18(bank, fn, sfx, cfg), \
  342. PORT_GP_CFG_1(bank, 18, fn, sfx, cfg), \
  343. PORT_GP_CFG_1(bank, 19, fn, sfx, cfg)
  344. #define PORT_GP_20(bank, fn, sfx) PORT_GP_CFG_20(bank, fn, sfx, 0)
  345. #define PORT_GP_CFG_21(bank, fn, sfx, cfg) \
  346. PORT_GP_CFG_20(bank, fn, sfx, cfg), \
  347. PORT_GP_CFG_1(bank, 20, fn, sfx, cfg)
  348. #define PORT_GP_21(bank, fn, sfx) PORT_GP_CFG_21(bank, fn, sfx, 0)
  349. #define PORT_GP_CFG_22(bank, fn, sfx, cfg) \
  350. PORT_GP_CFG_18(bank, fn, sfx, cfg), \
  351. PORT_GP_CFG_1(bank, 18, fn, sfx, cfg), PORT_GP_CFG_1(bank, 19, fn, sfx, cfg), \
  352. PORT_GP_CFG_1(bank, 20, fn, sfx, cfg), PORT_GP_CFG_1(bank, 21, fn, sfx, cfg)
  353. #define PORT_GP_22(bank, fn, sfx) PORT_GP_CFG_22(bank, fn, sfx, 0)
  354. #define PORT_GP_CFG_23(bank, fn, sfx, cfg) \
  355. PORT_GP_CFG_21(bank, fn, sfx, cfg), \
  356. PORT_GP_CFG_1(bank, 21, fn, sfx, cfg), \
  357. PORT_GP_CFG_1(bank, 22, fn, sfx, cfg)
  358. #define PORT_GP_23(bank, fn, sfx) PORT_GP_CFG_23(bank, fn, sfx, 0)
  359. #define PORT_GP_CFG_24(bank, fn, sfx, cfg) \
  360. PORT_GP_CFG_23(bank, fn, sfx, cfg), \
  361. PORT_GP_CFG_1(bank, 23, fn, sfx, cfg)
  362. #define PORT_GP_24(bank, fn, sfx) PORT_GP_CFG_24(bank, fn, sfx, 0)
  363. #define PORT_GP_CFG_26(bank, fn, sfx, cfg) \
  364. PORT_GP_CFG_24(bank, fn, sfx, cfg), \
  365. PORT_GP_CFG_1(bank, 24, fn, sfx, cfg), \
  366. PORT_GP_CFG_1(bank, 25, fn, sfx, cfg)
  367. #define PORT_GP_26(bank, fn, sfx) PORT_GP_CFG_26(bank, fn, sfx, 0)
  368. #define PORT_GP_CFG_28(bank, fn, sfx, cfg) \
  369. PORT_GP_CFG_26(bank, fn, sfx, cfg), \
  370. PORT_GP_CFG_1(bank, 26, fn, sfx, cfg), \
  371. PORT_GP_CFG_1(bank, 27, fn, sfx, cfg)
  372. #define PORT_GP_28(bank, fn, sfx) PORT_GP_CFG_28(bank, fn, sfx, 0)
  373. #define PORT_GP_CFG_29(bank, fn, sfx, cfg) \
  374. PORT_GP_CFG_28(bank, fn, sfx, cfg), \
  375. PORT_GP_CFG_1(bank, 28, fn, sfx, cfg)
  376. #define PORT_GP_29(bank, fn, sfx) PORT_GP_CFG_29(bank, fn, sfx, 0)
  377. #define PORT_GP_CFG_30(bank, fn, sfx, cfg) \
  378. PORT_GP_CFG_29(bank, fn, sfx, cfg), \
  379. PORT_GP_CFG_1(bank, 29, fn, sfx, cfg)
  380. #define PORT_GP_30(bank, fn, sfx) PORT_GP_CFG_30(bank, fn, sfx, 0)
  381. #define PORT_GP_CFG_32(bank, fn, sfx, cfg) \
  382. PORT_GP_CFG_30(bank, fn, sfx, cfg), \
  383. PORT_GP_CFG_1(bank, 30, fn, sfx, cfg), \
  384. PORT_GP_CFG_1(bank, 31, fn, sfx, cfg)
  385. #define PORT_GP_32(bank, fn, sfx) PORT_GP_CFG_32(bank, fn, sfx, 0)
  386. #define PORT_GP_32_REV(bank, fn, sfx) \
  387. PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx), \
  388. PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx), \
  389. PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx), \
  390. PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx), \
  391. PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx), \
  392. PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx), \
  393. PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx), \
  394. PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx), \
  395. PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx), \
  396. PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx), \
  397. PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx), \
  398. PORT_GP_1(bank, 9, fn, sfx), PORT_GP_1(bank, 8, fn, sfx), \
  399. PORT_GP_1(bank, 7, fn, sfx), PORT_GP_1(bank, 6, fn, sfx), \
  400. PORT_GP_1(bank, 5, fn, sfx), PORT_GP_1(bank, 4, fn, sfx), \
  401. PORT_GP_1(bank, 3, fn, sfx), PORT_GP_1(bank, 2, fn, sfx), \
  402. PORT_GP_1(bank, 1, fn, sfx), PORT_GP_1(bank, 0, fn, sfx)
  403. /* GP_ALL(suffix) - Expand to a list of GP_#_#_suffix */
  404. #define _GP_ALL(bank, pin, name, sfx, cfg) name##_##sfx
  405. #define GP_ALL(str) CPU_ALL_PORT(_GP_ALL, str)
  406. /* PINMUX_GPIO_GP_ALL - Expand to a list of sh_pfc_pin entries */
  407. #define _GP_GPIO(bank, _pin, _name, sfx, cfg) \
  408. { \
  409. .pin = (bank * 32) + _pin, \
  410. .name = __stringify(_name), \
  411. .enum_id = _name##_DATA, \
  412. .configs = cfg, \
  413. }
  414. #define PINMUX_GPIO_GP_ALL() CPU_ALL_PORT(_GP_GPIO, unused)
  415. /* PINMUX_DATA_GP_ALL - Expand to a list of name_DATA, name_FN marks */
  416. #define _GP_DATA(bank, pin, name, sfx, cfg) PINMUX_DATA(name##_DATA, name##_FN)
  417. #define PINMUX_DATA_GP_ALL() CPU_ALL_PORT(_GP_DATA, unused)
  418. /*
  419. * PORT style (linear pin space)
  420. */
  421. #define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx)
  422. #define PORT_10(pn, fn, pfx, sfx) \
  423. PORT_1(pn, fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx), \
  424. PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx), \
  425. PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx), \
  426. PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx), \
  427. PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx)
  428. #define PORT_90(pn, fn, pfx, sfx) \
  429. PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \
  430. PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \
  431. PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \
  432. PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \
  433. PORT_10(pn+90, fn, pfx##9, sfx)
  434. /* PORT_ALL(suffix) - Expand to a list of PORT_#_suffix */
  435. #define _PORT_ALL(pn, pfx, sfx) pfx##_##sfx
  436. #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
  437. /* PINMUX_GPIO - Expand to a sh_pfc_pin entry */
  438. #define PINMUX_GPIO(_pin) \
  439. [GPIO_##_pin] = { \
  440. .pin = (u16)-1, \
  441. .name = __stringify(GPIO_##_pin), \
  442. .enum_id = _pin##_DATA, \
  443. }
  444. /* SH_PFC_PIN_CFG - Expand to a sh_pfc_pin entry (named PORT#) with config */
  445. #define SH_PFC_PIN_CFG(_pin, cfgs) \
  446. { \
  447. .pin = _pin, \
  448. .name = __stringify(PORT##_pin), \
  449. .enum_id = PORT##_pin##_DATA, \
  450. .configs = cfgs, \
  451. }
  452. /* SH_PFC_PIN_NAMED - Expand to a sh_pfc_pin entry with the given name */
  453. #define SH_PFC_PIN_NAMED(row, col, _name) \
  454. { \
  455. .pin = PIN_NUMBER(row, col), \
  456. .name = __stringify(PIN_##_name), \
  457. .configs = SH_PFC_PIN_CFG_NO_GPIO, \
  458. }
  459. /* SH_PFC_PIN_NAMED_CFG - Expand to a sh_pfc_pin entry with the given name */
  460. #define SH_PFC_PIN_NAMED_CFG(row, col, _name, cfgs) \
  461. { \
  462. .pin = PIN_NUMBER(row, col), \
  463. .name = __stringify(PIN_##_name), \
  464. .configs = SH_PFC_PIN_CFG_NO_GPIO | cfgs, \
  465. }
  466. /* PINMUX_DATA_ALL - Expand to a list of PORT_name_DATA, PORT_name_FN0,
  467. * PORT_name_OUT, PORT_name_IN marks
  468. */
  469. #define _PORT_DATA(pn, pfx, sfx) \
  470. PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0, \
  471. PORT##pfx##_OUT, PORT##pfx##_IN)
  472. #define PINMUX_DATA_ALL() CPU_ALL_PORT(_PORT_DATA, , unused)
  473. /* GPIO_FN(name) - Expand to a sh_pfc_pin entry for a function GPIO */
  474. #define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
  475. [gpio - (base)] = { \
  476. .name = __stringify(gpio), \
  477. .enum_id = data_or_mark, \
  478. }
  479. #define GPIO_FN(str) \
  480. PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
  481. /*
  482. * PORTnCR helper macro for SH-Mobile/R-Mobile
  483. */
  484. #define PORTCR(nr, reg) \
  485. { \
  486. PINMUX_CFG_REG_VAR("PORT" nr "CR", reg, 8, 2, 2, 1, 3) {\
  487. /* PULMD[1:0], handled by .set_bias() */ \
  488. 0, 0, 0, 0, \
  489. /* IE and OE */ \
  490. 0, PORT##nr##_OUT, PORT##nr##_IN, 0, \
  491. /* SEC, not supported */ \
  492. 0, 0, \
  493. /* PTMD[2:0] */ \
  494. PORT##nr##_FN0, PORT##nr##_FN1, \
  495. PORT##nr##_FN2, PORT##nr##_FN3, \
  496. PORT##nr##_FN4, PORT##nr##_FN5, \
  497. PORT##nr##_FN6, PORT##nr##_FN7 \
  498. } \
  499. }
  500. /*
  501. * GPIO number helper macro for R-Car
  502. */
  503. #define RCAR_GP_PIN(bank, pin) (((bank) * 32) + (pin))
  504. #endif /* __SH_PFC_H */