History

ARM/mmc: Convert old mmci-omap to GPIO descriptors

A recent change to the OMAP driver making it use a dynamic GPIO base created problems with some old OMAP1 board files, among them Nokia 770, SX1 and also the OMAP2 Nokia n8x0. Fix up all instances of GPIOs being used for the MMC driver by pushing the handling of power, slot selection and MMC "cover" into the driver as optional GPIOs. This is maybe not the most perfect solution as the MMC framework have some central handlers for some of the stuff, but it at least makes the situtation better and solves the immediate issue.

Linus Walleij committed 3 years ago

Commit e519f0b1 parent 767d8335 files · +83 −94Browse files

Unified · Split

5 files
  1. arch/arm/mach-omap1/board-nokia770.c +13 −30
  2. arch/arm/mach-omap1/board-sx1-mmc.c +0 −1
  3. arch/arm/mach-omap2/board-n8x0.c +26 −59
  4. drivers/mmc/host/omap.c +44 −2
  5. include/linux/platform_data/mmc-omap.h +0 −2
arch/arm/mach-omap1/board-nokia770.c+13−30
@@ -184,27 +184,23 @@ static struct omap_usb_config nokia770_usb_config __initdata = { · 183 unmodified lines
184 184
185#if IS_ENABLED(CONFIG_MMC_OMAP)185#if IS_ENABLED(CONFIG_MMC_OMAP)
186 186
187#define NOKIA770_GPIO_MMC_POWER 41187static struct gpiod_lookup_table nokia770_mmc_gpio_table = {
188#define NOKIA770_GPIO_MMC_SWITCH 23188 .dev_id = "mmci-omap.1",
189 189 .table = {
190static int nokia770_mmc_set_power(struct device *dev, int slot, int power_on,190 /* Slot index 0, VSD power, GPIO 41 */
191 int vdd)191 GPIO_LOOKUP_IDX("gpio-32-47", 9,
192{192 "vsd", 0, GPIO_ACTIVE_HIGH),
193 gpio_set_value(NOKIA770_GPIO_MMC_POWER, power_on);193 /* Slot index 0, switch, GPIO 23 */
194 return 0;194 GPIO_LOOKUP_IDX("gpio-16-31", 7,
195}195 "cover", 0, GPIO_ACTIVE_HIGH),
196 196 { }
197static int nokia770_mmc_get_cover_state(struct device *dev, int slot)197 },
198{198};
199 return gpio_get_value(NOKIA770_GPIO_MMC_SWITCH);
200}
201 199
202static struct omap_mmc_platform_data nokia770_mmc2_data = {200static struct omap_mmc_platform_data nokia770_mmc2_data = {
203 .nr_slots = 1,201 .nr_slots = 1,
204 .max_freq = 12000000,202 .max_freq = 12000000,
205 .slots[0] = {203 .slots[0] = {
206 .set_power = nokia770_mmc_set_power,
207 .get_cover_state = nokia770_mmc_get_cover_state,
208 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,204 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
209 .name = "mmcblk",205 .name = "mmcblk",
210 },206 },
@@ -214,20 +210,7 @@ static struct omap_mmc_platform_data *nokia770_mmc_data[OMAP16XX_NR_MMC]; · 3 unmodified lines
214 210
215static void __init nokia770_mmc_init(void)211static void __init nokia770_mmc_init(void)
216{212{
217 int ret;213 gpiod_add_lookup_table(&nokia770_mmc_gpio_table);
218
219 ret = gpio_request(NOKIA770_GPIO_MMC_POWER, "MMC power");
220 if (ret < 0)
221 return;
222 gpio_direction_output(NOKIA770_GPIO_MMC_POWER, 0);
223
224 ret = gpio_request(NOKIA770_GPIO_MMC_SWITCH, "MMC cover");
225 if (ret < 0) {
226 gpio_free(NOKIA770_GPIO_MMC_POWER);
227 return;
228 }
229 gpio_direction_input(NOKIA770_GPIO_MMC_SWITCH);
230
231 /* Only the second MMC controller is used */214 /* Only the second MMC controller is used */
232 nokia770_mmc_data[1] = &nokia770_mmc2_data;215 nokia770_mmc_data[1] = &nokia770_mmc2_data;
233 omap1_init_mmc(nokia770_mmc_data, OMAP16XX_NR_MMC);216 omap1_init_mmc(nokia770_mmc_data, OMAP16XX_NR_MMC);
arch/arm/mach-omap1/board-sx1-mmc.c+0−1
@@ -9,7 +9,6 @@ · 8 unmodified lines
9 * Copyright (C) 2007 Instituto Nokia de Tecnologia - INdT9 * Copyright (C) 2007 Instituto Nokia de Tecnologia - INdT
10 */10 */
11 11
12#include <linux/gpio.h>
13#include <linux/platform_device.h>12#include <linux/platform_device.h>
14 13
15#include "hardware.h"14#include "hardware.h"
arch/arm/mach-omap2/board-n8x0.c+26−59
@@ -11,6 +11,7 @@ · 10 unmodified lines
11#include <linux/clk.h>11#include <linux/clk.h>
12#include <linux/delay.h>12#include <linux/delay.h>
13#include <linux/gpio.h>13#include <linux/gpio.h>
14#include <linux/gpio/machine.h>
14#include <linux/init.h>15#include <linux/init.h>
15#include <linux/io.h>16#include <linux/io.h>
16#include <linux/irq.h>17#include <linux/irq.h>
@@ -170,22 +171,32 @@ static struct spi_board_info n800_spi_board_info[] __initdata = { · 153 unmodified lines
170 * GPIO23 and GPIO9 slot 2 EMMC on N810171 * GPIO23 and GPIO9 slot 2 EMMC on N810
171 *172 *
172 */173 */
173#define N8X0_SLOT_SWITCH_GPIO 96
174#define N810_EMMC_VSD_GPIO 23
175#define N810_EMMC_VIO_GPIO 9
176
177static int slot1_cover_open;174static int slot1_cover_open;
178static int slot2_cover_open;175static int slot2_cover_open;
179static struct device *mmc_device;176static struct device *mmc_device;
180 177
181static int n8x0_mmc_switch_slot(struct device *dev, int slot)178static struct gpiod_lookup_table nokia8xx_mmc_gpio_table = {
182{179 .dev_id = "mmci-omap.0",
183#ifdef CONFIG_MMC_DEBUG180 .table = {
184 dev_dbg(dev, "Choose slot %d\n", slot + 1);181 /* Slot switch, GPIO 96 */
185#endif182 GPIO_LOOKUP("gpio-80-111", 16,
186 gpio_set_value(N8X0_SLOT_SWITCH_GPIO, slot);183 "switch", GPIO_ACTIVE_HIGH),
187 return 0;184 { }
188}185 },
186};
187
188static struct gpiod_lookup_table nokia810_mmc_gpio_table = {
189 .dev_id = "mmci-omap.0",
190 .table = {
191 /* Slot index 1, VSD power, GPIO 23 */
192 GPIO_LOOKUP_IDX("gpio-16-31", 7,
193 "vsd", 1, GPIO_ACTIVE_HIGH),
194 /* Slot index 1, VIO power, GPIO 9 */
195 GPIO_LOOKUP_IDX("gpio-0-15", 9,
196 "vsd", 1, GPIO_ACTIVE_HIGH),
197 { }
198 },
199};
189 200
190static int n8x0_mmc_set_power_menelaus(struct device *dev, int slot,201static int n8x0_mmc_set_power_menelaus(struct device *dev, int slot,
191 int power_on, int vdd)202 int power_on, int vdd)
@@ -256,31 +267,13 @@ static int n8x0_mmc_set_power_menelaus(struct device *dev, int slot, · 64 unmodified lines
256 return 0;267 return 0;
257}268}
258 269
259static void n810_set_power_emmc(struct device *dev,
260 int power_on)
261{
262 dev_dbg(dev, "Set EMMC power %s\n", power_on ? "on" : "off");
263
264 if (power_on) {
265 gpio_set_value(N810_EMMC_VSD_GPIO, 1);
266 msleep(1);
267 gpio_set_value(N810_EMMC_VIO_GPIO, 1);
268 msleep(1);
269 } else {
270 gpio_set_value(N810_EMMC_VIO_GPIO, 0);
271 msleep(50);
272 gpio_set_value(N810_EMMC_VSD_GPIO, 0);
273 msleep(50);
274 }
275}
276
277static int n8x0_mmc_set_power(struct device *dev, int slot, int power_on,270static int n8x0_mmc_set_power(struct device *dev, int slot, int power_on,
278 int vdd)271 int vdd)
279{272{
280 if (board_is_n800() || slot == 0)273 if (board_is_n800() || slot == 0)
281 return n8x0_mmc_set_power_menelaus(dev, slot, power_on, vdd);274 return n8x0_mmc_set_power_menelaus(dev, slot, power_on, vdd);
282 275
283 n810_set_power_emmc(dev, power_on);276 /* The n810 power will be handled by GPIO code in the driver */
284 277
285 return 0;278 return 0;
286}279}
@@ -418,13 +411,6 @@ static void n8x0_mmc_shutdown(struct device *dev) · 131 unmodified lines
418static void n8x0_mmc_cleanup(struct device *dev)411static void n8x0_mmc_cleanup(struct device *dev)
419{412{
420 menelaus_unregister_mmc_callback();413 menelaus_unregister_mmc_callback();
421
422 gpio_free(N8X0_SLOT_SWITCH_GPIO);
423
424 if (board_is_n810()) {
425 gpio_free(N810_EMMC_VSD_GPIO);
426 gpio_free(N810_EMMC_VIO_GPIO);
427 }
428}414}
429 415
430/*416/*
@@ -433,7 +419,6 @@ static void n8x0_mmc_cleanup(struct device *dev) · 2 unmodified lines
433 */419 */
434static struct omap_mmc_platform_data mmc1_data = {420static struct omap_mmc_platform_data mmc1_data = {
435 .nr_slots = 0,421 .nr_slots = 0,
436 .switch_slot = n8x0_mmc_switch_slot,
437 .init = n8x0_mmc_late_init,422 .init = n8x0_mmc_late_init,
438 .cleanup = n8x0_mmc_cleanup,423 .cleanup = n8x0_mmc_cleanup,
439 .shutdown = n8x0_mmc_shutdown,424 .shutdown = n8x0_mmc_shutdown,
@@ -463,14 +448,9 @@ static struct omap_mmc_platform_data mmc1_data = { · 23 unmodified lines
463 448
464static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC];449static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC];
465 450
466static struct gpio n810_emmc_gpios[] __initdata = {
467 { N810_EMMC_VSD_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot 2 Vddf" },
468 { N810_EMMC_VIO_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot 2 Vdd" },
469};
470
471static void __init n8x0_mmc_init(void)451static void __init n8x0_mmc_init(void)
472{452{
473 int err;453 gpiod_add_lookup_table(&nokia8xx_mmc_gpio_table);
474 454
475 if (board_is_n810()) {455 if (board_is_n810()) {
476 mmc1_data.slots[0].name = "external";456 mmc1_data.slots[0].name = "external";
@@ -483,20 +463,7 @@ static void __init n8x0_mmc_init(void) · 6 unmodified lines
483 */463 */
484 mmc1_data.slots[1].name = "internal";464 mmc1_data.slots[1].name = "internal";
485 mmc1_data.slots[1].ban_openended = 1;465 mmc1_data.slots[1].ban_openended = 1;
486 }466 gpiod_add_lookup_table(&nokia810_mmc_gpio_table);
487
488 err = gpio_request_one(N8X0_SLOT_SWITCH_GPIO, GPIOF_OUT_INIT_LOW,
489 "MMC slot switch");
490 if (err)
491 return;
492
493 if (board_is_n810()) {
494 err = gpio_request_array(n810_emmc_gpios,
495 ARRAY_SIZE(n810_emmc_gpios));
496 if (err) {
497 gpio_free(N8X0_SLOT_SWITCH_GPIO);
498 return;
499 }
500 }467 }
501 468
502 mmc1_data.nr_slots = 2;469 mmc1_data.nr_slots = 2;
drivers/mmc/host/omap.c+44−2
@@ -26,6 +26,7 @@ · 25 unmodified lines
26#include <linux/clk.h>26#include <linux/clk.h>
27#include <linux/scatterlist.h>27#include <linux/scatterlist.h>
28#include <linux/slab.h>28#include <linux/slab.h>
29#include <linux/gpio/consumer.h>
29#include <linux/platform_data/mmc-omap.h>30#include <linux/platform_data/mmc-omap.h>
30 31
31 32
@@ -111,6 +112,9 @@ struct mmc_omap_slot { · 79 unmodified lines
111 struct mmc_request *mrq;112 struct mmc_request *mrq;
112 struct mmc_omap_host *host;113 struct mmc_omap_host *host;
113 struct mmc_host *mmc;114 struct mmc_host *mmc;
115 struct gpio_desc *vsd;
116 struct gpio_desc *vio;
117 struct gpio_desc *cover;
114 struct omap_mmc_slot_data *pdata;118 struct omap_mmc_slot_data *pdata;
115};119};
116 120
@@ -133,6 +137,7 @@ struct mmc_omap_host { · 16 unmodified lines
133 int irq;137 int irq;
134 unsigned char bus_mode;138 unsigned char bus_mode;
135 unsigned int reg_shift;139 unsigned int reg_shift;
140 struct gpio_desc *slot_switch;
136 141
137 struct work_struct cmd_abort_work;142 struct work_struct cmd_abort_work;
138 unsigned abort:1;143 unsigned abort:1;
@@ -216,8 +221,13 @@ no_claim: · 77 unmodified lines
216 221
217 if (host->current_slot != slot) {222 if (host->current_slot != slot) {
218 OMAP_MMC_WRITE(host, CON, slot->saved_con & 0xFC00);223 OMAP_MMC_WRITE(host, CON, slot->saved_con & 0xFC00);
219 if (host->pdata->switch_slot != NULL)224 if (host->slot_switch)
220 host->pdata->switch_slot(mmc_dev(slot->mmc), slot->id);225 /*
226 * With two slots and a simple GPIO switch, setting
227 * the GPIO to 0 selects slot ID 0, setting it to 1
228 * selects slot ID 1.
229 */
230 gpiod_set_value(host->slot_switch, slot->id);
221 host->current_slot = slot;231 host->current_slot = slot;
222 }232 }
223 233
@@ -297,6 +307,9 @@ static void mmc_omap_release_slot(struct mmc_omap_slot *slot, int clk_enabled) · 73 unmodified lines
297static inline307static inline
298int mmc_omap_cover_is_open(struct mmc_omap_slot *slot)308int mmc_omap_cover_is_open(struct mmc_omap_slot *slot)
299{309{
310 /* If we have a GPIO then use that */
311 if (slot->cover)
312 return gpiod_get_value(slot->cover);
300 if (slot->pdata->get_cover_state)313 if (slot->pdata->get_cover_state)
301 return slot->pdata->get_cover_state(mmc_dev(slot->mmc),314 return slot->pdata->get_cover_state(mmc_dev(slot->mmc),
302 slot->id);315 slot->id);
@@ -1106,6 +1119,11 @@ static void mmc_omap_set_power(struct mmc_omap_slot *slot, int power_on, · 803 unmodified lines
1106 1119
1107 host = slot->host;1120 host = slot->host;
1108 1121
1122 if (slot->vsd)
1123 gpiod_set_value(slot->vsd, power_on);
1124 if (slot->vio)
1125 gpiod_set_value(slot->vio, power_on);
1126
1109 if (slot->pdata->set_power != NULL)1127 if (slot->pdata->set_power != NULL)
1110 slot->pdata->set_power(mmc_dev(slot->mmc), slot->id, power_on,1128 slot->pdata->set_power(mmc_dev(slot->mmc), slot->id, power_on,
1111 vdd);1129 vdd);
@@ -1240,6 +1258,23 @@ static int mmc_omap_new_slot(struct mmc_omap_host *host, int id) · 128 unmodified lines
1240 slot->power_mode = MMC_POWER_UNDEFINED;1258 slot->power_mode = MMC_POWER_UNDEFINED;
1241 slot->pdata = &host->pdata->slots[id];1259 slot->pdata = &host->pdata->slots[id];
1242 1260
1261 /* Check for some optional GPIO controls */
1262 slot->vsd = gpiod_get_index_optional(host->dev, "vsd",
1263 id, GPIOD_OUT_LOW);
1264 if (IS_ERR(slot->vsd))
1265 return dev_err_probe(host->dev, PTR_ERR(slot->vsd),
1266 "error looking up VSD GPIO\n");
1267 slot->vio = gpiod_get_index_optional(host->dev, "vio",
1268 id, GPIOD_OUT_LOW);
1269 if (IS_ERR(slot->vio))
1270 return dev_err_probe(host->dev, PTR_ERR(slot->vio),
1271 "error looking up VIO GPIO\n");
1272 slot->cover = gpiod_get_index_optional(host->dev, "cover",
1273 id, GPIOD_IN);
1274 if (IS_ERR(slot->cover))
1275 return dev_err_probe(host->dev, PTR_ERR(slot->cover),
1276 "error looking up cover switch GPIO\n");
1277
1243 host->slots[id] = slot;1278 host->slots[id] = slot;
1244 1279
1245 mmc->caps = 0;1280 mmc->caps = 0;
@@ -1349,6 +1384,13 @@ static int mmc_omap_probe(struct platform_device *pdev) · 103 unmodified lines
1349 if (IS_ERR(host->virt_base))1384 if (IS_ERR(host->virt_base))
1350 return PTR_ERR(host->virt_base);1385 return PTR_ERR(host->virt_base);
1351 1386
1387 host->slot_switch = gpiod_get_optional(host->dev, "switch",
1388 GPIOD_OUT_LOW);
1389 if (IS_ERR(host->slot_switch))
1390 return dev_err_probe(host->dev, PTR_ERR(host->slot_switch),
1391 "error looking up slot switch GPIO\n");
1392
1393
1352 INIT_WORK(&host->slot_release_work, mmc_omap_slot_release_work);1394 INIT_WORK(&host->slot_release_work, mmc_omap_slot_release_work);
1353 INIT_WORK(&host->send_stop_work, mmc_omap_send_stop_work);1395 INIT_WORK(&host->send_stop_work, mmc_omap_send_stop_work);
1354 1396
include/linux/platform_data/mmc-omap.h+0−2
@@ -20,8 +20,6 @@ struct omap_mmc_platform_data { · 19 unmodified lines
20 * maximum frequency on the MMC bus */20 * maximum frequency on the MMC bus */
21 unsigned int max_freq;21 unsigned int max_freq;
22 22
23 /* switch the bus to a new slot */
24 int (*switch_slot)(struct device *dev, int slot);
25 /* initialize board-specific MMC functionality, can be NULL if23 /* initialize board-specific MMC functionality, can be NULL if
26 * not supported */24 * not supported */
27 int (*init)(struct device *dev);25 int (*init)(struct device *dev);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t