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