diff mbox series

[U-Boot] serial: pl01x: Get clock from clock node if no clock property found

Message ID 41abe8ae8caa57672660321ff54368ccc0927f3f.1538545499.git.michal.simek@xilinx.com
State Deferred
Delegated to: Michal Simek
Headers show
Series [U-Boot] serial: pl01x: Get clock from clock node if no clock property found | expand

Commit Message

Michal Simek Oct. 3, 2018, 5:45 a.m. UTC
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(+)

Comments

Alexander Graf Oct. 16, 2018, 2:25 p.m. UTC | #1
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
Michal Simek Oct. 16, 2018, 2:46 p.m. UTC | #2
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
Alexander Graf Oct. 16, 2018, 2:57 p.m. UTC | #3
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
Michal Simek Oct. 16, 2018, 3 p.m. UTC | #4
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
diff mbox series

Patch

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");