From: "Hammer Hsieh 謝宏孟" <hammer.hsieh@sunplus.com>
To: Philipp Zabel <p.zabel@pengutronix.de>,
Hammer Hsieh <hammerh0314@gmail.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"robh+dt@kernel.org" <robh+dt@kernel.org>,
"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"jirislaby@kernel.org" <jirislaby@kernel.org>
Cc: "Tony Huang 黃懷厚" <tony.huang@sunplus.com>,
"Wells Lu 呂芳騰" <wells.lu@sunplus.com>
Subject: RE: [PATCH v2 2/2] serial:sunplus-uart:Add Sunplus SoC UART Driver
Date: Thu, 11 Nov 2021 09:45:41 +0000 [thread overview]
Message-ID: <2e6d1c1649a047109455da62f4ddecf1@sphcmbx01.sunplus.com.tw> (raw)
In-Reply-To: <59e1e68131b37b7c22109d79acad75a6e63a890c.camel@pengutronix.de>
> -----Original Message-----
> From: Philipp Zabel <p.zabel@pengutronix.de>
> Sent: Wednesday, November 10, 2021 5:50 PM
> To: Hammer Hsieh <hammerh0314@gmail.com>; gregkh@linuxfoundation.org;
> robh+dt@kernel.org; linux-serial@vger.kernel.org; devicetree@vger.kernel.org;
> linux-kernel@vger.kernel.org; jirislaby@kernel.org
> Cc: Tony Huang 黃懷厚 <tony.huang@sunplus.com>; Wells Lu 呂芳騰
> <wells.lu@sunplus.com>; Hammer Hsieh 謝宏孟
> <hammer.hsieh@sunplus.com>
> Subject: Re: [PATCH v2 2/2] serial:sunplus-uart:Add Sunplus SoC UART Driver
>
> Hi,
>
> On Wed, 2021-11-10 at 15:51 +0800, Hammer Hsieh wrote:
> [...]
> > +struct sunplus_uart_port {
> > + char name[16];
> > + struct uart_port uport;
> > + struct sunplus_dma_info *uartdma_rx;
> > + struct sunplus_dma_info *uartdma_tx;
> > + struct clk *clk;
> > + struct reset_control *rstc;
> > + unsigned int pllsys_rate;
> > + struct gpio_desc *rts_gpio;
> > + struct hrtimer rts_check_tx_empty;
> > + struct hrtimer rts_delay_before_send;
> > + struct hrtimer rts_delay_after_send; }; struct sunplus_uart_port
> > +sunplus_uart_ports[UART_NR];
>
> Does this have to be a global array? I would expect these to be allocated in the
> probe function, one at a time.
>
With console, it uses global array.
Such as:
/drivers/tty/serial/ar933x_uart.c
#ifdef CONFIG_SERIAL_AR933X_CONSOLE
ar933x_uart_port * ar933x_console_port[ ];
With normal use, it should probe once at a time.
I will think about how to modify it.
> [...]
> > +static int sunplus_uart_probe(struct platform_device *pdev) {
> > + struct resource *res_mem;
> > + struct uart_port *port;
> > + struct clk *clk, *pllsys;
> > + unsigned int pllsys_rate;
> > + int ret, irq;
> > + int idx_offset, idx;
> > + int idx_which_uart;
> > + char peri_name[16];
> > +
> > + if (pdev->dev.of_node) {
> > + pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
> > + if (pdev->id < 0)
> > + pdev->id = of_alias_get_id(pdev->dev.of_node, "uart");
> > + }
> > +
> > + idx_offset = -1;
> > +
> > + if (IS_UARTDMARX_ID(pdev->id))
> > + idx_offset = 0;
> > + else if (IS_UARTDMATX_ID(pdev->id))
> > + idx_offset = UART_DMARX_NR;
> > +
> > + /* init txdma or rxdma */
> > + if (idx_offset >= 0) {
> > + clk = devm_clk_get(&pdev->dev, NULL);
>
> Should this be requested by name? Looking at the binding, this could be
> UADMA or HWUA?
>
Yes, it is better requested by name.
But , if request by name , I can't probe both dma_tx and dma_rx with one line.
I will think about how to modify it.
> > + if (IS_ERR(clk))
> > + return PTR_ERR(clk);
> > +
> > + ret = clk_prepare_enable(clk);
> > + if (ret)
> > + return ret;
>
> I suggest to move this down after all required resources are available.
> Otherwise you'll have to either disable the clock in the error paths, or you are
> left with a running clock if anything below fails.
>
OK, I will modify it.
> > + if (idx_offset == 0)
> > + idx = idx_offset + pdev->id - ID_BASE_DMARX;
> > + else
> > + idx = idx_offset + pdev->id - ID_BASE_DMATX;
> > +
> > + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > + if (!res_mem)
> > + return -ENODEV;
> > +
> > + sprintf(peri_name, "PERI%d", (idx & 0x01));
> > +
> > + clk = devm_clk_get(&pdev->dev, peri_name);
> > + if (IS_ERR(clk))
> > + return PTR_ERR(clk);
> > +
> > + ret = clk_prepare_enable(clk);
>
> Same as above.
OK, I will modify it.
>
> > + if (ret)
> > + return ret;
> > +
> > + sunplus_uartdma[idx].addr_phy =
> > + (unsigned long)(res_mem->start);
> > + sunplus_uartdma[idx].membase =
> > + devm_ioremap_resource(&pdev->dev, res_mem);
> > +
> > + if (IS_ERR(sunplus_uartdma[idx].membase))
> > + return PTR_ERR(sunplus_uartdma[idx].membase);
> > +
> > + if (IS_UARTDMARX_ID(pdev->id)) {
> > + irq = platform_get_irq(pdev, 0);
> > + if (irq < 0)
> > + return -ENODEV;
> > +
> > + sunplus_uartdma[idx].irq = irq;
> > + } else {
> > + res_mem = platform_get_resource(pdev, IORESOURCE_MEM,
> 1);
> > + if (!res_mem)
> > + return -ENODEV;
> > +
> > + sunplus_uartdma[idx].gdma_membase =
> > + devm_ioremap_resource(&pdev->dev, res_mem);
> > +
> > + if (IS_ERR(sunplus_uartdma[idx].gdma_membase))
> > + return -EINVAL;
> > + }
> > +
> > + if (of_property_read_u32(pdev->dev.of_node, "which-uart",
> &idx_which_uart) != 0) {
> > + dev_err(&pdev->dev, "\"which-uart\" is not assigned.");
> > + return -EINVAL;
> > + }
> > +
> > + if (idx_which_uart >= UART_NR) {
> > + dev_err(&pdev->dev, "\"which-uart\" is not valid.");
> > + return -EINVAL;
> > + }
> > +
> > + sunplus_uartdma[idx].which_uart = idx_which_uart;
> > +
> > + return 0;
> > + } else if (pdev->id < 0 || pdev->id >= UART_NR)
> > + return -EINVAL;
> > +
> > + /* init uart */
> > + port = &sunplus_uart_ports[pdev->id].uport;
> > + if (port->membase)
> > + return -EBUSY;
> > +
> > + memset(port, 0, sizeof(*port));
> > +
> > + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > + if (!res_mem)
> > + return -ENODEV;
> > +
> > + port->dev = &pdev->dev;
> > + port->mapbase = res_mem->start;
> > +
> > + port->membase = devm_ioremap_resource(&pdev->dev, res_mem);
> > + if (IS_ERR(port->membase))
> > + return PTR_ERR(port->membase);
> > +
> > + irq = platform_get_irq(pdev, 0);
> > + if (irq < 0)
> > + return -ENODEV;
> > +
> > + uart_get_rs485_mode(port);
> > + sunplus_uart_ports[pdev->id].rts_gpio =
> > + devm_gpiod_get(&pdev->dev, "rts", GPIOD_OUT_LOW);
> > + port->rs485_config = sunplus_uart_config_rs485;
> > + sunplus_uart_ports[pdev->id].rts_check_tx_empty.function = NULL;
> > + sunplus_uart_ports[pdev->id].rts_delay_before_send.function = NULL;
> > + sunplus_uart_ports[pdev->id].rts_delay_after_send.function = NULL;
> > + if (port->rs485.flags & SER_RS485_ENABLED)
> > + sunplus_uart_rs485_on(port);
> > +
> > + sunplus_uart_ports[pdev->id].clk = devm_clk_get(&pdev->dev, NULL);
>
> Here the same nameless clock as in the loop above is requested again.
> Should this be UADMA or HWUA?
>
No, here should be UART clk, each uart didn't use "clock-names" , that's why we use NULL.
In dts UART only use clocks=<&clkc UA0> or <&clkc UA1> or <&clkc UA2>.
We did not use "clock-names".
uart_probe( ) , first init dma , then init uart.
> > + if (IS_ERR(sunplus_uart_ports[pdev->id].clk))
> > + return PTR_ERR(sunplus_uart_ports[pdev->id].clk);
> > +
> > + ret = clk_prepare_enable(sunplus_uart_ports[pdev->id].clk);
> > + if (ret)
> > + return ret;
>
> Same comment as above. Better to request the reset control before enabling
> the clock, for example.
>
OK, I will modify it.
> > +
> > + sunplus_uart_ports[pdev->id].rstc =
> > + devm_reset_control_get(&pdev->dev, NULL);
>
> Please use devm_reset_control_get_exclusive() instead.
>
OK, I will modify it.
> > +
> > + if (IS_ERR(sunplus_uart_ports[pdev->id].rstc))
> > + return PTR_ERR(sunplus_uart_ports[pdev->id].rstc);
> > +
> > + ret = reset_control_deassert(sunplus_uart_ports[pdev->id].rstc);
> > + if (ret)
> > + return ret;
> > +
> > + clk = sunplus_uart_ports[pdev->id].clk;
> > + if (IS_ERR(clk))
>
> This can't ever be true, the code above already returned in this case.
>
Indeed, I will modify it.
> [...]
> > +static int sunplus_uart_remove(struct platform_device *pdev) { #ifdef
> > +CONFIG_PM_RUNTIME_UART
> > + if (pdev->id != 0) {
> > + pm_runtime_disable(&pdev->dev);
> > + pm_runtime_set_suspended(&pdev->dev);
> > + }
> > +#endif
> > + uart_remove_one_port(&sunplus_uart_driver,
> > + &sunplus_uart_ports[pdev->id].uport);
> > +
> > + if (pdev->id < UART_NR) {
> > + clk_disable_unprepare(sunplus_uart_ports[pdev->id].clk);
> > + reset_control_assert(sunplus_uart_ports[pdev->id].rstc);
> > + }
>
> What about the PERI clocks? This seems to leave them enabled.
>
In case of dma enable, we should consider it.
I will modify it.
> regards
> Philipp
next prev parent reply other threads:[~2021-11-11 9:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-01 7:48 [PATCH 0/2] Add UART driver for Suplus SP7021 SoC hammer.hsieh
2021-11-01 7:48 ` [PATCH 1/2] dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver hammer.hsieh
2021-11-01 13:20 ` Rob Herring
2021-11-01 19:34 ` Rob Herring
2021-11-01 7:48 ` [PATCH 2/2] serial:sunplus-uart:Add " hammer.hsieh
2021-11-01 7:56 ` Greg KH
2021-11-10 7:51 ` [PATCH v2 0/2] Add UART driver for Suplus SP7021 SoC Hammer Hsieh
2021-11-10 7:51 ` [PATCH v2 1/2] dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver Hammer Hsieh
2021-11-10 7:51 ` [PATCH v2 2/2] serial:sunplus-uart:Add " Hammer Hsieh
2021-11-10 9:50 ` Philipp Zabel
2021-11-11 9:45 ` Hammer Hsieh 謝宏孟 [this message]
2021-11-12 8:31 ` kernel test robot
2021-11-10 16:41 ` [PATCH v2 0/2] Add UART driver for Suplus SP7021 SoC Andy Shevchenko
2021-11-19 5:19 ` [PATCH v3 " Hammer Hsieh
2021-11-19 5:19 ` [PATCH v3 1/2] dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver Hammer Hsieh
2021-11-29 0:22 ` Rob Herring
2021-11-19 5:19 ` [PATCH v3 2/2] serial:sunplus-uart:Add " Hammer Hsieh
2021-11-19 9:35 ` Andy Shevchenko
2021-11-23 3:43 ` Hammer Hsieh 謝宏孟
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=2e6d1c1649a047109455da62f4ddecf1@sphcmbx01.sunplus.com.tw \
--to=hammer.hsieh@sunplus.com \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hammerh0314@gmail.com \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=robh+dt@kernel.org \
--cc=tony.huang@sunplus.com \
--cc=wells.lu@sunplus.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
all inboxes | Powered by JetHome®