2019-09-19 05:37:10

by Lanqing Liu

[permalink] [raw]
Subject: [PATCH v2] serial: sprd: Add polling IO support

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 <[email protected]>
---
Change from v1:
- Add poll_init() support.
---
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


2019-09-19 05:40:16

by Lanqing Liu

[permalink] [raw]
Subject: Re: [PATCH v2] serial: sprd: Add polling IO support

Baolin Wang <[email protected]> 于2019年9月19日周四 上午11:21写道:
>
> Hi,
>
> On Thu, 19 Sep 2019 at 11:10, Lanqing Liu <[email protected]> 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 <[email protected]>
> > ---
> > 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 <[email protected]>
> Tested-by: Baolin Wang <[email protected]>
>
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

2019-09-19 05:40:34

by Baolin Wang

[permalink] [raw]
Subject: Re: [PATCH v2] serial: sprd: Add polling IO support

Hi,

On Thu, 19 Sep 2019 at 11:10, Lanqing Liu <[email protected]> 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 <[email protected]>
> ---
> 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 <[email protected]>
Tested-by: Baolin Wang <[email protected]>

> ---
> 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