Skip to contentSkip to conversation

dt-bindings: serial: sc16is7xx: Add description for polling mode

PATCH Superseded Andre Werner 2 participants 5 messages Jan 13, 2025

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 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.
V4:
- No changes
V5:
- No changes
V6:
- No changes

---
 Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml +2 -1
index 88871480018e..ab39b95dae40 100644
@@ -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
#1 lore raw

PATCH v6 2/2 serial: sc16is7xx: Add polling mode if no IRQ pin is available

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.

---
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 V5:
- Replace of_property check with IRQ number check to set polling
property. This will add support for usage without device tree
definitions. Thanks for that advice.
- Add blank line es requested.
V6:
- Use polling mode for IRQ numbers <= 0 which encounter no valid IRQ
were found/defined.

---
 drivers/tty/serial/sc16is7xx.c | 37 ++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
drivers/tty/serial/sc16is7xx.c +37 -0
index a3093e09309f..560f45ed19ae 100644
@@ -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);
 }
 
@@ -1538,6 +1561,11 @@ 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 = (irq <= 0);
+	if (s->polling)
+		dev_dbg(dev,
+			"No interrupt pin definition, falling back to polling mode\n");
+
 	s->clk = devm_clk_get_optional(dev, NULL);
 	if (IS_ERR(s->clk))
 		return PTR_ERR(s->clk);
@@ -1665,6 +1693,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 +1758,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);
 
Signature · 1 line
2.47.1
#2 lore raw

Re: [PATCH v6 2/2] serial: sc16is7xx: Add polling mode if no IRQ pin is available

Quoted 4 lines · Andre Werner

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.

pull ? Hmm...

...

Quoted 3 lines

V6:
- Use polling mode for IRQ numbers <= 0 which encounter no valid IRQ were found/defined.

Thanks, this part looks better now.

...

drivers/tty/serial/sc16is7xx.c static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) · line 871

Quoted 5 lines
drivers/tty/serial/sc16is7xx.c +5 -0
+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. */

Period.

drivers/tty/serial/sc16is7xx.c static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) · line 874

Quoted 3 lines
drivers/tty/serial/sc16is7xx.c +3 -0
+	sc16is7xx_irq(0, s);
+
+	/* Setup delay based on SC16IS7XX_POLL_PERIOD_MS */

No period.

drivers/tty/serial/sc16is7xx.c static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) · line 877

Quoted 3 lines
drivers/tty/serial/sc16is7xx.c +3 -0
+	kthread_queue_delayed_work(&s->kworker, &s->poll_work,
+				   msecs_to_jiffies(SC16IS7XX_POLL_PERIOD_MS));
+}

Please, go through the comments you added in the patch and use the style that is mostly used in the driver for the similar (one-line comment) situations.

...

drivers/tty/serial/sc16is7xx.c int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, · line 1697

Quoted 1 line
drivers/tty/serial/sc16is7xx.c +1 -0
+		/* Initialize kernel thread for polling */

Again, no period.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Re: [External Email] Re: [PATCH v6 2/2] serial: sc16is7xx: Add polling mode if no IRQ pin is available

Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Andre Werner

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.

pull ? Hmm...

Ah ... poll ... sorry.

Quoted 11 lines

...

Quoted 3 lines

V6:
- Use polling mode for IRQ numbers <= 0 which encounter no valid IRQ were found/defined.

Thanks, this part looks better now.

...

Quoted 7 lines

drivers/tty/serial/sc16is7xx.c static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) · line 871

Quoted 5 lines
drivers/tty/serial/sc16is7xx.c +5 -0
+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. */

Period.

What do you expect here? Shall I add the period time from the define as the dedicated value? I do not understand what I should add here in detail.

Quoted 6 lines

drivers/tty/serial/sc16is7xx.c static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) · line 874

Quoted 4 lines
drivers/tty/serial/sc16is7xx.c +3 -0
+	sc16is7xx_irq(0, s);
+
+	/* Setup delay based on SC16IS7XX_POLL_PERIOD_MS */

No period.

Or do you mean that I add the define only once and not add all used places?

Quoted 8 lines

drivers/tty/serial/sc16is7xx.c static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) · line 877

Quoted 4 lines
drivers/tty/serial/sc16is7xx.c +3 -0
+	kthread_queue_delayed_work(&s->kworker, &s->poll_work,
+				   msecs_to_jiffies(SC16IS7XX_POLL_PERIOD_MS));
+}

Please, go through the comments you added in the patch and use the style that is mostly used in the driver for the similar (one-line comment) situations.

Quoted 5 lines

...

drivers/tty/serial/sc16is7xx.c int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, · line 1697

Quoted 1 line
drivers/tty/serial/sc16is7xx.c +1 -0
+		/* Initialize kernel thread for polling */

Again, no period.

Same here. Do you expect the value here or the name of the used define?

Quoted 7 lines

--
With Best Regards,
Andy Shevchenko

Thanks in advance

André

#4 lore raw

Re: [External Email] Re: [PATCH v6 2/2] serial: sc16is7xx: Add polling mode if no IRQ pin is available

Quoted 2 lines · Andre Werner
Quoted 1 line · Andy Shevchenko

On Mon, Jan 13, 2025 at 08:30:30AM +0100, Andre Werner wrote:

...

Quoted 19 lines
Quoted 7 lines

drivers/tty/serial/sc16is7xx.c static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) · line 871

Quoted 5 lines
drivers/tty/serial/sc16is7xx.c +5 -0
+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. */

Period.

What do you expect here? Shall I add the period time from the define as the dedicated value? I do not understand what I should add here in detail.

Quoted 4 lines

drivers/tty/serial/sc16is7xx.c static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) · line 874

Quoted 2 lines
drivers/tty/serial/sc16is7xx.c +1 -0
+	/* Setup delay based on SC16IS7XX_POLL_PERIOD_MS */

No period.

Or do you mean that I add the define only once and not add all used places?

...

Quoted 2 lines
Quoted 2 lines

Please, go through the comments you added in the patch and use the style that is mostly used in the driver for the similar (one-line comment) situations.

^^^ Read this. You have added three comments in two different styles. It's not a big or anyhow critical issue in this case, it's matter of the consistency with the existing style.

I expect that all three will in the same style, preferable the one that is currently in use in the driver for other comments.

...

Quoted 5 lines
Quoted 3 lines

drivers/tty/serial/sc16is7xx.c int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, · line 1697

Quoted 1 line
drivers/tty/serial/sc16is7xx.c +1 -0
+		/* Initialize kernel thread for polling */

Again, no period.

Same here. Do you expect the value here or the name of the used define?

Signature · 2 lines
With Best Regards,
Andy Shevchenko