2020-04-22 18:04:59

by Sean Wang

[permalink] [raw]
Subject: [PATCH v3] tty: serial: don't do termios for BTIF

From: Sean Wang <[email protected]>

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.

Fixes: 1c16ae65e250 ("serial: 8250: of: Add new port type for MediaTek BTIF controller on MT7622/23 SoC")
Cc: Steven Liu <[email protected]>
Suggested-by: Andy Shevchenko <[email protected]>
Signed-off-by: Sean Wang <[email protected]>
Signed-off-by: Ryder Lee <[email protected]>

--
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.
---
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 33ad9d6de532..234d8db470c0 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 0325f2e53b74..abc974b4113f 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",
@@ -2544,6 +2544,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


2020-04-22 18:10:34

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v3] tty: serial: don't do termios for BTIF

On Thu, Apr 23, 2020 at 02:02:08AM +0800, [email protected] wrote:
> From: Sean Wang <[email protected]>
>
> 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.

Why does it matter? If the connection isn't exported to userspace, who
would run those termios functions on the port?

thanks,

greg k-h

2020-04-22 19:22:59

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v3] tty: serial: don't do termios for BTIF

On Wed, Apr 22, 2020 at 9:05 PM <[email protected]> wrote:
>
> From: Sean Wang <[email protected]>
>
> 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.
>
> Fixes: 1c16ae65e250 ("serial: 8250: of: Add new port type for MediaTek BTIF controller on MT7622/23 SoC")
> Cc: Steven Liu <[email protected]>

> Suggested-by: Andy Shevchenko <[email protected]>

I didn't suggest this change. I only commented on the name of the macro.

> Signed-off-by: Sean Wang <[email protected]>
> Signed-off-by: Ryder Lee <[email protected]>
>
> --
> 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.
> ---
> 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 33ad9d6de532..234d8db470c0 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 0325f2e53b74..abc974b4113f 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",
> @@ -2544,6 +2544,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



--
With Best Regards,
Andy Shevchenko

2020-05-05 11:12:31

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v3] tty: serial: don't do termios for BTIF

On Wed, Apr 22, 2020 at 08:09:00PM +0200, Greg KH wrote:
> On Thu, Apr 23, 2020 at 02:02:08AM +0800, [email protected] wrote:
> > From: Sean Wang <[email protected]>
> >
> > 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.
>
> Why does it matter? If the connection isn't exported to userspace, who
> would run those termios functions on the port?

Dropping from my patch queues due to a lack of response, please address
this question when you resend this.

greg k-h

2020-06-17 03:53:15

by Sean Wang

[permalink] [raw]
Subject: Re: [PATCH v3] tty: serial: don't do termios for BTIF

From: Sean Wang <[email protected]>

>On Thu, Apr 23, 2020 at 02:02:08AM +0800, [email protected] wrote:
>> From: Sean Wang <[email protected]>
>>
>> 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.
>
>Why does it matter? If the connection isn't exported to userspace, who would run those termios functions on the port?

The bluetooth driver would use BTIF device as a serdev.

The termios function would be called in kernelspace from ttyport_open and then
to tty_set_termios defined in drivers/tty/serdev/serdev-ttyport.c.

>
>thanks,
>
>greg k-h

2020-06-17 04:00:37

by Sean Wang

[permalink] [raw]
Subject: Re: [PATCH v3] tty: serial: don't do termios for BTIF

From: Sean Wang <[email protected]>

>>
>> From: Sean Wang <[email protected]>
>>
>> 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.
>>
>> Fixes: 1c16ae65e250 ("serial: 8250: of: Add new port type for MediaTek
>> BTIF controller on MT7622/23 SoC")
>> Cc: Steven Liu <[email protected]>
>
>> Suggested-by: Andy Shevchenko <[email protected]>
>
>I didn't suggest this change. I only commented on the name of the macro.

my fault. i will remove the tag from next version.

>
>> Signed-off-by: Sean Wang <[email protected]>
>> Signed-off-by: Ryder Lee <[email protected]>
>>
>> --