Skip to content

Commit 2cb90ed

Browse files
tkiskyalexandrebelloni
authored andcommitted
rtc: m41t80: avoid i2c read in m41t80_sqw_recalc_rate
This is a little more efficient, and avoids the warning WARNING: possible circular locking dependency detected 4.14.0-rc7-00007 #14 Not tainted ------------------------------------------------------ alsactl/330 is trying to acquire lock: (prepare_lock){+.+.}, at: [<c049300c>] clk_prepare_lock+0x80/0xf4 but task is already holding lock: (i2c_register_adapter){+.+.}, at: [<c0690ae0>] i2c_adapter_lock_bus+0x14/0x18 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #1 (i2c_register_adapter){+.+.}: rt_mutex_lock+0x44/0x5c i2c_adapter_lock_bus+0x14/0x18 i2c_transfer+0xa8/0xbc i2c_smbus_xfer+0x20c/0x5d8 i2c_smbus_read_byte_data+0x38/0x48 m41t80_sqw_recalc_rate+0x24/0x58 Signed-off-by: Troy Kisky <troy.kisky@boundarydevices.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
1 parent c8384bb commit 2cb90ed

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

drivers/rtc/rtc-m41t80.c

+17-11
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ struct m41t80_data {
154154
struct rtc_device *rtc;
155155
#ifdef CONFIG_COMMON_CLK
156156
struct clk_hw sqw;
157+
unsigned long freq;
157158
#endif
158159
};
159160

@@ -443,26 +444,28 @@ static SIMPLE_DEV_PM_OPS(m41t80_pm, m41t80_suspend, m41t80_resume);
443444
#ifdef CONFIG_COMMON_CLK
444445
#define sqw_to_m41t80_data(_hw) container_of(_hw, struct m41t80_data, sqw)
445446

446-
static unsigned long m41t80_sqw_recalc_rate(struct clk_hw *hw,
447-
unsigned long parent_rate)
447+
static unsigned long m41t80_decode_freq(int setting)
448+
{
449+
return (setting == 0) ? 0 : (setting == 1) ? M41T80_SQW_MAX_FREQ :
450+
M41T80_SQW_MAX_FREQ >> setting;
451+
}
452+
453+
static unsigned long m41t80_get_freq(struct m41t80_data *m41t80)
448454
{
449-
struct m41t80_data *m41t80 = sqw_to_m41t80_data(hw);
450455
struct i2c_client *client = m41t80->client;
451456
int reg_sqw = (m41t80->features & M41T80_FEATURE_SQ_ALT) ?
452457
M41T80_REG_WDAY : M41T80_REG_SQW;
453458
int ret = i2c_smbus_read_byte_data(client, reg_sqw);
454-
unsigned long val = M41T80_SQW_MAX_FREQ;
455459

456460
if (ret < 0)
457461
return 0;
462+
return m41t80_decode_freq(ret >> 4);
463+
}
458464

459-
ret >>= 4;
460-
if (ret == 0)
461-
val = 0;
462-
else if (ret > 1)
463-
val = val / (1 << ret);
464-
465-
return val;
465+
static unsigned long m41t80_sqw_recalc_rate(struct clk_hw *hw,
466+
unsigned long parent_rate)
467+
{
468+
return sqw_to_m41t80_data(hw)->freq;
466469
}
467470

468471
static long m41t80_sqw_round_rate(struct clk_hw *hw, unsigned long rate,
@@ -505,6 +508,8 @@ static int m41t80_sqw_set_rate(struct clk_hw *hw, unsigned long rate,
505508
reg = (reg & 0x0f) | (val << 4);
506509

507510
ret = i2c_smbus_write_byte_data(client, reg_sqw, reg);
511+
if (!ret)
512+
m41t80->freq = m41t80_decode_freq(val);
508513
return ret;
509514
}
510515

@@ -579,6 +584,7 @@ static struct clk *m41t80_sqw_register_clk(struct m41t80_data *m41t80)
579584
init.parent_names = NULL;
580585
init.num_parents = 0;
581586
m41t80->sqw.init = &init;
587+
m41t80->freq = m41t80_get_freq(m41t80);
582588

583589
/* optional override of the clockname */
584590
of_property_read_string(node, "clock-output-names", &init.name);

0 commit comments

Comments
 (0)