Skip to contentSkip to conversation

Si5341 driver updates

PATCH Superseded Robert Hancock 3 participants 19 messages Mar 11, 2021 – Mar 12, 2021 3 messages not in the archive

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Si5341 driver updates

Various fixes and enhancements to the Si5341 driver.

Robert Hancock (9):
dt-bindings: clock: clk-si5341: Add new attributes
clk: si5341: Wait for DEVICE_READY on startup
clk: si5341: Avoid divide errors due to bogus register contents
clk: si5341: Check for input clock presence and PLL lock on startup
clk: si5341: Update initialization magic
clk: si5341: Allow different output VDD_SEL values
clk: si5341: Add silabs,xaxb-ext-clk property
clk: si5341: Add silabs,iovdd-33 property
clk: si5341: Add sysfs properties to allow checking/resetting device
faults

 .../bindings/clock/silabs,si5341.txt          |  16 +-
 drivers/clk/clk-si5341.c                      | 343 ++++++++++++++++--
 2 files changed, 323 insertions(+), 36 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/9 dt-bindings: clock: clk-si5341: Add new attributes

Add new silabs,xaxb-ext-clk and silabs,iovdd-33 properties.

Changed vdd-supply on top-level node to optional since it is not actually used by the driver.

Removed vdd-supply from output sub-nodes, as it was not supported by the driver and it is not easily possible to support this in that location with the kernel regulator infrastructure. Changed to have vddX-supply attributes for each output on the top-level device node.

---
 .../devicetree/bindings/clock/silabs,si5341.txt  | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/clock/silabs,si5341.txt +10 -6
index 504cce3abe46..1cf7e002cb16 100644
@@ -24,9 +24,8 @@ it.
 
 The device type, speed grade and revision are determined runtime by probing.
 
-The driver currently only supports XTAL input mode, and does not support any
-fancy input configurations. They can still be programmed into the chip and
-the driver will leave them "as is".
+The driver currently does not support any fancy input configurations. They can
+still be programmed into the chip and the driver will leave them "as is".
 
 ==I2C device node==
 
@@ -45,9 +44,9 @@ Required properties:
 	corresponding to inputs. Use a fixed clock for the "xtal" input.
 	At least one must be present.
 - clock-names: One of: "xtal", "in0", "in1", "in2"
-- vdd-supply: Regulator node for VDD
 
 Optional properties:
+- vdd-supply: Regulator node for VDD
 - vdda-supply: Regulator node for VDDA
 - vdds-supply: Regulator node for VDDS
 - silabs,pll-m-num, silabs,pll-m-den: Numerator and denominator for PLL
@@ -60,7 +59,14 @@ Optional properties:
   be initialized, and always performs the soft-reset routine. Since this will
   temporarily stop all output clocks, don't do this if the chip is generating
   the CPU clock for example.
+- silabs,xaxb-ext-clk: When present, indicates that the XA/XB pins are used
+  in EXTCLK (external reference clock) rather than XTAL (crystal) mode.
 - interrupts: Interrupt for INTRb pin.
+- silabs,iovdd-33: When present, indicates that the I2C lines are using 3.3V
+  rather than 1.8V thresholds.
+- vddX-supply (where X is an output index): Regulator node for VDD for the
+  specified output. The driver selects the output VDD_SEL setting based on this
+  voltage.
 - #address-cells: shall be set to 1.
 - #size-cells: shall be set to 0.
 
@@ -77,8 +83,6 @@ Required child node properties:
 - reg: number of clock output.
 
 Optional child node properties:
-- vdd-supply: Regulator node for VDD for this output. The driver selects default
-	values for common-mode and amplitude based on the voltage.
 - silabs,format: Output format, one of:
 	1 = differential (defaults to LVDS levels)
 	2 = low-power (defaults to HCSL levels)
Signature · 1 line
2.27.0
#2 lore raw

PATCH 2/9 clk: si5341: Wait for DEVICE_READY on startup

In reply to Robert Hancock

The Si5341 datasheet warns that before accessing any other registers, including the PAGE register, we need to wait for the DEVICE_READY register to indicate the device is ready, or the process of the device loading its state from NVM can be corrupted. Wait for DEVICE_READY on startup before continuing initialization. This is done using a raw I2C register read prior to setting up regmap to avoid any potential unwanted automatic PAGE register accesses from regmap at this stage.

Fixes 3044a860fd ("clk: Add Si5341/Si5340 driver")
---
 drivers/clk/clk-si5341.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/clk/clk-si5341.c +31 -0
index e0446e66fa64..f210860fb96e 100644
@@ -94,6 +94,7 @@ struct clk_si5341_output_config {
 #define SI5341_STATUS		0x000C
 #define SI5341_SOFT_RST		0x001C
 #define SI5341_IN_SEL		0x0021
+#define SI5341_DEVICE_READY	0x00FE
 #define SI5341_XAXB_CFG		0x090E
 #define SI5341_IN_EN		0x0949
 #define SI5341_INX_TO_PFD_EN	0x094A
@@ -1189,6 +1190,31 @@ static const struct regmap_range_cfg si5341_regmap_ranges[] = {
 	},
 };
 
+static int si5341_wait_device_ready(struct i2c_client *client)
+{
+	int count;
+
+	/* Datasheet warns: Any attempt to read or write any register other
+	 * than DEVICE_READY before DEVICE_READY reads as 0x0F may corrupt the
+	 * NVM programming and may corrupt the register contents, as they are
+	 * read from NVM. Note that this includes accesses to the PAGE register.
+	 * Also: DEVICE_READY is available on every register page, so no page
+	 * change is needed to read it.
+	 * Do this outside regmap to avoid automatic PAGE register access.
+	 */
+	for (count = 0; count < 10; ++count) {
+		s32 result = i2c_smbus_read_byte_data(client,
+						      SI5341_DEVICE_READY);
+		if (result < 0)
+			return result;
+		if (result == 0x0F)
+			return 0;
+		usleep_range(1000, 20000);
+	}
+	dev_err(&client->dev, "timeout waiting for DEVICE_READY\n");
+	return -EIO;
+}
+
 static const struct regmap_config si5341_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
