Skip to contentSkip to conversation

Raspberry Pi DT clocks series

PATCH In review Eric Anholt 4 participants 19 messages May 18, 2015 – Jun 5, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Here's a series to add a real clock provider on Raspberry Pi. Previously, we've been using a mix of fixed clocks from clk-bcm2835.c (though some of them failed to get used by their intended consumers), and fixed-clock nodes in the DT.

This driver gives us the ability to enable/disable our clocks, and also lets us get and set frequency values. This will let us build a cpufreq driver (Andrea Merello has done some work on this front, and has a couple of options available), and get correct frequencies on the Raspberry Pi 2 without hardcoding new values.

This branch can be found at:

https://github.com/anholt/linux/tree/rpi-dt-clocks

which also has a patch for the MMC clock which is not included yet due to a bug in the sdhci driver. The series applies on top of rpi-mailbox, whose code is currently out for review:

http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-May/001762.html

#1 lore raw

PATCH 1/7 dt/bindings: Add binding for the Raspberry Pi clock provider

The hardware clocks are not controllable by the ARM, so we have to make requests to the firmware to do so from the VPU side. This will let us replace fixed clocks in our DT with actual clock control (and correct frequency information).

---
 .../bindings/clock/raspberrypi,firmware-clocks.txt | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/raspberrypi,firmware-clocks.txt
Documentation/devicetree/bindings/clock/raspberrypi,firmware-clocks.txt new file +24 -0
new file mode 100644
index 0000000..9e1f21b
@@ -0,0 +1,24 @@
+Raspberry Pi firmware clock provider.
+
+The Raspberry Pi architecture doesn't provide direct access to the
+CLOCKMAN peripheral from the ARM side, so Linux has to make requests
+to the VPU firmware to program them.
+
+This binding uses the common clock binding:
+Documentation/devicetree/bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible:	Should be "raspberrypi,firmware-clocks"
+
+- #clock-cells:	Shall have value <1>.  The permitted clock-specifier values
+		  can be found in include/dt-bindings/clk/raspberrypi.h.
+
+- firmware:	Phandle to the firmware driver node.
+
+Example:
+
+firmware_clocks: firmware-clocks {
+	compatible = "raspberrypi,firmware-clocks";
+	#clock-cells = <1>;
+	firmware = <&firmware>;
+};
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH 1/7] dt/bindings: Add binding for the Raspberry Pi clock provider

Quoted 8 lines · Eric Anholt

The hardware clocks are not controllable by the ARM, so we have to make requests to the firmware to do so from the VPU side. This will let us replace fixed clocks in our DT with actual clock control (and correct frequency information).

Documentation/devicetree/bindings/clock/raspberrypi,firmware-clocks.txt +1 -0
 
+Required properties:

...

Documentation/devicetree/bindings/clock/raspberrypi,firmware-clocks.txt line 14

Quoted 2 lines

+- #clock-cells: Shall have value <1>. The permitted clock-specifier values

Documentation/devicetree/bindings/clock/raspberrypi,firmware-clocks.txt +1 -0
+		  can be found in include/dt-bindings/clk/raspberrypi.h.

That file is explicitly part of the binding; any driver that implements this binding needs to use the same values. As such, that file would typically be part of the patch that adds the binding doc, not part of the patch that implements the driver.

No need to respin the series just because of that though.

Quoted 1 line

+- firmware: Phandle to the firmware driver node.

"firmware" is rather generic. I'd suggest a vendor prefix for the property name; raspberrypi,firmware.

#3 lore raw

PATCH 2/7 ARM: bcm2835: Add a Raspberry Pi-specific clock driver.

In reply to Eric Anholt

Unfortunately, the clock manager's registers are not accessible by the ARM, so we have to request that the firmware modify our clocks for us.

This driver only registers the clocks at the point they are requested by a client driver. This is partially to support returning -EPROBE_DEFER when the firmware driver isn't supported yet, but it also avoids issues with disabling "unused" clocks due to them not yet being connected to their consumers in the DT.

---
 drivers/clk/Makefile                  |   1 +
 drivers/clk/clk-raspberrypi.c         | 241 ++++++++++++++++++++++++++++++++++
 include/dt-bindings/clk/raspberrypi.h |  23 ++++
 3 files changed, 265 insertions(+)
 create mode 100644 drivers/clk/clk-raspberrypi.c
 create mode 100644 include/dt-bindings/clk/raspberrypi.h
