sh_pfc.h 19 KB

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