sh_pfc.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * SuperH Pin Function Controller Support
  4. *
  5. * Copyright (c) 2008 Magnus Damm
  6. */
  7. #ifndef __SH_PFC_H
  8. #define __SH_PFC_H
  9. #include <linux/stringify.h>
  10. enum {
  11. PINMUX_TYPE_NONE,
  12. PINMUX_TYPE_FUNCTION,
  13. PINMUX_TYPE_GPIO,
  14. PINMUX_TYPE_OUTPUT,
  15. PINMUX_TYPE_INPUT,
  16. };
  17. #define SH_PFC_PIN_NONE U16_MAX
  18. #define SH_PFC_PIN_CFG_INPUT (1 << 0)
  19. #define SH_PFC_PIN_CFG_OUTPUT (1 << 1)
  20. #define SH_PFC_PIN_CFG_PULL_UP (1 << 2)
  21. #define SH_PFC_PIN_CFG_PULL_DOWN (1 << 3)
  22. #define SH_PFC_PIN_CFG_PULL_UP_DOWN (SH_PFC_PIN_CFG_PULL_UP | \
  23. SH_PFC_PIN_CFG_PULL_DOWN)
  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_VOLTAGE_18_33 (0 << 6)
  27. #define SH_PFC_PIN_VOLTAGE_25_33 (1 << 6)
  28. #define SH_PFC_PIN_VOLTAGE_18_25 (2 << 6)
  29. #define SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 (SH_PFC_PIN_CFG_IO_VOLTAGE | \
  30. SH_PFC_PIN_VOLTAGE_18_33)
  31. #define SH_PFC_PIN_CFG_IO_VOLTAGE_25_33 (SH_PFC_PIN_CFG_IO_VOLTAGE | \
  32. SH_PFC_PIN_VOLTAGE_25_33)
  33. #define SH_PFC_PIN_CFG_IO_VOLTAGE_18_25 (SH_PFC_PIN_CFG_IO_VOLTAGE | \
  34. SH_PFC_PIN_VOLTAGE_18_25)
  35. #define SH_PFC_PIN_CFG_NO_GPIO (1 << 31)
  36. struct sh_pfc_pin {
  37. const char *name;
  38. unsigned int configs;
  39. u16 pin;
  40. u16 enum_id;
  41. };
  42. #define SH_PFC_PIN_GROUP_ALIAS(alias, _name) { \
  43. .name = #alias, \
  44. .pins = _name##_pins, \
  45. .mux = _name##_mux, \
  46. .nr_pins = ARRAY_SIZE(_name##_pins) + \
  47. BUILD_BUG_ON_ZERO(sizeof(_name##_pins) != sizeof(_name##_mux)), \
  48. }
  49. #define SH_PFC_PIN_GROUP(name) SH_PFC_PIN_GROUP_ALIAS(name, name)
  50. /*
  51. * Define a pin group referring to a subset of an array of pins.
  52. */
  53. #define SH_PFC_PIN_GROUP_SUBSET(_name, data, first, n) { \
  54. .name = #_name, \
  55. .pins = data##_pins + first, \
  56. .mux = data##_mux + first, \
  57. .nr_pins = n + \
  58. BUILD_BUG_ON_ZERO(first + n > ARRAY_SIZE(data##_pins)) + \
  59. BUILD_BUG_ON_ZERO(first + n > ARRAY_SIZE(data##_mux)), \
  60. }
  61. /*
  62. * Define a pin group for the data pins of a resizable bus.
  63. * An optional 'suffix' argument is accepted, to be used when the same group
  64. * can appear on a different set of pins.
  65. */
  66. #define BUS_DATA_PIN_GROUP(base, n, ...) \
  67. SH_PFC_PIN_GROUP_SUBSET(base##n##__VA_ARGS__, base##__VA_ARGS__, 0, n)
  68. struct sh_pfc_pin_group {
  69. const char *name;
  70. const unsigned int *pins;
  71. const unsigned int *mux;
  72. unsigned int nr_pins;
  73. };
  74. #define SH_PFC_FUNCTION(n) { \
  75. .name = #n, \
  76. .groups = n##_groups, \
  77. .nr_groups = ARRAY_SIZE(n##_groups), \
  78. }
  79. struct sh_pfc_function {
  80. const char *name;
  81. const char * const *groups;
  82. unsigned int nr_groups;
  83. };
  84. struct pinmux_func {
  85. u16 enum_id;
  86. const char *name;
  87. };
  88. struct pinmux_cfg_reg {
  89. u32 reg;
  90. u8 reg_width, field_width;
  91. #ifdef DEBUG
  92. u16 nr_enum_ids; /* for variable width regs only */
  93. #define SET_NR_ENUM_IDS(n) .nr_enum_ids = n,
  94. #else
  95. #define SET_NR_ENUM_IDS(n)
  96. #endif
  97. const u16 *enum_ids;
  98. const s8 *var_field_width;
  99. };
  100. #define GROUP(...) __VA_ARGS__
  101. /*
  102. * Describe a config register consisting of several fields of the same width
  103. * - name: Register name (unused, for documentation purposes only)
  104. * - r: Physical register address
  105. * - r_width: Width of the register (in bits)
  106. * - f_width: Width of the fixed-width register fields (in bits)
  107. * - ids: For each register field (from left to right, i.e. MSB to LSB),
  108. * 2^f_width enum IDs must be specified, one for each possible
  109. * combination of the register field bit values, all wrapped using
  110. * the GROUP() macro.
  111. */
  112. #define PINMUX_CFG_REG(name, r, r_width, f_width, ids) \
  113. .reg = r, .reg_width = r_width, \
  114. .field_width = f_width + BUILD_BUG_ON_ZERO(r_width % f_width) + \
  115. BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \
  116. (r_width / f_width) << f_width), \
  117. .enum_ids = (const u16 [(r_width / f_width) << f_width]) { ids }
  118. /*
  119. * Describe a config register consisting of several fields of different widths
  120. * - name: Register name (unused, for documentation purposes only)
  121. * - r: Physical register address
  122. * - r_width: Width of the register (in bits)
  123. * - f_widths: List of widths of the register fields (in bits), from left
  124. * to right (i.e. MSB to LSB), wrapped using the GROUP() macro.
  125. * Reserved fields are indicated by negating the field width.
  126. * - ids: For each non-reserved register field (from left to right, i.e. MSB
  127. * to LSB), 2^f_widths[i] enum IDs must be specified, one for each
  128. * possible combination of the register field bit values, all wrapped
  129. * using the GROUP() macro.
  130. */
  131. #define PINMUX_CFG_REG_VAR(name, r, r_width, f_widths, ids) \
  132. .reg = r, .reg_width = r_width, \
  133. .var_field_width = (const s8 []) { f_widths, 0 }, \
  134. SET_NR_ENUM_IDS(sizeof((const u16 []) { ids }) / sizeof(u16)) \
  135. .enum_ids = (const u16 []) { ids }
  136. struct pinmux_drive_reg_field {
  137. u16 pin;
  138. u8 offset;
  139. u8 size;
  140. };
  141. struct pinmux_drive_reg {
  142. u32 reg;
  143. const struct pinmux_drive_reg_field fields[10];
  144. };
  145. #define PINMUX_DRIVE_REG(name, r) \
  146. .reg = r, \
  147. .fields =
  148. struct pinmux_bias_reg { /* At least one of puen/pud must exist */
  149. u32 puen; /* Pull-enable or pull-up control register */
  150. u32 pud; /* Pull-up/down or pull-down control register */
  151. const u16 pins[32];
  152. };
  153. #define PINMUX_BIAS_REG(name1, r1, name2, r2) \
  154. .puen = r1, \
  155. .pud = r2, \
  156. .pins =
  157. struct pinmux_ioctrl_reg {
  158. u32 reg;
  159. };
  160. struct pinmux_data_reg {
  161. u32 reg;
  162. u8 reg_width;
  163. const u16 *enum_ids;
  164. };
  165. /*
  166. * Describe a data register
  167. * - name: Register name (unused, for documentation purposes only)
  168. * - r: Physical register address
  169. * - r_width: Width of the register (in bits)
  170. * - ids: For each register bit (from left to right, i.e. MSB to LSB), one
  171. * enum ID must be specified, all wrapped using the GROUP() macro.
  172. */
  173. #define PINMUX_DATA_REG(name, r, r_width, ids) \
  174. .reg = r, .reg_width = r_width + \
  175. BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \
  176. r_width), \
  177. .enum_ids = (const u16 [r_width]) { ids }
  178. struct pinmux_irq {
  179. const short *gpios;
  180. };
  181. /*
  182. * Describe the mapping from GPIOs to a single IRQ
  183. * - ids...: List of GPIOs that are mapped to the same IRQ
  184. */
  185. #define PINMUX_IRQ(ids...) { \
  186. .gpios = (const short []) { ids, -1 } \
  187. }
  188. struct pinmux_range {
  189. u16 begin;
  190. u16 end;
  191. u16 force;
  192. };
  193. struct sh_pfc_window {
  194. phys_addr_t phys;
  195. void __iomem *virt;
  196. unsigned long size;
  197. };
  198. struct sh_pfc_pin_range;
  199. struct sh_pfc {
  200. struct device *dev;
  201. const struct sh_pfc_soc_info *info;
  202. void *regs;
  203. struct sh_pfc_pin_range *ranges;
  204. unsigned int nr_ranges;
  205. unsigned int nr_gpio_pins;
  206. struct sh_pfc_chip *gpio;
  207. };
  208. struct sh_pfc_soc_operations {
  209. int (*init)(struct sh_pfc *pfc);
  210. unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
  211. void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
  212. unsigned int bias);
  213. int (*pin_to_pocctrl)(unsigned int pin, u32 *pocctrl);
  214. int (*pin_to_portcr)(unsigned int pin);
  215. };
  216. struct sh_pfc_soc_info {
  217. const char *name;
  218. const struct sh_pfc_soc_operations *ops;
  219. struct pinmux_range input;
  220. struct pinmux_range output;
  221. struct pinmux_range function;
  222. const struct sh_pfc_pin *pins;
  223. unsigned int nr_pins;
  224. const struct sh_pfc_pin_group *groups;
  225. unsigned int nr_groups;
  226. const struct sh_pfc_function *functions;
  227. unsigned int nr_functions;
  228. const struct pinmux_cfg_reg *cfg_regs;
  229. const struct pinmux_drive_reg *drive_regs;
  230. const struct pinmux_bias_reg *bias_regs;
  231. const struct pinmux_ioctrl_reg *ioctrl_regs;
  232. const struct pinmux_data_reg *data_regs;
  233. const u16 *pinmux_data;
  234. unsigned int pinmux_data_size;
  235. u32 unlock_reg; /* can be literal address or mask */
  236. };
  237. u32 sh_pfc_read(struct sh_pfc *pfc, u32 reg);
  238. void sh_pfc_write(struct sh_pfc *pfc, u32 reg, u32 data);
  239. extern const struct sh_pfc_soc_info emev2_pinmux_info;
  240. extern const struct sh_pfc_soc_info r8a73a4_pinmux_info;
  241. extern const struct sh_pfc_soc_info r8a7740_pinmux_info;
  242. extern const struct sh_pfc_soc_info r8a7742_pinmux_info;
  243. extern const struct sh_pfc_soc_info r8a7743_pinmux_info;
  244. extern const struct sh_pfc_soc_info r8a7744_pinmux_info;
  245. extern const struct sh_pfc_soc_info r8a7745_pinmux_info;
  246. extern const struct sh_pfc_soc_info r8a77470_pinmux_info;
  247. extern const struct sh_pfc_soc_info r8a774a1_pinmux_info;
  248. extern const struct sh_pfc_soc_info r8a774b1_pinmux_info;
  249. extern const struct sh_pfc_soc_info r8a774c0_pinmux_info;
  250. extern const struct sh_pfc_soc_info r8a774e1_pinmux_info;
  251. extern const struct sh_pfc_soc_info r8a7778_pinmux_info;
  252. extern const struct sh_pfc_soc_info r8a7779_pinmux_info;
  253. extern const struct sh_pfc_soc_info r8a7790_pinmux_info;
  254. extern const struct sh_pfc_soc_info r8a7791_pinmux_info;
  255. extern const struct sh_pfc_soc_info r8a7792_pinmux_info;
  256. extern const struct sh_pfc_soc_info r8a7793_pinmux_info;
  257. extern const struct sh_pfc_soc_info r8a7794_pinmux_info;
  258. extern const struct sh_pfc_soc_info r8a77950_pinmux_info;
  259. extern const struct sh_pfc_soc_info r8a77951_pinmux_info;
  260. extern const struct sh_pfc_soc_info r8a77960_pinmux_info;
  261. extern const struct sh_pfc_soc_info r8a77961_pinmux_info;
  262. extern const struct sh_pfc_soc_info r8a77965_pinmux_info;
  263. extern const struct sh_pfc_soc_info r8a77970_pinmux_info;
  264. extern const struct sh_pfc_soc_info r8a77980_pinmux_info;
  265. extern const struct sh_pfc_soc_info r8a77990_pinmux_info;
  266. extern const struct sh_pfc_soc_info r8a77995_pinmux_info;
  267. extern const struct sh_pfc_soc_info r8a779a0_pinmux_info;
  268. extern const struct sh_pfc_soc_info r8a779f0_pinmux_info;
  269. extern const struct sh_pfc_soc_info r8a779g0_pinmux_info;
  270. /* -----------------------------------------------------------------------------
  271. * Helper macros to create pin and port lists
  272. */
  273. /*
  274. * sh_pfc_soc_info pinmux_data array macros
  275. */
  276. /*
  277. * Describe generic pinmux data
  278. * - data_or_mark: *_DATA or *_MARK enum ID
  279. * - ids...: List of enum IDs to associate with data_or_mark
  280. */
  281. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  282. /*
  283. * Describe a pinmux configuration without GPIO function that needs
  284. * configuration in a Peripheral Function Select Register (IPSR)
  285. * - ipsr: IPSR field (unused, for documentation purposes only)
  286. * - fn: Function name, referring to a field in the IPSR
  287. */
  288. #define PINMUX_IPSR_NOGP(ipsr, fn) \
  289. PINMUX_DATA(fn##_MARK, FN_##fn)
  290. /*
  291. * Describe a pinmux configuration with GPIO function that needs configuration
  292. * in both a Peripheral Function Select Register (IPSR) and in a
  293. * GPIO/Peripheral Function Select Register (GPSR)
  294. * - ipsr: IPSR field
  295. * - fn: Function name, also referring to the IPSR field
  296. */
  297. #define PINMUX_IPSR_GPSR(ipsr, fn) \
  298. PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr)
  299. /*
  300. * Describe a pinmux configuration without GPIO function that needs
  301. * configuration in a Peripheral Function Select Register (IPSR), and where the
  302. * pinmux function has a representation in a Module Select Register (MOD_SEL).
  303. * - ipsr: IPSR field (unused, for documentation purposes only)
  304. * - fn: Function name, also referring to the IPSR field
  305. * - msel: Module selector
  306. */
  307. #define PINMUX_IPSR_NOGM(ipsr, fn, msel) \
  308. PINMUX_DATA(fn##_MARK, FN_##fn, FN_##msel)
  309. /*
  310. * Describe a pinmux configuration with GPIO function where the pinmux function
  311. * has no representation in a Peripheral Function Select Register (IPSR), but
  312. * instead solely depends on a group selection.
  313. * - gpsr: GPSR field
  314. * - fn: Function name, also referring to the GPSR field
  315. * - gsel: Group selector
  316. */
  317. #define PINMUX_IPSR_NOFN(gpsr, fn, gsel) \
  318. PINMUX_DATA(fn##_MARK, FN_##gpsr, FN_##gsel)
  319. /*
  320. * Describe a pinmux configuration with GPIO function that needs configuration
  321. * in both a Peripheral Function Select Register (IPSR) and a GPIO/Peripheral
  322. * Function Select Register (GPSR), and where the pinmux function has a
  323. * representation in a Module Select Register (MOD_SEL).
  324. * - ipsr: IPSR field
  325. * - fn: Function name, also referring to the IPSR field
  326. * - msel: Module selector
  327. */
  328. #define PINMUX_IPSR_MSEL(ipsr, fn, msel) \
  329. PINMUX_DATA(fn##_MARK, FN_##msel, FN_##fn, FN_##ipsr)
  330. /*
  331. * Describe a pinmux configuration similar to PINMUX_IPSR_MSEL, but with
  332. * an additional select register that controls physical multiplexing
  333. * with another pin.
  334. * - ipsr: IPSR field
  335. * - fn: Function name, also referring to the IPSR field
  336. * - psel: Physical multiplexing selector
  337. * - msel: Module selector
  338. */
  339. #define PINMUX_IPSR_PHYS_MSEL(ipsr, fn, psel, msel) \
  340. PINMUX_DATA(fn##_MARK, FN_##psel, FN_##msel, FN_##fn, FN_##ipsr)
  341. /*
  342. * Describe a pinmux configuration in which a pin is physically multiplexed
  343. * with other pins.
  344. * - ipsr: IPSR field
  345. * - fn: Function name
  346. * - psel: Physical multiplexing selector
  347. */
  348. #define PINMUX_IPSR_PHYS(ipsr, fn, psel) \
  349. PINMUX_DATA(fn##_MARK, FN_##psel, FN_##ipsr)
  350. /*
  351. * Describe a pinmux configuration for a single-function pin with GPIO
  352. * capability.
  353. * - fn: Function name
  354. */
  355. #define PINMUX_SINGLE(fn) \
  356. PINMUX_DATA(fn##_MARK, FN_##fn)
  357. /*
  358. * GP port style (32 ports banks)
  359. */
  360. #define PORT_GP_CFG_1(bank, pin, fn, sfx, cfg) \
  361. fn(bank, pin, GP_##bank##_##pin, sfx, cfg)
  362. #define PORT_GP_1(bank, pin, fn, sfx) PORT_GP_CFG_1(bank, pin, fn, sfx, 0)
  363. #define PORT_GP_CFG_2(bank, fn, sfx, cfg) \
  364. PORT_GP_CFG_1(bank, 0, fn, sfx, cfg), \
  365. PORT_GP_CFG_1(bank, 1, fn, sfx, cfg)
  366. #define PORT_GP_2(bank, fn, sfx) PORT_GP_CFG_2(bank, fn, sfx, 0)
  367. #define PORT_GP_CFG_4(bank, fn, sfx, cfg) \
  368. PORT_GP_CFG_2(bank, fn, sfx, cfg), \
  369. PORT_GP_CFG_1(bank, 2, fn, sfx, cfg), \
  370. PORT_GP_CFG_1(bank, 3, fn, sfx, cfg)
  371. #define PORT_GP_4(bank, fn, sfx) PORT_GP_CFG_4(bank, fn, sfx, 0)
  372. #define PORT_GP_CFG_6(bank, fn, sfx, cfg) \
  373. PORT_GP_CFG_4(bank, fn, sfx, cfg), \
  374. PORT_GP_CFG_1(bank, 4, fn, sfx, cfg), \
  375. PORT_GP_CFG_1(bank, 5, fn, sfx, cfg)
  376. #define PORT_GP_6(bank, fn, sfx) PORT_GP_CFG_6(bank, fn, sfx, 0)
  377. #define PORT_GP_CFG_7(bank, fn, sfx, cfg) \
  378. PORT_GP_CFG_6(bank, fn, sfx, cfg), \
  379. PORT_GP_CFG_1(bank, 6, fn, sfx, cfg)
  380. #define PORT_GP_7(bank, fn, sfx) PORT_GP_CFG_7(bank, fn, sfx, 0)
  381. #define PORT_GP_CFG_8(bank, fn, sfx, cfg) \
  382. PORT_GP_CFG_7(bank, fn, sfx, cfg), \
  383. PORT_GP_CFG_1(bank, 7, fn, sfx, cfg)
  384. #define PORT_GP_8(bank, fn, sfx) PORT_GP_CFG_8(bank, fn, sfx, 0)
  385. #define PORT_GP_CFG_9(bank, fn, sfx, cfg) \
  386. PORT_GP_CFG_8(bank, fn, sfx, cfg), \
  387. PORT_GP_CFG_1(bank, 8, fn, sfx, cfg)
  388. #define PORT_GP_9(bank, fn, sfx) PORT_GP_CFG_9(bank, fn, sfx, 0)
  389. #define PORT_GP_CFG_10(bank, fn, sfx, cfg) \
  390. PORT_GP_CFG_9(bank, fn, sfx, cfg), \
  391. PORT_GP_CFG_1(bank, 9, fn, sfx, cfg)
  392. #define PORT_GP_10(bank, fn, sfx) PORT_GP_CFG_10(bank, fn, sfx, 0)
  393. #define PORT_GP_CFG_11(bank, fn, sfx, cfg) \
  394. PORT_GP_CFG_10(bank, fn, sfx, cfg), \
  395. PORT_GP_CFG_1(bank, 10, fn, sfx, cfg)
  396. #define PORT_GP_11(bank, fn, sfx) PORT_GP_CFG_11(bank, fn, sfx, 0)
  397. #define PORT_GP_CFG_12(bank, fn, sfx, cfg) \
  398. PORT_GP_CFG_11(bank, fn, sfx, cfg), \
  399. PORT_GP_CFG_1(bank, 11, fn, sfx, cfg)
  400. #define PORT_GP_12(bank, fn, sfx) PORT_GP_CFG_12(bank, fn, sfx, 0)
  401. #define PORT_GP_CFG_13(bank, fn, sfx, cfg) \
  402. PORT_GP_CFG_12(bank, fn, sfx, cfg), \
  403. PORT_GP_CFG_1(bank, 12, fn, sfx, cfg)
  404. #define PORT_GP_13(bank, fn, sfx) PORT_GP_CFG_13(bank, fn, sfx, 0)
  405. #define PORT_GP_CFG_14(bank, fn, sfx, cfg) \
  406. PORT_GP_CFG_13(bank, fn, sfx, cfg), \
  407. PORT_GP_CFG_1(bank, 13, fn, sfx, cfg)
  408. #define PORT_GP_14(bank, fn, sfx) PORT_GP_CFG_14(bank, fn, sfx, 0)
  409. #define PORT_GP_CFG_15(bank, fn, sfx, cfg) \
  410. PORT_GP_CFG_14(bank, fn, sfx, cfg), \
  411. PORT_GP_CFG_1(bank, 14, fn, sfx, cfg)
  412. #define PORT_GP_15(bank, fn, sfx) PORT_GP_CFG_15(bank, fn, sfx, 0)
  413. #define PORT_GP_CFG_16(bank, fn, sfx, cfg) \
  414. PORT_GP_CFG_15(bank, fn, sfx, cfg), \
  415. PORT_GP_CFG_1(bank, 15, fn, sfx, cfg)
  416. #define PORT_GP_16(bank, fn, sfx) PORT_GP_CFG_16(bank, fn, sfx, 0)
  417. #define PORT_GP_CFG_17(bank, fn, sfx, cfg) \
  418. PORT_GP_CFG_16(bank, fn, sfx, cfg), \
  419. PORT_GP_CFG_1(bank, 16, fn, sfx, cfg)
  420. #define PORT_GP_17(bank, fn, sfx) PORT_GP_CFG_17(bank, fn, sfx, 0)
  421. #define PORT_GP_CFG_18(bank, fn, sfx, cfg) \
  422. PORT_GP_CFG_17(bank, fn, sfx, cfg), \
  423. PORT_GP_CFG_1(bank, 17, fn, sfx, cfg)
  424. #define PORT_GP_18(bank, fn, sfx) PORT_GP_CFG_18(bank, fn, sfx, 0)
  425. #define PORT_GP_CFG_19(bank, fn, sfx, cfg) \
  426. PORT_GP_CFG_18(bank, fn, sfx, cfg), \
  427. PORT_GP_CFG_1(bank, 18, fn, sfx, cfg)
  428. #define PORT_GP_19(bank, fn, sfx) PORT_GP_CFG_19(bank, fn, sfx, 0)
  429. #define PORT_GP_CFG_20(bank, fn, sfx, cfg) \
  430. PORT_GP_CFG_19(bank, fn, sfx, cfg), \
  431. PORT_GP_CFG_1(bank, 19, fn, sfx, cfg)
  432. #define PORT_GP_20(bank, fn, sfx) PORT_GP_CFG_20(bank, fn, sfx, 0)
  433. #define PORT_GP_CFG_21(bank, fn, sfx, cfg) \
  434. PORT_GP_CFG_20(bank, fn, sfx, cfg), \
  435. PORT_GP_CFG_1(bank, 20, fn, sfx, cfg)
  436. #define PORT_GP_21(bank, fn, sfx) PORT_GP_CFG_21(bank, fn, sfx, 0)
  437. #define PORT_GP_CFG_22(bank, fn, sfx, cfg) \
  438. PORT_GP_CFG_21(bank, fn, sfx, cfg), \
  439. PORT_GP_CFG_1(bank, 21, fn, sfx, cfg)
  440. #define PORT_GP_22(bank, fn, sfx) PORT_GP_CFG_22(bank, fn, sfx, 0)
  441. #define PORT_GP_CFG_23(bank, fn, sfx, cfg) \
  442. PORT_GP_CFG_22(bank, fn, sfx, cfg), \
  443. PORT_GP_CFG_1(bank, 22, fn, sfx, cfg)
  444. #define PORT_GP_23(bank, fn, sfx) PORT_GP_CFG_23(bank, fn, sfx, 0)
  445. #define PORT_GP_CFG_24(bank, fn, sfx, cfg) \
  446. PORT_GP_CFG_23(bank, fn, sfx, cfg), \
  447. PORT_GP_CFG_1(bank, 23, fn, sfx, cfg)
  448. #define PORT_GP_24(bank, fn, sfx) PORT_GP_CFG_24(bank, fn, sfx, 0)
  449. #define PORT_GP_CFG_25(bank, fn, sfx, cfg) \
  450. PORT_GP_CFG_24(bank, fn, sfx, cfg), \
  451. PORT_GP_CFG_1(bank, 24, fn, sfx, cfg)
  452. #define PORT_GP_25(bank, fn, sfx) PORT_GP_CFG_25(bank, fn, sfx, 0)
  453. #define PORT_GP_CFG_26(bank, fn, sfx, cfg) \
  454. PORT_GP_CFG_25(bank, fn, sfx, cfg), \
  455. PORT_GP_CFG_1(bank, 25, fn, sfx, cfg)
  456. #define PORT_GP_26(bank, fn, sfx) PORT_GP_CFG_26(bank, fn, sfx, 0)
  457. #define PORT_GP_CFG_27(bank, fn, sfx, cfg) \
  458. PORT_GP_CFG_26(bank, fn, sfx, cfg), \
  459. PORT_GP_CFG_1(bank, 26, fn, sfx, cfg)
  460. #define PORT_GP_27(bank, fn, sfx) PORT_GP_CFG_27(bank, fn, sfx, 0)
  461. #define PORT_GP_CFG_28(bank, fn, sfx, cfg) \
  462. PORT_GP_CFG_27(bank, fn, sfx, cfg), \
  463. PORT_GP_CFG_1(bank, 27, fn, sfx, cfg)
  464. #define PORT_GP_28(bank, fn, sfx) PORT_GP_CFG_28(bank, fn, sfx, 0)
  465. #define PORT_GP_CFG_29(bank, fn, sfx, cfg) \
  466. PORT_GP_CFG_28(bank, fn, sfx, cfg), \
  467. PORT_GP_CFG_1(bank, 28, fn, sfx, cfg)
  468. #define PORT_GP_29(bank, fn, sfx) PORT_GP_CFG_29(bank, fn, sfx, 0)
  469. #define PORT_GP_CFG_30(bank, fn, sfx, cfg) \
  470. PORT_GP_CFG_29(bank, fn, sfx, cfg), \
  471. PORT_GP_CFG_1(bank, 29, fn, sfx, cfg)
  472. #define PORT_GP_30(bank, fn, sfx) PORT_GP_CFG_30(bank, fn, sfx, 0)
  473. #define PORT_GP_CFG_31(bank, fn, sfx, cfg) \
  474. PORT_GP_CFG_30(bank, fn, sfx, cfg), \
  475. PORT_GP_CFG_1(bank, 30, fn, sfx, cfg)
  476. #define PORT_GP_31(bank, fn, sfx) PORT_GP_CFG_31(bank, fn, sfx, 0)
  477. #define PORT_GP_CFG_32(bank, fn, sfx, cfg) \
  478. PORT_GP_CFG_31(bank, fn, sfx, cfg), \
  479. PORT_GP_CFG_1(bank, 31, fn, sfx, cfg)
  480. #define PORT_GP_32(bank, fn, sfx) PORT_GP_CFG_32(bank, fn, sfx, 0)
  481. #define PORT_GP_32_REV(bank, fn, sfx) \
  482. PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx), \
  483. PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx), \
  484. PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx), \
  485. PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx), \
  486. PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx), \
  487. PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx), \
  488. PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx), \
  489. PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx), \
  490. PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx), \
  491. PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx), \
  492. PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx), \
  493. PORT_GP_1(bank, 9, fn, sfx), PORT_GP_1(bank, 8, fn, sfx), \
  494. PORT_GP_1(bank, 7, fn, sfx), PORT_GP_1(bank, 6, fn, sfx), \
  495. PORT_GP_1(bank, 5, fn, sfx), PORT_GP_1(bank, 4, fn, sfx), \
  496. PORT_GP_1(bank, 3, fn, sfx), PORT_GP_1(bank, 2, fn, sfx), \
  497. PORT_GP_1(bank, 1, fn, sfx), PORT_GP_1(bank, 0, fn, sfx)
  498. /* GP_ALL(suffix) - Expand to a list of GP_#_#_suffix */
  499. #define _GP_ALL(bank, pin, name, sfx, cfg) name##_##sfx
  500. #define GP_ALL(str) CPU_ALL_GP(_GP_ALL, str)
  501. /* PINMUX_GPIO_GP_ALL - Expand to a list of sh_pfc_pin entries */
  502. #define _GP_GPIO(bank, _pin, _name, sfx, cfg) { \
  503. .pin = (bank * 32) + _pin, \
  504. .name = __stringify(_name), \
  505. .enum_id = _name##_DATA, \
  506. .configs = cfg, \
  507. }
  508. #define PINMUX_GPIO_GP_ALL() CPU_ALL_GP(_GP_GPIO, unused)
  509. /* PINMUX_DATA_GP_ALL - Expand to a list of name_DATA, name_FN marks */
  510. #define _GP_DATA(bank, pin, name, sfx, cfg) PINMUX_DATA(name##_DATA, name##_FN)
  511. #define PINMUX_DATA_GP_ALL() CPU_ALL_GP(_GP_DATA, unused)
  512. /*
  513. * GP_ASSIGN_LAST() - Expand to an enum definition for the last GP pin
  514. *
  515. * The largest GP pin index is obtained by taking the size of a union,
  516. * containing one array per GP pin, sized by the corresponding pin index.
  517. * As the fields in the CPU_ALL_GP() macro definition are separated by commas,
  518. * while the members of a union must be terminated by semicolons, the commas
  519. * are absorbed by wrapping them inside dummy attributes.
  520. */
  521. #define _GP_ENTRY(bank, pin, name, sfx, cfg) \
  522. deprecated)); char name[(bank * 32) + pin] __attribute__((deprecated
  523. #define GP_ASSIGN_LAST() \
  524. GP_LAST = sizeof(union { \
  525. char dummy[0] __attribute__((deprecated, \
  526. CPU_ALL_GP(_GP_ENTRY, unused), \
  527. deprecated)); \
  528. })
  529. /*
  530. * PORT style (linear pin space)
  531. */
  532. #define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx)
  533. #define PORT_10(pn, fn, pfx, sfx) \
  534. PORT_1(pn, fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx), \
  535. PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx), \
  536. PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx), \
  537. PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx), \
  538. PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx)
  539. #define PORT_90(pn, fn, pfx, sfx) \
  540. PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \
  541. PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \
  542. PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \
  543. PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \
  544. PORT_10(pn+90, fn, pfx##9, sfx)
  545. /* PORT_ALL(suffix) - Expand to a list of PORT_#_suffix */
  546. #define _PORT_ALL(pn, pfx, sfx) pfx##_##sfx
  547. #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
  548. /* PINMUX_GPIO - Expand to a sh_pfc_pin entry */
  549. #define PINMUX_GPIO(_pin) \
  550. [GPIO_##_pin] = { \
  551. .pin = (u16)-1, \
  552. .name = __stringify(GPIO_##_pin), \
  553. .enum_id = _pin##_DATA, \
  554. }
  555. /* SH_PFC_PIN_CFG - Expand to a sh_pfc_pin entry (named PORT#) with config */
  556. #define SH_PFC_PIN_CFG(_pin, cfgs) { \
  557. .pin = _pin, \
  558. .name = __stringify(PORT##_pin), \
  559. .enum_id = PORT##_pin##_DATA, \
  560. .configs = cfgs, \
  561. }
  562. /* PINMUX_DATA_ALL - Expand to a list of PORT_name_DATA, PORT_name_FN0,
  563. * PORT_name_OUT, PORT_name_IN marks
  564. */
  565. #define _PORT_DATA(pn, pfx, sfx) \
  566. PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0, \
  567. PORT##pfx##_OUT, PORT##pfx##_IN)
  568. #define PINMUX_DATA_ALL() CPU_ALL_PORT(_PORT_DATA, , unused)
  569. /*
  570. * PORT_ASSIGN_LAST() - Expand to an enum definition for the last PORT pin
  571. *
  572. * The largest PORT pin index is obtained by taking the size of a union,
  573. * containing one array per PORT pin, sized by the corresponding pin index.
  574. * As the fields in the CPU_ALL_PORT() macro definition are separated by
  575. * commas, while the members of a union must be terminated by semicolons, the
  576. * commas are absorbed by wrapping them inside dummy attributes.
  577. */
  578. #define _PORT_ENTRY(pn, pfx, sfx) \
  579. deprecated)); char pfx[pn] __attribute__((deprecated
  580. #define PORT_ASSIGN_LAST() \
  581. PORT_LAST = sizeof(union { \
  582. char dummy[0] __attribute__((deprecated, \
  583. CPU_ALL_PORT(_PORT_ENTRY, PORT, unused), \
  584. deprecated)); \
  585. })
  586. /* GPIO_FN(name) - Expand to a sh_pfc_pin entry for a function GPIO */
  587. #define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
  588. [gpio - (base)] = { \
  589. .name = __stringify(gpio), \
  590. .enum_id = data_or_mark, \
  591. }
  592. #define GPIO_FN(str) \
  593. PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
  594. /*
  595. * Pins not associated with a GPIO port
  596. */
  597. #define PIN_NOGP_CFG(pin, name, fn, cfg) fn(pin, name, cfg)
  598. #define PIN_NOGP(pin, name, fn) fn(pin, name, 0)
  599. /* NOGP_ALL - Expand to a list of PIN_id */
  600. #define _NOGP_ALL(pin, name, cfg) PIN_##pin
  601. #define NOGP_ALL() CPU_ALL_NOGP(_NOGP_ALL)
  602. /* PINMUX_NOGP_ALL - Expand to a list of sh_pfc_pin entries */
  603. #define _NOGP_PINMUX(_pin, _name, cfg) { \
  604. .pin = PIN_##_pin, \
  605. .name = "PIN_" _name, \
  606. .configs = SH_PFC_PIN_CFG_NO_GPIO | cfg, \
  607. }
  608. #define PINMUX_NOGP_ALL() CPU_ALL_NOGP(_NOGP_PINMUX)
  609. /*
  610. * PORTnCR helper macro for SH-Mobile/R-Mobile
  611. */
  612. #define PORTCR(nr, reg) { \
  613. PINMUX_CFG_REG_VAR("PORT" nr "CR", reg, 8, GROUP(-2, 2, -1, 3), \
  614. GROUP( \
  615. /* PULMD[1:0], handled by .set_bias() */ \
  616. /* IE and OE */ \
  617. 0, PORT##nr##_OUT, PORT##nr##_IN, 0, \
  618. /* SEC, not supported */ \
  619. /* PTMD[2:0] */ \
  620. PORT##nr##_FN0, PORT##nr##_FN1, \
  621. PORT##nr##_FN2, PORT##nr##_FN3, \
  622. PORT##nr##_FN4, PORT##nr##_FN5, \
  623. PORT##nr##_FN6, PORT##nr##_FN7 \
  624. )) \
  625. }
  626. /*
  627. * GPIO number helper macro for R-Car
  628. */
  629. #define RCAR_GP_PIN(bank, pin) (((bank) * 32) + (pin))
  630. /*
  631. * Bias helpers
  632. */
  633. const struct pinmux_bias_reg *
  634. rcar_pin_to_bias_reg(const struct sh_pfc_soc_info *info, unsigned int pin,
  635. unsigned int *bit);
  636. unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin);
  637. void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
  638. unsigned int bias);
  639. #endif /* __SH_PFC_H */