From nobody Sun Sep 14 03:49:37 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 747E8C61DA2 for ; Thu, 26 Jan 2023 13:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230057AbjAZNvH (ORCPT ); Thu, 26 Jan 2023 08:51:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231639AbjAZNvC (ORCPT ); Thu, 26 Jan 2023 08:51:02 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB3EA4CE7F; Thu, 26 Jan 2023 05:50:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CCD51617FF; Thu, 26 Jan 2023 13:50:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEECBC433A0; Thu, 26 Jan 2023 13:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674741040; bh=waQRMFuqxVZvLTarVOLu2AMjbJkqhlrOHWytHi3gGkQ=; h=From:To:Cc:Subject:Date:From; b=lgLtdinpU/cdpYmJaguihJy2shzDnw1ETYSp6SSljokJpfSf2+1vzpeeLMzYfd1qV re1vWWKe/h1Evf1VtbwdREJ5VNH+p469I/ieMIoYsZosH/OaHjFUdPKA937Wg5hcfG dy3PJXtKiQB1WwSnC6AOxmdsZ4mcCsC9uS9piHTAD+i6oAuC1QSUZwKPjeiSQuoX9J oGv6AbjpP1QLqP27V+Ht7Xs1ub9pLa3SV9OsEWFigaWuHl/zeOdzmsGzhDuFEDGVKW rLggeNHipavLW0fec6i6YmhJYOaP39SbViMImyJnNMXJxPaBDCfCWJi+5CFo+jlg+9 sauZ3x65FrsCw== From: Arnd Bergmann To: Ludovic Desroches , Ulf Hansson Cc: linux-gpio@vger.kernel.org, Arnd Bergmann , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Subject: [PATCH] mmc: atmel: convert to gpio descriptos Date: Thu, 26 Jan 2023 14:50:04 +0100 Message-Id: <20230126135034.3320638-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Arnd Bergmann All Atmel (now Microchip) machines boot using DT, so the old platform_data for this driver is no longer used by any boards. Removing the pdata probe lets us simplify the GPIO handling with the use of the descriptor API. Signed-off-by: Arnd Bergmann --- drivers/mmc/host/atmel-mci.c | 179 +++++++++++++++-------------------- include/linux/atmel-mci.h | 46 --------- 2 files changed, 77 insertions(+), 148 deletions(-) delete mode 100644 include/linux/atmel-mci.h diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c index bb9bbf1c927b..40006a960277 100644 --- a/drivers/mmc/host/atmel-mci.c +++ b/drivers/mmc/host/atmel-mci.c @@ -30,7 +30,6 @@ #include #include =20 -#include #include #include #include @@ -40,6 +39,30 @@ #include #include =20 +#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 + * @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; + bool detect_is_active_high; + bool non_removable; +}; + /* * Superset of MCI IP registers integrated in Atmel AT91 Processor * Registers and bitfields marked with [2] are only available in MCI2 @@ -388,8 +411,8 @@ struct atmel_mci_slot { #define ATMCI_CARD_NEED_INIT 1 #define ATMCI_SHUTDOWN 2 =20 - int detect_pin; - int wp_pin; + struct gpio_desc *detect_pin; + struct gpio_desc *wp_pin; bool detect_is_active_high; =20 struct timer_list detect_timer; @@ -593,7 +616,6 @@ static void atmci_init_debugfs(struct atmel_mci_slot *s= lot) &host->completed_events); } =20 -#if defined(CONFIG_OF) static const struct of_device_id atmci_dt_ids[] =3D { { .compatible =3D "atmel,hsmci" }, { /* sentinel */ } @@ -601,23 +623,13 @@ static const struct of_device_id atmci_dt_ids[] =3D { =20 MODULE_DEVICE_TABLE(of, atmci_dt_ids); =20 -static struct mci_platform_data* -atmci_of_init(struct platform_device *pdev) +static int +atmci_of_init(struct platform_device *pdev, struct mci_slot_pdata *pdata) { struct device_node *np =3D pdev->dev.of_node; struct device_node *cnp; - struct mci_platform_data *pdata; u32 slot_id; =20 - if (!np) { - dev_err(&pdev->dev, "device node not found\n"); - return ERR_PTR(-EINVAL); - } - - pdata =3D devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); - if (!pdata) - return ERR_PTR(-ENOMEM); - for_each_child_of_node(np, cnp) { if (of_property_read_u32(cnp, "reg", &slot_id)) { dev_warn(&pdev->dev, "reg property is missing for %pOF\n", @@ -633,31 +645,18 @@ atmci_of_init(struct platform_device *pdev) } =20 if (of_property_read_u32(cnp, "bus-width", - &pdata->slot[slot_id].bus_width)) - pdata->slot[slot_id].bus_width =3D 1; - - pdata->slot[slot_id].detect_pin =3D - of_get_named_gpio(cnp, "cd-gpios", 0); + &pdata[slot_id].bus_width)) + pdata[slot_id].bus_width =3D 1; =20 - pdata->slot[slot_id].detect_is_active_high =3D + pdata[slot_id].detect_is_active_high =3D of_property_read_bool(cnp, "cd-inverted"); =20 - pdata->slot[slot_id].non_removable =3D + pdata[slot_id].non_removable =3D of_property_read_bool(cnp, "non-removable"); - - pdata->slot[slot_id].wp_pin =3D - of_get_named_gpio(cnp, "wp-gpios", 0); } =20 - return pdata; -} -#else /* CONFIG_OF */ -static inline struct mci_platform_data* -atmci_of_init(struct platform_device *dev) -{ - return ERR_PTR(-EINVAL); + return 0; } -#endif =20 static inline unsigned int atmci_get_version(struct atmel_mci *host) { @@ -1509,8 +1508,8 @@ static int atmci_get_ro(struct mmc_host *mmc) int read_only =3D -ENOSYS; struct atmel_mci_slot *slot =3D mmc_priv(mmc); =20 - if (gpio_is_valid(slot->wp_pin)) { - read_only =3D gpio_get_value(slot->wp_pin); + if (slot->wp_pin) { + read_only =3D gpiod_get_value(slot->wp_pin); dev_dbg(&mmc->class_dev, "card is %s\n", read_only ? "read-only" : "read-write"); } @@ -1523,8 +1522,8 @@ static int atmci_get_cd(struct mmc_host *mmc) int present =3D -ENOSYS; struct atmel_mci_slot *slot =3D mmc_priv(mmc); =20 - if (gpio_is_valid(slot->detect_pin)) { - present =3D !(gpio_get_value(slot->detect_pin) ^ + if (slot->detect_pin) { + present =3D !(gpiod_get_value(slot->detect_pin) ^ slot->detect_is_active_high); dev_dbg(&mmc->class_dev, "card is %spresent\n", present ? "" : "not "); @@ -1637,8 +1636,8 @@ static void atmci_detect_change(struct timer_list *t) if (test_bit(ATMCI_SHUTDOWN, &slot->flags)) return; =20 - enable_irq(gpio_to_irq(slot->detect_pin)); - present =3D !(gpio_get_value(slot->detect_pin) ^ + enable_irq(gpiod_to_irq(slot->detect_pin)); + present =3D !(gpiod_get_value(slot->detect_pin) ^ slot->detect_is_active_high); present_old =3D test_bit(ATMCI_CARD_PRESENT, &slot->flags); =20 @@ -2231,18 +2230,15 @@ static int atmci_init_slot(struct atmel_mci *host, slot =3D mmc_priv(mmc); slot->mmc =3D mmc; slot->host =3D host; - slot->detect_pin =3D slot_data->detect_pin; - slot->wp_pin =3D slot_data->wp_pin; slot->detect_is_active_high =3D slot_data->detect_is_active_high; slot->sdc_reg =3D sdc_reg; slot->sdio_irq =3D sdio_irq; =20 dev_dbg(&mmc->class_dev, - "slot[%u]: bus_width=3D%u, detect_pin=3D%d, " - "detect_is_active_high=3D%s, wp_pin=3D%d\n", - id, slot_data->bus_width, slot_data->detect_pin, - slot_data->detect_is_active_high ? "true" : "false", - slot_data->wp_pin); + "slot[%u]: bus_width=3D%u, " + "detect_is_active_high=3D%s\n", + id, slot_data->bus_width, + slot_data->detect_is_active_high ? "true" : "false"); =20 mmc->ops =3D &atmci_ops; mmc->f_min =3D DIV_ROUND_UP(host->bus_hz, 512); @@ -2278,30 +2274,29 @@ static int atmci_init_slot(struct atmel_mci *host, =20 /* 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 =3D -EBUSY; - } else if (gpio_get_value(slot->detect_pin) ^ - slot->detect_is_active_high) { + + slot->detect_pin =3D devm_gpiod_get_optional(&host->pdev->dev, "cd", GPIO= D_IN); + if (!IS_ERR(slot->detect_pin)) { + dev_dbg(&mmc->class_dev, "no detect pin available\n"); + slot->detect_pin =3D NULL; + } else if (slot->detect_pin) { + if (gpiod_get_value(slot->detect_pin) ^ + slot->detect_is_active_high) { clear_bit(ATMCI_CARD_PRESENT, &slot->flags); } } =20 - if (!gpio_is_valid(slot->detect_pin)) { + if (!slot->detect_pin) { if (slot_data->non_removable) mmc->caps |=3D MMC_CAP_NONREMOVABLE; else mmc->caps |=3D MMC_CAP_NEEDS_POLL; } =20 - 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 =3D -EBUSY; - } + slot->wp_pin =3D devm_gpiod_get_optional(&host->pdev->dev, "wp", GPIOD_IN= ); + if (IS_ERR(slot->wp_pin)) { + dev_dbg(&mmc->class_dev, "no WP pin available\n"); + slot->wp_pin =3D NULL; } =20 host->slot[id] =3D slot; @@ -2312,18 +2307,18 @@ static int atmci_init_slot(struct atmel_mci *host, return ret; } =20 - if (gpio_is_valid(slot->detect_pin)) { + if (slot->detect_pin) { timer_setup(&slot->detect_timer, atmci_detect_change, 0); =20 - ret =3D request_irq(gpio_to_irq(slot->detect_pin), + ret =3D request_irq(gpiod_to_irq(slot->detect_pin), 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 =3D -EBUSY; + gpiod_to_irq(slot->detect_pin)); + slot->detect_pin =3D NULL; } } =20 @@ -2342,10 +2337,8 @@ static void atmci_cleanup_slot(struct atmel_mci_slot= *slot, =20 mmc_remove_host(slot->mmc); =20 - if (gpio_is_valid(slot->detect_pin)) { - int pin =3D slot->detect_pin; - - free_irq(gpio_to_irq(pin), slot); + if (slot->detect_pin) { + free_irq(gpiod_to_irq(slot->detect_pin), slot); del_timer_sync(&slot->detect_timer); } =20 @@ -2357,22 +2350,6 @@ static int atmci_configure_dma(struct atmel_mci *hos= t) { host->dma.chan =3D dma_request_chan(&host->pdev->dev, "rxtx"); =20 - if (PTR_ERR(host->dma.chan) =3D=3D -ENODEV) { - struct mci_platform_data *pdata =3D 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 =3D dma_request_channel(mask, pdata->dma_filter, - pdata->dma_slave); - if (!host->dma.chan) - host->dma.chan =3D ERR_PTR(-ENODEV); - } - if (IS_ERR(host->dma.chan)) return PTR_ERR(host->dma.chan); =20 @@ -2450,7 +2427,7 @@ static void atmci_get_cap(struct atmel_mci *host) =20 static int atmci_probe(struct platform_device *pdev) { - struct mci_platform_data *pdata; + struct mci_slot_pdata pdata[ATMCI_MAX_NR_SLOTS]; struct atmel_mci *host; struct resource *regs; unsigned int nr_slots; @@ -2460,23 +2437,21 @@ static int atmci_probe(struct platform_device *pdev) regs =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!regs) return -ENXIO; - pdata =3D pdev->dev.platform_data; - if (!pdata) { - pdata =3D atmci_of_init(pdev); - if (IS_ERR(pdata)) { - dev_err(&pdev->dev, "platform data not available\n"); - return PTR_ERR(pdata); - } + + host =3D devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); + if (!host) + return -ENOMEM; + + ret =3D atmci_of_init(pdev, pdata); + if (ret) { + dev_err(&pdev->dev, "error parsing DT\n"); + return ret; } =20 irq =3D platform_get_irq(pdev, 0); if (irq < 0) return irq; =20 - host =3D devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); - if (!host) - return -ENOMEM; - host->pdev =3D pdev; spin_lock_init(&host->lock); INIT_LIST_HEAD(&host->queue); @@ -2540,16 +2515,16 @@ static int atmci_probe(struct platform_device *pdev) /* We need at least one slot to succeed */ nr_slots =3D 0; ret =3D -ENODEV; - if (pdata->slot[0].bus_width) { - ret =3D atmci_init_slot(host, &pdata->slot[0], + if (pdata[0].bus_width) { + ret =3D atmci_init_slot(host, &pdata[0], 0, ATMCI_SDCSEL_SLOT_A, ATMCI_SDIOIRQA); if (!ret) { nr_slots++; host->buf_size =3D host->slot[0]->mmc->max_req_size; } } - if (pdata->slot[1].bus_width) { - ret =3D atmci_init_slot(host, &pdata->slot[1], + if (pdata[1].bus_width) { + ret =3D atmci_init_slot(host, &pdata[1], 1, ATMCI_SDCSEL_SLOT_B, ATMCI_SDIOIRQB); if (!ret) { nr_slots++; @@ -2671,7 +2646,7 @@ static struct platform_driver atmci_driver =3D { .driver =3D { .name =3D "atmel_mci", .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, - .of_match_table =3D of_match_ptr(atmci_dt_ids), + .of_match_table =3D atmci_dt_ids, .pm =3D &atmci_dev_pm_ops, }, }; diff --git a/include/linux/atmel-mci.h b/include/linux/atmel-mci.h deleted file mode 100644 index 1491af38cc6e..000000000000 --- a/include/linux/atmel-mci.h +++ /dev/null @@ -1,46 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __LINUX_ATMEL_MCI_H -#define __LINUX_ATMEL_MCI_H - -#include -#include - -#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 - * @dma_slave: DMA slave interface to use in data transfers. - * @slot: Per-slot configuration data. - */ -struct mci_platform_data { - void *dma_slave; - dma_filter_fn dma_filter; - struct mci_slot_pdata slot[ATMCI_MAX_NR_SLOTS]; -}; - -#endif /* __LINUX_ATMEL_MCI_H */ --=20 2.39.0