Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph...
[pandora-kernel.git] / drivers / pcmcia / au1000_pb1x00.c
1 /*
2  *
3  * Alchemy Semi Pb1000 boards specific pcmcia routines.
4  *
5  * Copyright 2002 MontaVista Software Inc.
6  * Author: 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 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/ioport.h>
28 #include <linux/kernel.h>
29 #include <linux/timer.h>
30 #include <linux/mm.h>
31 #include <linux/proc_fs.h>
32 #include <linux/types.h>
33
34 #include <pcmcia/cs.h>
35 #include <pcmcia/ss.h>
36 #include <pcmcia/cistpl.h>
37
38 #include <asm/io.h>
39 #include <asm/irq.h>
40 #include <asm/system.h>
41
42 #include <asm/au1000.h>
43 #include <asm/au1000_pcmcia.h>
44
45 #define debug(fmt, arg...) do { } while (0)
46
47 #include <asm/pb1000.h>
48 #define PCMCIA_IRQ AU1000_GPIO_15
49
50 static int pb1x00_pcmcia_init(struct pcmcia_init *init)
51 {
52         u16 pcr;
53         pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
54
55         au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
56         au_sync_delay(100);
57         au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
58         au_sync();
59
60         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
61         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
62         au_writel(pcr, PB1000_PCR);
63         au_sync_delay(20);
64           
65         return PCMCIA_NUM_SOCKS;
66 }
67
68 static int pb1x00_pcmcia_shutdown(void)
69 {
70         u16 pcr;
71         pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
72         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
73         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
74         au_writel(pcr, PB1000_PCR);
75         au_sync_delay(20);
76         return 0;
77 }
78
79 static int 
80 pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
81 {
82         u32 inserted0, inserted1;
83         u16 vs0, vs1;
84
85         vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
86         inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
87         inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
88         vs0 = (vs0 >> 4) & 0x3;
89         vs1 = (vs1 >> 12) & 0x3;
90
91         state->ready = 0;
92         state->vs_Xv = 0;
93         state->vs_3v = 0;
94         state->detect = 0;
95
96         if (sock == 0) {
97                 if (inserted0) {
98                         switch (vs0) {
99                                 case 0:
100                                 case 2:
101                                         state->vs_3v=1;
102                                         break;
103                                 case 3: /* 5V */
104                                         break;
105                                 default:
106                                         /* return without setting 'detect' */
107                                         printk(KERN_ERR "pb1x00 bad VS (%d)\n",
108                                                         vs0);
109                                         return 0;
110                         }
111                         state->detect = 1;
112                 }
113         }
114         else  {
115                 if (inserted1) {
116                         switch (vs1) {
117                                 case 0:
118                                 case 2:
119                                         state->vs_3v=1;
120                                         break;
121                                 case 3: /* 5V */
122                                         break;
123                                 default:
124                                         /* return without setting 'detect' */
125                                         printk(KERN_ERR "pb1x00 bad VS (%d)\n",
126                                                         vs1);
127                                         return 0;
128                         }
129                         state->detect = 1;
130                 }
131         }
132
133         if (state->detect) {
134                 state->ready = 1;
135         }
136
137         state->bvd1=1;
138         state->bvd2=1;
139         state->wrprot=0; 
140         return 1;
141 }
142
143
144 static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
145 {
146
147         if(info->sock > PCMCIA_MAX_SOCK) return -1;
148
149         /*
150          * Even in the case of the Pb1000, both sockets are connected
151          * to the same irq line.
152          */
153         info->irq = PCMCIA_IRQ;
154
155         return 0;
156 }
157
158
159 static int 
160 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
161 {
162         u16 pcr;
163
164         if(configure->sock > PCMCIA_MAX_SOCK) return -1;
165
166         pcr = au_readl(PB1000_PCR);
167
168         if (configure->sock == 0) {
169                 pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 | 
170                                 PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
171         }
172         else  {
173                 pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 | 
174                                 PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
175         }
176
177         pcr &= ~PCR_SLOT_0_RST;
178         debug("Vcc %dV Vpp %dV, pcr %x\n", 
179                         configure->vcc, configure->vpp, pcr);
180         switch(configure->vcc){
181                 case 0:  /* Vcc 0 */
182                         switch(configure->vpp) {
183                                 case 0:
184                                         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
185                                                         configure->sock);
186                                         break;
187                                 case 12:
188                                         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
189                                                         configure->sock);
190                                         break;
191                                 case 50:
192                                         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
193                                                         configure->sock);
194                                         break;
195                                 case 33:
196                                         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
197                                                         configure->sock);
198                                         break;
199                                 default:
200                                         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
201                                                         configure->sock);
202                                         printk("%s: bad Vcc/Vpp (%d:%d)\n", 
203                                                         __func__,
204                                                         configure->vcc, 
205                                                         configure->vpp);
206                                         break;
207                         }
208                         break;
209                 case 50: /* Vcc 5V */
210                         switch(configure->vpp) {
211                                 case 0:
212                                         pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
213                                                         configure->sock);
214                                         break;
215                                 case 50:
216                                         pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
217                                                         configure->sock);
218                                         break;
219                                 case 12:
220                                         pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
221                                                         configure->sock);
222                                         break;
223                                 case 33:
224                                         pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
225                                                         configure->sock);
226                                         break;
227                                 default:
228                                         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
229                                                         configure->sock);
230                                         printk("%s: bad Vcc/Vpp (%d:%d)\n", 
231                                                         __func__,
232                                                         configure->vcc, 
233                                                         configure->vpp);
234                                         break;
235                         }
236                         break;
237                 case 33: /* Vcc 3.3V */
238                         switch(configure->vpp) {
239                                 case 0:
240                                         pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
241                                                         configure->sock);
242                                         break;
243                                 case 50:
244                                         pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
245                                                         configure->sock);
246                                         break;
247                                 case 12:
248                                         pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
249                                                         configure->sock);
250                                         break;
251                                 case 33:
252                                         pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
253                                                         configure->sock);
254                                         break;
255                                 default:
256                                         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
257                                                         configure->sock);
258                                         printk("%s: bad Vcc/Vpp (%d:%d)\n", 
259                                                         __func__,
260                                                         configure->vcc, 
261                                                         configure->vpp);
262                                         break;
263                         }
264                         break;
265                 default: /* what's this ? */
266                         pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
267                         printk(KERN_ERR "%s: bad Vcc %d\n", 
268                                         __func__, configure->vcc);
269                         break;
270         }
271
272         if (configure->sock == 0) {
273         pcr &= ~(PCR_SLOT_0_RST);
274                 if (configure->reset)
275                 pcr |= PCR_SLOT_0_RST;
276         }
277         else {
278                 pcr &= ~(PCR_SLOT_1_RST);
279                 if (configure->reset)
280                         pcr |= PCR_SLOT_1_RST;
281         }
282         au_writel(pcr, PB1000_PCR);
283         au_sync_delay(300);
284
285         return 0;
286 }
287
288
289 struct pcmcia_low_level pb1x00_pcmcia_ops = { 
290         pb1x00_pcmcia_init,
291         pb1x00_pcmcia_shutdown,
292         pb1x00_pcmcia_socket_state,
293         pb1x00_pcmcia_get_irq_info,
294         pb1x00_pcmcia_configure_socket
295 };