mux.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 "mux34xx.h"
  11. #define OMAP_MUX_TERMINATOR 0xffff
  12. /* 34xx mux mode options for each pin. See TRM for options */
  13. #define OMAP_MUX_MODE0 0
  14. #define OMAP_MUX_MODE1 1
  15. #define OMAP_MUX_MODE2 2
  16. #define OMAP_MUX_MODE3 3
  17. #define OMAP_MUX_MODE4 4
  18. #define OMAP_MUX_MODE5 5
  19. #define OMAP_MUX_MODE6 6
  20. #define OMAP_MUX_MODE7 7
  21. /* 24xx/34xx mux bit defines */
  22. #define OMAP_PULL_ENA (1 << 3)
  23. #define OMAP_PULL_UP (1 << 4)
  24. #define OMAP_ALTELECTRICALSEL (1 << 5)
  25. /* 34xx specific mux bit defines */
  26. #define OMAP_INPUT_EN (1 << 8)
  27. #define OMAP_OFF_EN (1 << 9)
  28. #define OMAP_OFFOUT_EN (1 << 10)
  29. #define OMAP_OFFOUT_VAL (1 << 11)
  30. #define OMAP_OFF_PULL_EN (1 << 12)
  31. #define OMAP_OFF_PULL_UP (1 << 13)
  32. #define OMAP_WAKEUP_EN (1 << 14)
  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(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE4)
  49. /* Flags for omap_mux_init */
  50. #define OMAP_PACKAGE_MASK 0xffff
  51. #define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */
  52. #define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */
  53. #define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */
  54. #define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */
  55. #define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */
  56. #define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */
  57. #define OMAP_MUX_NR_MODES 8 /* Available modes */
  58. #define OMAP_MUX_NR_SIDES 2 /* Bottom & top */
  59. /**
  60. * struct omap_mux - data for omap mux register offset and it's value
  61. * @reg_offset: mux register offset from the mux base
  62. * @gpio: GPIO number
  63. * @muxnames: available signal modes for a ball
  64. */
  65. struct omap_mux {
  66. u16 reg_offset;
  67. u16 gpio;
  68. #ifdef CONFIG_OMAP_MUX
  69. char *muxnames[OMAP_MUX_NR_MODES];
  70. #ifdef CONFIG_DEBUG_FS
  71. char *balls[OMAP_MUX_NR_SIDES];
  72. #endif
  73. #endif
  74. };
  75. /**
  76. * struct omap_ball - data for balls on omap package
  77. * @reg_offset: mux register offset from the mux base
  78. * @balls: available balls on the package
  79. */
  80. struct omap_ball {
  81. u16 reg_offset;
  82. char *balls[OMAP_MUX_NR_SIDES];
  83. };
  84. /**
  85. * struct omap_board_mux - data for initializing mux registers
  86. * @reg_offset: mux register offset from the mux base
  87. * @mux_value: desired mux value to set
  88. */
  89. struct omap_board_mux {
  90. u16 reg_offset;
  91. u16 value;
  92. };
  93. #if defined(CONFIG_OMAP_MUX)
  94. /**
  95. * omap_mux_init_gpio - initialize a signal based on the GPIO number
  96. * @gpio: GPIO number
  97. * @val: Options for the mux register value
  98. */
  99. int omap_mux_init_gpio(int gpio, int val);
  100. /**
  101. * omap_mux_init_signal - initialize a signal based on the signal name
  102. * @muxname: Mux name in mode0_name.signal_name format
  103. * @val: Options for the mux register value
  104. */
  105. int omap_mux_init_signal(char *muxname, int val);
  106. #else
  107. static inline int omap_mux_init_gpio(int gpio, int val)
  108. {
  109. return 0;
  110. }
  111. static inline int omap_mux_init_signal(char *muxname, int val)
  112. {
  113. return 0;
  114. }
  115. #endif
  116. /**
  117. * omap_mux_get_gpio() - get mux register value based on GPIO number
  118. * @gpio: GPIO number
  119. *
  120. */
  121. u16 omap_mux_get_gpio(int gpio);
  122. /**
  123. * omap_mux_set_gpio() - set mux register value based on GPIO number
  124. * @val: New mux register value
  125. * @gpio: GPIO number
  126. *
  127. */
  128. void omap_mux_set_gpio(u16 val, int gpio);
  129. /**
  130. * omap_mux_read() - read mux register
  131. * @mux_offset: Offset of the mux register
  132. *
  133. */
  134. u16 omap_mux_read(u16 mux_offset);
  135. /**
  136. * omap_mux_write() - write mux register
  137. * @val: New mux register value
  138. * @mux_offset: Offset of the mux register
  139. *
  140. * This should be only needed for dynamic remuxing of non-gpio signals.
  141. */
  142. void omap_mux_write(u16 val, u16 mux_offset);
  143. /**
  144. * omap_mux_write_array() - write an array of mux registers
  145. * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR
  146. *
  147. * This should be only needed for dynamic remuxing of non-gpio signals.
  148. */
  149. void omap_mux_write_array(struct omap_board_mux *board_mux);
  150. /**
  151. * omap2420_mux_init() - initialize mux system with board specific set
  152. * @board_mux: Board specific mux table
  153. * @flags: OMAP package type used for the board
  154. */
  155. int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
  156. /**
  157. * omap3_mux_init() - initialize mux system with board specific set
  158. * @board_mux: Board specific mux table
  159. * @flags: OMAP package type used for the board
  160. */
  161. int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
  162. /**
  163. * omap_mux_init - private mux init function, do not call
  164. */
  165. int omap_mux_init(u32 mux_pbase, u32 mux_size,
  166. struct omap_mux *superset,
  167. struct omap_mux *package_subset,
  168. struct omap_board_mux *board_mux,
  169. struct omap_ball *package_balls);