Skip to contentSkip to conversation

clk: vc5: Prevent division by zero on unconfigured outputs

PATCH In review Marek Vasut 4 participants 16 messages Jun 29, 2017 – Jul 1, 2017

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

PATCH 1/8 clk: vc5: Prevent division by zero on unconfigured outputs

From: Marek Vasut <[email protected]>

In case the initial values of the FOD registers are not configured in the OTP or by the bootloader, it is possible that the FOD registers will contain zeroes. The code in vc5_fod_recalc_rate() immediately feeds the FOD divider value obtained from the FOD registers into the div64_u64() and if the FOD divider value is zero, triggers division by zero exception.

Check if the FOD divider value is zero and return the frequency of the FOD output as 0 Hz if it is so. This prevents the division by zero exception.

Cc Stephen Boyd <[email protected]>
Cc Alexey Firago <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 drivers/clk/clk-versaclock5.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/clk/clk-versaclock5.c +4 -0
index ea7d552a2f2b..60bf4afb51bd 100644
@@ -426,6 +426,10 @@ static unsigned long vc5_fod_recalc_rate(struct clk_hw *hw,
 	div_frc = (od_frc[0] << 22) | (od_frc[1] << 14) |
 		  (od_frc[2] << 6) | (od_frc[3] >> 2);
 
+	/* Avoid division by zero if the output is not configured. */
+	if ((div_int == 0) && (div_frc == 0))
+		return 0;
+
 	/* The PLL divider has 12 integer bits and 30 fractional bits */
 	return div64_u64((u64)f_in << 24ULL, ((u64)div_int << 24ULL) + div_frc);
 }
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/8 clk: vc5: Fix trivial typo

From: Marek Vasut <[email protected]>

Fix trivial typo in vc5_clk_out_unprepare() , s/Enable/Disable/ .

Cc Stephen Boyd <[email protected]>
Cc Alexey Firago <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 drivers/clk/clk-versaclock5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk-versaclock5.c +1 -1
index 60bf4afb51bd..d835d48cf14d 100644
@@ -520,7 +520,7 @@ static void vc5_clk_out_unprepare(struct clk_hw *hw)
 	struct vc5_hw_data *hwdata = container_of(hw, struct vc5_hw_data, hw);
 	struct vc5_driver_data *vc5 = hwdata->vc5;
 
-	/* Enable the clock buffer */
+	/* Disable the clock buffer */
 	regmap_update_bits(vc5->regmap, VC5_CLK_OUTPUT_CFG(hwdata->num, 1),
 			   VC5_CLK_OUTPUT_CFG1_EN_CLKBUF, 0);
 }
Signature · 1 line
2.11.0
#2 lore raw

PATCH 3/8 clk: vc5: Do not warn about disabled output buffer input muxes

In reply to Marek Vasut

From: Marek Vasut <[email protected]>

The output buffer input mux can be configured in either of three states -- disabled, input from FOD, input from previous output. If the output buffer input mux is set to disabled, the code in vc5_clk_out_get_parent() would consider this an invalid setting and warn about it, which is not necessarily the case.

In case the output buffer input mux is disabled, default to input from FOD to have some parent and don't print the warning.

Cc Stephen Boyd <[email protected]>
Cc Alexey Firago <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 drivers/clk/clk-versaclock5.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/clk/clk-versaclock5.c +4 -0
index d835d48cf14d..766fcc5cc0b3 100644
@@ -541,6 +541,9 @@ static unsigned char vc5_clk_out_get_parent(struct clk_hw *hw)
 	regmap_read(vc5->regmap, VC5_OUT_DIV_CONTROL(hwdata->num), &src);
 	src &= mask;
 
+	if (src == 0)	/* Input mux set to DISABLED */
+		return 0;
+
 	if ((src & fodclkmask) == VC5_OUT_DIV_CONTROL_EN_FOD)
 		return 0;
 
@@ -549,6 +552,7 @@ static unsigned char vc5_clk_out_get_parent(struct clk_hw *hw)
 
 	dev_warn(&vc5->client->dev,
 		 "Invalid clock output configuration (%02x)\n", src);
+
 	return 0;
 }
 
Signature · 1 line
2.11.0
#3 lore raw

Re: [PATCH 3/8] clk: vc5: Do not warn about disabled output buffer input muxes

