summaryrefslogtreecommitdiffstats
path: root/target/linux/pxa/patches-2.6.21/031-mmc-card-detect.patch
blob: 890f19578a033b6d9ad5eb4db94b574361251a2f (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
--- a/arch/arm/mach-pxa/gumstix.c
+++ b/arch/arm/mach-pxa/gumstix.c
@@ -29,19 +29,55 @@
 
 #include "generic.h"
 
-static int gumstix_mci_init(struct device *dev, irqreturn_t (*lubbock_detect_int)(int, void *, struct pt_regs *), void *data)
+static struct pxamci_platform_data gumstix_mci_platform_data;
+
+static int gumstix_mci_init(struct device *dev, irqreturn_t (*gumstix_detect_int)(int, void *, struct pt_regs *), void *data)
 {
-	// Set up MMC controller
+	int err;
+
 	pxa_gpio_mode(GPIO6_MMCCLK_MD);
 	pxa_gpio_mode(GPIO53_MMCCLK_MD);
 	pxa_gpio_mode(GPIO8_MMCCS0_MD);
 
+	pxa_gpio_mode(GUMSTIX_GPIO_nSD_DETECT | GPIO_IN);
+	set_irq_type(GUMSTIX_IRQ_GPIO_nSD_DETECT, IRQT_BOTHEDGE);
+	pxa_gpio_mode(GUMSTIX_GPIO_nSD_WP | GPIO_IN);
+
+	gumstix_mci_platform_data.detect_delay = msecs_to_jiffies(250);
+
+	err = request_irq(GUMSTIX_IRQ_GPIO_nSD_DETECT, gumstix_detect_int, SA_INTERRUPT,
+			     "MMC card detect", data);
+	if (err) {
+		printk(KERN_ERR "gumstix_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
+		return -1;
+	}
+
+	err = set_irq_type(GUMSTIX_IRQ_GPIO_nSD_DETECT, IRQT_BOTHEDGE);
+
 	return 0;
 }
 
+static int gumstix_mci_get_ro(struct device *dev)
+{
+#ifdef CONFIG_ARCH_GUMSTIX_VERDEX
+	return 0;	// microSD is always writable on verdex
+#else
+	int ro;
+	ro = GPLR(GUMSTIX_GPIO_nSD_WP) & GPIO_bit(GUMSTIX_GPIO_nSD_WP);
+	return ro;
+#endif
+}
+
+static void gumstix_mci_exit(struct device *dev, void *data)
+{
+	free_irq(GUMSTIX_IRQ_GPIO_nSD_DETECT, data);
+}
+
 static struct pxamci_platform_data gumstix_mci_platform_data = {
 	.ocr_mask	= MMC_VDD_32_33|MMC_VDD_33_34,
-	.init		= &gumstix_mci_init,
+	.init		= gumstix_mci_init,
+	.get_ro		= gumstix_mci_get_ro,
+	.exit		= gumstix_mci_exit,
 };
 
 static struct pxa2xx_udc_mach_info gumstix_udc_info __initdata = {
--- a/include/asm-arm/arch-pxa/gumstix.h
+++ b/include/asm-arm/arch-pxa/gumstix.h
@@ -36,6 +36,12 @@
 #define GPIO_GUMSTIX_USB_GPIOx_CON_MD	(GPIO_GUMSTIX_USB_GPIOx | GPIO_OUT)
 #define GPIO_GUMSTIX_USB_GPIOx_DIS_MD	(GPIO_GUMSTIX_USB_GPIOx | GPIO_IN)
 
+/*
+ * SD/MMC definitions
+ */
+#define GUMSTIX_GPIO_nSD_WP		22 /* SD Write Protect */
+#define GUMSTIX_GPIO_nSD_DETECT		11 /* MMC/SD Card Detect */
+#define GUMSTIX_IRQ_GPIO_nSD_DETECT	IRQ_GPIO(GUMSTIX_GPIO_nSD_DETECT)
 
 /*
  * SMC Ethernet definitions