devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacky Huang <ychuang570808@gmail.com>
To: Jiri Slaby <jirislaby@kernel.org>,
	robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
	lee@kernel.org, mturquette@baylibre.com, sboyd@kernel.org,
	p.zabel@pengutronix.de, gregkh@linuxfoundation.org,
	tmaimon77@gmail.com, catalin.marinas@arm.com, will@kernel.org
Cc: devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-serial@vger.kernel.org, arnd@arndb.de, soc@kernel.org,
	schung@nuvoton.com, mjchen@nuvoton.com,
	Jacky Huang <ychuang3@nuvoton.com>
Subject: Re: [PATCH v11 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support
Date: Tue, 30 May 2023 09:09:16 +0800	[thread overview]
Message-ID: <c9493f4d-8056-20a0-6ed2-161fbcc3d34e@gmail.com> (raw)
In-Reply-To: <aaef529f-69dc-8bec-0ae1-959a1ede87e0@gmail.com>

Dear Jiri,


On 2023/5/24 下午 04:34, Jacky Huang wrote:
> Dear Jiri,
>
> Thanks for your advice.
>
> On 2023/5/24 下午 03:42, Jiri Slaby wrote:
>> On 16. 05. 23, 9:52, Jacky Huang wrote:
>>> +static void ma35d1serial_config_port(struct uart_port *port, int 
>>> flags)
>>> +{
>>> +    /*
>>> +     * Driver core for serial ports forces a non-zero value for 
>>> port type.
>>> +     * Write an arbitrary value here to accommodate the serial core 
>>> driver,
>>> +     * as ID part of UAPI is redundant.
>>> +     */
>>> +    port->type = 1;
>>
>> So this 1 translates to PORT_8250. Why not to use it directly? Or 
>> something more saner like PORT_16550A?
>>
> It's not actually 8250 or 16550A.
> Can we add the following definition to 
> 'include/uapi/linux/serial_core.h' and use PORT_MA35 instead?
>
> #define PORT_MA35    124
>
>
>>> +}
>>> +
>>> +static int ma35d1serial_verify_port(struct uart_port *port, struct 
>>> serial_struct *ser)
>>> +{
>>> +    if (port->type != PORT_UNKNOWN && ser->type != 1)
>>> +        return -EINVAL;
>>> +
>>> +    return 0;
>>> +}
>> ...
>>> +static int __init ma35d1serial_console_setup(struct console *co, 
>>> char *options)
>>> +{
>>> +    struct device_node *np = ma35d1serial_uart_nodes[co->index];
>>> +    struct uart_ma35d1_port *p = &ma35d1serial_ports[co->index];
>>> +    u32 val32[4];
>>> +    struct uart_port *port;
>>> +    int baud = 115200;
>>> +    int bits = 8;
>>> +    int parity = 'n';
>>> +    int flow = 'n';
>>> +
>>> +    /*
>>> +     * Check whether an invalid uart number has been specified, and
>>
>> You dereferenced ma35d1serial_uart_nodes already. Doesn't 
>> console=ttyNVT1000 (or something like that) crash the system?
>>
>
> I will add the following check before np = 
> "ma35d1serial_uart_nodes[co->index]".
>
> if (co->index < 0 || co->index >= MA35_UART_NR)
>     return -EINVAL;
>
>
>>> +     * if so, search for the first available port that does have
>>> +     * console support.
>>
>> The code below doesn't match this comment.
>
> Yes, I will remove the above comment.
>
>>
>>> +     */
>>> +    if ((co->index < 0) || (co->index >= MA35_UART_NR)) {
>>> +        pr_debug("Console Port%x out of range\n", co->index);
>>> +        return -EINVAL;
>>> +    }
>>> +
>>> +    if (of_property_read_u32_array(np, "reg", val32, 4) != 0)
>>
>> Shouldn't that 4 be ARRAY_SIZE(val32) instead?
>>
>
> Will be fixed.
>
>>> +        return -EINVAL;
>>
>> One \n here please.
>>
>
> Okay, I will add it.
>
>>> +    p->port.iobase = val32[1];
>>> +    p->port.membase = ioremap(p->port.iobase, MA35_UART_REG_SIZE);
>>
>> What if this fails?
>>
>
> I will add a check for the return value.
>
>>> +    p->port.ops = &ma35d1serial_ops;
>>> +    p->port.line = 0;
>>> +    p->port.uartclk = MA35_UART_CONSOLE_CLK;
>>> +
>>> +    port = &ma35d1serial_ports[co->index].port;
>>
>> Isn't this:
>>   port = &p->port;
>> ?
>>
>> Either use port on all above lines or drop the "port" variable 
>> completely and use "p->port" below instead.
>>
>
> I will remove port variable and use p->port only.
>
>>> +
>>> +    if (options)
>>> +        uart_parse_options(options, &baud, &parity, &bits, &flow);
>>> +
>>> +    return uart_set_options(port, co, baud, parity, bits, flow);
>>> +}
>>> +
>>> +static struct console ma35d1serial_console = {
>>> +    .name    = "ttyNVT",
>>> +    .write   = ma35d1serial_console_write,
>>> +    .device  = uart_console_device,
>>> +    .setup   = ma35d1serial_console_setup,
>>> +    .flags   = CON_PRINTBUFFER | CON_ENABLED,
>>> +    .index   = -1,
>>> +    .data    = &ma35d1serial_reg,
>>
>> I don't see console->data used anywhere in the driver?
>>
>
> I will remove it.
>

I removed the " .data    = &ma35d1serial_reg", but kernel crashed in 
'drivers/tty/serial/serial_core.c'.

The variable 'p' of  uart_console_device() refer to a NULL, because 
co->data is NULL.
As a result, kernel crashed at 'p->tty_driver'.

struct tty_driver *uart_console_device(struct console *co, int *index)
{
     struct uart_driver *p = co->data;
     *index = co->index;
     return p->tty_driver;
}

We seem to be unable to remove it.
If there are no other considerations, I will keep it in the next version.

>>> +};
>> ...
>>> +static int ma35d1serial_probe(struct platform_device *pdev)
>>> +{
>>> +    struct resource *res_mem;
>>> +    struct uart_ma35d1_port *up;
>>> +    int ret = 0;
>>> +
>>> +    if (pdev->dev.of_node) {
>>> +        ret = of_alias_get_id(pdev->dev.of_node, "serial");
>>> +        if (ret < 0) {
>>> +            dev_err(&pdev->dev, "failed to get alias/pdev id, errno 
>>> %d\n", ret);
>>> +            return ret;
>>> +        }
>>> +    }
>>> +    up = &ma35d1serial_ports[ret];
>>> +    up->port.line = ret;
>>> +    res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>> +    if (!res_mem)
>>> +        return -ENODEV;
>>> +
>>> +    up->port.iobase = res_mem->start;
>>> +    up->port.membase = ioremap(up->port.iobase, MA35_UART_REG_SIZE);
>>
>> Check this too.
>>
>
> Okay, sure.
>
>>> +    up->port.ops = &ma35d1serial_ops;
>>> +
>>> +    spin_lock_init(&up->port.lock);
>>> +
>>> +    up->clk = of_clk_get(pdev->dev.of_node, 0);
>>> +    if (IS_ERR(up->clk)) {
>>> +        ret = PTR_ERR(up->clk);
>>> +        dev_err(&pdev->dev, "failed to get core clk: %d\n", ret);
>>> +        goto err_iounmap;
>>> +    }
>>> +
>>> +    ret = clk_prepare_enable(up->clk);
>>> +    if (ret)
>>> +        goto err_iounmap;
>>> +
>>> +    if (up->port.line != 0)
>>> +        up->port.uartclk = clk_get_rate(up->clk);
>>> +
>>> +    ret = platform_get_irq(pdev, 0);
>>> +    if (ret < 0)
>>> +        goto err_clk_disable;
>>> +
>>> +    up->port.irq = ret;
>>> +    up->port.dev = &pdev->dev;
>>> +    up->port.flags = UPF_BOOT_AUTOCONF;
>>> +
>>> +    platform_set_drvdata(pdev, up);
>>> +
>>> +    ret = uart_add_one_port(&ma35d1serial_reg, &up->port);
>>> +    if (ret < 0)
>>> +        goto err_free_irq;
>>> +
>>> +    return 0;
>>> +
>>> +err_free_irq:
>>> +    free_irq(up->port.irq, &up->port);
>>> +
>>> +err_clk_disable:
>>> +    clk_disable_unprepare(up->clk);
>>> +
>>> +err_iounmap:
>>> +    iounmap(up->port.membase);
>>> +    return ret;
>>> +}
>>
>> thanks,
>
> Best regards,
> Jacky Huang
>

Best regards,
Jacky Huang


  parent reply	other threads:[~2023-05-30  1:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16  7:52 [PATCH v11 00/10] Introduce Nuvoton ma35d1 SoC Jacky Huang
2023-05-16  7:52 ` [PATCH v11 01/10] arm64: Kconfig.platforms: Add config for Nuvoton MA35 platform Jacky Huang
2023-05-16  7:52 ` [PATCH v11 02/10] arm64: defconfig: Add support for Nuvoton MA35 family SoCs Jacky Huang
2023-05-16  7:52 ` [PATCH v11 03/10] dt-bindings: clock: nuvoton: add binding for ma35d1 clock controller Jacky Huang
2023-05-16  7:52 ` [PATCH v11 04/10] dt-bindings: reset: nuvoton: Document ma35d1 reset control Jacky Huang
2023-05-16  7:52 ` [PATCH v11 05/10] dt-bindings: arm: Add initial bindings for Nuvoton platform Jacky Huang
2023-05-16  7:52 ` [PATCH v11 06/10] dt-bindings: serial: Document ma35d1 uart controller Jacky Huang
2023-05-16  7:52 ` [PATCH v11 07/10] arm64: dts: nuvoton: Add initial ma35d1 device tree Jacky Huang
2023-05-16  7:52 ` [PATCH v11 08/10] clk: nuvoton: Add clock driver for ma35d1 clock controller Jacky Huang
2023-05-16  7:52 ` [PATCH v11 09/10] reset: Add Nuvoton ma35d1 reset driver support Jacky Huang
2023-05-16  7:52 ` [PATCH v11 10/10] tty: serial: Add Nuvoton ma35d1 serial " Jacky Huang
2023-05-24  7:42   ` Jiri Slaby
2023-05-24  8:34     ` Jacky Huang
2023-05-24  9:00       ` Arnd Bergmann
2023-05-25  5:48         ` Jiri Slaby
2023-05-30  1:09       ` Jacky Huang [this message]
2023-05-30  5:35         ` Jiri Slaby

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=c9493f4d-8056-20a0-6ed2-161fbcc3d34e@gmail.com \
    --to=ychuang570808@gmail.com \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mjchen@nuvoton.com \
    --cc=mturquette@baylibre.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=schung@nuvoton.com \
    --cc=soc@kernel.org \
    --cc=tmaimon77@gmail.com \
    --cc=will@kernel.org \
    --cc=ychuang3@nuvoton.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;
as well as URLs for NNTP newsgroup(s).