drivers/clk/clk-versaclock5.c static unsigned char vc5_clk_out_get_parent(struct clk_hw *hw) · line 558

Quoted 8 lines · Marek Vasut
drivers/clk/clk-versaclock5.c +1 -0
@@ -549,6 +552,7 @@ static unsigned char vc5_clk_out_get_parent(struct clk_hw *hw)
 
 	dev_warn(&vc5->client->dev,
 		 "Invalid clock output configuration (%02x)\n", src);
+
 	return 0;
 }
 

Please drop this hunk as it isn't relevant to the patch.

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

Re: [PATCH 3/8] clk: vc5: Do not warn about disabled output buffer input muxes

Quoted 12 lines · Stephen Boyd

drivers/clk/clk-versaclock5.c static unsigned char vc5_clk_out_get_parent(struct clk_hw *hw) · line 558

Quoted 8 lines · Marek Vasut
drivers/clk/clk-versaclock5.c +1 -0
@@ -549,6 +552,7 @@ static unsigned char vc5_clk_out_get_parent(struct clk_hw *hw)
 
 	dev_warn(&vc5->client->dev,
 		 "Invalid clock output configuration (%02x)\n", src);
+
 	return 0;
 }
 

Please drop this hunk as it isn't relevant to the patch.

Done in V2, thanks.

Signature · 2 lines
Best regards,
Marek Vasut
#5 lore raw

PATCH 4/8 clk: vc5: Configure the output buffer input mux on prepare

In reply to Marek Vasut

From: Marek Vasut <[email protected]>

The output buffer input mux can be configured in either of three states -- disabled, input from FOD, input from previous output. Once the .prepare() callback of the output buffer is called, the output buffer input mux must be set to either input from FOD or input from previous output, it cannot be set to Disabled anymore or the output won't work.

Default to the input from FOD if the output buffer input mux was Disabled and the .prepare() was called on it.

Note that we do not set the output buffer input mux back to Disabled in the .unprepare() callback as there is no obvious benefit of doing so. We disable the entire output buffer in the .unprepare() callback already.

