au1000_xxs1500.c 4.3 KB

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