sh_pfc.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. #include <asm-generic/gpio.h>
  14. typedef unsigned short pinmux_enum_t;
  15. typedef unsigned short pinmux_flag_t;
  16. enum {
  17. PINMUX_TYPE_NONE,
  18. PINMUX_TYPE_FUNCTION,
  19. PINMUX_TYPE_GPIO,
  20. PINMUX_TYPE_OUTPUT,
  21. PINMUX_TYPE_INPUT,
  22. PINMUX_TYPE_INPUT_PULLUP,
  23. PINMUX_TYPE_INPUT_PULLDOWN,
  24. PINMUX_FLAG_TYPE, /* must be last */
  25. };
  26. #define PINMUX_FLAG_DBIT_SHIFT 5
  27. #define PINMUX_FLAG_DBIT (0x1f << PINMUX_FLAG_DBIT_SHIFT)
  28. #define PINMUX_FLAG_DREG_SHIFT 10
  29. #define PINMUX_FLAG_DREG (0x3f << PINMUX_FLAG_DREG_SHIFT)
  30. struct pinmux_pin {
  31. const pinmux_enum_t enum_id;
  32. pinmux_flag_t flags;
  33. const char *name;
  34. };
  35. struct pinmux_func {
  36. const pinmux_enum_t enum_id;
  37. const char *name;
  38. };
  39. #define PINMUX_GPIO(gpio, data_or_mark) \
  40. [gpio] = { \
  41. .name = __stringify(gpio), \
  42. .enum_id = data_or_mark, \
  43. .flags = PINMUX_TYPE_GPIO \
  44. }
  45. #define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
  46. [gpio - (base)] = { \
  47. .name = __stringify(gpio), \
  48. .enum_id = data_or_mark, \
  49. }
  50. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  51. struct pinmux_cfg_reg {
  52. unsigned long reg, reg_width, field_width;
  53. unsigned long *cnt;
  54. pinmux_enum_t *enum_ids;
  55. unsigned long *var_field_width;
  56. };
  57. #define PINMUX_CFG_REG(name, r, r_width, f_width) \
  58. .reg = r, .reg_width = r_width, .field_width = f_width, \
  59. .cnt = (unsigned long [r_width / f_width]) {}, \
  60. .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)])
  61. #define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
  62. .reg = r, .reg_width = r_width, \
  63. .cnt = (unsigned long [r_width]) {}, \
  64. .var_field_width = (unsigned long [r_width]) { var_fw0, var_fwn, 0 }, \
  65. .enum_ids = (pinmux_enum_t [])
  66. struct pinmux_data_reg {
  67. unsigned long reg, reg_width, reg_shadow;
  68. pinmux_enum_t *enum_ids;
  69. void __iomem *mapped_reg;
  70. };
  71. #define PINMUX_DATA_REG(name, r, r_width) \
  72. .reg = r, .reg_width = r_width, \
  73. .enum_ids = (pinmux_enum_t [r_width]) \
  74. struct pinmux_irq {
  75. int irq;
  76. pinmux_enum_t *enum_ids;
  77. };
  78. #define PINMUX_IRQ(irq_nr, ids...) \
  79. { .irq = irq_nr, .enum_ids = (pinmux_enum_t []) { ids, 0 } } \
  80. struct pinmux_range {
  81. pinmux_enum_t begin;
  82. pinmux_enum_t end;
  83. pinmux_enum_t force;
  84. };
  85. struct sh_pfc_soc_info {
  86. char *name;
  87. struct pinmux_range input;
  88. struct pinmux_range input_pd;
  89. struct pinmux_range input_pu;
  90. struct pinmux_range output;
  91. struct pinmux_range function;
  92. struct pinmux_pin *pins;
  93. unsigned int nr_pins;
  94. struct pinmux_func *func_gpios;
  95. unsigned int nr_func_gpios;
  96. struct pinmux_cfg_reg *cfg_regs;
  97. struct pinmux_data_reg *data_regs;
  98. pinmux_enum_t *gpio_data;
  99. unsigned int gpio_data_size;
  100. struct pinmux_irq *gpio_irq;
  101. unsigned int gpio_irq_size;
  102. unsigned long unlock_reg;
  103. };
  104. enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
  105. /* helper macro for port */
  106. #define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
  107. #define PORT_10(fn, pfx, sfx) \
  108. PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
  109. PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
  110. PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
  111. PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
  112. PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
  113. #define PORT_90(fn, pfx, sfx) \
  114. PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
  115. PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
  116. PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
  117. PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
  118. PORT_10(fn, pfx##9, sfx)
  119. #define _PORT_ALL(pfx, sfx) pfx##_##sfx
  120. #define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
  121. #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
  122. #define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
  123. #define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
  124. /* helper macro for pinmux_enum_t */
  125. #define PORT_DATA_I(nr) \
  126. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN)
  127. #define PORT_DATA_I_PD(nr) \
  128. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
  129. PORT##nr##_IN, PORT##nr##_IN_PD)
  130. #define PORT_DATA_I_PU(nr) \
  131. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
  132. PORT##nr##_IN, PORT##nr##_IN_PU)
  133. #define PORT_DATA_I_PU_PD(nr) \
  134. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
  135. PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
  136. #define PORT_DATA_O(nr) \
  137. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT)
  138. #define PORT_DATA_IO(nr) \
  139. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  140. PORT##nr##_IN)
  141. #define PORT_DATA_IO_PD(nr) \
  142. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  143. PORT##nr##_IN, PORT##nr##_IN_PD)
  144. #define PORT_DATA_IO_PU(nr) \
  145. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  146. PORT##nr##_IN, PORT##nr##_IN_PU)
  147. #define PORT_DATA_IO_PU_PD(nr) \
  148. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  149. PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
  150. /* helper macro for top 4 bits in PORTnCR */
  151. #define _PCRH(in, in_pd, in_pu, out) \
  152. 0, (out), (in), 0, \
  153. 0, 0, 0, 0, \
  154. 0, 0, (in_pd), 0, \
  155. 0, 0, (in_pu), 0
  156. #define PORTCR(nr, reg) \
  157. { \
  158. PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
  159. _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
  160. PORT##nr##_IN_PU, PORT##nr##_OUT), \
  161. PORT##nr##_FN0, PORT##nr##_FN1, \
  162. PORT##nr##_FN2, PORT##nr##_FN3, \
  163. PORT##nr##_FN4, PORT##nr##_FN5, \
  164. PORT##nr##_FN6, PORT##nr##_FN7 } \
  165. }
  166. #endif /* __SH_PFC_H */