sh_pfc.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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_gpio {
  31. pinmux_enum_t enum_id;
  32. pinmux_flag_t flags;
  33. const char *name;
  34. };
  35. #define PINMUX_GPIO(gpio, data_or_mark) \
  36. [gpio] = { .name = __stringify(gpio), .enum_id = data_or_mark, .flags = PINMUX_TYPE_NONE }
  37. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  38. struct pinmux_cfg_reg {
  39. unsigned long reg, reg_width, field_width;
  40. unsigned long *cnt;
  41. pinmux_enum_t *enum_ids;
  42. unsigned long *var_field_width;
  43. };
  44. #define PINMUX_CFG_REG(name, r, r_width, f_width) \
  45. .reg = r, .reg_width = r_width, .field_width = f_width, \
  46. .cnt = (unsigned long [r_width / f_width]) {}, \
  47. .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)])
  48. #define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
  49. .reg = r, .reg_width = r_width, \
  50. .cnt = (unsigned long [r_width]) {}, \
  51. .var_field_width = (unsigned long [r_width]) { var_fw0, var_fwn, 0 }, \
  52. .enum_ids = (pinmux_enum_t [])
  53. struct pinmux_data_reg {
  54. unsigned long reg, reg_width, reg_shadow;
  55. pinmux_enum_t *enum_ids;
  56. void __iomem *mapped_reg;
  57. };
  58. #define PINMUX_DATA_REG(name, r, r_width) \
  59. .reg = r, .reg_width = r_width, \
  60. .enum_ids = (pinmux_enum_t [r_width]) \
  61. struct pinmux_irq {
  62. int irq;
  63. pinmux_enum_t *enum_ids;
  64. };
  65. #define PINMUX_IRQ(irq_nr, ids...) \
  66. { .irq = irq_nr, .enum_ids = (pinmux_enum_t []) { ids, 0 } } \
  67. struct pinmux_range {
  68. pinmux_enum_t begin;
  69. pinmux_enum_t end;
  70. pinmux_enum_t force;
  71. };
  72. struct sh_pfc_soc_info {
  73. char *name;
  74. pinmux_enum_t reserved_id;
  75. struct pinmux_range data;
  76. struct pinmux_range input;
  77. struct pinmux_range input_pd;
  78. struct pinmux_range input_pu;
  79. struct pinmux_range output;
  80. struct pinmux_range mark;
  81. struct pinmux_range function;
  82. unsigned first_gpio, last_gpio;
  83. struct pinmux_gpio *gpios;
  84. struct pinmux_cfg_reg *cfg_regs;
  85. struct pinmux_data_reg *data_regs;
  86. pinmux_enum_t *gpio_data;
  87. unsigned int gpio_data_size;
  88. struct pinmux_irq *gpio_irq;
  89. unsigned int gpio_irq_size;
  90. unsigned long unlock_reg;
  91. };
  92. enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
  93. /* helper macro for port */
  94. #define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
  95. #define PORT_10(fn, pfx, sfx) \
  96. PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
  97. PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
  98. PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
  99. PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
  100. PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
  101. #define PORT_90(fn, pfx, sfx) \
  102. PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
  103. PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
  104. PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
  105. PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
  106. PORT_10(fn, pfx##9, sfx)
  107. #define _PORT_ALL(pfx, sfx) pfx##_##sfx
  108. #define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
  109. #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
  110. #define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
  111. #define GPIO_FN(str) PINMUX_GPIO(GPIO_FN_##str, str##_MARK)
  112. /* helper macro for pinmux_enum_t */
  113. #define PORT_DATA_I(nr) \
  114. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN)
  115. #define PORT_DATA_I_PD(nr) \
  116. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
  117. PORT##nr##_IN, PORT##nr##_IN_PD)
  118. #define PORT_DATA_I_PU(nr) \
  119. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
  120. PORT##nr##_IN, PORT##nr##_IN_PU)
  121. #define PORT_DATA_I_PU_PD(nr) \
  122. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
  123. PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
  124. #define PORT_DATA_O(nr) \
  125. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT)
  126. #define PORT_DATA_IO(nr) \
  127. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  128. PORT##nr##_IN)
  129. #define PORT_DATA_IO_PD(nr) \
  130. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  131. PORT##nr##_IN, PORT##nr##_IN_PD)
  132. #define PORT_DATA_IO_PU(nr) \
  133. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  134. PORT##nr##_IN, PORT##nr##_IN_PU)
  135. #define PORT_DATA_IO_PU_PD(nr) \
  136. PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
  137. PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
  138. /* helper macro for top 4 bits in PORTnCR */
  139. #define _PCRH(in, in_pd, in_pu, out) \
  140. 0, (out), (in), 0, \
  141. 0, 0, 0, 0, \
  142. 0, 0, (in_pd), 0, \
  143. 0, 0, (in_pu), 0
  144. #define PORTCR(nr, reg) \
  145. { \
  146. PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
  147. _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
  148. PORT##nr##_IN_PU, PORT##nr##_OUT), \
  149. PORT##nr##_FN0, PORT##nr##_FN1, \
  150. PORT##nr##_FN2, PORT##nr##_FN3, \
  151. PORT##nr##_FN4, PORT##nr##_FN5, \
  152. PORT##nr##_FN6, PORT##nr##_FN7 } \
  153. }
  154. #endif /* __SH_PFC_H */