drivers/clk/Makefile +1 -0
index 3d00c25..6a5dafa 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_MACH_ASM9260)		+= clk-asm9260.o
 obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN)	+= clk-axi-clkgen.o
 obj-$(CONFIG_ARCH_AXXIA)		+= clk-axm5516.o
 obj-$(CONFIG_ARCH_BCM2835)		+= clk-bcm2835.o
+obj-$(CONFIG_ARCH_BCM2835)		+= clk-raspberrypi.o
 obj-$(CONFIG_COMMON_CLK_CDCE706)	+= clk-cdce706.o
 obj-$(CONFIG_ARCH_CLPS711X)		+= clk-clps711x.o
 obj-$(CONFIG_ARCH_EFM32)		+= clk-efm32gg.o
drivers/clk/clk-raspberrypi.c new file +241 -0

241 lines not on this page · raw message

include/dt-bindings/clk/raspberrypi.h new file +23 -0
new file mode 100644
index 0000000..c9fa85c
@@ -0,0 +1,23 @@
+#/*
+ *  Copyright ? 2015 Broadcom
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _DT_BINDINGS_CLK_RASPBERRYPI_H
+#define _DT_BINDINGS_CLK_RASPBERRYPI_H
+
+#define RPI_CLOCK_EMMC	0
+#define RPI_CLOCK_UART0	1
+#define RPI_CLOCK_ARM	2
+#define RPI_CLOCK_CORE	3
+#define RPI_CLOCK_V3D	4
+#define RPI_CLOCK_H264	5
+#define RPI_CLOCK_ISP	6
+#define RPI_CLOCK_SDRAM	7
+#define RPI_CLOCK_PIXEL	8
+#define RPI_CLOCK_PWM	9
+
+#endif
Signature · 1 line
2.1.4
#4 lore raw

Re: [PATCH 2/7] ARM: bcm2835: Add a Raspberry Pi-specific clock driver.

Hi Eric,

Quoted 1 line · Eric Anholt

+DEFINE_MUTEX(delayed_clock_init);

Static?

baruch

Signature · 3 lines
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
#5 lore raw

PATCH v2 2/7 ARM: bcm2835: Add a Raspberry Pi-specific clock driver.

Unfortunately, the clock manager's registers are not accessible by the ARM, so we have to request that the firmware modify our clocks for us.

This driver only registers the clocks at the point they are requested by a client driver. This is partially to support returning -EPROBE_DEFER when the firmware driver isn't supported yet, but it also avoids issues with disabling "unused" clocks due to them not yet being connected to their consumers in the DT.

---

v2: Declare the mutex static (from review by Baruch Siach), merge
description and copyright comments.

 drivers/clk/Makefile                  |   1 +
 drivers/clk/clk-raspberrypi.c         | 239 ++++++++++++++++++++++++++++++++++
 include/dt-bindings/clk/raspberrypi.h |  23 ++++
 3 files changed, 263 insertions(+)
 create mode 100644 drivers/clk/clk-raspberrypi.c
 create mode 100644 include/dt-bindings/clk/raspberrypi.h
drivers/clk/Makefile +1 -0
index 3d00c25..6a5dafa 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_MACH_ASM9260)		+= clk-asm9260.o
 obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN)	+= clk-axi-clkgen.o
 obj-$(CONFIG_ARCH_AXXIA)		+= clk-axm5516.o
 obj-$(CONFIG_ARCH_BCM2835)		+= clk-bcm2835.o
+obj-$(CONFIG_ARCH_BCM2835)		+= clk-raspberrypi.o
 obj-$(CONFIG_COMMON_CLK_CDCE706)	+= clk-cdce706.o
 obj-$(CONFIG_ARCH_CLPS711X)		+= clk-clps711x.o
 obj-$(CONFIG_ARCH_EFM32)		+= clk-efm32gg.o
drivers/clk/clk-raspberrypi.c new file +239 -0

239 lines not on this page · raw message

