mbox series

[0/3] serial: Separate RT288x/Au1xxx code into own file

Message ID 20221230114603.16946-1-ilpo.jarvinen@linux.intel.com
Headers show
Series serial: Separate RT288x/Au1xxx code into own file | expand

Message

Ilpo Järvinen Dec. 30, 2022, 11:46 a.m. UTC
A non-trivial amount of RT288x/Au1xxx code is encapsulated into
ifdeffery in 8250_port / 8250_early and some if/switch UPIO_AU blocks.
Create a separate file from them and do a few additional cleanups.

I kept the Kconfig entry as bool because the code has somewhat tricky
dependency chain (mips arch code and 8250_of driver). It would be nice
to make it tristate but I don't know how blocking some invalid =m + =y
combinations would be best addressed. It should probably be best done
on top of this series independent of the split itself anyway.

UPIO_AU could now be removed because it's same as UPIO_MEM for the
remaining code path but I'm unsure if that's allowed (is the port
iotype part of stable ABI or not)?

Ilpo Järvinen (3):
  serial: 8250: RT288x/Au1xxx code away from core
  serial: 8250_rt288x: Name non-standard divisor latch reg
  serial: 8250_rt288x: Remove unnecessary UART_REG_UNMAPPED

 arch/mips/alchemy/common/platform.c   |  10 +-
 drivers/tty/serial/8250/8250_core.c   |   4 +
 drivers/tty/serial/8250/8250_early.c  |  21 ----
 drivers/tty/serial/8250/8250_of.c     |   4 +-
 drivers/tty/serial/8250/8250_port.c   |  78 ---------------
 drivers/tty/serial/8250/8250_rt288x.c | 135 ++++++++++++++++++++++++++
 drivers/tty/serial/8250/Makefile      |   1 +
 include/linux/serial_8250.h           |  14 ++-
 8 files changed, 163 insertions(+), 104 deletions(-)
 create mode 100644 drivers/tty/serial/8250/8250_rt288x.c

Comments

Philippe Mathieu-Daudé Dec. 30, 2022, 1:14 p.m. UTC | #1
Hi Ilpo,

On 30/12/22 12:46, Ilpo Järvinen wrote:
> As unmapped registers are at the tail of the array, the ARRAY_SIZE()
> condition will catch them just fine. No need to define special
> value for them.

True but fragile example...

> Also, let the compiler to calculate the size of the array instead of
> providing it manually.
> 
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
>   drivers/tty/serial/8250/8250_rt288x.c | 16 ++++------------
>   1 file changed, 4 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_rt288x.c b/drivers/tty/serial/8250/8250_rt288x.c
> index 3015afb99722..da8be9a802c1 100644
> --- a/drivers/tty/serial/8250/8250_rt288x.c
> +++ b/drivers/tty/serial/8250/8250_rt288x.c
> @@ -14,10 +14,8 @@
>   
>   #define RT288X_DL	0x28
>   
> -#define UART_REG_UNMAPPED	-1


> -static const s8 au_io_out_map[8] = {
> +static const s8 au_io_out_map[] = {
>   	[UART_TX]	= 1,
>   	[UART_IER]	= 2,
>   	[UART_FCR]	= 4,
>   	[UART_LCR]	= 5,
>   	[UART_MCR]	= 6,
> -	[UART_LSR]	= UART_REG_UNMAPPED,
> -	[UART_MSR]	= UART_REG_UNMAPPED,
> -	[UART_SCR]	= UART_REG_UNMAPPED,

If someone were to re-add an unlikely single

         [UART_SCR] = 42,

The array will also contain these hidden entries:

         [UART_LSR] = 0,
         [UART_MSR] = 0,

And these 2 registers end mapped.

>   };

Trying to 'optimize' array size when the array is index-initialized
can be bug-prone.

>   static unsigned int au_serial_in(struct uart_port *p, int offset)
> @@ -44,8 +38,7 @@ static unsigned int au_serial_in(struct uart_port *p, int offset)
>   	if (offset >= ARRAY_SIZE(au_io_in_map))
>   		return UINT_MAX;
>   	offset = au_io_in_map[offset];
> -	if (offset == UART_REG_UNMAPPED)
> -		return UINT_MAX;
> +
>   	return __raw_readl(p->membase + (offset << p->regshift));
>   }
Regards,

Phil.