From patchwork Thu Jan 26 16:17:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 48784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp361633wrn; Thu, 26 Jan 2023 08:26:29 -0800 (PST) X-Google-Smtp-Source: AK7set8VXoioIW9NURO6wJMdImNPLcGy1601s2EEpRkjSs8uoXEm1JURISTHPrBDfpdqRmWWTOmg X-Received: by 2002:a17:902:d195:b0:194:d609:e1ca with SMTP id m21-20020a170902d19500b00194d609e1camr1696970plb.54.1674750389686; Thu, 26 Jan 2023 08:26:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674750389; cv=none; d=google.com; s=arc-20160816; b=HpfQ2/10enKHBfu5xLn+SSzh0jNtY4jyy6G4+PpXuHhzM2wtA5wxtEahPxSKhn6MgI y2ISoLOb0edUezZnYG7aiRbHQUTspSThf8CbUTw9TpL7NElBROoW5nlBANwGHmRR//ue 00H/sFn0i6ltYfL9OoE2AhJT5ImpAftlugDgFnJpaSSwD2G4iHViXbx2WQnzAPlaLtvA 0W+QK5aTAayyNEBt3AHpDmICfGRpfnjUHg5UhtfFFjaQhRtmdnE/Eh6RjSGl3iYvC8Or 5YKnJ3hW6zUXhtTxFveMCrRV2uEVWGJ/soaCVAs/bH3o1FUq4Fsud1FABT89YSorLhyD eLsA== 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=VvpGKHfBq/+7FqBIwjmG99YlZL1o9MO9i4f3kPeLR7w=; b=e5B2flGm2kj1me4EIiAQzixkiLaCSuLAdXNriQ9DmmQc1Ferz8sQlOmEDPTwfz9b23 ZYHwxCCEnKzGNdKzb59XfT5AFk1dgqWi4Zat2lrazTbArdpgKzhjD1kr30LuR5fyiVNV NKLWjFRZGq4+kRZRUD5nJf50/oisc3Y01xmzIGgn9kwH46NlV6oTg0TnkTfF6cPXtbO1 xclZgqgyUxBpk3Tg9HLLIXggbW8WXnia94Df8lSnfjX2/C8M4+uSjsg3oJH5fO8IG2+5 uFd6RoL5RdjJYZ0FVnfGrr7+o7Kon50kPcR3f+sthla6FeOAo8K+7N/wkevW6fUjLBiU 01oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cTckPmHc; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p14-20020a170902b08e00b001930a5bccfcsi1725998plr.610.2023.01.26.08.26.17; Thu, 26 Jan 2023 08:26:29 -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=@kernel.org header.s=k20201202 header.b=cTckPmHc; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232465AbjAZQR7 (ORCPT + 99 others); Thu, 26 Jan 2023 11:17:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232154AbjAZQRy (ORCPT ); Thu, 26 Jan 2023 11:17:54 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4BB82D163; Thu, 26 Jan 2023 08:17:45 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8925DB81E95; Thu, 26 Jan 2023 16:17:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AC1FC4339B; Thu, 26 Jan 2023 16:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674749863; bh=qoJdV7Hy0K/c3KYKzdd66F4ZCzYzGAgyJAzosdZYTXY=; h=From:To:Cc:Subject:Date:From; b=cTckPmHczcg+AmhpY0WopBVBiM4auGprubeGb+ETYLShjMPmJ5mpuaJ5Fb9c3chV7 4oAxWJ37kNRL0IUroFpa8oppcSeG4A1V/D4789jqdycoA0h1mZwo6sQluhxF23HL9Q 3U0qeWhGPgwjuBxF95V8hBvtfFkf2Kjx05CAFKDYm54iaXuf5l8o1w60oYVYKcbGFD OfqMZY2DuXEYF8x403lWa5nu9rB5e1Ddnk62W2bGW28QMoLwc+I9Y8tDoYSOzJT7zO zqXtMaglx4z6G99tVWYzg5RdC1YaJcxunFnbvfxRr/VGjienZC9y9u/6FTLeKoLfbS WLmQofbj2Pb1Q== From: Arnd Bergmann To: Alexander Aring , Stefan Schmidt Cc: linux-gpio@vger.kernel.org, Arnd Bergmann , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Hauke Mehrtens , linux-wpan@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ca8210: move to gpio descriptors Date: Thu, 26 Jan 2023 17:17:15 +0100 Message-Id: <20230126161737.2985704-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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?1756103064337169333?= X-GMAIL-MSGID: =?utf-8?q?1756103064337169333?= From: Arnd Bergmann The driver requires DT based probing already, and can be simplified by using the modern gpio interfaces. Signed-off-by: Arnd Bergmann --- drivers/net/ieee802154/ca8210.c | 93 +++++++++------------------------ 1 file changed, 24 insertions(+), 69 deletions(-) diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c index 5c0be6a3ec5e..2ee2746688ea 100644 --- a/drivers/net/ieee802154/ca8210.c +++ b/drivers/net/ieee802154/ca8210.c @@ -52,13 +52,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -312,6 +310,9 @@ struct ca8210_test { * @promiscuous: whether the ca8210 is in promiscuous mode or not * @retries: records how many times the current pending spi * transfer has been retried + * @gpio_reset: gpio of ca8210 reset line + * @gpio_irq: gpio number of ca8210 interrupt line + * @irq_id: identifier for the ca8210 irq */ struct ca8210_priv { struct spi_device *spi; @@ -332,6 +333,9 @@ struct ca8210_priv { struct completion spi_transfer_complete, sync_exchange_complete; bool promiscuous; int retries; + struct gpio_desc *gpio_reset; + struct gpio_desc *gpio_irq; + int irq_id; }; /** @@ -351,18 +355,12 @@ struct work_priv_container { * @extclockenable: true if the external clock is to be enabled * @extclockfreq: frequency of the external clock * @extclockgpio: ca8210 output gpio of the external clock - * @gpio_reset: gpio number of ca8210 reset line - * @gpio_irq: gpio number of ca8210 interrupt line - * @irq_id: identifier for the ca8210 irq * */ struct ca8210_platform_data { bool extclockenable; unsigned int extclockfreq; unsigned int extclockgpio; - int gpio_reset; - int gpio_irq; - int irq_id; }; /** @@ -628,14 +626,13 @@ static int ca8210_spi_transfer( */ static void ca8210_reset_send(struct spi_device *spi, unsigned int ms) { - struct ca8210_platform_data *pdata = spi->dev.platform_data; struct ca8210_priv *priv = spi_get_drvdata(spi); long status; - gpio_set_value(pdata->gpio_reset, 0); + gpiod_set_value(priv->gpio_reset, 0); reinit_completion(&priv->ca8210_is_awake); msleep(ms); - gpio_set_value(pdata->gpio_reset, 1); + gpiod_set_value(priv->gpio_reset, 1); priv->promiscuous = false; /* Wait until wakeup indication seen */ @@ -2788,74 +2785,34 @@ static void ca8210_unregister_ext_clock(struct spi_device *spi) dev_info(&spi->dev, "External clock unregistered\n"); } -/** - * ca8210_reset_init() - Initialise the reset input to the ca8210 - * @spi: Pointer to target ca8210 spi device - * - * Return: 0 or linux error code - */ -static int ca8210_reset_init(struct spi_device *spi) -{ - int ret; - struct ca8210_platform_data *pdata = spi->dev.platform_data; - - pdata->gpio_reset = of_get_named_gpio( - spi->dev.of_node, - "reset-gpio", - 0 - ); - - ret = gpio_direction_output(pdata->gpio_reset, 1); - if (ret < 0) { - dev_crit( - &spi->dev, - "Reset GPIO %d did not set to output mode\n", - pdata->gpio_reset - ); - } - - return ret; -} - /** * ca8210_interrupt_init() - Initialise the irq output from the ca8210 * @spi: Pointer to target ca8210 spi device * * Return: 0 or linux error code */ -static int ca8210_interrupt_init(struct spi_device *spi) +static int ca8210_interrupt_init(struct spi_device *spi, struct ca8210_priv *priv) { int ret; - struct ca8210_platform_data *pdata = spi->dev.platform_data; - pdata->gpio_irq = of_get_named_gpio( - spi->dev.of_node, - "irq-gpio", - 0 - ); - - pdata->irq_id = gpio_to_irq(pdata->gpio_irq); - if (pdata->irq_id < 0) { - dev_crit( - &spi->dev, - "Could not get irq for gpio pin %d\n", - pdata->gpio_irq - ); - gpio_free(pdata->gpio_irq); - return pdata->irq_id; + priv->gpio_irq = gpiod_get(&spi->dev, "irq", GPIOD_IN); + priv->irq_id = gpiod_to_irq(priv->gpio_irq); + if (priv->irq_id < 0) { + dev_crit(&spi->dev, "Could not get irq for gpio pin\n"); + gpiod_put(priv->gpio_irq); + return priv->irq_id; } ret = request_irq( - pdata->irq_id, + priv->irq_id, ca8210_interrupt_handler, IRQF_TRIGGER_FALLING, "ca8210-irq", spi_get_drvdata(spi) ); if (ret) { - dev_crit(&spi->dev, "request_irq %d failed\n", pdata->irq_id); - gpiod_unexport(gpio_to_desc(pdata->gpio_irq)); - gpio_free(pdata->gpio_irq); + dev_crit(&spi->dev, "request_irq %d failed\n", priv->irq_id); + gpiod_put(priv->gpio_irq); } return ret; @@ -3009,7 +2966,7 @@ static void ca8210_test_interface_clear(struct ca8210_priv *priv) */ static void ca8210_remove(struct spi_device *spi_device) { - struct ca8210_priv *priv; + struct ca8210_priv *priv = spi_get_drvdata(spi_device); struct ca8210_platform_data *pdata; dev_info(&spi_device->dev, "Removing ca8210\n"); @@ -3020,12 +2977,10 @@ static void ca8210_remove(struct spi_device *spi_device) ca8210_unregister_ext_clock(spi_device); ca8210_config_extern_clk(pdata, spi_device, 0); } - free_irq(pdata->irq_id, spi_device->dev.driver_data); + free_irq(priv->irq_id, spi_device->dev.driver_data); kfree(pdata); spi_device->dev.platform_data = NULL; } - /* get spi_device private data */ - priv = spi_get_drvdata(spi_device); if (priv) { dev_info( &spi_device->dev, @@ -3114,13 +3069,13 @@ static int ca8210_probe(struct spi_device *spi_device) dev_crit(&spi_device->dev, "ca8210_dev_com_init failed\n"); goto error; } - ret = ca8210_reset_init(priv->spi); - if (ret) { - dev_crit(&spi_device->dev, "ca8210_reset_init failed\n"); + priv->gpio_reset = gpiod_get(&spi_device->dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(priv->gpio_reset)) { + dev_crit(&spi_device->dev, "ca8210 reset init failed\n"); goto error; } - ret = ca8210_interrupt_init(priv->spi); + ret = ca8210_interrupt_init(priv->spi, priv); if (ret) { dev_crit(&spi_device->dev, "ca8210_interrupt_init failed\n"); goto error;