public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Vlad Zakharov <Vladislav.Zakharov@synopsys.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v7 02/12] serial: ns16550: Support clocks via phandle
Date: Tue, 4 Oct 2016 11:52:20 +0000	[thread overview]
Message-ID: <1475581938.6545.12.camel@synopsys.com> (raw)
In-Reply-To: <20160908064739.25313-3-paul.burton@imgtec.com>

Hello,

I found that this commit breaks serial?ns16550 driver on ARC.
I have investigated the issue and found that it is because ARC timer node in device tree doesn't refer to any clock
devices.?

In such case clk_get_by_index() returns -ENOENT error, but neither -ENODEV nor -ENOSYS (as CONFIG_CLK is enabled for
ARC). So the error is not ignored and we exit with error instead of trying to get "clock-frequency" property from the
device tree.

Thus I wonder why we ignore only ENOSYS and ENODEV errors and exit if any other error code appears?
As shown in my example such behavior can lead to breakages.?
What should we do if ENOENT occurs??

Thanks.

On Thu, 2016-09-08 at 07:47 +0100, Paul Burton wrote:
> Previously ns16550 compatible UARTs probed via device tree have needed
> their device tree nodes to contain a clock-frequency property. An
> alternative to this commonly used with Linux is to reference a clock via
> a phandle. This patch allows U-Boot to support that, retrieving the
> clock frequency by probing the appropriate clock device.
> 
> For example, a system might choose to provide the UART base clock as a
> reference to a clock common to multiple devices:
> 
> ? sys_clk: clock {
> ????compatible = "fixed-clock";
> ????#clock-cells = <0>;
> ????clock-frequency = <10000000>;
> ? };
> 
> ? uart0: uart at 10000000 {
> ????compatible = "ns16550a";
> ????reg = <0x10000000 0x1000>;
> ????clocks = <&sys_clk>;
> ? };
> 
> ? uart1: uart at 10000000 {
> ????compatible = "ns16550a";
> ????reg = <0x10001000 0x1000>;
> ????clocks = <&sys_clk>;
> ? };
> 
> This removes the need for the frequency information to be duplicated in
> multiple nodes and allows the device tree to be more descriptive of the
> system.
> 
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> ---
> 
> Changes in v7:
> - Check clk_get_rate return for error values
> 
> Changes in v6:
> - Ignore -ENOSYS from clk_get_by_index too, for systems with CONFIG_CLK=n
> 
> Changes in v5: None
> Changes in v4: None
> Changes in v3: None
> Changes in v2:
> - Propogate non-ENODEV errors from clk_get_by_index
> 
> ?drivers/serial/ns16550.c | 21 ++++++++++++++++++---
> ?1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
> index 88fca15..3f6ea4d 100644
> --- a/drivers/serial/ns16550.c
> +++ b/drivers/serial/ns16550.c
> @@ -5,6 +5,7 @@
> ? */
> ?
> ?#include <common.h>
> +#include <clk.h>
> ?#include <dm.h>
> ?#include <errno.h>
> ?#include <fdtdec.h>
> @@ -352,6 +353,8 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
> ?{
> ?	struct ns16550_platdata *plat = dev->platdata;
> ?	fdt_addr_t addr;
> +	struct clk clk;
> +	int err;
> ?
> ?	/* try Processor Local Bus device first */
> ?	addr = dev_get_addr(dev);
> @@ -397,9 +400,21 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
> ?				?????"reg-offset", 0);
> ?	plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
> ?					?"reg-shift", 0);
> -	plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
> -				?????"clock-frequency",
> -				?????CONFIG_SYS_NS16550_CLK);
> +
> +	err = clk_get_by_index(dev, 0, &clk);
> +	if (!err) {
> +		err = clk_get_rate(&clk);
> +		if (!IS_ERR_VALUE(err))
> +			plat->clock = err;
> +	} else if (err != -ENODEV && err != -ENOSYS) {
> +		debug("ns16550 failed to get clock\n");
> +		return err;
> +	}
> +
> +	if (!plat->clock)
> +		plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
> +					?????"clock-frequency",
> +					?????CONFIG_SYS_NS16550_CLK);
> ?	if (!plat->clock) {
> ?		debug("ns16550 clock not defined\n");
> ?		return -EINVAL;
-- 
Best regards,
Vlad Zakharov <vzakhar@synopsys.com>

  reply	other threads:[~2016-10-04 11:52 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-08  6:47 [U-Boot] [PATCH v7 00/12] MIPS Boston Development Board Support Paul Burton
2016-09-08  6:47 ` [U-Boot] [PATCH v7 01/12] clk: Use dummy clk_get_by_* functions when CONFIG_CLK is disabled Paul Burton
2016-09-09  3:15   ` Masahiro Yamada
2016-09-09  8:01     ` Paul Burton
2016-09-11 13:25       ` Masahiro Yamada
2016-09-11 15:14         ` Paul Burton
2016-09-15 10:54           ` Masahiro Yamada
2016-09-12 16:44         ` Stephen Warren
2016-09-08  6:47 ` [U-Boot] [PATCH v7 02/12] serial: ns16550: Support clocks via phandle Paul Burton
2016-10-04 11:52   ` Vlad Zakharov [this message]
2016-10-04 14:56   ` Vlad Zakharov
2016-09-08  6:47 ` [U-Boot] [PATCH v7 03/12] dt-bindings: Add interrupt-controller/mips-gic.h header Paul Burton
2016-09-08  6:47 ` [U-Boot] [PATCH v7 04/12] pci: xilinx: Add a driver for Xilinx AXI to PCIe bridge Paul Burton
2016-09-08  6:47 ` [U-Boot] [PATCH v7 05/12] pci: Flip condition for detecting non-PCI parent devices Paul Burton
2016-09-08  6:47 ` [U-Boot] [PATCH v7 06/12] net: pch_gbe: Use dm_pci_map_bar to discover MMIO base Paul Burton
2016-09-08  6:47 ` [U-Boot] [PATCH v7 07/12] net: pch_gbe: Make 64 bit safe Paul Burton
2016-09-08  6:47 ` [U-Boot] [PATCH v7 08/12] dm: regmap: Implement simple regmap_read & regmap_write Paul Burton
2016-09-08  6:47 ` [U-Boot] [PATCH v7 09/12] dm: core: Match compatible strings in order of priority Paul Burton
2016-09-23  4:15   ` Simon Glass
2016-09-08  6:47 ` [U-Boot] [PATCH v7 10/12] dm: syscon: Provide a generic syscon driver Paul Burton
2016-09-23  4:15   ` Simon Glass
2016-09-23 16:12     ` Paul Burton
2016-09-23 21:09       ` Simon Glass
2016-09-08  6:47 ` [U-Boot] [PATCH v7 11/12] clk: boston: Providea simple driver for Boston board clocks Paul Burton
2016-09-08  6:47 ` [U-Boot] [PATCH v7 12/12] boston: Introduce support for the MIPS Boston development board Paul Burton
2016-09-10 12:17   ` Daniel Schwierzeck
2016-09-10 13:02     ` Paul Burton

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=1475581938.6545.12.camel@synopsys.com \
    --to=vladislav.zakharov@synopsys.com \
    --cc=u-boot@lists.denx.de \
    /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