brcm2708: rename target to bcm27xx
[openwrt/staging/wigyori.git] / target / linux / bcm27xx / patches-4.19 / 950-0606-i2c-bcm2835-Ensure-clock-exists-when-probing.patch
1 From 1a5122f1756ef4fc5779324ad26b6a04142166b5 Mon Sep 17 00:00:00 2001
2 From: Annaliese McDermond <nh6z@nh6z.net>
3 Date: Fri, 21 Jun 2019 03:52:50 -0700
4 Subject: [PATCH] i2c: bcm2835: Ensure clock exists when probing
5
6 Commit 9de93b04df16b055824e3f1f13fedb90fbcf2e4f upstream.
7
8 Probe function fails to recognize that upstream clock actually
9 doesn't yet exist because clock driver has not been initialized.
10 Actually try to go get the clock and test for its existence
11 before trying to set up a downstream clock based upon it.
12
13 This fixes a bug that causes the i2c driver not to work with
14 monolithic kernels.
15
16 Fixes: bebff81fb8b9 ("i2c: bcm2835: Model Divider in CCF")
17 Signed-off-by: Annaliese McDermond <nh6z@nh6z.net>
18 Acked-by: Stefan Wahren <wahrenst@gmx.net>
19 Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
20 ---
21 drivers/i2c/busses/i2c-bcm2835.c | 16 ++++++++++++----
22 1 file changed, 12 insertions(+), 4 deletions(-)
23
24 --- a/drivers/i2c/busses/i2c-bcm2835.c
25 +++ b/drivers/i2c/busses/i2c-bcm2835.c
26 @@ -244,15 +244,18 @@ static const struct clk_ops clk_bcm2835_
27 };
28
29 static struct clk *bcm2835_i2c_register_div(struct device *dev,
30 - const char *mclk_name,
31 + struct clk *mclk,
32 struct bcm2835_i2c_dev *i2c_dev)
33 {
34 struct clk_init_data init;
35 struct clk_bcm2835_i2c *priv;
36 char name[32];
37 + const char *mclk_name;
38
39 snprintf(name, sizeof(name), "%s_div", dev_name(dev));
40
41 + mclk_name = __clk_get_name(mclk);
42 +
43 init.ops = &clk_bcm2835_i2c_ops;
44 init.name = name;
45 init.parent_names = (const char* []) { mclk_name };
46 @@ -505,8 +508,8 @@ static int bcm2835_i2c_probe(struct plat
47 struct resource *mem, *irq;
48 int ret;
49 struct i2c_adapter *adap;
50 - const char *mclk_name;
51 struct clk *bus_clk;
52 + struct clk *mclk;
53 u32 bus_clk_rate;
54
55 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
56 @@ -521,9 +524,14 @@ static int bcm2835_i2c_probe(struct plat
57 if (IS_ERR(i2c_dev->regs))
58 return PTR_ERR(i2c_dev->regs);
59
60 - mclk_name = of_clk_get_parent_name(pdev->dev.of_node, 0);
61 + mclk = devm_clk_get(&pdev->dev, NULL);
62 + if (IS_ERR(mclk)) {
63 + if (PTR_ERR(mclk) != -EPROBE_DEFER)
64 + dev_err(&pdev->dev, "Could not get clock\n");
65 + return PTR_ERR(mclk);
66 + }
67
68 - bus_clk = bcm2835_i2c_register_div(&pdev->dev, mclk_name, i2c_dev);
69 + bus_clk = bcm2835_i2c_register_div(&pdev->dev, mclk, i2c_dev);
70
71 if (IS_ERR(bus_clk)) {
72 dev_err(&pdev->dev, "Could not register clock\n");