Skip to content

Commit e519f0b

Browse files
author
Linus Walleij
committed
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. Fixes: 92bf78b ("gpio: omap: use dynamic allocation of base") Acked-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 767d833 commit e519f0b

5 files changed

Lines changed: 83 additions & 94 deletions

File tree

arch/arm/mach-omap1/board-nokia770.c

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -184,27 +184,23 @@ static struct omap_usb_config nokia770_usb_config __initdata = {
184184

185185
#if IS_ENABLED(CONFIG_MMC_OMAP)
186186

187-
#define NOKIA770_GPIO_MMC_POWER 41
188-
#define NOKIA770_GPIO_MMC_SWITCH 23
189-
190-
static int nokia770_mmc_set_power(struct device *dev, int slot, int power_on,
191-
int vdd)
192-
{
193-
gpio_set_value(NOKIA770_GPIO_MMC_POWER, power_on);
194-
return 0;
195-
}
196-
197-
static int nokia770_mmc_get_cover_state(struct device *dev, int slot)
198-
{
199-
return gpio_get_value(NOKIA770_GPIO_MMC_SWITCH);
200-
}
187+
static struct gpiod_lookup_table nokia770_mmc_gpio_table = {
188+
.dev_id = "mmci-omap.1",
189+
.table = {
190+
/* Slot index 0, VSD power, GPIO 41 */
191+
GPIO_LOOKUP_IDX("gpio-32-47", 9,
192+
"vsd", 0, GPIO_ACTIVE_HIGH),
193+
/* Slot index 0, switch, GPIO 23 */
194+
GPIO_LOOKUP_IDX("gpio-16-31", 7,
195+
"cover", 0, GPIO_ACTIVE_HIGH),
196+
{ }
197+
},
198+
};
201199

202200
static struct omap_mmc_platform_data nokia770_mmc2_data = {
203201
.nr_slots = 1,
204202
.max_freq = 12000000,
205203
.slots[0] = {
206-
.set_power = nokia770_mmc_set_power,
207-
.get_cover_state = nokia770_mmc_get_cover_state,
208204
.ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
209205
.name = "mmcblk",
210206
},
@@ -214,20 +210,7 @@ static struct omap_mmc_platform_data *nokia770_mmc_data[OMAP16XX_NR_MMC];
214210

215211
static void __init nokia770_mmc_init(void)
216212
{
217-
int ret;
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-
213+
gpiod_add_lookup_table(&nokia770_mmc_gpio_table);
231214
/* Only the second MMC controller is used */
232215
nokia770_mmc_data[1] = &nokia770_mmc2_data;
233216
omap1_init_mmc(nokia770_mmc_data, OMAP16XX_NR_MMC);

arch/arm/mach-omap1/board-sx1-mmc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* Copyright (C) 2007 Instituto Nokia de Tecnologia - INdT
1010
*/
1111

12-
#include <linux/gpio.h>
1312
#include <linux/platform_device.h>
1413

1514
#include "hardware.h"

arch/arm/mach-omap2/board-n8x0.c

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/clk.h>
1212
#include <linux/delay.h>
1313
#include <linux/gpio.h>
14+
#include <linux/gpio/machine.h>
1415
#include <linux/init.h>
1516
#include <linux/io.h>
1617
#include <linux/irq.h>
@@ -170,22 +171,32 @@ static struct spi_board_info n800_spi_board_info[] __initdata = {
170171
* GPIO23 and GPIO9 slot 2 EMMC on N810
171172
*
172173
*/
173-
#define N8X0_SLOT_SWITCH_GPIO 96
174-
#define N810_EMMC_VSD_GPIO 23
175-
#define N810_EMMC_VIO_GPIO 9
176-
177174
static int slot1_cover_open;
178175
static int slot2_cover_open;
179176
static struct device *mmc_device;
180177

181-
static int n8x0_mmc_switch_slot(struct device *dev, int slot)
182-
{
183-
#ifdef CONFIG_MMC_DEBUG
184-
dev_dbg(dev, "Choose slot %d\n", slot + 1);
185-
#endif
186-
gpio_set_value(N8X0_SLOT_SWITCH_GPIO, slot);
187-
return 0;
188-
}
178+
static struct gpiod_lookup_table nokia8xx_mmc_gpio_table = {
179+
.dev_id = "mmci-omap.0",
180+
.table = {
181+
/* Slot switch, GPIO 96 */
182+
GPIO_LOOKUP("gpio-80-111", 16,
183+
"switch", GPIO_ACTIVE_HIGH),
184+
{ }
185+
},
186+
};
187+
188+
static 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+
};
189200

190201
static int n8x0_mmc_set_power_menelaus(struct device *dev, int slot,
191202
int power_on, int vdd)
@@ -256,31 +267,13 @@ static int n8x0_mmc_set_power_menelaus(struct device *dev, int slot,
256267
return 0;
257268
}
258269

259-
static 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-
277270
static int n8x0_mmc_set_power(struct device *dev, int slot, int power_on,
278271
int vdd)
279272
{
280273
if (board_is_n800() || slot == 0)
281274
return n8x0_mmc_set_power_menelaus(dev, slot, power_on, vdd);
282275

283-
n810_set_power_emmc(dev, power_on);
276+
/* The n810 power will be handled by GPIO code in the driver */
284277

285278
return 0;
286279
}
@@ -418,13 +411,6 @@ static void n8x0_mmc_shutdown(struct device *dev)
418411
static void n8x0_mmc_cleanup(struct device *dev)
419412
{
420413
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-
}
428414
}
429415

430416
/*
@@ -433,7 +419,6 @@ static void n8x0_mmc_cleanup(struct device *dev)
433419
*/
434420
static struct omap_mmc_platform_data mmc1_data = {
435421
.nr_slots = 0,
436-
.switch_slot = n8x0_mmc_switch_slot,
437422
.init = n8x0_mmc_late_init,
438423
.cleanup = n8x0_mmc_cleanup,
439424
.shutdown = n8x0_mmc_shutdown,
@@ -463,14 +448,9 @@ static struct omap_mmc_platform_data mmc1_data = {
463448

464449
static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC];
465450

466-
static 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-
471451
static void __init n8x0_mmc_init(void)
472452
{
473-
int err;
453+
gpiod_add_lookup_table(&nokia8xx_mmc_gpio_table);
474454

475455
if (board_is_n810()) {
476456
mmc1_data.slots[0].name = "external";
@@ -483,20 +463,7 @@ static void __init n8x0_mmc_init(void)
483463
*/
484464
mmc1_data.slots[1].name = "internal";
485465
mmc1_data.slots[1].ban_openended = 1;
486-
}
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-
}
466+
gpiod_add_lookup_table(&nokia810_mmc_gpio_table);
500467
}
501468

502469
mmc1_data.nr_slots = 2;

drivers/mmc/host/omap.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/clk.h>
2727
#include <linux/scatterlist.h>
2828
#include <linux/slab.h>
29+
#include <linux/gpio/consumer.h>
2930
#include <linux/platform_data/mmc-omap.h>
3031

3132

@@ -111,6 +112,9 @@ struct mmc_omap_slot {
111112
struct mmc_request *mrq;
112113
struct mmc_omap_host *host;
113114
struct mmc_host *mmc;
115+
struct gpio_desc *vsd;
116+
struct gpio_desc *vio;
117+
struct gpio_desc *cover;
114118
struct omap_mmc_slot_data *pdata;
115119
};
116120

@@ -133,6 +137,7 @@ struct mmc_omap_host {
133137
int irq;
134138
unsigned char bus_mode;
135139
unsigned int reg_shift;
140+
struct gpio_desc *slot_switch;
136141

137142
struct work_struct cmd_abort_work;
138143
unsigned abort:1;
@@ -216,8 +221,13 @@ static void mmc_omap_select_slot(struct mmc_omap_slot *slot, int claimed)
216221

217222
if (host->current_slot != slot) {
218223
OMAP_MMC_WRITE(host, CON, slot->saved_con & 0xFC00);
219-
if (host->pdata->switch_slot != NULL)
220-
host->pdata->switch_slot(mmc_dev(slot->mmc), slot->id);
224+
if (host->slot_switch)
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);
221231
host->current_slot = slot;
222232
}
223233

@@ -297,6 +307,9 @@ static void mmc_omap_release_slot(struct mmc_omap_slot *slot, int clk_enabled)
297307
static inline
298308
int mmc_omap_cover_is_open(struct mmc_omap_slot *slot)
299309
{
310+
/* If we have a GPIO then use that */
311+
if (slot->cover)
312+
return gpiod_get_value(slot->cover);
300313
if (slot->pdata->get_cover_state)
301314
return slot->pdata->get_cover_state(mmc_dev(slot->mmc),
302315
slot->id);
@@ -1106,6 +1119,11 @@ static void mmc_omap_set_power(struct mmc_omap_slot *slot, int power_on,
11061119

11071120
host = slot->host;
11081121

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+
11091127
if (slot->pdata->set_power != NULL)
11101128
slot->pdata->set_power(mmc_dev(slot->mmc), slot->id, power_on,
11111129
vdd);
@@ -1240,6 +1258,23 @@ static int mmc_omap_new_slot(struct mmc_omap_host *host, int id)
12401258
slot->power_mode = MMC_POWER_UNDEFINED;
12411259
slot->pdata = &host->pdata->slots[id];
12421260

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+
12431278
host->slots[id] = slot;
12441279

12451280
mmc->caps = 0;
@@ -1349,6 +1384,13 @@ static int mmc_omap_probe(struct platform_device *pdev)
13491384
if (IS_ERR(host->virt_base))
13501385
return PTR_ERR(host->virt_base);
13511386

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+
13521394
INIT_WORK(&host->slot_release_work, mmc_omap_slot_release_work);
13531395
INIT_WORK(&host->send_stop_work, mmc_omap_send_stop_work);
13541396

include/linux/platform_data/mmc-omap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ struct omap_mmc_platform_data {
2020
* maximum frequency on the MMC bus */
2121
unsigned int max_freq;
2222

23-
/* switch the bus to a new slot */
24-
int (*switch_slot)(struct device *dev, int slot);
2523
/* initialize board-specific MMC functionality, can be NULL if
2624
* not supported */
2725
int (*init)(struct device *dev);

0 commit comments

Comments
 (0)