From: Hugo Villeneuve <hugo@hugovil.com>
To: Andre Werner <andre.werner@systec-electronic.com>
Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org,
hvilleneuve@dimonoff.com, andy@kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-serial@vger.kernel.org, lech.perczak@camlingroup.com,
krzk+dt@kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v4 2/2] serial: sc16is7xx: Add polling mode if no IRQ pin is available
Date: Thu, 9 Jan 2025 09:43:03 -0500 [thread overview]
Message-ID: <20250109094303.9c1917e2e8704ff265dac4e2@hugovil.com> (raw)
In-Reply-To: <20250109093834.1013025-2-andre.werner@systec-electronic.com>
Hi Andre,
On Thu, 9 Jan 2025 10:38:34 +0100
Andre Werner <andre.werner@systec-electronic.com> wrote:
> Fall back to polling mode if no interrupt is configured because there
> is no possibility to connect the interrupt pin.
> If "interrupts" property is missing in devicetree the driver
> uses a delayed worker to pull the state of interrupt status registers.
>
> Signed-off-by: Andre Werner <andre.werner@systec-electronic.com>
> ---
> V2:
> - Change warning for polling mode to debug log entry
> - Correct typo: Resuse -> Reuse
> - Format define with missing tabs for SC16IS7XX_POLL_PERIOD
> - Format struct declaration sc16is7xx_one_config with missing tabs for polling and shutdown
> - Adapt dtbinding with new polling feature
> V3:
> - Use suffix with units and drop a comment SC16IS7XX_POLL_PERIOD_MS. Sorry for that miss.
> - Make Kernel lowercase.
> V4:
> - Reword commit messages for better understanding.
> - Remove 'shutdown' property for canceling delayed worker.
> - Rename worker function: sc16is7xx_transmission_poll -> sc16is7xx_poll_proc
> - Unify argument for worker functions: kthread_work *work -> kthread_work *ws
> ---
> drivers/tty/serial/sc16is7xx.c | 38 ++++++++++++++++++++++++++++++++++
> 1 file changed, 38 insertions(+)
>
> diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
> index a3093e09309f..6645cab2ae5f 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_MS 10
> #define SC16IS7XX_RECONF_MD BIT(0)
> #define SC16IS7XX_RECONF_IER BIT(1)
> #define SC16IS7XX_RECONF_RS485 BIT(2)
> @@ -348,6 +349,8 @@ struct sc16is7xx_port {
> u8 mctrl_mask;
> struct kthread_worker kworker;
> struct task_struct *kworker_task;
> + struct kthread_delayed_work poll_work;
> + bool polling;
> struct sc16is7xx_one p[];
> };
>
> @@ -861,6 +864,18 @@ static irqreturn_t sc16is7xx_irq(int irq, void *dev_id)
> return IRQ_HANDLED;
> }
>
> +static void sc16is7xx_poll_proc(struct kthread_work *ws)
> +{
> + struct sc16is7xx_port *s = container_of(ws, struct sc16is7xx_port, poll_work.work);
> +
> + /* Reuse standard IRQ handler. Interrupt ID is unused in this context. */
> + sc16is7xx_irq(0, s);
> +
> + /* Setup delay based on SC16IS7XX_POLL_PERIOD_MS */
> + kthread_queue_delayed_work(&s->kworker, &s->poll_work,
> + msecs_to_jiffies(SC16IS7XX_POLL_PERIOD_MS));
> +}
> +
> static void sc16is7xx_tx_proc(struct kthread_work *ws)
> {
> struct uart_port *port = &(to_sc16is7xx_one(ws, tx_work)->port);
> @@ -1149,6 +1164,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;
>
> @@ -1211,6 +1227,10 @@ static int sc16is7xx_startup(struct uart_port *port)
> sc16is7xx_enable_ms(port);
> uart_port_unlock_irqrestore(port, flags);
>
> + if (s->polling)
> + kthread_queue_delayed_work(&s->kworker, &s->poll_work,
> + msecs_to_jiffies(SC16IS7XX_POLL_PERIOD_MS));
> +
> return 0;
> }
>
> @@ -1232,6 +1252,9 @@ static void sc16is7xx_shutdown(struct uart_port *port)
>
> sc16is7xx_power(port, 0);
>
> + if (s->polling)
> + kthread_cancel_delayed_work_sync(&s->poll_work);
> +
> kthread_flush_worker(&s->kworker);
> }
>
> @@ -1537,6 +1560,12 @@ 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);
You are still missing a blank line here to better separate logical
blocks (polling is not related to clock-frequency).
> + s->polling = !device_property_present(dev, "interrupts");
> + if (s->polling) {
> + dev_dbg(dev,
> + "No interrupt pin definition, falling back to polling mode\n");
> + irq = 0;
> + }
>
> s->clk = devm_clk_get_optional(dev, NULL);
> if (IS_ERR(s->clk))
> @@ -1665,6 +1694,12 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,
> goto out_ports;
> #endif
>
> + if (s->polling) {
> + /* Initialize kernel thread for polling */
> + kthread_init_delayed_work(&s->poll_work, sc16is7xx_poll_proc);
> + return 0;
> + }
> +
> /*
> * Setup interrupt. We first try to acquire the IRQ line as level IRQ.
> * If that succeeds, we can allow sharing the interrupt as well.
> @@ -1724,6 +1759,9 @@ void sc16is7xx_remove(struct device *dev)
> sc16is7xx_power(&s->p[i].port, 0);
> }
>
> + if (s->polling)
> + kthread_cancel_delayed_work_sync(&s->poll_work);
> +
> kthread_flush_worker(&s->kworker);
> kthread_stop(s->kworker_task);
>
> --
> 2.47.1
>
>
>
--
Hugo Villeneuve
prev parent reply other threads:[~2025-01-09 14:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-09 9:38 [PATCH v4 1/2] dt-bindings: serial: sc16is7xx: Add description for polling mode Andre Werner
2025-01-09 9:38 ` [PATCH v4 2/2] serial: sc16is7xx: Add polling mode if no IRQ pin is available Andre Werner
2025-01-09 14:43 ` Hugo Villeneuve [this message]
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=20250109094303.9c1917e2e8704ff265dac4e2@hugovil.com \
--to=hugo@hugovil.com \
--cc=andre.werner@systec-electronic.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hvilleneuve@dimonoff.com \
--cc=jirislaby@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lech.perczak@camlingroup.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=robh@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
all inboxes | Powered by JetHome®