Skip to contentSkip to conversation

driver/clk/clk-si5338: Add common clock framework driver for si5338

PATCH Superseded York Sun 2 participants 4 messages Jun 15, 2015 – Jun 16, 2015

Subsystems (3)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

York Sun

author
#0 lore raw

PATCH v2 1/1 driver/clk/clk-si5338: Add common clock framework driver for si5338

SI5338 is a programmable clock generator. It has 4 sets of inputs, PLL, multisynth and dividers to make 4 outputs. This driver splits them into multiple clocks to comply with common clock framework.

See Documentation/devicetree/bindings/clock/silabs,si5338.txt for details.

CC Mike Turquette <[email protected]>
CC Sebastian Hesselbarth <[email protected]>
CC Guenter Roeck <[email protected]>
CC Andrey Filippov <[email protected]>

---
Change log:
v2: Fix handling name prefix if the driver is unloaded and loaded again

 .../devicetree/bindings/clock/silabs,si5338.txt    |  173 +
 drivers/clk/Kconfig                                |   14 +-
 drivers/clk/Makefile                               |    1 +
 drivers/clk/clk-si5338.c                           | 3656 ++++++++++++++++++++
 drivers/clk/clk-si5338.h                           |  305 ++
 include/dt-bindings/clock/clk-si5338.h             |   69 +
 include/linux/platform_data/si5338.h               |   49 +
 7 files changed, 4266 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/clock/silabs,si5338.txt
 create mode 100644 drivers/clk/clk-si5338.c
 create mode 100644 drivers/clk/clk-si5338.h
 create mode 100644 include/dt-bindings/clock/clk-si5338.h
 create mode 100644 include/linux/platform_data/si5338.h
