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 DD9CAC6379F for ; Tue, 21 Feb 2023 09:42:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233999AbjBUJmz (ORCPT ); Tue, 21 Feb 2023 04:42:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233984AbjBUJmw (ORCPT ); Tue, 21 Feb 2023 04:42:52 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 191783C2A; Tue, 21 Feb 2023 01:42:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1676972570; x=1708508570; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cwT8q1A86no5rdEsZdVhE2849MtfhAeHuu+QdmDlJaA=; b=SuOeTeuxt5PGyf4TJCALUZqZoddRC1SSh+3BrvKkAEHUHCH3A+i5yiMz eg0mEfBiH0UHpVK0PSR6BvNNZdI7731zNElfeIA4nNNT5xo/vP4JfNaxD iVT6arJxp6Pnpkmbrt8rBN63V2x1MVd91mWGpElLPvdMBY2MCJs09yX/2 xYHZMG3ruflFCEiPBHQxQ18dqoKveW7x+Pi823j9SA+PVYI249eVsPREs cHSTDheqEV9JxEHwR6iTqmFW0aULwVugLoVtiXUz70ntMdhtaJaxGFrFI WBS3eQU0cG6e726b5SP182Fsf0O7diRFcUjmNz++wqkrqiVeUwDU4bQGa Q==; X-IronPort-AV: E=Sophos;i="5.97,315,1669100400"; d="scan'208";a="138246810" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Feb 2023 02:42:49 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Tue, 21 Feb 2023 02:42:48 -0700 Received: from che-lt-i64410lx.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Tue, 21 Feb 2023 02:42:44 -0700 From: Balamanikandan Gunasundar To: , , , , , , , , CC: , Subject: [PATCH v4 1/2] mmc: atmel-mci: Convert to gpio descriptors Date: Tue, 21 Feb 2023 15:12:06 +0530 Message-ID: <20230221094207.102006-2-balamanikandan.gunasundar@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230221094207.102006-1-balamanikandan.gunasundar@microchip.com> References: <20230221094207.102006-1-balamanikandan.gunasundar@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/mmc/host/atmel-mci.c | 77 +++++++++++++++++------------------- include/linux/atmel-mci.h | 4 +- 2 files changed, 39 insertions(+), 42 deletions(-) diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c index dd18440a90c5..ddad5a929634 100644 --- a/drivers/mmc/host/atmel-mci.c +++ b/drivers/mmc/host/atmel-mci.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -19,7 +18,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -388,8 +388,8 @@ struct atmel_mci_slot { #define ATMCI_CARD_NEED_INIT 1 #define ATMCI_SHUTDOWN 2 - int detect_pin; - int wp_pin; + struct gpio_desc *detect_pin; + struct gpio_desc *wp_pin; bool detect_is_active_high; struct timer_list detect_timer; @@ -637,7 +637,10 @@ atmci_of_init(struct platform_device *pdev) pdata->slot[slot_id].bus_width = 1; 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 = of_property_read_bool(cnp, "cd-inverted"); @@ -646,7 +649,10 @@ atmci_of_init(struct platform_device *pdev) of_property_read_bool(cnp, "non-removable"); 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; @@ -1509,8 +1515,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_pin) { + read_only = gpiod_get_value(slot->wp_pin); dev_dbg(&mmc->class_dev, "card is %s\n", read_only ? "read-only" : "read-write"); } @@ -1523,8 +1529,8 @@ 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) ^ + if (slot->detect_pin) { + present = !(gpiod_get_raw_value(slot->detect_pin) ^ slot->detect_is_active_high); dev_dbg(&mmc->class_dev, "card is %spresent\n", present ? "" : "not "); @@ -1637,8 +1643,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) ^ + enable_irq(gpiod_to_irq(slot->detect_pin)); + present = !(gpiod_get_raw_value(slot->detect_pin) ^ slot->detect_is_active_high); present_old = test_bit(ATMCI_CARD_PRESENT, &slot->flags); @@ -2237,9 +2243,9 @@ static int atmci_init_slot(struct atmel_mci *host, 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, + id, slot_data->bus_width, desc_to_gpio(slot_data->detect_pin), slot_data->detect_is_active_high ? "true" : "false", - slot_data->wp_pin); + desc_to_gpio(slot_data->wp_pin)); mmc->ops = &atmci_ops; mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512); @@ -2275,31 +2281,24 @@ 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_pin) { + if (gpiod_get_raw_value(slot->detect_pin) ^ + slot->detect_is_active_high) { 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) 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; - } - } + if (!slot->wp_pin) + dev_dbg(&mmc->class_dev, "no WP pin available\n"); host->slot[id] = slot; mmc_regulator_get_supply(mmc); @@ -2309,18 +2308,18 @@ static int atmci_init_slot(struct atmel_mci *host, return ret; } - if (gpio_is_valid(slot->detect_pin)) { + if (slot->detect_pin) { timer_setup(&slot->detect_timer, atmci_detect_change, 0); - ret = request_irq(gpio_to_irq(slot->detect_pin), - atmci_detect_interrupt, - IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, - "mmc-detect", slot); + ret = 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 = -EBUSY; + gpiod_to_irq(slot->detect_pin)); + slot->detect_pin = NULL; } } @@ -2339,10 +2338,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_pin) { + free_irq(gpiod_to_irq(slot->detect_pin), slot); del_timer_sync(&slot->detect_timer); } diff --git a/include/linux/atmel-mci.h b/include/linux/atmel-mci.h index 1491af38cc6e..017e7d8f6126 100644 --- a/include/linux/atmel-mci.h +++ b/include/linux/atmel-mci.h @@ -26,8 +26,8 @@ */ struct mci_slot_pdata { unsigned int bus_width; - int detect_pin; - int wp_pin; + struct gpio_desc *detect_pin; + struct gpio_desc *wp_pin; bool detect_is_active_high; bool non_removable; }; -- 2.25.1