Skip to content

Commit ce6e947

Browse files
bala-gunasundarstorulf
authored andcommitted
mmc: atmel-mci: Convert to gpio descriptors
Replace the legacy GPIO APIs with gpio descriptor consumer interface. To maintain backward compatibility, we rely on the "cd-inverted" property to manage the invertion flag instead of GPIO property. Signed-off-by: Balamanikandan Gunasundar <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent d83d251 commit ce6e947

File tree

2 files changed

+39
-42
lines changed

2 files changed

+39
-42
lines changed

drivers/mmc/host/atmel-mci.c

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
#include <linux/dmaengine.h>
1212
#include <linux/dma-mapping.h>
1313
#include <linux/err.h>
14-
#include <linux/gpio.h>
1514
#include <linux/init.h>
1615
#include <linux/interrupt.h>
1716
#include <linux/io.h>
1817
#include <linux/ioport.h>
1918
#include <linux/module.h>
2019
#include <linux/of.h>
21-
#include <linux/of_gpio.h>
20+
#include <linux/irq.h>
21+
#include <linux/gpio/consumer.h>
2222
#include <linux/platform_device.h>
2323
#include <linux/scatterlist.h>
2424
#include <linux/seq_file.h>
@@ -387,8 +387,8 @@ struct atmel_mci_slot {
387387
#define ATMCI_CARD_NEED_INIT 1
388388
#define ATMCI_SHUTDOWN 2
389389

390-
int detect_pin;
391-
int wp_pin;
390+
struct gpio_desc *detect_pin;
391+
struct gpio_desc *wp_pin;
392392
bool detect_is_active_high;
393393

394394
struct timer_list detect_timer;
@@ -636,7 +636,10 @@ atmci_of_init(struct platform_device *pdev)
636636
pdata->slot[slot_id].bus_width = 1;
637637

638638
pdata->slot[slot_id].detect_pin =
639-
of_get_named_gpio(cnp, "cd-gpios", 0);
639+
devm_fwnode_gpiod_get(&pdev->dev, of_fwnode_handle(cnp),
640+
"cd", GPIOD_IN, "cd-gpios");
641+
if (IS_ERR(pdata->slot[slot_id].detect_pin))
642+
pdata->slot[slot_id].detect_pin = NULL;
640643

641644
pdata->slot[slot_id].detect_is_active_high =
642645
of_property_read_bool(cnp, "cd-inverted");
@@ -645,7 +648,10 @@ atmci_of_init(struct platform_device *pdev)
645648
of_property_read_bool(cnp, "non-removable");
646649

647650
pdata->slot[slot_id].wp_pin =
648-
of_get_named_gpio(cnp, "wp-gpios", 0);
651+
devm_fwnode_gpiod_get(&pdev->dev, of_fwnode_handle(cnp),
652+
"wp", GPIOD_IN, "wp-gpios");
653+
if (IS_ERR(pdata->slot[slot_id].wp_pin))
654+
pdata->slot[slot_id].wp_pin = NULL;
649655
}
650656

651657
return pdata;
@@ -1508,8 +1514,8 @@ static int atmci_get_ro(struct mmc_host *mmc)
15081514
int read_only = -ENOSYS;
15091515
struct atmel_mci_slot *slot = mmc_priv(mmc);
15101516

