From: Greg KH <gregkh@linuxfoundation.org>
To: Andre Werner <andre.werner@systec-electronic.com>
Cc: jirislaby@kernel.org, hvilleneuve@dimonoff.com, andy@kernel.org,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
lech.perczak@camlingroup.com
Subject: Re: [PATCH] serial: sc16is7xx: Add polling feature if no IRQ usage possible
Date: Thu, 19 Dec 2024 09:56:17 +0100 [thread overview]
Message-ID: <2024121931-turbojet-preamble-b520@gregkh> (raw)
In-Reply-To: <20241219084638.960253-1-andre.werner@systec-electronic.com>
On Thu, Dec 19, 2024 at 09:46:38AM +0100, Andre Werner wrote:
> Fall back to polling mode if no interrupt is configured because not
> possible. If "interrupts" property is missing in devicetree the driver
> uses a delayed worker to pull state of interrupt status registers.
>
> Signed-off-by: Andre Werner <andre.werner@systec-electronic.com>
> ---
> This driver was tested on Linux 5.10. We had a custom board that was not
> able to connect the interrupt port. Only I2C was available.
Could you not test this on the latest tree? 5.10 is _VERY_ old now.
> ---
> ---
> drivers/tty/serial/sc16is7xx.c | 40 ++++++++++++++++++++++++++++++++++
> 1 file changed, 40 insertions(+)
>
> diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
> index a3093e09309f..31962fdca178 100644
> --- a/drivers/tty/serial/sc16is7xx.c
> +++ b/drivers/tty/serial/sc16is7xx.c
> @@ -314,6 +314,7 @@
> #define SC16IS7XX_FIFO_SIZE (64)
> #define SC16IS7XX_GPIOS_PER_BANK 4
>
> +#define SC16IS7XX_POLL_PERIOD 10 /*ms*/
Please use a tab here.
> #define SC16IS7XX_RECONF_MD BIT(0)
> #define SC16IS7XX_RECONF_IER BIT(1)
> #define SC16IS7XX_RECONF_RS485 BIT(2)
> @@ -348,6 +349,9 @@ struct sc16is7xx_port {
> u8 mctrl_mask;
> struct kthread_worker kworker;
> struct task_struct *kworker_task;
> + struct kthread_delayed_work poll_work;
> + bool polling;
> + bool shutdown;
> struct sc16is7xx_one p[];
> };
>
> @@ -861,6 +865,19 @@ static irqreturn_t sc16is7xx_irq(int irq, void *dev_id)
> return IRQ_HANDLED;
> }
>
> +static void sc16is7xx_transmission_poll(struct kthread_work *work)
> +{
> + struct sc16is7xx_port *s = container_of(work, struct sc16is7xx_port, poll_work.work);
> +
> + /* Resuse standard IRQ handler. Interrupt ID is unused in this context. */
> + sc16is7xx_irq(0, s);
> +
> + /* setup delay based on SC16IS7XX_POLL_PERIOD */
> + if (!s->shutdown)
> + kthread_queue_delayed_work(&s->kworker, &s->poll_work,
> + msecs_to_jiffies(SC16IS7XX_POLL_PERIOD));
> +}
> +
> static void sc16is7xx_tx_proc(struct kthread_work *ws)
> {
> struct uart_port *port = &(to_sc16is7xx_one(ws, tx_work)->port);
> @@ -1149,6 +1166,7 @@ static int sc16is7xx_config_rs485(struct uart_port *port, struct ktermios *termi
> static int sc16is7xx_startup(struct uart_port *port)
> {
> struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
> + struct sc16is7xx_port *s = dev_get_drvdata(port->dev);
> unsigned int val;
> unsigned long flags;
>
> @@ -1210,6 +1228,11 @@ static int sc16is7xx_startup(struct uart_port *port)
> uart_port_lock_irqsave(port, &flags);
> sc16is7xx_enable_ms(port);
> uart_port_unlock_irqrestore(port, flags);
> + if (s->polling) {
> + s->shutdown = false;
> + kthread_queue_delayed_work(&s->kworker, &s->poll_work,
> + msecs_to_jiffies(SC16IS7XX_POLL_PERIOD));
> + }
>
> return 0;
> }
> @@ -1232,6 +1255,10 @@ static void sc16is7xx_shutdown(struct uart_port *port)
>
> sc16is7xx_power(port, 0);
>
> + if (s->polling) {
> + s->shutdown = true;
> + kthread_cancel_delayed_work_sync(&s->poll_work);
> + }
> kthread_flush_worker(&s->kworker);
> }
>
> @@ -1537,7 +1564,13 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,
>
> /* Always ask for fixed clock rate from a property. */
> device_property_read_u32(dev, "clock-frequency", &uartclk);
> + s->polling = !device_property_present(dev, "interrupts");
>
> + if (s->polling) {
> + dev_warn(dev,
> + "No interrupt definition found. Falling back to polling mode.\n");
What is a user supposed to do with this message? And why would a device
NOT have any interrupts? This feels like it is just going to pound on
the device and cause a lot of power drain for just a simple little uart.
Why can't your system provide a valid irq line?
thanks,
greg k-h
next prev parent reply other threads:[~2024-12-19 8:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-19 8:46 [PATCH] serial: sc16is7xx: Add polling feature if no IRQ usage possible Andre Werner
2024-12-19 8:56 ` Greg KH [this message]
2024-12-19 9:22 ` [External Email] " Andre Werner
2024-12-19 9:41 ` Greg KH
2024-12-20 5:50 ` Andre Werner
2024-12-23 14:27 ` Maarten Brock
2024-12-23 17:59 ` Greg KH
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=2024121931-turbojet-preamble-b520@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=andre.werner@systec-electronic.com \
--cc=andy@kernel.org \
--cc=hvilleneuve@dimonoff.com \
--cc=jirislaby@kernel.org \
--cc=lech.perczak@camlingroup.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@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 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.