Skip to content

Commit 4268254

Browse files
tq-steinaAndi Shyti
authored andcommitted
i2c: lpi2c: Avoid calling clk_get_rate during transfer
Instead of repeatedly calling clk_get_rate for each transfer, lock the clock rate and cache the value. A deadlock has been observed while adding tlv320aic32x4 audio codec to the system. When this clock provider adds its clock, the clk mutex is locked already, it needs to access i2c, which in return needs the mutex for clk_get_rate as well. Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
1 parent 355b151 commit 4268254

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

drivers/i2c/busses/i2c-imx-lpi2c.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct lpi2c_imx_struct {
9999
__u8 *rx_buf;
100100
__u8 *tx_buf;
101101
struct completion complete;
102+
unsigned long rate_per;
102103
unsigned int msglen;
103104
unsigned int delivered;
104105
unsigned int block_data;
@@ -212,9 +213,7 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)
212213

213214
lpi2c_imx_set_mode(lpi2c_imx);
214215

215-
clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk);
216-
if (!clk_rate)
217-
return -EINVAL;
216+
clk_rate = lpi2c_imx->rate_per;
218217

219218
if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
220219
filt = 0;
@@ -611,6 +610,20 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
611610
if (ret)
612611
return ret;
613612

613+
/*
614+
* Lock the parent clock rate to avoid getting parent clock upon
615+
* each transfer
616+
*/
617+
ret = devm_clk_rate_exclusive_get(&pdev->dev, lpi2c_imx->clks[0].clk);
618+
if (ret)
619+
return dev_err_probe(&pdev->dev, ret,
620+
"can't lock I2C peripheral clock rate\n");
621+
622+
lpi2c_imx->rate_per = clk_get_rate(lpi2c_imx->clks[0].clk);
623+
if (!lpi2c_imx->rate_per)
624+
return dev_err_probe(&pdev->dev, -EINVAL,
625+
"can't get I2C peripheral clock rate\n");
626+
614627
pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT);
615628
pm_runtime_use_autosuspend(&pdev->dev);
616629
pm_runtime_get_noresume(&pdev->dev);

0 commit comments

Comments
 (0)