au1000_pb1x00.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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/cs_types.h>
  34. #include <pcmcia/cs.h>
  35. #include <pcmcia/ss.h>
  36. #include <pcmcia/cistpl.h>
  37. #include <pcmcia/bus_ops.h>
  38. #include <asm/io.h>
  39. #include <asm/irq.h>
  40. #include <asm/system.h>
  41. #include <asm/au1000.h>
  42. #include <asm/au1000_pcmcia.h>
  43. #define debug(fmt, arg...) do { } while (0)
  44. #include <asm/pb1000.h>
  45. #define PCMCIA_IRQ AU1000_GPIO_15
  46. static int pb1x00_pcmcia_init(struct pcmcia_init *init)
  47. {
  48. u16 pcr;
  49. pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
  50. au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
  51. au_sync_delay(100);
  52. au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
  53. au_sync();
  54. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
  55. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
  56. au_writel(pcr, PB1000_PCR);
  57. au_sync_delay(20);
  58. return PCMCIA_NUM_SOCKS;
  59. }
  60. static int pb1x00_pcmcia_shutdown(void)
  61. {
  62. u16 pcr;
  63. pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
  64. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
  65. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
  66. au_writel(pcr, PB1000_PCR);
  67. au_sync_delay(20);
  68. return 0;
  69. }
  70. static int
  71. pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
  72. {
  73. u32 inserted0, inserted1;
  74. u16 vs0, vs1;
  75. vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
  76. inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
  77. inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
  78. vs0 = (vs0 >> 4) & 0x3;
  79. vs1 = (vs1 >> 12) & 0x3;
  80. state->ready = 0;
  81. state->vs_Xv = 0;
  82. state->vs_3v = 0;
  83. state->detect = 0;
  84. if (sock == 0) {
  85. if (inserted0) {
  86. switch (vs0) {
  87. case 0:
  88. case 2:
  89. state->vs_3v=1;
  90. break;
  91. case 3: /* 5V */
  92. break;
  93. default:
  94. /* return without setting 'detect' */
  95. printk(KERN_ERR "pb1x00 bad VS (%d)\n",
  96. vs0);
  97. return 0;
  98. }
  99. state->detect = 1;
  100. }
  101. }
  102. else {
  103. if (inserted1) {
  104. switch (vs1) {
  105. case 0:
  106. case 2:
  107. state->vs_3v=1;
  108. break;
  109. case 3: /* 5V */
  110. break;
  111. default:
  112. /* return without setting 'detect' */
  113. printk(KERN_ERR "pb1x00 bad VS (%d)\n",
  114. vs1);
  115. return 0;
  116. }
  117. state->detect = 1;
  118. }
  119. }
  120. if (state->detect) {
  121. state->ready = 1;
  122. }
  123. state->bvd1=1;
  124. state->bvd2=1;
  125. state->wrprot=0;
  126. return 1;
  127. }
  128. static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
  129. {
  130. if(info->sock > PCMCIA_MAX_SOCK) return -1;
  131. /*
  132. * Even in the case of the Pb1000, both sockets are connected
  133. * to the same irq line.
  134. */
  135. info->irq = PCMCIA_IRQ;
  136. return 0;
  137. }
  138. static int
  139. pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
  140. {
  141. u16 pcr;
  142. if(configure->sock > PCMCIA_MAX_SOCK) return -1;
  143. pcr = au_readl(PB1000_PCR);
  144. if (configure->sock == 0) {
  145. pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 |
  146. PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
  147. }
  148. else {
  149. pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 |
  150. PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
  151. }
  152. pcr &= ~PCR_SLOT_0_RST;
  153. debug("Vcc %dV Vpp %dV, pcr %x\n",
  154. configure->vcc, configure->vpp, pcr);
  155. switch(configure->vcc){
  156. case 0: /* Vcc 0 */
  157. switch(configure->vpp) {
  158. case 0:
  159. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
  160. configure->sock);
  161. break;
  162. case 12:
  163. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
  164. configure->sock);
  165. break;
  166. case 50:
  167. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
  168. configure->sock);
  169. break;
  170. case 33:
  171. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
  172. configure->sock);
  173. break;
  174. default:
  175. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
  176. configure->sock);
  177. printk("%s: bad Vcc/Vpp (%d:%d)\n",
  178. __func__,
  179. configure->vcc,
  180. configure->vpp);
  181. break;
  182. }
  183. break;
  184. case 50: /* Vcc 5V */
  185. switch(configure->vpp) {
  186. case 0:
  187. pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
  188. configure->sock);
  189. break;
  190. case 50:
  191. pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
  192. configure->sock);
  193. break;
  194. case 12:
  195. pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
  196. configure->sock);
  197. break;
  198. case 33:
  199. pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
  200. configure->sock);
  201. break;
  202. default:
  203. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
  204. configure->sock);
  205. printk("%s: bad Vcc/Vpp (%d:%d)\n",
  206. __func__,
  207. configure->vcc,
  208. configure->vpp);
  209. break;
  210. }
  211. break;
  212. case 33: /* Vcc 3.3V */
  213. switch(configure->vpp) {
  214. case 0:
  215. pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
  216. configure->sock);
  217. break;
  218. case 50:
  219. pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
  220. configure->sock);
  221. break;
  222. case 12:
  223. pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
  224. configure->sock);
  225. break;
  226. case 33:
  227. pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
  228. configure->sock);
  229. break;
  230. default:
  231. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
  232. configure->sock);
  233. printk("%s: bad Vcc/Vpp (%d:%d)\n",
  234. __func__,
  235. configure->vcc,
  236. configure->vpp);
  237. break;
  238. }
  239. break;
  240. default: /* what's this ? */
  241. pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
  242. printk(KERN_ERR "%s: bad Vcc %d\n",
  243. __func__, configure->vcc);
  244. break;
  245. }
  246. if (configure->sock == 0) {
  247. pcr &= ~(PCR_SLOT_0_RST);
  248. if (configure->reset)
  249. pcr |= PCR_SLOT_0_RST;
  250. }
  251. else {
  252. pcr &= ~(PCR_SLOT_1_RST);
  253. if (configure->reset)
  254. pcr |= PCR_SLOT_1_RST;
  255. }
  256. au_writel(pcr, PB1000_PCR);
  257. au_sync_delay(300);
  258. return 0;
  259. }
  260. struct pcmcia_low_level pb1x00_pcmcia_ops = {
  261. pb1x00_pcmcia_init,
  262. pb1x00_pcmcia_shutdown,
  263. pb1x00_pcmcia_socket_state,
  264. pb1x00_pcmcia_get_irq_info,
  265. pb1x00_pcmcia_configure_socket
  266. };