linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] tty: serial: don't do termios for BTIF
@ 2020-06-19 19:59 sean.wang
  2020-06-27 14:12 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: sean.wang @ 2020-06-19 19:59 UTC (permalink / raw)
  To: robh+dt, gregkh, jslaby, andriy.shevchenko, robert.jarzmik, arnd,
	p.zabel, joel, david, jan.kiszka, heikki.krogerus, hpeter,
	vigneshr, matthias.bgg, tthayer
  Cc: devicetree, Ryder Lee, Steven Liu, Sean Wang, linux-kernel,
	linux-mediatek, linux-serial, linux-arm-kernel

From: Sean Wang <sean.wang@mediatek.com>

Bluetooth Interface (BTIF) is designed dedicatedly for MediaTek SOC with
BT in order to be instead of the UART interface between BT module and Host
CPU, and not exported to user space to access.

As the UART design, BTIF will be an APB slave and can transmit or receive
data by MCU access, but doesn't provide termios function like baudrate and
flow control setup.

Even LCR on offset 0xC that is just a FAKELCR
a. If FAKELCR[7] is equaled to 1, RBR(0x00), THR(0x00), IER(0x04)
   will not be readable/writable.

b. If FAKELCR is equaled to 0xBF, RBR(0x00), THR(0x00), IER(0x04),
   IIR(0x08), and LSR(0x14) will not be readable/writable.

So adding a new capability 'UART_CAP_NTIO' for the unusual unsupported
case.

The bluetooth driver would use BTIF device as a serdev. So the termios
still function would be called in kernelspace from ttyport_open in
drivers/tty/serdev/serdev-ttyprt.c.

Fixes: 1c16ae65e250 ("serial: 8250: of: Add new port type for MediaTek BTIF controller on MT7622/23 SoC")
Cc: Steven Liu <steven.liu@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>

--
v1->v2:
no change on termios->c_cflag and refine commit message

v2->v3:
change the naming from NMOD to NTIO as TIO is a well established prefix
for termios IOCTLs.

v3->v4:
1. remove appropriate tag
2. add the explanation why the termios is required even when the connection
   isn't exported to userspace.
---
 drivers/tty/serial/8250/8250.h      | 1 +
 drivers/tty/serial/8250/8250_port.c | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
