1 --- a/drivers/pcmcia/Makefile
2 +++ b/drivers/pcmcia/Makefile
3 @@ -69,4 +69,4 @@ sa1100_cs-$(CONFIG_SA1100_SIMPAD) += sa
4 pxa2xx_cs-$(CONFIG_ARCH_LUBBOCK) += pxa2xx_lubbock.o sa1111_generic.o
5 pxa2xx_cs-$(CONFIG_MACH_MAINSTONE) += pxa2xx_mainstone.o
6 pxa2xx_cs-$(CONFIG_PXA_SHARPSL) += pxa2xx_sharpsl.o
8 +pxa2xx_cs-$(CONFIG_ARCH_GUMSTIX) += pxa2xx_gumstix.o
10 +++ b/drivers/pcmcia/pxa2xx_gumstix.c
13 + * linux/drivers/pcmcia/pxa2xx_gumstix.c
15 + * Gumstix PCMCIA specific routines. Based on Mainstone
17 + * Copyright 2004, Craig Hughes <craig@gumstix.com>
19 + * This program is free software; you can redistribute it and/or modify
20 + * it under the terms of the GNU General Public License version 2 as
21 + * published by the Free Software Foundation.
24 +#include <linux/module.h>
25 +#include <linux/init.h>
26 +#include <linux/kernel.h>
27 +#include <linux/errno.h>
28 +#include <linux/interrupt.h>
29 +#include <linux/device.h>
30 +#include <linux/platform_device.h>
32 +#include <pcmcia/ss.h>
34 +#include <asm/hardware.h>
35 +#include <asm/delay.h>
36 +#include <asm/arch/pxa-regs.h>
40 +#include <asm/arch/gumstix.h>
42 +#include "soc_common.h"
44 +static struct pcmcia_irqs gumstix_pcmcia_irqs0[] = {
45 + { 0, GUMSTIX_S0_nCD_IRQ, "CF0 nCD" },
46 + { 0, GUMSTIX_S0_nSTSCHG_IRQ, "CF0 nSTSCHG" },
49 +static struct pcmcia_irqs gumstix_pcmcia_irqs1[] = {
50 + { 1, GUMSTIX_S1_nCD_IRQ, "CF1 nCD" },
51 + { 1, GUMSTIX_S1_nSTSCHG_IRQ, "CF1 nSTSCHG" },
54 +static int net_cf_vx_mode = 0;
56 +static int gumstix_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
60 + pxa_gpio_mode(GPIO_GUMSTIX_nSTSCHG_0_MD);
61 + pxa_gpio_mode(GPIO_GUMSTIX_nCD_0_MD);
63 + pxa_gpio_mode(GPIO_GUMSTIX_PRDY_nBSY_0_OLD_MD);
65 + pxa_gpio_mode(GPIO_GUMSTIX_PRDY_nBSY_0_MD);
67 + pxa_gpio_mode(GPIO_GUMSTIX_nSTSCHG_1_MD);
68 + pxa_gpio_mode(GPIO_GUMSTIX_nCD_1_MD);
69 + pxa_gpio_mode(GPIO_GUMSTIX_PRDY_nBSY_1_MD);
72 + pxa_gpio_mode(GPIO_GUMSTIX_nPOE_MD);
73 + pxa_gpio_mode(GPIO_GUMSTIX_nPWE_MD);
74 + pxa_gpio_mode(GPIO_GUMSTIX_nPIOR_MD);
75 + pxa_gpio_mode(GPIO_GUMSTIX_nPIOW_MD);
76 + pxa_gpio_mode(GPIO_GUMSTIX_nPCE_1_MD);
77 + pxa_gpio_mode(GPIO_GUMSTIX_nPCE_2_MD);
78 + pxa_gpio_mode(GPIO_GUMSTIX_pSKTSEL_MD);
79 + pxa_gpio_mode(GPIO_GUMSTIX_nPREG_MD);
80 + pxa_gpio_mode(GPIO_GUMSTIX_nPWAIT_MD);
81 + pxa_gpio_mode(GPIO_GUMSTIX_nIOIS16_MD);
83 + skt->irq = (skt->nr == 0) ? ((net_cf_vx_mode == 0) ? GUMSTIX_S0_PRDY_nBSY_IRQ : GUMSTIX_S0_PRDY_nBSY_OLD_IRQ) : GUMSTIX_S1_PRDY_nBSY_IRQ;
85 + return (skt->nr == 0) ? soc_pcmcia_request_irqs(skt, gumstix_pcmcia_irqs0, ARRAY_SIZE(gumstix_pcmcia_irqs0)) :
86 + soc_pcmcia_request_irqs(skt, gumstix_pcmcia_irqs1, ARRAY_SIZE(gumstix_pcmcia_irqs1));
89 +static void gumstix_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
93 + soc_pcmcia_free_irqs(skt, gumstix_pcmcia_irqs0, ARRAY_SIZE(gumstix_pcmcia_irqs0));
95 + soc_pcmcia_free_irqs(skt, gumstix_pcmcia_irqs1, ARRAY_SIZE(gumstix_pcmcia_irqs1));
99 +static void gumstix_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
100 + struct pcmcia_state *state)
102 + unsigned int cd, prdy_nbsy, nbvd1;
105 + cd = GPIO_GUMSTIX_nCD_0;
107 + prdy_nbsy = GPIO_GUMSTIX_PRDY_nBSY_0_OLD;
109 + prdy_nbsy = GPIO_GUMSTIX_PRDY_nBSY_0;
110 + nbvd1 = GPIO_GUMSTIX_nBVD1_0;
112 + cd = GPIO_GUMSTIX_nCD_1;
113 + prdy_nbsy = GPIO_GUMSTIX_PRDY_nBSY_1;
114 + nbvd1 = GPIO_GUMSTIX_nBVD1_1;
116 + state->detect = !(GPLR(cd) & GPIO_bit(cd));
117 + state->ready = !!(GPLR(prdy_nbsy) & GPIO_bit(prdy_nbsy));
118 + state->bvd1 = !!(GPLR(nbvd1) & GPIO_bit(nbvd1));
125 +static int gumstix_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
126 + const socket_state_t *state)
131 +static void gumstix_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
134 + soc_pcmcia_enable_irqs(skt, gumstix_pcmcia_irqs0, ARRAY_SIZE(gumstix_pcmcia_irqs0));
136 + soc_pcmcia_enable_irqs(skt, gumstix_pcmcia_irqs1, ARRAY_SIZE(gumstix_pcmcia_irqs1));
140 +static void gumstix_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
143 + soc_pcmcia_disable_irqs(skt, gumstix_pcmcia_irqs0, ARRAY_SIZE(gumstix_pcmcia_irqs0));
145 + soc_pcmcia_disable_irqs(skt, gumstix_pcmcia_irqs1, ARRAY_SIZE(gumstix_pcmcia_irqs1));
149 +static struct pcmcia_low_level gumstix_pcmcia_ops = {
150 + .owner = THIS_MODULE,
151 + .hw_init = gumstix_pcmcia_hw_init,
152 + .hw_shutdown = gumstix_pcmcia_hw_shutdown,
153 + .socket_state = gumstix_pcmcia_socket_state,
154 + .configure_socket = gumstix_pcmcia_configure_socket,
155 + .socket_init = gumstix_pcmcia_socket_init,
156 + .socket_suspend = gumstix_pcmcia_socket_suspend,
160 +static struct platform_device *gumstix_pcmcia_device;
162 +inline void __init gumstix_pcmcia_cpld_clk(void)
164 + GPCR(GPIO_GUMSTIX_nPOE) = GPIO_bit(GPIO_GUMSTIX_nPOE);
165 + GPSR(GPIO_GUMSTIX_nPOE) = GPIO_bit(GPIO_GUMSTIX_nPOE);
168 +inline unsigned char __init gumstix_pcmcia_cpld_read_bits(int bits)
170 + unsigned char result = 0;
171 + unsigned int shift = 0;
174 + result |= !!(GPLR(GPIO_GUMSTIX_nCD_0) & GPIO_bit(GPIO_GUMSTIX_nCD_0)) << shift;
176 + gumstix_pcmcia_cpld_clk();
178 + printk("CPLD responded with: %02x\n",result);
182 +/* We use the CPLD on the CF-CF card to read a value from a shift register. If we can read that
183 + * magic sequence, then we have 2 CF cards; otherwise we assume just one
184 + * The CPLD will send the value of the shift register on GPIO11 (the CD line for slot 0)
185 + * when RESET is held in reset. We use GPIO48 (nPOE) as a clock signal,
186 + * GPIO52/53 (card enable for both cards) to control read/write to the shift register
188 +static void __init gumstix_count_cards(void)
190 + pxa_gpio_mode(GPIO_GUMSTIX_nPOE | GPIO_OUT);
191 + pxa_gpio_mode(GPIO_GUMSTIX_nPCE_1 | GPIO_OUT);
192 + pxa_gpio_mode(GPIO_GUMSTIX_nPCE_2 | GPIO_OUT);
193 + pxa_gpio_mode(GPIO_GUMSTIX_nCD_0 | GPIO_IN);
195 + pxa_gpio_mode(GPIO_GUMSTIX_CF_OLD_RESET | GPIO_OUT);
197 + pxa_gpio_mode(GPIO_GUMSTIX_CF_RESET | GPIO_OUT);
201 + GPSR(GPIO_GUMSTIX_CF_OLD_RESET) = GPIO_bit(GPIO_GUMSTIX_CF_OLD_RESET);
203 + GPSR(GPIO_GUMSTIX_CF_RESET) = GPIO_bit(GPIO_GUMSTIX_CF_RESET);
205 + // Setup the shift register
206 + GPSR(GPIO_GUMSTIX_nPCE_1) = GPIO_bit(GPIO_GUMSTIX_nPCE_1);
207 + GPCR(GPIO_GUMSTIX_nPCE_2) = GPIO_bit(GPIO_GUMSTIX_nPCE_2);
209 + // Tick the clock to program the shift register
210 + gumstix_pcmcia_cpld_clk();
212 + // Now set shift register into read mode
213 + GPCR(GPIO_GUMSTIX_nPCE_1) = GPIO_bit(GPIO_GUMSTIX_nPCE_1);
214 + GPSR(GPIO_GUMSTIX_nPCE_2) = GPIO_bit(GPIO_GUMSTIX_nPCE_2);
216 + // We can read the bits now -- 0xC2 means "Dual compact flash"
217 + if(gumstix_pcmcia_cpld_read_bits(8) != 0xC2)
219 + // We do not have 2 CF slots
220 + gumstix_pcmcia_ops.nr = 1;
224 +#ifdef CONFIG_ARCH_GUMSTIX_VERDEX
225 +static void __init gumstix_check_if_netCF_vx(void)
227 + void *network_controller_memory = ioremap(0x04000300,16);
228 + // Look for the special 91c111 value in the bank select register
229 + if((0xff00 & readw(network_controller_memory+0x0e)) == 0x3300) {
230 + printk("Detected netCF-vx board: using older GPIO configuration\n");
231 + net_cf_vx_mode = 1;
233 + printk("Not netCF-vx board: using newer GPIO configuration\n");
234 + net_cf_vx_mode = 0;
236 + iounmap(network_controller_memory);
240 +static int __init gumstix_pcmcia_init(void)
244 +#ifdef CONFIG_ARCH_GUMSTIX_VERDEX
245 + gumstix_check_if_netCF_vx();
248 + gumstix_count_cards();
252 + GPCR(GPIO_GUMSTIX_CF_OLD_RESET) = GPIO_bit(GPIO_GUMSTIX_CF_OLD_RESET);
254 + GPCR(GPIO_GUMSTIX_CF_RESET) = GPIO_bit(GPIO_GUMSTIX_CF_RESET);
256 + gumstix_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
257 + if (!gumstix_pcmcia_device)
260 + gumstix_pcmcia_device->dev.platform_data = &gumstix_pcmcia_ops;
262 + ret = platform_device_add(gumstix_pcmcia_device);
264 + platform_device_put(gumstix_pcmcia_device);
269 +static void __exit gumstix_pcmcia_exit(void)
272 + * This call is supposed to free our gumstix_pcmcia_device.
273 + * Unfortunately platform_device don't have a free method, and
274 + * we can't assume it's free of any reference at this point so we
275 + * can't free it either.
277 + platform_device_unregister(gumstix_pcmcia_device);
280 +fs_initcall(gumstix_pcmcia_init);
281 +module_exit(gumstix_pcmcia_exit);
283 +MODULE_LICENSE("GPL");