include/dt-bindings/clk/raspberrypi.h new file +23 -0
new file mode 100644
index 0000000..c9fa85c
@@ -0,0 +1,23 @@
+#/*
+ *  Copyright ? 2015 Broadcom
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _DT_BINDINGS_CLK_RASPBERRYPI_H
+#define _DT_BINDINGS_CLK_RASPBERRYPI_H
+
+#define RPI_CLOCK_EMMC	0
+#define RPI_CLOCK_UART0	1
+#define RPI_CLOCK_ARM	2
+#define RPI_CLOCK_CORE	3
+#define RPI_CLOCK_V3D	4
+#define RPI_CLOCK_H264	5
+#define RPI_CLOCK_ISP	6
+#define RPI_CLOCK_SDRAM	7
+#define RPI_CLOCK_PIXEL	8
+#define RPI_CLOCK_PWM	9
+
+#endif
Signature · 1 line
2.1.4
#6 lore raw

Re: [PATCH 2/7] ARM: bcm2835: Add a Raspberry Pi-specific clock driver.

In reply to Eric Anholt
Quoted 8 lines · Eric Anholt

Unfortunately, the clock manager's registers are not accessible by the ARM, so we have to request that the firmware modify our clocks for us.

This driver only registers the clocks at the point they are requested by a client driver. This is partially to support returning -EPROBE_DEFER when the firmware driver isn't supported yet, but it also avoids issues with disabling "unused" clocks due to them not yet being connected to their consumers in the DT.

It looks like you forgot to CC the clock subsystem maintainers:

M:      Mike Turquette <[email protected]>
M:      Stephen Boyd <[email protected]>

The description above sounds like a neat solution, but has the disadvantage that the clocks without a client won't show up in debugfs. I wonder if the clock maintainers know of a better way?

drivers/clk/Makefile obj-$(CONFIG_MACH_ASM9260) += clk-asm9260.o · line 23

Quoted 4 lines
drivers/clk/Makefile +1 -0
 
 obj-$(CONFIG_ARCH_BCM2835)		+= clk-bcm2835.o
+obj-$(CONFIG_ARCH_BCM2835)		+= clk-raspberrypi.o

Shouldn't this replace the old legacy code in clk-bcm2835.c?

I wonder if a separate Kconfig symbol is warranted for the clock driver. Looking at the context in the patch, it's common not to do that though.

drivers/clk/clk-raspberrypi.c line 29

Quoted 5 lines
drivers/clk/clk-raspberrypi.c +3 -0
 
