From patchwork Sat Aug 28 17:15:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 503774 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp259852jai; Sat, 28 Aug 2021 10:18:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvH+wNwiiKBCd4L3TKA/yKvB8yZk3Wqb0lQ68Q7wrJxI+jDjP/XzRlR/+i/ufpjAafSCg1 X-Received: by 2002:a05:6e02:dcc:: with SMTP id l12mr10634430ilj.20.1630171097015; Sat, 28 Aug 2021 10:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630171097; cv=none; d=google.com; s=arc-20160816; b=kU/ordASEG/2/kbdPEb6MI2X/twDni9GB7hbYu11ASAZ6wm79BIGW7EmMEq3aw5o6q HYWq6Fz3QMAK2vaOLUjffqdF651Ssukno1feRWek5Qsmui80Z7Lgh1hOcYWNnNoYhbWT UwbXth7PHnctbxS+ddddIBlkjZPWJzWGN+x/UQ6bIofE+8+7OOHVf9htFfADoqhd2ToE 9JPuCPbeJknhc99N0QAzwpAhKs0WWwrDO5NbTecUjX90VqADI8OKaEBGpMW7YbqTBNg2 gkfdJ2WUKBuCJYLngB1ZhrYcVsDC/WqJq6/JpkeMYS8+3Q/TWglK4AEvVqAtmEaepCxk BgEg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZXI2en2FpO56VmbTeLm1+JipCE8ULCAYjbhwip5qLZ0=; b=K5UUls/6Nj9dOcWXuNJvmpuQJ4l5g9W4K6gOo79ot24zY6o5GW4Bm63TyJO6ZYJsuk F9sR/h662lpMYLW9g5vPcFTpZnbQOCPVp7up7NEjbVVvDgZtCIbAh9wxWILA00MLZDdL n1bQimcXunO5rcTSQboAgbLnS8DfzxQfj+xE+a1bti5fw3T1bHJeWEoRv7Rgkur7vOGD pjLBC9Wzh3o+uZfdb6PpYEg23iyNluxskkzskrsbkRseKnrcKkQ/+Zn49GvzrAYGuhte ZFfGmf9cfm3sTY3g2vCys883X8nGUZyA+1rih1Yh3QRqOs4lscZzP2BgOONYZNmj9NHh 9SSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hvWE2eXE; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i126si4695650iof.61.2021.08.28.10.18.16; Sat, 28 Aug 2021 10:18:17 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hvWE2eXE; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234647AbhH1RTG (ORCPT + 8 others); Sat, 28 Aug 2021 13:19:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbhH1RS6 (ORCPT ); Sat, 28 Aug 2021 13:18:58 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4E20C0613D9 for ; Sat, 28 Aug 2021 10:18:07 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id h1so17442226ljl.9 for ; Sat, 28 Aug 2021 10:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZXI2en2FpO56VmbTeLm1+JipCE8ULCAYjbhwip5qLZ0=; b=hvWE2eXExRvPfs7okKuf18YhH/yeTHDrP0yKn3lNm/w+5+sUDpMVoKON2Gd4Nl9dzt antEJyF5qB2Pj/Jmu9wQbHIAgVt/NDfs7dTHY7ghZ5mvUbi5uSjvPIRk3trNrxoozfhF GjiXm0oc+1lRyaXCfVOX/enoCNponcZVRRCErDJcnyAJ+gYQaA+AQ3DiHarg1gFcVUab oK3IaWBqjrJ8UKT7MfmTMYlTnVX5AA36MZPXRi5atQYKHoXwFoTEOpUq3nhBSkNW+75b bMGdW8pn5N3p+fT6iOHLA/w8PUSMGbN9kWUzRf3hQdvlC4apy5TPL6ib0wCm9o6f/TxP yGYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZXI2en2FpO56VmbTeLm1+JipCE8ULCAYjbhwip5qLZ0=; b=ZZ3EAAQ66WnqVhHfpRU7VHXhzTxuETkMBpLBBuLzX8lnaaxQACKWUnY2vWo/kp9rV/ iItwLsCx8DrooiISKPCaqMKH2GH50oA3B+XQNs7Z8XFQ3cThdxrn5JgQPO5weHByTgYv 0iWDfIiGZTCslzbDo9j837l8C9YQXEs/TjGIlYp9PS1BqGmY/KC4tGPQys9bzxXzvxbU oDvOg8TtsfdkkO9MGSvlIfcpDrDEwlp4WeXw1fAUIEgnUoRYrSWvcn/oMCyNAghSqsIt FFRi6PtdUNNzYFEkh7zckBunkDjdtzHmutcBhJKLsIt7fN8pMKhfQK4DWooHsCkdB/EQ KYUg== X-Gm-Message-State: AOAM532+ZThwNfhXF88qkFSm4BiFDaekrgYTJf5vhHLQUqJnRi4g+jgU DBjLB9f7pSAF4ZS7UW7O0nXCWHJYVGhQ4g== X-Received: by 2002:a2e:99c8:: with SMTP id l8mr13133242ljj.178.1630171086161; Sat, 28 Aug 2021 10:18:06 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id p1sm202195lfo.255.2021.08.28.10.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Aug 2021 10:18:05 -0700 (PDT) From: Linus Walleij To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: Imre Kaloz , Krzysztof Halasa , Linus Walleij , Arnd Bergmann Subject: [PATCH net-next 3/5 v3] ixp4xx_eth: Stop referring to GPIOs Date: Sat, 28 Aug 2021 19:15:46 +0200 Message-Id: <20210828171548.143057-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210828171548.143057-1-linus.walleij@linaro.org> References: <20210828171548.143057-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The driver is being passed interrupts, then looking up the same interrupts as GPIOs a second time to convert them into interrupts and set properties on them. This is pointless: the GPIO and irqchip APIs of a GPIO chip are orthogonal. Just request the interrupts and be done with it, drop reliance on any GPIO functions or definitions. Use devres-managed functions and add a small devress quirk to unregister the clock as well and we can rely on devres to handle all the resources and cut down a bunch of boilerplate in the process. Cc: Arnd Bergmann Signed-off-by: Linus Walleij --- drivers/net/ethernet/xscale/ptp_ixp46x.c | 84 ++++++++---------------- 1 file changed, 28 insertions(+), 56 deletions(-) -- 2.31.1 diff --git a/drivers/net/ethernet/xscale/ptp_ixp46x.c b/drivers/net/ethernet/xscale/ptp_ixp46x.c index 466f233edd21..c7ff150bf23f 100644 --- a/drivers/net/ethernet/xscale/ptp_ixp46x.c +++ b/drivers/net/ethernet/xscale/ptp_ixp46x.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -23,8 +22,6 @@ #define DRIVER "ptp_ixp46x" #define N_EXT_TS 2 -#define MASTER_GPIO 8 -#define SLAVE_GPIO 7 struct ixp_clock { struct ixp46x_ts_regs *regs; @@ -245,38 +242,6 @@ static const struct ptp_clock_info ptp_ixp_caps = { static struct ixp_clock ixp_clock; -static int setup_interrupt(int gpio) -{ - int irq; - int err; - - err = gpio_request(gpio, "ixp4-ptp"); - if (err) - return err; - - err = gpio_direction_input(gpio); - if (err) - return err; - - irq = gpio_to_irq(gpio); - if (irq < 0) - return irq; - - err = irq_set_irq_type(irq, IRQF_TRIGGER_FALLING); - if (err) { - pr_err("cannot set trigger type for irq %d\n", irq); - return err; - } - - err = request_irq(irq, isr, 0, DRIVER, &ixp_clock); - if (err) { - pr_err("request_irq failed for irq %d\n", irq); - return err; - } - - return irq; -} - int ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index) { *regs = ixp_clock.regs; @@ -289,18 +254,20 @@ int ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index) } EXPORT_SYMBOL_GPL(ixp46x_ptp_find); -static int ptp_ixp_remove(struct platform_device *pdev) +/* Called from the registered devm action */ +static void ptp_ixp_unregister_action(void *d) { - free_irq(ixp_clock.master_irq, &ixp_clock); - free_irq(ixp_clock.slave_irq, &ixp_clock); - ptp_clock_unregister(ixp_clock.ptp_clock); - ixp_clock.ptp_clock = NULL; + struct ptp_clock *ptp_clock = d; - return 0; + ptp_clock_unregister(ptp_clock); + ixp_clock.ptp_clock = NULL; } static int ptp_ixp_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; + int ret; + ixp_clock.regs = devm_platform_ioremap_resource(pdev, 0); ixp_clock.master_irq = platform_get_irq(pdev, 0); ixp_clock.slave_irq = platform_get_irq(pdev, 1); @@ -315,34 +282,39 @@ static int ptp_ixp_probe(struct platform_device *pdev) if (IS_ERR(ixp_clock.ptp_clock)) return PTR_ERR(ixp_clock.ptp_clock); + ret = devm_add_action_or_reset(dev, ptp_ixp_unregister_action, + ixp_clock.ptp_clock); + if (ret) { + dev_err(dev, "failed to install clock removal handler\n"); + return ret; + } + __raw_writel(DEFAULT_ADDEND, &ixp_clock.regs->addend); __raw_writel(1, &ixp_clock.regs->trgt_lo); __raw_writel(0, &ixp_clock.regs->trgt_hi); __raw_writel(TTIPEND, &ixp_clock.regs->event); - if (ixp_clock.master_irq != setup_interrupt(MASTER_GPIO)) { - pr_err("failed to setup gpio %d as irq\n", MASTER_GPIO); - goto no_master; - } - if (ixp_clock.slave_irq != setup_interrupt(SLAVE_GPIO)) { - pr_err("failed to setup gpio %d as irq\n", SLAVE_GPIO); - goto no_slave; - } + ret = devm_request_irq(dev, ixp_clock.master_irq, isr, + 0, DRIVER, &ixp_clock); + if (ret) + return dev_err_probe(dev, ret, + "request_irq failed for irq %d\n", + ixp_clock.master_irq); + + ret = devm_request_irq(dev, ixp_clock.slave_irq, isr, + 0, DRIVER, &ixp_clock); + if (ret) + return dev_err_probe(dev, ret, + "request_irq failed for irq %d\n", + ixp_clock.slave_irq); return 0; -no_slave: - free_irq(ixp_clock.master_irq, &ixp_clock); -no_master: - ptp_clock_unregister(ixp_clock.ptp_clock); - ixp_clock.ptp_clock = NULL; - return -ENODEV; } static struct platform_driver ptp_ixp_driver = { .driver.name = "ptp-ixp46x", .driver.suppress_bind_attrs = true, .probe = ptp_ixp_probe, - .remove = ptp_ixp_remove, }; module_platform_driver(ptp_ixp_driver);