All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: Rob Herring <robh+dt@kernel.org>,
	William Breathitt Gray <vilhelm.gray@gmail.com>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	David Jander <david@protonic.nl>,
	Robin van der Gracht <robin@protonic.nl>,
	linux-iio@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>
Subject: Re: [PATCH v6 2/2] counter: add IRQ or GPIO based event counter
Date: Sun, 21 Feb 2021 15:41:32 +0000	[thread overview]
Message-ID: <20210221154132.037100ff@archlinux> (raw)
In-Reply-To: <20210216081356.3577-3-o.rempel@pengutronix.de>

On Tue, 16 Feb 2021 09:13:56 +0100
Oleksij Rempel <o.rempel@pengutronix.de> wrote:

> Add simple IRQ or GPIO base event counter. This device is used to measure
> rotation speed of some agricultural devices, so no high frequency on the
> counter pin is expected.
> 
> The maximal measurement frequency depends on the CPU and system load. On
> the idle iMX6S I was able to measure up to 20kHz without count drops.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
A FYI note inline.

Driver looks good to me.

Jonathan

> ---
>  MAINTAINERS                     |   7 +
>  drivers/counter/Kconfig         |  10 ++
>  drivers/counter/Makefile        |   1 +
>  drivers/counter/interrupt-cnt.c | 249 ++++++++++++++++++++++++++++++++
>  4 files changed, 267 insertions(+)
>  create mode 100644 drivers/counter/interrupt-cnt.c
> 
...

> +static int interrupt_cnt_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct interrupt_cnt_priv *priv;
> +	int ret;
> +
> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	priv->irq = platform_get_irq_optional(pdev,  0);
> +	if (priv->irq == -ENXIO)
> +		priv->irq = 0;
> +	else if (priv->irq < 0)
> +		return dev_err_probe(dev, priv->irq, "failed to get IRQ\n");
> +
> +	priv->gpio = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
> +	if (IS_ERR(priv->gpio))
> +		return dev_err_probe(dev, PTR_ERR(priv->gpio), "failed to get GPIO\n");
> +
> +	if (!priv->irq && !priv->gpio) {
> +		dev_err(dev, "IRQ and GPIO are not found. At least one source should be provided\n");
> +		return -ENODEV;
> +	}
> +
> +	if (!priv->irq) {
> +		int irq = gpiod_to_irq(priv->gpio);
> +
> +		if (irq < 0)
> +			return dev_err_probe(dev, irq, "failed to get IRQ from GPIO\n");
> +
> +		priv->irq = irq;
> +	}
> +
> +	priv->counter.priv = priv;
> +	priv->counter.name = dev_name(dev);
> +	priv->counter.parent = dev;
> +	priv->counter.ops = &interrupt_cnt_ops;
> +	priv->counter.counts = interrupt_cnts;
> +	priv->counter.num_counts = ARRAY_SIZE(interrupt_cnts);
> +	priv->counter.signals = interrupt_cnt_signals;
> +	priv->counter.num_signals = priv->gpio ?
> +				    ARRAY_SIZE(interrupt_cnt_signals) : 0;
> +
> +	irq_set_status_flags(priv->irq, IRQ_NOAUTOEN);

Just as a side note, there is a series that cleans up this case, though no
idea if it will make the merge window or not.

https://lore.kernel.org/linux-input/aefbe49321b845c98e505518314a93cc@hisilicon.com/

If it does we can tidy this up then.

> +	ret = devm_request_irq(dev, priv->irq, interrupt_cnt_isr,
> +			       IRQF_TRIGGER_RISING | IRQF_NO_THREAD,
> +			       INTERRUPT_CNT_NAME, priv);
> +	if (ret)
> +		return ret;
> +
> +	return devm_counter_register(dev, &priv->counter);
> +}
> +
...

  reply	other threads:[~2021-02-21 15:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-16  8:13 [PATCH v6 0/2] add support for GPIO or IRQ based evemt counter Oleksij Rempel
2021-02-16  8:13 ` [PATCH v6 1/2] dt-bindings: counter: add event-counter binding Oleksij Rempel
2021-03-05 21:53   ` Rob Herring
2021-02-16  8:13 ` [PATCH v6 2/2] counter: add IRQ or GPIO based event counter Oleksij Rempel
2021-02-21 15:41   ` Jonathan Cameron [this message]
2021-02-22  1:48 ` [PATCH v6 0/2] add support for GPIO or IRQ based evemt counter William Breathitt Gray
2021-02-23  7:16   ` Oleksij Rempel
2021-02-23  8:14     ` William Breathitt Gray

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=20210221154132.037100ff@archlinux \
    --to=jic23@kernel.org \
    --cc=a.fatoum@pengutronix.de \
    --cc=david@protonic.nl \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=robh+dt@kernel.org \
    --cc=robin@protonic.nl \
    --cc=vilhelm.gray@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.