Skip to contentSkip to conversation

CREG clk driver for NXP LPC18xx family

PATCH Applied Joachim Eastwood 2 participants 8 messages Mar 3, 2016 – Mar 4, 2016

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

v5 cover CREG clk driver for NXP LPC18xx family

This patch set adds a clk driver for the low power clocks found in the CREG block on lpc18xx. CREG is a collection of miscellaneous configuration registers that can be accessed through a syscon regmap interface. The clk driver makes it possible to setup and enabled these two clocks.

This need to support peripherals like the internal RTC on the lpc18xx platform.

The driver has one early init using CLK_OF_DECLARE and a standard platform driver. The early init is used to register the 32KHZ clk which may be needed early on. The other clock (1KHZ) is registered when the platform driver probe runs.

This version splits clk array into clk_creg_early and clk_creg. I think this will work as long as clk_creg_early is _not_ used after the clk_creg is registered.

This seems to work, but I currently don't have a setup that requires the 32khz clock early so that part isn't really tested.

The probe deferral seems to work for the RTC:

[    3.386861] lpc24xx-rtc 40046000.rtc: error getting rtc clock
[    6.737615] lpc24xx-rtc 40046000.rtc: rtc core: registered lpc24xx-rtc as rtc0

Changes since v4:
- Use devm_clk_register in platform probe
- Fix typo in dt doc
- Add ack from Rob Herring on dt doc

Changes since v3:
- Add .is_enabled function to both creg clks.
- Remove unit address from bindings as requested by Rob Herring.

Changes since v2:
- Use two clk arrays for registration.
- Couple of minor cleanups.

Changes since v1:
- Split driver with one early init and one platform driver probe.
- Rebase on v4.5-rc1.

Joachim Eastwood (2):
clk: add lpc18xx creg clk driver
doc: dt: add documentation for lpc1850-creg-clk driver

 .../devicetree/bindings/clock/lpc1850-creg-clk.txt |  52 +++++
 drivers/clk/nxp/Makefile                           |   1 +
 drivers/clk/nxp/clk-lpc18xx-creg.c                 | 226 +++++++++++++++++++++
 3 files changed, 279 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/lpc1850-creg-clk.txt
 create mode 100644 drivers/clk/nxp/clk-lpc18xx-creg.c
Signature · 1 line
1.8.0
#1 lore raw

PATCH v5 1/2 clk: add lpc18xx creg clk driver

The CREG block on lpc18xx contains configuration register for two low power clocks. Support enabling of these two clocks with a clk driver that access CREG trough the syscon regmap interface.

These clocks are needed to support peripherals like the internal RTC on lpc18xx.

---
 drivers/clk/nxp/Makefile           |   1 +
 drivers/clk/nxp/clk-lpc18xx-creg.c | 226 +++++++++++++++++++++++++++++++++++++
 2 files changed, 227 insertions(+)
 create mode 100644 drivers/clk/nxp/clk-lpc18xx-creg.c
drivers/clk/nxp/Makefile +1 -0
index 607bd48c6563..d456ee6cc3d3 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_ARCH_LPC18XX)	+= clk-lpc18xx-cgu.o
 obj-$(CONFIG_ARCH_LPC18XX)	+= clk-lpc18xx-ccu.o
+obj-$(CONFIG_ARCH_LPC18XX)	+= clk-lpc18xx-creg.o
 obj-$(CONFIG_ARCH_LPC32XX)	+= clk-lpc32xx.o
drivers/clk/nxp/clk-lpc18xx-creg.c new file +226 -0

226 lines not on this page · raw message

Signature · 1 line
1.8.0
#2 lore raw

Re: [PATCH v5 1/2] clk: add lpc18xx creg clk driver

Quoted 20 lines · Joachim Eastwood
drivers/clk/nxp/clk-lpc18xx-creg.c new file +14 -0
new file mode 100644
index 000000000000..d44b61afa2dc
@@ -0,0 +1,226 @@
+
+static int clk_creg_32k_is_prepared(struct clk_hw *hw)
+{
+	struct clk_creg_data *creg = to_clk_creg(hw);
+	u32 reg;
+
+	regmap_read(creg->reg, LPC18XX_CREG_CREG0, &reg);
+
+	return !(reg & LPC18XX_CREG_CREG0_PD32KHZ) &&
+	       !(reg & LPC18XX_CREG_CREG0_RESET32KHZ);
+}
+
+static unsigned long clk_creg_1k_recalc_rate(struct clk_hw *hw,
+					     unsigned long parent_rate)

drivers/clk/nxp/clk-lpc18xx-creg.c line 24

