Skip to contentSkip to conversation

mmc: atmel-mci: Get rid of external platform data

PATCH In review Andy Shevchenko 2 participants 4 messages Feb 15, 2023 – Feb 16, 2023

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mmc: atmel-mci: Get rid of external platform data

There is no in-kernel user that uses platform data. Hide it. This will allow the further cleanups to the driver.

---
 drivers/mmc/host/atmel-mci.c | 75 ++++++++++++++++++++----------------
 include/linux/atmel-mci.h    | 46 ----------------------
 2 files changed, 41 insertions(+), 80 deletions(-)
 delete mode 100644 include/linux/atmel-mci.h
drivers/mmc/host/atmel-mci.c +41 -34
index b51001c68786..fad5e6b4c654 100644
@@ -30,7 +30,6 @@
 #include <linux/mmc/host.h>
 #include <linux/mmc/sdio.h>
 
-#include <linux/atmel-mci.h>
 #include <linux/atmel_pdc.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
@@ -40,6 +39,41 @@
 #include <asm/io.h>
 #include <asm/unaligned.h>
 
+#define ATMCI_MAX_NR_SLOTS	2
+
+/**
+ * struct mci_slot_pdata - board-specific per-slot configuration
+ * @bus_width: Number of data lines wired up the slot
+ * @detect_pin: GPIO pin wired to the card detect switch
+ * @wp_pin: GPIO pin wired to the write protect sensor
+ * @detect_is_active_high: The state of the detect pin when it is active
+ * @non_removable: The slot is not removable, only detect once
+ *
+ * If a given slot is not present on the board, @bus_width should be
+ * set to 0. The other fields are ignored in this case.
+ *
+ * Any pins that aren't available should be set to a negative value.
+ *
+ * Note that support for multiple slots is experimental -- some cards
+ * might get upset if we don't get the clock management exactly right.
+ * But in most cases, it should work just fine.
+ */
+struct mci_slot_pdata {
+	unsigned int		bus_width;
+	int			detect_pin;
+	int			wp_pin;
+	bool			detect_is_active_high;
+	bool			non_removable;
+};
+
+/**
+ * struct mci_platform_data - board-specific MMC/SDcard configuration
+ * @slot: Per-slot configuration data.
+ */
+struct mci_platform_data {
+	struct mci_slot_pdata	slot[ATMCI_MAX_NR_SLOTS];
+};
+
 /*
  * Superset of MCI IP registers integrated in Atmel AT91 Processor
  * Registers and bitfields marked with [2] are only available in MCI2
@@ -593,7 +627,6 @@ static void atmci_init_debugfs(struct atmel_mci_slot *slot)
 			   &host->completed_events);
 }
 
-#if defined(CONFIG_OF)
 static const struct of_device_id atmci_dt_ids[] = {
 	{ .compatible = "atmel,hsmci" },
 	{ /* sentinel */ }
@@ -651,13 +684,6 @@ atmci_of_init(struct platform_device *pdev)
 
 	return pdata;
 }