+struct rpi_firmware_clock {
+	/* Clock definitions in our static struct. */
+	int clock_id;

Why not just use the raw HW IDs (from the mailbox protocol) as the ID in DT and the driver? The only thing that would need to change is to add a error check for "clkspec->args[0] == 0" in rpi_firmware_delayed_get_clk(). The advantage would be that include/dt-bindings/clk/raspberrypi.h would exactly match the firmware protocol, and hence be easily correlated with the documentation.

drivers/clk/clk-raspberrypi.c line 136

Quoted 11 lines
drivers/clk/clk-raspberrypi.c +11 -0
+static int rpi_clk_set_rate(struct clk_hw *hw,
+			    unsigned long rate, unsigned long parent_rate)
+{
+	struct rpi_firmware_clock *rpi_clk =
+		container_of(hw, struct rpi_firmware_clock, hw);
+	u32 packet[2];
+	int ret;
+
+	packet[0] = rpi_clk->clock_id;
+	packet[1] = rate;
+	ret = rpi_firmware_property(rpi_clk->firmware_node,

The docs indicate there's a third word here "skip setting turbo". Is that optional?

https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface

drivers/clk/clk-raspberrypi.c line 157

Quoted 11 lines
drivers/clk/clk-raspberrypi.c +11 -0
+static long rpi_clk_round_rate(struct clk_hw *hw, unsigned long rate,
+			       unsigned long *parent_rate)
+{
+	/*
+	 * The firmware will end up rounding our rate to something,
+	 * but we don't have an interface for it.  Just return the
+	 * requested value, and it'll get updated after the clock gets
+	 * set.
+	 */
+	return rate;
+}

Hmm. I wonder if that will confuse things; I thought the purpose of round_rate() was so code could know exactly what would happen ahead of time?

Quoted 5 lines
drivers/clk/clk-raspberrypi.c +4 -0
+static struct clk *rpi_firmware_delayed_get_clk(struct of_phandle_args *clkspec,
+						void *_data)
 
+	rpi_clk = &rpi_clocks[clkspec->args[0]];
+

drivers/clk/clk-raspberrypi.c line 203

Quoted 10 lines
drivers/clk/clk-raspberrypi.c +10 -0
+	firmware_node = of_parse_phandle(of_node, "firmware", 0);
+	if (!firmware_node) {
+		dev_err(dev, "%s: Missing firmware node\n", rpi_clk->name);
+		return ERR_PTR(-ENODEV);
+	}
+
+	/* Try a no-op transaction to see if the driver is loaded yet. */
+	ret = rpi_firmware_property_list(firmware_node, NULL, 0);
+	if (ret)
+		return ERR_PTR(ret);

I would move all that into this driver's probe().

drivers/clk/clk-raspberrypi.c line 217

Quoted 1 line
drivers/clk/clk-raspberrypi.c +1 -0
+	init.flags = CLK_IS_ROOT;

Is it possible to add clock parent information to the driver, so the clocks are all hooked together into the correct tree, rather than all looking like root clocks?

One of the many reasons I didn't do anything FW-wise for the kernel was the hope that such information would be forthcoming, and hence we could have complete kernel drivers.

drivers/clk/clk-raspberrypi.c line 235

Quoted 6 lines
drivers/clk/clk-raspberrypi.c +6 -0
+void __init rpi_firmware_init_clock_provider(struct device_node *node)
+{
+	/* We delay construction of our struct clks until get time,
+	 * because we need to be able to return -EPROBE_DEFER if the
+	 * firmware driver isn't up yet.  clk core doesn't support
+	 * re-probing on -EPROBE_DEFER, but callers of clk_get can.

Oh, that's nasty. What would it take to fix the clock core to support deferred probe? It really should.

drivers/clk/clk-raspberrypi.c line 241

Quoted 2 lines
drivers/clk/clk-raspberrypi.c +2 -0
+CLK_OF_DECLARE(rpi_firmware_clocks, "raspberrypi,firmware-clocks",
+	       rpi_firmware_init_clock_provider);

Oh, I guess the same comment as for the firmware node applies re: the over-genericity of the DT compatible value applies here too. Perhaps raspberrypi,bcm2835-firmware-clocks to match Lee's proposal for the firmware node?

#7 lore raw

Re: [PATCH 2/7] ARM: bcm2835: Add a Raspberry Pi-specific clock driver.

Quoted 10 lines · Stephen Warren
Quoted 8 lines · Eric Anholt

Unfortunately, the clock manager's registers are not accessible by the ARM, so we have to request that the firmware modify our clocks for us.

This driver only registers the clocks at the point they are requested by a client driver. This is partially to support returning -EPROBE_DEFER when the firmware driver isn't supported yet, but it also avoids issues with disabling "unused" clocks due to them not yet being connected to their consumers in the DT.

Quoted 5 lines

It looks like you forgot to CC the clock subsystem maintainers:

M:      Mike Turquette <[email protected]>
M:      Stephen Boyd <[email protected]>

Thanks, except I don't have the full patch context here to review the patch.

Quoted 3 lines

The description above sounds like a neat solution, but has the disadvantage that the clocks without a client won't show up in debugfs. I wonder if the clock maintainers know of a better way?

Can you mark them as CLK_IGNORE_UNUSED? The probe defer problem has a solution in sight (see more below).

Quoted 6 lines
Quoted 6 lines
drivers/clk/clk-raspberrypi.c new file +6 -0
+static long rpi_clk_round_rate(struct clk_hw *hw, unsigned long rate,
+			       unsigned long *parent_rate)
+{
+	/*
+	 * The firmware will end up rounding our rate to something,
+	 * but we don't have an interface for it.  Just return the
Quoted 8 lines

drivers/clk/clk-raspberrypi.c line 157

Quoted 5 lines
drivers/clk/clk-raspberrypi.c new file +5 -0
+	 * requested value, and it'll get updated after the clock gets
+	 * set.
+	 */
+	return rate;
+}

Hmm. I wonder if that will confuse things; I thought the purpose of round_rate() was so code could know exactly what would happen ahead of time?

We have to do the same thing on Qualcomm platforms for FW controlled clocks. We don't have any insight to what the rate is going to be. We can only ask the firmware to set a rate and the firmware guarantees it will be at least that rate.

Quoted 11 lines

drivers/clk/clk-raspberrypi.c line 217

Quoted 2 lines
drivers/clk/clk-raspberrypi.c new file +1 -0
+	init.flags = CLK_IS_ROOT;

Is it possible to add clock parent information to the driver, so the clocks are all hooked together into the correct tree, rather than all looking like root clocks?

One of the many reasons I didn't do anything FW-wise for the kernel was the hope that such information would be forthcoming, and hence we could have complete kernel drivers.

Quoted 9 lines

drivers/clk/clk-raspberrypi.c line 235

Quoted 6 lines
drivers/clk/clk-raspberrypi.c new file +6 -0
+void __init rpi_firmware_init_clock_provider(struct device_node *node)
+{
+	/* We delay construction of our struct clks until get time,
+	 * because we need to be able to return -EPROBE_DEFER if the
+	 * firmware driver isn't up yet.  clk core doesn't support
+	 * re-probing on -EPROBE_DEFER, but callers of clk_get can.

Oh, that's nasty. What would it take to fix the clock core to support deferred probe? It really should.

There are patches to support probe defer from clk_get() but they stalled because sunxi is needs to keep clocks on from their providing driver (termed "critical clocks"). If we can resolve the "critical clocks" thing then we should be able to support probe defer, unless we find other users of orphaned clk pointers.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#8 lore raw

Re: [PATCH 2/7] ARM: bcm2835: Add a Raspberry Pi-specific clock driver.

Quoted 47 lines · Stephen Boyd
Quoted 10 lines · Stephen Warren
Quoted 8 lines · Eric Anholt

Unfortunately, the clock manager's registers are not accessible by the ARM, so we have to request that the firmware modify our clocks for us.

This driver only registers the clocks at the point they are requested by a client driver. This is partially to support returning -EPROBE_DEFER when the firmware driver isn't supported yet, but it also avoids issues with disabling "unused" clocks due to them not yet being connected to their consumers in the DT.

Quoted 5 lines

It looks like you forgot to CC the clock subsystem maintainers:

M:      Mike Turquette <[email protected]>
M:      Stephen Boyd <[email protected]>

Thanks, except I don't have the full patch context here to review the patch.

Quoted 3 lines

The description above sounds like a neat solution, but has the disadvantage that the clocks without a client won't show up in debugfs. I wonder if the clock maintainers know of a better way?

Can you mark them as CLK_IGNORE_UNUSED? The probe defer problem has a solution in sight (see more below).

Quoted 10 lines

drivers/clk/clk-raspberrypi.c line 217

Quoted 1 line
drivers/clk/clk-raspberrypi.c new file +1 -0
+	init.flags = CLK_IS_ROOT;

Is it possible to add clock parent information to the driver, so the clocks are all hooked together into the correct tree, rather than all looking like root clocks?

One of the many reasons I didn't do anything FW-wise for the kernel was the hope that such information would be forthcoming, and hence we could have complete kernel drivers.

Quoted 9 lines

drivers/clk/clk-raspberrypi.c line 235

Quoted 6 lines
drivers/clk/clk-raspberrypi.c new file +6 -0
+void __init rpi_firmware_init_clock_provider(struct device_node *node)
+{
+	/* We delay construction of our struct clks until get time,
+	 * because we need to be able to return -EPROBE_DEFER if the
+	 * firmware driver isn't up yet.  clk core doesn't support
+	 * re-probing on -EPROBE_DEFER, but callers of clk_get can.

Oh, that's nasty. What would it take to fix the clock core to support deferred probe? It really should.

Quoted 6 lines

There are patches to support probe defer from clk_get() but they stalled because sunxi is needs to keep clocks on from their providing driver (termed "critical clocks"). If we can resolve the "critical clocks" thing then we should be able to support probe defer, unless we find other users of orphaned clk pointers.

Great! I'm certainly happy to switch to a normal registration of all my clocks once -EPROBE_DEFER works from the clock provider init.

If those patches aren't landing this release, that also gives us a
release to wire up all the clock consumers in the DT before we get hit
by stable DT ABI, so we'll be able to give a nice limited set of
CLOCK_IGNORE_UNUSED in the flags when we transition.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150529/f0a794cb/attachment.sig>

#9 lore raw

Re: [PATCH 2/7] ARM: bcm2835: Add a Raspberry Pi-specific clock driver.

In reply to Stephen Warren
Quoted 10 lines · Stephen Warren

drivers/clk/clk-raspberrypi.c line 217

Quoted 1 line · Eric Anholt
drivers/clk/clk-raspberrypi.c new file +1 -0
+	init.flags = CLK_IS_ROOT;

Is it possible to add clock parent information to the driver, so the clocks are all hooked together into the correct tree, rather than all looking like root clocks?

One of the many reasons I didn't do anything FW-wise for the kernel was the hope that such information would be forthcoming, and hence we could have complete kernel drivers.

As far as I can tell, none of these clocks are the parent of any other.

There's a layer of PLLs, then clockman almost always just dividing off
of those. In response to a clockman request (which is what this
property tag quickly maps to), only PLLH ever gets changed as a result
of RPI_CLOCK_PIXEL. PLLH feeds the HDMI and VEC (SDTV). We don't have
an SDTV clock for us to control through these interfaces, so there are
no conflicts that I can see. Only two clockman clocks I see divide off
of on other clockman clocks, and we don't have access to those.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150529/4f7dc2b5/attachment.sig>

#10 lore raw

Re: [PATCH 2/7] ARM: bcm2835: Add a Raspberry Pi-specific clock driver.

In reply to Stephen Warren
Quoted 5 lines · Stephen Warren
Quoted 2 lines · Eric Anholt

obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835.o
+obj-$(CONFIG_ARCH_BCM2835) += clk-raspberrypi.o

Shouldn't this replace the old legacy code in clk-bcm2835.c?

I don't think we can, because of DT backwards compat (Sigh).

Quoted 3 lines

I wonder if a separate Kconfig symbol is warranted for the clock driver. Looking at the context in the patch, it's common not to do that though.

I've moved it under RASPBERRYPI_FIRMWARE, since it needs that to build.

Quoted 12 lines

drivers/clk/clk-raspberrypi.c line 29

Quoted 5 lines
drivers/clk/clk-raspberrypi.c +3 -0
 
+struct rpi_firmware_clock {
+	/* Clock definitions in our static struct. */
+	int clock_id;

Why not just use the raw HW IDs (from the mailbox protocol) as the ID in DT and the driver? The only thing that would need to change is to add a error check for "clkspec->args[0] == 0" in rpi_firmware_delayed_get_clk(). The advantage would be that include/dt-bindings/clk/raspberrypi.h would exactly match the firmware protocol, and hence be easily correlated with the documentation.

Done.

Quoted 15 lines

drivers/clk/clk-raspberrypi.c line 136

Quoted 11 lines
drivers/clk/clk-raspberrypi.c +11 -0
+static int rpi_clk_set_rate(struct clk_hw *hw,
+			    unsigned long rate, unsigned long parent_rate)
+{
+	struct rpi_firmware_clock *rpi_clk =
+		container_of(hw, struct rpi_firmware_clock, hw);
+	u32 packet[2];
+	int ret;
+
+	packet[0] = rpi_clk->clock_id;
+	packet[1] = rate;
+	ret = rpi_firmware_property(rpi_clk->firmware_node,

The docs indicate there's a third word here "skip setting turbo". Is that optional?

Quoted 1 line

https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface

Yeah, it's optional based on the buffer size specified in the packet.

Quoted 6 lines
Quoted 6 lines
drivers/clk/clk-raspberrypi.c +6 -0
+static long rpi_clk_round_rate(struct clk_hw *hw, unsigned long rate,
+			       unsigned long *parent_rate)
+{
+	/*
+	 * The firmware will end up rounding our rate to something,
+	 * but we don't have an interface for it.  Just return the
Quoted 8 lines

drivers/clk/clk-raspberrypi.c line 157

Quoted 5 lines
drivers/clk/clk-raspberrypi.c +5 -0
+	 * requested value, and it'll get updated after the clock gets
+	 * set.
+	 */
+	return rate;
+}

Hmm. I wonder if that will confuse things; I thought the purpose of round_rate() was so code could know exactly what would happen ahead of time?

Well, we don't have the ability. Things seem to work, anyway. Certainly better than just living with fixed clocks for everything like we are today.

Quoted 17 lines
Quoted 5 lines

+static struct clk *rpi_firmware_delayed_get_clk(struct of_phandle_args *clkspec, + void *_data)

drivers/clk/clk-raspberrypi.c +2 -0
+	rpi_clk = &rpi_clocks[clkspec->args[0]];
+

drivers/clk/clk-raspberrypi.c line 203

Quoted 10 lines
drivers/clk/clk-raspberrypi.c +10 -0
+	firmware_node = of_parse_phandle(of_node, "firmware", 0);
+	if (!firmware_node) {
+		dev_err(dev, "%s: Missing firmware node\n", rpi_clk->name);
+		return ERR_PTR(-ENODEV);
+	}
+
+	/* Try a no-op transaction to see if the driver is loaded yet. */
+	ret = rpi_firmware_property_list(firmware_node, NULL, 0);
+	if (ret)
+		return ERR_PTR(ret);

I would move all that into this driver's probe().

We can't move all this into the driver's probe, because this is where we're returning -EPROBE_DEFER. We could potentially do just the phandle parse up front and allocate some memory to pass it and our own device node to this function through the _data arg, but I don't see much point.

Quoted 7 lines

drivers/clk/clk-raspberrypi.c line 241

Quoted 2 lines
drivers/clk/clk-raspberrypi.c +2 -0
+CLK_OF_DECLARE(rpi_firmware_clocks, "raspberrypi,firmware-clocks",
+	       rpi_firmware_init_clock_provider);

Oh, I guess the same comment as for the firmware node applies re: the over-genericity of the DT compatible value applies here too. Perhaps raspberrypi,bcm2835-firmware-clocks to match Lee's proposal for the firmware node?

Done.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150529/8e2e93a0/attachment.sig>

#11 lore raw

Re: [PATCH 2/7] ARM: bcm2835: Add a Raspberry Pi-specific clock driver.

Quoted 17 lines · Eric Anholt
Quoted 5 lines · Stephen Warren
Quoted 2 lines · Eric Anholt

+static struct clk *rpi_firmware_delayed_get_clk(struct of_phandle_args *clkspec, + void *_data)

Quoted 9 lines
Quoted 7 lines
(quoted diff) +1 -0
+	rpi_clk = &rpi_clocks[clkspec->args[0]]; + +	firmware_node =

of_parse_phandle(of_node, "firmware", 0); + if (!firmware_node)
{ + dev_err(dev, "%s: Missing firmware node\n",
rpi_clk->name); + return ERR_PTR(-ENODEV); + } + + /* Try a
no-op transaction to see if the driver is loaded yet. */ + ret
= rpi_firmware_property_list(firmware_node, NULL, 0); + if
(ret) + return ERR_PTR(ret);

I would move all that into this driver's probe().

Quoted 5 lines

We can't move all this into the driver's probe, because this is where we're returning -EPROBE_DEFER. We could potentially do just the phandle parse up front and allocate some memory to pass it and our own device node to this function through the _data arg, but I don't see much point.

Well, once the clock core correctly supports deferred probe, that can be moved.

Aside from that, I think all your other replies to my replies in this thread/series make sense.

#12 lore raw

PATCH 3/7 ARM: bcm2835: Add DT for the firmware clocks driver.

In reply to Eric Anholt
---
 arch/arm/boot/dts/bcm2835-rpi.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/boot/dts/bcm2835-rpi.dtsi +6 -0
index ace33f6..ac5f84c 100644
@@ -20,6 +20,12 @@
 			compatible = "raspberrypi,firmware";
 			mboxes = <&mailbox>;
 		};
+
+		firmware_clocks: firmware-clocks {
+			compatible = "raspberrypi,firmware-clocks";
+			#clock-cells = <1>;
+			firmware = <&firmware>;
+		};
 	};
 };
 
Signature · 1 line
2.1.4
#13 lore raw

PATCH 4/7 ARM: bcm2835: Drop never-used clock-frequency property of uart0.

In reply to Eric Anholt

This appears to have been copy-and-paste from another serial driver's DT. The driver has never used this value -- instead, the pl011 driver is getting the fixed 20201000.uart clock from clk-bcm2835.c.

---
 arch/arm/boot/dts/bcm2835.dtsi | 1 -
 1 file changed, 1 deletion(-)
arch/arm/boot/dts/bcm2835.dtsi +0 -1
index 301c73f..32f5830 100644
@@ -96,7 +96,6 @@
 			compatible = "brcm,bcm2835-pl011", "arm,pl011", "arm,primecell";
 			reg = <0x7e201000 0x1000>;
 			interrupts = <2 25>;
-			clock-frequency = <3000000>;
 			arm,primecell-periphid = <0x00241011>;
 		};
 
Signature · 1 line
2.1.4
#14 lore raw

PATCH 5/7 ARM: bcm2835: Drop the fixed sys_pclk.

In reply to Eric Anholt

Nothing uses it, and I can't find any evidence that anything ever has.

---
 drivers/clk/clk-bcm2835.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/clk/clk-bcm2835.c +0 -5
index 6b950ca..dd295e4 100644
@@ -32,11 +32,6 @@ void __init bcm2835_init_clocks(void)
 	struct clk *clk;
 	int ret;
 
-	clk = clk_register_fixed_rate(NULL, "sys_pclk", NULL, CLK_IS_ROOT,
-					250000000);
-	if (IS_ERR(clk))
-		pr_err("sys_pclk not registered\n");
-
 	clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT,
 					126000000);
 	if (IS_ERR(clk))
Signature · 1 line
2.1.4
#15 lore raw

Re: [PATCH 5/7] ARM: bcm2835: Drop the fixed sys_pclk.

Quoted 1 line · Eric Anholt

Nothing uses it, and I can't find any evidence that anything ever has.

Does the clock actually exist though? If it does, it seems reasonable to keep it.

#16 lore raw

Re: [PATCH 5/7] ARM: bcm2835: Drop the fixed sys_pclk.

Quoted 5 lines · Stephen Warren
Quoted 1 line · Eric Anholt

Nothing uses it, and I can't find any evidence that anything ever has.

Does the clock actually exist though? If it does, it seems reasonable to keep it.

Yes, it's kept in the form of the core clock in the RPi driver, and the
clock-frequency values in spi and i2c in bcm2835.dtsi.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150529/733f9b02/attachment-0001.sig>

#17 lore raw

PATCH 6/7 ARM: bcm2835: Use the RPi firmware clocks for uart.

In reply to Eric Anholt

This gets us a correct apb_pclk, which previously was accidentally using the "20201000.uart" clock from clk-bcm2835.c, due to the fallback clk_get_sys() path.

---
 arch/arm/boot/dts/bcm2835-rpi.dtsi | 7 +++++++
 arch/arm/boot/dts/bcm2835.dtsi     | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
arch/arm/boot/dts/bcm2835-rpi.dtsi +7 -0
index ac5f84c..53285a3 100644
@@ -1,3 +1,4 @@
+#include <dt-bindings/clk/raspberrypi.h>
 #include "bcm2835.dtsi"
 
 / {
@@ -62,3 +63,9 @@
 	status = "okay";
 	bus-width = <4>;
 };
+
+&uart0 {
+	clocks = <&firmware_clocks RPI_CLOCK_UART0>,
+		 <&firmware_clocks RPI_CLOCK_CORE>;
+	clock-names = "uartclk", "apb_pclk";
+};
arch/arm/boot/dts/bcm2835.dtsi +1 -1
index 32f5830..5be2862 100644
@@ -92,7 +92,7 @@
 			#interrupt-cells = <2>;
 		};
 
-		uart at 7e201000 {
+		uart0: uart at 7e201000 {
 			compatible = "brcm,bcm2835-pl011", "arm,pl011", "arm,primecell";
 			reg = <0x7e201000 0x1000>;
 			interrupts = <2 25>;
Signature · 1 line
2.1.4
#18 lore raw

PATCH 7/7 ARM: bcm2835: Tie SPI clock to the core clock rate.

In reply to Eric Anholt

We were previously using a fixed clock declared in the 2835 DT, but it's actually the core clock, and it might not be the same if you had adjusted it using the firmware's config.txt.

---

This is the only patch in the series I haven't really tested, since I don't have any SPI devices.

 arch/arm/boot/dts/bcm2835-rpi.dtsi | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/boot/dts/bcm2835-rpi.dtsi +4 -0
index 53285a3..994c8e7 100644
@@ -69,3 +69,7 @@
 		 <&firmware_clocks RPI_CLOCK_CORE>;
 	clock-names = "uartclk", "apb_pclk";
 };
+
+&spi {
+	clocks = <&firmware_clocks RPI_CLOCK_CORE>;
+};
Signature · 1 line
2.1.4