Documentation/devicetree/bindings/clock/silabs,si5338.txt new file +173 -0
new file mode 100644
index 0000000..aeeb81d
@@ -0,0 +1,173 @@
+Binding for Silicon Labs Si5338 programmable i2c clock generator.
+
+Reference
+[1] Si5338 Data Sheet
+    http://www.silabs.com/Support%20Documents/TechnicalDocs/Si5338.pdf
+
+The Si5338 is a programmable i2c clock generators with up to 4 output
+clocks. It has 4 sets of possible input clocks
+
+IN1/IN2: differential
+IN3: single-ended
+IN4: single-ended
+IN5/IN6: differential
+
+Additionally, IN1/IN2 can be used as XTAL with different setting.
+The clock tree looks like below (without support of zero-delay)
+
+
+      IN1/IN2 IN3         IN4 IN5/IN6
+         |     |           |     |
+   ------|     |           |     |
+   |     |     |           |     |
+   |     \     /           \     /
+   |      \   /             \   /
+   |       \ /               \ /
+ XTAL     REFCLK            FBCLK
+   |       |  \             /   |
+   |       |   \           /    |
+   |       | DIVREFCLK DIVFBCLK |
+   |       |     \       /      |
+   |       |      \     /       |
+   |       |       \   /        |
+   |       |        PLL         |
+   |       |      / | | \       |
+   |       |     /  / \  \      |
+   |       |    /  /   \  \     |
+   |       |   /   |   |   \    |
+   |       |   |   |   |   |    |
+   |       |  MS0 MS1 MS2 MS3   |
+   |       |   |   |   |   |    |
+
+       OUT0  OUT1  OUT2  OUT3
+
+The output clock can choose from any of the above clock as its source, with
+exceptions: MS1 can only be used for OUT1, MS2 can only be used for OUT2, MS3
+can only be used for OUT3.
+
+==I2C device node==
+
+Required properties:
+- compatible: shall be "silabs,si5338".
+- reg: i2c device address, shall be 0x60, 0x61, 0x70, or 0x71
+- #clock-cells: shall be set to 1 for multiple outputs
+- clocks: list of parent clocks in the order of <xtal>, <in1/2>, <in3>, <in4>, <in5/6>
+          Note, xtal and in1/2 are mutually exclusive. Only one can be set.
+- #address-cells: shall be set to 1.
+- #size-cells: shall be set to 0.
+
+Optional properties if not set by platform driver:
+- silab,ref-source: source of refclk, valid value is defined as
+	#define SI5338_REF_SRC_CLKIN12          0
+	#define SI5338_REF_SRC_CLKIN3           1
+	#define SI5338_REF_SRC_XTAL             4
+- silab,fb-source:  source of fbclk, valid value is defined as
+	#define SI5338_FB_SRC_CLKIN4            2
+	#define SI5338_FB_SRC_CLKIN56           3
+	#define SI5338_FB_SRC_NOCLK             5
+- silabs,pll-source: source of pll, valid value is defined as
+	#define SI5338_PFD_IN_REF_REFCLK           0
+	#define SI5338_PFD_IN_REF_FBCLK            1
+	#define SI5338_PFD_IN_REF_DIVREFCLK        2
+	#define SI5338_PFD_IN_REF_DIVFBCLK         3
+	#define SI5338_PFD_IN_REF_XOCLK            4
+	#define SI5338_PFD_IN_REF_NOCLK            5
+- silabs,pll-master: Pick one MS (0, 1, 2, or 3) to allow chaning PLL rate
+	This is arbitrary since MS0/1/2/3 share one PLL.  PLL can be calculated
+	backward to satisfy MS.
+
+==Child nodes==
+
+Each of the clock outputs can be configured individually by
+using a child node to the I2C device node. If a child node for a clock
+output is not set, platform driver has to set up.
+
+Required child node properties:
+- reg: number of clock output.
+
+Optional child node properties:
+- silabs,drive-config: the configuration of output driver
+  The valid value list is long. Please refer to soruce code.
+- silabs,clock-source: source clock of the output divider
+	#define SI5338_OUT_MUX_FBCLK            0
+	#define SI5338_OUT_MUX_REFCLK           1
+	#deinfe SI5338_OUT_MUX_DIVFBCLK         2
+	#deinfe SI5338_OUT_MUX_DIVREFCLK        3
+	#deinfe SI5338_OUT_MUX_XOCLK            4
+	#deinfe SI5338_OUT_MUX_MS0              5
+	#deinfe SI5338_OUT_MUX_MSN              6 /* MS0/1/2/3 */
+	#deinfe SI5338_OUT_MUX_NOCLK            7
+- silabs,disable-state : clock output disable state, shall be
+	#define SI5338_OUT_DIS_HIZ              0
+	#define SI5338_OUT_DIS_LOW              1
+	#define SI5338_OUT_DIS_HI               2
+	#define SI5338_OUT_DIS_ALWAYS_ON        3
+
+==Example==
+
+/* 25MHz reference crystal */
+ref25: ref25M {
+	compatible = "fixed-clock";
+	#clock-cells = <0>;
+	clock-frequency = <25000000>;
+};
+clkin56: ref100M {
+	compatible = "fixed-clock";
+	#clock-cells = <0>;
+	clock-frequency = <100000000>;
+};
+i2c-master-node {
+	si5338: clock-generator@70 {
+		compatible = "silabs,si5338";
+		reg = <0x70>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		#clock-cells = <1>;
+
+		/* connect xtal to 25MHz, in5/in6 to 100MHz */
+		clocks = <&ref25>, <>, <>, <>, <&clkin56>;
+
+		/* connect xtal as source of refclk */
+		silab,ref-source = <SI5338_REF_SRC_XTAL>;
+
+		/* connect in5/in6 as source of fbclk */
+		silab,fb-source = <SI5338_FB_SRC_CLKIN56>;
+
+		/* connect divrefclk as soruce of pll */
+		silab,pll-source = <SI5338_PFD_IN_REF_DIVREFCLK>;
+
+		/* Choose one MS for pll master */
+		silabs,pll-master = <0>;
+
+		/* output */
+		clkout0 {
+			reg = <0>;
+			silabs,drive-config = "1V8_LVDS";
+			silabs,clock-source = <SI5338_OUT_MUX_MS0>;
+			silabs,disable-state = <SI5338_OUT_DIS_HIZ>;
+			clock-frequency = <125000000>;
+		};
+		clkout1 {
+			reg = <1>;
+			silabs,drive-config = "1V8_LVDS";
+			silabs,clock-source = <SI5338_OUT_MUX_MSN>;
+			silabs,disable-state = <SI5338_OUT_DIS_HIZ>;
+			clock-frequency = <125000000>;
+		};
+		clkout2 {
+			reg = <2>;
+			silabs,drive-config = "1V8_LVDS";
+			silabs,clock-source = <SI5338_OUT_MUX_MSN>;
+			silabs,disable-state = <SI5338_OUT_DIS_HIZ>;
+			clock-frequency = <125000000>;
+		};
+		clkout3 {
+			reg = <3>;
+			silabs,drive-config = "1V8_LVDS";
+			silabs,clock-source = <SI5338_OUT_MUX_MSN>;
+			silabs,disable-state = <SI5338_OUT_DIS_HIZ>;
+			clock-frequency = <125000000>;
+		};
+
+	};
+};
drivers/clk/Kconfig +13 -1
index 0b474a0..07f0b2f 100644
@@ -10,7 +10,7 @@ config HAVE_MACH_CLKDEV
 	bool
 
 config COMMON_CLK
