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