mux.h 9.6 KB

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