-	bool
+	tristate "Common Clock"
 	select HAVE_CLK_PREPARE
 	select CLKDEV_LOOKUP
 	select SRCU
@@ -78,6 +78,18 @@ config COMMON_CLK_SI570
 	  This driver supports Silicon Labs 570/571/598/599 programmable
 	  clock generators.
 
+config COMMON_CLK_SI5338
+	tristate "Clock driver for SiLabs 5338"
+	depends on I2C
+	select REGMAP_I2C
+	select RATIONAL
+	---help---
+	  This driver supports Silicon Labs 5338 programmable clock generators,
+	  using common clock framework. It needs parent clock as input(s).
+	  Internal clocks are registered with unique names in case multiple
+	  devices exist. See devicetree/bindings/clock/silabs,si5338.txt
+	  under Documentation for details.
+
 config COMMON_CLK_S2MPS11
 	tristate "Clock driver for S2MPS1X/S5M8767 MFD"
 	depends on MFD_SEC_CORE
drivers/clk/Makefile +1 -0
index d478ceb..c6aab0e 100644
@@ -35,6 +35,7 @@ obj-$(CONFIG_COMMON_CLK_PALMAS)		+= clk-palmas.o
 obj-$(CONFIG_CLK_QORIQ)			+= clk-qoriq.o
 obj-$(CONFIG_COMMON_CLK_RK808)		+= clk-rk808.o
 obj-$(CONFIG_COMMON_CLK_S2MPS11)	+= clk-s2mps11.o
+obj-$(CONFIG_COMMON_CLK_SI5338)		+= clk-si5338.o
 obj-$(CONFIG_COMMON_CLK_SI5351)		+= clk-si5351.o
 obj-$(CONFIG_COMMON_CLK_SI570)		+= clk-si570.o
 obj-$(CONFIG_CLK_TWL6040)		+= clk-twl6040.o
drivers/clk/clk-si5338.c new file +3656 -0

2,794 lines not on this page · raw message

drivers/clk/clk-si5338.h new file +305 -0

305 lines not on this page · raw message

include/dt-bindings/clock/clk-si5338.h new file +69 -0

69 lines not on this page · raw message

include/linux/platform_data/si5338.h new file +49 -0

49 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.9.5

Part of the diff is not shown here. View the raw message.

#1 lore raw

One question and a few nits follow.

Quoted 9 lines · York Sun

SI5338 is a programmable clock generator. It has 4 sets of inputs, PLL, multisynth and dividers to make 4 outputs. This driver splits them into multiple clocks to comply with common clock framework.

See Documentation/devicetree/bindings/clock/silabs,si5338.txt for details.

CC Mike Turquette <[email protected]>

Apparently that's now [email protected] .

drivers/clk/Kconfig config HAVE_MACH_CLKDEV · line 16

Quoted 13 lines
CC Sebastian Hesselbarth <[email protected]>
CC Guenter Roeck <[email protected]>
CC Andrey Filippov <[email protected]>
drivers/clk/Kconfig +1 -1
 
 config COMMON_CLK
