sh_pfc.h 21 KB

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