314
314
#define SC16IS7XX_FIFO_SIZE (64)
315
315
#define SC16IS7XX_GPIOS_PER_BANK 4
316
316
317
+ #define SC16IS7XX_POLL_PERIOD_MS 10
317
318
#define SC16IS7XX_RECONF_MD BIT(0)
318
319
#define SC16IS7XX_RECONF_IER BIT(1)
319
320
#define SC16IS7XX_RECONF_RS485 BIT(2)
@@ -348,6 +349,8 @@ struct sc16is7xx_port {
348
349
u8 mctrl_mask ;
349
350
struct kthread_worker kworker ;
350
351
struct task_struct * kworker_task ;
352
+ struct kthread_delayed_work poll_work ;
353
+ bool polling ;
351
354
struct sc16is7xx_one p [];
352
355
};
353
356
@@ -861,6 +864,18 @@ static irqreturn_t sc16is7xx_irq(int irq, void *dev_id)
861
864
return IRQ_HANDLED ;
862
865
}
863
866
867
+ static void sc16is7xx_poll_proc (struct kthread_work * ws )
868
+ {
869
+ struct sc16is7xx_port * s = container_of (ws , struct sc16is7xx_port , poll_work .work );
870
+
871
+ /* Reuse standard IRQ handler. Interrupt ID is unused in this context. */
872
+ sc16is7xx_irq (0 , s );
873
+
874
+ /* Setup delay based on SC16IS7XX_POLL_PERIOD_MS */
875
+ kthread_queue_delayed_work (& s -> kworker , & s -> poll_work ,
876
+ msecs_to_jiffies (SC16IS7XX_POLL_PERIOD_MS ));
877
+ }
878
+
864
879
static void sc16is7xx_tx_proc (struct kthread_work * ws )
865
880
{
866
881
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
1149
1164
static int sc16is7xx_startup (struct uart_port * port )
1150
1165
{
1151
1166
struct sc16is7xx_one * one = to_sc16is7xx_one (port , port );
1167
+ struct sc16is7xx_port * s = dev_get_drvdata (port -> dev );
1152
1168
unsigned int val ;
1153
1169
unsigned long flags ;
1154
1170
@@ -1211,6 +1227,10 @@ static int sc16is7xx_startup(struct uart_port *port)
1211
1227
sc16is7xx_enable_ms (port );
1212
1228
uart_port_unlock_irqrestore (port , flags );
1213
1229
1230
+ if (s -> polling )
1231
+ kthread_queue_delayed_work (& s -> kworker , & s -> poll_work ,
1232
+ msecs_to_jiffies (SC16IS7XX_POLL_PERIOD_MS ));
1233
+
1214
1234
return 0 ;
1215
1235
}
1216
1236
@@ -1232,6 +1252,9 @@ static void sc16is7xx_shutdown(struct uart_port *port)
1232
1252
1233
1253
sc16is7xx_power (port , 0 );
1234
1254
1255
+ if (s -> polling )
1256
+ kthread_cancel_delayed_work_sync (& s -> poll_work );
1257
+
1235
1258
kthread_flush_worker (& s -> kworker );
1236
1259
}
1237
1260
@@ -1538,6 +1561,11 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,
1538
1561
/* Always ask for fixed clock rate from a property. */
1539
1562
device_property_read_u32 (dev , "clock-frequency" , & uartclk );
1540
1563
1564
+ s -> polling = !!irq ;
1565
+ if (s -> polling )
1566
+ dev_dbg (dev ,
1567
+ "No interrupt pin definition, falling back to polling mode\n" );
1568
+
1541
1569
s -> clk = devm_clk_get_optional (dev , NULL );
1542
1570
if (IS_ERR (s -> clk ))
1543
1571
return PTR_ERR (s -> clk );
@@ -1665,6 +1693,12 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,
1665
1693
goto out_ports ;
1666
1694
#endif
1667
1695
1696
+ if (s -> polling ) {
1697
+ /* Initialize kernel thread for polling */
1698
+ kthread_init_delayed_work (& s -> poll_work , sc16is7xx_poll_proc );
1699
+ return 0 ;
1700
+ }
1701
+
1668
1702
/*
1669
1703
* Setup interrupt. We first try to acquire the IRQ line as level IRQ.
1670
1704
* If that succeeds, we can allow sharing the interrupt as well.
@@ -1724,6 +1758,9 @@ void sc16is7xx_remove(struct device *dev)
1724
1758
sc16is7xx_power (& s -> p [i ].port , 0 );
1725
1759
}
1726
1760
1761
+ if (s -> polling )
1762
+ kthread_cancel_delayed_work_sync (& s -> poll_work );
1763
+
1727
1764
kthread_flush_worker (& s -> kworker );
1728
1765
kthread_stop (s -> kworker_task );
1729
1766
0 commit comments