Re: [PATCH v2] serial: sprd: Add polling IO support
Baolin Wang 于2019年9月19日周四 上午11:21写道: > > Hi, > > On Thu, 19 Sep 2019 at 11:10, Lanqing Liu wrote: > > > > In order to access the UART without the interrupts, the kernel uses > > the basic polling methods for IO with the device. With these methods > > implemented, it is now possible to enable kgdb during early boot over > > serial. > > > > Signed-off-by: Lanqing Liu > > --- > > Change from v1: > > - Add poll_init() support. > > Looks good to me and the KGDB can work well on my board, so feel free > to add my tags: > Reviewed-by: Baolin Wang > Tested-by: Baolin Wang > ok, thanks > > --- > > drivers/tty/serial/sprd_serial.c | 33 + > > 1 file changed, 33 insertions(+) > > > > diff --git a/drivers/tty/serial/sprd_serial.c > > b/drivers/tty/serial/sprd_serial.c > > index 73d71a4..d833160 100644 > > --- a/drivers/tty/serial/sprd_serial.c > > +++ b/drivers/tty/serial/sprd_serial.c > > @@ -911,6 +911,34 @@ static void sprd_pm(struct uart_port *port, unsigned > > int state, > > } > > } > > > > +#ifdef CONFIG_CONSOLE_POLL > > +static int sprd_poll_init(struct uart_port *port) > > +{ > > + if (port->state->pm_state != UART_PM_STATE_ON) { > > + sprd_pm(port, UART_PM_STATE_ON, 0); > > + port->state->pm_state = UART_PM_STATE_ON; > > + } > > + > > + return 0; > > +} > > + > > +static int sprd_poll_get_char(struct uart_port *port) > > +{ > > + while (!(serial_in(port, SPRD_STS1) & SPRD_RX_FIFO_CNT_MASK)) > > + cpu_relax(); > > + > > + return serial_in(port, SPRD_RXD); > > +} > > + > > +static void sprd_poll_put_char(struct uart_port *port, unsigned char ch) > > +{ > > + while (serial_in(port, SPRD_STS1) & SPRD_TX_FIFO_CNT_MASK) > > + cpu_relax(); > > + > > + serial_out(port, SPRD_TXD, ch); > > +} > > +#endif > > + > > static const struct uart_ops serial_sprd_ops = { > > .tx_empty = sprd_tx_empty, > > .get_mctrl = sprd_get_mctrl, > > @@ -928,6 +956,11 @@ static void sprd_pm(struct uart_port *port, unsigned > > int state, > > .config_port = sprd_config_port, > > .verify_port = sprd_verify_port, > > .pm = sprd_pm, > > +#ifdef CONFIG_CONSOLE_POLL > > + .poll_init = sprd_poll_init, > > + .poll_get_char = sprd_poll_get_char, > > + .poll_put_char = sprd_poll_put_char, > > +#endif > > }; > > > > #ifdef CONFIG_SERIAL_SPRD_CONSOLE > > -- > > 1.9.1 > > > > > -- > Baolin Wang > Best Regards
Re: [PATCH] serial: sprd: Add polling IO support
Baolin Wang 于2019年9月18日周三 下午8:10写道: > > Hi Lanqing, > > On Wed, 18 Sep 2019 at 16:16, Lanqing Liu wrote: > > > > In order to access the UART without the interrupts, the kernel uses > > the basic polling methods for IO with the device. With these methods > > implemented, it is now possible to enable kgdb during early boot over > > serial. > > > > Signed-off-by: Lanqing Liu > > --- > > drivers/tty/serial/sprd_serial.c | 22 ++ > > 1 file changed, 22 insertions(+) > > > > diff --git a/drivers/tty/serial/sprd_serial.c > > b/drivers/tty/serial/sprd_serial.c > > index 73d71a4..579ab41 100644 > > --- a/drivers/tty/serial/sprd_serial.c > > +++ b/drivers/tty/serial/sprd_serial.c > > @@ -911,6 +911,24 @@ static void sprd_pm(struct uart_port *port, unsigned > > int state, > > } > > } > > > > +#ifdef CONFIG_CONSOLE_POLL > > +static int sprd_poll_get_char(struct uart_port *port) > > +{ > > + while (!(serial_in(port, SPRD_STS1) & SPRD_RX_FIFO_CNT_MASK)) > > + cpu_relax(); > > + > > + return serial_in(port, SPRD_RXD); > > +} > > + > > +static void sprd_poll_put_char(struct uart_port *port, unsigned char ch) > > +{ > > + while (serial_in(port, SPRD_STS1) & SPRD_TX_FIFO_CNT_MASK) > > + cpu_relax(); > > + > > + serial_out(port, SPRD_TXD, ch); > > +} > > +#endif > > When I tested your patch, I found only one case can work if the port > used by KGDB is same with the port selected as console, which means > this port will be powered on all the time. We had implemented the > power management for the UART ports, so I think you should enable the > clock for the port used by KGDB in poll_init(), then other ports can > be used by KGDB. > Yes, agree with you. I will add poll_init() support. Thanks for your comments. > > + > > static const struct uart_ops serial_sprd_ops = { > > .tx_empty = sprd_tx_empty, > > .get_mctrl = sprd_get_mctrl, > > @@ -928,6 +946,10 @@ static void sprd_pm(struct uart_port *port, unsigned > > int state, > > .config_port = sprd_config_port, > > .verify_port = sprd_verify_port, > > .pm = sprd_pm, > > +#ifdef CONFIG_CONSOLE_POLL > > + .poll_get_char = sprd_poll_get_char, > > + .poll_put_char = sprd_poll_put_char, > > +#endif > > }; > > > > #ifdef CONFIG_SERIAL_SPRD_CONSOLE > > -- > > 1.9.1 > > > > > -- > Baolin Wang > Best Regards
Re: [PATCH] tty: serial_core: Fix the incorrect configuration of baud rate and data length at the console serial port resume
Johan Hovold 于2019年5月14日周二 下午3:35写道: > > On Thu, May 09, 2019 at 01:42:39PM +0800, Lanqing Liu wrote: > > When userspace opens a serial port for console, uart_port_startup() > > is called. This function assigns the uport->cons->cflag value to > > TTY->termios.c_cflag, then it is cleared to 0. When the user space > > closes this serial port, the TTY structure will be released, and at > > this time uport->cons->cflag has also been cleared. > > > > On the Spreadtrum platform, in some special scenarios, like charging mode, > > userspace needs to close the console, which means the uport->cons->cflag > > has also been cleared. But printing logs is still needed in the kernel. So > > when system enters suspend and resume, the console needs to be configure > > the baud rate and data length of the serial port according to its own cflag > > when resuming the console port. At this time, the cflag is 0, which will > > cause serial port to produce configuration errors that do not meet user > > expectations. > > This is actually yet another regression due to 761ed4a94582 ("tty: > serial_core: convert uart_close to use tty_port_close") which > incidentally removed the call to uart_shutdown() where the cflag was > being saved precisely to avoid the problem you're describing: > > ae84db9661ca ("serial: core: Preserve termios c_cflag for console > resume") Yes, agree with you. > > Judging from a quick look it seems the xmit buf, which is released in > that function may now be leaking too. We haven't found this issue before, but we can try to reproduce it on our platform. > > > To fix this, assigning the TTY->termios.c_cflag value to uport->cons->cflag > > before the userspace closes this console serial port. It will ensure that > > the correct cflag value can be gotten when the console serial port was > > resumed. > > Not sure this is the right fix, but I don't have time to look at this > right now. OK. Thanks for your comments.