summaryrefslogtreecommitdiffstats
path: root/openwrt/package/linux/kernel-source/drivers/pcmcia/bcm4710_pcmcia.c
blob: 6e3da040c894994a17f3d457a17f95fcd3d3bc63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
 * BCM4710 specific pcmcia routines.
 *
 * Copyright 2004, Broadcom Corporation
 * All Rights Reserved.
 * 
 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
 *
 * $Id$
 */
#include <linux/module.h>
#include <linux/init.h>
#include <linux/config.h>
#include <linux/delay.h>
#include <linux/ioport.h>
#include <linux/kernel.h>
#include <linux/tqueue.h>
#include <linux/timer.h>
#include <linux/mm.h>
#include <linux/proc_fs.h>
#include <linux/version.h>
#include <linux/types.h>
#include <linux/pci.h>

#include <pcmcia/version.h>
#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/ss.h>
#include <pcmcia/bulkmem.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/bus_ops.h>
#include "cs_internal.h"

#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.h>


#include <typedefs.h>
#include <bcmdevs.h>
#include <bcm4710.h>
#include <sbconfig.h>
#include <sbextif.h>

#include "bcm4710pcmcia.h"

/* Use a static var for irq dev_id */
static int bcm47xx_pcmcia_dev_id;

/* Do we think we have a card or not? */
static int bcm47xx_pcmcia_present = 0;


static void bcm4710_pcmcia_reset(void)
{
	extifregs_t *eir;
	unsigned long s;
	uint32 out0, out1, outen;


	eir = (extifregs_t *) ioremap_nocache(BCM4710_REG_EXTIF, sizeof(extifregs_t));

	save_and_cli(s);

	/* Use gpio7 to reset the pcmcia slot */
	outen = readl(&eir->gpio[0].outen);
	outen |= BCM47XX_PCMCIA_RESET;
	out0 = readl(&eir->gpio[0].out);
	out0 &= ~(BCM47XX_PCMCIA_RESET);
	out1 = out0 | BCM47XX_PCMCIA_RESET;

	writel(out0, &eir->gpio[0].out);
	writel(outen, &eir->gpio[0].outen);
	mdelay(1);
	writel(out1, &eir->gpio[0].out);
	mdelay(1);
	writel(out0, &eir->gpio[0].out);

	restore_flags(s);
}


static int bcm4710_pcmcia_init(struct pcmcia_init *init)
{
	struct pci_dev *pdev;
	extifregs_t *eir;
	uint32 outen, intp, intm, tmp;
	uint16 *attrsp;
	int rc = 0, i;
	extern unsigned long bcm4710_cpu_cycle;


	if (!(pdev = pci_find_device(VENDOR_BROADCOM, SB_EXTIF, NULL))) {
		printk(KERN_ERR "bcm4710_pcmcia: extif not found\n");
		return -ENODEV;
	}
	eir = (extifregs_t *) ioremap_nocache(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));

	/* Initialize the pcmcia i/f: 16bit no swap */
	writel(CF_EM_PCMCIA | CF_DS | CF_EN, &eir->pcmcia_config);

#ifdef	notYet

	/* Set the timing for memory accesses */
	tmp = (19 / bcm4710_cpu_cycle) << 24;		/* W3 = 10nS */
	tmp = tmp | ((29 / bcm4710_cpu_cycle) << 16);	/* W2 = 20nS */
	tmp = tmp | ((109 / bcm4710_cpu_cycle) << 8);	/* W1 = 100nS */
	tmp = tmp | (129 / bcm4710_cpu_cycle);		/* W0 = 120nS */
	writel(tmp, &eir->pcmcia_memwait);		/* 0x01020a0c for a 100Mhz clock */

	/* Set the timing for I/O accesses */
	tmp = (19 / bcm4710_cpu_cycle) << 24;		/* W3 = 10nS */
	tmp = tmp | ((29 / bcm4710_cpu_cycle) << 16);	/* W2 = 20nS */
	tmp = tmp | ((109 / bcm4710_cpu_cycle) << 8);	/* W1 = 100nS */
	tmp = tmp | (129 / bcm4710_cpu_cycle);		/* W0 = 120nS */
	writel(tmp, &eir->pcmcia_iowait);		/* 0x01020a0c for a 100Mhz clock */

	/* Set the timing for attribute accesses */
	tmp = (19 / bcm4710_cpu_cycle) << 24;		/* W3 = 10nS */
	tmp = tmp | ((29 / bcm4710_cpu_cycle) << 16);	/* W2 = 20nS */
	tmp = tmp | ((109 / bcm4710_cpu_cycle) << 8);	/* W1 = 100nS */
	tmp = tmp | (129 / bcm4710_cpu_cycle);		/* W0 = 120nS */
	writel(tmp, &eir->pcmcia_attrwait);		/* 0x01020a0c for a 100Mhz clock */

#endif
	/* Make sure gpio0 and gpio5 are inputs */
	outen = readl(&eir->gpio[0].outen);
	outen &= ~(BCM47XX_PCMCIA_WP | BCM47XX_PCMCIA_STSCHG | BCM47XX_PCMCIA_RESET);
	writel(outen, &eir->gpio[0].outen);

	/* Issue a reset to the pcmcia socket */
	bcm4710_pcmcia_reset();