Cc Stephen Boyd <[email protected]>
Cc Alexey Firago <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 drivers/clk/clk-versaclock5.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/clk/clk-versaclock5.c +19 -0
index 766fcc5cc0b3..a5256f793627 100644
@@ -507,6 +507,25 @@ static int vc5_clk_out_prepare(struct clk_hw *hw)
 {
 	struct vc5_hw_data *hwdata = container_of(hw, struct vc5_hw_data, hw);
 	struct vc5_driver_data *vc5 = hwdata->vc5;
+	const u8 mask = VC5_OUT_DIV_CONTROL_SELB_NORM |
+			VC5_OUT_DIV_CONTROL_SEL_EXT |
+			VC5_OUT_DIV_CONTROL_EN_FOD;
+	unsigned int src;
+	int ret;
+
+	/*
+	 * If the input mux is disabled, enable it first and
+	 * select source from matching FOD.
+	 */
+	regmap_read(vc5->regmap, VC5_OUT_DIV_CONTROL(hwdata->num), &src);
+	if ((src & mask) == 0) {
+		src = VC5_OUT_DIV_CONTROL_RESET | VC5_OUT_DIV_CONTROL_EN_FOD;
+		ret = regmap_update_bits(vc5->regmap,
+					 VC5_OUT_DIV_CONTROL(hwdata->num),
+					 mask | VC5_OUT_DIV_CONTROL_RESET, src);
+		if (ret)
+			return ret;
+	}
 
 	/* Enable the clock buffer */
 	regmap_update_bits(vc5->regmap, VC5_CLK_OUTPUT_CFG(hwdata->num, 1),
Signature · 1 line
2.11.0
#6 lore raw

PATCH 5/8 clk: vc5: Split clock input mux and predivider

In reply to Marek Vasut

From: Marek Vasut <[email protected]>

Split the VC5 clock input mux and the predivider to more accurately model the hardware and fix the previously incorrect assumption that both the OUT_SEL_I2CB and the PLL are fed from the predivider.

It is in fact the clock input mux output which is directly feeding the clock into the OUT_SEL_I2CB output, while the clock input mux output first passes through the predivider before it is fed into the PLL.

Cc Stephen Boyd <[email protected]>
Cc Alexey Firago <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 drivers/clk/clk-versaclock5.c | 46 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 12 deletions(-)
drivers/clk/clk-versaclock5.c +34 -12
index a5256f793627..fcde42393997 100644
@@ -157,6 +157,7 @@ struct vc5_driver_data {
 	struct clk		*pin_clkin;
 	unsigned char		clk_mux_ins;
 	struct clk_hw		clk_mux;
+	struct clk_hw		clk_pfd;
 	struct vc5_hw_data	clk_pll;
 	struct vc5_hw_data	clk_fod[VC5_MAX_FOD_NUM];
 	struct vc5_hw_data	clk_out[VC5_MAX_CLK_OUT_NUM];
@@ -166,6 +167,10 @@ static const char * const vc5_mux_names[] = {
 	"mux"
 };
 
+static const char * const vc5_pfd_names[] = {
+	"pfd"
+};
+
 static const char * const vc5_pll_names[] = {
 	"pll"
 };
@@ -254,11 +259,16 @@ static int vc5_mux_set_parent(struct clk_hw *hw, u8 index)
 	return regmap_update_bits(vc5->regmap, VC5_PRIM_SRC_SHDN, mask, src);
 }
 
-static unsigned long vc5_mux_recalc_rate(struct clk_hw *hw,
+static const struct clk_ops vc5_mux_ops = {
+	.set_parent	= vc5_mux_set_parent,
+	.get_parent	= vc5_mux_get_parent,
+};
+
+static unsigned long vc5_pfd_recalc_rate(struct clk_hw *hw,
 					 unsigned long parent_rate)
 {
 	struct vc5_driver_data *vc5 =
-		container_of(hw, struct vc5_driver_data, clk_mux);
+		container_of(hw, struct vc5_driver_data, clk_pfd);
 	unsigned int prediv, div;
 
 	regmap_read(vc5->regmap, VC5_VCO_CTRL_AND_PREDIV, &prediv);
@@ -276,7 +286,7 @@ static unsigned long vc5_mux_recalc_rate(struct clk_hw *hw,
 		return parent_rate / VC5_REF_DIVIDER_REF_DIV(div);
 }
 
-static long vc5_mux_round_rate(struct clk_hw *hw, unsigned long rate,
+static long vc5_pfd_round_rate(struct clk_hw *hw, unsigned long rate,
 			       unsigned long *parent_rate)
 {
 	unsigned long idiv;
@@ -296,11 +306,11 @@ static long vc5_mux_round_rate(struct clk_hw *hw, unsigned long rate,
 	return *parent_rate / idiv;
 }
 
-static int vc5_mux_set_rate(struct clk_hw *hw, unsigned long rate,
+static int vc5_pfd_set_rate(struct clk_hw *hw, unsigned long rate,
 			    unsigned long parent_rate)
 {
 	struct vc5_driver_data *vc5 =
-		container_of(hw, struct vc5_driver_data, clk_mux);
+		container_of(hw, struct vc5_driver_data, clk_pfd);
 	unsigned long idiv;
 	u8 div;
 
@@ -328,12 +338,10 @@ static int vc5_mux_set_rate(struct clk_hw *hw, unsigned long rate,
 	return 0;
 }
 
-static const struct clk_ops vc5_mux_ops = {
-	.set_parent	= vc5_mux_set_parent,
-	.get_parent	= vc5_mux_get_parent,
-	.recalc_rate	= vc5_mux_recalc_rate,
-	.round_rate	= vc5_mux_round_rate,
-	.set_rate	= vc5_mux_set_rate,
+static const struct clk_ops vc5_pfd_ops = {
+	.recalc_rate	= vc5_pfd_recalc_rate,
+	.round_rate	= vc5_pfd_round_rate,
+	.set_rate	= vc5_pfd_set_rate,
 };
 
 /*
@@ -699,12 +707,26 @@ static int vc5_probe(struct i2c_client *client,
 		goto err_clk;
 	}
 
+	/* Register PFD */
+	memset(&init, 0, sizeof(init));
+	init.name = vc5_pfd_names[0];
+	init.ops = &vc5_pfd_ops;
+	init.flags = CLK_SET_RATE_PARENT;
+	init.parent_names = vc5_mux_names;
+	init.num_parents = 1;
+	vc5->clk_pfd.init = &init;
+	ret = devm_clk_hw_register(&client->dev, &vc5->clk_pfd);
+	if (ret) {
+		dev_err(&client->dev, "unable to register %s\n", init.name);
+		goto err_clk;
+	}
+
 	/* Register PLL */
 	memset(&init, 0, sizeof(init));
 	init.name = vc5_pll_names[0];
 	init.ops = &vc5_pll_ops;
 	init.flags = CLK_SET_RATE_PARENT;
-	init.parent_names = vc5_mux_names;
+	init.parent_names = vc5_pfd_names;
 	init.num_parents = 1;
 	vc5->clk_pll.num = 0;
 	vc5->clk_pll.vc5 = vc5;
Signature · 1 line
2.11.0
#7 lore raw

PATCH 6/8 clk: vc5: Add support for the input frequency doubler

In reply to Marek Vasut

From: Marek Vasut <[email protected]>

The VersaClock 6 has an input frequency doubler between the input clock mux and the predivider. Add new capability flag and support for this frequency doubler block into the driver.

Cc Stephen Boyd <[email protected]>
Cc Alexey Firago <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 drivers/clk/clk-versaclock5.c | 78 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 77 insertions(+), 1 deletion(-)
drivers/clk/clk-versaclock5.c +77 -1
index fcde42393997..6db84358520a 100644
@@ -57,6 +57,7 @@
 #define VC5_PRIM_SRC_SHDN			0x10
 #define VC5_PRIM_SRC_SHDN_EN_XTAL		BIT(7)
 #define VC5_PRIM_SRC_SHDN_EN_CLKIN		BIT(6)
+#define VC5_PRIM_SRC_SHDN_EN_DOUBLE_XTAL_FREQ	BIT(3)
 #define VC5_PRIM_SRC_SHDN_SP			BIT(1)
 #define VC5_PRIM_SRC_SHDN_EN_GBL_SHDN		BIT(0)
 
@@ -122,6 +123,8 @@
 /* flags to describe chip features */
 /* chip has built-in oscilator */
 #define VC5_HAS_INTERNAL_XTAL	BIT(0)
+/* chip has PFD requency doubler */
+#define VC5_HAS_PFD_FREQ_DBL	BIT(1)
 
 /* Supported IDT VC5 models. */
 enum vc5_model {
@@ -157,6 +160,7 @@ struct vc5_driver_data {
 	struct clk		*pin_clkin;
 	unsigned char		clk_mux_ins;
 	struct clk_hw		clk_mux;
+	struct clk_hw		clk_mul;
 	struct clk_hw		clk_pfd;
 	struct vc5_hw_data	clk_pll;
 	struct vc5_hw_data	clk_fod[VC5_MAX_FOD_NUM];
@@ -167,6 +171,10 @@ static const char * const vc5_mux_names[] = {
 	"mux"
 };
 
+static const char * const vc5_dbl_names[] = {
+	"dbl"
+};
+
 static const char * const vc5_pfd_names[] = {
 	"pfd"
 };
@@ -264,6 +272,54 @@ static const struct clk_ops vc5_mux_ops = {
 	.get_parent	= vc5_mux_get_parent,
 };
 
+static unsigned long vc5_dbl_recalc_rate(struct clk_hw *hw,
+					 unsigned long parent_rate)
+{
+	struct vc5_driver_data *vc5 =
+		container_of(hw, struct vc5_driver_data, clk_mul);
+	unsigned int premul;
+
+	regmap_read(vc5->regmap, VC5_PRIM_SRC_SHDN, &premul);
+	if (premul & VC5_PRIM_SRC_SHDN_EN_DOUBLE_XTAL_FREQ)
+		parent_rate *= 2;
+
+	return parent_rate;
+}
+
+static long vc5_dbl_round_rate(struct clk_hw *hw, unsigned long rate,
+			       unsigned long *parent_rate)
+{
+	if ((*parent_rate == rate) || ((*parent_rate * 2) == rate))
+		return rate;
+	else
+		return -EINVAL;
+}
+
+static int vc5_dbl_set_rate(struct clk_hw *hw, unsigned long rate,
+			    unsigned long parent_rate)
+{
+	struct vc5_driver_data *vc5 =
+		container_of(hw, struct vc5_driver_data, clk_mul);
+	u32 mask;
+
+	if ((parent_rate * 2) == rate)
+		mask = VC5_PRIM_SRC_SHDN_EN_DOUBLE_XTAL_FREQ;
+	else
+		mask = 0;
+
+	regmap_update_bits(vc5->regmap, VC5_PRIM_SRC_SHDN,
+			   VC5_PRIM_SRC_SHDN_EN_DOUBLE_XTAL_FREQ,
+			   mask);
+
+	return 0;
+}
+
+static const struct clk_ops vc5_dbl_ops = {
+	.recalc_rate	= vc5_dbl_recalc_rate,
+	.round_rate	= vc5_dbl_round_rate,
+	.set_rate	= vc5_dbl_set_rate,
+};
+
 static unsigned long vc5_pfd_recalc_rate(struct clk_hw *hw,
 					 unsigned long parent_rate)
 {
@@ -707,12 +763,32 @@ static int vc5_probe(struct i2c_client *client,
 		goto err_clk;
 	}
 
+	if (vc5->chip_info->flags & VC5_HAS_PFD_FREQ_DBL) {
+		/* Register frequency doubler */
+		memset(&init, 0, sizeof(init));
+		init.name = vc5_dbl_names[0];
+		init.ops = &vc5_dbl_ops;
+		init.flags = CLK_SET_RATE_PARENT;
+		init.parent_names = vc5_mux_names;
+		init.num_parents = 1;
+		vc5->clk_mul.init = &init;
+		ret = devm_clk_hw_register(&client->dev, &vc5->clk_mul);
+		if (ret) {
+			dev_err(&client->dev, "unable to register %s\n",
+				init.name);
+			goto err_clk;
+		}
+	}
+
 	/* Register PFD */
 	memset(&init, 0, sizeof(init));
 	init.name = vc5_pfd_names[0];
 	init.ops = &vc5_pfd_ops;
 	init.flags = CLK_SET_RATE_PARENT;
-	init.parent_names = vc5_mux_names;
+	if (vc5->chip_info->flags & VC5_HAS_PFD_FREQ_DBL)
+		init.parent_names = vc5_dbl_names;
+	else
+		init.parent_names = vc5_mux_names;
 	init.num_parents = 1;
 	vc5->clk_pfd.init = &init;
 	ret = devm_clk_hw_register(&client->dev, &vc5->clk_pfd);
Signature · 1 line
2.11.0
#8 lore raw

PATCH 7/8 clk: vc5: Add bindings for IDT VersaClock 5P49V6901

In reply to Marek Vasut

From: Marek Vasut <[email protected]>

IDT VersaClock 6 5P49V6901 has 4 clock outputs, 4 fractional dividers. Input clock source can be taken from either external crystal or from external reference clock.

Cc Alexey Firago <[email protected]>
Cc Rob Herring <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 .../devicetree/bindings/clock/idt,versaclock5.txt         | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/clock/idt,versaclock5.txt +12 -3
index 53d7e50ed875..a3d4260039a8 100644
@@ -7,18 +7,20 @@ from 3 to 12 output clocks.
 
 Required properties:
 - compatible:	shall be one of "idt,5p49v5923" , "idt,5p49v5933" ,
-		"idt,5p49v5935".
+		"idt,5p49v5935" , "idt,5p49v6901".
 - reg:		i2c device address, shall be 0x68 or 0x6a.
 - #clock-cells:	from common clock binding; shall be set to 1.
 - clocks:	from common clock binding; list of parent clock handles,
-		- 5p49v5923: (required) either or both of XTAL or CLKIN
+		- 5p49v5923 and
+		  5p49v6901: (required) either or both of XTAL or CLKIN
 					reference clock.
 		- 5p49v5933 and
 		- 5p49v5935: (optional) property not present (internal
 					Xtal used) or CLKIN reference
 					clock.
 - clock-names:	from common clock binding; clock input names, can be
-		- 5p49v5923: (required) either or both of "xin", "clkin".
+		- 5p49v5923 and
+		  5p49v6901: (required) either or both of "xin", "clkin".
 		- 5p49v5933 and
 		- 5p49v5935: (optional) property not present or "clkin".
 
@@ -44,6 +46,13 @@ clock specifier, the following mapping applies:
 	3 -- OUT3
 	4 -- OUT4
 
+5P49V6901:
+	0 -- OUT0_SEL_I2CB
+	1 -- OUT1
+	2 -- OUT2
+	3 -- OUT3
+	4 -- OUT4
+
 ==Example==
 
 /* 25MHz reference crystal */
Signature · 1 line
2.11.0
Acked-by on v1 7/8
#9 lore raw

Re: [PATCH 7/8] clk: vc5: Add bindings for IDT VersaClock 5P49V6901

Hi Marek,

Documentation/devicetree/bindings/clock/idt,versaclock5.txt

Quoted 22 lines · Marek Vasut

From: Marek Vasut <[email protected]>

IDT VersaClock 6 5P49V6901 has 4 clock outputs, 4 fractional dividers. Input clock source can be taken from either external crystal or from external reference clock.

Cc Alexey Firago <[email protected]>
Cc Rob Herring <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 .../devicetree/bindings/clock/idt,versaclock5.txt         | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/clock/idt,versaclock5.txt +0 -0
index 53d7e50ed875..a3d4260039a8 100644

Probably you want to sprinkle the first few lines of the document with a few "VersaClock 6" references?

Documentation/devicetree/bindings/clock/idt,versaclock5.txt from 3 to 12 output clocks.

Quoted 1 line
Documentation/devicetree/bindings/clock/idt,versaclock5.txt +0 -0
@@ -7,18 +7,20 @@ from 3 to 12 output clocks.

The rest looks OK to me, so

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#10 lore raw

Re: [PATCH 7/8] clk: vc5: Add bindings for IDT VersaClock 5P49V6901

Quoted 21 lines · Geert Uytterhoeven

Hi Marek,

Quoted 18 lines · Marek Vasut

From: Marek Vasut <[email protected]>

IDT VersaClock 6 5P49V6901 has 4 clock outputs, 4 fractional dividers. Input clock source can be taken from either external crystal or from external reference clock.

Cc Alexey Firago <[email protected]>
Cc Rob Herring <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 .../devicetree/bindings/clock/idt,versaclock5.txt         | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
Quoted 7 lines

Documentation/devicetree/bindings/clock/idt,versaclock5.txt

Quoted 4 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.txt +0 -0
index 53d7e50ed875..a3d4260039a8 100644

Probably you want to sprinkle the first few lines of the document with a few "VersaClock 6" references?

Something like this?

Documentation/devicetree/bindings/clock/idt,versaclock5.txt +3 -3
@@ -1,7 +1,7 @@
-Binding for IDT VersaClock5 programmable i2c clock generator.
+Binding for IDT VersaClock 5,6 programmable i2c clock generators.
 
-The IDT VersaClock5 are programmable i2c clock generators providing
-from 3 to 12 output clocks.
+The IDT VersaClock 5 and VersaClock 6 are programmable i2c clock
+generators providing from 3 to 12 output clocks.
 
 ==I2C device node==
 
Quoted 4 lines

Documentation/devicetree/bindings/clock/idt,versaclock5.txt from 3 to 12 output clocks.

Quoted 1 line
Documentation/devicetree/bindings/clock/idt,versaclock5.txt +0 -0
@@ -7,18 +7,20 @@ from 3 to 12 output clocks.

The rest looks OK to me, so

Thanks

Signature · 2 lines
Best regards,
Marek Vasut
#11 lore raw

Re: [PATCH 7/8] clk: vc5: Add bindings for IDT VersaClock 5P49V6901

Hi Marek,

Quoted 21 lines · Marek Vasut
Quoted 7 lines · Geert Uytterhoeven
Quoted 6 lines · Marek Vasut

From: Marek Vasut <[email protected]>

IDT VersaClock 6 5P49V6901 has 4 clock outputs, 4 fractional dividers. Input clock source can be taken from either external crystal or from external reference clock.

Quoted 7 lines

Documentation/devicetree/bindings/clock/idt,versaclock5.txt

Quoted 4 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.txt +0 -0

Probably you want to sprinkle the first few lines of the document with a few "VersaClock 6" references?

Something like this?

Documentation/devicetree/bindings/clock/idt,versaclock5.txt line 6

Quoted 9 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.txt +3 -3
@@ -1,7 +1,7 @@
-Binding for IDT VersaClock5 programmable i2c clock generator.
+Binding for IDT VersaClock 5,6 programmable i2c clock generators.
 
-The IDT VersaClock5 are programmable i2c clock generators providing
-from 3 to 12 output clocks.
+The IDT VersaClock 5 and VersaClock 6 are programmable i2c clock
+generators providing from 3 to 12 output clocks.
 
 ==I2C device node==

Exactly. Thanks!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#12 lore raw

PATCH 8/8 clk: vc5: Add support for IDT VersaClock 5P49V6901

In reply to Marek Vasut

From: Marek Vasut <[email protected]>

Update IDT VersaClock 6 driver to support 5P49V6901. This chip has two clock inputs (external XTAL or external CLKIN), four fractional dividers (FODs) and five clock outputs (four universal clock outputs and one reference clock output at OUT0_SELB_I2C).

Cc Alexey Firago <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 drivers/clk/clk-versaclock5.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/clk/clk-versaclock5.c +11 -0
index 6db84358520a..6e3166e00c8e 100644
@@ -131,6 +131,7 @@ enum vc5_model {
 	IDT_VC5_5P49V5923,
 	IDT_VC5_5P49V5933,
 	IDT_VC5_5P49V5935,
+	IDT_VC6_5P49V6901,
 };
 
 /* Structure to describe features of a particular VC5 model */
@@ -687,6 +688,7 @@ static int vc5_map_index_to_output(const enum vc5_model model,
 		return (n == 0) ? 0 : 3;
 	case IDT_VC5_5P49V5923:
 	case IDT_VC5_5P49V5935:
+	case IDT_VC6_5P49V6901:
 	default:
 		return n;
 	}
@@ -924,10 +926,18 @@ static const struct vc5_chip_info idt_5p49v5935_info = {
 	.flags = VC5_HAS_INTERNAL_XTAL,
 };
 
+static const struct vc5_chip_info idt_5p49v6901_info = {
+	.model = IDT_VC6_5P49V6901,
+	.clk_fod_cnt = 4,
+	.clk_out_cnt = 5,
+	.flags = VC5_HAS_PFD_FREQ_DBL,
+};
+
 static const struct i2c_device_id vc5_id[] = {
 	{ "5p49v5923", .driver_data = IDT_VC5_5P49V5923 },
 	{ "5p49v5933", .driver_data = IDT_VC5_5P49V5933 },
 	{ "5p49v5935", .driver_data = IDT_VC5_5P49V5935 },
+	{ "5p49v6901", .driver_data = IDT_VC6_5P49V6901 },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, vc5_id);
@@ -936,6 +946,7 @@ static const struct of_device_id clk_vc5_of_match[] = {
 	{ .compatible = "idt,5p49v5923", .data = &idt_5p49v5923_info },
 	{ .compatible = "idt,5p49v5933", .data = &idt_5p49v5933_info },
 	{ .compatible = "idt,5p49v5935", .data = &idt_5p49v5935_info },
+	{ .compatible = "idt,5p49v6901", .data = &idt_5p49v6901_info },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, clk_vc5_of_match);
Signature · 1 line
2.11.0
#13 lore raw

Re: [PATCH 8/8] clk: vc5: Add support for IDT VersaClock 5P49V6901

Hi Marek,

Quoted 3 lines · Marek Vasut

From: Marek Vasut <[email protected]>

Update IDT VersaClock 6 driver to support 5P49V6901. This chip has

Update the IDT VersaClock5 driver to support the VersaClock6 5P49V6901?

Quoted 4 lines

two clock inputs (external XTAL or external CLKIN), four fractional dividers (FODs) and five clock outputs (four universal clock outputs and one reference clock output at OUT0_SELB_I2C).

Quoted 8 lines
Cc Alexey Firago <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 drivers/clk/clk-versaclock5.c | 11 +++++++++++

and

drivers/clk/Kconfig +3 -3
@@ -210,14 +210,14 @@ config COMMON_CLK_OXNAS
          Support for the OXNAS SoC Family clocks.
 
 config COMMON_CLK_VC5
-       tristate "Clock driver for IDT VersaClock5 devices"
+       tristate "Clock driver for IDT VersaClock5/6 devices"
        depends on I2C
        depends on OF
        select REGMAP_I2C
        help
        ---help---
-         This driver supports the IDT VersaClock5 programmable clock
-         generator.
+         This driver supports the IDT VersaClock5 and VersaClock6
+         programmable clock generator.
 
 source "drivers/clk/bcm/Kconfig"
 source "drivers/clk/hisilicon/Kconfig"

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#14 lore raw

Re: [PATCH 8/8] clk: vc5: Add support for IDT VersaClock 5P49V6901

Quoted 31 lines · Geert Uytterhoeven

Hi Marek,

Quoted 3 lines · Marek Vasut

From: Marek Vasut <[email protected]>

Update IDT VersaClock 6 driver to support 5P49V6901. This chip has

Update the IDT VersaClock5 driver to support the VersaClock6 5P49V6901?

Quoted 4 lines

two clock inputs (external XTAL or external CLKIN), four fractional dividers (FODs) and five clock outputs (four universal clock outputs and one reference clock output at OUT0_SELB_I2C).

Quoted 8 lines
Cc Alexey Firago <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 drivers/clk/clk-versaclock5.c | 11 +++++++++++

and

drivers/clk/Kconfig +0 -1
@@ -210,14 +210,14 @@ config COMMON_CLK_OXNAS
          Support for the OXNAS SoC Family clocks.
 
 config COMMON_CLK_VC5
-       tristate "Clock driver for IDT VersaClock5 devices"

drivers/clk/Kconfig config COMMON_CLK_OXNAS · line 220

Quoted 10 lines
drivers/clk/Kconfig +3 -2
+       tristate "Clock driver for IDT VersaClock5/6 devices"
        depends on I2C
        depends on OF
        select REGMAP_I2C
        help
        ---help---
-         This driver supports the IDT VersaClock5 programmable clock
-         generator.
+         This driver supports the IDT VersaClock5 and VersaClock6
+         programmable clock generator.

Tweaked a bit more, but yes, good point.

Signature · 2 lines
Best regards,
Marek Vasut
Tested-by on v1 1/8
#15 lore raw
In reply to Marek Vasut

Hi Marek,

Thank you for the patches.

Quoted 13 lines · On Thursday 29 Jun 2017 12:18:44 Marek Vasut wrote:

From: Marek Vasut <[email protected]>

In case the initial values of the FOD registers are not configured in the OTP or by the bootloader, it is possible that the FOD registers will contain zeroes. The code in vc5_fod_recalc_rate() immediately feeds the FOD divider value obtained from the FOD registers into the div64_u64() and if the FOD divider value is zero, triggers division by zero exception.

Check if the FOD divider value is zero and return the frequency of the FOD output as 0 Hz if it is so. This prevents the division by zero exception.

Quoted 6 lines
Cc Stephen Boyd <[email protected]>
Cc Alexey Firago <[email protected]>
Cc Michael Turquette <[email protected]>
Cc Laurent Pinchart <[email protected]>

For the whole series,

on Salvator-XS with the display LVDS output.

Quoted 9 lines
---
 drivers/clk/clk-versaclock5.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/clk/clk-versaclock5.c +0 -0
index ea7d552a2f2b..60bf4afb51bd 100644

drivers/clk/clk-versaclock5.c static unsigned long vc5_fod_recalc_rate(struct clk_hw · line 434

Quoted 9 lines
drivers/clk/clk-versaclock5.c +4 -0
@@ -426,6 +426,10 @@ static unsigned long vc5_fod_recalc_rate(struct clk_hw
 *hw, div_frc = (od_frc[0] << 22) | (od_frc[1] << 14) |
 		  (od_frc[2] << 6) | (od_frc[3] >> 2);
 
+	/* Avoid division by zero if the output is not configured. */
+	if ((div_int == 0) && (div_frc == 0))
+		return 0;
+
 	/* The PLL divider has 12 integer bits and 30 fractional bits */
 	return div64_u64((u64)f_in << 24ULL, ((u64)div_int << 24ULL) + 

div_frc);

Quoted 1 line
drivers/clk/clk-versaclock5.c +0 -0
 }
Signature · 3 lines
Regards,

Laurent Pinchart