From patchwork Wed Nov 9 04:38:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balamanikandan Gunasundar X-Patchwork-Id: 17343 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp143803wru; Tue, 8 Nov 2022 20:58:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Mt8F3m+SUAGWTeNo8Lcq7qjG2Xk2S6TjhXmn07f9IysfSksDiMTBaDYbEwPXINNNIzg9a X-Received: by 2002:a17:902:8a97:b0:188:8cad:f8ca with SMTP id p23-20020a1709028a9700b001888cadf8camr5128622plo.84.1667969931575; Tue, 08 Nov 2022 20:58:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667969931; cv=none; d=google.com; s=arc-20160816; b=SAOm6LMMBNmQt99s9lJONlbWSuayTBi6oCziZIcJrZDdT1bv0pXgS130aE9Rmu6Y9j sfxEY3gzErw+/ODwvTVyEW+tF6kAeZTZbu5XShWajEq8fCPsimgMSOUeeqhNXeI3+Qlt 5yhyXKhSnc+ORKeAjH8iEfSuQ2NOisaLjgurr3bskcMstZ6qBZar/o9bLKt6OskMfro1 EdpWRywoHP1PNhgEpfnTOXwwvPl+3hc9zD7AZlav2DJMtFAZyZJEtsgArdmU/1NG7c59 NFO0TW6ZFuPr5DS2aU/YVq+qw24BaYxiw1vpI7G75CFuukYrR1iMJkC9DoPL5Ko4Yxlg ovEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=UKK9sOqc3qyWvvgK9y8MJhBJqBLWlhhWcqQ8li+U7ms=; b=iuzfes0MHiFoGJXwm4V0+/r3MdmGTwvOHNaxES97eLiGXYxhvWvG+oHaNj79SCh9mQ JW2NyWBWXh+FH4++1upTExKqf329+ynTfmkIZ3xsUJ3xVRQGEIUOzIsrMWW0il17BZL/ T8xmBPIaga1OJ8NbYVJ+4mubo5U8FNqZllc6Hz7sEExQ+STolbPgcq5RzyXXfGAgCH6C 0xn9/dBROH3+ypqqfNAMeVNqZcggqOuH8RP53k5dSNiWLeBZVBCDbi5tzsoy/3hUEIu3 aGeVHTB8IdH2QQTn1AaFq4wt4elALT90mcwnfNFTi0USv1q4AYW6epbXmzx7BECnn6wV kI5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=JkQQux3H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g12-20020a1709026b4c00b0018862b8c9a2si15538028plt.12.2022.11.08.20.58.30; Tue, 08 Nov 2022 20:58:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=JkQQux3H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbiKIEjN (ORCPT + 99 others); Tue, 8 Nov 2022 23:39:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiKIEjL (ORCPT ); Tue, 8 Nov 2022 23:39:11 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 420371F63E; Tue, 8 Nov 2022 20:39:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1667968749; x=1699504749; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ekN32mgld3p7ua9y3RzHpl+0iatY7zZXfAVZJNEDssk=; b=JkQQux3HoL6/RqtcQ70QAMf3kqiIwd6piYtLPLLVkIFjseeaxzfYw0Q5 /ZD1ghzaQZi8aFq0pSolhrlez0uNwz821c3C5UhOR9t2JxflKymdyVDo+ 1/Yxv+HmZOnewNvkAxZOhRE51/VNUWThdLalnov4wpLDFDhiJonyuQuKv 1/eba6u9fsZCRFyyig4ZwaPJd6fJXzqGKla+TvBe7lQjLGn9i9J3lqTb3 izDhe0AA0W+DyUUrBzEKTFF3WtjAFSYwAM+2IWDkIwN6qk+siP3csEBcb W2/2cybuNObqCQc0pu/WEAFL6gKiCNdzquQ8a/7KTzddpU2tTCYK7HrOw A==; X-IronPort-AV: E=Sophos;i="5.96,149,1665471600"; d="scan'208";a="199007811" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 08 Nov 2022 21:39:09 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Tue, 8 Nov 2022 21:39:08 -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.12 via Frontend Transport; Tue, 8 Nov 2022 21:39:04 -0700 From: Balamanikandan Gunasundar To: , , , , <3chas3@gmail.com>, , , , , CC: Subject: [PATCH] mmc: atmel-mci: Convert to gpio descriptors Date: Wed, 9 Nov 2022 10:08:45 +0530 Message-ID: <20221109043845.16617-1-balamanikandan.gunasundar@microchip.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748993239003203341?= X-GMAIL-MSGID: =?utf-8?q?1748993239003203341?= 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 | 79 ++++++++++++++++++------------------ include/linux/atmel-mci.h | 4 +- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c index 67b2cd166e56..1df90966e104 100644 --- a/drivers/mmc/host/atmel-mci.c +++ b/drivers/mmc/host/atmel-mci.c @@ -19,7 +19,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -389,8 +390,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; @@ -638,7 +639,11 @@ 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_gpiod_get_from_of_node(&pdev->dev, cnp, + "cd-gpios", + 0, 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"); @@ -647,7 +652,11 @@ 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_gpiod_get_from_of_node(&pdev->dev, cnp, + "wp-gpios", + 0, GPIOD_IN, "wp-gpios"); + if (IS_ERR(pdata->slot[slot_id].wp_pin)) + pdata->slot[slot_id].wp_pin = NULL; } return pdata; @@ -1511,8 +1520,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"); } @@ -1525,8 +1534,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 "); @@ -1639,8 +1648,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); @@ -2241,9 +2250,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); @@ -2279,51 +2288,43 @@ 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); - mmc_pwrseq_alloc(slot->mmc); mmc_add_host(mmc); - if (gpio_is_valid(slot->detect_pin)) { + if (slot->detect_pin) { int ret; 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; } } @@ -2342,10 +2343,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; };