#ifdef	DO_BCM47XX_PCMCIA_INTERRUPTS
	/* Setup gpio5 to be the STSCHG interrupt */
	intp = readl(&eir->gpiointpolarity);
	writel(intp | BCM47XX_PCMCIA_STSCHG, &eir->gpiointpolarity);	/* Active low */
	intm = readl(&eir->gpiointmask);
	writel(intm | BCM47XX_PCMCIA_STSCHG, &eir->gpiointmask);	/* Enable it */
#endif

	DEBUG(2, "bcm4710_pcmcia after reset:\n");
	DEBUG(2, "\textstatus\t= 0x%08x:\n", readl(&eir->extstatus));
	DEBUG(2, "\tpcmcia_config\t= 0x%08x:\n", readl(&eir->pcmcia_config));
	DEBUG(2, "\tpcmcia_memwait\t= 0x%08x:\n", readl(&eir->pcmcia_memwait));
	DEBUG(2, "\tpcmcia_attrwait\t= 0x%08x:\n", readl(&eir->pcmcia_attrwait));
	DEBUG(2, "\tpcmcia_iowait\t= 0x%08x:\n", readl(&eir->pcmcia_iowait));
	DEBUG(2, "\tgpioin\t\t= 0x%08x:\n", readl(&eir->gpioin));
	DEBUG(2, "\tgpio_outen0\t= 0x%08x:\n", readl(&eir->gpio[0].outen));
	DEBUG(2, "\tgpio_out0\t= 0x%08x:\n", readl(&eir->gpio[0].out));
	DEBUG(2, "\tgpiointpolarity\t= 0x%08x:\n", readl(&eir->gpiointpolarity));
	DEBUG(2, "\tgpiointmask\t= 0x%08x:\n", readl(&eir->gpiointmask));

#ifdef	DO_BCM47XX_PCMCIA_INTERRUPTS
	/* Request pcmcia interrupt */
	rc =  request_irq(BCM47XX_PCMCIA_IRQ, init->handler, SA_INTERRUPT,
			  "PCMCIA Interrupt", &bcm47xx_pcmcia_dev_id);
#endif

	attrsp = (uint16 *)ioremap_nocache(EXTIF_PCMCIA_CFGBASE(BCM4710_EXTIF), 0x1000);
	tmp = readw(&attrsp[0]);
	DEBUG(2, "\tattr[0] = 0x%04x\n", tmp);
	if ((tmp == 0x7fff) || (tmp == 0x7f00)) {
		bcm47xx_pcmcia_present = 0;
	} else {
		bcm47xx_pcmcia_present = 1;
	}

	/* There's only one socket */
	return 1;
}

static int bcm4710_pcmcia_shutdown(void)
{
	extifregs_t *eir;
	uint32 intm;

	eir = (extifregs_t *) ioremap_nocache(BCM4710_REG_EXTIF, sizeof(extifregs_t));

	/* Disable the pcmcia i/f */
	writel(0, &eir->pcmcia_config);

	/* Reset gpio's */
	intm = readl(&eir->gpiointmask);
	writel(intm & ~BCM47XX_PCMCIA_STSCHG, &eir->gpiointmask);	/* Disable it */

	free_irq(BCM47XX_PCMCIA_IRQ, &bcm47xx_pcmcia_dev_id);

	return 0;
}

static int 
bcm4710_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
{
	extifregs_t *eir;

	eir = (extifregs_t *) ioremap_nocache(BCM4710_REG_EXTIF, sizeof(extifregs_t));


	if (sock != 0) {
		printk(KERN_ERR "bcm4710 socket_state bad sock %d\n", sock);
		return -1;
	}

	if (bcm47xx_pcmcia_present) {
		state->detect = 1;
		state->ready = 1;
		state->bvd1 = 1;
		state->bvd2 = 1;
		state->wrprot = (readl(&eir->gpioin) & BCM47XX_PCMCIA_WP) == BCM47XX_PCMCIA_WP; 
		state->vs_3v = 0;
		state->vs_Xv = 0;
	} else {
		state->detect = 0;
		state->ready = 0;
	}

	return 1;
}


static int bcm4710_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
{
	if (info->sock >= BCM47XX_PCMCIA_MAX_SOCK) return -1;

	info->irq = BCM47XX_PCMCIA_IRQ;		

	return 0;
}


static int 
bcm4710_pcmcia_configure_socket(const struct pcmcia_configure *configure)
{
	if (configure->sock >= BCM47XX_PCMCIA_MAX_SOCK) return -1;


	DEBUG(2, "Vcc %dV Vpp %dV output %d speaker %d reset %d\n", configure->vcc,
	      configure->vpp, configure->output, configure->speaker, configure->reset);

	if ((configure->vcc != 50) || (configure->vpp != 50)) {
		printk("%s: bad Vcc/Vpp (%d:%d)\n", __FUNCTION__, configure->vcc, 
		       configure->vpp);
	}

	if (configure->reset) {
		/* Issue a reset to the pcmcia socket */
		DEBUG(1, "%s: Reseting socket\n", __FUNCTION__);
		bcm4710_pcmcia_reset();
	}


	return 0;
}

struct pcmcia_low_level bcm4710_pcmcia_ops = { 
	bcm4710_pcmcia_init,
	bcm4710_pcmcia_shutdown,
	bcm4710_pcmcia_socket_state,
	bcm4710_pcmcia_get_irq_info,
	bcm4710_pcmcia_configure_socket
};