au1000_pb1x00.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. *
  3. * Alchemy Semi Pb1000 boards specific pcmcia routines.
  4. *
  5. * Copyright 2002 MontaVista Software Inc.
  6. * Author: MontaVista Software, Inc.
  7. * ppopov@mvista.com or source@mvista.com
  8. *
  9. * ########################################################################
  10. *
  11. * This program is free software; you can distribute it and/or modify it
  12. * under the terms of the GNU General Public License (Version 2) as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. * for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  23. */
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/delay.h>
  27. #include <linux/ioport.h>
  28. #include <linux/kernel.h>
  29. #include <linux/timer.h>
  30. #include <linux/mm.h>
  31. #include <linux/proc_fs.h>
  32. #include <linux/types.h>
  33. #include <pcmcia/ss.h>
  34. #include <pcmcia/cistpl.h>
  35. #include <asm/io.h>
  36. #include <asm/irq.h>
  37. #include <asm/system.h>
  38. #include <asm/au1000.h>
  39. #include <asm/au1000_pcmcia.h>
  40. #define debug(fmt, arg...) do { } while (0)
  41. #include <asm/pb1000.h>
  42. #define PCMCIA_IRQ AU1000_GPIO_15
  43. static int pb1x00_pcmcia_init(struct pcmcia_init *init)
  44. {
  45. u16 pcr;
  46. pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
  47. au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
  48. au_sync_delay(100);
  49. au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
  50. au_sync();
  51. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
  52. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
  53. au_writel(pcr, PB1000_PCR);
  54. au_sync_delay(20);
  55. return PCMCIA_NUM_SOCKS;
  56. }
  57. static int pb1x00_pcmcia_shutdown(void)
  58. {
  59. u16 pcr;
  60. pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
  61. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
  62. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
  63. au_writel(pcr, PB1000_PCR);
  64. au_sync_delay(20);
  65. return 0;
  66. }
  67. static int
  68. pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
  69. {
  70. u32 inserted0, inserted1;
  71. u16 vs0, vs1;
  72. vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
  73. inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
  74. inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
  75. vs0 = (vs0 >> 4) & 0x3;
  76. vs1 = (vs1 >> 12) & 0x3;
  77. state->ready = 0;
  78. state->vs_Xv = 0;
  79. state->vs_3v = 0;
  80. state->detect = 0;
  81. if (sock == 0) {
  82. if (inserted0) {
  83. switch (vs0) {
  84. case 0:
  85. case 2:
  86. state->vs_3v=1;
  87. break;
  88. case 3: /* 5V */
  89. break;
  90. default:
  91. /* return without setting 'detect' */
  92. printk(KERN_ERR "pb1x00 bad VS (%d)\n",
  93. vs0);
  94. return 0;
  95. }
  96. state->detect = 1;
  97. }
  98. }
  99. else {
  100. if (inserted1) {
  101. switch (vs1) {
  102. case 0:
  103. case 2:
  104. state->vs_3v=1;
  105. break;
  106. case 3: /* 5V */
  107. break;
  108. default:
  109. /* return without setting 'detect' */
  110. printk(KERN_ERR "pb1x00 bad VS (%d)\n",
  111. vs1);
  112. return 0;
  113. }
  114. state->detect = 1;
  115. }
  116. }
  117. if (state->detect) {
  118. state->ready = 1;
  119. }
  120. state->bvd1=1;
  121. state->bvd2=1;
  122. state->wrprot=0;
  123. return 1;
  124. }
  125. static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
  126. {
  127. if(info->sock > PCMCIA_MAX_SOCK) return -1;
  128. /*
  129. * Even in the case of the Pb1000, both sockets are connected
  130. * to the same irq line.
  131. */
  132. info->irq = PCMCIA_IRQ;
  133. return 0;
  134. }
  135. static int
  136. pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
  137. {
  138. u16 pcr;
  139. if(configure->sock > PCMCIA_MAX_SOCK) return -1;
  140. pcr = au_readl(PB1000_PCR);
  141. if (configure->sock == 0) {
  142. pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 |
  143. PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
  144. }
  145. else {
  146. pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 |
  147. PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
  148. }
  149. pcr &= ~PCR_SLOT_0_RST;
  150. debug("Vcc %dV Vpp %dV, pcr %x\n",
  151. configure->vcc, configure->vpp, pcr);
  152. switch(configure->vcc){
  153. case 0: /* Vcc 0 */
  154. switch(configure->vpp) {
  155. case 0:
  156. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
  157. configure->sock);
  158. break;
  159. case 12:
  160. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
  161. configure->sock);
  162. break;
  163. case 50:
  164. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
  165. configure->sock);
  166. break;
  167. case 33:
  168. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
  169. configure->sock);
  170. break;
  171. default:
  172. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
  173. configure->sock);
  174. printk("%s: bad Vcc/Vpp (%d:%d)\n",
  175. __func__,
  176. configure->vcc,
  177. configure->vpp);
  178. break;
  179. }
  180. break;
  181. case 50: /* Vcc 5V */
  182. switch(configure->vpp) {
  183. case 0:
  184. pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
  185. configure->sock);
  186. break;
  187. case 50:
  188. pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
  189. configure->sock);
  190. break;
  191. case 12:
  192. pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
  193. configure->sock);
  194. break;
  195. case 33:
  196. pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
  197. configure->sock);
  198. break;
  199. default:
  200. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
  201. configure->sock);
  202. printk("%s: bad Vcc/Vpp (%d:%d)\n",
  203. __func__,
  204. configure->vcc,
  205. configure->vpp);
  206. break;
  207. }
  208. break;
  209. case 33: /* Vcc 3.3V */
  210. switch(configure->vpp) {
  211. case 0:
  212. pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
  213. configure->sock);
  214. break;
  215. case 50:
  216. pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
  217. configure->sock);
  218. break;
  219. case 12:
  220. pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
  221. configure->sock);
  222. break;
  223. case 33:
  224. pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
  225. configure->sock);
  226. break;
  227. default:
  228. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
  229. configure->sock);
  230. printk("%s: bad Vcc/Vpp (%d:%d)\n",
  231. __func__,
  232. configure->vcc,
  233. configure->vpp);
  234. break;
  235. }
  236. break;
  237. default: /* what's this ? */
  238. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
  239. printk(KERN_ERR "%s: bad Vcc %d\n",
  240. __func__, configure->vcc);
  241. break;
  242. }
  243. if (configure->sock == 0) {
  244. pcr &= ~(PCR_SLOT_0_RST);
  245. if (configure->reset)
  246. pcr |= PCR_SLOT_0_RST;
  247. }
  248. else {
  249. pcr &= ~(PCR_SLOT_1_RST);
  250. if (configure->reset)
  251. pcr |= PCR_SLOT_1_RST;
  252. }
  253. au_writel(pcr, PB1000_PCR);
  254. au_sync_delay(300);
  255. return 0;
  256. }
  257. struct pcmcia_low_level pb1x00_pcmcia_ops = {
  258. pb1x00_pcmcia_init,
  259. pb1x00_pcmcia_shutdown,
  260. pb1x00_pcmcia_socket_state,
  261. pb1x00_pcmcia_get_irq_info,
  262. pb1x00_pcmcia_configure_socket
  263. };