Skip to content

Commit 6e7d2de

Browse files
robhancocksedbebarino
authored andcommitted
clk: si5341: Wait for DEVICE_READY on startup
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: 3044a86 ("clk: Add Si5341/Si5340 driver") Signed-off-by: Robert Hancock <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent c832bb9 commit 6e7d2de

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

drivers/clk/clk-si5341.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct clk_si5341_output_config {
9494
#define SI5341_STATUS 0x000C
9595
#define SI5341_SOFT_RST 0x001C
9696
#define SI5341_IN_SEL 0x0021
97+
#define SI5341_DEVICE_READY 0x00FE
9798
#define SI5341_XAXB_CFG 0x090E
9899
#define SI5341_IN_EN 0x0949
99100
#define SI5341_INX_TO_PFD_EN 0x094A
@@ -1189,6 +1190,32 @@ static const struct regmap_range_cfg si5341_regmap_ranges[] = {
11891190
},
11901191
};
11911192

1193+
static int si5341_wait_device_ready(struct i2c_client *client)
1194+
{
1195+
int count;
1196+
1197+
/* Datasheet warns: Any attempt to read or write any register other
1198+
* than DEVICE_READY before DEVICE_READY reads as 0x0F may corrupt the
1199+
* NVM programming and may corrupt the register contents, as they are
1200+
* read from NVM. Note that this includes accesses to the PAGE register.
1201+
* Also: DEVICE_READY is available on every register page, so no page
1202+
* change is needed to read it.
1203+
* Do this outside regmap to avoid automatic PAGE register access.
1204+
* May take up to 300ms to complete.
1205+
*/
1206+
for (count = 0; count < 15; ++count) {
1207+
s32 result = i2c_smbus_read_byte_data(client,
1208+
SI5341_DEVICE_READY);
1209+
if (result < 0)
1210+
return result;
1211+
if (result == 0x0F)
1212+
return 0;
1213+
msleep(20);
1214+
}
1215+
dev_err(&client->dev, "timeout waiting for DEVICE_READY\n");
1216+
return -EIO;
1217+
}
1218+
11921219
static const struct regmap_config si5341_regmap_config = {
11931220
.reg_bits = 8,
11941221
.val_bits = 8,
@@ -1385,6 +1412,11 @@ static int si5341_probe(struct i2c_client *client,
13851412

13861413
data->i2c_client = client;
13871414

1415+
/* Must be done before otherwise touching hardware */
1416+
err = si5341_wait_device_ready(client);
1417+
if (err)
1418+
return err;
1419+
13881420
for (i = 0; i < SI5341_NUM_INPUTS; ++i) {
13891421
input = devm_clk_get(&client->dev, si5341_input_clock_names[i]);
13901422
if (IS_ERR(input)) {

0 commit comments

Comments
 (0)