FAILED: patch "[PATCH] serial: sc16is7xx: implement gpio get_direction() callback" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x af071d9e07e57cfff239e8d09d2f3b05ebc9c667
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072914-sandbar-very-7f7d@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From af071d9e07e57cfff239e8d09d2f3b05ebc9c667 Mon Sep 17 00:00:00 2001
From: Hugo Villeneuve <[email protected]>
Date: Thu, 16 Jul 2026 17:08:09 -0400
Subject: [PATCH] serial: sc16is7xx: implement gpio get_direction() callback
It's strongly recommended for GPIO drivers to always implement the .get_direction() callback - even when the direction is tracked in software. The GPIO core emits a warning when the callback is missing and a user reads the direction of a line, e.g. via /sys/kernel/debug/gpio.
drivers/tty/serial/sc16is7xx.c +12 -0
@@ -1273,6 +1273,17 @@ static int sc16is7xx_gpio_set(struct gpio_chip *chip, unsigned int offset,return 0 ; } +static int sc16is7xx_gpio_get_direction (struct gpio_chip *chip,unsigned int offset) +{ +struct sc16is7xx_port *s =gpiochip_get_data (chip); +struct uart_port *port = &s->p[0 ].port; +unsigned int val; + + val =sc16is7xx_port_read (port,SC16IS7XX_IODIR_REG ); + +return val &BIT (offset) ?GPIO_LINE_DIRECTION_OUT :GPIO_LINE_DIRECTION_IN ; +} +static int sc16is7xx_gpio_direction_input (struct gpio_chip *chip,unsigned offset) {
@@ -1350,6 +1361,7 @@ static int sc16is7xx_setup_gpio_chip(struct sc16is7xx_port *s) s->gpio.parent = dev; s->gpio.label =dev_name (dev); s->gpio.init_valid_mask = sc16is7xx_gpio_init_valid_mask; + s->gpio.get_direction = sc16is7xx_gpio_get_direction; s->gpio.direction_input = sc16is7xx_gpio_direction_input; s->gpio.get = sc16is7xx_gpio_get; s->gpio.direction_output = sc16is7xx_gpio_direction_output;
Sasha Levin
maintainerPATCH 1/5 sc16is7xx: Properly resume TX after stop
From: Tomasz Moń <[email protected]>
[ Upstream commit cc4c1d05eb10c3ad4c6315f1897bc56b1e7429aa ]
sc16is7xx_stop_tx() clears THRI bit and thus disables THRI interrupt. This makes it possible for transmission to cease indefinitely when more than 64 characters are being sent.
The sc16is7xx_handle_tx() call executed by sc16is7xx_tx_proc() can send up to FIFO length (64) characters. If more characters are written to the output buffer, then the THRI interrupt is needed.
Solve the issue by enabling THRI interrupt in sc16is7xx_tx_proc().
Stable-dep-of: af071d9e07e5 ("serial: sc16is7xx: implement gpio get_direction() callback")
--- drivers/tty/serial/sc16is7xx.c | 47 +++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-)
drivers/tty/serial/sc16is7xx.c +41 -6
@@ -307,7 +307,8 @@ struct sc16is7xx_devtype {struct sc16is7xx_one_config {unsigned int flags; -u8 ier_clear; +u8 ier_mask; +u8 ier_val; };struct sc16is7xx_one {
@@ -341,6 +342,9 @@ static struct uart_driver sc16is7xx_uart = { .nr = SC16IS7XX_MAX_DEVS, }; +static void sc16is7xx_ier_set (struct uart_port *port,u8 bit); +static void sc16is7xx_stop_tx (struct uart_port *port); +#define to_sc16is7xx_port (p,e) ((container_of((p), struct sc16is7xx_port, e)))#define to_sc16is7xx_one (p,e) ((container_of((p), struct sc16is7xx_one, e)))
@@ -650,6 +654,7 @@ static void sc16is7xx_handle_tx(struct uart_port *port)struct sc16is7xx_port *s =dev_get_drvdata (port->dev);struct circ_buf *xmit = &port->state->xmit;unsigned int txlen, to_send, i; +unsigned long flags;if (unlikely (port->x_char)) {sc16is7xx_port_write (port,SC16IS7XX_THR_REG , port->x_char);
@@ -658,8 +663,12 @@ static void sc16is7xx_handle_tx(struct uart_port *port)return ; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) +if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { +spin_lock_irqsave (&port->lock, flags); +sc16is7xx_stop_tx (port); +spin_unlock_irqrestore (&port->lock, flags);return ; + }/* Get length of data pending in circular buffer */ to_send =uart_circ_chars_pending (xmit);
@@ -686,8 +695,13 @@ static void sc16is7xx_handle_tx(struct uart_port *port)sc16is7xx_fifo_write (port, to_send); } +spin_lock_irqsave (&port->lock, flags);if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS )uart_write_wakeup (port); + +if (uart_circ_empty (xmit)) +sc16is7xx_stop_tx (port); +spin_unlock_irqrestore (&port->lock, flags); }static bool sc16is7xx_port_irq (struct sc16is7xx_port *s,int portno)
@@ -762,6 +776,7 @@ static void sc16is7xx_tx_proc(struct kthread_work *ws) {struct uart_port *port = &(to_sc16is7xx_one (ws, tx_work)->port);struct sc16is7xx_port *s =dev_get_drvdata (port->dev); +unsigned long flags;if ((port->rs485.flags &SER_RS485_ENABLED ) && (port->rs485.delay_rts_before_send >0 ))
@@ -770,6 +785,10 @@ static void sc16is7xx_tx_proc(struct kthread_work *ws)mutex_lock (&s->efr_lock);sc16is7xx_handle_tx (port);mutex_unlock (&s->efr_lock); + +spin_lock_irqsave (&port->lock, flags); +sc16is7xx_ier_set (port,SC16IS7XX_IER_THRI_BIT ); +spin_unlock_irqrestore (&port->lock, flags); }static void sc16is7xx_reconf_rs485 (struct uart_port *port)
@@ -819,7 +838,7 @@ static void sc16is7xx_reg_proc(struct kthread_work *ws) }if (config.flags &SC16IS7XX_RECONF_IER )sc16is7xx_port_update (&one->port,SC16IS7XX_IER_REG , - config.ier_clear,0 ); + config.ier_mask, config.ier_val);if (config.flags &SC16IS7XX_RECONF_RS485 )sc16is7xx_reconf_rs485 (&one->port);
@@ -830,8 +849,24 @@ static void sc16is7xx_ier_clear(struct uart_port *port, u8 bit)struct sc16is7xx_port *s =dev_get_drvdata (port->dev);struct sc16is7xx_one *one =to_sc16is7xx_one (port, port); +lockdep_assert_held_once (&port->lock); + + one->config.flags |=SC16IS7XX_RECONF_IER ; + one->config.ier_mask |= bit; + one->config.ier_val &= ~bit; +kthread_queue_work (&s->kworker, &one->reg_work); +} + +static void sc16is7xx_ier_set (struct uart_port *port,u8 bit) +{ +struct sc16is7xx_port *s =dev_get_drvdata (port->dev); +struct sc16is7xx_one *one =to_sc16is7xx_one (port, port); + +lockdep_assert_held_once (&port->lock); + one->config.flags |=SC16IS7XX_RECONF_IER ; - one->config.ier_clear |= bit; + one->config.ier_mask |= bit; + one->config.ier_val |= bit;kthread_queue_work (&s->kworker, &one->reg_work); }
@@ -1059,8 +1094,8 @@ static int sc16is7xx_startup(struct uart_port *port)SC16IS7XX_EFCR_TXDISABLE_BIT , 0); -/* Enable RX, TX interrupts */ - val =SC16IS7XX_IER_RDI_BIT |SC16IS7XX_IER_THRI_BIT ; +/* Enable RX interrupt */ + val =SC16IS7XX_IER_RDI_BIT ;sc16is7xx_port_write (port,SC16IS7XX_IER_REG , val);return 0 ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/5 serial: sc16is7xx: Fill in rs485_supported
From: Ilpo Järvinen <[email protected]>
[ Upstream commit 267913ecf73745ca3e8fc8282671b0b4f24df5fe ]
Add information on supported serial_rs485 features.
This driver does not support delay_rts_after_send but the pre-existing behavior is to return -EINVAL if delay_rts_after_send is non-zero. In contrast, other drivers that do not support delay_rts_after_send either zero delay_rts_after_send or do not care (leave the inaccurate value). As changing this would cause userspace visible impact, the change is not attempted here. But perhaps it should be still tried (maybe nobody finds that kind of API oddity significant)?
Stable-dep-of: af071d9e07e5 ("serial: sc16is7xx: implement gpio get_direction() callback")
--- drivers/tty/serial/sc16is7xx.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/tty/serial/sc16is7xx.c +7 -0
@@ -1239,6 +1239,12 @@ static int sc16is7xx_gpio_direction_output(struct gpio_chip *chip, }#endif +static const struct serial_rs485 sc16is7xx_rs485_supported = { + .flags =SER_RS485_ENABLED |SER_RS485_RTS_AFTER_SEND , + .delay_rts_before_send =1 , + .delay_rts_after_send =1 ,/* Not supported but keep returning -EINVAL */ +}; +static int sc16is7xx_probe (struct device *dev,const struct sc16is7xx_devtype *devtype,struct regmap *regmap,int irq)
@@ -1326,6 +1332,7 @@ static int sc16is7xx_probe(struct device *dev, s->p[i].port.iotype =UPIO_PORT ; s->p[i].port.uartclk = freq; s->p[i].port.rs485_config = sc16is7xx_config_rs485; + s->p[i].port.rs485_supported = &sc16is7xx_rs485_supported; s->p[i].port.ops = &sc16is7xx_ops; s->p[i].port.line =sc16is7xx_alloc_line ();if (s->p[i].port.line >=SC16IS7XX_MAX_DEVS ) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/5 serial: sc16is7xx: remove obsolete out_thread label
In reply to Sasha LevinFrom: Hugo Villeneuve <[email protected]>
[ Upstream commit dabc54a45711fe77674a6c0348231e00e66bd567 ]
Commit c8f71b49ee4d ("serial: sc16is7xx: setup GPIO controller later in probe") moved GPIO setup code later in probe function. Doing so also required to move ports cleanup code (out_ports label) after the GPIO cleanup code.
After these moves, the out_thread label becomes misplaced and makes part of the cleanup code illogical.
This patch remove the now obsolete out_thread label and make GPIO setup code jump to out_ports label if it fails.
Stable-dep-of: af071d9e07e5 ("serial: sc16is7xx: implement gpio get_direction() callback")
--- drivers/tty/serial/sc16is7xx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/tty/serial/sc16is7xx.c +1 -3
@@ -1397,7 +1397,7 @@ static int sc16is7xx_probe(struct device *dev, s->gpio.can_sleep =1 ; ret =gpiochip_add_data (&s->gpio, s);if (ret) - goto out_thread; + goto out_ports; }#endif
@@ -1423,8 +1423,6 @@ static int sc16is7xx_probe(struct device *dev,#ifdef CONFIG_GPIOLIB if (devtype->nr_gpio)gpiochip_remove (&s->gpio); - -out_thread:#endif out_ports:
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/5 serial: sc16is7xx: fix regression with GPIO configuration
In reply to Sasha LevinFrom: Hugo Villeneuve <[email protected]>
[ Upstream commit 0499942928341d572a42199580433c2b0725211e ]
Commit 679875d1d880 ("sc16is7xx: Separate GPIOs from modem control lines") and commit 21144bab4f11 ("sc16is7xx: Handle modem status lines") changed the function of the GPIOs pins to act as modem control lines without any possibility of selecting GPIO function.
As a consequence, applications that depends on GPIO lines configured by default as GPIO pins no longer work as expected.
Also, the change to select modem control lines function was done only for channel A of dual UART variants (752/762). This was not documented in the log message.
Allow to specify GPIO or modem control line function in the device tree, and for each of the ports (A or B).
Do so by using the new device-tree property named "nxp,modem-control-line-ports" (property added in separate patch).
When registering GPIO chip controller, mask-out GPIO pins declared as modem control lines according to this new DT property.
Stable-dep-of: af071d9e07e5 ("serial: sc16is7xx: implement gpio get_direction() callback")
--- drivers/tty/serial/sc16is7xx.c | 124 ++++++++++++++++++++++++++++----- 1 file changed, 105 insertions(+), 19 deletions(-)
drivers/tty/serial/sc16is7xx.c +105 -19
@@ -237,7 +237,8 @@/* IOControl register bits (Only 750/760) */ #define SC16IS7XX_IOCONTROL_LATCH_BIT (1 << 0)/* Enable input latching */ -#define SC16IS7XX_IOCONTROL_MODEM_BIT (1 << 1)/* Enable GPIO[7:4] as modem pins */ +#define SC16IS7XX_IOCONTROL_MODEM_A_BIT (1 << 1)/* Enable GPIO[7:4] as modem A pins */ +#define SC16IS7XX_IOCONTROL_MODEM_B_BIT (1 << 2)/* Enable GPIO[3:0] as modem B pins */ #define SC16IS7XX_IOCONTROL_SRESET_BIT (1 << 3)/* Software Reset */ /* EFCR register bits */
@@ -294,6 +295,7 @@/* Misc definitions */ #define SC16IS7XX_FIFO_SIZE (64)#define SC16IS7XX_REG_SHIFT 2 +#define SC16IS7XX_GPIOS_PER_BANK 4struct sc16is7xx_devtype {char name[10 ];
@@ -326,7 +328,9 @@ struct sc16is7xx_port {struct clk *clk;#ifdef CONFIG_GPIOLIB struct gpio_chip gpio; +unsigned long gpio_valid_mask;#endif +u8 mctrl_mask;unsigned char buf[SC16IS7XX_FIFO_SIZE ];struct kthread_worker kworker;struct task_struct *kworker_task;
@@ -1237,8 +1241,98 @@ static int sc16is7xx_gpio_direction_output(struct gpio_chip *chip,return 0 ; } + +static int sc16is7xx_gpio_init_valid_mask (struct gpio_chip *chip, +unsigned long *valid_mask, +unsigned int ngpios) +{ +struct sc16is7xx_port *s =gpiochip_get_data (chip); + + *valid_mask = s->gpio_valid_mask; + +return 0 ; +} + +static int sc16is7xx_setup_gpio_chip (struct sc16is7xx_port *s) +{ +struct device *dev = s->p[0 ].port.dev; + +if (!s->devtype->nr_gpio) +return 0 ; + +switch (s->mctrl_mask) { +case 0 : + s->gpio_valid_mask =GENMASK (7 ,0 ); +break ; +case SC16IS7XX_IOCONTROL_MODEM_A_BIT : + s->gpio_valid_mask =GENMASK (3 ,0 ); +break ; +case SC16IS7XX_IOCONTROL_MODEM_B_BIT : + s->gpio_valid_mask =GENMASK (7 ,4 ); +break ; +default : +break ; + } + +if (s->gpio_valid_mask ==0 ) +return 0 ; + + s->gpio.owner =THIS_MODULE ; + s->gpio.parent = dev; + s->gpio.label =dev_name (dev); + s->gpio.init_valid_mask = sc16is7xx_gpio_init_valid_mask; + s->gpio.direction_input = sc16is7xx_gpio_direction_input; + s->gpio.get = sc16is7xx_gpio_get; + s->gpio.direction_output = sc16is7xx_gpio_direction_output; + s->gpio.set = sc16is7xx_gpio_set; + s->gpio.base =-1 ; + s->gpio.ngpio = s->devtype->nr_gpio; + s->gpio.can_sleep =1 ; + +return gpiochip_add_data (&s->gpio, s); +}#endif +/* +* Configure ports designated to operate as modem control lines. +*/ +static int sc16is7xx_setup_mctrl_ports (struct sc16is7xx_port *s) +{ +int i; +int ret; +int count; +u32 mctrl_port[2 ]; +struct device *dev = s->p[0 ].port.dev; + + count =device_property_count_u32 (dev,"nxp,modem-control-line-ports" ); +if (count <0 || count >ARRAY_SIZE (mctrl_port)) +return 0 ; + + ret =device_property_read_u32_array (dev,"nxp,modem-control-line-ports" , + mctrl_port, count); +if (ret) +return ret; + + s->mctrl_mask =0 ; + +for (i =0 ; i < count; i++) { +/* Use GPIO lines as modem control lines */ +if (mctrl_port[i] ==0 ) + s->mctrl_mask |=SC16IS7XX_IOCONTROL_MODEM_A_BIT ; +else if (mctrl_port[i] ==1 ) + s->mctrl_mask |=SC16IS7XX_IOCONTROL_MODEM_B_BIT ; + } + +if (s->mctrl_mask) +regmap_update_bits ( + s->regmap, +SC16IS7XX_IOCONTROL_REG <<SC16IS7XX_REG_SHIFT , +SC16IS7XX_IOCONTROL_MODEM_A_BIT | +SC16IS7XX_IOCONTROL_MODEM_B_BIT , s->mctrl_mask); + +return 0 ; +} +static const struct serial_rs485 sc16is7xx_rs485_supported = { .flags =SER_RS485_ENABLED |SER_RS485_RTS_AFTER_SEND , .delay_rts_before_send =1 ,
@@ -1346,6 +1440,7 @@ static int sc16is7xx_probe(struct device *dev,sc16is7xx_port_write (&s->p[i].port,SC16IS7XX_EFCR_REG ,SC16IS7XX_EFCR_RXDISABLE_BIT |SC16IS7XX_EFCR_TXDISABLE_BIT ); +/* Initialize kthread work structs */ kthread_init_work (&s->p[i].tx_work, sc16is7xx_tx_proc);kthread_init_work (&s->p[i].reg_work, sc16is7xx_reg_proc);
@@ -1382,23 +1477,14 @@ static int sc16is7xx_probe(struct device *dev, s->p[u].irda_mode = true; } + ret =sc16is7xx_setup_mctrl_ports (s); +if (ret) + goto out_ports; +#ifdef CONFIG_GPIOLIB -if (devtype->nr_gpio) { -/* Setup GPIO cotroller */ - s->gpio.owner =THIS_MODULE ; - s->gpio.parent = dev; - s->gpio.label =dev_name (dev); - s->gpio.direction_input = sc16is7xx_gpio_direction_input; - s->gpio.get = sc16is7xx_gpio_get; - s->gpio.direction_output = sc16is7xx_gpio_direction_output; - s->gpio.set = sc16is7xx_gpio_set; - s->gpio.base =-1 ; - s->gpio.ngpio = devtype->nr_gpio; - s->gpio.can_sleep =1 ; - ret =gpiochip_add_data (&s->gpio, s); -if (ret) - goto out_ports; - } + ret =sc16is7xx_setup_gpio_chip (s); +if (ret) + goto out_ports;#endif /*
@@ -1421,7 +1507,7 @@ static int sc16is7xx_probe(struct device *dev,return 0 ;#ifdef CONFIG_GPIOLIB -if (devtype->nr_gpio) +if (s->gpio_valid_mask)gpiochip_remove (&s->gpio);#endif
@@ -1446,7 +1532,7 @@ static int sc16is7xx_remove(struct device *dev)int i;#ifdef CONFIG_GPIOLIB -if (s->devtype->nr_gpio) +if (s->gpio_valid_mask)gpiochip_remove (&s->gpio);#endif
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 5/5 serial: sc16is7xx: implement gpio get_direction() callback
In reply to Sasha LevinFrom: Hugo Villeneuve <[email protected]>
[ Upstream commit af071d9e07e57cfff239e8d09d2f3b05ebc9c667 ]
It's strongly recommended for GPIO drivers to always implement the .get_direction() callback - even when the direction is tracked in software. The GPIO core emits a warning when the callback is missing and a user reads the direction of a line, e.g. via /sys/kernel/debug/gpio.
--- drivers/tty/serial/sc16is7xx.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/tty/serial/sc16is7xx.c +12 -0
@@ -1204,6 +1204,17 @@ static void sc16is7xx_gpio_set(struct gpio_chip *chip, unsigned offset, int val) val ? BIT(offset) : 0); } +static int sc16is7xx_gpio_get_direction (struct gpio_chip *chip,unsigned int offset) +{ +struct sc16is7xx_port *s =gpiochip_get_data (chip); +struct uart_port *port = &s->p[0 ].port; +unsigned int val; + + val =sc16is7xx_port_read (port,SC16IS7XX_IODIR_REG ); + +return val &BIT (offset) ?GPIO_LINE_DIRECTION_OUT :GPIO_LINE_DIRECTION_IN ; +} +static int sc16is7xx_gpio_direction_input (struct gpio_chip *chip,unsigned offset) {
@@ -1281,6 +1292,7 @@ static int sc16is7xx_setup_gpio_chip(struct sc16is7xx_port *s) s->gpio.parent = dev; s->gpio.label =dev_name (dev); s->gpio.init_valid_mask = sc16is7xx_gpio_init_valid_mask; + s->gpio.get_direction = sc16is7xx_gpio_get_direction; s->gpio.direction_input = sc16is7xx_gpio_direction_input; s->gpio.get = sc16is7xx_gpio_get; s->gpio.direction_output = sc16is7xx_gpio_direction_output;
Signature · 1 line
2.53.0