au1000_xxs1500.c 4.3 KB

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