From: Linus Walleij <linus.walleij@linaro.org>
To: netdev@vger.kernel.org, "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Cc: Imre Kaloz <kaloz@openwrt.org>,
Krzysztof Halasa <khalasa@piap.pl>,
Linus Walleij <linus.walleij@linaro.org>,
Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH net-next 4/6] ixp4xx_eth: Stop referring to GPIOs
Date: Sun, 1 Aug 2021 02:27:35 +0200 [thread overview]
Message-ID: <20210801002737.3038741-5-linus.walleij@linaro.org> (raw)
In-Reply-To: <20210801002737.3038741-1-linus.walleij@linaro.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 <arnd@arndb.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/net/ethernet/xscale/ptp_ixp46x.c | 84 ++++++++----------------
1 file changed, 28 insertions(+), 56 deletions(-)
diff --git a/drivers/net/ethernet/xscale/ptp_ixp46x.c b/drivers/net/ethernet/xscale/ptp_ixp46x.c
index 6232a0e0710e..3ed40b0d0ad2 100644
--- a/drivers/net/ethernet/xscale/ptp_ixp46x.c
+++ b/drivers/net/ethernet/xscale/ptp_ixp46x.c
@@ -7,7 +7,6 @@
#include <linux/device.h>
#include <linux/module.h>
#include <linux/err.h>
-#include <linux/gpio.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
@@ -21,8 +20,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;
@@ -243,38 +240,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;
@@ -287,18 +252,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);
@@ -313,34 +280,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);
--
2.31.1
next prev parent reply other threads:[~2021-08-01 0:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-01 0:27 [PATCH net-next 0/6] IXP46x PTP Timer clean-up and DT Linus Walleij
2021-08-01 0:27 ` [PATCH net-next 1/6] ixp4xx_eth: make ptp support a platform driver Linus Walleij
2021-08-01 0:27 ` [PATCH net-next 2/6] ixp4xx_eth: fix compile-testing Linus Walleij
2021-08-01 0:27 ` [PATCH net-next 3/6] ixp4xx_eth: enable compile testing Linus Walleij
2021-08-01 0:27 ` Linus Walleij [this message]
2021-08-01 0:27 ` [PATCH net-next 5/6] ixp4xx_eth: Add devicetree bindings Linus Walleij
2021-08-03 20:38 ` Rob Herring
2021-08-01 0:27 ` [PATCH net-next 6/6] ixp4xx_eth: Probe the PTP module from the device tree Linus Walleij
2021-08-02 16:05 ` [PATCH net-next 0/6] IXP46x PTP Timer clean-up and DT Jakub Kicinski
2022-11-12 6:37 [PATCH net-next 4/6] ixp4xx_eth: Stop referring to GPIOs Ernest Ugwu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210801002737.3038741-5-linus.walleij@linaro.org \
--to=linus.walleij@linaro.org \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=kaloz@openwrt.org \
--cc=khalasa@piap.pl \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).