diff options
author | Anton Vorontsov <avorontsov@ru.mvista.com> | 2008-12-30 10:15:28 -0500 |
---|---|---|
committer | Pierre Ossman <drzeus@drzeus.cx> | 2008-12-31 13:01:55 -0500 |
commit | 9c43df57910bbba540a6cb5c9132302a9ea5f41a (patch) | |
tree | a3f7debf605e4ad9a9d61a775222c5b6d738da26 | |
parent | c00a46abd4d45a67ff62f4ff6d4f839dff38b877 (diff) |
mmc_spi: Add support for OpenFirmware bindings
The support is implemented via platform data accessors, new module
(of_mmc_spi) will be created automatically when the driver compiles
on OpenFirmware platforms. Link-time dependency will load the module
automatically.
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
-rw-r--r-- | drivers/mmc/host/Makefile | 3 | ||||
-rw-r--r-- | drivers/mmc/host/mmc_spi.c | 4 | ||||
-rw-r--r-- | drivers/mmc/host/of_mmc_spi.c | 149 | ||||
-rw-r--r-- | include/linux/spi/mmc_spi.h | 15 |
4 files changed, 169 insertions, 2 deletions
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile index c794cc5ce442..f4853288bbb1 100644 --- a/drivers/mmc/host/Makefile +++ b/drivers/mmc/host/Makefile | |||
@@ -19,6 +19,9 @@ obj-$(CONFIG_MMC_AT91) += at91_mci.o | |||
19 | obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o | 19 | obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o |
20 | obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o | 20 | obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o |
21 | obj-$(CONFIG_MMC_SPI) += mmc_spi.o | 21 | obj-$(CONFIG_MMC_SPI) += mmc_spi.o |
22 | ifeq ($(CONFIG_OF),y) | ||
23 | obj-$(CONFIG_MMC_SPI) += of_mmc_spi.o | ||
24 | endif | ||
22 | obj-$(CONFIG_MMC_S3C) += s3cmci.o | 25 | obj-$(CONFIG_MMC_S3C) += s3cmci.o |
23 | obj-$(CONFIG_MMC_SDRICOH_CS) += sdricoh_cs.o | 26 | obj-$(CONFIG_MMC_SDRICOH_CS) += sdricoh_cs.o |
24 | obj-$(CONFIG_MMC_TMIO) += tmio_mmc.o | 27 | obj-$(CONFIG_MMC_TMIO) += tmio_mmc.o |
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c index ad00e1632317..87e211df68ac 100644 --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c | |||
@@ -1285,7 +1285,7 @@ static int mmc_spi_probe(struct spi_device *spi) | |||
1285 | /* Platform data is used to hook up things like card sensing | 1285 | /* Platform data is used to hook up things like card sensing |
1286 | * and power switching gpios. | 1286 | * and power switching gpios. |
1287 | */ | 1287 | */ |
1288 | host->pdata = spi->dev.platform_data; | 1288 | host->pdata = mmc_spi_get_pdata(spi); |
1289 | if (host->pdata) | 1289 | if (host->pdata) |
1290 | mmc->ocr_avail = host->pdata->ocr_mask; | 1290 | mmc->ocr_avail = host->pdata->ocr_mask; |
1291 | if (!mmc->ocr_avail) { | 1291 | if (!mmc->ocr_avail) { |
@@ -1368,6 +1368,7 @@ fail_glue_init: | |||
1368 | 1368 | ||
1369 | fail_nobuf1: | 1369 | fail_nobuf1: |
1370 | mmc_free_host(mmc); | 1370 | mmc_free_host(mmc); |
1371 | mmc_spi_put_pdata(spi); | ||
1371 | dev_set_drvdata(&spi->dev, NULL); | 1372 | dev_set_drvdata(&spi->dev, NULL); |
1372 | 1373 | ||
1373 | nomem: | 1374 | nomem: |
@@ -1402,6 +1403,7 @@ static int __devexit mmc_spi_remove(struct spi_device *spi) | |||
1402 | 1403 | ||
1403 | spi->max_speed_hz = mmc->f_max; | 1404 | spi->max_speed_hz = mmc->f_max; |
1404 | mmc_free_host(mmc); | 1405 | mmc_free_host(mmc); |
1406 | mmc_spi_put_pdata(spi); | ||
1405 | dev_set_drvdata(&spi->dev, NULL); | 1407 | dev_set_drvdata(&spi->dev, NULL); |
1406 | } | 1408 | } |
1407 | return 0; | 1409 | return 0; |
diff --git a/drivers/mmc/host/of_mmc_spi.c b/drivers/mmc/host/of_mmc_spi.c new file mode 100644 index 000000000000..fb2921f8099d --- /dev/null +++ b/drivers/mmc/host/of_mmc_spi.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * OpenFirmware bindings for the MMC-over-SPI driver | ||
3 | * | ||
4 | * Copyright (c) MontaVista Software, Inc. 2008. | ||
5 | * | ||
6 | * Author: Anton Vorontsov <avorontsov@ru.mvista.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/device.h> | ||
17 | #include <linux/gpio.h> | ||
18 | #include <linux/of.h> | ||
19 | #include <linux/of_gpio.h> | ||
20 | #include <linux/spi/spi.h> | ||
21 | #include <linux/spi/mmc_spi.h> | ||
22 | #include <linux/mmc/core.h> | ||
23 | #include <linux/mmc/host.h> | ||
24 | |||
25 | enum { | ||
26 | CD_GPIO = 0, | ||
27 | WP_GPIO, | ||
28 | NUM_GPIOS, | ||
29 | }; | ||
30 | |||
31 | struct of_mmc_spi { | ||
32 | int gpios[NUM_GPIOS]; | ||
33 | bool alow_gpios[NUM_GPIOS]; | ||
34 | struct mmc_spi_platform_data pdata; | ||
35 | }; | ||
36 | |||
37 | static struct of_mmc_spi *to_of_mmc_spi(struct device *dev) | ||
38 | { | ||
39 | return container_of(dev->platform_data, struct of_mmc_spi, pdata); | ||
40 | } | ||
41 | |||
42 | static int of_mmc_spi_read_gpio(struct device *dev, int gpio_num) | ||
43 | { | ||
44 | struct of_mmc_spi *oms = to_of_mmc_spi(dev); | ||
45 | bool active_low = oms->alow_gpios[gpio_num]; | ||
46 | bool value = gpio_get_value(oms->gpios[gpio_num]); | ||
47 | |||
48 | return active_low ^ value; | ||
49 | } | ||
50 | |||
51 | static int of_mmc_spi_get_cd(struct device *dev) | ||
52 | { | ||
53 | return of_mmc_spi_read_gpio(dev, CD_GPIO); | ||
54 | } | ||
55 | |||
56 | static int of_mmc_spi_get_ro(struct device *dev) | ||
57 | { | ||
58 | return of_mmc_spi_read_gpio(dev, WP_GPIO); | ||
59 | } | ||
60 | |||
61 | struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi) | ||
62 | { | ||
63 | struct device *dev = &spi->dev; | ||
64 | struct device_node *np = dev_archdata_get_node(&dev->archdata); | ||
65 | struct of_mmc_spi *oms; | ||
66 | const u32 *voltage_ranges; | ||
67 | int num_ranges; | ||
68 | int i; | ||
69 | int ret = -EINVAL; | ||
70 | |||
71 | if (dev->platform_data || !np) | ||
72 | return dev->platform_data; | ||
73 | |||
74 | oms = kzalloc(sizeof(*oms), GFP_KERNEL); | ||
75 | if (!oms) | ||
76 | return NULL; | ||
77 | |||
78 | voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges); | ||
79 | num_ranges = num_ranges / sizeof(*voltage_ranges) / 2; | ||
80 | if (!voltage_ranges || !num_ranges) { | ||
81 | dev_err(dev, "OF: voltage-ranges unspecified\n"); | ||
82 | goto err_ocr; | ||
83 | } | ||
84 | |||
85 | for (i = 0; i < num_ranges; i++) { | ||
86 | const int j = i * 2; | ||
87 | u32 mask; | ||
88 | |||
89 | mask = mmc_vddrange_to_ocrmask(voltage_ranges[j], | ||
90 | voltage_ranges[j + 1]); | ||
91 | if (!mask) { | ||
92 | ret = -EINVAL; | ||
93 | dev_err(dev, "OF: voltage-range #%d is invalid\n", i); | ||
94 | goto err_ocr; | ||
95 | } | ||
96 | oms->pdata.ocr_mask |= mask; | ||
97 | } | ||
98 | |||
99 | for (i = 0; i < ARRAY_SIZE(oms->gpios); i++) { | ||
100 | enum of_gpio_flags gpio_flags; | ||
101 | |||
102 | oms->gpios[i] = of_get_gpio_flags(np, i, &gpio_flags); | ||
103 | if (!gpio_is_valid(oms->gpios[i])) | ||
104 | continue; | ||
105 | |||
106 | ret = gpio_request(oms->gpios[i], dev->bus_id); | ||
107 | if (ret < 0) { | ||
108 | oms->gpios[i] = -EINVAL; | ||
109 | continue; | ||
110 | } | ||
111 | |||
112 | if (gpio_flags & OF_GPIO_ACTIVE_LOW) | ||
113 | oms->alow_gpios[i] = true; | ||
114 | } | ||
115 | |||
116 | if (gpio_is_valid(oms->gpios[CD_GPIO])) | ||
117 | oms->pdata.get_cd = of_mmc_spi_get_cd; | ||
118 | if (gpio_is_valid(oms->gpios[WP_GPIO])) | ||
119 | oms->pdata.get_ro = of_mmc_spi_get_ro; | ||
120 | |||
121 | /* We don't support interrupts yet, let's poll. */ | ||
122 | oms->pdata.caps |= MMC_CAP_NEEDS_POLL; | ||
123 | |||
124 | dev->platform_data = &oms->pdata; | ||
125 | return dev->platform_data; | ||
126 | err_ocr: | ||
127 | kfree(oms); | ||
128 | return NULL; | ||
129 | } | ||
130 | EXPORT_SYMBOL(mmc_spi_get_pdata); | ||
131 | |||
132 | void mmc_spi_put_pdata(struct spi_device *spi) | ||
133 | { | ||
134 | struct device *dev = &spi->dev; | ||
135 | struct device_node *np = dev_archdata_get_node(&dev->archdata); | ||
136 | struct of_mmc_spi *oms = to_of_mmc_spi(dev); | ||
137 | int i; | ||
138 | |||
139 | if (!dev->platform_data || !np) | ||
140 | return; | ||
141 | |||
142 | for (i = 0; i < ARRAY_SIZE(oms->gpios); i++) { | ||
143 | if (gpio_is_valid(oms->gpios[i])) | ||
144 | gpio_free(oms->gpios[i]); | ||
145 | } | ||
146 | kfree(oms); | ||
147 | dev->platform_data = NULL; | ||
148 | } | ||
149 | EXPORT_SYMBOL(mmc_spi_put_pdata); | ||
diff --git a/include/linux/spi/mmc_spi.h b/include/linux/spi/mmc_spi.h index a3626aedaec9..0f4eb165f254 100644 --- a/include/linux/spi/mmc_spi.h +++ b/include/linux/spi/mmc_spi.h | |||
@@ -1,9 +1,10 @@ | |||
1 | #ifndef __LINUX_SPI_MMC_SPI_H | 1 | #ifndef __LINUX_SPI_MMC_SPI_H |
2 | #define __LINUX_SPI_MMC_SPI_H | 2 | #define __LINUX_SPI_MMC_SPI_H |
3 | 3 | ||
4 | #include <linux/device.h> | ||
5 | #include <linux/spi/spi.h> | ||
4 | #include <linux/interrupt.h> | 6 | #include <linux/interrupt.h> |
5 | 7 | ||
6 | struct device; | ||
7 | struct mmc_host; | 8 | struct mmc_host; |
8 | 9 | ||
9 | /* Put this in platform_data of a device being used to manage an MMC/SD | 10 | /* Put this in platform_data of a device being used to manage an MMC/SD |
@@ -41,4 +42,16 @@ struct mmc_spi_platform_data { | |||
41 | void (*setpower)(struct device *, unsigned int maskval); | 42 | void (*setpower)(struct device *, unsigned int maskval); |
42 | }; | 43 | }; |
43 | 44 | ||
45 | #ifdef CONFIG_OF | ||
46 | extern struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi); | ||
47 | extern void mmc_spi_put_pdata(struct spi_device *spi); | ||
48 | #else | ||
49 | static inline struct mmc_spi_platform_data * | ||
50 | mmc_spi_get_pdata(struct spi_device *spi) | ||
51 | { | ||
52 | return spi->dev.platform_data; | ||
53 | } | ||
54 | static inline void mmc_spi_put_pdata(struct spi_device *spi) {} | ||
55 | #endif /* CONFIG_OF */ | ||
56 | |||
44 | #endif /* __LINUX_SPI_MMC_SPI_H */ | 57 | #endif /* __LINUX_SPI_MMC_SPI_H */ |