mux.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright (C) 2009 Nokia
  3. * Copyright (C) 2009-2010 Texas Instruments
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include "mux2420.h"
  10. #include "mux2430.h"
  11. #include "mux34xx.h"
  12. #include "mux44xx.h"
  13. #define OMAP_MUX_TERMINATOR 0xffff
  14. /* 34xx mux mode options for each pin. See TRM for options */
  15. #define OMAP_MUX_MODE0 0
  16. #define OMAP_MUX_MODE1 1
  17. #define OMAP_MUX_MODE2 2
  18. #define OMAP_MUX_MODE3 3
  19. #define OMAP_MUX_MODE4 4
  20. #define OMAP_MUX_MODE5 5
  21. #define OMAP_MUX_MODE6 6
  22. #define OMAP_MUX_MODE7 7
  23. /* 24xx/34xx mux bit defines */
  24. #define OMAP_PULL_ENA (1 << 3)
  25. #define OMAP_PULL_UP (1 << 4)
  26. #define OMAP_ALTELECTRICALSEL (1 << 5)
  27. /* 34xx specific mux bit defines */
  28. #define OMAP_INPUT_EN (1 << 8)
  29. #define OMAP_OFF_EN (1 << 9)
  30. #define OMAP_OFFOUT_EN (1 << 10)
  31. #define OMAP_OFFOUT_VAL (1 << 11)
  32. #define OMAP_OFF_PULL_EN (1 << 12)
  33. #define OMAP_OFF_PULL_UP (1 << 13)
  34. #define OMAP_WAKEUP_EN (1 << 14)
  35. /* 44xx specific mux bit defines */
  36. #define OMAP_WAKEUP_EVENT (1 << 15)
  37. /* Active pin states */
  38. #define OMAP_PIN_OUTPUT 0
  39. #define OMAP_PIN_INPUT OMAP_INPUT_EN
  40. #define OMAP_PIN_INPUT_PULLUP (OMAP_PULL_ENA | OMAP_INPUT_EN \
  41. | OMAP_PULL_UP)
  42. #define OMAP_PIN_INPUT_PULLDOWN (OMAP_PULL_ENA | OMAP_INPUT_EN)
  43. /* Off mode states */
  44. #define OMAP_PIN_OFF_NONE 0
  45. #define OMAP_PIN_OFF_OUTPUT_HIGH (OMAP_OFF_EN | OMAP_OFFOUT_EN \
  46. | OMAP_OFFOUT_VAL)
  47. #define OMAP_PIN_OFF_OUTPUT_LOW (OMAP_OFF_EN | OMAP_OFFOUT_EN)
  48. #define OMAP_PIN_OFF_INPUT_PULLUP (OMAP_OFF_EN | OMAP_OFF_PULL_EN \
  49. | OMAP_OFF_PULL_UP)
  50. #define OMAP_PIN_OFF_INPUT_PULLDOWN (OMAP_OFF_EN | OMAP_OFF_PULL_EN)
  51. #define OMAP_PIN_OFF_WAKEUPENABLE OMAP_WAKEUP_EN
  52. #define OMAP_MODE_GPIO(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE4)
  53. /* Flags for omapX_mux_init */
  54. #define OMAP_PACKAGE_MASK 0xffff
  55. #define OMAP_PACKAGE_CBS 8 /* 547-pin 0.40 0.40 */
  56. #define OMAP_PACKAGE_CBL 7 /* 547-pin 0.40 0.40 */
  57. #define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */
  58. #define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */
  59. #define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */
  60. #define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */
  61. #define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */
  62. #define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */
  63. #define OMAP_MUX_NR_MODES 8 /* Available modes */
  64. #define OMAP_MUX_NR_SIDES 2 /* Bottom & top */
  65. /*
  66. * omap_mux_init flags definition:
  67. *
  68. * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits.
  69. * The default value is 16 bits.
  70. * OMAP_MUX_GPIO_IN_MODE3: The GPIO is selected in mode3.
  71. * The default is mode4.
  72. */
  73. #define OMAP_MUX_REG_8BIT (1 << 0)
  74. #define OMAP_MUX_GPIO_IN_MODE3 (1 << 1)
  75. /**
  76. * struct mux_partition - contain partition related information
  77. * @name: name of the current partition
  78. * @flags: flags specific to this partition
  79. * @phys: physical address
  80. * @size: partition size
  81. * @base: virtual address after ioremap
  82. * @muxmodes: list of nodes that belong to a partition
  83. * @node: list node for the partitions linked list
  84. */
  85. struct omap_mux_partition {
  86. const char *name;
  87. u32 flags;
  88. u32 phys;
  89. u32 size;
  90. void __iomem *base;
  91. struct list_head muxmodes;
  92. struct list_head node;
  93. };
  94. /**
  95. * struct omap_mux - data for omap mux register offset and it's value
  96. * @reg_offset: mux register offset from the mux base
  97. * @gpio: GPIO number
  98. * @muxnames: available signal modes for a ball
  99. * @balls: available balls on the package
  100. * @partition: mux partition
  101. */
  102. struct omap_mux {
  103. u16 reg_offset;
  104. u16 gpio;
  105. #ifdef CONFIG_OMAP_MUX
  106. char *muxnames[OMAP_MUX_NR_MODES];
  107. #ifdef CONFIG_DEBUG_FS
  108. char *balls[OMAP_MUX_NR_SIDES];
  109. #endif
  110. #endif
  111. };
  112. /**
  113. * struct omap_ball - data for balls on omap package
  114. * @reg_offset: mux register offset from the mux base
  115. * @balls: available balls on the package
  116. */
  117. struct omap_ball {
  118. u16 reg_offset;
  119. char *balls[OMAP_MUX_NR_SIDES];
  120. };
  121. /**
  122. * struct omap_board_mux - data for initializing mux registers
  123. * @reg_offset: mux register offset from the mux base
  124. * @mux_value: desired mux value to set
  125. */
  126. struct omap_board_mux {
  127. u16 reg_offset;
  128. u16 value;
  129. };
  130. #if defined(CONFIG_OMAP_MUX)
  131. /**
  132. * omap_mux_init_gpio - initialize a signal based on the GPIO number
  133. * @gpio: GPIO number
  134. * @val: Options for the mux register value
  135. */
  136. int omap_mux_init_gpio(int gpio, int val);
  137. /**
  138. * omap_mux_init_signal - initialize a signal based on the signal name
  139. * @muxname: Mux name in mode0_name.signal_name format
  140. * @val: Options for the mux register value
  141. */
  142. int omap_mux_init_signal(const char *muxname, int val);
  143. #else
  144. static inline int omap_mux_init_gpio(int gpio, int val)
  145. {
  146. return 0;
  147. }
  148. static inline int omap_mux_init_signal(char *muxname, int val)
  149. {
  150. return 0;
  151. }
  152. #endif
  153. /**
  154. * omap_mux_get_gpio() - get mux register value based on GPIO number
  155. * @gpio: GPIO number
  156. *
  157. */
  158. u16 omap_mux_get_gpio(int gpio);
  159. /**
  160. * omap_mux_set_gpio() - set mux register value based on GPIO number
  161. * @val: New mux register value
  162. * @gpio: GPIO number
  163. *
  164. */
  165. void omap_mux_set_gpio(u16 val, int gpio);
  166. /**
  167. * omap_mux_get() - get a mux partition by name
  168. * @name: Name of the mux partition
  169. *
  170. */
  171. struct omap_mux_partition *omap_mux_get(const char *name);
  172. /**
  173. * omap_mux_read() - read mux register
  174. * @partition: Mux partition
  175. * @mux_offset: Offset of the mux register
  176. *
  177. */
  178. u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset);
  179. /**
  180. * omap_mux_write() - write mux register
  181. * @partition: Mux partition
  182. * @val: New mux register value
  183. * @mux_offset: Offset of the mux register
  184. *
  185. * This should be only needed for dynamic remuxing of non-gpio signals.
  186. */
  187. void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset);
  188. /**
  189. * omap_mux_write_array() - write an array of mux registers
  190. * @partition: Mux partition
  191. * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR
  192. *
  193. * This should be only needed for dynamic remuxing of non-gpio signals.
  194. */
  195. void omap_mux_write_array(struct omap_mux_partition *p,
  196. struct omap_board_mux *board_mux);
  197. /**
  198. * omap2420_mux_init() - initialize mux system with board specific set
  199. * @board_mux: Board specific mux table
  200. * @flags: OMAP package type used for the board
  201. */
  202. int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
  203. /**
  204. * omap2430_mux_init() - initialize mux system with board specific set
  205. * @board_mux: Board specific mux table
  206. * @flags: OMAP package type used for the board
  207. */
  208. int omap2430_mux_init(struct omap_board_mux *board_mux, int flags);
  209. /**
  210. * omap3_mux_init() - initialize mux system with board specific set
  211. * @board_mux: Board specific mux table
  212. * @flags: OMAP package type used for the board
  213. */
  214. int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
  215. /**
  216. * omap4_mux_init() - initialize mux system with board specific set
  217. * @board_mux: Board specific mux table
  218. * @flags: OMAP package type used for the board
  219. */
  220. int omap4_mux_init(struct omap_board_mux *board_mux, int flags);
  221. /**
  222. * omap_mux_init - private mux init function, do not call
  223. */
  224. int omap_mux_init(const char *name, u32 flags,
  225. u32 mux_pbase, u32 mux_size,
  226. struct omap_mux *superset,
  227. struct omap_mux *package_subset,
  228. struct omap_board_mux *board_mux,
  229. struct omap_ball *package_balls);