pinmux.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. Linux PINMUX.C
  3. */
  4. #include <linux/module.h>
  5. #include <linux/spinlock.h>
  6. #include <mach/am_regs.h>
  7. #include <mach/pinmux.h>
  8. /**
  9. * UTIL interface
  10. * these function can be implement in a tools
  11. */
  12. /**
  13. * @return NULL is fail
  14. * errno NOTAVAILABLE ,
  15. * SOMEPIN IS LOCKED
  16. */
  17. static DEFINE_SPINLOCK(lock);
  18. #define PINMUX_REG_NUM sizeof(pimux_reg_addr)/sizeof(pimux_reg_addr[0])
  19. static const uint32_t pimux_reg_addr[] = {
  20. CBUS_REG_ADDR(PERIPHS_PIN_MUX_0),
  21. CBUS_REG_ADDR(PERIPHS_PIN_MUX_1),
  22. CBUS_REG_ADDR(PERIPHS_PIN_MUX_2),
  23. CBUS_REG_ADDR(PERIPHS_PIN_MUX_3),
  24. CBUS_REG_ADDR(PERIPHS_PIN_MUX_4),
  25. CBUS_REG_ADDR(PERIPHS_PIN_MUX_5),
  26. CBUS_REG_ADDR(PERIPHS_PIN_MUX_6),
  27. CBUS_REG_ADDR(PERIPHS_PIN_MUX_7),
  28. CBUS_REG_ADDR(PERIPHS_PIN_MUX_8),
  29. CBUS_REG_ADDR(PERIPHS_PIN_MUX_9),
  30. CBUS_REG_ADDR(PERIPHS_PIN_MUX_10),
  31. CBUS_REG_ADDR(PERIPHS_PIN_MUX_11),
  32. CBUS_REG_ADDR(PERIPHS_PIN_MUX_12),
  33. //AOBUS_REG_ADDR(AO_RTI_PIN_MUX_REG)
  34. };
  35. static uint32_t pimux_locktable[PINMUX_REG_NUM];
  36. pinmux_set_t *pinmux_cacl_str(char *pad, char *sig, ...)
  37. {
  38. printk(" %s , NOT IMPLENMENT\n", __func__);
  39. BUG();
  40. /**
  41. * @todo NOT implement;
  42. */
  43. return NULL;
  44. }
  45. EXPORT_SYMBOL(pinmux_cacl_str);
  46. pinmux_set_t *pinmux_cacl_int(uint32_t pad, uint32_t sig, ...)
  47. {
  48. printk(" %s , NOT IMPLENMENT\n", __func__);
  49. BUG();
  50. /**
  51. * @todo NOT implement;
  52. */
  53. return NULL;
  54. }
  55. EXPORT_SYMBOL(pinmux_cacl_int);
  56. pinmux_set_t *pinmux_cacl(char *str) ///formate is "pad=sig pad=sig "
  57. {
  58. printk(" %s , NOT IMPLENMENT\n", __func__);
  59. BUG();
  60. /**
  61. * @todo NOT implement;
  62. */
  63. return NULL;
  64. }
  65. EXPORT_SYMBOL(pinmux_cacl);
  66. char **pin_get_list(void)
  67. {
  68. printk(" %s , NOT IMPLENMENT\n", __func__);
  69. BUG();
  70. /**
  71. * @todo NOT implement;
  72. */
  73. return NULL;
  74. }
  75. EXPORT_SYMBOL(pin_get_list);
  76. char **sig_get_list(void)
  77. {
  78. printk(" %s , NOT IMPLENMENT\n", __func__);
  79. BUG();
  80. /**
  81. * @todo NOT implement;
  82. */
  83. return NULL;
  84. }
  85. EXPORT_SYMBOL(sig_get_list);
  86. char *pin_getname(uint32_t pin)
  87. {
  88. printk(" %s , NOT IMPLENMENT\n", __func__);
  89. BUG();
  90. /**
  91. * @todo NOT implement;
  92. */
  93. return NULL;
  94. }
  95. EXPORT_SYMBOL(pin_getname);
  96. char *sig_getname(uint32_t sig)
  97. {
  98. printk(" %s , NOT IMPLENMENT\n", __func__);
  99. BUG();
  100. /**
  101. * @todo NOT implement;
  102. */
  103. return NULL;
  104. }
  105. EXPORT_SYMBOL(sig_getname);
  106. uint32_t pins_num(void)
  107. {
  108. printk(" %s , NOT IMPLENMENT\n", __func__);
  109. BUG();
  110. /**
  111. * @todo NOT implement;
  112. */
  113. return 0 - 1;
  114. }
  115. EXPORT_SYMBOL(pins_num);
  116. /**
  117. * Util Get status function
  118. */
  119. uint32_t pin_sig(uint32_t pin)
  120. {
  121. printk(" %s , NOT IMPLENMENT\n", __func__);
  122. BUG();
  123. /**
  124. * @todo NOT implement;
  125. */
  126. return 0 - 1;
  127. }
  128. EXPORT_SYMBOL(pin_sig);
  129. uint32_t sig_pin(uint32_t sig)
  130. {
  131. printk(" %s , NOT IMPLENMENT\n", __func__);
  132. BUG();
  133. /**
  134. * @todo NOT implement;
  135. */
  136. return 0 - 1;
  137. }
  138. EXPORT_SYMBOL(sig_pin);
  139. /**
  140. * pinmux set function
  141. * @return 0, success ,
  142. * SOMEPIN IS LOCKED, some pin is locked to the specail feature . You can not change it
  143. * NOTAVAILABLE, not available .
  144. */
  145. int32_t pinmux_set(pinmux_set_t * pinmux)
  146. {
  147. uint32_t locallock[PINMUX_REG_NUM];
  148. ulong flags;
  149. int i;
  150. if (pinmux == NULL)
  151. return -4;
  152. memset(locallock, 0, sizeof(locallock));
  153. ///check lock table
  154. for (i = 0; pinmux->pinmux[i].reg != 0xffffffff; i++) {
  155. locallock[pinmux->pinmux[i].reg] =
  156. pinmux->pinmux[i].clrmask | pinmux->pinmux[i].setmask;
  157. if (locallock[pinmux->pinmux[i].reg] &
  158. pimux_locktable[pinmux->pinmux[i].reg])
  159. return -1; ///lock fail some pin is locked by others
  160. }
  161. if (pinmux->chip_select != NULL) {
  162. if (pinmux->chip_select(true) == false)
  163. return -3; ///@select chip fail;
  164. }
  165. spin_lock_irqsave(&lock, flags);
  166. for (i = 0; pinmux->pinmux[i].reg != 0xffffffff; i++) {
  167. pimux_locktable[pinmux->pinmux[i].reg] |=
  168. locallock[pinmux->pinmux[i].reg];
  169. clrsetbits_le32(pimux_reg_addr[pinmux->pinmux[i].reg],
  170. pinmux->pinmux[i].clrmask,
  171. pinmux->pinmux[i].setmask);
  172. }
  173. spin_unlock_irqrestore(&lock, flags);
  174. return 0;
  175. }
  176. EXPORT_SYMBOL(pinmux_set);
  177. int32_t pinmux_clr(pinmux_set_t * pinmux)
  178. {
  179. ulong flags;
  180. int i;
  181. if (pinmux == NULL)
  182. return -4;
  183. if (pinmux->chip_select == NULL) ///non share device , we should put the pins in same status always
  184. return 0;
  185. pinmux->chip_select(false);
  186. spin_lock_irqsave(&lock, flags);
  187. for (i = 0; pinmux->pinmux[i].reg != 0xffffffff; i++) {
  188. pimux_locktable[pinmux->pinmux[i].reg] &=
  189. ~(pinmux->pinmux[i].clrmask | pinmux->pinmux[i].setmask);
  190. }
  191. for (i = 0; pinmux->pinmux[i].reg != 0xffffffff; i++) {
  192. clrbits_le32(pimux_reg_addr[pinmux->pinmux[i].reg],
  193. pinmux->pinmux[i].setmask);
  194. }
  195. spin_unlock_irqrestore(&lock, flags);
  196. return 0;
  197. }
  198. EXPORT_SYMBOL(pinmux_clr);
  199. int32_t pinmux_set_locktable(pinmux_set_t * pinmux)
  200. {
  201. ulong flags;
  202. int i;
  203. if (pinmux == NULL)
  204. return -4;
  205. spin_lock_irqsave(&lock, flags);
  206. for (i = 0; pinmux->pinmux[i].reg != 0xffffffff; i++) {
  207. pimux_locktable[pinmux->pinmux[i].reg] |=
  208. pinmux->pinmux[i].clrmask | pinmux->pinmux[i].setmask;
  209. clrsetbits_le32(pimux_reg_addr[pinmux->pinmux[i].reg],
  210. pinmux->pinmux[i].clrmask,
  211. pinmux->pinmux[i].setmask);
  212. }
  213. spin_unlock_irqrestore(&lock, flags);
  214. return 0;
  215. }
  216. EXPORT_SYMBOL(pinmux_set_locktable);