-#else /* CONFIG_OF */
-static inline struct mci_platform_data*
-atmci_of_init(struct platform_device *dev)
-{
-	return ERR_PTR(-EINVAL);
-}
-#endif
 
 static inline unsigned int atmci_get_version(struct atmel_mci *host)
 {
@@ -2353,23 +2379,6 @@ static void atmci_cleanup_slot(struct atmel_mci_slot *slot,
 static int atmci_configure_dma(struct atmel_mci *host)
 {
 	host->dma.chan = dma_request_chan(&host->pdev->dev, "rxtx");
-
-	if (PTR_ERR(host->dma.chan) == -ENODEV) {
-		struct mci_platform_data *pdata = host->pdev->dev.platform_data;
-		dma_cap_mask_t mask;
-
-		if (!pdata || !pdata->dma_filter)
-			return -ENODEV;
-
-		dma_cap_zero(mask);
-		dma_cap_set(DMA_SLAVE, mask);
-
-		host->dma.chan = dma_request_channel(mask, pdata->dma_filter,
-						     pdata->dma_slave);
-		if (!host->dma.chan)
-			host->dma.chan = ERR_PTR(-ENODEV);
-	}
-
 	if (IS_ERR(host->dma.chan))
 		return PTR_ERR(host->dma.chan);
 
@@ -2457,13 +2466,11 @@ static int atmci_probe(struct platform_device *pdev)
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!regs)
 		return -ENXIO;
-	pdata = pdev->dev.platform_data;
-	if (!pdata) {
-		pdata = atmci_of_init(pdev);
-		if (IS_ERR(pdata)) {
-			dev_err(&pdev->dev, "platform data not available\n");
-			return PTR_ERR(pdata);
-		}
+
+	pdata = atmci_of_init(pdev);
+	if (IS_ERR(pdata)) {
+		dev_err(&pdev->dev, "platform data not available\n");
+		return PTR_ERR(pdata);
 	}
 
 	irq = platform_get_irq(pdev, 0);
@@ -2668,7 +2675,7 @@ static struct platform_driver atmci_driver = {
 	.driver		= {
 		.name		= "atmel_mci",
 		.probe_type	= PROBE_PREFER_ASYNCHRONOUS,
-		.of_match_table	= of_match_ptr(atmci_dt_ids),
+		.of_match_table	= atmci_dt_ids,
 		.pm		= &atmci_dev_pm_ops,
 	},
 };
include/linux/atmel-mci.h deleted +0 -46

46 lines not on this page · raw message

Signature · 1 line
2.39.1
#1 lore raw

PATCH 2/2 mmc: atmel-mci: Convert to agnostic GPIO API

The of_gpio.h is going to be removed. In preparation of that convert the driver to the agnostic API.

---
 drivers/mmc/host/atmel-mci.c | 106 ++++++++++++++++-------------------
 1 file changed, 48 insertions(+), 58 deletions(-)
drivers/mmc/host/atmel-mci.c +48 -58
index fad5e6b4c654..79876e3152e6 100644
@@ -11,7 +11,7 @@
 #include <linux/dmaengine.h>
 #include <linux/dma-mapping.h>
 #include <linux/err.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
@@ -19,7 +19,6 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 #include <linux/scatterlist.h>
 #include <linux/seq_file.h>
@@ -44,8 +43,8 @@
 /**
  * struct mci_slot_pdata - board-specific per-slot configuration
  * @bus_width: Number of data lines wired up the slot
- * @detect_pin: GPIO pin wired to the card detect switch
- * @wp_pin: GPIO pin wired to the write protect sensor
+ * @wp_gpio: GPIO pin wired to the write protect sensor
+ * @detect_gpio: GPIO pin wired to the card detect switch
  * @detect_is_active_high: The state of the detect pin when it is active
  * @non_removable: The slot is not removable, only detect once
  *
@@ -60,8 +59,8 @@
  */
 struct mci_slot_pdata {
 	unsigned int		bus_width;
-	int			detect_pin;
-	int			wp_pin;
+	struct gpio_desc	*wp_gpio;
+	struct gpio_desc	*detect_gpio;
 	bool			detect_is_active_high;
 	bool			non_removable;
 };
@@ -399,12 +398,12 @@ struct atmel_mci {
  *	&struct atmel_mci.
  * @clock: Clock rate configured by set_ios(). Protected by host->lock.
  * @flags: Random state bits associated with the slot.
- * @detect_pin: GPIO pin used for card detection, or negative if not
- *	available.
- * @wp_pin: GPIO pin used for card write protect sending, or negative
+ * @wp_gpio: GPIO pin used for card write protect sending, or NULL
  *	if not available.
+ * @detect_gpio: GPIO pin used for card detection, or negative if not
+ *	available.
  * @detect_is_active_high: The state of the detect pin when it is active.
- * @detect_timer: Timer used for debouncing @detect_pin interrupts.
+ * @detect_timer: Timer used for debouncing @detect_gpio interrupts.
  */
 struct atmel_mci_slot {
 	struct mmc_host		*mmc;
@@ -422,8 +421,9 @@ struct atmel_mci_slot {
 #define ATMCI_CARD_NEED_INIT	1
 #define ATMCI_SHUTDOWN		2
 
-	int			detect_pin;
-	int			wp_pin;
+	struct gpio_desc	*wp_gpio;
+
+	struct gpio_desc	*detect_gpio;
 	bool			detect_is_active_high;
 
 	struct timer_list	detect_timer;
@@ -637,7 +637,8 @@ MODULE_DEVICE_TABLE(of, atmci_dt_ids);
 static struct mci_platform_data*
 atmci_of_init(struct platform_device *pdev)
 {
-	struct device_node *np = pdev->dev.of_node;
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
 	struct device_node *cnp;
 	struct mci_platform_data *pdata;
 	u32 slot_id;
@@ -669,8 +670,10 @@ atmci_of_init(struct platform_device *pdev)
 		                         &pdata->slot[slot_id].bus_width))
 			pdata->slot[slot_id].bus_width = 1;
 
-		pdata->slot[slot_id].detect_pin =
-			of_get_named_gpio(cnp, "cd-gpios", 0);
+		pdata->slot[slot_id].detect_gpio = devm_gpiod_get_optional(dev, "cd", GPIOD_IN);
+		if (!pdata->slot[slot_id].detect_gpio)
+			dev_dbg(dev, "no detect pin available\n");
+		gpiod_set_consumer_name(pdata->slot[slot_id].detect_gpio, "mmc_detect");
 
 		pdata->slot[slot_id].detect_is_active_high =
 			of_property_read_bool(cnp, "cd-inverted");
@@ -678,8 +681,10 @@ atmci_of_init(struct platform_device *pdev)
 		pdata->slot[slot_id].non_removable =
 			of_property_read_bool(cnp, "non-removable");
 
-		pdata->slot[slot_id].wp_pin =
-			of_get_named_gpio(cnp, "wp-gpios", 0);
+		pdata->slot[slot_id].wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_IN);
+		if (!pdata->slot[slot_id].wp_gpio)
+			dev_dbg(dev, "no WP pin available\n");
+		gpiod_set_consumer_name(pdata->slot[slot_id].wp_gpio, "mmc_wp");
 	}
 
 	return pdata;
@@ -1535,8 +1540,8 @@ static int atmci_get_ro(struct mmc_host *mmc)
 	int			read_only = -ENOSYS;
 	struct atmel_mci_slot	*slot = mmc_priv(mmc);
 
-	if (gpio_is_valid(slot->wp_pin)) {
-		read_only = gpio_get_value(slot->wp_pin);
+	if (slot->wp_gpio) {
+		read_only = gpiod_get_value(slot->wp_gpio);
 		dev_dbg(&mmc->class_dev, "card is %s\n",
 				read_only ? "read-only" : "read-write");
 	}
@@ -1544,14 +1549,18 @@ static int atmci_get_ro(struct mmc_host *mmc)
 	return read_only;
 }
 
+static bool is_card_present(struct atmel_mci_slot *slot)
+{
+	return !(gpiod_get_raw_value(slot->detect_gpio) ^ slot->detect_is_active_high);
+}
+
 static int atmci_get_cd(struct mmc_host *mmc)
 {
 	int			present = -ENOSYS;
 	struct atmel_mci_slot	*slot = mmc_priv(mmc);
 
-	if (gpio_is_valid(slot->detect_pin)) {
-		present = !(gpio_get_value(slot->detect_pin) ^
-			    slot->detect_is_active_high);
+	if (slot->detect_gpio) {
+		present = is_card_present(slot);
 		dev_dbg(&mmc->class_dev, "card is %spresent\n",
 				present ? "" : "not ");
 	}
@@ -1663,9 +1672,8 @@ static void atmci_detect_change(struct timer_list *t)
 	if (test_bit(ATMCI_SHUTDOWN, &slot->flags))
 		return;
 
-	enable_irq(gpio_to_irq(slot->detect_pin));
-	present = !(gpio_get_value(slot->detect_pin) ^
-		    slot->detect_is_active_high);
+	enable_irq(gpiod_to_irq(slot->detect_gpio));
+	present = is_card_present(slot);
 	present_old = test_bit(ATMCI_CARD_PRESENT, &slot->flags);
 
 	dev_vdbg(&slot->mmc->class_dev, "detect change: %d (was %d)\n",
@@ -2254,18 +2262,18 @@ static int atmci_init_slot(struct atmel_mci *host,
 	slot = mmc_priv(mmc);
 	slot->mmc = mmc;
 	slot->host = host;
-	slot->detect_pin = slot_data->detect_pin;
-	slot->wp_pin = slot_data->wp_pin;
+	slot->wp_gpio = slot_data->wp_gpio;
+	slot->detect_gpio = slot_data->detect_gpio;
 	slot->detect_is_active_high = slot_data->detect_is_active_high;
 	slot->sdc_reg = sdc_reg;
 	slot->sdio_irq = sdio_irq;
 
 	dev_dbg(&mmc->class_dev,
-	        "slot[%u]: bus_width=%u, detect_pin=%d, "
-		"detect_is_active_high=%s, wp_pin=%d\n",
-		id, slot_data->bus_width, slot_data->detect_pin,
+	        "slot[%u]: bus_width=%u, detect_gpio=%d, "
+		"detect_is_active_high=%s, wp_gpio=%d\n",
+		id, slot_data->bus_width, desc_to_gpio(slot_data->detect_gpio),
 		slot_data->detect_is_active_high ? "true" : "false",
-		slot_data->wp_pin);
+		desc_to_gpio(slot_data->wp_gpio));
 
 	mmc->ops = &atmci_ops;
 	mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512);
@@ -2301,32 +2309,16 @@ static int atmci_init_slot(struct atmel_mci *host,
 
 	/* Assume card is present initially */
 	set_bit(ATMCI_CARD_PRESENT, &slot->flags);
-	if (gpio_is_valid(slot->detect_pin)) {
-		if (devm_gpio_request(&host->pdev->dev, 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) {
+	if (slot->detect_gpio) {
+		if (!is_card_present(slot))
 			clear_bit(ATMCI_CARD_PRESENT, &slot->flags);
-		}
-	}
-
-	if (!gpio_is_valid(slot->detect_pin)) {
+	} else {
 		if (slot_data->non_removable)
 			mmc->caps |= MMC_CAP_NONREMOVABLE;
 		else
 			mmc->caps |= MMC_CAP_NEEDS_POLL;
 	}
 
-	if (gpio_is_valid(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");
-			slot->wp_pin = -EBUSY;
-		}
-	}
-
 	host->slot[id] = slot;
 	mmc_regulator_get_supply(mmc);
 	ret = mmc_add_host(mmc);
@@ -2335,18 +2327,18 @@ static int atmci_init_slot(struct atmel_mci *host,
 		return ret;
 	}
 
-	if (gpio_is_valid(slot->detect_pin)) {
+	if (slot->detect_gpio) {
 		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_gpio),
 				atmci_detect_interrupt,
 				IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
 				"mmc-detect", slot);
 		if (ret) {
 			dev_dbg(&mmc->class_dev,
 				"could not request IRQ %d for detect pin\n",
-				gpio_to_irq(slot->detect_pin));
-			slot->detect_pin = -EBUSY;
+				gpiod_to_irq(slot->detect_gpio));
+			slot->detect_gpio = NULL;
 		}
 	}
 
@@ -2365,10 +2357,8 @@ static void atmci_cleanup_slot(struct atmel_mci_slot *slot,
 
 	mmc_remove_host(slot->mmc);
 
-	if (gpio_is_valid(slot->detect_pin)) {
-		int pin = slot->detect_pin;
-
-		free_irq(gpio_to_irq(pin), slot);
+	if (slot->detect_gpio) {
+		free_irq(gpiod_to_irq(slot->detect_gpio), slot);
 		del_timer_sync(&slot->detect_timer);
 	}
 
Signature · 1 line
2.39.1
#2 lore raw

Re: [PATCH v1 2/2] mmc: atmel-mci: Convert to agnostic GPIO API

+ Arnd, Balamanikandan

Quoted 5 lines · Andy Shevchenko

The of_gpio.h is going to be removed. In preparation of that convert the driver to the agnostic API.

This is the third attempt to get this done, within this release cycle. :-)

Arnd's:
https://lore.kernel.org/netdev/[email protected]/

Balamanikandan's:
https://lore.kernel.org/all/[email protected]/

Actually, Balamanikandan's version was acked already in December by Linus Walleij and Ludovic, but I failed to apply it so I was requesting a rebase.

That said, I think we should give BalaBalamanikandan some more time for a re-spin (unless someone is willing to help him out in this regard), as it's getting late for v6.3 anyway.

Kind regards
Uffe

Quoted 257 lines
---
 drivers/mmc/host/atmel-mci.c | 106 ++++++++++++++++-------------------
 1 file changed, 48 insertions(+), 58 deletions(-)
drivers/mmc/host/atmel-mci.c +48 -59
index fad5e6b4c654..79876e3152e6 100644
@@ -11,7 +11,7 @@
 #include <linux/dmaengine.h>
 #include <linux/dma-mapping.h>
 #include <linux/err.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
@@ -19,7 +19,6 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 #include <linux/scatterlist.h>
 #include <linux/seq_file.h>
@@ -44,8 +43,8 @@
 /**
  * struct mci_slot_pdata - board-specific per-slot configuration
  * @bus_width: Number of data lines wired up the slot
- * @detect_pin: GPIO pin wired to the card detect switch
- * @wp_pin: GPIO pin wired to the write protect sensor
+ * @wp_gpio: GPIO pin wired to the write protect sensor
+ * @detect_gpio: GPIO pin wired to the card detect switch
  * @detect_is_active_high: The state of the detect pin when it is active
  * @non_removable: The slot is not removable, only detect once
  *
@@ -60,8 +59,8 @@
  */
 struct mci_slot_pdata {
        unsigned int            bus_width;
-       int                     detect_pin;
-       int                     wp_pin;
+       struct gpio_desc        *wp_gpio;
+       struct gpio_desc        *detect_gpio;
        bool                    detect_is_active_high;
        bool                    non_removable;
 };
@@ -399,12 +398,12 @@ struct atmel_mci {
  *     &struct atmel_mci.
  * @clock: Clock rate configured by set_ios(). Protected by host->lock.
  * @flags: Random state bits associated with the slot.
- * @detect_pin: GPIO pin used for card detection, or negative if not
- *     available.
- * @wp_pin: GPIO pin used for card write protect sending, or negative
+ * @wp_gpio: GPIO pin used for card write protect sending, or NULL
  *     if not available.
+ * @detect_gpio: GPIO pin used for card detection, or negative if not
+ *     available.
  * @detect_is_active_high: The state of the detect pin when it is active.
- * @detect_timer: Timer used for debouncing @detect_pin interrupts.
+ * @detect_timer: Timer used for debouncing @detect_gpio interrupts.
  */
 struct atmel_mci_slot {
        struct mmc_host         *mmc;
@@ -422,8 +421,9 @@ struct atmel_mci_slot {
 #define ATMCI_CARD_NEED_INIT   1
 #define ATMCI_SHUTDOWN         2
 
-       int                     detect_pin;
-       int                     wp_pin;
+       struct gpio_desc        *wp_gpio;
+
+       struct gpio_desc        *detect_gpio;
        bool                    detect_is_active_high;
 
        struct timer_list       detect_timer;
@@ -637,7 +637,8 @@ MODULE_DEVICE_TABLE(of, atmci_dt_ids);
 static struct mci_platform_data*
 atmci_of_init(struct platform_device *pdev)
 {
-       struct device_node *np = pdev->dev.of_node;
+       struct device *dev = &pdev->dev;
+       struct device_node *np = dev->of_node;
        struct device_node *cnp;
        struct mci_platform_data *pdata;
        u32 slot_id;
@@ -669,8 +670,10 @@ atmci_of_init(struct platform_device *pdev)
                                         &pdata->slot[slot_id].bus_width))
                        pdata->slot[slot_id].bus_width = 1;
 
-               pdata->slot[slot_id].detect_pin =
-                       of_get_named_gpio(cnp, "cd-gpios", 0);
+               pdata->slot[slot_id].detect_gpio = devm_gpiod_get_optional(dev, "cd", GPIOD_IN);
+               if (!pdata->slot[slot_id].detect_gpio)
+                       dev_dbg(dev, "no detect pin available\n");
+               gpiod_set_consumer_name(pdata->slot[slot_id].detect_gpio, "mmc_detect");
 
                pdata->slot[slot_id].detect_is_active_high =
                        of_property_read_bool(cnp, "cd-inverted");
@@ -678,8 +681,10 @@ atmci_of_init(struct platform_device *pdev)
                pdata->slot[slot_id].non_removable =
                        of_property_read_bool(cnp, "non-removable");
 
-               pdata->slot[slot_id].wp_pin =
-                       of_get_named_gpio(cnp, "wp-gpios", 0);
+               pdata->slot[slot_id].wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_IN);
+               if (!pdata->slot[slot_id].wp_gpio)
+                       dev_dbg(dev, "no WP pin available\n");
+               gpiod_set_consumer_name(pdata->slot[slot_id].wp_gpio, "mmc_wp");
        }
 
        return pdata;
@@ -1535,8 +1540,8 @@ static int atmci_get_ro(struct mmc_host *mmc)
        int                     read_only = -ENOSYS;
        struct atmel_mci_slot   *slot = mmc_priv(mmc);
 
-       if (gpio_is_valid(slot->wp_pin)) {
-               read_only = gpio_get_value(slot->wp_pin);
+       if (slot->wp_gpio) {
+               read_only = gpiod_get_value(slot->wp_gpio);
                dev_dbg(&mmc->class_dev, "card is %s\n",
                                read_only ? "read-only" : "read-write");
        }
@@ -1544,14 +1549,18 @@ static int atmci_get_ro(struct mmc_host *mmc)
        return read_only;
 }
 
+static bool is_card_present(struct atmel_mci_slot *slot)
+{
+       return !(gpiod_get_raw_value(slot->detect_gpio) ^ slot->detect_is_active_high);
+}
+
 static int atmci_get_cd(struct mmc_host *mmc)
 {
        int                     present = -ENOSYS;
        struct atmel_mci_slot   *slot = mmc_priv(mmc);
 
-       if (gpio_is_valid(slot->detect_pin)) {
-               present = !(gpio_get_value(slot->detect_pin) ^
-                           slot->detect_is_active_high);
+       if (slot->detect_gpio) {
+               present = is_card_present(slot);
                dev_dbg(&mmc->class_dev, "card is %spresent\n",
                                present ? "" : "not ");
        }
@@ -1663,9 +1672,8 @@ static void atmci_detect_change(struct timer_list *t)
        if (test_bit(ATMCI_SHUTDOWN, &slot->flags))
                return;
 
-       enable_irq(gpio_to_irq(slot->detect_pin));
-       present = !(gpio_get_value(slot->detect_pin) ^
-                   slot->detect_is_active_high);
+       enable_irq(gpiod_to_irq(slot->detect_gpio));
+       present = is_card_present(slot);
        present_old = test_bit(ATMCI_CARD_PRESENT, &slot->flags);
 
        dev_vdbg(&slot->mmc->class_dev, "detect change: %d (was %d)\n",
@@ -2254,18 +2262,18 @@ static int atmci_init_slot(struct atmel_mci *host,
        slot = mmc_priv(mmc);
        slot->mmc = mmc;
        slot->host = host;
-       slot->detect_pin = slot_data->detect_pin;
-       slot->wp_pin = slot_data->wp_pin;
+       slot->wp_gpio = slot_data->wp_gpio;
+       slot->detect_gpio = slot_data->detect_gpio;
        slot->detect_is_active_high = slot_data->detect_is_active_high;
        slot->sdc_reg = sdc_reg;
        slot->sdio_irq = sdio_irq;
 
        dev_dbg(&mmc->class_dev,
-               "slot[%u]: bus_width=%u, detect_pin=%d, "
-               "detect_is_active_high=%s, wp_pin=%d\n",
-               id, slot_data->bus_width, slot_data->detect_pin,
+               "slot[%u]: bus_width=%u, detect_gpio=%d, "
+               "detect_is_active_high=%s, wp_gpio=%d\n",
+               id, slot_data->bus_width, desc_to_gpio(slot_data->detect_gpio),
                slot_data->detect_is_active_high ? "true" : "false",
-               slot_data->wp_pin);
+               desc_to_gpio(slot_data->wp_gpio));
 
        mmc->ops = &atmci_ops;
        mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512);
@@ -2301,32 +2309,16 @@ static int atmci_init_slot(struct atmel_mci *host,
 
        /* Assume card is present initially */
        set_bit(ATMCI_CARD_PRESENT, &slot->flags);
-       if (gpio_is_valid(slot->detect_pin)) {
-               if (devm_gpio_request(&host->pdev->dev, 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) {
+       if (slot->detect_gpio) {
+               if (!is_card_present(slot))
                        clear_bit(ATMCI_CARD_PRESENT, &slot->flags);
-               }
-       }
-
-       if (!gpio_is_valid(slot->detect_pin)) {
+       } else {
                if (slot_data->non_removable)
                        mmc->caps |= MMC_CAP_NONREMOVABLE;
                else
                        mmc->caps |= MMC_CAP_NEEDS_POLL;
        }
 
-       if (gpio_is_valid(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");
-                       slot->wp_pin = -EBUSY;
-               }
-       }
-
        host->slot[id] = slot;
        mmc_regulator_get_supply(mmc);
        ret = mmc_add_host(mmc);
@@ -2335,18 +2327,18 @@ static int atmci_init_slot(struct atmel_mci *host,
                return ret;
        }
 
-       if (gpio_is_valid(slot->detect_pin)) {
+       if (slot->detect_gpio) {
                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_gpio),
                                atmci_detect_interrupt,
                                IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
                                "mmc-detect", slot);
                if (ret) {
                        dev_dbg(&mmc->class_dev,
                                "could not request IRQ %d for detect pin\n",
-                               gpio_to_irq(slot->detect_pin));
-                       slot->detect_pin = -EBUSY;
+                               gpiod_to_irq(slot->detect_gpio));
+                       slot->detect_gpio = NULL;
                }
        }
 
@@ -2365,10 +2357,8 @@ static void atmci_cleanup_slot(struct atmel_mci_slot *slot,
 
        mmc_remove_host(slot->mmc);
 
-       if (gpio_is_valid(slot->detect_pin)) {
-               int pin = slot->detect_pin;
-
-               free_irq(gpio_to_irq(pin), slot);
+       if (slot->detect_gpio) {
+               free_irq(gpiod_to_irq(slot->detect_gpio), slot);
                del_timer_sync(&slot->detect_timer);
        }
 
--

2.39.1

#3 lore raw

Re: [PATCH v1 2/2] mmc: atmel-mci: Convert to agnostic GPIO API

Quoted 16 lines · Ulf Hansson
Quoted 5 lines · Andy Shevchenko

The of_gpio.h is going to be removed. In preparation of that convert the driver to the agnostic API.

This is the third attempt to get this done, within this release cycle. :-)

Arnd's:
https://lore.kernel.org/netdev/[email protected]/

Balamanikandan's:
https://lore.kernel.org/all/[email protected]/

Quoted 7 lines

Actually, Balamanikandan's version was acked already in December by Linus Walleij and Ludovic, but I failed to apply it so I was requesting a rebase.

That said, I think we should give BalaBalamanikandan some more time for a re-spin (unless someone is willing to help him out in this regard), as it's getting late for v6.3 anyway.

I see, thanks for heads up!

I believe there is still room for improvement in his series (I briefly looked at it). Let's wait for v4 which I would like to review.

Signature · 2 lines
With Best Regards,
Andy Shevchenko