1 Index: linux-2.6.21.7/drivers/pcmcia/Makefile
2 ===================================================================
3 --- linux-2.6.21.7.orig/drivers/pcmcia/Makefile
4 +++ linux-2.6.21.7/drivers/pcmcia/Makefile
5 @@ -69,4 +69,4 @@ sa1100_cs-$(CONFIG_SA1100_SIMPAD) += sa
6 pxa2xx_cs-$(CONFIG_ARCH_LUBBOCK) += pxa2xx_lubbock.o sa1111_generic.o
7 pxa2xx_cs-$(CONFIG_MACH_MAINSTONE) += pxa2xx_mainstone.o
8 pxa2xx_cs-$(CONFIG_PXA_SHARPSL) += pxa2xx_sharpsl.o
10 +pxa2xx_cs-$(CONFIG_ARCH_GUMSTIX) += pxa2xx_gumstix.o
11 Index: linux-2.6.21.7/drivers/pcmcia/pxa2xx_gumstix.c
12 ===================================================================
14 +++ linux-2.6.21.7/drivers/pcmcia/pxa2xx_gumstix.c
17 + * linux/drivers/pcmcia/pxa2xx_gumstix.c
19 + * Gumstix PCMCIA specific routines. Based on Mainstone
21 + * Copyright 2004, Craig Hughes <craig@gumstix.com>
23 + * This program is free software; you can redistribute it and/or modify
24 + * it under the terms of the GNU General Public License version 2 as
25 + * published by the Free Software Foundation.
28 +#include <linux/module.h>
29 +#include <linux/init.h>
30 +#include <linux/kernel.h>
31 +#include <linux/errno.h>
32 +#include <linux/interrupt.h>
33 +#include <linux/device.h>
34 +#include <linux/platform_device.h>
36 +#include <pcmcia/ss.h>
38 +#include <asm/hardware.h>
39 +#include <asm/delay.h>
40 +#include <asm/arch/pxa-regs.h>
44 +#include <asm/arch/gumstix.h>
46 +#include "soc_common.h"
48 +static struct pcmcia_irqs gumstix_pcmcia_irqs0[] = {
49 + { 0, GUMSTIX_S0_nCD_IRQ, "CF0 nCD" },
50 + { 0, GUMSTIX_S0_nSTSCHG_IRQ, "CF0 nSTSCHG" },
53 +static struct pcmcia_irqs gumstix_pcmcia_irqs1[] = {
54 + { 1, GUMSTIX_S1_nCD_IRQ, "CF1 nCD" },
55 + { 1, GUMSTIX_S1_nSTSCHG_IRQ, "CF1 nSTSCHG" },
58 +static int net_cf_vx_mode = 0;
60 +static int gumstix_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
64 + pxa_gpio_mode(GPIO_GUMSTIX_nSTSCHG_0_MD);
65 + pxa_gpio_mode(GPIO_GUMSTIX_nCD_0_MD);
67 + pxa_gpio_mode(GPIO_GUMSTIX_PRDY_nBSY_0_OLD_MD);
69 + pxa_gpio_mode(GPIO_GUMSTIX_PRDY_nBSY_0_MD);
71 + pxa_gpio_mode(GPIO_GUMSTIX_nSTSCHG_1_MD);
72 + pxa_gpio_mode(GPIO_GUMSTIX_nCD_1_MD);
73 + pxa_gpio_mode(GPIO_GUMSTIX_PRDY_nBSY_1_MD);
76 + pxa_gpio_mode(GPIO_GUMSTIX_nPOE_MD);
77 + pxa_gpio_mode(GPIO_GUMSTIX_nPWE_MD);
78 + pxa_gpio_mode(GPIO_GUMSTIX_nPIOR_MD);
79 + pxa_gpio_mode(GPIO_GUMSTIX_nPIOW_MD);
80 + pxa_gpio_mode(GPIO_GUMSTIX_nPCE_1_MD);
81 + pxa_gpio_mode(GPIO_GUMSTIX_nPCE_2_MD);
82 + pxa_gpio_mode(GPIO_GUMSTIX_pSKTSEL_MD);
83 + pxa_gpio_mode(GPIO_GUMSTIX_nPREG_MD);
84 + pxa_gpio_mode(GPIO_GUMSTIX_nPWAIT_MD);
85 + pxa_gpio_mode(GPIO_GUMSTIX_nIOIS16_MD);
87 + 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;
89 + return (skt->nr == 0) ? soc_pcmcia_request_irqs(skt, gumstix_pcmcia_irqs0, ARRAY_SIZE(gumstix_pcmcia_irqs0)) :
90 + soc_pcmcia_request_irqs(skt, gumstix_pcmcia_irqs1, ARRAY_SIZE(gumstix_pcmcia_irqs1));
93 +static void gumstix_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
97 + soc_pcmcia_free_irqs(skt, gumstix_pcmcia_irqs0, ARRAY_SIZE(gumstix_pcmcia_irqs0));
99 + soc_pcmcia_free_irqs(skt, gumstix_pcmcia_irqs1, ARRAY_SIZE(gumstix_pcmcia_irqs1));
103 +static void gumstix_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
104 + struct pcmcia_state *state)
106 + unsigned int cd, prdy_nbsy, nbvd1;
109 + cd = GPIO_GUMSTIX_nCD_0;
111 + prdy_nbsy = GPIO_GUMSTIX_PRDY_nBSY_0_OLD;
113 + prdy_nbsy = GPIO_GUMSTIX_PRDY_nBSY_0;
114 + nbvd1 = GPIO_GUMSTIX_nBVD1_0;
116 + cd = GPIO_GUMSTIX_nCD_1;
117 + prdy_nbsy = GPIO_GUMSTIX_PRDY_nBSY_1;
118 + nbvd1 = GPIO_GUMSTIX_nBVD1_1;
120 + state->detect = !(GPLR(cd) & GPIO_bit(cd));
121 + state->ready = !!(GPLR(prdy_nbsy) & GPIO_bit(prdy_nbsy));
122 + state->bvd1 = !!(GPLR(nbvd1) & GPIO_bit(nbvd1));
129 +static int gumstix_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
130 + const socket_state_t *state)
135 +static void gumstix_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
138 + soc_pcmcia_enable_irqs(skt, gumstix_pcmcia_irqs0, ARRAY_SIZE(gumstix_pcmcia_irqs0));
140 + soc_pcmcia_enable_irqs(skt, gumstix_pcmcia_irqs1, ARRAY_SIZE(gumstix_pcmcia_irqs1));
144 +static void gumstix_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
147 + soc_pcmcia_disable_irqs(skt, gumstix_pcmcia_irqs0, ARRAY_SIZE(gumstix_pcmcia_irqs0));
149 + soc_pcmcia_disable_irqs(skt, gumstix_pcmcia_irqs1, ARRAY_SIZE(gumstix_pcmcia_irqs1));
153 +static struct pcmcia_low_level gumstix_pcmcia_ops = {
154 + .owner = THIS_MODULE,
155 + .hw_init = gumstix_pcmcia_hw_init,
156 + .hw_shutdown = gumstix_pcmcia_hw_shutdown,
157 + .socket_state = gumstix_pcmcia_socket_state,
158 + .configure_socket = gumstix_pcmcia_configure_socket,
159 + .socket_init = gumstix_pcmcia_socket_init,
160 + .socket_suspend = gumstix_pcmcia_socket_suspend,
164 +static struct platform_device *gumstix_pcmcia_device;
166 +inline void __init gumstix_pcmcia_cpld_clk(void)
168 + GPCR(GPIO_GUMSTIX_nPOE) = GPIO_bit(GPIO_GUMSTIX_nPOE);
169 + GPSR(GPIO_GUMSTIX_nPOE) = GPIO_bit(GPIO_GUMSTIX_nPOE);
172 +inline unsigned char __init gumstix_pcmcia_cpld_read_bits(int bits)
174 + unsigned char result = 0;
175 + unsigned int shift = 0;
178 + result |= !!(GPLR(GPIO_GUMSTIX_nCD_0) & GPIO_bit(GPIO_GUMSTIX_nCD_0)) << shift;
180 + gumstix_pcmcia_cpld_clk();
182 + printk("CPLD responded with: %02x\n",result);
186 +/* We use the CPLD on the CF-CF card to read a value from a shift register. If we can read that
187 + * magic sequence, then we have 2 CF cards; otherwise we assume just one
188 + * The CPLD will send the value of the shift register on GPIO11 (the CD line for slot 0)
189 + * when RESET is held in reset. We use GPIO48 (nPOE) as a clock signal,
190 + * GPIO52/53 (card enable for both cards) to control read/write to the shift register
192 +static void __init gumstix_count_cards(void)
194 + pxa_gpio_mode(GPIO_GUMSTIX_nPOE | GPIO_OUT);
195 + pxa_gpio_mode(GPIO_GUMSTIX_nPCE_1 | GPIO_OUT);
196 + pxa_gpio_mode(GPIO_GUMSTIX_nPCE_2 | GPIO_OUT);
197 + pxa_gpio_mode(GPIO_GUMSTIX_nCD_0 | GPIO_IN);
199 + pxa_gpio_mode(GPIO_GUMSTIX_CF_OLD_RESET | GPIO_OUT);
201 + pxa_gpio_mode(GPIO_GUMSTIX_CF_RESET | GPIO_OUT);
205 + GPSR(GPIO_GUMSTIX_CF_OLD_RESET) = GPIO_bit(GPIO_GUMSTIX_CF_OLD_RESET);
207 + GPSR(GPIO_GUMSTIX_CF_RESET) = GPIO_bit(GPIO_GUMSTIX_CF_RESET);
209 + // Setup the shift register
210 + GPSR(GPIO_GUMSTIX_nPCE_1) = GPIO_bit(GPIO_GUMSTIX_nPCE_1);
211 + GPCR(GPIO_GUMSTIX_nPCE_2) = GPIO_bit(GPIO_GUMSTIX_nPCE_2);
213 + // Tick the clock to program the shift register
214 + gumstix_pcmcia_cpld_clk();
216 + // Now set shift register into read mode
217 + GPCR(GPIO_GUMSTIX_nPCE_1) = GPIO_bit(GPIO_GUMSTIX_nPCE_1);
218 + GPSR(GPIO_GUMSTIX_nPCE_2) = GPIO_bit(GPIO_GUMSTIX_nPCE_2);
220 + // We can read the bits now -- 0xC2 means "Dual compact flash"
221 + if(gumstix_pcmcia_cpld_read_bits(8) != 0xC2)
223 + // We do not have 2 CF slots
224 + gumstix_pcmcia_ops.nr = 1;
228 +#ifdef CONFIG_ARCH_GUMSTIX_VERDEX
229 +static void __init gumstix_check_if_netCF_vx(void)
231 + void *network_controller_memory = ioremap(0x04000300,16);
232 + // Look for the special 91c111 value in the bank select register
233 + if((0xff00 & readw(network_controller_memory+0x0e)) == 0x3300) {
234 + printk("Detected netCF-vx board: using older GPIO configuration\n");
235 + net_cf_vx_mode = 1;
237 + printk("Not netCF-vx board: using newer GPIO configuration\n");
238 + net_cf_vx_mode = 0;
240 + iounmap(network_controller_memory);
244 +static int __init gumstix_pcmcia_init(void)
248 +#ifdef CONFIG_ARCH_GUMSTIX_VERDEX
249 + gumstix_check_if_netCF_vx();
252 + gumstix_count_cards();
256 + GPCR(GPIO_GUMSTIX_CF_OLD_RESET) = GPIO_bit(GPIO_GUMSTIX_CF_OLD_RESET);
258 + GPCR(GPIO_GUMSTIX_CF_RESET) = GPIO_bit(GPIO_GUMSTIX_CF_RESET);
260 + gumstix_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
261 + if (!gumstix_pcmcia_device)
264 + gumstix_pcmcia_device->dev.platform_data = &gumstix_pcmcia_ops;
266 + ret = platform_device_add(gumstix_pcmcia_device);
268 + platform_device_put(gumstix_pcmcia_device);
273 +static void __exit gumstix_pcmcia_exit(void)
276 + * This call is supposed to free our gumstix_pcmcia_device.
277 + * Unfortunately platform_device don't have a free method, and
278 + * we can't assume it's free of any reference at this point so we
279 + * can't free it either.
281 + platform_device_unregister(gumstix_pcmcia_device);
284 +fs_initcall(gumstix_pcmcia_init);
285 +module_exit(gumstix_pcmcia_exit);
287 +MODULE_LICENSE("GPL");