au1000_xxs1500.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. *
  3. * MyCable board specific pcmcia routines.
  4. *
  5. * Copyright 2003 MontaVista Software Inc.
  6. * Author: Pete Popov, 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. * ########################################################################
  25. *
  26. *
  27. */
  28. #include <linux/module.h>
  29. #include <linux/init.h>
  30. #include <linux/delay.h>
  31. #include <linux/ioport.h>
  32. #include <linux/kernel.h>
  33. #include <linux/timer.h>
  34. #include <linux/mm.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/types.h>
  37. #include <pcmcia/cs_types.h>
  38. #include <pcmcia/cs.h>
  39. #include <pcmcia/ss.h>
  40. #include <pcmcia/cistpl.h>
  41. #include <pcmcia/bus_ops.h>
  42. #include <asm/io.h>
  43. #include <asm/irq.h>
  44. #include <asm/system.h>
  45. #include <asm/au1000.h>
  46. #include <asm/au1000_pcmcia.h>
  47. #define PCMCIA_MAX_SOCK 0
  48. #define PCMCIA_NUM_SOCKS (PCMCIA_MAX_SOCK + 1)
  49. #define PCMCIA_IRQ AU1000_GPIO_4
  50. #if 0
  51. #define DEBUG(x, args...) printk(__func__ ": " x, ##args)
  52. #else
  53. #define DEBUG(x,args...)
  54. #endif
  55. static int xxs1500_pcmcia_init(struct pcmcia_init *init)
  56. {
  57. return PCMCIA_NUM_SOCKS;
  58. }
  59. static int xxs1500_pcmcia_shutdown(void)
  60. {
  61. /* turn off power */
  62. au_writel(au_readl(GPIO2_PINSTATE) | (1<<14)|(1<<30),
  63. GPIO2_OUTPUT);
  64. au_sync_delay(100);
  65. /* assert reset */
  66. au_writel(au_readl(GPIO2_PINSTATE) | (1<<4)|(1<<20),
  67. GPIO2_OUTPUT);
  68. au_sync_delay(100);
  69. return 0;
  70. }
  71. static int
  72. xxs1500_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
  73. {
  74. u32 inserted; u32 vs;
  75. unsigned long gpio, gpio2;
  76. if(sock > PCMCIA_MAX_SOCK) return -1;
  77. gpio = au_readl(SYS_PINSTATERD);
  78. gpio2 = au_readl(GPIO2_PINSTATE);
  79. vs = gpio2 & ((1<<8) | (1<<9));
  80. inserted = (!(gpio & 0x1) && !(gpio & 0x2));
  81. state->ready = 0;
  82. state->vs_Xv = 0;
  83. state->vs_3v = 0;
  84. state->detect = 0;
  85. if (inserted) {
  86. switch (vs) {
  87. case 0:
  88. case 1:
  89. case 2:
  90. state->vs_3v=1;
  91. break;
  92. case 3: /* 5V */
  93. default:
  94. /* return without setting 'detect' */
  95. printk(KERN_ERR "au1x00_cs: unsupported VS\n",
  96. vs);
  97. return;
  98. }
  99. state->detect = 1;
  100. }
  101. if (state->detect) {
  102. state->ready = 1;
  103. }
  104. state->bvd1= gpio2 & (1<<10);
  105. state->bvd2 = gpio2 & (1<<11);
  106. state->wrprot=0;
  107. return 1;
  108. }
  109. static int xxs1500_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
  110. {
  111. if(info->sock > PCMCIA_MAX_SOCK) return -1;
  112. info->irq = PCMCIA_IRQ;
  113. return 0;
  114. }
  115. static int
  116. xxs1500_pcmcia_configure_socket(const struct pcmcia_configure *configure)
  117. {
  118. if(configure->sock > PCMCIA_MAX_SOCK) return -1;
  119. DEBUG("Vcc %dV Vpp %dV, reset %d\n",
  120. configure->vcc, configure->vpp, configure->reset);
  121. switch(configure->vcc){
  122. case 33: /* Vcc 3.3V */
  123. /* turn on power */
  124. DEBUG("turn on power\n");
  125. au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<14))|(1<<30),
  126. GPIO2_OUTPUT);
  127. au_sync_delay(100);
  128. break;
  129. case 50: /* Vcc 5V */
  130. default: /* what's this ? */
  131. printk(KERN_ERR "au1x00_cs: unsupported VCC\n");
  132. case 0: /* Vcc 0 */
  133. /* turn off power */
  134. au_sync_delay(100);
  135. au_writel(au_readl(GPIO2_PINSTATE) | (1<<14)|(1<<30),
  136. GPIO2_OUTPUT);
  137. break;
  138. }
  139. if (!configure->reset) {
  140. DEBUG("deassert reset\n");
  141. au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<4))|(1<<20),
  142. GPIO2_OUTPUT);
  143. au_sync_delay(100);
  144. au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<5))|(1<<21),
  145. GPIO2_OUTPUT);
  146. }
  147. else {
  148. DEBUG("assert reset\n");
  149. au_writel(au_readl(GPIO2_PINSTATE) | (1<<4)|(1<<20),
  150. GPIO2_OUTPUT);
  151. }
  152. au_sync_delay(100);
  153. return 0;
  154. }
  155. struct pcmcia_low_level xxs1500_pcmcia_ops = {
  156. xxs1500_pcmcia_init,
  157. xxs1500_pcmcia_shutdown,
  158. xxs1500_pcmcia_socket_state,
  159. xxs1500_pcmcia_get_irq_info,
  160. xxs1500_pcmcia_configure_socket
  161. };