All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] serial: pl01x: Get clock from clock node if no clock property found
@ 2018-10-03  5:45 Michal Simek
  2018-10-16 14:25 ` Alexander Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Simek @ 2018-10-03  5:45 UTC (permalink / raw)
  To: u-boot

From: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>

This patch gets clock from clock nodes if no clock property found
in serial node.

Signed-off-by: Siva Durga Prasad Paladugu <sivadur@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

 drivers/serial/serial_pl01x.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/serial/serial_pl01x.c b/drivers/serial/serial_pl01x.c
index 2a5f256184f2..f4f33b13ff33 100644
--- a/drivers/serial/serial_pl01x.c
+++ b/drivers/serial/serial_pl01x.c
@@ -10,6 +10,7 @@
 
 /* Simple U-Boot driver for the PrimeCell PL010/PL011 UARTs */
 
+#include <clk.h>
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
@@ -341,6 +342,9 @@ int pl01x_serial_ofdata_to_platdata(struct udevice *dev)
 {
 	struct pl01x_serial_platdata *plat = dev_get_platdata(dev);
 	fdt_addr_t addr;
+	unsigned long clock;
+	int ret;
+	struct clk clk;
 
 	addr = devfdt_get_addr(dev);
 	if (addr == FDT_ADDR_T_NONE)
@@ -348,6 +352,28 @@ int pl01x_serial_ofdata_to_platdata(struct udevice *dev)
 
 	plat->base = addr;
 	plat->clock = dev_read_u32_default(dev, "clock", 1);
+	if (plat->clock == 1) {
+		ret = clk_get_by_index(dev, 0, &clk);
+		if (ret < 0) {
+			dev_err(dev, "failed to get clock\n");
+			return ret;
+		}
+
+		clock = clk_get_rate(&clk);
+		if (IS_ERR_VALUE(clock)) {
+			dev_err(dev, "failed to get rate\n");
+			return clock;
+		}
+		debug("%s: CLK %ld\n", __func__, clock);
+
+		ret = clk_enable(&clk);
+		if (ret && ret != -ENOSYS) {
+			dev_err(dev, "failed to enable clock\n");
+			return ret;
+		}
+		plat->clock = clock;
+	}
+
 	plat->type = dev_get_driver_data(dev);
 	plat->skip_init = dev_read_bool(dev, "skip-init");
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH] serial: pl01x: Get clock from clock node if no clock property found
  2018-10-03  5:45 [U-Boot] [PATCH] serial: pl01x: Get clock from clock node if no clock property found Michal Simek
@ 2018-10-16 14:25 ` Alexander Graf
  2018-10-16 14:46   ` Michal Simek
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Graf @ 2018-10-16 14:25 UTC (permalink / raw)
  To: u-boot



On 03.10.18 07:45, Michal Simek wrote:
> From: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
> 
> This patch gets clock from clock nodes if no clock property found
> in serial node.
> 
> Signed-off-by: Siva Durga Prasad Paladugu <sivadur@xilinx.com>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>

Is this what Linux does? If so, you probably want to explicitly state that.


Alex

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH] serial: pl01x: Get clock from clock node if no clock property found
  2018-10-16 14:25 ` Alexander Graf
@ 2018-10-16 14:46   ` Michal Simek
  2018-10-16 14:57     ` Alexander Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Simek @ 2018-10-16 14:46 UTC (permalink / raw)
  To: u-boot

On 16.10.2018 16:25, Alexander Graf wrote:
> 
> 
> On 03.10.18 07:45, Michal Simek wrote:
>> From: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
>>
>> This patch gets clock from clock nodes if no clock property found
>> in serial node.
>>
>> Signed-off-by: Siva Durga Prasad Paladugu <sivadur@xilinx.com>
>> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> 
> Is this what Linux does? If so, you probably want to explicitly state that.

yes. Linux does that.
On the other hand reading clock property is something what it is out of
dt binding spec.

Thanks,
Michal

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH] serial: pl01x: Get clock from clock node if no clock property found
  2018-10-16 14:46   ` Michal Simek
@ 2018-10-16 14:57     ` Alexander Graf
  2018-10-16 15:00       ` Michal Simek
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Graf @ 2018-10-16 14:57 UTC (permalink / raw)
  To: u-boot



On 16.10.18 16:46, Michal Simek wrote:
> On 16.10.2018 16:25, Alexander Graf wrote:
>>
>>
>> On 03.10.18 07:45, Michal Simek wrote:
>>> From: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
>>>
>>> This patch gets clock from clock nodes if no clock property found
>>> in serial node.
>>>
>>> Signed-off-by: Siva Durga Prasad Paladugu <sivadur@xilinx.com>
>>> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
>>
>> Is this what Linux does? If so, you probably want to explicitly state that.
> 
> yes. Linux does that.
> On the other hand reading clock property is something what it is out of
> dt binding spec.

In that case, please at least note that in the patch description or
maybe even in a comment in the code, so the next time someone looks at
the code they don't get confused :).

Speaking of which, why isn't this handled generically already? I was
expecting that find clocks would be a matter of 2 lines of code - or
maybe none thanks to magic.


Alex

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH] serial: pl01x: Get clock from clock node if no clock property found
  2018-10-16 14:57     ` Alexander Graf
@ 2018-10-16 15:00       ` Michal Simek
  0 siblings, 0 replies; 5+ messages in thread
From: Michal Simek @ 2018-10-16 15:00 UTC (permalink / raw)
  To: u-boot

On 16.10.2018 16:57, Alexander Graf wrote:
> 
> 
> On 16.10.18 16:46, Michal Simek wrote:
>> On 16.10.2018 16:25, Alexander Graf wrote:
>>>
>>>
>>> On 03.10.18 07:45, Michal Simek wrote:
>>>> From: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
>>>>
>>>> This patch gets clock from clock nodes if no clock property found
>>>> in serial node.
>>>>
>>>> Signed-off-by: Siva Durga Prasad Paladugu <sivadur@xilinx.com>
>>>> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
>>>
>>> Is this what Linux does? If so, you probably want to explicitly state that.
>>
>> yes. Linux does that.
>> On the other hand reading clock property is something what it is out of
>> dt binding spec.
> 
> In that case, please at least note that in the patch description or
> maybe even in a comment in the code, so the next time someone looks at
> the code they don't get confused :).

Right now I have removed this patch from my PR because it is breaking
generic arm/arm64 model because there are missing some dt patches on
qemu side. Look at our discussing in my PR to Tom done yesterday.

> 
> Speaking of which, why isn't this handled generically already? I was
> expecting that find clocks would be a matter of 2 lines of code - or
> maybe none thanks to magic.

It depends.

M

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-10-16 15:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-03  5:45 [U-Boot] [PATCH] serial: pl01x: Get clock from clock node if no clock property found Michal Simek
2018-10-16 14:25 ` Alexander Graf
2018-10-16 14:46   ` Michal Simek
2018-10-16 14:57     ` Alexander Graf
2018-10-16 15:00       ` Michal Simek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.