linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: sprd: Add polling IO support
@ 2019-09-18  8:15 Lanqing Liu
  2019-09-18 12:10 ` Baolin Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Lanqing Liu @ 2019-09-18  8:15 UTC (permalink / raw)
  To: gregkh, jslaby
  Cc: baolin.wang, lanqing.liu, liuhhome, linux-serial, linux-kernel,
	orsonzhai, zhang.lyra

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 <liuhhome@gmail.com>
---
 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
+
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: sprd: Add polling IO support
  2019-09-18  8:15 [PATCH] serial: sprd: Add polling IO support Lanqing Liu
@ 2019-09-18 12:10 ` Baolin Wang
  2019-09-19  2:14   ` hhome liu
  0 siblings, 1 reply; 3+ messages in thread
From: Baolin Wang @ 2019-09-18 12:10 UTC (permalink / raw)
  To: Lanqing Liu
  Cc: Greg KH, Jiri Slaby, lanqing.liu, linux-serial, LKML, Orson Zhai,
	Chunyan Zhang

Hi Lanqing,

On Wed, 18 Sep 2019 at 16:16, Lanqing Liu <liuhhome@gmail.com> 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 <liuhhome@gmail.com>
> ---
>  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.

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: sprd: Add polling IO support
  2019-09-18 12:10 ` Baolin Wang
@ 2019-09-19  2:14   ` hhome liu
  0 siblings, 0 replies; 3+ messages in thread
From: hhome liu @ 2019-09-19  2:14 UTC (permalink / raw)
  To: Baolin Wang
  Cc: Greg KH, Jiri Slaby, 刘岚清 (Lanqing Liu),
	linux-serial, LKML, Orson Zhai, Chunyan Zhang

Baolin Wang <baolin.wang@linaro.org> 于2019年9月18日周三 下午8:10写道:
>
> Hi Lanqing,
>
> On Wed, 18 Sep 2019 at 16:16, Lanqing Liu <liuhhome@gmail.com> 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 <liuhhome@gmail.com>
> > ---
> >  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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-09-19  2:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-18  8:15 [PATCH] serial: sprd: Add polling IO support Lanqing Liu
2019-09-18 12:10 ` Baolin Wang
2019-09-19  2:14   ` hhome liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).