index 52bb21205bb6..0d9d3bfe48af 100644
--- a/drivers/tty/serial/8250/8250.h
+++ b/drivers/tty/serial/8250/8250.h
@@ -82,6 +82,7 @@ struct serial8250_config {
 #define UART_CAP_MINI	(1 << 17)	/* Mini UART on BCM283X family lacks:
 					 * STOP PARITY EPAR SPAR WLEN5 WLEN6
 					 */
+#define UART_CAP_NTIO	(1 << 18)	/* UART doesn't do termios */
 
 #define UART_BUG_QUOT	(1 << 0)	/* UART has buggy quot LSB */
 #define UART_BUG_TXEN	(1 << 1)	/* UART has buggy TX IIR status */
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 1632f7d25acc..af54db877efe 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -286,7 +286,7 @@ static const struct serial8250_config uart_config[] = {
 		.tx_loadsz	= 16,
 		.fcr		= UART_FCR_ENABLE_FIFO |
 				  UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
-		.flags		= UART_CAP_FIFO,
+		.flags		= UART_CAP_FIFO | UART_CAP_NTIO,
 	},
 	[PORT_NPCM] = {
 		.name		= "Nuvoton 16550",
@@ -2640,6 +2640,9 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 	unsigned long flags;
 	unsigned int baud, quot, frac = 0;
 
+	if (up->capabilities & UART_CAP_NTIO)
+		return;
+
 	if (up->capabilities & UART_CAP_MINI) {
 		termios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CMSPAR);
 		if ((termios->c_cflag & CSIZE) == CS5 ||
-- 
2.25.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* Re: [PATCH v4] tty: serial: don't do termios for BTIF
  2020-06-19 19:59 [PATCH v4] tty: serial: don't do termios for BTIF sean.wang
@ 2020-06-27 14:12 ` Greg KH
  2020-06-29  8:29   ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2020-06-27 14:12 UTC (permalink / raw)
  To: sean.wang
  Cc: devicetree, heikki.krogerus, david, arnd, linux-serial,
	Steven Liu, jan.kiszka, hpeter, linux-kernel, tthayer, Ryder Lee,
	robh+dt, linux-mediatek, joel, p.zabel, jslaby, matthias.bgg,
	andriy.shevchenko, robert.jarzmik, linux-arm-kernel, vigneshr

On Sat, Jun 20, 2020 at 03:59:14AM +0800, sean.wang@mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> Bluetooth Interface (BTIF) is designed dedicatedly for MediaTek SOC with
> BT in order to be instead of the UART interface between BT module and Host
> CPU, and not exported to user space to access.
> 
> As the UART design, BTIF will be an APB slave and can transmit or receive
> data by MCU access, but doesn't provide termios function like baudrate and
> flow control setup.
> 
> Even LCR on offset 0xC that is just a FAKELCR
> a. If FAKELCR[7] is equaled to 1, RBR(0x00), THR(0x00), IER(0x04)
>    will not be readable/writable.
> 
> b. If FAKELCR is equaled to 0xBF, RBR(0x00), THR(0x00), IER(0x04),
>    IIR(0x08), and LSR(0x14) will not be readable/writable.
> 
> So adding a new capability 'UART_CAP_NTIO' for the unusual unsupported
> case.
> 
> The bluetooth driver would use BTIF device as a serdev. So the termios
> still function would be called in kernelspace from ttyport_open in
> drivers/tty/serdev/serdev-ttyprt.c.
> 
> Fixes: 1c16ae65e250 ("serial: 8250: of: Add new port type for MediaTek BTIF controller on MT7622/23 SoC")
> Cc: Steven Liu <steven.liu@mediatek.com>
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
> 
> --
> v1->v2:
> no change on termios->c_cflag and refine commit message
> 
> v2->v3:
> change the naming from NMOD to NTIO as TIO is a well established prefix
> for termios IOCTLs.
> 
> v3->v4:
> 1. remove appropriate tag
> 2. add the explanation why the termios is required even when the connection
>    isn't exported to userspace.
> ---
>  drivers/tty/serial/8250/8250.h      | 1 +
>  drivers/tty/serial/8250/8250_port.c | 5 ++++-
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
> index 52bb21205bb6..0d9d3bfe48af 100644
> --- a/drivers/tty/serial/8250/8250.h
> +++ b/drivers/tty/serial/8250/8250.h
> @@ -82,6 +82,7 @@ struct serial8250_config {
>  #define UART_CAP_MINI	(1 << 17)	/* Mini UART on BCM283X family lacks:
>  					 * STOP PARITY EPAR SPAR WLEN5 WLEN6
>  					 */
> +#define UART_CAP_NTIO	(1 << 18)	/* UART doesn't do termios */

Naming is hard.  I will never remember what "NTIO" is, how about we make
it explicit:
	define UART_CAP_IGNORE_TERMIOS

And the _CAP_ name is getting out of hand, this isn't a "capability",
it's a "quirk for this port" but that's a battle to worry about later...

thanks,

greg k-h

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* Re: [PATCH v4] tty: serial: don't do termios for BTIF
  2020-06-27 14:12 ` Greg KH
@ 2020-06-29  8:29   ` Andy Shevchenko
  2020-06-29  8:40     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2020-06-29  8:29 UTC (permalink / raw)
  To: Greg KH
  Cc: devicetree, heikki.krogerus, david, arnd, linux-serial,
	Steven Liu, jan.kiszka, sean.wang, hpeter, linux-kernel, tthayer,
	Ryder Lee, robh+dt, linux-mediatek, joel, p.zabel, jslaby,
	matthias.bgg, robert.jarzmik, linux-arm-kernel, vigneshr

On Sat, Jun 27, 2020 at 04:12:22PM +0200, Greg KH wrote:
> On Sat, Jun 20, 2020 at 03:59:14AM +0800, sean.wang@mediatek.com wrote:
> > From: Sean Wang <sean.wang@mediatek.com>
> > 
> > Bluetooth Interface (BTIF) is designed dedicatedly for MediaTek SOC with
> > BT in order to be instead of the UART interface between BT module and Host
> > CPU, and not exported to user space to access.
> > 
> > As the UART design, BTIF will be an APB slave and can transmit or receive
> > data by MCU access, but doesn't provide termios function like baudrate and
> > flow control setup.
> > 
> > Even LCR on offset 0xC that is just a FAKELCR
> > a. If FAKELCR[7] is equaled to 1, RBR(0x00), THR(0x00), IER(0x04)
> >    will not be readable/writable.
> > 
> > b. If FAKELCR is equaled to 0xBF, RBR(0x00), THR(0x00), IER(0x04),
> >    IIR(0x08), and LSR(0x14) will not be readable/writable.
> > 
> > So adding a new capability 'UART_CAP_NTIO' for the unusual unsupported
> > case.
> > 
> > The bluetooth driver would use BTIF device as a serdev. So the termios
> > still function would be called in kernelspace from ttyport_open in
> > drivers/tty/serdev/serdev-ttyprt.c.

> > +#define UART_CAP_NTIO	(1 << 18)	/* UART doesn't do termios */
> 
> Naming is hard.  I will never remember what "NTIO" is, how about we make
> it explicit:
> 	define UART_CAP_IGNORE_TERMIOS
> 
> And the _CAP_ name is getting out of hand, this isn't a "capability",
> it's a "quirk for this port" but that's a battle to worry about later...

For quirks we have a separate field in struct uart_port. Perhaps that can be used?

-- 
With Best Regards,
Andy Shevchenko



_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* Re: [PATCH v4] tty: serial: don't do termios for BTIF
  2020-06-29  8:29   ` Andy Shevchenko
@ 2020-06-29  8:40     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2020-06-29  8:40 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: devicetree, heikki.krogerus, david, arnd, linux-serial,
	Steven Liu, jan.kiszka, sean.wang, hpeter, linux-kernel, tthayer,
	Ryder Lee, robh+dt, linux-mediatek, joel, p.zabel, jslaby,
	matthias.bgg, robert.jarzmik, linux-arm-kernel, vigneshr

On Mon, Jun 29, 2020 at 11:29:27AM +0300, Andy Shevchenko wrote:
> On Sat, Jun 27, 2020 at 04:12:22PM +0200, Greg KH wrote:
> > On Sat, Jun 20, 2020 at 03:59:14AM +0800, sean.wang@mediatek.com wrote:
> > > From: Sean Wang <sean.wang@mediatek.com>
> > > 
> > > Bluetooth Interface (BTIF) is designed dedicatedly for MediaTek SOC with
> > > BT in order to be instead of the UART interface between BT module and Host
> > > CPU, and not exported to user space to access.
> > > 
> > > As the UART design, BTIF will be an APB slave and can transmit or receive
> > > data by MCU access, but doesn't provide termios function like baudrate and
> > > flow control setup.
> > > 
> > > Even LCR on offset 0xC that is just a FAKELCR
> > > a. If FAKELCR[7] is equaled to 1, RBR(0x00), THR(0x00), IER(0x04)
> > >    will not be readable/writable.
> > > 
> > > b. If FAKELCR is equaled to 0xBF, RBR(0x00), THR(0x00), IER(0x04),
> > >    IIR(0x08), and LSR(0x14) will not be readable/writable.
> > > 
> > > So adding a new capability 'UART_CAP_NTIO' for the unusual unsupported
> > > case.
> > > 
> > > The bluetooth driver would use BTIF device as a serdev. So the termios
> > > still function would be called in kernelspace from ttyport_open in
> > > drivers/tty/serdev/serdev-ttyprt.c.
> 
> > > +#define UART_CAP_NTIO	(1 << 18)	/* UART doesn't do termios */
> > 
> > Naming is hard.  I will never remember what "NTIO" is, how about we make
> > it explicit:
> > 	define UART_CAP_IGNORE_TERMIOS
> > 
> > And the _CAP_ name is getting out of hand, this isn't a "capability",
> > it's a "quirk for this port" but that's a battle to worry about later...
> 
> For quirks we have a separate field in struct uart_port. Perhaps that can be used?

That would be much nicer, if possible.

thanks,

greg k-h

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

end of thread, other threads:[~2020-06-29  8:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-19 19:59 [PATCH v4] tty: serial: don't do termios for BTIF sean.wang
2020-06-27 14:12 ` Greg KH
2020-06-29  8:29   ` Andy Shevchenko
2020-06-29  8:40     ` Greg KH

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