0f3ea9a9f2dd1a81da9af5e6832d2ff08a48e3a7
[openwrt/staging/noltari.git] /
1 From 8d9f3526529d857376c661c21820a0049c2e62de Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Sat, 12 Jan 2019 08:07:43 -0800
4 Subject: [PATCH] soc: bcm: bcm2835-pm: Fix error paths of
5 initialization.
6
7 The clock driver may probe after ours and so we need to pass the
8 -EPROBE_DEFER out. Fix the other error path while we're here.
9
10 v2: Use dom->name instead of dom->gov as the flag for initialized
11 domains, since we aren't setting up a governor. Make sure to
12 clear ->clk when no clk is present in the DT.
13
14 Signed-off-by: Eric Anholt <eric@anholt.net>
15 Fixes: 670c672608a1 ("soc: bcm: bcm2835-pm: Add support for power domains under a new binding.")
16 ---
17 drivers/soc/bcm/bcm2835-power.c | 35 ++++++++++++++++++++++++++++-----
18 1 file changed, 30 insertions(+), 5 deletions(-)
19
20 --- a/drivers/soc/bcm/bcm2835-power.c
21 +++ b/drivers/soc/bcm/bcm2835-power.c
22 @@ -485,7 +485,7 @@ static int bcm2835_power_pd_power_off(st
23 }
24 }
25
26 -static void
27 +static int
28 bcm2835_init_power_domain(struct bcm2835_power *power,
29 int pd_xlate_index, const char *name)
30 {
31 @@ -493,6 +493,17 @@ bcm2835_init_power_domain(struct bcm2835
32 struct bcm2835_power_domain *dom = &power->domains[pd_xlate_index];
33
34 dom->clk = devm_clk_get(dev->parent, name);
35 + if (IS_ERR(dom->clk)) {
36 + int ret = PTR_ERR(dom->clk);
37 +
38 + if (ret == -EPROBE_DEFER)
39 + return ret;
40 +
41 + /* Some domains don't have a clk, so make sure that we
42 + * don't deref an error pointer later.
43 + */
44 + dom->clk = NULL;
45 + }
46
47 dom->base.name = name;
48 dom->base.power_on = bcm2835_power_pd_power_on;
49 @@ -505,6 +516,8 @@ bcm2835_init_power_domain(struct bcm2835
50 pm_genpd_init(&dom->base, NULL, true);
51
52 power->pd_xlate.domains[pd_xlate_index] = &dom->base;
53 +
54 + return 0;
55 }
56
57 /** bcm2835_reset_reset - Resets a block that has a reset line in the
58 @@ -602,7 +615,7 @@ static int bcm2835_power_probe(struct pl
59 { BCM2835_POWER_DOMAIN_IMAGE_PERI, BCM2835_POWER_DOMAIN_CAM0 },
60 { BCM2835_POWER_DOMAIN_IMAGE_PERI, BCM2835_POWER_DOMAIN_CAM1 },
61 };
62 - int ret, i;
63 + int ret = 0, i;
64 u32 id;
65
66 power = devm_kzalloc(dev, sizeof(*power), GFP_KERNEL);
67 @@ -629,8 +642,11 @@ static int bcm2835_power_probe(struct pl
68
69 power->pd_xlate.num_domains = ARRAY_SIZE(power_domain_names);
70
71 - for (i = 0; i < ARRAY_SIZE(power_domain_names); i++)
72 - bcm2835_init_power_domain(power, i, power_domain_names[i]);
73 + for (i = 0; i < ARRAY_SIZE(power_domain_names); i++) {
74 + ret = bcm2835_init_power_domain(power, i, power_domain_names[i]);
75 + if (ret)
76 + goto fail;
77 + }
78
79 for (i = 0; i < ARRAY_SIZE(domain_deps); i++) {
80 pm_genpd_add_subdomain(&power->domains[domain_deps[i].parent].base,
81 @@ -644,12 +660,21 @@ static int bcm2835_power_probe(struct pl
82
83 ret = devm_reset_controller_register(dev, &power->reset);
84 if (ret)
85 - return ret;
86 + goto fail;
87
88 of_genpd_add_provider_onecell(dev->parent->of_node, &power->pd_xlate);
89
90 dev_info(dev, "Broadcom BCM2835 power domains driver");
91 return 0;
92 +
93 +fail:
94 + for (i = 0; i < ARRAY_SIZE(power_domain_names); i++) {
95 + struct generic_pm_domain *dom = &power->domains[i].base;
96 +
97 + if (dom->name)
98 + pm_genpd_remove(dom);
99 + }
100 + return ret;
101 }
102
103 static int bcm2835_power_remove(struct platform_device *pdev)