69cc155d8d23078aba5ec74131118c1485fcc5d5
[openwrt/staging/dangole.git] / target / linux / mediatek / patches-5.15 / 855-i2c-mt65xx-allow-optional-pmic-clock.patch
1 From 3bf827929a44c17bfb1bf1000b143c02ce26a929 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Sat, 26 Aug 2023 21:56:51 +0100
4 Subject: [PATCH] i2c: mt65xx: allow optional pmic clock
5
6 Using the I2C host controller on the MT7981 SoC requires 4 clocks to
7 be enabled. One of them, the pmic clk, is only enabled in case
8 'mediatek,have-pmic' is also set which has other consequences which
9 are not desired in this case.
10
11 Allow defining a pmic clk even in case the 'mediatek,have-pmic' propterty
12 is not present and the bus is not used to connect to a pmic, but may
13 still require to enable the pmic clock.
14
15 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
16 ---
17 drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
18 1 file changed, 8 insertions(+), 4 deletions(-)
19
20 --- a/drivers/i2c/busses/i2c-mt65xx.c
21 +++ b/drivers/i2c/busses/i2c-mt65xx.c
22 @@ -1444,15 +1444,19 @@ static int mtk_i2c_probe(struct platform
23 if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk))
24 return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk);
25
26 + i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get_optional(&pdev->dev, "pmic");
27 + if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
28 + dev_err(&pdev->dev, "cannot get pmic clock\n");
29 + return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
30 + }
31 +
32 if (i2c->have_pmic) {
33 - i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get(&pdev->dev, "pmic");
34 - if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
35 + if (!i2c->clocks[I2C_MT65XX_CLK_PMIC].clk) {
36 dev_err(&pdev->dev, "cannot get pmic clock\n");
37 - return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
38 + return -ENODEV;
39 }
40 speed_clk = I2C_MT65XX_CLK_PMIC;
41 } else {
42 - i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = NULL;
43 speed_clk = I2C_MT65XX_CLK_MAIN;
44 }
45