1511-
if (gpio_is_valid(slot->wp_pin)) {
1512-
read_only = gpio_get_value(slot->wp_pin);
1517+
if (slot->wp_pin) {
1518+
read_only = gpiod_get_value(slot->wp_pin);
15131519
dev_dbg(&mmc->class_dev, "card is %s\n",
15141520
read_only ? "read-only" : "read-write");
15151521
}
@@ -1522,8 +1528,8 @@ static int atmci_get_cd(struct mmc_host *mmc)
15221528
int present = -ENOSYS;
15231529
struct atmel_mci_slot *slot = mmc_priv(mmc);
15241530

1525-
if (gpio_is_valid(slot->detect_pin)) {
1526-
present = !(gpio_get_value(slot->detect_pin) ^
1531+
if (slot->detect_pin) {
1532+
present = !(gpiod_get_raw_value(slot->detect_pin) ^
15271533
slot->detect_is_active_high);
15281534
dev_dbg(&mmc->class_dev, "card is %spresent\n",
15291535
present ? "" : "not ");
@@ -1636,8 +1642,8 @@ static void atmci_detect_change(struct timer_list *t)
16361642
if (test_bit(ATMCI_SHUTDOWN, &slot->flags))
16371643
return;
16381644

1639-
enable_irq(gpio_to_irq(slot->detect_pin));
1640-
present = !(gpio_get_value(slot->detect_pin) ^
1645+
enable_irq(gpiod_to_irq(slot->detect_pin));
1646+
present = !(gpiod_get_raw_value(slot->detect_pin) ^
16411647
slot->detect_is_active_high);
16421648
present_old = test_bit(ATMCI_CARD_PRESENT, &slot->flags);
16431649

@@ -2236,9 +2242,9 @@ static int atmci_init_slot(struct atmel_mci *host,
22362242
dev_dbg(&mmc->class_dev,
22372243
"slot[%u]: bus_width=%u, detect_pin=%d, "
22382244
"detect_is_active_high=%s, wp_pin=%d\n",
2239-
id, slot_data->bus_width, slot_data->detect_pin,
2245+
id, slot_data->bus_width, desc_to_gpio(slot_data->detect_pin),
22402246
slot_data->detect_is_active_high ? "true" : "false",
2241-
slot_data->wp_pin);
2247+
desc_to_gpio(slot_data->wp_pin));
22422248

22432249
mmc->ops = &atmci_ops;
22442250
mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512);
@@ -2274,31 +2280,24 @@ static int atmci_init_slot(struct atmel_mci *host,
22742280

22752281
/* Assume card is present initially */
22762282
set_bit(ATMCI_CARD_PRESENT, &slot->flags);
2277-
if (gpio_is_valid(slot->detect_pin)) {
2278-
if (devm_gpio_request(&host->pdev->dev, slot->detect_pin,
2279-
"mmc_detect")) {
2280-
dev_dbg(&mmc->class_dev, "no detect pin available\n");
2281-
slot->detect_pin = -EBUSY;
2282-
} else if (gpio_get_value(slot->detect_pin) ^
2283-
slot->detect_is_active_high) {
2283+
if (slot->detect_pin) {
2284+
if (gpiod_get_raw_value(slot->detect_pin) ^
2285+
slot->detect_is_active_high) {
22842286
clear_bit(ATMCI_CARD_PRESENT, &slot->flags);
22852287
}
2288+
} else {
2289+
dev_dbg(&mmc->class_dev, "no detect pin available\n");
22862290
}
22872291

2288-
if (!gpio_is_valid(slot->detect_pin)) {
2292+
if (!slot->detect_pin) {
22892293
if (slot_data->non_removable)
22902294
mmc->caps |= MMC_CAP_NONREMOVABLE;
22912295
else
22922296
mmc->caps |= MMC_CAP_NEEDS_POLL;
22932297
}
22942298

2295-
if (gpio_is_valid(slot->wp_pin)) {
2296-
if (devm_gpio_request(&host->pdev->dev, slot->wp_pin,
2297-
"mmc_wp")) {
2298-
dev_dbg(&mmc->class_dev, "no WP pin available\n");
2299-
slot->wp_pin = -EBUSY;
2300-
}
2301-
}
2299+
if (!slot->wp_pin)
2300+
dev_dbg(&mmc->class_dev, "no WP pin available\n");
23022301

23032302
host->slot[id] = slot;
23042303
mmc_regulator_get_supply(mmc);
@@ -2308,18 +2307,18 @@ static int atmci_init_slot(struct atmel_mci *host,
23082307
return ret;
23092308
}
23102309

2311-
if (gpio_is_valid(slot->detect_pin)) {
2310+
if (slot->detect_pin) {
23122311
timer_setup(&slot->detect_timer, atmci_detect_change, 0);
23132312

2314-
ret = request_irq(gpio_to_irq(slot->detect_pin),
2315-
atmci_detect_interrupt,
2316-
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
2317-
"mmc-detect", slot);
2313+
ret = request_irq(gpiod_to_irq(slot->detect_pin),
2314+
atmci_detect_interrupt,
2315+
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
2316+
"mmc-detect", slot);
23182317
if (ret) {
23192318
dev_dbg(&mmc->class_dev,
23202319
"could not request IRQ %d for detect pin\n",
2321-
gpio_to_irq(slot->detect_pin));
2322-
slot->detect_pin = -EBUSY;
2320+
gpiod_to_irq(slot->detect_pin));
2321+
slot->detect_pin = NULL;
23232322
}
23242323
}
23252324

@@ -2338,10 +2337,8 @@ static void atmci_cleanup_slot(struct atmel_mci_slot *slot,
23382337

23392338
mmc_remove_host(slot->mmc);
23402339

2341-
if (gpio_is_valid(slot->detect_pin)) {
2342-
int pin = slot->detect_pin;
2343-
2344-
free_irq(gpio_to_irq(pin), slot);
2340+
if (slot->detect_pin) {
2341+
free_irq(gpiod_to_irq(slot->detect_pin), slot);
23452342
del_timer_sync(&slot->detect_timer);
23462343
}
23472344

include/linux/atmel-mci.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
*/
2727
struct mci_slot_pdata {
2828
unsigned int bus_width;
29-
int detect_pin;
30-
int wp_pin;
29+
struct gpio_desc *detect_pin;
30+
struct gpio_desc *wp_pin;
3131
bool detect_is_active_high;
3232
bool non_removable;
3333
};

0 commit comments

Comments
 (0)