Commit ce6e9472 authored by Balamanikandan Gunasundar's avatar Balamanikandan Gunasundar Committed by Ulf Hansson

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: default avatarBalamanikandan Gunasundar <balamanikandan.gunasundar@microchip.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20230825095157.76073-2-balamanikandan.gunasundar@microchip.comSigned-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent d83d251b
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
#include <linux/dmaengine.h> #include <linux/dmaengine.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/gpio.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_gpio.h> #include <linux/irq.h>
#include <linux/gpio/consumer.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
...@@ -387,8 +387,8 @@ struct atmel_mci_slot { ...@@ -387,8 +387,8 @@ struct atmel_mci_slot {
#define ATMCI_CARD_NEED_INIT 1 #define ATMCI_CARD_NEED_INIT 1
#define ATMCI_SHUTDOWN 2 #define ATMCI_SHUTDOWN 2
int detect_pin; struct gpio_desc *detect_pin;
int wp_pin; struct gpio_desc *wp_pin;
bool detect_is_active_high; bool detect_is_active_high;
struct timer_list detect_timer; struct timer_list detect_timer;
...@@ -636,7 +636,10 @@ atmci_of_init(struct platform_device *pdev) ...@@ -636,7 +636,10 @@ atmci_of_init(struct platform_device *pdev)
pdata->slot[slot_id].bus_width = 1; pdata->slot[slot_id].bus_width = 1;
pdata->slot[slot_id].detect_pin = pdata->slot[slot_id].detect_pin =
of_get_named_gpio(cnp, "cd-gpios", 0); devm_fwnode_gpiod_get(&pdev->dev, of_fwnode_handle(cnp),
"cd", GPIOD_IN, "cd-gpios");
if (IS_ERR(pdata->slot[slot_id].detect_pin))
pdata->slot[slot_id].detect_pin = NULL;
pdata->slot[slot_id].detect_is_active_high = pdata->slot[slot_id].detect_is_active_high =
of_property_read_bool(cnp, "cd-inverted"); of_property_read_bool(cnp, "cd-inverted");
...@@ -645,7 +648,10 @@ atmci_of_init(struct platform_device *pdev) ...@@ -645,7 +648,10 @@ atmci_of_init(struct platform_device *pdev)
of_property_read_bool(cnp, "non-removable"); of_property_read_bool(cnp, "non-removable");
pdata->slot[slot_id].wp_pin = pdata->slot[slot_id].wp_pin =
of_get_named_gpio(cnp, "wp-gpios", 0); devm_fwnode_gpiod_get(&pdev->dev, of_fwnode_handle(cnp),
"wp", GPIOD_IN, "wp-gpios");
if (IS_ERR(pdata->slot[slot_id].wp_pin))
pdata->slot[slot_id].wp_pin = NULL;
} }
return pdata; return pdata;
...@@ -1508,8 +1514,8 @@ static int atmci_get_ro(struct mmc_host *mmc) ...@@ -1508,8 +1514,8 @@ static int atmci_get_ro(struct mmc_host *mmc)
int read_only = -ENOSYS; int read_only = -ENOSYS;
struct atmel_mci_slot *slot = mmc_priv(mmc); struct atmel_mci_slot *slot = mmc_priv(mmc);
if (gpio_is_valid(slot->wp_pin)) { if (slot->wp_pin) {
read_only = gpio_get_value(slot->wp_pin); read_only = gpiod_get_value(slot->wp_pin);
dev_dbg(&mmc->class_dev, "card is %s\n", dev_dbg(&mmc->class_dev, "card is %s\n",
read_only ? "read-only" : "read-write"); read_only ? "read-only" : "read-write");
} }
...@@ -1522,8 +1528,8 @@ static int atmci_get_cd(struct mmc_host *mmc) ...@@ -1522,8 +1528,8 @@ static int atmci_get_cd(struct mmc_host *mmc)
int present = -ENOSYS; int present = -ENOSYS;
struct atmel_mci_slot *slot = mmc_priv(mmc); struct atmel_mci_slot *slot = mmc_priv(mmc);
if (gpio_is_valid(slot->detect_pin)) { if (slot->detect_pin) {
present = !(gpio_get_value(slot->detect_pin) ^ present = !(gpiod_get_raw_value(slot->detect_pin) ^
slot->detect_is_active_high); slot->detect_is_active_high);
dev_dbg(&mmc->class_dev, "card is %spresent\n", dev_dbg(&mmc->class_dev, "card is %spresent\n",
present ? "" : "not "); present ? "" : "not ");
...@@ -1636,8 +1642,8 @@ static void atmci_detect_change(struct timer_list *t) ...@@ -1636,8 +1642,8 @@ static void atmci_detect_change(struct timer_list *t)
if (test_bit(ATMCI_SHUTDOWN, &slot->flags)) if (test_bit(ATMCI_SHUTDOWN, &slot->flags))
return; return;
enable_irq(gpio_to_irq(slot->detect_pin)); enable_irq(gpiod_to_irq(slot->detect_pin));
present = !(gpio_get_value(slot->detect_pin) ^ present = !(gpiod_get_raw_value(slot->detect_pin) ^
slot->detect_is_active_high); slot->detect_is_active_high);
present_old = test_bit(ATMCI_CARD_PRESENT, &slot->flags); present_old = test_bit(ATMCI_CARD_PRESENT, &slot->flags);
...@@ -2236,9 +2242,9 @@ static int atmci_init_slot(struct atmel_mci *host, ...@@ -2236,9 +2242,9 @@ static int atmci_init_slot(struct atmel_mci *host,
dev_dbg(&mmc->class_dev, dev_dbg(&mmc->class_dev,
"slot[%u]: bus_width=%u, detect_pin=%d, " "slot[%u]: bus_width=%u, detect_pin=%d, "
"detect_is_active_high=%s, wp_pin=%d\n", "detect_is_active_high=%s, wp_pin=%d\n",
id, slot_data->bus_width, slot_data->detect_pin, id, slot_data->bus_width, desc_to_gpio(slot_data->detect_pin),
slot_data->detect_is_active_high ? "true" : "false", slot_data->detect_is_active_high ? "true" : "false",
slot_data->wp_pin); desc_to_gpio(slot_data->wp_pin));
mmc->ops = &atmci_ops; mmc->ops = &atmci_ops;
mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512); mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512);
...@@ -2274,31 +2280,24 @@ static int atmci_init_slot(struct atmel_mci *host, ...@@ -2274,31 +2280,24 @@ static int atmci_init_slot(struct atmel_mci *host,
/* Assume card is present initially */ /* Assume card is present initially */
set_bit(ATMCI_CARD_PRESENT, &slot->flags); set_bit(ATMCI_CARD_PRESENT, &slot->flags);
if (gpio_is_valid(slot->detect_pin)) { if (slot->detect_pin) {
if (devm_gpio_request(&host->pdev->dev, slot->detect_pin, if (gpiod_get_raw_value(slot->detect_pin) ^
"mmc_detect")) {
dev_dbg(&mmc->class_dev, "no detect pin available\n");
slot->detect_pin = -EBUSY;
} else if (gpio_get_value(slot->detect_pin) ^
slot->detect_is_active_high) { slot->detect_is_active_high) {
clear_bit(ATMCI_CARD_PRESENT, &slot->flags); clear_bit(ATMCI_CARD_PRESENT, &slot->flags);
} }
} else {
dev_dbg(&mmc->class_dev, "no detect pin available\n");
} }
if (!gpio_is_valid(slot->detect_pin)) { if (!slot->detect_pin) {
if (slot_data->non_removable) if (slot_data->non_removable)
mmc->caps |= MMC_CAP_NONREMOVABLE; mmc->caps |= MMC_CAP_NONREMOVABLE;
else else
mmc->caps |= MMC_CAP_NEEDS_POLL; mmc->caps |= MMC_CAP_NEEDS_POLL;
} }
if (gpio_is_valid(slot->wp_pin)) { if (!slot->wp_pin)
if (devm_gpio_request(&host->pdev->dev, slot->wp_pin,
"mmc_wp")) {
dev_dbg(&mmc->class_dev, "no WP pin available\n"); dev_dbg(&mmc->class_dev, "no WP pin available\n");
slot->wp_pin = -EBUSY;
}
}
host->slot[id] = slot; host->slot[id] = slot;
mmc_regulator_get_supply(mmc); mmc_regulator_get_supply(mmc);
...@@ -2308,18 +2307,18 @@ static int atmci_init_slot(struct atmel_mci *host, ...@@ -2308,18 +2307,18 @@ static int atmci_init_slot(struct atmel_mci *host,
return ret; return ret;
} }
if (gpio_is_valid(slot->detect_pin)) { if (slot->detect_pin) {
timer_setup(&slot->detect_timer, atmci_detect_change, 0); timer_setup(&slot->detect_timer, atmci_detect_change, 0);
ret = request_irq(gpio_to_irq(slot->detect_pin), ret = request_irq(gpiod_to_irq(slot->detect_pin),
atmci_detect_interrupt, atmci_detect_interrupt,
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
"mmc-detect", slot); "mmc-detect", slot);
if (ret) { if (ret) {
dev_dbg(&mmc->class_dev, dev_dbg(&mmc->class_dev,
"could not request IRQ %d for detect pin\n", "could not request IRQ %d for detect pin\n",
gpio_to_irq(slot->detect_pin)); gpiod_to_irq(slot->detect_pin));
slot->detect_pin = -EBUSY; slot->detect_pin = NULL;
} }
} }
...@@ -2338,10 +2337,8 @@ static void atmci_cleanup_slot(struct atmel_mci_slot *slot, ...@@ -2338,10 +2337,8 @@ static void atmci_cleanup_slot(struct atmel_mci_slot *slot,
mmc_remove_host(slot->mmc); mmc_remove_host(slot->mmc);
if (gpio_is_valid(slot->detect_pin)) { if (slot->detect_pin) {
int pin = slot->detect_pin; free_irq(gpiod_to_irq(slot->detect_pin), slot);
free_irq(gpio_to_irq(pin), slot);
del_timer_sync(&slot->detect_timer); del_timer_sync(&slot->detect_timer);
} }
......
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
*/ */
struct mci_slot_pdata { struct mci_slot_pdata {
unsigned int bus_width; unsigned int bus_width;
int detect_pin; struct gpio_desc *detect_pin;
int wp_pin; struct gpio_desc *wp_pin;
bool detect_is_active_high; bool detect_is_active_high;
bool non_removable; bool non_removable;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment