diff mbox series

tty: serial: samsung_tty: support more than 4 uart ports

Message ID 20220627071512.18180-1-chanho61.park@samsung.com (mailing list archive)
State New
Headers show
Series tty: serial: samsung_tty: support more than 4 uart ports | expand

Commit Message

Chanho Park June 27, 2022, 7:15 a.m. UTC
Regarding Exynos Auto v9 SoC, it supports uarts up to 12. However, the
maximum number of the ports has been derived from
CONFIG_SERIAL_SAMSUNG_UARTS and tightly coupled with the config for
previous Samsung SoCs such as s3c24xx and s3c64xx. To overcome this
limitation, this changes the usage of the definition to UART_NR which is
widely used from other serial drivers. This also defines the value to 12
only for ARM64 SoCs to not affect the change to previous arm32 SoCs.
Instead of enumerating all the ports as predefined arrays, this
introduces s3c24xx_serial_init_port_default that is initializing the
structure as default value. Regarding the ports which are greater than 4
will be initialized as default value and the fifo size will be retrieved
from the DT property.

Signed-off-by: Chanho Park <chanho61.park@samsung.com>
---
 drivers/tty/serial/samsung_tty.c | 34 ++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

Comments

Krzysztof Kozlowski June 27, 2022, 10:33 a.m. UTC | #1
On 27/06/2022 09:15, Chanho Park wrote:
> Regarding Exynos Auto v9 SoC, it supports uarts up to 12. However, the
> maximum number of the ports has been derived from
> CONFIG_SERIAL_SAMSUNG_UARTS and tightly coupled with the config for
> previous Samsung SoCs such as s3c24xx and s3c64xx. To overcome this
> limitation, this changes the usage of the definition to UART_NR which is
> widely used from other serial drivers. This also defines the value to 12
> only for ARM64 SoCs to not affect the change to previous arm32 SoCs.
> Instead of enumerating all the ports as predefined arrays, this
> introduces s3c24xx_serial_init_port_default that is initializing the
> structure as default value. 
> Regarding the ports which are greater than 4
> will be initialized as default value and the fifo size will be retrieved
> from the DT property.

You need to explain why you are doing this.

It's confusing to initialize some statically and some dynamically.

Best regards,
Krzysztof
Greg KH June 27, 2022, 11:52 a.m. UTC | #2
On Mon, Jun 27, 2022 at 12:33:51PM +0200, Krzysztof Kozlowski wrote:
> On 27/06/2022 09:15, Chanho Park wrote:
> > Regarding Exynos Auto v9 SoC, it supports uarts up to 12. However, the
> > maximum number of the ports has been derived from
> > CONFIG_SERIAL_SAMSUNG_UARTS and tightly coupled with the config for
> > previous Samsung SoCs such as s3c24xx and s3c64xx. To overcome this
> > limitation, this changes the usage of the definition to UART_NR which is
> > widely used from other serial drivers. This also defines the value to 12
> > only for ARM64 SoCs to not affect the change to previous arm32 SoCs.
> > Instead of enumerating all the ports as predefined arrays, this
> > introduces s3c24xx_serial_init_port_default that is initializing the
> > structure as default value. 
> > Regarding the ports which are greater than 4
> > will be initialized as default value and the fifo size will be retrieved
> > from the DT property.
> 
> You need to explain why you are doing this.
> 
> It's confusing to initialize some statically and some dynamically.

I agree, why not just make them all dynamic?

thanks,

greg k-h
Chanho Park June 28, 2022, 1:16 p.m. UTC | #3
> Subject: Re: [PATCH] tty: serial: samsung_tty: support more than 4 uart
> ports
> 
> On Mon, Jun 27, 2022 at 12:33:51PM +0200, Krzysztof Kozlowski wrote:
> > On 27/06/2022 09:15, Chanho Park wrote:
> > > Regarding Exynos Auto v9 SoC, it supports uarts up to 12. However,
> > > the maximum number of the ports has been derived from
> > > CONFIG_SERIAL_SAMSUNG_UARTS and tightly coupled with the config for
> > > previous Samsung SoCs such as s3c24xx and s3c64xx. To overcome this
> > > limitation, this changes the usage of the definition to UART_NR
> > > which is widely used from other serial drivers. This also defines
> > > the value to 12 only for ARM64 SoCs to not affect the change to
> previous arm32 SoCs.
> > > Instead of enumerating all the ports as predefined arrays, this
> > > introduces s3c24xx_serial_init_port_default that is initializing the
> > > structure as default value.
> > > Regarding the ports which are greater than 4 will be initialized as
> > > default value and the fifo size will be retrieved from the DT
> > > property.
> >
> > You need to explain why you are doing this.
> >
> > It's confusing to initialize some statically and some dynamically.
> 
> I agree, why not just make them all dynamic?

