mux.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (C) 2009 Nokia
  3. * Copyright (C) 2009 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. /* Active pin states */
  35. #define OMAP_PIN_OUTPUT 0
  36. #define OMAP_PIN_INPUT OMAP_INPUT_EN
  37. #define OMAP_PIN_INPUT_PULLUP (OMAP_PULL_ENA | OMAP_INPUT_EN \
  38. | OMAP_PULL_UP)
  39. #define OMAP_PIN_INPUT_PULLDOWN (OMAP_PULL_ENA | OMAP_INPUT_EN)
  40. /* Off mode states */
  41. #define OMAP_PIN_OFF_NONE 0
  42. #define OMAP_PIN_OFF_OUTPUT_HIGH (OMAP_OFF_EN | OMAP_OFFOUT_EN \
  43. | OMAP_OFFOUT_VAL)
  44. #define OMAP_PIN_OFF_OUTPUT_LOW (OMAP_OFF_EN | OMAP_OFFOUT_EN)
  45. #define OMAP_PIN_OFF_INPUT_PULLUP (OMAP_OFF_EN | OMAP_OFF_PULL_EN \
  46. | OMAP_OFF_PULL_UP)
  47. #define OMAP_PIN_OFF_INPUT_PULLDOWN (OMAP_OFF_EN | OMAP_OFF_PULL_EN)
  48. #define OMAP_PIN_OFF_WAKEUPENABLE OMAP_WAKEUP_EN
  49. #define OMAP_MODE_GPIO(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE4)
  50. /* Flags for omap_mux_init */
  51. #define OMAP_PACKAGE_MASK 0xffff
  52. #define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */
  53. #define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */
  54. #define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */
  55. #define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */
  56. #define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */
  57. #define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */
  58. #define OMAP_MUX_NR_MODES 8 /* Available modes */
  59. #define OMAP_MUX_NR_SIDES 2 /* Bottom & top */
  60. /**
  61. * struct omap_mux - data for omap mux register offset and it's value
  62. * @reg_offset: mux register offset from the mux base
  63. * @gpio: GPIO number
  64. * @muxnames: available signal modes for a ball
  65. */
  66. struct omap_mux {
  67. u16 reg_offset;
  68. u16 gpio;
  69. #ifdef CONFIG_OMAP_MUX
  70. char *muxnames[OMAP_MUX_NR_MODES];
  71. #ifdef CONFIG_DEBUG_FS
  72. char *balls[OMAP_MUX_NR_SIDES];
  73. #endif
  74. #endif
  75. };
  76. /**
  77. * struct omap_ball - data for balls on omap package
  78. * @reg_offset: mux register offset from the mux base
  79. * @balls: available balls on the package
  80. */
  81. struct omap_ball {
  82. u16 reg_offset;
  83. char *balls[OMAP_MUX_NR_SIDES];
  84. };
  85. /**
  86. * struct omap_board_mux - data for initializing mux registers
  87. * @reg_offset: mux register offset from the mux base
  88. * @mux_value: desired mux value to set
  89. */
  90. struct omap_board_mux {
  91. u16 reg_offset;
  92. u16 value;
  93. };
  94. #if defined(CONFIG_OMAP_MUX)
  95. /**
  96. * omap_mux_init_gpio - initialize a signal based on the GPIO number
  97. * @gpio: GPIO number
  98. * @val: Options for the mux register value
  99. */
  100. int omap_mux_init_gpio(int gpio, int val);
  101. /**
  102. * omap_mux_init_signal - initialize a signal based on the signal name
  103. * @muxname: Mux name in mode0_name.signal_name format
  104. * @val: Options for the mux register value
  105. */
  106. int omap_mux_init_signal(char *muxname, int val);
  107. #else
  108. static inline int omap_mux_init_gpio(int gpio, int val)
  109. {
  110. return 0;
  111. }
  112. static inline int omap_mux_init_signal(char *muxname, int val)
  113. {
  114. return 0;
  115. }
  116. #endif
  117. /**
  118. * omap_mux_get_gpio() - get mux register value based on GPIO number
  119. * @gpio: GPIO number
  120. *
  121. */
  122. u16 omap_mux_get_gpio(int gpio);
  123. /**
  124. * omap_mux_set_gpio() - set mux register value based on GPIO number
  125. * @val: New mux register value
  126. * @gpio: GPIO number
  127. *
  128. */
  129. void omap_mux_set_gpio(u16 val, int gpio);
  130. /**
  131. * omap_mux_read() - read mux register
  132. * @mux_offset: Offset of the mux register
  133. *
  134. */
  135. u16 omap_mux_read(u16 mux_offset);
  136. /**
  137. * omap_mux_write() - write mux register
  138. * @val: New mux register value
  139. * @mux_offset: Offset of the mux register
  140. *
  141. * This should be only needed for dynamic remuxing of non-gpio signals.
  142. */
  143. void omap_mux_write(u16 val, u16 mux_offset);
  144. /**
  145. * omap_mux_write_array() - write an array of mux registers
  146. * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR
  147. *
  148. * This should be only needed for dynamic remuxing of non-gpio signals.
  149. */
  150. void omap_mux_write_array(struct omap_board_mux *board_mux);
  151. /**
  152. * omap2420_mux_init() - initialize mux system with board specific set
  153. * @board_mux: Board specific mux table
  154. * @flags: OMAP package type used for the board
  155. */
  156. int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
  157. /**
  158. * omap2430_mux_init() - initialize mux system with board specific set
  159. * @board_mux: Board specific mux table
  160. * @flags: OMAP package type used for the board
  161. */
  162. int omap2430_mux_init(struct omap_board_mux *board_mux, int flags);
  163. /**
  164. * omap3_mux_init() - initialize mux system with board specific set
  165. * @board_mux: Board specific mux table
  166. * @flags: OMAP package type used for the board
  167. */
  168. int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
  169. /**
  170. * omap_mux_init - private mux init function, do not call
  171. */
  172. int omap_mux_init(u32 mux_pbase, u32 mux_size,
  173. struct omap_mux *superset,
  174. struct omap_mux *package_subset,
  175. struct omap_board_mux *board_mux,
  176. struct omap_ball *package_balls);