dt-bindings: serial: sc16is7xx: Add description for polling mode
Subsystems (2)
PATCH v3 1/2 dt-bindings: serial: sc16is7xx: Add description for polling mode
Polling mode is enabled if the "interrupts" property is missing. Thus, this commit deletes "interrupts" entry from "required" section and adds a description for the fallback to polling mode at the "interrupts" entry.
---
V3:
- No changes on source.
- Add Acked-By to commit message.
--- Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml +2 -1
@@ -23,6 +23,8 @@ properties: maxItems: 1 interrupts: + description: + When missing, device driver uses polling instead. maxItems: 1 clocks:
@@ -76,7 +78,6 @@ properties: required: - compatible - reg - - interrupts allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml#
Signature · 1 line
2.47.1
PATCH v3 2/2 serial: sc16is7xx: Add polling feature if no IRQ usage possible
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.
---
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.
---
--- drivers/tty/serial/sc16is7xx.c | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
drivers/tty/serial/sc16is7xx.c +40 -0
@@ -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,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); + +/* Reuse standard IRQ handler. Interrupt ID is unused in this context. */ +sc16is7xx_irq (0 , s); + +/* Setup delay based on SC16IS7XX_POLL_PERIOD_MS */ +if (!s->shutdown) +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 +1166,7 @@ static int sc16is7xx_config_rs485(struct uart_port *port, struct ktermios *termistatic 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_MS )); + }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_dbg (dev, +"No interrupt definition found. Falling back to polling mode.\n" ); + irq =0 ; + } s->clk =devm_clk_get_optional (dev,NULL );if (IS_ERR (s->clk))return PTR_ERR (s->clk);
@@ -1664,6 +1697,11 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,if (ret) goto out_ports;#endif +if (s->polling) { +/* Initialize kernel thread for polling */ +kthread_init_delayed_work (&s->poll_work, sc16is7xx_transmission_poll); +return 0 ; + }/* * Setup interrupt. We first try to acquire the IRQ line as level IRQ.
@@ -1724,6 +1762,8 @@ 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);
Signature · 1 line
2.47.1
Re: [PATCH v3 2/2] serial: sc16is7xx: Add polling feature if no IRQ usage possible
On Tue, 7 Jan 2025 15:29:47 +0100
Andre Werner <[email protected]> wrote:
Hi Andre,
Quoted 3 lines
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.
"not possible" is confusing. Maybe:
"Fall back to polling mode if interrupt pin is not connected or available."
You also could change the commit title in a similar way (Add polling feature if no IRQ pin is available).
I would also replace "feature" with "mode" for consistency with your other comments below.
Quoted 40 lines
Signed-off-by Andre Werner <[email protected]>---
V2:
- Change warning for polling mode to debug log entry
- Correct typo: Resuse -> Reuse
- Format define with missing tabs forSC16IS7XX_POLL_PERIOD
- Format struct declarationsc16is7xx_one_configwith missing tabs for polling and shutdown
- Adapt dtbinding with new polling feature
V3:
- Use suffix with units and drop a commentSC16IS7XX_POLL_PERIOD_MS. Sorry for that miss.
- Make Kernel lowercase.
------ drivers/tty/serial/sc16is7xx.c | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)drivers/tty/serial/sc16is7xx.c +4
-0@@ -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,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[]; };
drivers/tty/serial/sc16is7xx.c static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) · line 868
Quoted 4 lines
drivers/tty/serial/sc16is7xx.c +1
-0@@ -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)
Maybe drop "transmission", as this is used for tx/rx?
And other kthread work functions use _proc suffix, so rename to follow the same convention -> sc16is7xx_poll_proc()
They also use "wk" as argument name, so also rename it for consistency.
Quoted 24 lines
drivers/tty/serial/sc16is7xx.c +13
-0+{ + struct sc16is7xx_port *s = container_of(work, 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 */ +if (!s->shutdown) +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 +1166,7 @@ static int sc16is7xx_config_rs485(struct uart_port *port, struct ktermios *termistatic 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;
drivers/tty/serial/sc16is7xx.c static int sc16is7xx_startup(struct uart_port *port) · line 1230
Quoted 3 lines
drivers/tty/serial/sc16is7xx.c +0
-0@@ -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);
Insert blank line
Quoted 9 lines
drivers/tty/serial/sc16is7xx.c +5
-0+if (s->polling) { + s->shutdown = false; +kthread_queue_delayed_work (&s->kworker, &s->poll_work, +msecs_to_jiffies (SC16IS7XX_POLL_PERIOD_MS )); + }return 0 ; }
drivers/tty/serial/sc16is7xx.c static void sc16is7xx_shutdown(struct uart_port *port) · line 1259
Quoted 5 lines
drivers/tty/serial/sc16is7xx.c +2
-0@@ -1232,6 +1255,10 @@ static void sc16is7xx_shutdown(struct uart_port *port)sc16is7xx_power (port,0 ); +if (s->polling) { + s->shutdown = true;
Can we avoid using this shutdown variable?
From what I see, kthread_cancel_delayed_work_sync()
itself will call kthread_cancel_work_sync(), and doc for it states that:
"This function can be used even if the work re-queues itself"
drivers/tty/serial/sc16is7xx.c static void sc16is7xx_shutdown(struct uart_port *port) · line 1261
Quoted 2 lines
drivers/tty/serial/sc16is7xx.c +2
-0+kthread_cancel_delayed_work_sync (&s->poll_work); + }
Blank line
drivers/tty/serial/sc16is7xx.c int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, · line 1566
Quoted 7 lines
drivers/tty/serial/sc16is7xx.c +0
-0kthread_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);
Blank line
drivers/tty/serial/sc16is7xx.c int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, · line 1568
Quoted 2 lines
drivers/tty/serial/sc16is7xx.c +1
-0+ s->polling = !device_property_present (dev,"interrupts" );
Remove blank line
drivers/tty/serial/sc16is7xx.c int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, · line 1571
Quoted 3 lines
drivers/tty/serial/sc16is7xx.c +3
-0+if (s->polling) { +dev_dbg (dev, +"No interrupt definition found. Falling back to polling mode.\n" );
Maybe: "No interrupt pin definition, falling back to polling mode\n"
(add pin and gets rid of trailing point)
drivers/tty/serial/sc16is7xx.c int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, · line 1573
Quoted 2 lines
drivers/tty/serial/sc16is7xx.c +2
-0+ irq =0 ; + }
Blank line
drivers/tty/serial/sc16is7xx.c int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, · line 1699
Quoted 7 lines
drivers/tty/serial/sc16is7xx.c +0
-0s->clk =devm_clk_get_optional (dev,NULL );if (IS_ERR (s->clk))return PTR_ERR (s->clk);@@ -1664,6 +1697,11 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,if (ret) goto out_ports;#endif
Blank line
Quoted 9 lines
drivers/tty/serial/sc16is7xx.c +5
-0+if (s->polling) { +/* Initialize kernel thread for polling */ +kthread_init_delayed_work (&s->poll_work, sc16is7xx_transmission_poll); +return 0 ; + }/* * Setup interrupt. We first try to acquire the IRQ line as level IRQ.
drivers/tty/serial/sc16is7xx.c void sc16is7xx_remove(struct device *dev) · line 1766
Quoted 5 lines
drivers/tty/serial/sc16is7xx.c +2
-0@@ -1724,6 +1762,8 @@ void sc16is7xx_remove(struct device *dev)sc16is7xx_power (&s->p[i].port,0 ); } +if (s->polling) +kthread_cancel_delayed_work_sync (&s->poll_work);
Blank line
Quoted 8 lines
drivers/tty/serial/sc16is7xx.c +0
-0kthread_flush_worker (&s->kworker);kthread_stop (s->kworker_task);Signature · 1 line
2.47.1
Signature · 1 line
Hugo Villeneuve