I thought it was the easiest way for me to expand the number of ports
without many changes :)
I'm looking around all other drivers how they initialize the ports.
I couldn't find any drivers who initializes the port dynamically. I think
they need to assign .nr of struct uart driver so they don't need to allocate
the ports dynamically.

static struct uart_driver s3c24xx_uart_drv = {
	.nr             = UART_NR,

I'll try to convert the initialization dynamically but I'm not convinced
whether it can be possible.

Best Regards,
Chanho Park
diff mbox series

Patch

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index d7d035cd95c0..679789bf856d 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -48,6 +48,12 @@ 
 #define S3C24XX_SERIAL_MAJOR	204
 #define S3C24XX_SERIAL_MINOR	64
 
+#ifdef CONFIG_ARM64
+#define UART_NR			12
+#else
+#define UART_NR			CONFIG_SERIAL_SAMSUNG_UARTS
+#endif
+
 #define S3C24XX_TX_PIO			1
 #define S3C24XX_TX_DMA			2
 #define S3C24XX_RX_PIO			1
@@ -87,7 +93,7 @@  struct s3c24xx_uart_info {
 struct s3c24xx_serial_drv_data {
 	const struct s3c24xx_uart_info	info;
 	const struct s3c2410_uartcfg	def_cfg;
-	const unsigned int		fifosize[CONFIG_SERIAL_SAMSUNG_UARTS];
+	const unsigned int		fifosize[UART_NR];
 };
 
 struct s3c24xx_uart_dma {
@@ -1815,7 +1821,7 @@  static const struct uart_ops apple_s5l_serial_ops = {
 static struct uart_driver s3c24xx_uart_drv = {
 	.owner		= THIS_MODULE,
 	.driver_name	= "s3c2410_serial",
-	.nr		= CONFIG_SERIAL_SAMSUNG_UARTS,
+	.nr		= UART_NR,
 	.cons		= S3C24XX_SERIAL_CONSOLE,
 	.dev_name	= S3C24XX_SERIAL_NAME,
 	.major		= S3C24XX_SERIAL_MAJOR,
@@ -1825,7 +1831,7 @@  static struct uart_driver s3c24xx_uart_drv = {
 #define __PORT_LOCK_UNLOCKED(i) \
 	__SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[i].port.lock)
 static struct s3c24xx_uart_port
-s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = {
+s3c24xx_serial_ports[UART_NR] = {
 	[0] = {
 		.port = {
 			.lock		= __PORT_LOCK_UNLOCKED(0),
@@ -1848,7 +1854,7 @@  s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = {
 			.line		= 1,
 		}
 	},
-#if CONFIG_SERIAL_SAMSUNG_UARTS > 2
+#if UART_NR > 2
 	[2] = {
 		.port = {
 			.lock		= __PORT_LOCK_UNLOCKED(2),
@@ -1861,7 +1867,7 @@  s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = {
 		}
 	},
 #endif
-#if CONFIG_SERIAL_SAMSUNG_UARTS > 3
+#if UART_NR > 3
 	[3] = {
 		.port = {
 			.lock		= __PORT_LOCK_UNLOCKED(3),
@@ -1877,6 +1883,19 @@  s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = {
 };
 #undef __PORT_LOCK_UNLOCKED
 
+static void s3c24xx_serial_init_port_default(int index) {
+	struct uart_port *port = &s3c24xx_serial_ports[index].port;
+
+	spin_lock_init(&port->lock);
+
+	port->iotype = UPIO_MEM;
+	port->uartclk = 0;
+	port->fifosize = 16;
+	port->ops = &s3c24xx_serial_ops;
+	port->flags = UPF_BOOT_AUTOCONF;
+	port->line = index;
+}
+
 /* s3c24xx_serial_resetport
  *
  * reset the fifos and other the settings.
@@ -2191,6 +2210,9 @@  static int s3c24xx_serial_probe(struct platform_device *pdev)
 	}
 	ourport = &s3c24xx_serial_ports[index];
 
+	if (ourport->port.line != index)
+		s3c24xx_serial_init_port_default(index);
+
 	ourport->drv_data = s3c24xx_get_driver_data(pdev);
 	if (!ourport->drv_data) {
 		dev_err(&pdev->dev, "could not find driver data\n");
@@ -2589,7 +2611,7 @@  s3c24xx_serial_console_setup(struct console *co, char *options)
 
 	/* is this a valid port */
 
-	if (co->index == -1 || co->index >= CONFIG_SERIAL_SAMSUNG_UARTS)
+	if (co->index == -1 || co->index >= UART_NR)
 		co->index = 0;
 
 	port = &s3c24xx_serial_ports[co->index].port;