Quoted 10 lines
drivers/clk/nxp/clk-lpc18xx-creg.c new file +10 -0
+{
+	return parent_rate / 32;
+}
+
+static int clk_creg_enable(struct clk_hw *hw)
+{
+	struct clk_creg_data *creg = to_clk_creg(hw);
+
+	return regmap_update_bits(creg->reg, LPC18XX_CREG_CREG0,
+				  creg->en_mask, creg->en_mask);

Have you tested this with CONFIG_DEBUG_ATOMIC_SLEEP=y? I seem to recall that syscon uses a regmap with regmap_config::fast_io set to false, so all regmap operations take a mutex lock. clk_ops::enable is called with a spinlock held, so that isn't going to work well.

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

Re: [PATCH v5 1/2] clk: add lpc18xx creg clk driver

Quoted 29 lines · Stephen Boyd
Quoted 28 lines · Joachim Eastwood
drivers/clk/nxp/clk-lpc18xx-creg.c new file +22 -0
new file mode 100644
index 000000000000..d44b61afa2dc
@@ -0,0 +1,226 @@
+
+static int clk_creg_32k_is_prepared(struct clk_hw *hw)
+{
+     struct clk_creg_data *creg = to_clk_creg(hw);
+     u32 reg;
+
+     regmap_read(creg->reg, LPC18XX_CREG_CREG0, &reg);
+
+     return !(reg & LPC18XX_CREG_CREG0_PD32KHZ) &&
+            !(reg & LPC18XX_CREG_CREG0_RESET32KHZ);
+}
+
+static unsigned long clk_creg_1k_recalc_rate(struct clk_hw *hw,
+                                          unsigned long parent_rate)
+{
+     return parent_rate / 32;
+}
+
+static int clk_creg_enable(struct clk_hw *hw)
+{
+     struct clk_creg_data *creg = to_clk_creg(hw);
+
Quoted 8 lines

drivers/clk/nxp/clk-lpc18xx-creg.c line 97

Quoted 2 lines
drivers/clk/nxp/clk-lpc18xx-creg.c new file +2 -0
+     return regmap_update_bits(creg->reg, LPC18XX_CREG_CREG0,
+                               creg->en_mask, creg->en_mask);

Have you tested this with CONFIG_DEBUG_ATOMIC_SLEEP=y? I seem to recall that syscon uses a regmap with regmap_config::fast_io set to false, so all regmap operations take a mutex lock. clk_ops::enable is called with a spinlock held, so that isn't going to work well.

The MMIO bus config sets fast io to true and __regmap_init() uses spinlocks if either bus or regmap config is set to true.

http://lxr.free-electrons.com/source/drivers/base/regmap/regmap-mmio.c#L209
http://lxr.free-electrons.com/source/drivers/base/regmap/regmap.c#L548

or am I missing something?

regards,
Joachim Eastwood

#4 lore raw

Re: [PATCH v5 1/2] clk: add lpc18xx creg clk driver

Quoted 9 lines · Joachim Eastwood

The MMIO bus config sets fast io to true and __regmap_init() uses spinlocks if either bus or regmap config is set to true.

http://lxr.free-electrons.com/source/drivers/base/regmap/regmap-mmio.c#L209
http://lxr.free-electrons.com/source/drivers/base/regmap/regmap.c#L548

or am I missing something?

Ah good! Brain model updated.

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

Re: [PATCH v5 1/2] clk: add lpc18xx creg clk driver

In reply to Joachim Eastwood
Quoted 10 lines · Joachim Eastwood

The CREG block on lpc18xx contains configuration register for two low power clocks. Support enabling of these two clocks with a clk driver that access CREG trough the syscon regmap interface.

These clocks are needed to support peripherals like the internal RTC on lpc18xx.

---

Applied to clk-next

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

PATCH v5 2/2 doc: dt: add documentation for lpc1850-creg-clk driver

In reply to Joachim Eastwood

Add DT binding documentation for lpc1850-creg-clk driver.

---
 .../devicetree/bindings/clock/lpc1850-creg-clk.txt | 52 ++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/lpc1850-creg-clk.txt
Documentation/devicetree/bindings/clock/lpc1850-creg-clk.txt new file +52 -0
new file mode 100644
index 000000000000..6f1c7b4e4d2c
@@ -0,0 +1,52 @@
+* NXP LPC1850 CREG clocks
+
+The NXP LPC18xx/43xx CREG (Configuration Registers) block contains
+control registers for two low speed clocks. One of the clocks is a
+32 kHz oscillator driver with power up/down and clock gating. Next
+is a fixed divider that creates a 1 kHz clock from the 32 kHz osc.
+
+These clocks are used by the RTC and the Event Router peripherials.
+The 32 kHz can also be routed to other peripherials to enable low
+power modes.
+
+This binding uses the common clock binding:
+    Documentation/devicetree/bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible:
+	Should be "nxp,lpc1850-creg-clk"
+- #clock-cells:
+	Shall have value <1>.
+- clocks:
+	Shall contain a phandle to the fixed 32 kHz crystal.
+
+The creg-clk node must be a child of the creg syscon node.
+
+The following clocks are available from the clock node.
+
+Clock ID	Name
+   0		 1 kHz clock
+   1		32 kHz Oscillator
+
+Example:
+soc {
+	creg: syscon@40043000 {
+		compatible = "nxp,lpc1850-creg", "syscon", "simple-mfd";
+		reg = <0x40043000 0x1000>;
+
+		creg_clk: clock-controller {
+			compatible = "nxp,lpc1850-creg-clk";
+			clocks = <&xtal32>;
+			#clock-cells = <1>;
+		};
+
+		...
+	};
+
+	rtc: rtc@40046000 {
+		...
+		clocks = <&creg_clk 0>, <&ccu1 CLK_CPU_BUS>;
+		clock-names = "rtc", "reg";
+		...
+	};
+};
Signature · 1 line
1.8.0
Applied
#7 lore raw

Re: [PATCH v5 2/2] doc: dt: add documentation for lpc1850-creg-clk driver

Quoted 5 lines · Joachim Eastwood

Add DT binding documentation for lpc1850-creg-clk driver.

---

Applied to clk-next

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