-	bool
+	tristate "Common Clock"
 	select HAVE_CLK_PREPARE
 	select CLKDEV_LOOKUP
 	select SRCU

Why? The commit explanation doesn't mention this. Did you use an unclean tree? If not, you just created over a dozen of new modules:

    $ git grep -nw CONFIG_COMMON_CLK -- "*Makefile*"
    arch/arm/mach-mmp/Makefile:13:ifeq ($(CONFIG_COMMON_CLK), )
    arch/arm/mach-shmobile/Makefile:21:ifndef CONFIG_COMMON_CLK
    arch/powerpc/platforms/512x/Makefile:4:obj-$(CONFIG_COMMON_CLK) += clock-commonclk.o
    drivers/clk/Makefile:4:obj-$(CONFIG_COMMON_CLK) += clk.o
    drivers/clk/Makefile:5:obj-$(CONFIG_COMMON_CLK) += clk-divider.o
    drivers/clk/Makefile:6:obj-$(CONFIG_COMMON_CLK) += clk-fixed-factor.o
    drivers/clk/Makefile:7:obj-$(CONFIG_COMMON_CLK) += clk-fixed-rate.o
    drivers/clk/Makefile:8:obj-$(CONFIG_COMMON_CLK) += clk-gate.o
    drivers/clk/Makefile:9:obj-$(CONFIG_COMMON_CLK) += clk-mux.o
    drivers/clk/Makefile:10:obj-$(CONFIG_COMMON_CLK)        += clk-composite.o
    drivers/clk/Makefile:11:obj-$(CONFIG_COMMON_CLK)        += clk-fractional-divider.o
    drivers/clk/Makefile:12:obj-$(CONFIG_COMMON_CLK)        += clk-gpio-gate.o
    drivers/clk/Makefile:14:obj-$(CONFIG_COMMON_CLK)        += clk-conf.o
    drivers/clk/Makefile:59:ifeq ($(CONFIG_COMMON_CLK), y)
    drivers/clk/samsung/Makefile:5:obj-$(CONFIG_COMMON_CLK) += clk.o clk-pll.o
    drivers/gpu/drm/msm/Makefile:53:msm-$(CONFIG_COMMON_CLK) += mdp/mdp4/mdp4_lvds_pll.o
    drivers/sh/Makefile:5:ifneq ($(CONFIG_COMMON_CLK),y)
Quoted 14 lines
drivers/clk/Kconfig +11 -0
+config COMMON_CLK_SI5338
+	tristate "Clock driver for SiLabs 5338"
+	depends on I2C
+	select REGMAP_I2C
+	select RATIONAL
+	---help---
+	  This driver supports Silicon Labs 5338 programmable clock generators,
+	  using common clock framework. It needs parent clock as input(s).
+	  Internal clocks are registered with unique names in case multiple
+	  devices exist. See devicetree/bindings/clock/silabs,si5338.txt
+	  under Documentation for details.

drivers/clk/clk-si5338.c line 692

Quoted 6 lines
drivers/clk/clk-si5338.c new file +5 -0
 
+unsigned long si5338_divrefclk_recalc_rate(struct clk_hw *hw,
+					   unsigned long parent_rate)
+{
+	[...]
+}

Can't this be made static? It compiles cleanly with static too. Is there some subtle issue I'm missing?

drivers/clk/clk-si5338.c line 738

Quoted 9 lines
drivers/clk/clk-si5338.c new file +8 -0
+static const struct clk_ops si5338_divrefclk_ops = {
+	.recalc_rate = si5338_divrefclk_recalc_rate,
+};
 
+unsigned long si5338_divfbclk_recalc_rate(struct clk_hw *hw,
+					   unsigned long parent_rate)
+{
+	[...]
+}

Ditto.

include/dt-bindings/clock/clk-si5338.h line 21

Quoted 9 lines
drivers/clk/clk-si5338.c new file +3 -0
+static const struct clk_ops si5338_divfbclk_ops = {
+	.recalc_rate = si5338_divfbclk_recalc_rate,
+};
include/dt-bindings/clock/clk-si5338.h new file +2 -0
 