@@ -1385,6 +1411,11 @@ static int si5341_probe(struct i2c_client *client,
 
 	data->i2c_client = client;
 
+	/* Must be done before otherwise touching hardware */
+	err = si5341_wait_device_ready(client);
+	if (err)
+		return err;
+
 	for (i = 0; i < SI5341_NUM_INPUTS; ++i) {
 		input = devm_clk_get(&client->dev, si5341_input_clock_names[i]);
 		if (IS_ERR(input)) {
Signature · 1 line
2.27.0
#3 lore raw

Re: [PATCH 2/9] clk: si5341: Wait for DEVICE_READY on startup

One remark below.

Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: www.topicproducts.com

Please consider the environment before printing this e-mail

Quoted 42 lines · Robert Hancock

The Si5341 datasheet warns that before accessing any other registers, including the PAGE register, we need to wait for the DEVICE_READY register to indicate the device is ready, or the process of the device loading its state from NVM can be corrupted. Wait for DEVICE_READY on startup before continuing initialization. This is done using a raw I2C register read prior to setting up regmap to avoid any potential unwanted automatic PAGE register accesses from regmap at this stage.

Fixes 3044a860fd ("clk: Add Si5341/Si5340 driver")
---
  drivers/clk/clk-si5341.c | 31 +++++++++++++++++++++++++++++++
  1 file changed, 31 insertions(+)
drivers/clk/clk-si5341.c +13 -0
index e0446e66fa64..f210860fb96e 100644
@@ -94,6 +94,7 @@ struct clk_si5341_output_config {
  #define SI5341_STATUS		0x000C
  #define SI5341_SOFT_RST		0x001C
  #define SI5341_IN_SEL		0x0021
+#define SI5341_DEVICE_READY	0x00FE
  #define SI5341_XAXB_CFG		0x090E
  #define SI5341_IN_EN		0x0949
  #define SI5341_INX_TO_PFD_EN	0x094A
@@ -1189,6 +1190,31 @@ static const struct regmap_range_cfg si5341_regmap_ranges[] = {
  	},
  };
 
+static int si5341_wait_device_ready(struct i2c_client *client)
+{
+	int count;
+
+	/* Datasheet warns: Any attempt to read or write any register other
+	 * than DEVICE_READY before DEVICE_READY reads as 0x0F may corrupt the
+	 * NVM programming and may corrupt the register contents, as they are
+	 * read from NVM. Note that this includes accesses to the PAGE register.
+	 * Also: DEVICE_READY is available on every register page, so no page
+	 * change is needed to read it.
+	 * Do this outside regmap to avoid automatic PAGE register access.
+	 */

drivers/clk/clk-si5341.c static const struct regmap_range_cfg si5341_regmap_ranges[] = { · line 1214

Quoted 10 lines
drivers/clk/clk-si5341.c +10 -0
+	for (count = 0; count < 10; ++count) {
+		s32 result = i2c_smbus_read_byte_data(client,
+						      SI5341_DEVICE_READY);
+		if (result < 0)
+			return result;
+		if (result == 0x0F)
+			return 0;
+		usleep_range(1000, 20000);
+	}
+	dev_err(&client->dev, "timeout waiting for DEVICE_READY\n");

The "timeout" here is random between 10 and 200 milliseconds.

The datasheet says that the device may take 300ms to initialize, so I guess 300 milliseconds would be a good timeout.

I'm also pretty sure there's a built-in kernel function to poll a register with timeout that you should use here.

Quoted 18 lines
drivers/clk/clk-si5341.c +8 -0
+	return -EIO;
+}
+
  static const struct regmap_config si5341_regmap_config = {
  	.reg_bits = 8,
  	.val_bits = 8,
@@ -1385,6 +1411,11 @@ static int si5341_probe(struct i2c_client *client,
 
  	data->i2c_client = client;
 
+	/* Must be done before otherwise touching hardware */
+	err = si5341_wait_device_ready(client);
+	if (err)
+		return err;
+
  	for (i = 0; i < SI5341_NUM_INPUTS; ++i) {
  		input = devm_clk_get(&client->dev, si5341_input_clock_names[i]);
  		if (IS_ERR(input)) {
Signature · 1 line
Mike Looijmans
#4 lore raw

Re: [PATCH 2/9] clk: si5341: Wait for DEVICE_READY on startup

Quoted 78 lines · Mike Looijmans

One remark below.

Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W:
https://urldefense.com/v3/__http://www.topicproducts.com__;!!IOGos0k!2aBLUJa-5kaozesyVznxIfxn2Hn5L4i0RdhELnnHU1WJ85FIzmGyRCRmXW5-kXbcsi0$

Please consider the environment before printing this e-mail

Quoted 44 lines · Robert Hancock

The Si5341 datasheet warns that before accessing any other registers, including the PAGE register, we need to wait for the DEVICE_READY register to indicate the device is ready, or the process of the device loading its state from NVM can be corrupted. Wait for DEVICE_READY on startup before continuing initialization. This is done using a raw I2C register read prior to setting up regmap to avoid any potential unwanted automatic PAGE register accesses from regmap at this stage.

Fixes 3044a860fd ("clk: Add Si5341/Si5340 driver")
---
  drivers/clk/clk-si5341.c | 31 +++++++++++++++++++++++++++++++
  1 file changed, 31 insertions(+)
drivers/clk/clk-si5341.c +9 -0
index e0446e66fa64..f210860fb96e 100644
@@ -94,6 +94,7 @@ struct clk_si5341_output_config {
  #define SI5341_STATUS		0x000C
  #define SI5341_SOFT_RST		0x001C
  #define SI5341_IN_SEL		0x0021
+#define SI5341_DEVICE_READY	0x00FE
  #define SI5341_XAXB_CFG		0x090E
  #define SI5341_IN_EN		0x0949
  #define SI5341_INX_TO_PFD_EN	0x094A
@@ -1189,6 +1190,31 @@ static const struct regmap_range_cfg
 si5341_regmap_ranges[] = {
  	},
  };
 
+static int si5341_wait_device_ready(struct i2c_client *client)
+{
+	int count;
+
+	/* Datasheet warns: Any attempt to read or write any register other
+	 * than DEVICE_READY before DEVICE_READY reads as 0x0F may corrupt the
+	 * NVM programming and may corrupt the register contents, as they are
+	 * read from NVM. Note that this includes accesses to the PAGE

register.

drivers/clk/clk-si5341.c +4 -0
+	 * Also: DEVICE_READY is available on every register page, so no page
+	 * change is needed to read it.
+	 * Do this outside regmap to avoid automatic PAGE register access.
+	 */

drivers/clk/clk-si5341.c static const struct regmap_range_cfg si5341_regmap_ranges[] = { · line 1214

Quoted 10 lines
drivers/clk/clk-si5341.c +10 -0
+	for (count = 0; count < 10; ++count) {
+		s32 result = i2c_smbus_read_byte_data(client,
+						      SI5341_DEVICE_READY);
+		if (result < 0)
+			return result;
+		if (result == 0x0F)
+			return 0;
+		usleep_range(1000, 20000);
+	}
+	dev_err(&client->dev, "timeout waiting for DEVICE_READY\n");

The "timeout" here is random between 10 and 200 milliseconds.

Quoted 2 lines

The datasheet says that the device may take 300ms to initialize, so I guess 300 milliseconds would be a good timeout.

I think I missed the 300ms figure. We should definitely allow at least that much time then. Will address in v2.

Quoted 3 lines

I'm also pretty sure there's a built-in kernel function to poll a register with timeout that you should use here.

There is a regmap_read_poll_timeout function, but we're trying to specifically not use regmap here because it may access other registers behind our back. I'm not aware of something better that operates at the I2C layer..

Quoted 23 lines
Quoted 21 lines
drivers/clk/clk-si5341.c +8 -0
+	return -EIO;
+}
+
  static const struct regmap_config si5341_regmap_config = {
  	.reg_bits = 8,
  	.val_bits = 8,
@@ -1385,6 +1411,11 @@ static int si5341_probe(struct i2c_client *client,
 
  	data->i2c_client = client;
 
+	/* Must be done before otherwise touching hardware */
+	err = si5341_wait_device_ready(client);
+	if (err)
+		return err;
+
  	for (i = 0; i < SI5341_NUM_INPUTS; ++i) {
  		input = devm_clk_get(&client->dev,
 si5341_input_clock_names[i]);
  		if (IS_ERR(input)) {
Signature · 3 lines
Robert Hancock
Senior Hardware Designer, Calian Advanced Technologies
www.calian.com
#5 lore raw

PATCH 3/9 clk: si5341: Avoid divide errors due to bogus register contents

In reply to Robert Hancock

If the Si5341 is being initially programmed and has no stored NVM configuration, some of the register contents may contain unexpected values, such as zeros, which could cause divide by zero errors during driver initialization. Trap errors caused by zero registers or zero clock rates which could result in divide errors later in the code.

Fixes 3044a860fd ("clk: Add Si5341/Si5340 driver")
---
 drivers/clk/clk-si5341.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/clk/clk-si5341.c +13 -2
index f210860fb96e..2d69b2144acf 100644
@@ -624,6 +624,9 @@ static unsigned long si5341_synth_clk_recalc_rate(struct clk_hw *hw,
 			SI5341_SYNTH_N_NUM(synth->index), &n_num, &n_den);
 	if (err < 0)
 		return err;
+	/* Check for bogus/uninitialized settings */
+	if (!n_num || !n_den)
+		return 0;
 
 	/*
 	 * n_num and n_den are shifted left as much as possible, so to prevent
@@ -807,6 +810,9 @@ static long si5341_output_clk_round_rate(struct clk_hw *hw, unsigned long rate,
 {
 	unsigned long r;
 
+	if (!rate)
+		return 0;
+
 	r = *parent_rate >> 1;
 
 	/* If rate is an even divisor, no changes to parent required */
@@ -835,11 +841,16 @@ static int si5341_output_clk_set_rate(struct clk_hw *hw, unsigned long rate,
 		unsigned long parent_rate)
 {
 	struct clk_si5341_output *output = to_clk_si5341_output(hw);
-	/* Frequency divider is (r_div + 1) * 2 */
-	u32 r_div = (parent_rate / rate) >> 1;
+	u32 r_div;
 	int err;
 	u8 r[3];
 
+	if (!rate)
+		return -EINVAL;
+
+	/* Frequency divider is (r_div + 1) * 2 */
+	r_div = (parent_rate / rate) >> 1;
+
 	if (r_div <= 1)
 		r_div = 0;
 	else if (r_div >= BIT(24))
Signature · 1 line
2.27.0
#6 lore raw

PATCH 4/9 clk: si5341: Check for input clock presence and PLL lock on startup

In reply to Robert Hancock

After initializing the device, allow sufficient time for the PLL to lock (if we reconfigured it) and verify that the input clock is present and the PLL has locked before declaring success.

Fixes 3044a860fd ("clk: Add Si5341/Si5340 driver")
---
 drivers/clk/clk-si5341.c | 46 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
drivers/clk/clk-si5341.c +46 -0
index 2d69b2144acf..5221e431f6cb 100644
@@ -92,6 +92,9 @@ struct clk_si5341_output_config {
 #define SI5341_PN_BASE		0x0002
 #define SI5341_DEVICE_REV	0x0005
 #define SI5341_STATUS		0x000C
+#define SI5341_LOS		0x000D
+#define SI5341_STATUS_STICKY	0x0011
+#define SI5341_LOS_STICKY	0x0012
 #define SI5341_SOFT_RST		0x001C
 #define SI5341_IN_SEL		0x0021
 #define SI5341_DEVICE_READY	0x00FE
@@ -99,6 +102,12 @@ struct clk_si5341_output_config {
 #define SI5341_IN_EN		0x0949
 #define SI5341_INX_TO_PFD_EN	0x094A
 
+/* Status bits */
+#define SI5341_STATUS_SYSINCAL	BIT(0)
+#define SI5341_STATUS_LOSXAXB	BIT(1)
+#define SI5341_STATUS_LOSREF	BIT(2)
+#define SI5341_STATUS_LOL	BIT(3)
+
 /* Input selection */
 #define SI5341_IN_SEL_MASK	0x06
 #define SI5341_IN_SEL_SHIFT	1
@@ -1403,6 +1412,29 @@ static int si5341_clk_select_active_input(struct clk_si5341 *data)
 	return res;
 }
 
+static int si5341_check_healthy(struct clk_si5341 *data)
+{
+	u32 status;
+	int res = regmap_read(data->regmap, SI5341_STATUS, &status);
+
+	if (res < 0) {
+		dev_err(&data->i2c_client->dev, "failed to read status\n");
+		return res;
+	}
+
+	if ((status & SI5341_STATUS_LOSREF)) {
+		dev_err(&data->i2c_client->dev, "input clock not present\n");
+		return -EIO;
+	}
+
+	if ((status & SI5341_STATUS_LOL)) {
+		dev_err(&data->i2c_client->dev, "PLL not locked\n");
+		return -EIO;
+	}
+
+	return 0;
+}
+
 static int si5341_probe(struct i2c_client *client,
 		const struct i2c_device_id *id)
 {
@@ -1580,6 +1612,20 @@ static int si5341_probe(struct i2c_client *client,
 		err = si5341_finalize_defaults(data);
 		if (err < 0)
 			return err;
+
+		/* allow time for PLL to lock */
+		msleep(250);
+	}
+
+	err = si5341_check_healthy(data);
+	if (err)
+		return err;
+
+	/* clear sticky alarm bits from initialization */
+	err = regmap_write(data->regmap, SI5341_STATUS_STICKY, 0);
+	if (err) {
+		dev_err(&client->dev, "unable to clear sticky status\n");
+		return err;
 	}
 
 	/* Free the names, clk framework makes copies */
Signature · 1 line
2.27.0
#7 lore raw

Re: [PATCH 4/9] clk: si5341: Check for input clock presence and PLL lock on startup

Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: www.topicproducts.com

Please consider the environment before printing this e-mail

Quoted 68 lines · Robert Hancock

After initializing the device, allow sufficient time for the PLL to lock (if we reconfigured it) and verify that the input clock is present and the PLL has locked before declaring success.

Fixes 3044a860fd ("clk: Add Si5341/Si5340 driver")
---
  drivers/clk/clk-si5341.c | 46 ++++++++++++++++++++++++++++++++++++++++
  1 file changed, 46 insertions(+)
drivers/clk/clk-si5341.c +32 -0
index 2d69b2144acf..5221e431f6cb 100644
@@ -92,6 +92,9 @@ struct clk_si5341_output_config {
  #define SI5341_PN_BASE		0x0002
  #define SI5341_DEVICE_REV	0x0005
  #define SI5341_STATUS		0x000C
+#define SI5341_LOS		0x000D
+#define SI5341_STATUS_STICKY	0x0011
+#define SI5341_LOS_STICKY	0x0012
  #define SI5341_SOFT_RST		0x001C
  #define SI5341_IN_SEL		0x0021
  #define SI5341_DEVICE_READY	0x00FE
@@ -99,6 +102,12 @@ struct clk_si5341_output_config {
  #define SI5341_IN_EN		0x0949
  #define SI5341_INX_TO_PFD_EN	0x094A
 
+/* Status bits */
+#define SI5341_STATUS_SYSINCAL	BIT(0)
+#define SI5341_STATUS_LOSXAXB	BIT(1)
+#define SI5341_STATUS_LOSREF	BIT(2)
+#define SI5341_STATUS_LOL	BIT(3)
+
  /* Input selection */
  #define SI5341_IN_SEL_MASK	0x06
  #define SI5341_IN_SEL_SHIFT	1
@@ -1403,6 +1412,29 @@ static int si5341_clk_select_active_input(struct clk_si5341 *data)
  	return res;
  }
 
+static int si5341_check_healthy(struct clk_si5341 *data)
+{
+	u32 status;
+	int res = regmap_read(data->regmap, SI5341_STATUS, &status);
+
+	if (res < 0) {
+		dev_err(&data->i2c_client->dev, "failed to read status\n");
+		return res;
+	}
+
+	if ((status & SI5341_STATUS_LOSREF)) {
+		dev_err(&data->i2c_client->dev, "input clock not present\n");
+		return -EIO;
+	}
+
+	if ((status & SI5341_STATUS_LOL)) {
+		dev_err(&data->i2c_client->dev, "PLL not locked\n");
+		return -EIO;
+	}
+
+	return 0;
+}
+
  static int si5341_probe(struct i2c_client *client,
  		const struct i2c_device_id *id)
  {

drivers/clk/clk-si5341.c static int si5341_probe(struct i2c_client *client, · line 1617

Quoted 6 lines
drivers/clk/clk-si5341.c +3 -0
@@ -1580,6 +1612,20 @@ static int si5341_probe(struct i2c_client *client,
  		err = si5341_finalize_defaults(data);
  		if (err < 0)
  			return err;
+
+		/* allow time for PLL to lock */
+		msleep(250);

Can't this be a poll loop with timeout? Seems rather harsh to just sleep here.

Quoted 14 lines
drivers/clk/clk-si5341.c +11 -0
+	}
+
+	err = si5341_check_healthy(data);
+	if (err)
+		return err;
+
+	/* clear sticky alarm bits from initialization */
+	err = regmap_write(data->regmap, SI5341_STATUS_STICKY, 0);
+	if (err) {
+		dev_err(&client->dev, "unable to clear sticky status\n");
+		return err;
  	}
 
  	/* Free the names, clk framework makes copies */
Signature · 1 line
Mike Looijmans
#8 lore raw

Re: [PATCH 4/9] clk: si5341: Check for input clock presence and PLL lock on startup

Quoted 88 lines · Mike Looijmans

Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W:
https://urldefense.com/v3/__http://www.topicproducts.com__;!!IOGos0k!wiWtHGRxxa459e4cDke1e1LNom9k55h5ayHt6t0CboF-tMxY8bgYWiRsplbzxz6sN94$

Please consider the environment before printing this e-mail

Quoted 70 lines · Robert Hancock

After initializing the device, allow sufficient time for the PLL to lock (if we reconfigured it) and verify that the input clock is present and the PLL has locked before declaring success.

Fixes 3044a860fd ("clk: Add Si5341/Si5340 driver")
---
  drivers/clk/clk-si5341.c | 46 ++++++++++++++++++++++++++++++++++++++++
  1 file changed, 46 insertions(+)
drivers/clk/clk-si5341.c +32 -0
index 2d69b2144acf..5221e431f6cb 100644
@@ -92,6 +92,9 @@ struct clk_si5341_output_config {
  #define SI5341_PN_BASE		0x0002
  #define SI5341_DEVICE_REV	0x0005
  #define SI5341_STATUS		0x000C
+#define SI5341_LOS		0x000D
+#define SI5341_STATUS_STICKY	0x0011
+#define SI5341_LOS_STICKY	0x0012
  #define SI5341_SOFT_RST		0x001C
  #define SI5341_IN_SEL		0x0021
  #define SI5341_DEVICE_READY	0x00FE
@@ -99,6 +102,12 @@ struct clk_si5341_output_config {
  #define SI5341_IN_EN		0x0949
  #define SI5341_INX_TO_PFD_EN	0x094A
 
+/* Status bits */
+#define SI5341_STATUS_SYSINCAL	BIT(0)
+#define SI5341_STATUS_LOSXAXB	BIT(1)
+#define SI5341_STATUS_LOSREF	BIT(2)
+#define SI5341_STATUS_LOL	BIT(3)
+
  /* Input selection */
  #define SI5341_IN_SEL_MASK	0x06
  #define SI5341_IN_SEL_SHIFT	1
@@ -1403,6 +1412,29 @@ static int si5341_clk_select_active_input(struct
 clk_si5341 *data)
  	return res;
  }
 
+static int si5341_check_healthy(struct clk_si5341 *data)
+{
+	u32 status;
+	int res = regmap_read(data->regmap, SI5341_STATUS, &status);
+
+	if (res < 0) {
+		dev_err(&data->i2c_client->dev, "failed to read status\n");
+		return res;
+	}
+
+	if ((status & SI5341_STATUS_LOSREF)) {
+		dev_err(&data->i2c_client->dev, "input clock not present\n");
+		return -EIO;
+	}
+
+	if ((status & SI5341_STATUS_LOL)) {
+		dev_err(&data->i2c_client->dev, "PLL not locked\n");
+		return -EIO;
+	}
+
+	return 0;
+}
+
  static int si5341_probe(struct i2c_client *client,
  		const struct i2c_device_id *id)
  {
drivers/clk/clk-si5341.c +0 -0
@@ -1580,6 +1612,20 @@ static int si5341_probe(struct i2c_client *client,
  		err = si5341_finalize_defaults(data);
Quoted 8 lines

drivers/clk/clk-si5341.c static int si5341_probe(struct i2c_client *client, · line 1617

Quoted 5 lines
drivers/clk/clk-si5341.c +3 -0
  		if (err < 0)
  			return err;
+
+		/* allow time for PLL to lock */
+		msleep(250);

Can't this be a poll loop with timeout? Seems rather harsh to just sleep here.

Indeed, regmap_read_poll_timeout would likely work here. Will address in v2.

Quoted 17 lines
Quoted 15 lines
drivers/clk/clk-si5341.c +11 -0
+	}
+
+	err = si5341_check_healthy(data);
+	if (err)
+		return err;
+
+	/* clear sticky alarm bits from initialization */
+	err = regmap_write(data->regmap, SI5341_STATUS_STICKY, 0);
+	if (err) {
+		dev_err(&client->dev, "unable to clear sticky status\n");
+		return err;
  	}
 
  	/* Free the names, clk framework makes copies */
#9 lore raw

PATCH 5/9 clk: si5341: Update initialization magic

In reply to Robert Hancock

Update the default register settings to include the VCO_RESET_CALCODE settings (set by the SiLabs ClockBuilder software but not described in the datasheet). Also update part of the initialization sequence to match ClockBuilder and the datasheet.

Fixes 3044a860fd ("clk: Add Si5341/Si5340 driver")
---
 drivers/clk/clk-si5341.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/clk-si5341.c +3 -1
index 5221e431f6cb..b758cc9987ca 100644
@@ -350,6 +350,8 @@ static const struct si5341_reg_default si5341_reg_defaults[] = {
 	{ 0x094A, 0x00 }, /* INx_TO_PFD_EN (disabled) */
 	{ 0x0A02, 0x00 }, /* Not in datasheet */
 	{ 0x0B44, 0x0F }, /* PDIV_ENB (datasheet does not mention what it is) */
+	{ 0x0B57, 0x10 }, /* VCO_RESET_CALCODE (not described in datasheet) */
+	{ 0x0B58, 0x05 }, /* VCO_RESET_CALCODE (not described in datasheet) */
 };
 
 /* Read and interpret a 44-bit followed by a 32-bit value in the regmap */
@@ -1104,7 +1106,7 @@ static const struct si5341_reg_default si5341_preamble[] = {
 	{ 0x0B25, 0x00 },
 	{ 0x0502, 0x01 },
 	{ 0x0505, 0x03 },
-	{ 0x0957, 0x1F },
+	{ 0x0957, 0x17 },
 	{ 0x0B4E, 0x1A },
 };
 
Signature · 1 line
2.27.0
#10 lore raw

PATCH 6/9 clk: si5341: Allow different output VDD_SEL values

In reply to Robert Hancock

The driver was not previously programming the VDD_SEL values for each output to indicate what external VDD voltage was used for each. Add ability to specify a regulator supplying the VDD pin for each output of the device. The voltage of the regulator is used to automatically set the VDD_SEL value appropriately. If no regulator is specified and the chip is being reconfigured, assume 2.5V which appears to be the chip default.

---
 drivers/clk/clk-si5341.c | 136 +++++++++++++++++++++++++++++++--------
 1 file changed, 110 insertions(+), 26 deletions(-)
drivers/clk/clk-si5341.c +110 -26
index b758cc9987ca..f01a20fdf005 100644
@@ -19,6 +19,7 @@
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 #include <asm/unaligned.h>
 
@@ -59,6 +60,7 @@ struct clk_si5341_synth {
 struct clk_si5341_output {
 	struct clk_hw hw;
 	struct clk_si5341 *data;
+	struct regulator *vdd_reg;
 	u8 index;
 };
 #define to_clk_si5341_output(_hw) \
@@ -84,6 +86,7 @@ struct clk_si5341 {
 struct clk_si5341_output_config {
 	u8 out_format_drv_bits;
 	u8 out_cm_ampl_bits;
+	u8 vdd_sel_bits;
 	bool synth_master;
 	bool always_on;
 };
@@ -136,6 +139,8 @@ struct clk_si5341_output_config {
 #define SI5341_OUT_R_REG(output)	\
 			((output)->data->reg_rdiv_offset[(output)->index])
 
+#define SI5341_OUT_MUX_VDD_SEL_MASK 0x38
+
 /* Synthesize N divider */
 #define SI5341_SYNTH_N_NUM(x)	(0x0302 + ((x) * 11))
 #define SI5341_SYNTH_N_DEN(x)	(0x0308 + ((x) * 11))
@@ -1247,11 +1252,11 @@ static const struct regmap_config si5341_regmap_config = {
 	.volatile_table = &si5341_regmap_volatile,
 };
 
-static int si5341_dt_parse_dt(struct i2c_client *client,
-	struct clk_si5341_output_config *config)
+static int si5341_dt_parse_dt(struct clk_si5341 *data,
+			      struct clk_si5341_output_config *config)
 {
 	struct device_node *child;
-	struct device_node *np = client->dev.of_node;
+	struct device_node *np = data->i2c_client->dev.of_node;
 	u32 num;
 	u32 val;
 
@@ -1260,13 +1265,13 @@ static int si5341_dt_parse_dt(struct i2c_client *client,
 
 	for_each_child_of_node(np, child) {
 		if (of_property_read_u32(child, "reg", &num)) {
-			dev_err(&client->dev, "missing reg property of %s\n",
+			dev_err(&data->i2c_client->dev, "missing reg property of %s\n",
 				child->name);
 			goto put_child;
 		}
 
 		if (num >= SI5341_MAX_NUM_OUTPUTS) {
-			dev_err(&client->dev, "invalid clkout %d\n", num);
+			dev_err(&data->i2c_client->dev, "invalid clkout %d\n", num);
 			goto put_child;
 		}
 
@@ -1285,7 +1290,7 @@ static int si5341_dt_parse_dt(struct i2c_client *client,
 				config[num].out_format_drv_bits |= 0xc0;
 				break;
 			default:
-				dev_err(&client->dev,
+				dev_err(&data->i2c_client->dev,
 					"invalid silabs,format %u for %u\n",
 					val, num);
 				goto put_child;
@@ -1298,7 +1303,7 @@ static int si5341_dt_parse_dt(struct i2c_client *client,
 
 		if (!of_property_read_u32(child, "silabs,common-mode", &val)) {
 			if (val > 0xf) {
-				dev_err(&client->dev,
+				dev_err(&data->i2c_client->dev,
 					"invalid silabs,common-mode %u\n",
 					val);
 				goto put_child;
@@ -1309,7 +1314,7 @@ static int si5341_dt_parse_dt(struct i2c_client *client,
 
 		if (!of_property_read_u32(child, "silabs,amplitude", &val)) {
 			if (val > 0xf) {
-				dev_err(&client->dev,
+				dev_err(&data->i2c_client->dev,
 					"invalid silabs,amplitude %u\n",
 					val);
 				goto put_child;
@@ -1326,6 +1331,34 @@ static int si5341_dt_parse_dt(struct i2c_client *client,
 
 		config[num].always_on =
 			of_property_read_bool(child, "always-on");
+
+		config[num].vdd_sel_bits = 0x08;
+		if (data->clk[num].vdd_reg) {
+			int vdd = regulator_get_voltage(data->clk[num].vdd_reg);
+
+			switch (vdd) {
+			case 3300000:
+				config[num].vdd_sel_bits |= 0 << 4;
+				break;
+			case 1800000:
+				config[num].vdd_sel_bits |= 1 << 4;
+				break;
+			case 2500000:
+				config[num].vdd_sel_bits |= 2 << 4;
+				break;
+			default:
+				dev_err(&data->i2c_client->dev,
+					"unsupported vdd voltage %d for %s\n",
+					vdd, child->name);
+				goto put_child;
+			}
+		} else {
+			/* chip seems to default to 2.5V when not set */
+			dev_warn(&data->i2c_client->dev,
+				"no regulator set, defaulting vdd_sel to 2.5V for %s\n",
+				child->name);
+			config[num].vdd_sel_bits |= 2 << 4;
+		}
 	}
 
 	return 0;
@@ -1473,9 +1506,33 @@ static int si5341_probe(struct i2c_client *client,
 		}
 	}
 
-	err = si5341_dt_parse_dt(client, config);
+	for (i = 0; i < SI5341_MAX_NUM_OUTPUTS; ++i) {
+		char reg_name[10];
+
+		snprintf(reg_name, sizeof(reg_name), "vdd%d", i);
+		data->clk[i].vdd_reg = devm_regulator_get_optional(
+			&client->dev, reg_name);
+		if (IS_ERR(data->clk[i].vdd_reg)) {
+			err = PTR_ERR(data->clk[i].vdd_reg);
+			data->clk[i].vdd_reg = NULL;
+			if (err == -ENODEV)
+				continue;
+			goto cleanup;
+		} else {
+			err = regulator_enable(data->clk[i].vdd_reg);
+			if (err) {
+				dev_err(&client->dev,
+					"failed to enable %s regulator: %d\n",
+					reg_name, err);
+				data->clk[i].vdd_reg = NULL;
+				goto cleanup;
+			}
+		}
+	}
+
+	err = si5341_dt_parse_dt(data, config);
 	if (err)
-		return err;
+		goto cleanup;
 
 	if (of_property_read_string(client->dev.of_node, "clock-output-names",
 			&init.name))
@@ -1483,21 +1540,23 @@ static int si5341_probe(struct i2c_client *client,
 	root_clock_name = init.name;
 
 	data->regmap = devm_regmap_init_i2c(client, &si5341_regmap_config);
-	if (IS_ERR(data->regmap))
-		return PTR_ERR(data->regmap);
+	if (IS_ERR(data->regmap)) {
+		err = PTR_ERR(data->regmap);
+		goto cleanup;
+	}
 
 	i2c_set_clientdata(client, data);
 
 	err = si5341_probe_chip_id(data);
 	if (err < 0)
-		return err;
+		goto cleanup;
 
 	if (of_property_read_bool(client->dev.of_node, "silabs,reprogram")) {
 		initialization_required = true;
 	} else {
 		err = si5341_is_programmed_already(data);
 		if (err < 0)
-			return err;
+			goto cleanup;
 
 		initialization_required = !err;
 	}
@@ -1506,11 +1565,11 @@ static int si5341_probe(struct i2c_client *client,
 		/* Populate the regmap cache in preparation for "cache only" */
 		err = si5341_read_settings(data);
 		if (err < 0)
-			return err;
+			goto cleanup;
 
 		err = si5341_send_preamble(data);
 		if (err < 0)
-			return err;
+			goto cleanup;
 
 		/*
 		 * We intend to send all 'final' register values in a single
@@ -1523,19 +1582,19 @@ static int si5341_probe(struct i2c_client *client,
 		err = si5341_write_multiple(data, si5341_reg_defaults,
 					ARRAY_SIZE(si5341_reg_defaults));
 		if (err < 0)
-			return err;
+			goto cleanup;
 	}
 
 	/* Input must be up and running at this point */
 	err = si5341_clk_select_active_input(data);
 	if (err < 0)
-		return err;
+		goto cleanup;
 
 	if (initialization_required) {
 		/* PLL configuration is required */
 		err = si5341_initialize_pll(data);
 		if (err < 0)
-			return err;
+			goto cleanup;
 	}
 
 	/* Register the PLL */
@@ -1548,7 +1607,7 @@ static int si5341_probe(struct i2c_client *client,
 	err = devm_clk_hw_register(&client->dev, &data->hw);
 	if (err) {
 		dev_err(&client->dev, "clock registration failed\n");
-		return err;
+		goto cleanup;
 	}
 
 	init.num_parents = 1;
@@ -1585,13 +1644,17 @@ static int si5341_probe(struct i2c_client *client,
 			regmap_write(data->regmap,
 				SI5341_OUT_CM(&data->clk[i]),
 				config[i].out_cm_ampl_bits);
+			regmap_update_bits(data->regmap,
+				SI5341_OUT_MUX_SEL(&data->clk[i]),
+				SI5341_OUT_MUX_VDD_SEL_MASK,
+				config[i].vdd_sel_bits);
 		}
 		err = devm_clk_hw_register(&client->dev, &data->clk[i].hw);
 		kfree(init.name); /* clock framework made a copy of the name */
 		if (err) {
 			dev_err(&client->dev,
 				"output %u registration failed\n", i);
-			return err;
+			goto cleanup;
 		}
 		if (config[i].always_on)
 			clk_prepare(data->clk[i].hw.clk);
@@ -1601,7 +1664,7 @@ static int si5341_probe(struct i2c_client *client,
 			data);
 	if (err) {
 		dev_err(&client->dev, "unable to add clk provider\n");
-		return err;
+		goto cleanup;
 	}
 
 	if (initialization_required) {
@@ -1609,11 +1672,11 @@ static int si5341_probe(struct i2c_client *client,
 		regcache_cache_only(data->regmap, false);
 		err = regcache_sync(data->regmap);
 		if (err < 0)
-			return err;
+			goto cleanup;
 
 		err = si5341_finalize_defaults(data);
 		if (err < 0)
-			return err;
+			goto cleanup;
 
 		/* allow time for PLL to lock */
 		msleep(250);
@@ -1621,13 +1684,13 @@ static int si5341_probe(struct i2c_client *client,
 
 	err = si5341_check_healthy(data);
 	if (err)
-		return err;
+		goto cleanup;
 
 	/* clear sticky alarm bits from initialization */
 	err = regmap_write(data->regmap, SI5341_STATUS_STICKY, 0);
 	if (err) {
 		dev_err(&client->dev, "unable to clear sticky status\n");
-		return err;
+		goto cleanup;
 	}
 
 	/* Free the names, clk framework makes copies */
@@ -1635,6 +1698,26 @@ static int si5341_probe(struct i2c_client *client,
 		 devm_kfree(&client->dev, (void *)synth_clock_names[i]);
 
 	return 0;
+
+cleanup:
+	for (i = 0; i < SI5341_MAX_NUM_OUTPUTS; ++i) {
+		if (data->clk[i].vdd_reg)
+			regulator_disable(data->clk[i].vdd_reg);
+	}
+	return err;
+}
+
+int si5341_remove(struct i2c_client *client)
+{
+	struct clk_si5341 *data = i2c_get_clientdata(client);
+	int i;
+
+	for (i = 0; i < SI5341_MAX_NUM_OUTPUTS; ++i) {
+		if (data->clk[i].vdd_reg)
+			regulator_disable(data->clk[i].vdd_reg);
+	}
+
+	return 0;
 }
 
 static const struct i2c_device_id si5341_id[] = {
@@ -1663,6 +1746,7 @@ static struct i2c_driver si5341_driver = {
 		.of_match_table = clk_si5341_of_match,
 	},
 	.probe		= si5341_probe,
+	.remove		= si5341_remove,
 	.id_table	= si5341_id,
 };
 module_i2c_driver(si5341_driver);
Signature · 1 line
2.27.0
#11 lore raw

Re: [PATCH 6/9] clk: si5341: Allow different output VDD_SEL values

Thank you for the patch! Perhaps something to improve:

Hi Robert,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on clk/clk-next]
[also build test WARNING on v5.12-rc2 next-20210311]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Robert-Hancock/Si5341-driver-updates/20210312-062821
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
config: i386-randconfig-s001-20210312 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-262-g5e674421-dirty
        # https://github.com/0day-ci/linux/commit/636016363158ea8e30592ff4974f344ca0043f82
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Robert-Hancock/Si5341-driver-updates/20210312-062821
        git checkout 636016363158ea8e30592ff4974f344ca0043f82
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

"sparse warnings: (new ones prefixed by >>)"

>> drivers/clk/clk-si5341.c:1710:5: sparse: sparse: symbol 'si5341_remove' was not declared. Should it be static?

Please review and possibly fold the followup patch.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#12 lore raw

[RFC PATCH] clk: si5341: si5341_remove() can be static

In reply to Robert Hancock
Reported-by: kernel test robot <[email protected]>
---
 clk-si5341.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk-si5341.c +1 -1
index f01a20fdf0054..5a3128e58f18e 100644
@@ -1707,7 +1707,7 @@ static int si5341_probe(struct i2c_client *client,
 	return err;
 }
 
-int si5341_remove(struct i2c_client *client)
+static int si5341_remove(struct i2c_client *client)
 {
 	struct clk_si5341 *data = i2c_get_clientdata(client);
 	int i;
#13 lore raw

Re: [PATCH 6/9] clk: si5341: Allow different output VDD_SEL values

In reply to Robert Hancock
Thank you for the patch! Perhaps something to improve:

Hi Robert,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on clk/clk-next]
[also build test WARNING on v5.12-rc2 next-20210311]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Robert-Hancock/Si5341-driver-updates/20210312-062821
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
config: arm64-randconfig-r034-20210312 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 7b153b43d3a14d76975039408c4b922beb576735)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/636016363158ea8e30592ff4974f344ca0043f82
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Robert-Hancock/Si5341-driver-updates/20210312-062821 git checkout 636016363158ea8e30592ff4974f344ca0043f82
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/clk/clk-si5341.c:1710:5: warning: no previous prototype for function 'si5341_remove' [-Wmissing-prototypes]
   int si5341_remove(struct i2c_client *client)
       ^

drivers/clk/clk-si5341.c:1710:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int si5341_remove(struct i2c_client *client)
^
static
1 warning generated.

vim +/si5341_remove +1710 drivers/clk/clk-si5341.c

1709

> 1710	int si5341_remove(struct i2c_client *client)

1711 {
1712 struct clk_si5341 *data = i2c_get_clientdata(client);
1713 int i;
1714
1715 for (i = 0; i < SI5341_MAX_NUM_OUTPUTS; ++i) {
1716 if (data->clk[i].vdd_reg)
1717 regulator_disable(data->clk[i].vdd_reg);
1718 }
1719
1720 return 0;
1721 }
1722

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#14 lore raw

PATCH 7/9 clk: si5341: Add silabs,xaxb-ext-clk property

In reply to Robert Hancock

Add a property to allow specifying that the device XA/XB pins are used for an external clock input rather than for a clock crystal.

---
 drivers/clk/clk-si5341.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/clk/clk-si5341.c +7 -2
index f01a20fdf005..11740855bcde 100644
@@ -80,6 +80,7 @@ struct clk_si5341 {
 	u8 num_outputs;
 	u8 num_synth;
 	u16 chip_id;
+	bool xaxb_ext_clk;
 };
 #define to_clk_si5341(_hw)	container_of(_hw, struct clk_si5341, hw)
 
@@ -529,9 +530,11 @@ static int si5341_clk_reparent(struct clk_si5341 *data, u8 index)
 		if (err < 0)
 			return err;
 
-		/* Power up XTAL oscillator and buffer */
+		/* Power up XTAL oscillator and buffer, select clock mode */
 		err = regmap_update_bits(data->regmap, SI5341_XAXB_CFG,
-				SI5341_XAXB_CFG_PDNB, SI5341_XAXB_CFG_PDNB);
+				SI5341_XAXB_CFG_PDNB | SI5341_XAXB_CFG_EXTCLK_EN,
+				SI5341_XAXB_CFG_PDNB | (data->xaxb_ext_clk ?
+					SI5341_XAXB_CFG_EXTCLK_EN : 0));
 		if (err < 0)
 			return err;
 	}
@@ -1560,6 +1563,8 @@ static int si5341_probe(struct i2c_client *client,
 
 		initialization_required = !err;
 	}
+	data->xaxb_ext_clk = of_property_read_bool(client->dev.of_node,
+						   "silabs,xaxb-ext-clk");
 
 	if (initialization_required) {
 		/* Populate the regmap cache in preparation for "cache only" */
Signature · 1 line
2.27.0
#15 lore raw

PATCH 8/9 clk: si5341: Add silabs,iovdd-33 property

In reply to Robert Hancock

Add a property to allow specifying that the external I2C IO pins are using 3.3V voltage thresholds rather than 1.8V.

---
 drivers/clk/clk-si5341.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/clk/clk-si5341.c +9 -1
index 11740855bcde..4cd80ef389d2 100644
@@ -81,6 +81,7 @@ struct clk_si5341 {
 	u8 num_synth;
 	u16 chip_id;
 	bool xaxb_ext_clk;
+	bool iovdd_33;
 };
 #define to_clk_si5341(_hw)	container_of(_hw, struct clk_si5341, hw)
 
@@ -103,6 +104,7 @@ struct clk_si5341_output_config {
 #define SI5341_IN_SEL		0x0021
 #define SI5341_DEVICE_READY	0x00FE
 #define SI5341_XAXB_CFG		0x090E
+#define SI5341_IO_VDD_SEL	0x0943
 #define SI5341_IN_EN		0x0949
 #define SI5341_INX_TO_PFD_EN	0x094A
 
@@ -351,7 +353,6 @@ static const struct si5341_reg_default si5341_reg_defaults[] = {
 	{ 0x0804, 0x00 }, /* Not in datasheet */
 	{ 0x090E, 0x02 }, /* XAXB_EXTCLK_EN=0 XAXB_PDNB=1 (use XTAL) */
 	{ 0x091C, 0x04 }, /* ZDM_EN=4 (Normal mode) */
-	{ 0x0943, 0x00 }, /* IO_VDD_SEL=0 (0=1v8, use 1=3v3) */
 	{ 0x0949, 0x00 }, /* IN_EN (disable input clocks) */
 	{ 0x094A, 0x00 }, /* INx_TO_PFD_EN (disabled) */
 	{ 0x0A02, 0x00 }, /* Not in datasheet */
@@ -1160,6 +1161,11 @@ static int si5341_finalize_defaults(struct clk_si5341 *data)
 	int res;
 	u32 revision;
 
+	res = regmap_write(data->regmap, SI5341_IO_VDD_SEL,
+			   data->iovdd_33 ? 1 : 0);
+	if (res < 0)
+		return res;
+
 	res = regmap_read(data->regmap, SI5341_DEVICE_REV, &revision);
 	if (res < 0)
 		return res;
@@ -1565,6 +1571,8 @@ static int si5341_probe(struct i2c_client *client,
 	}
 	data->xaxb_ext_clk = of_property_read_bool(client->dev.of_node,
 						   "silabs,xaxb-ext-clk");
+	data->iovdd_33 = of_property_read_bool(client->dev.of_node,
+					       "silabs,iovdd-33");
 
 	if (initialization_required) {
 		/* Populate the regmap cache in preparation for "cache only" */
Signature · 1 line
2.27.0
#16 lore raw

Re: [PATCH 8/9] clk: si5341: Add silabs,iovdd-33 property

Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: www.topicproducts.com

Please consider the environment before printing this e-mail

Quoted 49 lines · Robert Hancock

Add a property to allow specifying that the external I2C IO pins are using 3.3V voltage thresholds rather than 1.8V.

---
  drivers/clk/clk-si5341.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
drivers/clk/clk-si5341.c +7 -1
index 11740855bcde..4cd80ef389d2 100644
@@ -81,6 +81,7 @@ struct clk_si5341 {
  	u8 num_synth;
  	u16 chip_id;
  	bool xaxb_ext_clk;
+	bool iovdd_33;
  };
  #define to_clk_si5341(_hw)	container_of(_hw, struct clk_si5341, hw)
 
@@ -103,6 +104,7 @@ struct clk_si5341_output_config {
  #define SI5341_IN_SEL		0x0021
  #define SI5341_DEVICE_READY	0x00FE
  #define SI5341_XAXB_CFG		0x090E
+#define SI5341_IO_VDD_SEL	0x0943
  #define SI5341_IN_EN		0x0949
  #define SI5341_INX_TO_PFD_EN	0x094A
 
@@ -351,7 +353,6 @@ static const struct si5341_reg_default si5341_reg_defaults[] = {
  	{ 0x0804, 0x00 }, /* Not in datasheet */
  	{ 0x090E, 0x02 }, /* XAXB_EXTCLK_EN=0 XAXB_PDNB=1 (use XTAL) */
  	{ 0x091C, 0x04 }, /* ZDM_EN=4 (Normal mode) */
-	{ 0x0943, 0x00 }, /* IO_VDD_SEL=0 (0=1v8, use 1=3v3) */
  	{ 0x0949, 0x00 }, /* IN_EN (disable input clocks) */
  	{ 0x094A, 0x00 }, /* INx_TO_PFD_EN (disabled) */
  	{ 0x0A02, 0x00 }, /* Not in datasheet */
@@ -1160,6 +1161,11 @@ static int si5341_finalize_defaults(struct clk_si5341 *data)
  	int res;
  	u32 revision;
 
+	res = regmap_write(data->regmap, SI5341_IO_VDD_SEL,
+			   data->iovdd_33 ? 1 : 0);
+	if (res < 0)
+		return res;
+
  	res = regmap_read(data->regmap, SI5341_DEVICE_REV, &revision);
  	if (res < 0)
  		return res;

drivers/clk/clk-si5341.c static int si5341_probe(struct i2c_client *client, · line 1576

Quoted 6 lines
drivers/clk/clk-si5341.c +2 -0
@@ -1565,6 +1571,8 @@ static int si5341_probe(struct i2c_client *client,
  	}
  	data->xaxb_ext_clk = of_property_read_bool(client->dev.of_node,
  						   "silabs,xaxb-ext-clk");
+	data->iovdd_33 = of_property_read_bool(client->dev.of_node,
+					       "silabs,iovdd-33");
 

Seems a waste to me to store this in the 'data' object forever while it is to be used only once during init and never again after that.

Quoted 2 lines
drivers/clk/clk-si5341.c +0 -0
  	if (initialization_required) {
  		/* Populate the regmap cache in preparation for "cache only" */
Signature · 1 line
Mike Looijmans
#17 lore raw

Re: [PATCH 8/9] clk: si5341: Add silabs,iovdd-33 property

Quoted 71 lines · Mike Looijmans

Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W:
https://urldefense.com/v3/__http://www.topicproducts.com__;!!IOGos0k!1ZKoWVwv09fDC-o4jRw92NZvHBl_3MOcBIPl8DLLDN0szJlo9IH0GC-6qH0-Pq1W-PA$

Please consider the environment before printing this e-mail

Quoted 53 lines · Robert Hancock

Add a property to allow specifying that the external I2C IO pins are using 3.3V voltage thresholds rather than 1.8V.

---
  drivers/clk/clk-si5341.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
drivers/clk/clk-si5341.c +2 -1
index 11740855bcde..4cd80ef389d2 100644
@@ -81,6 +81,7 @@ struct clk_si5341 {
  	u8 num_synth;
  	u16 chip_id;
  	bool xaxb_ext_clk;
+	bool iovdd_33;
  };
  #define to_clk_si5341(_hw)	container_of(_hw, struct clk_si5341,
 hw)
@@ -103,6 +104,7 @@ struct clk_si5341_output_config {
  #define SI5341_IN_SEL		0x0021
  #define SI5341_DEVICE_READY	0x00FE
  #define SI5341_XAXB_CFG		0x090E
+#define SI5341_IO_VDD_SEL	0x0943
  #define SI5341_IN_EN		0x0949
  #define SI5341_INX_TO_PFD_EN	0x094A
 
@@ -351,7 +353,6 @@ static const struct si5341_reg_default
 si5341_reg_defaults[] = {
  	{ 0x0804, 0x00 }, /* Not in datasheet */
  	{ 0x090E, 0x02 }, /* XAXB_EXTCLK_EN=0 XAXB_PDNB=1 (use XTAL) */
  	{ 0x091C, 0x04 }, /* ZDM_EN=4 (Normal mode) */
-	{ 0x0943, 0x00 }, /* IO_VDD_SEL=0 (0=1v8, use 1=3v3) */
  	{ 0x0949, 0x00 }, /* IN_EN (disable input clocks) */
  	{ 0x094A, 0x00 }, /* INx_TO_PFD_EN (disabled) */

{ 0x0A02, 0x00 }, /* Not in datasheet */

drivers/clk/clk-si5341.c +5 -0
@@ -1160,6 +1161,11 @@ static int si5341_finalize_defaults(struct
 clk_si5341 *data)
  	int res;
  	u32 revision;
 
+	res = regmap_write(data->regmap, SI5341_IO_VDD_SEL,
+			   data->iovdd_33 ? 1 : 0);
+	if (res < 0)
+		return res;
+
  	res = regmap_read(data->regmap, SI5341_DEVICE_REV, &revision);
  	if (res < 0)

return res;

drivers/clk/clk-si5341.c +0 -0
@@ -1565,6 +1571,8 @@ static int si5341_probe(struct i2c_client *client,
  	}
Quoted 8 lines

drivers/clk/clk-si5341.c static int si5341_probe(struct i2c_client *client, · line 1576

Quoted 5 lines
drivers/clk/clk-si5341.c +2 -0
  	data->xaxb_ext_clk = of_property_read_bool(client->dev.of_node,
  						   "silabs,xaxb-ext-clk");
+	data->iovdd_33 = of_property_read_bool(client->dev.of_node,
+					       "silabs,iovdd-33");
 

Seems a waste to me to store this in the 'data' object forever while it is to be used only once during init and never again after that.

That is true, but it would then have to be passed down into the si5341_finalize_defaults function separately and it would be inconsistent with how all of the other configuration is handled. So I'm not sure it's worth saving ~ 1 byte in the data object..

Quoted 6 lines
Quoted 4 lines
drivers/clk/clk-si5341.c +0 -0
  	if (initialization_required) {
  		/* Populate the regmap cache in preparation for "cache only" */
#18 lore raw

PATCH 9/9 clk: si5341: Add sysfs properties to allow checking/resetting device faults

In reply to Robert Hancock

Add sysfs property files to allow viewing the current and latched states of the input present and PLL lock bits, and allow resetting the latched fault state. This allows manual checks or automated userspace polling for faults occurring after initialization.

---
 drivers/clk/clk-si5341.c | 96 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)
drivers/clk/clk-si5341.c +96 -0
index 4cd80ef389d2..f2bcaedf1c71 100644
@@ -1479,6 +1479,94 @@ static int si5341_check_healthy(struct clk_si5341 *data)
 	return 0;
 }
 
+static ssize_t input_present_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)
+{
+	struct clk_si5341 *data = dev_get_drvdata(dev);
+	u32 status;
+	int res = regmap_read(data->regmap, SI5341_STATUS, &status);
+
+	if (res < 0)
+		return res;
+	res = !(status & SI5341_STATUS_LOSREF);
+	return snprintf(buf, PAGE_SIZE, "%d\n", res);
+}
+static DEVICE_ATTR_RO(input_present);
+
+static ssize_t input_present_sticky_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct clk_si5341 *data = dev_get_drvdata(dev);
+	u32 status;
+	int res = regmap_read(data->regmap, SI5341_STATUS_STICKY, &status);
+
+	if (res < 0)
+		return res;
+	res = !(status & SI5341_STATUS_LOSREF);
+	return snprintf(buf, PAGE_SIZE, "%d\n", res);
+}
+static DEVICE_ATTR_RO(input_present_sticky);
+
+static ssize_t pll_locked_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buf)
+{
+	struct clk_si5341 *data = dev_get_drvdata(dev);
+	u32 status;
+	int res = regmap_read(data->regmap, SI5341_STATUS, &status);
+
+	if (res < 0)
+		return res;
+	res = !(status & SI5341_STATUS_LOL);
+	return snprintf(buf, PAGE_SIZE, "%d\n", res);
+}
+static DEVICE_ATTR_RO(pll_locked);
+
+static ssize_t pll_locked_sticky_show(struct device *dev,
+				      struct device_attribute *attr,
+				      char *buf)
+{
+	struct clk_si5341 *data = dev_get_drvdata(dev);
+	u32 status;
+	int res = regmap_read(data->regmap, SI5341_STATUS_STICKY, &status);
+
+	if (res < 0)
+		return res;
+	res = !(status & SI5341_STATUS_LOL);
+	return snprintf(buf, PAGE_SIZE, "%d\n", res);
+}
+static DEVICE_ATTR_RO(pll_locked_sticky);
+
+static ssize_t clear_sticky_store(struct device *dev,
+				  struct device_attribute *attr,
+				  const char *buf, size_t count)
+{
+	struct clk_si5341 *data = dev_get_drvdata(dev);
+	long val;
+
+	if (kstrtol(buf, 10, &val))
+		return -EINVAL;
+	if (val) {
+		int res = regmap_write(data->regmap, SI5341_STATUS_STICKY, 0);
+
+		if (res < 0)
+			return res;
+	}
+	return count;
+}
+static DEVICE_ATTR_WO(clear_sticky);
+
+static const struct attribute *si5341_attributes[] = {
+	&dev_attr_input_present.attr,
+	&dev_attr_input_present_sticky.attr,
+	&dev_attr_pll_locked.attr,
+	&dev_attr_pll_locked_sticky.attr,
+	&dev_attr_clear_sticky.attr,
+	NULL
+};
+
 static int si5341_probe(struct i2c_client *client,
 		const struct i2c_device_id *id)
 {
@@ -1706,6 +1794,12 @@ static int si5341_probe(struct i2c_client *client,
 		goto cleanup;
 	}
 
+	err = sysfs_create_files(&client->dev.kobj, si5341_attributes);
+	if (err) {
+		dev_err(&client->dev, "unable to create sysfs files\n");
+		goto cleanup;
+	}
+
 	/* Free the names, clk framework makes copies */
 	for (i = 0; i < data->num_synth; ++i)
 		 devm_kfree(&client->dev, (void *)synth_clock_names[i]);
@@ -1725,6 +1819,8 @@ int si5341_remove(struct i2c_client *client)
 	struct clk_si5341 *data = i2c_get_clientdata(client);
 	int i;
 
+	sysfs_remove_files(&client->dev.kobj, si5341_attributes);
+
 	for (i = 0; i < SI5341_MAX_NUM_OUTPUTS; ++i) {
 		if (data->clk[i].vdd_reg)
 			regulator_disable(data->clk[i].vdd_reg);
Signature · 1 line
2.27.0