mux.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. #define OMAP_MUX_TERMINATOR 0xffff
  13. /* 34xx mux mode options for each pin. See TRM for options */
  14. #define OMAP_MUX_MODE0 0
  15. #define OMAP_MUX_MODE1 1
  16. #define OMAP_MUX_MODE2 2
  17. #define OMAP_MUX_MODE3 3
  18. #define OMAP_MUX_MODE4 4
  19. #define OMAP_MUX_MODE5 5
  20. #define OMAP_MUX_MODE6 6
  21. #define OMAP_MUX_MODE7 7
  22. /* 24xx/34xx mux bit defines */
  23. #define OMAP_PULL_ENA (1 << 3)
  24. #define OMAP_PULL_UP (1 << 4)
  25. #define OMAP_ALTELECTRICALSEL (1 << 5)
  26. /* 34xx specific mux bit defines */
  27. #define OMAP_INPUT_EN (1 << 8)
  28. #define OMAP_OFF_EN (1 << 9)
  29. #define OMAP_OFFOUT_EN (1 << 10)
  30. #define OMAP_OFFOUT_VAL (1 << 11)
  31. #define OMAP_OFF_PULL_EN (1 << 12)
  32. #define OMAP_OFF_PULL_UP (1 << 13)
  33. #define OMAP_WAKEUP_EN (1 << 14)
  34. /* 44xx specific mux bit defines */
  35. #define OMAP_WAKEUP_EVENT (1 << 15)
  36. /* Active pin states */
  37. #define OMAP_PIN_OUTPUT 0
  38. #define OMAP_PIN_INPUT OMAP_INPUT_EN
  39. #define OMAP_PIN_INPUT_PULLUP (OMAP_PULL_ENA | OMAP_INPUT_EN \
  40. | OMAP_PULL_UP)
  41. #define OMAP_PIN_INPUT_PULLDOWN (OMAP_PULL_ENA | OMAP_INPUT_EN)
  42. /* Off mode states */
  43. #define OMAP_PIN_OFF_NONE 0
  44. #define OMAP_PIN_OFF_OUTPUT_HIGH (OMAP_OFF_EN | OMAP_OFFOUT_EN \
  45. | OMAP_OFFOUT_VAL)
  46. #define OMAP_PIN_OFF_OUTPUT_LOW (OMAP_OFF_EN | OMAP_OFFOUT_EN)
  47. #define OMAP_PIN_OFF_INPUT_PULLUP (OMAP_OFF_EN | OMAP_OFF_PULL_EN \
  48. | OMAP_OFF_PULL_UP)
  49. #define OMAP_PIN_OFF_INPUT_PULLDOWN (OMAP_OFF_EN | OMAP_OFF_PULL_EN)
  50. #define OMAP_PIN_OFF_WAKEUPENABLE OMAP_WAKEUP_EN
  51. #define OMAP_MODE_GPIO(partition, x) (((x) & OMAP_MUX_MODE7) == \
  52. partition->gpio)
  53. #define OMAP_MODE_UART(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE0)
  54. /* Flags for omapX_mux_init */
  55. #define OMAP_PACKAGE_MASK 0xffff
  56. #define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */
  57. #define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */
  58. #define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */
  59. #define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */
  60. #define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */
  61. #define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */
  62. #define OMAP_MUX_NR_MODES 8 /* Available modes */
  63. #define OMAP_MUX_NR_SIDES 2 /* Bottom & top */
  64. /*
  65. * omap_mux_init flags definition:
  66. *
  67. * OMAP_GPIO_MUX_MODE, bits 0-2: gpio muxing mode, same like pad control
  68. * register which includes values from 0-7.
  69. * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits.
  70. * The default value is 16 bits.
  71. */
  72. #define OMAP_MUX_GPIO_IN_MODE0 OMAP_MUX_MODE0
  73. #define OMAP_MUX_GPIO_IN_MODE1 OMAP_MUX_MODE1
  74. #define OMAP_MUX_GPIO_IN_MODE2 OMAP_MUX_MODE2
  75. #define OMAP_MUX_GPIO_IN_MODE3 OMAP_MUX_MODE3
  76. #define OMAP_MUX_GPIO_IN_MODE4 OMAP_MUX_MODE4
  77. #define OMAP_MUX_GPIO_IN_MODE5 OMAP_MUX_MODE5
  78. #define OMAP_MUX_GPIO_IN_MODE6 OMAP_MUX_MODE6
  79. #define OMAP_MUX_GPIO_IN_MODE7 OMAP_MUX_MODE7
  80. #define OMAP_MUX_REG_8BIT (1 << 3)
  81. /**
  82. * struct omap_board_data - board specific device data
  83. * @id: instance id
  84. * @flags: additional flags for platform init code
  85. * @pads: array of device specific pads
  86. * @pads_cnt: ARRAY_SIZE() of pads
  87. */
  88. struct omap_board_data {
  89. int id;
  90. u32 flags;
  91. struct omap_device_pad *pads;
  92. int pads_cnt;
  93. };
  94. /**
  95. * struct mux_partition - contain partition related information
  96. * @name: name of the current partition
  97. * @flags: flags specific to this partition
  98. * @gpio: gpio mux mode
  99. * @phys: physical address
  100. * @size: partition size
  101. * @base: virtual address after ioremap
  102. * @muxmodes: list of nodes that belong to a partition
  103. * @node: list node for the partitions linked list
  104. */
  105. struct omap_mux_partition {
  106. const char *name;
  107. u32 flags;
  108. u32 gpio;
  109. u32 phys;
  110. u32 size;
  111. void __iomem *base;
  112. struct list_head muxmodes;
  113. struct list_head node;
  114. };
  115. /**
  116. * struct omap_mux - data for omap mux register offset and it's value
  117. * @reg_offset: mux register offset from the mux base
  118. * @gpio: GPIO number
  119. * @muxnames: available signal modes for a ball
  120. * @balls: available balls on the package
  121. */
  122. struct omap_mux {
  123. u16 reg_offset;
  124. u16 gpio;
  125. #ifdef CONFIG_OMAP_MUX
  126. char *muxnames[OMAP_MUX_NR_MODES];
  127. #ifdef CONFIG_DEBUG_FS
  128. char *balls[OMAP_MUX_NR_SIDES];
  129. #endif
  130. #endif
  131. };
  132. /**
  133. * struct omap_ball - data for balls on omap package
  134. * @reg_offset: mux register offset from the mux base
  135. * @balls: available balls on the package
  136. */
  137. struct omap_ball {
  138. u16 reg_offset;
  139. char *balls[OMAP_MUX_NR_SIDES];
  140. };
  141. /**
  142. * struct omap_board_mux - data for initializing mux registers
  143. * @reg_offset: mux register offset from the mux base
  144. * @mux_value: desired mux value to set
  145. */
  146. struct omap_board_mux {
  147. u16 reg_offset;
  148. u16 value;
  149. };
  150. #define OMAP_DEVICE_PAD_REMUX BIT(1) /* Dynamically remux a pad,
  151. needs enable, idle and off
  152. values */
  153. #define OMAP_DEVICE_PAD_WAKEUP BIT(0) /* Pad is wake-up capable */
  154. /**
  155. * struct omap_device_pad - device specific pad configuration
  156. * @name: signal name
  157. * @flags: pad specific runtime flags
  158. * @enable: runtime value for a pad
  159. * @idle: idle value for a pad
  160. * @off: off value for a pad, defaults to safe mode
  161. * @partition: mux partition
  162. * @mux: mux register
  163. */
  164. struct omap_device_pad {
  165. char *name;
  166. u8 flags;
  167. u16 enable;
  168. u16 idle;
  169. u16 off;
  170. struct omap_mux_partition *partition;
  171. struct omap_mux *mux;
  172. };
  173. struct omap_hwmod_mux_info;
  174. #define OMAP_MUX_STATIC(signal, mode) \
  175. { \
  176. .name = (signal), \
  177. .enable = (mode), \
  178. }
  179. #if defined(CONFIG_OMAP_MUX)
  180. /**
  181. * omap_mux_init_gpio - initialize a signal based on the GPIO number
  182. * @gpio: GPIO number
  183. * @val: Options for the mux register value
  184. */
  185. int omap_mux_init_gpio(int gpio, int val);
  186. /**
  187. * omap_mux_init_signal - initialize a signal based on the signal name
  188. * @muxname: Mux name in mode0_name.signal_name format
  189. * @val: Options for the mux register value
  190. */
  191. int omap_mux_init_signal(const char *muxname, int val);
  192. /**
  193. * omap_hwmod_mux_init - initialize hwmod specific mux data
  194. * @bpads: Board specific device signal names
  195. * @nr_pads: Number of signal names for the device
  196. */
  197. extern struct omap_hwmod_mux_info *
  198. omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads);
  199. /**
  200. * omap_hwmod_mux - omap hwmod specific pin muxing
  201. * @hmux: Pads for a hwmod
  202. * @state: Desired _HWMOD_STATE
  203. *
  204. * Called only from omap_hwmod.c, do not use.
  205. */
  206. void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state);
  207. int omap_mux_get_by_name(const char *muxname,
  208. struct omap_mux_partition **found_partition,
  209. struct omap_mux **found_mux);
  210. #else
  211. static inline int omap_mux_get_by_name(const char *muxname,
  212. struct omap_mux_partition **found_partition,
  213. struct omap_mux **found_mux)
  214. {
  215. return 0;
  216. }
  217. static inline int omap_mux_init_gpio(int gpio, int val)
  218. {
  219. return 0;
  220. }
  221. static inline int omap_mux_init_signal(char *muxname, int val)
  222. {
  223. return 0;
  224. }
  225. static inline struct omap_hwmod_mux_info *
  226. omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
  227. {
  228. return NULL;
  229. }
  230. static inline void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
  231. {
  232. }
  233. static struct omap_board_mux *board_mux __maybe_unused;
  234. #endif
  235. /**
  236. * omap_mux_get_gpio() - get mux register value based on GPIO number
  237. * @gpio: GPIO number
  238. *
  239. */
  240. u16 omap_mux_get_gpio(int gpio);
  241. /**
  242. * omap_mux_set_gpio() - set mux register value based on GPIO number
  243. * @val: New mux register value
  244. * @gpio: GPIO number
  245. *
  246. */
  247. void omap_mux_set_gpio(u16 val, int gpio);
  248. /**
  249. * omap_mux_get() - get a mux partition by name
  250. * @name: Name of the mux partition
  251. *
  252. */
  253. struct omap_mux_partition *omap_mux_get(const char *name);
  254. /**
  255. * omap_mux_read() - read mux register
  256. * @partition: Mux partition
  257. * @mux_offset: Offset of the mux register
  258. *
  259. */
  260. u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset);
  261. /**
  262. * omap_mux_write() - write mux register
  263. * @partition: Mux partition
  264. * @val: New mux register value
  265. * @mux_offset: Offset of the mux register
  266. *
  267. * This should be only needed for dynamic remuxing of non-gpio signals.
  268. */
  269. void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset);
  270. /**
  271. * omap_mux_write_array() - write an array of mux registers
  272. * @partition: Mux partition
  273. * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR
  274. *
  275. * This should be only needed for dynamic remuxing of non-gpio signals.
  276. */
  277. void omap_mux_write_array(struct omap_mux_partition *p,
  278. struct omap_board_mux *board_mux);
  279. /**
  280. * omap2420_mux_init() - initialize mux system with board specific set
  281. * @board_mux: Board specific mux table
  282. * @flags: OMAP package type used for the board
  283. */
  284. int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
  285. /**
  286. * omap2430_mux_init() - initialize mux system with board specific set
  287. * @board_mux: Board specific mux table
  288. * @flags: OMAP package type used for the board
  289. */
  290. int omap2430_mux_init(struct omap_board_mux *board_mux, int flags);
  291. /**
  292. * omap3_mux_init() - initialize mux system with board specific set
  293. * @board_mux: Board specific mux table
  294. * @flags: OMAP package type used for the board
  295. */
  296. int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
  297. /**
  298. * omap4_mux_init() - initialize mux system with board specific set
  299. * @board_subset: Board specific mux table
  300. * @board_wkup_subset: Board specific mux table for wakeup instance
  301. * @flags: OMAP package type used for the board
  302. */
  303. int omap4_mux_init(struct omap_board_mux *board_subset,
  304. struct omap_board_mux *board_wkup_subset, int flags);
  305. /**
  306. * omap_mux_init - private mux init function, do not call
  307. */
  308. int omap_mux_init(const char *name, u32 flags,
  309. u32 mux_pbase, u32 mux_size,
  310. struct omap_mux *superset,
  311. struct omap_mux *package_subset,
  312. struct omap_board_mux *board_mux,
  313. struct omap_ball *package_balls);