+#ifndef _DT_BINDINGS_CLK_DSI5338_H
+#define _DT_BINDINGS_CLK_DSI5338_H

(I spotted a D that looks odd here.)

And git am whines:
new blank line at EOF.

Thanks,

Paul Bolle

author
#2 lore raw

Paul,

Thanks for reviewing.

Quoted 7 lines · Paul Bolle

One question and a few nits follow.

Quoted 4 lines · York Sun

SI5338 is a programmable clock generator. It has 4 sets of inputs, PLL, multisynth and dividers to make 4 outputs. This driver splits them into multiple clocks to comply with common clock framework.

Quoted 7 lines
Quoted 5 lines

See Documentation/devicetree/bindings/clock/silabs,si5338.txt for details.

CC Mike Turquette <[email protected]>

Apparently that's now mturquette-rdvid1DuHRBWk0Htik3J/[email protected] .

Thanks. Will change.

Quoted 8 lines
Quoted 7 lines
CC Sebastian Hesselbarth <[email protected]>
CC Guenter Roeck <[email protected]>
CC Andrey Filippov <[email protected]>
drivers/clk/Kconfig +0 -0
Quoted 9 lines

drivers/clk/Kconfig config HAVE_MACH_CLKDEV · line 16

Quoted 6 lines

config COMMON_CLK

drivers/clk/Kconfig +1 -1
-	bool
+	tristate "Common Clock"
 	select HAVE_CLK_PREPARE
 	select CLKDEV_LOOKUP
 	select SRCU

Why? The commit explanation doesn't mention this. Did you use an unclean tree? If not, you just created over a dozen of new modules:

Thanks for catching this. I was testing building the driver within and outside of kernel tree for another kernel version. If this driver is built-in, I don't need to make it tristate. Will revert in next version.

Quoted 34 lines
    $ git grep -nw CONFIG_COMMON_CLK -- "*Makefile*"
    arch/arm/mach-mmp/Makefile:13:ifeq ($(CONFIG_COMMON_CLK), )
    arch/arm/mach-shmobile/Makefile:21:ifndef CONFIG_COMMON_CLK
    arch/powerpc/platforms/512x/Makefile:4:obj-$(CONFIG_COMMON_CLK) += clock-commonclk.o
    drivers/clk/Makefile:4:obj-$(CONFIG_COMMON_CLK) += clk.o
    drivers/clk/Makefile:5:obj-$(CONFIG_COMMON_CLK) += clk-divider.o
    drivers/clk/Makefile:6:obj-$(CONFIG_COMMON_CLK) += clk-fixed-factor.o
    drivers/clk/Makefile:7:obj-$(CONFIG_COMMON_CLK) += clk-fixed-rate.o
    drivers/clk/Makefile:8:obj-$(CONFIG_COMMON_CLK) += clk-gate.o
    drivers/clk/Makefile:9:obj-$(CONFIG_COMMON_CLK) += clk-mux.o
    drivers/clk/Makefile:10:obj-$(CONFIG_COMMON_CLK)        += clk-composite.o
    drivers/clk/Makefile:11:obj-$(CONFIG_COMMON_CLK)        += clk-fractional-divider.o
    drivers/clk/Makefile:12:obj-$(CONFIG_COMMON_CLK)        += clk-gpio-gate.o
    drivers/clk/Makefile:14:obj-$(CONFIG_COMMON_CLK)        += clk-conf.o
    drivers/clk/Makefile:59:ifeq ($(CONFIG_COMMON_CLK), y)
    drivers/clk/samsung/Makefile:5:obj-$(CONFIG_COMMON_CLK) += clk.o clk-pll.o
    drivers/gpu/drm/msm/Makefile:53:msm-$(CONFIG_COMMON_CLK) += mdp/mdp4/mdp4_lvds_pll.o
    drivers/sh/Makefile:5:ifneq ($(CONFIG_COMMON_CLK),y)
