From: neil.armstrong@linaro.org
To: Dmitry Rokosov <ddrokosov@sberdevices.ru>,
gregkh@linuxfoundation.org, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
jbrunet@baylibre.com, jirislaby@kernel.org, khilman@baylibre.com,
martin.blumenstingl@googlemail.com
Cc: kelvin.zhang@amlogic.com, xianwei.zhao@amlogic.com,
kernel@sberdevices.ru, rockosov@gmail.com,
linux-amlogic@lists.infradead.org, linux-serial@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 3/7] tty: serial: meson: apply ttyS devname instead of ttyAML for new SoCs
Date: Thu, 6 Jul 2023 09:08:48 +0200 [thread overview]
Message-ID: <606ed182-14b8-4c8f-37d3-21971ec71f38@linaro.org> (raw)
In-Reply-To: <20230705181833.16137-4-ddrokosov@sberdevices.ru>
Hi,
On 05/07/2023 20:18, Dmitry Rokosov wrote:
> It is worth noting that the devname ttyS is a widely recognized tty name
> and is commonly used by many uart device drivers. Given the established
> usage and compatibility concerns, it may not be feasible to change the
> devname for older SoCs. However, for new definitions, it is acceptable
> and even recommended to use a new devname to help ensure clarity and
> avoid any potential conflicts on lower or upper software levels.
>
> For more information please refer to IRC discussion at [1].
>
> Links:
> [1]: https://libera.irclog.whitequark.org/linux-amlogic/2023-07-03
>
> Signed-off-by: Dmitry Rokosov <ddrokosov@sberdevices.ru>
> ---
> drivers/tty/serial/meson_uart.c | 82 ++++++++++++++++++++++-----------
> 1 file changed, 56 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c
> index dcf994a11a21..ad0748a10db7 100644
> --- a/drivers/tty/serial/meson_uart.c
> +++ b/drivers/tty/serial/meson_uart.c
> @@ -72,16 +72,22 @@
>
> #define AML_UART_PORT_NUM 12
> #define AML_UART_PORT_OFFSET 6
> -#define AML_UART_DEV_NAME "ttyAML"
>
> #define AML_UART_POLL_USEC 5
> #define AML_UART_TIMEOUT_USEC 10000
>
> -static struct uart_driver meson_uart_driver;
> +#define MESON_UART_DRIVER(_devname) meson_uart_driver_##_devname
> +
> +#define MESON_UART_DRIVER_DECLARE(_devname) \
> + static struct uart_driver MESON_UART_DRIVER(_devname)
> +
> +MESON_UART_DRIVER_DECLARE(ttyAML);
> +MESON_UART_DRIVER_DECLARE(ttyS);
Not sure those macros are useful:
MESON_UART_DRIVER_DECLARE(ttyAML)
vs
static struct uart_driver meson_uart_driver_ttyAML
I prefer the second...
>
> static struct uart_port *meson_ports[AML_UART_PORT_NUM];
>
> struct meson_uart_data {
> + struct uart_driver *uart_driver;
> bool has_xtal_div2;
> };
>
> @@ -611,15 +617,21 @@ static int meson_serial_console_setup(struct console *co, char *options)
> return uart_set_options(port, co, baud, parity, bits, flow);
> }
I think the uart_driver meson_uart_driver_ttyXXX should be declared here instead or..
>
> -static struct console meson_serial_console = {
> - .name = AML_UART_DEV_NAME,
> - .write = meson_serial_console_write,
> - .device = uart_console_device,
> - .setup = meson_serial_console_setup,
> - .flags = CON_PRINTBUFFER,
> - .index = -1,
> - .data = &meson_uart_driver,
> -};
> +#define MESON_SERIAL_CONSOLE(_devname) meson_serial_console_##_devname
> +
> +#define MESON_SERIAL_CONSOLE_DEFINE(_devname) \
> + static struct console MESON_SERIAL_CONSOLE(_devname) = { \
> + .name = __stringify(_devname), \
> + .write = meson_serial_console_write, \
> + .device = uart_console_device, \
> + .setup = meson_serial_console_setup, \
> + .flags = CON_PRINTBUFFER, \
> + .index = -1, \
> + .data = &MESON_UART_DRIVER(_devname), \
> + }
... you could even declare the meson_uart_driver_ttyXXX in this macro instead.
> +
> +MESON_SERIAL_CONSOLE_DEFINE(ttyAML);
> +MESON_SERIAL_CONSOLE_DEFINE(ttyS);
>
> static void meson_serial_early_console_write(struct console *co,
> const char *s,
> @@ -644,18 +656,22 @@ meson_serial_early_console_setup(struct earlycon_device *device, const char *opt
> OF_EARLYCON_DECLARE(meson, "amlogic,meson-ao-uart",
> meson_serial_early_console_setup);
>
> -#define MESON_SERIAL_CONSOLE (&meson_serial_console)
> +#define MESON_SERIAL_CONSOLE_PTR(_devname) (&MESON_SERIAL_CONSOLE(_devname))
> #else
> -#define MESON_SERIAL_CONSOLE NULL
> +#define MESON_SERIAL_CONSOLE_PTR(_devname) (NULL)
> #endif
>
> -static struct uart_driver meson_uart_driver = {
> - .owner = THIS_MODULE,
> - .driver_name = "meson_uart",
> - .dev_name = AML_UART_DEV_NAME,
> - .nr = AML_UART_PORT_NUM,
> - .cons = MESON_SERIAL_CONSOLE,
> -};
> +#define MESON_UART_DRIVER_DEFINE(_devname) \
> + static struct uart_driver MESON_UART_DRIVER(_devname) = { \
> + .owner = THIS_MODULE, \
> + .driver_name = "meson_uart", \
> + .dev_name = __stringify(_devname), \
> + .nr = AML_UART_PORT_NUM, \
> + .cons = MESON_SERIAL_CONSOLE_PTR(_devname), \
> + }
> +
> +MESON_UART_DRIVER_DEFINE(ttyAML);
> +MESON_UART_DRIVER_DEFINE(ttyS);
Those macros are fine, but drop the MESON_UART_DRIVER & MESON_SERIAL_CONSOLE macros and drop the _DEFINE in those macros.
>
> static int meson_uart_probe_clocks(struct platform_device *pdev,
> struct uart_port *port)
> @@ -681,8 +697,16 @@ static int meson_uart_probe_clocks(struct platform_device *pdev,
> return 0;
> }
>
> +static struct uart_driver *meson_uart_current(const struct meson_uart_data *pd)
> +{
> + return (pd && pd->uart_driver) ?
> + pd->uart_driver : &MESON_UART_DRIVER(ttyAML);
I'll definitely prefer if you use the real variable name everywhere and in the 2 following patches
> +}
> +
> static int meson_uart_probe(struct platform_device *pdev)
> {
> + const struct meson_uart_data *priv_data;
> + struct uart_driver *uart_driver;
> struct resource *res_mem;
> struct uart_port *port;
> u32 fifosize = 64; /* Default is 64, 128 for EE UART_0 */
> @@ -729,8 +753,12 @@ static int meson_uart_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> - if (!meson_uart_driver.state) {
> - ret = uart_register_driver(&meson_uart_driver);
> + priv_data = device_get_match_data(&pdev->dev);
> +
> + uart_driver = meson_uart_current(priv_data);
> +
> + if (!uart_driver->state) {
> + ret = uart_register_driver(uart_driver);
> if (ret)
> return dev_err_probe(&pdev->dev, ret,
> "can't register uart driver\n");
> @@ -748,7 +776,7 @@ static int meson_uart_probe(struct platform_device *pdev)
> port->x_char = 0;
> port->ops = &meson_uart_ops;
> port->fifosize = fifosize;
> - port->private_data = (void *)device_get_match_data(&pdev->dev);
> + port->private_data = (void *)priv_data;
>
> meson_ports[pdev->id] = port;
> platform_set_drvdata(pdev, port);
> @@ -759,7 +787,7 @@ static int meson_uart_probe(struct platform_device *pdev)
> meson_uart_release_port(port);
> }
>
> - ret = uart_add_one_port(&meson_uart_driver, port);
> + ret = uart_add_one_port(uart_driver, port);
> if (ret)
> meson_ports[pdev->id] = NULL;
>
> @@ -768,10 +796,12 @@ static int meson_uart_probe(struct platform_device *pdev)
>
> static int meson_uart_remove(struct platform_device *pdev)
> {
> + struct uart_driver *uart_driver;
> struct uart_port *port;
>
> port = platform_get_drvdata(pdev);
> - uart_remove_one_port(&meson_uart_driver, port);
> + uart_driver = meson_uart_current(port->private_data);
> + uart_remove_one_port(uart_driver, port);
> meson_ports[pdev->id] = NULL;
>
> for (int id = 0; id < AML_UART_PORT_NUM; id++)
> @@ -779,7 +809,7 @@ static int meson_uart_remove(struct platform_device *pdev)
> return 0;
>
> /* No more available uart ports, unregister uart driver */
> - uart_unregister_driver(&meson_uart_driver);
> + uart_unregister_driver(uart_driver);
>
> return 0;
> }
Anyway this looks much better :-)
Thanks,
Neil
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-07-06 7:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-05 18:18 [PATCH v2 0/7] tty: serial: meson: support ttyS devname Dmitry Rokosov
2023-07-05 18:18 ` [PATCH v2 1/7] tty: serial: meson: use dev_err_probe Dmitry Rokosov
2023-07-06 6:59 ` neil.armstrong
2023-07-05 18:18 ` [PATCH v2 2/7] tty: serial: meson: redesign the module to platform_driver Dmitry Rokosov
2023-07-06 6:59 ` neil.armstrong
2023-07-05 18:18 ` [PATCH v2 3/7] tty: serial: meson: apply ttyS devname instead of ttyAML for new SoCs Dmitry Rokosov
2023-07-06 7:08 ` neil.armstrong [this message]
2023-07-05 18:18 ` [PATCH v2 4/7] tty: serial: meson: introduce separate uart_data for S4 SoC family Dmitry Rokosov
2023-07-06 7:09 ` neil.armstrong
2023-07-05 18:18 ` [PATCH v2 5/7] tty: serial: meson: add independent uart_data for A1 " Dmitry Rokosov
2023-07-06 7:09 ` neil.armstrong
2023-07-05 18:18 ` [PATCH v2 6/7] dt-bindings: serial: amlogic,meson-uart: support Amlogic A1 Dmitry Rokosov
2023-07-05 21:10 ` Conor Dooley
2023-07-06 17:57 ` Rob Herring
2023-07-05 18:18 ` [PATCH v2 7/7] arm64: dts: meson: a1: change uart compatible string Dmitry Rokosov
2023-07-06 7:10 ` neil.armstrong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=606ed182-14b8-4c8f-37d3-21971ec71f38@linaro.org \
--to=neil.armstrong@linaro.org \
--cc=conor+dt@kernel.org \
--cc=ddrokosov@sberdevices.ru \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jbrunet@baylibre.com \
--cc=jirislaby@kernel.org \
--cc=kelvin.zhang@amlogic.com \
--cc=kernel@sberdevices.ru \
--cc=khilman@baylibre.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=robh+dt@kernel.org \
--cc=rockosov@gmail.com \
--cc=xianwei.zhao@amlogic.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox