Skip to contentSkip to conversation

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

PATCH RESEND Superseded York Sun 2 participants 15 messages Oct 9, 2015 – Oct 21, 2015

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

York Sun

author
#0 lore raw

PATCH RESEND v6 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]>
CC Paul Bolle <[email protected]>

---
This is a resend. I didn't see the v6 patch in mailing list archive.

Change log:
v6: Fix multiline comments style
Add msleep in loop of polling registers
Deal with function return error consistently Remove unnecessary memset calls
Fix calling strncat
Use IS_ERR_OR_NULL when applicable
Add a local function devm_of_clk_get()
Remove clk_put in remove function
Use clkout name in device tree and platform data if set Add warning if name is too long for clkdev
s/if (a == 0)/if (!a)
s/if (a != 0)/if (a)
Remove "if (a) a = 1" and alike
Add dealing with -EPROBE_DEFER for of_clk_get() Prepare the clocks before calling post init as required by HW Update module license to GPL v2 be consistent with header

v5: Rebase to v4.2
Move clk-si5338.h file into clk-si5338.c
Drop unused macros
Add macro HWDATA to replace container_of
Collapse functions for using bsearch
Use return inside switch {}
Separate hardware setting from recalc
Rename variable ms and p123
Remove casting for returns and write_reg
Change device_attr to S_IRUGO
Drop sysfs, use debugfs for output status
Drop exporting __clk_is_prepared
Add "enabled" in device tree binding if the clocks need to be
enabled when driver is loaded
Add enable/disable ops for clock output

v4: Add binding silabs,pll-vco
Set pll rate initial value
Separate COMMON_CLK change from this patch

v3: Add calling unprepare upon removal
Add registering to clkdev so the clk can be acquired when device
tree is not in use
Add a dev_info message when driver is removed
Add missing "static" to two functions in clk-si5338.c Cosmatic fix in dt-bindings.clock/clk-si5338.h

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

---
 .../devicetree/bindings/clock/silabs,si5338.txt    |  188 +
 drivers/clk/Kconfig                                |   12 +
 drivers/clk/Makefile                               |    1 +
 drivers/clk/clk-si5338.c                           | 3826 ++++++++++++++++++++
 include/dt-bindings/clock/clk-si5338.h             |   68 +
 include/linux/platform_data/si5338.h               |   52 +
 6 files changed, 4147 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/silabs,si5338.txt
 create mode 100644 drivers/clk/clk-si5338.c
 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 +188 -0
new file mode 100644
index 0000000..943ac3d
@@ -0,0 +1,188 @@
+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,name-prefix: name prefix for si5338
+        If multiple si5338 chips exist, use name-prefix to form unique names.
+	If omitted, i2c bus name will be used as the prefix.
+- 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.
+- silabs,pll-vco: Specify VCO frequency for optimal ratios for all outputs.
+	If specified, silabs,pll-master is ignored.
+
+==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:
+- name: name for the child node
+        It has to be unique. The name prefix is ignored.
+	If using platform data and the name is not specificed,
+        clkout0/1/2/3 will be used with name prefix.
+- 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
+- enabled: the output is enabled by default
+	The existence of this node enables the output when the driver is loaded
+	otherwise the clock is only enabled when used
+
+==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 source of pll */
+		silab,pll-source = <SI5338_PFD_IN_REF_DIVREFCLK>;
+
+		/* Choose one MS for pll master */
+		silabs,pll-master = <0>;
+
+		/* Specify pll-vco frequency. pll-master is ignored. */
+		silabs,pll-vco = <2450000000>;
+
+		/* 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 +12 -0
index 0269a1c..f10c5d9 100644
@@ -59,6 +59,18 @@ config COMMON_CLK_RK808
 	  clocked at 32KHz each. Clkout1 is always on, Clkout2 can off
 	  by control register.
 
+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_SI5351
 	tristate "Clock driver for SiLabs 5351A/B/C"
 	depends on I2C
drivers/clk/Makefile +1 -0
index c4cf075..f7e5b8d 100644
@@ -36,6 +36,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_COMMON_CLK_CDCE925)	+= clk-cdce925.o
drivers/clk/clk-si5338.c new file +3826 -0

2,787 lines not on this page · raw message

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

68 lines not on this page · raw message

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

52 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
Quoted 14 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]>
CC Sebastian Hesselbarth <[email protected]>
CC Guenter Roeck <[email protected]>
CC Andrey Filippov <[email protected]>
CC Paul Bolle <[email protected]>
Quoted 2 lines

---
This is a resend. I didn't see the v6 patch in mailing list archive.

Can you please refresh this on clk-next? It doesn't compile there. I've added some more nitpicks. I'll look in more detail next week.

drivers/clk/clk-si5338.c line 34

Quoted 9 lines
drivers/clk/clk-si5338.c new file +9 -0
+
+#include <dt-bindings/clock/clk-si5338.h>
+#include <linux/bsearch.h>
+#include <linux/clkdev.h>
+#include <linux/clk-provider.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/freezer.h>

This is used?

drivers/clk/clk-si5338.c line 39

Quoted 5 lines
drivers/clk/clk-si5338.c new file +5 -0
+#include <linux/kernel.h>
+#include <linux/i2c.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>

Is this used?

Quoted 5 lines
drivers/clk/clk-si5338.c new file +5 -0
+#include <linux/platform_data/si5338.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+

[...]

drivers/clk/clk-si5338.c line 2238

Quoted 2 lines
drivers/clk/clk-si5338.c new file +2 -0
+
+static u32 awe_fcal[] = {

const?

drivers/clk/clk-si5338.c line 2245

Quoted 7 lines
drivers/clk/clk-si5338.c new file +7 -0
+	AWE_FCAL_07_00,
+	AWE_FCAL_15_08,
+	AWE_FCAL_17_16,
+	0
+};
+
+static u32 awe_fcal_ovrd[] = {

const?

Quoted 6 lines
drivers/clk/clk-si5338.c new file +6 -0
+	AWE_FCAL_OVRD_07_00,
+	AWE_FCAL_OVRD_15_08,
+	AWE_FCAL_OVRD_17_15,
+	0
+};
+

[..]

Quoted 5 lines
drivers/clk/clk-si5338.c new file +5 -0
+
+static const struct clk_ops si5338_clkout_ops = {
+	.prepare = si5338_clkout_prepare,
+	.unprepare = si5338_clkout_unprepare,
+	.enable = si5338_clkout_enable,

drivers/clk/clk-si5338.c line 2680

Quoted 10 lines
drivers/clk/clk-si5338.c new file +10 -0
+	.disable = si5338_clkout_disable,
+	.set_parent = si5338_clkout_set_parent,
+	.get_parent = si5338_clkout_get_parent,
+	.recalc_rate = si5338_clkout_recalc_rate,
+	.round_rate = si5338_clkout_round_rate,
+	.set_rate = si5338_clkout_set_rate,
+};
+
+#ifdef CONFIG_DEBUG_FS
+#include <linux/debugfs.h>

Just include this at the top unconditionally please.

drivers/clk/clk-si5338.c line 2781

Quoted 8 lines
drivers/clk/clk-si5338.c new file +8 -0
+
+/*
+ * Create debugfs files for status for each si5338 clkout
+ */
+
+static int clkout_status_show(struct seq_file *s, void *data)
+{
+	struct si5338_hw_data *clkout = (struct si5338_hw_data *)s->private;

Useless cast, please remove.

Quoted 6 lines
drivers/clk/clk-si5338.c new file +6 -0
+	struct si5338_driver_data *drvdata = clkout->drvdata;
+	int i, j, match = 0;
+	int drv_type, drv_vdd, drv_trim, drv_invert;
+	int out_src, src_group = 0, src = 0;
+	const int in_numbers[] = {
+		12, 3, 4, 56

[...]

drivers/clk/clk-si5338.c line 2967

Quoted 12 lines
drivers/clk/clk-si5338.c new file +12 -0
+/*
+ * To support multiple si5338 chips, we cannot use devm_clk_get because
+ * each chip has its own clock sources. If device tree is not used,
+ * platform driver should provide these clocks. Let the clocks be freed
+ * automatically when device is unbound. We implement our own devm_of_clk_get.
+ */
+static void devm_of_clk_release(struct device *dev, void *res)
+{
+	clk_put(*(struct clk **)res);
+}
+
+static struct clk *devm_of_clk_get(struct device *dev, struct device_node *np,

What is this? I don't get it at all.

Quoted 10 lines
drivers/clk/clk-si5338.c new file +10 -0
+			    int index)
+{
+	struct clk **ptr, *clk;
+
+	ptr = devres_alloc(devm_of_clk_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	clk = of_clk_get(np, index);
+

[...]

drivers/clk/clk-si5338.c line 3756

Quoted 11 lines
drivers/clk/clk-si5338.c new file +11 -0
+	/*
+	 * Important: Go through the procedure to check PLL locking
+	 * and other steps required by si5338 reference manual.
+	 */
+	ret = post_init(drvdata);
+	if (ret)
+		return ret;
+
+	dev_dbg(&client->dev, "%s clocks are registered\n", id->name);
+
+#ifdef CONFIG_OF

Remove this ifdef

Quoted 6 lines
drivers/clk/clk-si5338.c new file +6 -0
+	ret = of_clk_add_provider(client->dev.of_node,
+				  of_clk_src_onecell_get,
+				  &drvdata->onecell);
+	if (ret) {
+		dev_err(&client->dev, "unable to add clk provider\n");
+		return ret;

[..]

drivers/clk/clk-si5338.c line 3792

Quoted 7 lines
drivers/clk/clk-si5338.c new file +7 -0
+
+static int si5338_i2c_remove(struct i2c_client *client)
+{
+	struct si5338_driver_data *drvdata = i2c_get_clientdata(client);
+	int n;
+
+#ifdef CONFIG_OF

And this one.

Quoted 3 lines
drivers/clk/clk-si5338.c new file +3 -0
+	of_clk_del_provider(client->dev.of_node);
+#endif
+
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#2 lore raw
Quoted 15 lines · Stephen Boyd
Quoted 14 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]>
CC Sebastian Hesselbarth <[email protected]>
CC Guenter Roeck <[email protected]>
CC Andrey Filippov <[email protected]>
CC Paul Bolle <[email protected]>
Quoted 6 lines
Quoted 2 lines

---
This is a resend. I didn't see the v6 patch in mailing list archive.

Can you please refresh this on clk-next? It doesn't compile there. I've added some more nitpicks. I'll look in more detail next week.

I realized some APIs are changed. Will send out a new version once verified.

Quoted 12 lines

drivers/clk/clk-si5338.c line 34

Quoted 10 lines
drivers/clk/clk-si5338.c new file +9 -0
+
+#include <dt-bindings/clock/clk-si5338.h>
+#include <linux/bsearch.h>
+#include <linux/clkdev.h>
+#include <linux/clk-provider.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/freezer.h>

This is used?

Not any more. I will delete it.

Quoted 8 lines

drivers/clk/clk-si5338.c line 39

Quoted 6 lines
drivers/clk/clk-si5338.c new file +5 -0
+#include <linux/kernel.h>
+#include <linux/i2c.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>

Is this used?

Not any more. Will delete it.

Quoted 11 lines
Quoted 6 lines
drivers/clk/clk-si5338.c new file +5 -0
+#include <linux/platform_data/si5338.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+

[...]

drivers/clk/clk-si5338.c line 2238

Quoted 2 lines
drivers/clk/clk-si5338.c new file +2 -0
+
+static u32 awe_fcal[] = {

const?

Sure

Quoted 10 lines

drivers/clk/clk-si5338.c line 2245

Quoted 8 lines
drivers/clk/clk-si5338.c new file +7 -0
+	AWE_FCAL_07_00,
+	AWE_FCAL_15_08,
+	AWE_FCAL_17_16,
+	0
+};
+
+static u32 awe_fcal_ovrd[] = {

const?

OK

Quoted 17 lines
Quoted 7 lines
drivers/clk/clk-si5338.c new file +6 -0
+	AWE_FCAL_OVRD_07_00,
+	AWE_FCAL_OVRD_15_08,
+	AWE_FCAL_OVRD_17_15,
+	0
+};
+

[..]

Quoted 9 lines
drivers/clk/clk-si5338.c new file +9 -0
+
+static const struct clk_ops si5338_clkout_ops = {
+	.prepare = si5338_clkout_prepare,
+	.unprepare = si5338_clkout_unprepare,
+	.enable = si5338_clkout_enable,
+	.disable = si5338_clkout_disable,
+	.set_parent = si5338_clkout_set_parent,
+	.get_parent = si5338_clkout_get_parent,
+	.recalc_rate = si5338_clkout_recalc_rate,
Quoted 8 lines

drivers/clk/clk-si5338.c line 2680

Quoted 6 lines
drivers/clk/clk-si5338.c new file +6 -0
+	.round_rate = si5338_clkout_round_rate,
+	.set_rate = si5338_clkout_set_rate,
+};
+
+#ifdef CONFIG_DEBUG_FS
+#include <linux/debugfs.h>

Just include this at the top unconditionally please.

OK.

Quoted 11 lines

drivers/clk/clk-si5338.c line 2781

Quoted 9 lines
drivers/clk/clk-si5338.c new file +8 -0
+
+/*
+ * Create debugfs files for status for each si5338 clkout
+ */
+
+static int clkout_status_show(struct seq_file *s, void *data)
+{
+	struct si5338_hw_data *clkout = (struct si5338_hw_data *)s->private;

Useless cast, please remove.

OK.

Quoted 8 lines
Quoted 7 lines
drivers/clk/clk-si5338.c new file +6 -0
+	struct si5338_driver_data *drvdata = clkout->drvdata;
+	int i, j, match = 0;
+	int drv_type, drv_vdd, drv_trim, drv_invert;
+	int out_src, src_group = 0, src = 0;
+	const int in_numbers[] = {
+		12, 3, 4, 56

[...]

Quoted 14 lines

drivers/clk/clk-si5338.c line 2967

Quoted 12 lines
drivers/clk/clk-si5338.c new file +12 -0
+/*
+ * To support multiple si5338 chips, we cannot use devm_clk_get because
+ * each chip has its own clock sources. If device tree is not used,
+ * platform driver should provide these clocks. Let the clocks be freed
+ * automatically when device is unbound. We implement our own devm_of_clk_get.
+ */
+static void devm_of_clk_release(struct device *dev, void *res)
+{
+	clk_put(*(struct clk **)res);
+}
+
+static struct clk *devm_of_clk_get(struct device *dev, struct device_node *np,

What is this? I don't get it at all.

Maybe you can help me on this.
We have two ways to get parent clock. One is from device tree, the other is from platform data. When the clock is from platform data, the consumer gets the clock and passes it. The clock will be put by the consumer as well. When the parent clock comes from device tree, what I am trying to do is to call of_clk_get(), without worrying about to call clk_put() later when the driver is removed, so I don't have to know where the parent clock data came from.

Quoted 12 lines
Quoted 11 lines
drivers/clk/clk-si5338.c new file +10 -0
+			    int index)
+{
+	struct clk **ptr, *clk;
+
+	ptr = devres_alloc(devm_of_clk_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	clk = of_clk_get(np, index);
+

[...]

Quoted 13 lines

drivers/clk/clk-si5338.c line 3756

Quoted 11 lines
drivers/clk/clk-si5338.c new file +11 -0
+	/*
+	 * Important: Go through the procedure to check PLL locking
+	 * and other steps required by si5338 reference manual.
+	 */
+	ret = post_init(drvdata);
+	if (ret)
+		return ret;
+
+	dev_dbg(&client->dev, "%s clocks are registered\n", id->name);
+
+#ifdef CONFIG_OF

Remove this ifdef

So we always use OF?

York

#3 lore raw
Quoted 19 lines · York Sun
Quoted 15 lines · Stephen Boyd

drivers/clk/clk-si5338.c line 2967

Quoted 12 lines · York Sun
drivers/clk/clk-si5338.c new file +12 -0
+/*
+ * To support multiple si5338 chips, we cannot use devm_clk_get because
+ * each chip has its own clock sources. If device tree is not used,
+ * platform driver should provide these clocks. Let the clocks be freed
+ * automatically when device is unbound. We implement our own devm_of_clk_get.
+ */
+static void devm_of_clk_release(struct device *dev, void *res)
+{
+	clk_put(*(struct clk **)res);
+}
+
+static struct clk *devm_of_clk_get(struct device *dev, struct device_node *np,

What is this? I don't get it at all.

Quoted 8 lines

Maybe you can help me on this.
We have two ways to get parent clock. One is from device tree, the other is from platform data. When the clock is from platform data, the consumer gets the clock and passes it. The clock will be put by the consumer as well. When the parent clock comes from device tree, what I am trying to do is to call of_clk_get(), without worrying about to call clk_put() later when the driver is removed, so I don't have to know where the parent clock data came from.

This driver should always use clk_get() then. If the mode is device tree, clk_get() will lookup the clock in DT and get it from there. If the mode is platform data, then we'll fallback to the clkdev method of clk_get(), which will look for a clk_lookup created for the device calling clk_get() + the connection id that was provided by the lookup creator. This driver should always call clk_put() on the clock when it's done with it, regardless of DT vs. platform data.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/clk/clk-si5338.c new file +5 -0
+	/*
+	 * Important: Go through the procedure to check PLL locking
+	 * and other steps required by si5338 reference manual.
+	 */
+	ret = post_init(drvdata);
Quoted 8 lines

drivers/clk/clk-si5338.c line 3756

Quoted 6 lines
drivers/clk/clk-si5338.c new file +6 -0
+	if (ret)
+		return ret;
+
+	dev_dbg(&client->dev, "%s clocks are registered\n", id->name);
+
+#ifdef CONFIG_OF

Remove this ifdef

Quoted 1 line

So we always use OF?

No, the function is stubbed out if CONFIG_OF=n so there's no point to the ifdef. The compiler will optimize away the dead code.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#4 lore raw
Quoted 29 lines · Stephen Boyd
Quoted 19 lines · York Sun
Quoted 15 lines · Stephen Boyd

drivers/clk/clk-si5338.c line 2967

Quoted 12 lines · York Sun
drivers/clk/clk-si5338.c new file +12 -0
+/*
+ * To support multiple si5338 chips, we cannot use devm_clk_get because
+ * each chip has its own clock sources. If device tree is not used,
+ * platform driver should provide these clocks. Let the clocks be freed
+ * automatically when device is unbound. We implement our own devm_of_clk_get.
+ */
+static void devm_of_clk_release(struct device *dev, void *res)
+{
+	clk_put(*(struct clk **)res);
+}
+
+static struct clk *devm_of_clk_get(struct device *dev, struct device_node *np,

What is this? I don't get it at all.

Quoted 8 lines

Maybe you can help me on this.
We have two ways to get parent clock. One is from device tree, the other is from platform data. When the clock is from platform data, the consumer gets the clock and passes it. The clock will be put by the consumer as well. When the parent clock comes from device tree, what I am trying to do is to call of_clk_get(), without worrying about to call clk_put() later when the driver is removed, so I don't have to know where the parent clock data came from.

Quoted 9 lines

This driver should always use clk_get() then. If the mode is device tree, clk_get() will lookup the clock in DT and get it from there. If the mode is platform data, then we'll fallback to the clkdev method of clk_get(), which will look for a clk_lookup created for the device calling clk_get() + the connection id that was provided by the lookup creator. This driver should always call clk_put() on the clock when it's done with it, regardless of DT vs. platform data.

For the platform data mode, I think it is up to the consumer to get and put the parent clocks. The current code is to pass (struct clk *) pointers as parent clocks. Are you suggesting to pass the name of parent clocks?

York

#5 lore raw
Quoted 42 lines · York Sun
Quoted 29 lines · Stephen Boyd
Quoted 19 lines · York Sun
Quoted 15 lines · Stephen Boyd

drivers/clk/clk-si5338.c line 2967

Quoted 12 lines · York Sun
drivers/clk/clk-si5338.c new file +12 -0
+/*
+ * To support multiple si5338 chips, we cannot use devm_clk_get because
+ * each chip has its own clock sources. If device tree is not used,
+ * platform driver should provide these clocks. Let the clocks be freed
+ * automatically when device is unbound. We implement our own devm_of_clk_get.
+ */
+static void devm_of_clk_release(struct device *dev, void *res)
+{
+	clk_put(*(struct clk **)res);
+}
+
+static struct clk *devm_of_clk_get(struct device *dev, struct device_node *np,

What is this? I don't get it at all.

Quoted 8 lines

Maybe you can help me on this.
We have two ways to get parent clock. One is from device tree, the other is from platform data. When the clock is from platform data, the consumer gets the clock and passes it. The clock will be put by the consumer as well. When the parent clock comes from device tree, what I am trying to do is to call of_clk_get(), without worrying about to call clk_put() later when the driver is removed, so I don't have to know where the parent clock data came from.

Quoted 9 lines

This driver should always use clk_get() then. If the mode is device tree, clk_get() will lookup the clock in DT and get it from there. If the mode is platform data, then we'll fallback to the clkdev method of clk_get(), which will look for a clk_lookup created for the device calling clk_get() + the connection id that was provided by the lookup creator. This driver should always call clk_put() on the clock when it's done with it, regardless of DT vs. platform data.

Quoted 4 lines

For the platform data mode, I think it is up to the consumer to get and put the parent clocks. The current code is to pass (struct clk *) pointers as parent clocks. Are you suggesting to pass the name of parent clocks?

I'm suggesting to register clocks with clkdev using a device name that matches the consumer. The consumer (this driver?) will simply call clk_get() and clk_put() then, nothing else is needed. I'm not suggesting to pass the names of the parent clocks. It sounds like those are inputs to this device, so we should be calling clk_get() with a device and a connection id to get the clock.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#6 lore raw
Quoted 48 lines · Stephen Boyd
Quoted 42 lines · York Sun
Quoted 29 lines · Stephen Boyd
Quoted 19 lines · York Sun
Quoted 15 lines · Stephen Boyd

drivers/clk/clk-si5338.c line 2967

Quoted 12 lines · York Sun
drivers/clk/clk-si5338.c new file +12 -0
+/*
+ * To support multiple si5338 chips, we cannot use devm_clk_get because
+ * each chip has its own clock sources. If device tree is not used,
+ * platform driver should provide these clocks. Let the clocks be freed
+ * automatically when device is unbound. We implement our own devm_of_clk_get.
+ */
+static void devm_of_clk_release(struct device *dev, void *res)
+{
+	clk_put(*(struct clk **)res);
+}
+
+static struct clk *devm_of_clk_get(struct device *dev, struct device_node *np,

What is this? I don't get it at all.

Quoted 8 lines

Maybe you can help me on this.
We have two ways to get parent clock. One is from device tree, the other is from platform data. When the clock is from platform data, the consumer gets the clock and passes it. The clock will be put by the consumer as well. When the parent clock comes from device tree, what I am trying to do is to call of_clk_get(), without worrying about to call clk_put() later when the driver is removed, so I don't have to know where the parent clock data came from.

Quoted 9 lines

This driver should always use clk_get() then. If the mode is device tree, clk_get() will lookup the clock in DT and get it from there. If the mode is platform data, then we'll fallback to the clkdev method of clk_get(), which will look for a clk_lookup created for the device calling clk_get() + the connection id that was provided by the lookup creator. This driver should always call clk_put() on the clock when it's done with it, regardless of DT vs. platform data.

Quoted 4 lines

For the platform data mode, I think it is up to the consumer to get and put the parent clocks. The current code is to pass (struct clk *) pointers as parent clocks. Are you suggesting to pass the name of parent clocks?

Quoted 8 lines

I'm suggesting to register clocks with clkdev using a device name that matches the consumer. The consumer (this driver?) will simply call clk_get() and clk_put() then, nothing else is needed. I'm not suggesting to pass the names of the parent clocks. It sounds like those are inputs to this device, so we should be calling clk_get() with a device and a connection id to get the clock.

Thanks. I think I mostly understand the idea. Let me try.
BTW, I mean the platform device (or whoever uses the output of the clock) is the clock consumer.

York

author
#7 lore raw
In reply to Stephen Boyd
Quoted 48 lines · Stephen Boyd
Quoted 42 lines · York Sun
Quoted 29 lines · Stephen Boyd
Quoted 19 lines · York Sun
Quoted 15 lines · Stephen Boyd

drivers/clk/clk-si5338.c line 2967

Quoted 12 lines · York Sun
drivers/clk/clk-si5338.c new file +12 -0
+/*
+ * To support multiple si5338 chips, we cannot use devm_clk_get because
+ * each chip has its own clock sources. If device tree is not used,
+ * platform driver should provide these clocks. Let the clocks be freed
+ * automatically when device is unbound. We implement our own devm_of_clk_get.
+ */
+static void devm_of_clk_release(struct device *dev, void *res)
+{
+	clk_put(*(struct clk **)res);
+}
+
+static struct clk *devm_of_clk_get(struct device *dev, struct device_node *np,

What is this? I don't get it at all.

Quoted 8 lines

Maybe you can help me on this.
We have two ways to get parent clock. One is from device tree, the other is from platform data. When the clock is from platform data, the consumer gets the clock and passes it. The clock will be put by the consumer as well. When the parent clock comes from device tree, what I am trying to do is to call of_clk_get(), without worrying about to call clk_put() later when the driver is removed, so I don't have to know where the parent clock data came from.

Quoted 9 lines

This driver should always use clk_get() then. If the mode is device tree, clk_get() will lookup the clock in DT and get it from there. If the mode is platform data, then we'll fallback to the clkdev method of clk_get(), which will look for a clk_lookup created for the device calling clk_get() + the connection id that was provided by the lookup creator. This driver should always call clk_put() on the clock when it's done with it, regardless of DT vs. platform data.

Quoted 4 lines

For the platform data mode, I think it is up to the consumer to get and put the parent clocks. The current code is to pass (struct clk *) pointers as parent clocks. Are you suggesting to pass the name of parent clocks?

Quoted 8 lines

I'm suggesting to register clocks with clkdev using a device name that matches the consumer. The consumer (this driver?) will simply call clk_get() and clk_put() then, nothing else is needed. I'm not suggesting to pass the names of the parent clocks. It sounds like those are inputs to this device, so we should be calling clk_get() with a device and a connection id to get the clock.

Stephen,

I am still having difficulty to implement this. The platform device doesn't know the clock device id when probing the clock chip. For my case, the platform device is a PCIe device, with I2C controller on it. The clock chip is on the I2C bus. When the PCIe device is probed, it registers the parent clocks for si5338 before calling i2c_new_probed_device(). At this moment, the si5338 doesn't have an instance yet. So the parent clock pointer(s) in platform data structure is/are passed.

I have another solution, let the platform data has clk pointer(s). The clock driver for si5338 will use device tree of_clk_get() if device tree is used, or take the pointer(s) from platform data. Upon driver removal, this driver call clk_put() regardless where the pointer(s) came from. The change will be in my platform device driver. It doesn't need to call clk_put again.

Would it be acceptable?

York

#8 lore raw
Quoted 70 lines · York Sun
Quoted 48 lines · Stephen Boyd
Quoted 42 lines · York Sun
Quoted 29 lines · Stephen Boyd
Quoted 19 lines · York Sun
Quoted 15 lines · Stephen Boyd

Review

Quoted 12 lines · York Sun
(quoted diff) +12 -0
+/*
+ * To support multiple si5338 chips, we cannot use devm_clk_get because
+ * each chip has its own clock sources. If device tree is not used,
+ * platform driver should provide these clocks. Let the clocks be freed
+ * automatically when device is unbound. We implement our own devm_of_clk_get.
+ */
+static void devm_of_clk_release(struct device *dev, void *res)
+{
+	clk_put(*(struct clk **)res);
+}
+
+static struct clk *devm_of_clk_get(struct device *dev, struct device_node *np,

What is this? I don't get it at all.

Quoted 8 lines

Maybe you can help me on this.
We have two ways to get parent clock. One is from device tree, the other is from platform data. When the clock is from platform data, the consumer gets the clock and passes it. The clock will be put by the consumer as well. When the parent clock comes from device tree, what I am trying to do is to call of_clk_get(), without worrying about to call clk_put() later when the driver is removed, so I don't have to know where the parent clock data came from.

Quoted 9 lines

This driver should always use clk_get() then. If the mode is device tree, clk_get() will lookup the clock in DT and get it from there. If the mode is platform data, then we'll fallback to the clkdev method of clk_get(), which will look for a clk_lookup created for the device calling clk_get() + the connection id that was provided by the lookup creator. This driver should always call clk_put() on the clock when it's done with it, regardless of DT vs. platform data.

Quoted 4 lines

For the platform data mode, I think it is up to the consumer to get and put the parent clocks. The current code is to pass (struct clk *) pointers as parent clocks. Are you suggesting to pass the name of parent clocks?

Quoted 8 lines

I'm suggesting to register clocks with clkdev using a device name that matches the consumer. The consumer (this driver?) will simply call clk_get() and clk_put() then, nothing else is needed. I'm not suggesting to pass the names of the parent clocks. It sounds like those are inputs to this device, so we should be calling clk_get() with a device and a connection id to get the clock.

Stephen,

I am still having difficulty to implement this. The platform device doesn't know the clock device id when probing the clock chip. For my case, the platform device is a PCIe device, with I2C controller on it. The clock chip is on the I2C bus. When the PCIe device is probed, it registers the parent clocks for si5338 before calling i2c_new_probed_device(). At this moment, the si5338 doesn't have an instance yet. So the parent clock pointer(s) in platform data structure is/are passed.

Quoted 7 lines

I have another solution, let the platform data has clk pointer(s). The clock driver for si5338 will use device tree of_clk_get() if device tree is used, or take the pointer(s) from platform data. Upon driver removal, this driver call clk_put() regardless where the pointer(s) came from. The change will be in my platform device driver. It doesn't need to call clk_put again.

Would it be acceptable?

Sorry I'm a little lost. Where does the platform data come into the picture? Is the i2c driver going to the parent device to get the platform data?

If we have a way to pass data to the si5338 i2c device, then I assume we have a way to get the device name of the i2c device. If that's true, then we can create a clk lookup structure with clkdev_create() in the place where we have the clock pointer and use the dev_name() of the i2c device as the third argument to that function.

BTW, the i2c device doesn't need to call of_clk_get(), it can just call clk_get() and pass the device pointer and it will use the DT path if there's a provider. Please don't use of_clk_get() when a struct device is present.

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

Sorry for top posting. I am on outlook web.

We have no problem with device tree. Let's put it aside.

When device is not used, the platform data is used to hold the data, filled=
by a platform device before probing the clock. For my case, the platform d=
evice is a PCIe device. It is a multifunction device with I2C controller on=
it. The pseudo code looks like

struct i2c_board_info si5338_info[NUM_SI5338_CHIPS] =3D {
        {
                .type =3D "si5338",
                .platform_data =3D &si5338_pdata[0],
        },
        {
                .type =3D "si5338",
                .platform_data =3D &si5338_pdata[1],
        },
        {
                .type =3D "si5338",
                .platform_data =3D &si5338_pdata[2],
        },
        {
                .type =3D "si5338",
                .platform_data =3D &si5338_pdata[3],
        },
};
clk =3D clk_register_fixed_rate(&pdev->dev, "ref25", NULL, CLK_IS_ROOT, 250=
00000);
for (i =3D 0; i < NUM_SI5338_CHIPS; i++) {
    si5338_pdata[i].clk_xtal =3D clk;
    adap =3D i2c_get_adapter(private->i2c_adp->nr + 1 + i);
    private->i2c_client[i] =3D i2c_new_probed_device(adap, &si5338_info[i],=

i2c_si5338_addr, NULL);
}

You can see, when the fixed-rate clock is registered, the device id of si53= 38 is unknown yet. (I am using one 25MHz clock to feed multiple si5338, whe= re maybe I should create multiple 25MHz clocks, but that's another discussi= on.)

I hope I have made it clear.

York

________________________________________
From: Stephen Boyd <[email protected]>
Sent: Monday, October 19, 2015 5:03 PM
To: Sun York-R58495
Cc: [email protected]; [email protected]; Mike Turquette; Sebas= tian Hesselbarth; Guenter Roeck; Andrey Filippov; Paul Bolle
Subject: Re: [Resend Patch v6] driver/clk/clk-si5338: Add common clock fram= ework driver for si5338

Quoted 3 lines

Stephen,

I am still having difficulty to implement this. The platform device doesn=

't know

Quoted 1 line

the clock device id when probing the clock chip. For my case, the platfor=

m

Quoted 1 line

device is a PCIe device, with I2C controller on it. The clock chip is on =

the I2C

Quoted 1 line

bus. When the PCIe device is probed, it registers the parent clocks for s=

i5338

Quoted 1 line

before calling i2c_new_probed_device(). At this moment, the si5338 doesn'=

t have

Quoted 1 line

an instance yet. So the parent clock pointer(s) in platform data structur=

e

Quoted 3 lines

is/are passed.

I have another solution, let the platform data has clk pointer(s). The cl=

ock

Quoted 1 line

driver for si5338 will use device tree of_clk_get() if device tree is use=

d, or

Quoted 1 line

take the pointer(s) from platform data. Upon driver removal, this driver =

call

Quoted 1 line

clk_put() regardless where the pointer(s) came from. The change will be i=

n my

Quoted 3 lines

platform device driver. It doesn't need to call clk_put again.

Would it be acceptable?

Sorry I'm a little lost. Where does the platform data come into the picture? Is the i2c driver going to the parent device to get the platform data?

If we have a way to pass data to the si5338 i2c device, then I assume we have a way to get the device name of the i2c device. If that's true, then we can create a clk lookup structure with clkdev_create() in the place where we have the clock pointer and use the dev_name() of the i2c device as the third argument to that function.

BTW, the i2c device doesn't need to call of_clk_get(), it can just call clk_get() and pass the device pointer and it will use the DT path if there's a provider. Please don't use of_clk_get() when a struct device is present.

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

#10 lore raw
Quoted 31 lines · York Sun

Sorry for top posting. I am on outlook web.

We have no problem with device tree. Let's put it aside.

When device is not used, the platform data is used to hold the data, filled by a platform device before probing the clock. For my case, the platform device is a PCIe device. It is a multifunction device with I2C controller on it. The pseudo code looks like

struct i2c_board_info si5338_info[NUM_SI5338_CHIPS] = {
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[0],
        },
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[1],
        },
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[2],
        },
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[3],
        },
};
clk = clk_register_fixed_rate(&pdev->dev, "ref25", NULL, CLK_IS_ROOT, 25000000);
for (i = 0; i < NUM_SI5338_CHIPS; i++) {
    si5338_pdata[i].clk_xtal = clk;
    adap = i2c_get_adapter(private->i2c_adp->nr + 1 + i);
    private->i2c_client[i] = i2c_new_probed_device(adap, &si5338_info[i], i2c_si5338_addr, NULL);
}
Quoted 3 lines

You can see, when the fixed-rate clock is registered, the device id of si5338 is unknown yet. (I am using one 25MHz clock to feed multiple si5338, where maybe I should create multiple 25MHz clocks, but that's another discussion.)

I hope I have made it clear.

Yes. It would be great if we could modify the i2c framework to let us create an i2c device but not call device_register() until a later time. So something like this could be done in the platform driver:

	for (i = 0; i < NUM_SI5338_CHIPS; i++) {
	     adap = i2c_get_adapter(private->i2c_adp->nr + 1 + i);
	     private->i2c_client[i] = i2c_new_device_unregistered(adap,
	     				&si5338_info[i], i2c_si5338_addr);
	     clkdev_create(clk, NULL, dev_name(private->i2c_client[i]->dev));
	     device_register(private->i2c_client[i]->dev);
	}

Then in the si5338 driver we call devm_clk_get(i2c->dev, NULL) and we get the xtal clock.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#11 lore raw
Quoted 49 lines · Stephen Boyd
Quoted 31 lines · York Sun

Sorry for top posting. I am on outlook web.

We have no problem with device tree. Let's put it aside.

When device is not used, the platform data is used to hold the data, filled by a platform device before probing the clock. For my case, the platform device is a PCIe device. It is a multifunction device with I2C controller on it. The pseudo code looks like

struct i2c_board_info si5338_info[NUM_SI5338_CHIPS] = {
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[0],
        },
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[1],
        },
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[2],
        },
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[3],
        },
};
clk = clk_register_fixed_rate(&pdev->dev, "ref25", NULL, CLK_IS_ROOT, 25000000);
for (i = 0; i < NUM_SI5338_CHIPS; i++) {
    si5338_pdata[i].clk_xtal = clk;
    adap = i2c_get_adapter(private->i2c_adp->nr + 1 + i);
    private->i2c_client[i] = i2c_new_probed_device(adap, &si5338_info[i], i2c_si5338_addr, NULL);
}
Quoted 3 lines

You can see, when the fixed-rate clock is registered, the device id of si5338 is unknown yet. (I am using one 25MHz clock to feed multiple si5338, where maybe I should create multiple 25MHz clocks, but that's another discussion.)

I hope I have made it clear.

Yes. It would be great if we could modify the i2c framework to let us create an i2c device but not call device_register() until a later time. So something like this could be done in the platform driver:

	for (i = 0; i < NUM_SI5338_CHIPS; i++) {
	     adap = i2c_get_adapter(private->i2c_adp->nr + 1 + i);
	     private->i2c_client[i] = i2c_new_device_unregistered(adap,
	     				&si5338_info[i], i2c_si5338_addr);
	     clkdev_create(clk, NULL, dev_name(private->i2c_client[i]->dev));
	     device_register(private->i2c_client[i]->dev);
	}
Quoted 3 lines

Then in the si5338 driver we call devm_clk_get(i2c->dev, NULL) and we get the xtal clock.

Then what do we do before we have this i2c_new_device_unregistered()? Does my proposal make sense?

York

author
#12 lore raw
Quoted 52 lines · York Sun
Quoted 49 lines · Stephen Boyd
Quoted 31 lines · York Sun

Sorry for top posting. I am on outlook web.

We have no problem with device tree. Let's put it aside.

When device is not used, the platform data is used to hold the data, filled by a platform device before probing the clock. For my case, the platform device is a PCIe device. It is a multifunction device with I2C controller on it. The pseudo code looks like

struct i2c_board_info si5338_info[NUM_SI5338_CHIPS] = {
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[0],
        },
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[1],
        },
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[2],
        },
        {
                .type = "si5338",
                .platform_data = &si5338_pdata[3],
        },
};
clk = clk_register_fixed_rate(&pdev->dev, "ref25", NULL, CLK_IS_ROOT, 25000000);
for (i = 0; i < NUM_SI5338_CHIPS; i++) {
    si5338_pdata[i].clk_xtal = clk;
    adap = i2c_get_adapter(private->i2c_adp->nr + 1 + i);
    private->i2c_client[i] = i2c_new_probed_device(adap, &si5338_info[i], i2c_si5338_addr, NULL);
}
Quoted 3 lines

You can see, when the fixed-rate clock is registered, the device id of si5338 is unknown yet. (I am using one 25MHz clock to feed multiple si5338, where maybe I should create multiple 25MHz clocks, but that's another discussion.)

I hope I have made it clear.

Yes. It would be great if we could modify the i2c framework to let us create an i2c device but not call device_register() until a later time. So something like this could be done in the platform driver:

	for (i = 0; i < NUM_SI5338_CHIPS; i++) {
	     adap = i2c_get_adapter(private->i2c_adp->nr + 1 + i);
	     private->i2c_client[i] = i2c_new_device_unregistered(adap,
	     				&si5338_info[i], i2c_si5338_addr);
	     clkdev_create(clk, NULL, dev_name(private->i2c_client[i]->dev));
	     device_register(private->i2c_client[i]->dev);
	}
Quoted 7 lines
Quoted 3 lines

Then in the si5338 driver we call devm_clk_get(i2c->dev, NULL) and we get the xtal clock.

Then what do we do before we have this i2c_new_device_unregistered()? Does my proposal make sense?

Stephen,

How about this? I will use devm_clk_get() when parsing device tree, and still pass clk pointer if using platform data. In this way, I don't have to call clk_put() in the driver to release the parent clocks. The platform device driver is responsible to get the clock and put the clock. It seems reasonable to me. If you don't disagree, I will prepare v7 patch for review.

York

#13 lore raw
In reply to York Sun
Quoted 22 lines · York Sun
Quoted 19 lines · Stephen Boyd
Quoted 4 lines · York Sun

You can see, when the fixed-rate clock is registered, the device id of si5338 is unknown yet. (I am using one 25MHz clock to feed multiple si5338, where maybe I should create multiple 25MHz clocks, but that's another discussion.)

I hope I have made it clear.

Yes. It would be great if we could modify the i2c framework to let us create an i2c device but not call device_register() until a later time. So something like this could be done in the platform driver:

	for (i = 0; i < NUM_SI5338_CHIPS; i++) {
	     adap = i2c_get_adapter(private->i2c_adp->nr + 1 + i);
	     private->i2c_client[i] = i2c_new_device_unregistered(adap,
	     				&si5338_info[i], i2c_si5338_addr);
	     clkdev_create(clk, NULL, dev_name(private->i2c_client[i]->dev));
	     device_register(private->i2c_client[i]->dev);
	}
Quoted 6 lines
Quoted 3 lines

Then in the si5338 driver we call devm_clk_get(i2c->dev, NULL) and we get the xtal clock.

Then what do we do before we have this i2c_new_device_unregistered()? Does my proposal make sense?

There's nothing to do before we make this new API. Make a patch to add the new API, and then use it in the pcie driver. Your proposal makes sense, but it isn't necessary or desirable.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#14 lore raw
Quoted 27 lines · Stephen Boyd
Quoted 26 lines · York Sun
Quoted 22 lines · Stephen Boyd
Quoted 4 lines · York Sun

You can see, when the fixed-rate clock is registered, the device id of si5338 is unknown yet. (I am using one 25MHz clock to feed multiple si5338, where maybe I should create multiple 25MHz clocks, but that's another discussion.)

I hope I have made it clear.

Yes. It would be great if we could modify the i2c framework to let us create an i2c device but not call device_register() until a later time. So something like this could be done in the platform driver:

	for (i = 0; i < NUM_SI5338_CHIPS; i++) {
	     adap = i2c_get_adapter(private->i2c_adp->nr + 1 + i);
	     private->i2c_client[i] = i2c_new_device_unregistered(adap,
	     				&si5338_info[i], i2c_si5338_addr);
	     clkdev_create(clk, NULL, dev_name(private->i2c_client[i]->dev));
	     device_register(private->i2c_client[i]->dev);
	}

Then in the si5338 driver we call devm_clk_get(i2c->dev, NULL) and we get the xtal clock.

Quoted 7 lines
Quoted 2 lines

Then what do we do before we have this i2c_new_device_unregistered()? Does my proposal make sense?

There's nothing to do before we make this new API. Make a patch to add the new API, and then use it in the pcie driver. Your proposal makes sense, but it isn't necessary or desirable.

Stephen,

I am making progress on this direction, but need your guidance on one matter.

When device tree is used, devm_clk_get() generates a pr_err if the clock doesn't exist. For si5338, it can have one/two/three/four parent clocks. Missing some clocks shouldn't be treated as an error. It works but the message is confusing and annoying. I am thinking to add flags to mark unused clocks when parsing device tree. Please let me know if it is a bad idea.

York