Quoted 14 lines
drivers/clk/Kconfig +11 -0
+config COMMON_CLK_SI5338
+	tristate "Clock driver for SiLabs 5338"
+	depends on I2C
+	select REGMAP_I2C
+	select RATIONAL
+	---help---
+	  This driver supports Silicon Labs 5338 programmable clock generators,
+	  using common clock framework. It needs parent clock as input(s).
+	  Internal clocks are registered with unique names in case multiple
+	  devices exist. See devicetree/bindings/clock/silabs,si5338.txt
+	  under Documentation for details.
drivers/clk/clk-si5338.c new file +0 -0
Quoted 9 lines

drivers/clk/clk-si5338.c line 692

Quoted 5 lines
drivers/clk/clk-si5338.c new file +5 -0
+unsigned long si5338_divrefclk_recalc_rate(struct clk_hw *hw,
+					   unsigned long parent_rate)
+{
+	[...]
+}

Can't this be made static? It compiles cleanly with static too. Is there some subtle issue I'm missing?

Absolutely. I must have missed them for some functions.

Quoted 16 lines

drivers/clk/clk-si5338.c line 738

Quoted 9 lines
drivers/clk/clk-si5338.c new file +8 -0
+static const struct clk_ops si5338_divrefclk_ops = {
+	.recalc_rate = si5338_divrefclk_recalc_rate,
+};
 
+unsigned long si5338_divfbclk_recalc_rate(struct clk_hw *hw,
+					   unsigned long parent_rate)
+{
+	[...]
+}

Ditto.

Quoted 3 lines
drivers/clk/clk-si5338.c new file +3 -0
+static const struct clk_ops si5338_divfbclk_ops = {
+	.recalc_rate = si5338_divfbclk_recalc_rate,
+};
Quoted 7 lines

include/dt-bindings/clock/clk-si5338.h line 21

Quoted 5 lines
include/dt-bindings/clock/clk-si5338.h new file +2 -0
 
+#ifndef _DT_BINDINGS_CLK_DSI5338_H
+#define _DT_BINDINGS_CLK_DSI5338_H

(I spotted a D that looks odd here.)

Me, too. It takes fresh eyes to spot this non-sense error.

Quoted 3 lines

And git am whines:
new blank line at EOF.

Thanks.

York

author
#3 lore raw
Quoted 40 lines · York Sun

Paul,

Thanks for reviewing.

Quoted 7 lines · Paul Bolle

One question and a few nits follow.

Quoted 4 lines · York Sun

SI5338 is a programmable clock generator. It has 4 sets of inputs, PLL, multisynth and dividers to make 4 outputs. This driver splits them into multiple clocks to comply with common clock framework.

Quoted 7 lines
Quoted 5 lines

See Documentation/devicetree/bindings/clock/silabs,si5338.txt for details.

CC Mike Turquette <[email protected]>

Apparently that's now mturquette-rdvid1DuHRBWk0Htik3J/[email protected] .

Thanks. Will change.

Quoted 8 lines
Quoted 7 lines
CC Sebastian Hesselbarth <[email protected]>
CC Guenter Roeck <[email protected]>
CC Andrey Filippov <[email protected]>
drivers/clk/Kconfig +0 -0
Quoted 9 lines

drivers/clk/Kconfig config HAVE_MACH_CLKDEV · line 16

Quoted 6 lines

config COMMON_CLK

drivers/clk/Kconfig +1 -1
-	bool
+	tristate "Common Clock"
 	select HAVE_CLK_PREPARE
 	select CLKDEV_LOOKUP
 	select SRCU

Why? The commit explanation doesn't mention this. Did you use an unclean tree? If not, you just created over a dozen of new modules:

Quoted 4 lines

Thanks for catching this. I was testing building the driver within and outside of kernel tree for another kernel version. If this driver is built-in, I don't need to make it tristate. Will revert in next version.

Now I remember why I did this. COMMON_CLK wasn't an option users can select, because it is a bool and only selected by some platforms. I think it should be a tristate so one can build a driver with it. When it is selected, some drivers are built, either into kernel or as modules, up to user's choice. They are needed by common clock framework.

I should add explanation in commit message. Or separate it into an individual patch. Which one is preferred?

York