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