blob: 84c8900542e4478e60398d674fada7094968d870 [file] [log] [blame]
Gregory CLEMENTc3828942018-09-12 15:40:17 +02001// SPDX-License-Identifier: GPL-2.0
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +02002/*
3 * Marvell Armada CP110 System Controller
4 *
5 * Copyright (C) 2016 Marvell
6 *
7 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
8 *
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +02009 */
10
11/*
Konstantin Porotchkina45af6d2017-05-31 15:19:15 +020012 * CP110 has 6 core clocks:
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020013 *
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +010014 * - PLL0 (1 Ghz)
15 * - PPv2 core (1/3 PLL0)
16 * - x2 Core (1/2 PLL0)
17 * - Core (1/2 x2 Core)
18 * - SDIO (2/5 PLL0)
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020019 *
20 * - NAND clock, which is either:
Konstantin Porotchkina45af6d2017-05-31 15:19:15 +020021 * - Equal to SDIO clock
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +010022 * - 2/5 PLL0
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020023 *
Colin Ian King7fbb6392019-04-16 12:56:16 +010024 * CP110 has 32 gateable clocks, for the various peripherals in the IP.
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020025 */
26
27#define pr_fmt(fmt) "cp110-system-controller: " fmt
28
Gregory CLEMENT33c02592019-07-10 15:43:42 +020029#include "armada_ap_cp_helper.h"
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020030#include <linux/clk-provider.h>
31#include <linux/mfd/syscon.h>
Paul Gortmaker7acf7512016-07-04 17:12:13 -040032#include <linux/init.h>
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020033#include <linux/of.h>
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020034#include <linux/platform_device.h>
35#include <linux/regmap.h>
36#include <linux/slab.h>
37
38#define CP110_PM_CLOCK_GATING_REG 0x220
39#define CP110_NAND_FLASH_CLK_CTRL_REG 0x700
40#define NF_CLOCK_SEL_400_MASK BIT(0)
41
42enum {
43 CP110_CLK_TYPE_CORE,
44 CP110_CLK_TYPE_GATABLE,
45};
46
Konstantin Porotchkina45af6d2017-05-31 15:19:15 +020047#define CP110_MAX_CORE_CLOCKS 6
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020048#define CP110_MAX_GATABLE_CLOCKS 32
49
50#define CP110_CLK_NUM \
51 (CP110_MAX_CORE_CLOCKS + CP110_MAX_GATABLE_CLOCKS)
52
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +010053#define CP110_CORE_PLL0 0
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020054#define CP110_CORE_PPV2 1
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +010055#define CP110_CORE_X2CORE 2
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020056#define CP110_CORE_CORE 3
57#define CP110_CORE_NAND 4
Konstantin Porotchkina45af6d2017-05-31 15:19:15 +020058#define CP110_CORE_SDIO 5
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020059
Colin Ian King7fbb6392019-04-16 12:56:16 +010060/* A number of gateable clocks need special handling */
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020061#define CP110_GATE_AUDIO 0
62#define CP110_GATE_COMM_UNIT 1
63#define CP110_GATE_NAND 2
64#define CP110_GATE_PPV2 3
65#define CP110_GATE_SDIO 4
Thomas Petazzoni1006ccc2016-12-21 11:26:56 +010066#define CP110_GATE_MG 5
67#define CP110_GATE_MG_CORE 6
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020068#define CP110_GATE_XOR1 7
69#define CP110_GATE_XOR0 8
Thomas Petazzoni1006ccc2016-12-21 11:26:56 +010070#define CP110_GATE_GOP_DP 9
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020071#define CP110_GATE_PCIE_X1_0 11
72#define CP110_GATE_PCIE_X1_1 12
73#define CP110_GATE_PCIE_X4 13
74#define CP110_GATE_PCIE_XOR 14
75#define CP110_GATE_SATA 15
76#define CP110_GATE_SATA_USB 16
77#define CP110_GATE_MAIN 17
Thomas Petazzoni1006ccc2016-12-21 11:26:56 +010078#define CP110_GATE_SDMMC_GOP 18
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +020079#define CP110_GATE_SLOW_IO 21
80#define CP110_GATE_USB3H0 22
81#define CP110_GATE_USB3H1 23
82#define CP110_GATE_USB3DEV 24
83#define CP110_GATE_EIP150 25
84#define CP110_GATE_EIP197 26
85
Stephen Boyd4a5aa062017-06-19 17:11:47 -070086static const char * const gate_base_names[] = {
Gregory CLEMENTf5667272017-05-31 15:11:09 +020087 [CP110_GATE_AUDIO] = "audio",
88 [CP110_GATE_COMM_UNIT] = "communit",
89 [CP110_GATE_NAND] = "nand",
90 [CP110_GATE_PPV2] = "ppv2",
91 [CP110_GATE_SDIO] = "sdio",
92 [CP110_GATE_MG] = "mg-domain",
93 [CP110_GATE_MG_CORE] = "mg-core",
94 [CP110_GATE_XOR1] = "xor1",
95 [CP110_GATE_XOR0] = "xor0",
96 [CP110_GATE_GOP_DP] = "gop-dp",
97 [CP110_GATE_PCIE_X1_0] = "pcie_x10",
98 [CP110_GATE_PCIE_X1_1] = "pcie_x11",
99 [CP110_GATE_PCIE_X4] = "pcie_x4",
100 [CP110_GATE_PCIE_XOR] = "pcie-xor",
101 [CP110_GATE_SATA] = "sata",
102 [CP110_GATE_SATA_USB] = "sata-usb",
103 [CP110_GATE_MAIN] = "main",
104 [CP110_GATE_SDMMC_GOP] = "sd-mmc-gop",
105 [CP110_GATE_SLOW_IO] = "slow-io",
106 [CP110_GATE_USB3H0] = "usb3h0",
107 [CP110_GATE_USB3H1] = "usb3h1",
108 [CP110_GATE_USB3DEV] = "usb3dev",
109 [CP110_GATE_EIP150] = "eip150",
110 [CP110_GATE_EIP197] = "eip197"
111};
112
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200113struct cp110_gate_clk {
114 struct clk_hw hw;
115 struct regmap *regmap;
116 u8 bit_idx;
117};
118
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200119#define to_cp110_gate_clk(hw) container_of(hw, struct cp110_gate_clk, hw)
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200120
121static int cp110_gate_enable(struct clk_hw *hw)
122{
123 struct cp110_gate_clk *gate = to_cp110_gate_clk(hw);
124
125 regmap_update_bits(gate->regmap, CP110_PM_CLOCK_GATING_REG,
126 BIT(gate->bit_idx), BIT(gate->bit_idx));
127
128 return 0;
129}
130
131static void cp110_gate_disable(struct clk_hw *hw)
132{
133 struct cp110_gate_clk *gate = to_cp110_gate_clk(hw);
134
135 regmap_update_bits(gate->regmap, CP110_PM_CLOCK_GATING_REG,
136 BIT(gate->bit_idx), 0);
137}
138
139static int cp110_gate_is_enabled(struct clk_hw *hw)
140{
141 struct cp110_gate_clk *gate = to_cp110_gate_clk(hw);
142 u32 val;
143
144 regmap_read(gate->regmap, CP110_PM_CLOCK_GATING_REG, &val);
145
146 return val & BIT(gate->bit_idx);
147}
148
149static const struct clk_ops cp110_gate_ops = {
150 .enable = cp110_gate_enable,
151 .disable = cp110_gate_disable,
152 .is_enabled = cp110_gate_is_enabled,
153};
154
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200155static struct clk_hw *cp110_register_gate(const char *name,
156 const char *parent_name,
157 struct regmap *regmap, u8 bit_idx)
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200158{
159 struct cp110_gate_clk *gate;
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200160 struct clk_hw *hw;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200161 struct clk_init_data init;
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200162 int ret;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200163
164 gate = kzalloc(sizeof(*gate), GFP_KERNEL);
165 if (!gate)
166 return ERR_PTR(-ENOMEM);
167
Marcin Wojtasad715b22016-09-21 11:05:57 +0200168 memset(&init, 0, sizeof(init));
169
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200170 init.name = name;
171 init.ops = &cp110_gate_ops;
172 init.parent_names = &parent_name;
173 init.num_parents = 1;
174
175 gate->regmap = regmap;
176 gate->bit_idx = bit_idx;
177 gate->hw.init = &init;
178
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200179 hw = &gate->hw;
180 ret = clk_hw_register(NULL, hw);
181 if (ret) {
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200182 kfree(gate);
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200183 hw = ERR_PTR(ret);
184 }
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200185
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200186 return hw;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200187}
188
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200189static void cp110_unregister_gate(struct clk_hw *hw)
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200190{
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200191 clk_hw_unregister(hw);
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200192 kfree(to_cp110_gate_clk(hw));
193}
194
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200195static struct clk_hw *cp110_of_clk_get(struct of_phandle_args *clkspec,
196 void *data)
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200197{
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200198 struct clk_hw_onecell_data *clk_data = data;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200199 unsigned int type = clkspec->args[0];
200 unsigned int idx = clkspec->args[1];
201
202 if (type == CP110_CLK_TYPE_CORE) {
Dan Carpenterd9f5b7f2018-12-03 17:50:55 +0300203 if (idx >= CP110_MAX_CORE_CLOCKS)
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200204 return ERR_PTR(-EINVAL);
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200205 return clk_data->hws[idx];
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200206 } else if (type == CP110_CLK_TYPE_GATABLE) {
Dan Carpenterd9f5b7f2018-12-03 17:50:55 +0300207 if (idx >= CP110_MAX_GATABLE_CLOCKS)
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200208 return ERR_PTR(-EINVAL);
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200209 return clk_data->hws[CP110_MAX_CORE_CLOCKS + idx];
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200210 }
211
212 return ERR_PTR(-EINVAL);
213}
214
Gregory CLEMENT5ffeb5f2017-05-30 17:46:06 +0200215static int cp110_syscon_common_probe(struct platform_device *pdev,
216 struct device_node *syscon_node)
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200217{
218 struct regmap *regmap;
Gregory CLEMENTf5667272017-05-31 15:11:09 +0200219 struct device *dev = &pdev->dev;
220 struct device_node *np = dev->of_node;
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100221 const char *ppv2_name, *pll0_name, *core_name, *x2core_name, *nand_name,
Konstantin Porotchkina45af6d2017-05-31 15:19:15 +0200222 *sdio_name;
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200223 struct clk_hw_onecell_data *cp110_clk_data;
224 struct clk_hw *hw, **cp110_clks;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200225 u32 nand_clk_ctrl;
226 int i, ret;
Gregory CLEMENTf5667272017-05-31 15:11:09 +0200227 char *gate_name[ARRAY_SIZE(gate_base_names)];
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200228
Gregory CLEMENT5ffeb5f2017-05-30 17:46:06 +0200229 regmap = syscon_node_to_regmap(syscon_node);
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200230 if (IS_ERR(regmap))
231 return PTR_ERR(regmap);
232
233 ret = regmap_read(regmap, CP110_NAND_FLASH_CLK_CTRL_REG,
234 &nand_clk_ctrl);
235 if (ret)
236 return ret;
237
Stephen Kitte620a1e2019-09-27 20:51:10 +0200238 cp110_clk_data = devm_kzalloc(dev, struct_size(cp110_clk_data, hws,
239 CP110_CLK_NUM),
Marcin Wojtasa0245eb2016-09-21 11:05:58 +0200240 GFP_KERNEL);
241 if (!cp110_clk_data)
242 return -ENOMEM;
243
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200244 cp110_clks = cp110_clk_data->hws;
245 cp110_clk_data->num = CP110_CLK_NUM;
Marcin Wojtasa0245eb2016-09-21 11:05:58 +0200246
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100247 /* Register the PLL0 which is the root of the hw tree */
Gregory CLEMENT33c02592019-07-10 15:43:42 +0200248 pll0_name = ap_cp_unique_name(dev, syscon_node, "pll0");
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100249 hw = clk_hw_register_fixed_rate(NULL, pll0_name, NULL, 0,
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200250 1000 * 1000 * 1000);
251 if (IS_ERR(hw)) {
252 ret = PTR_ERR(hw);
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100253 goto fail_pll0;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200254 }
255
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100256 cp110_clks[CP110_CORE_PLL0] = hw;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200257
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100258 /* PPv2 is PLL0/3 */
Gregory CLEMENT33c02592019-07-10 15:43:42 +0200259 ppv2_name = ap_cp_unique_name(dev, syscon_node, "ppv2-core");
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100260 hw = clk_hw_register_fixed_factor(NULL, ppv2_name, pll0_name, 0, 1, 3);
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200261 if (IS_ERR(hw)) {
262 ret = PTR_ERR(hw);
Gregory CLEMENT29e6beb52017-04-07 15:47:08 +0200263 goto fail_ppv2;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200264 }
265
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200266 cp110_clks[CP110_CORE_PPV2] = hw;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200267
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100268 /* X2CORE clock is PLL0/2 */
Gregory CLEMENT33c02592019-07-10 15:43:42 +0200269 x2core_name = ap_cp_unique_name(dev, syscon_node, "x2core");
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100270 hw = clk_hw_register_fixed_factor(NULL, x2core_name, pll0_name,
271 0, 1, 2);
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200272 if (IS_ERR(hw)) {
273 ret = PTR_ERR(hw);
Gregory CLEMENT29e6beb52017-04-07 15:47:08 +0200274 goto fail_eip;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200275 }
276
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100277 cp110_clks[CP110_CORE_X2CORE] = hw;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200278
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100279 /* Core clock is X2CORE/2 */
Gregory CLEMENT33c02592019-07-10 15:43:42 +0200280 core_name = ap_cp_unique_name(dev, syscon_node, "core");
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100281 hw = clk_hw_register_fixed_factor(NULL, core_name, x2core_name,
282 0, 1, 2);
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200283 if (IS_ERR(hw)) {
284 ret = PTR_ERR(hw);
Gregory CLEMENT29e6beb52017-04-07 15:47:08 +0200285 goto fail_core;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200286 }
287
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200288 cp110_clks[CP110_CORE_CORE] = hw;
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100289 /* NAND can be either PLL0/2.5 or core clock */
Gregory CLEMENT33c02592019-07-10 15:43:42 +0200290 nand_name = ap_cp_unique_name(dev, syscon_node, "nand-core");
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200291 if (nand_clk_ctrl & NF_CLOCK_SEL_400_MASK)
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200292 hw = clk_hw_register_fixed_factor(NULL, nand_name,
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100293 pll0_name, 0, 2, 5);
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200294 else
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200295 hw = clk_hw_register_fixed_factor(NULL, nand_name,
296 core_name, 0, 1, 1);
297 if (IS_ERR(hw)) {
298 ret = PTR_ERR(hw);
Gregory CLEMENT29e6beb52017-04-07 15:47:08 +0200299 goto fail_nand;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200300 }
301
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200302 cp110_clks[CP110_CORE_NAND] = hw;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200303
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100304 /* SDIO clock is PLL0/2.5 */
Gregory CLEMENT33c02592019-07-10 15:43:42 +0200305 sdio_name = ap_cp_unique_name(dev, syscon_node, "sdio-core");
Konstantin Porotchkina45af6d2017-05-31 15:19:15 +0200306 hw = clk_hw_register_fixed_factor(NULL, sdio_name,
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100307 pll0_name, 0, 2, 5);
Konstantin Porotchkina45af6d2017-05-31 15:19:15 +0200308 if (IS_ERR(hw)) {
309 ret = PTR_ERR(hw);
310 goto fail_sdio;
311 }
312
313 cp110_clks[CP110_CORE_SDIO] = hw;
314
Gregory CLEMENTf5667272017-05-31 15:11:09 +0200315 /* create the unique name for all the gate clocks */
316 for (i = 0; i < ARRAY_SIZE(gate_base_names); i++)
Gregory CLEMENT33c02592019-07-10 15:43:42 +0200317 gate_name[i] = ap_cp_unique_name(dev, syscon_node,
Gregory CLEMENT5ffeb5f2017-05-30 17:46:06 +0200318 gate_base_names[i]);
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200319
Gregory CLEMENTf5667272017-05-31 15:11:09 +0200320 for (i = 0; i < ARRAY_SIZE(gate_base_names); i++) {
321 const char *parent;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200322
Gregory CLEMENTf5667272017-05-31 15:11:09 +0200323 if (gate_name[i] == NULL)
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200324 continue;
325
326 switch (i) {
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200327 case CP110_GATE_NAND:
328 parent = nand_name;
329 break;
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100330 case CP110_GATE_MG:
331 case CP110_GATE_GOP_DP:
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200332 case CP110_GATE_PPV2:
333 parent = ppv2_name;
334 break;
335 case CP110_GATE_SDIO:
Konstantin Porotchkina45af6d2017-05-31 15:19:15 +0200336 parent = sdio_name;
337 break;
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100338 case CP110_GATE_MAIN:
339 case CP110_GATE_PCIE_XOR:
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200340 case CP110_GATE_PCIE_X4:
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100341 case CP110_GATE_EIP150:
342 case CP110_GATE_EIP197:
343 parent = x2core_name;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200344 break;
345 default:
346 parent = core_name;
347 break;
348 }
Gregory CLEMENTf5667272017-05-31 15:11:09 +0200349 hw = cp110_register_gate(gate_name[i], parent, regmap, i);
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200350
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200351 if (IS_ERR(hw)) {
352 ret = PTR_ERR(hw);
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200353 goto fail_gate;
354 }
355
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200356 cp110_clks[CP110_MAX_CORE_CLOCKS + i] = hw;
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200357 }
358
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200359 ret = of_clk_add_hw_provider(np, cp110_of_clk_get, cp110_clk_data);
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200360 if (ret)
361 goto fail_clk_add;
362
Marcin Wojtasa0245eb2016-09-21 11:05:58 +0200363 platform_set_drvdata(pdev, cp110_clks);
364
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200365 return 0;
366
367fail_clk_add:
368fail_gate:
369 for (i = 0; i < CP110_MAX_GATABLE_CLOCKS; i++) {
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200370 hw = cp110_clks[CP110_MAX_CORE_CLOCKS + i];
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200371
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200372 if (hw)
373 cp110_unregister_gate(hw);
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200374 }
375
Konstantin Porotchkina45af6d2017-05-31 15:19:15 +0200376 clk_hw_unregister_fixed_factor(cp110_clks[CP110_CORE_SDIO]);
377fail_sdio:
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200378 clk_hw_unregister_fixed_factor(cp110_clks[CP110_CORE_NAND]);
Gregory CLEMENT29e6beb52017-04-07 15:47:08 +0200379fail_nand:
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200380 clk_hw_unregister_fixed_factor(cp110_clks[CP110_CORE_CORE]);
Gregory CLEMENT29e6beb52017-04-07 15:47:08 +0200381fail_core:
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100382 clk_hw_unregister_fixed_factor(cp110_clks[CP110_CORE_X2CORE]);
Gregory CLEMENT29e6beb52017-04-07 15:47:08 +0200383fail_eip:
Marcin Wojtas57ecc7a2016-09-25 09:47:53 +0200384 clk_hw_unregister_fixed_factor(cp110_clks[CP110_CORE_PPV2]);
Gregory CLEMENT29e6beb52017-04-07 15:47:08 +0200385fail_ppv2:
Gregory CLEMENTc7e92de2018-02-28 15:07:51 +0100386 clk_hw_unregister_fixed_rate(cp110_clks[CP110_CORE_PLL0]);
387fail_pll0:
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200388 return ret;
389}
390
Gregory CLEMENT5ffeb5f2017-05-30 17:46:06 +0200391static int cp110_syscon_legacy_clk_probe(struct platform_device *pdev)
392{
393 dev_warn(&pdev->dev, FW_WARN "Using legacy device tree binding\n");
394 dev_warn(&pdev->dev, FW_WARN "Update your device tree:\n");
395 dev_warn(&pdev->dev, FW_WARN
396 "This binding won't be supported in future kernels\n");
397
398 return cp110_syscon_common_probe(pdev, pdev->dev.of_node);
399}
400
401static int cp110_clk_probe(struct platform_device *pdev)
402{
403 return cp110_syscon_common_probe(pdev, pdev->dev.of_node->parent);
404}
405
Gregory CLEMENT5ffeb5f2017-05-30 17:46:06 +0200406static const struct of_device_id cp110_syscon_legacy_of_match[] = {
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200407 { .compatible = "marvell,cp110-system-controller0", },
408 { }
409};
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200410
Gregory CLEMENT5ffeb5f2017-05-30 17:46:06 +0200411static struct platform_driver cp110_syscon_legacy_driver = {
Stephen Boyd4a5aa062017-06-19 17:11:47 -0700412 .probe = cp110_syscon_legacy_clk_probe,
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200413 .driver = {
414 .name = "marvell-cp110-system-controller0",
Gregory CLEMENT5ffeb5f2017-05-30 17:46:06 +0200415 .of_match_table = cp110_syscon_legacy_of_match,
Paul Gortmaker7acf7512016-07-04 17:12:13 -0400416 .suppress_bind_attrs = true,
Thomas Petazzonid3da3ea2016-04-14 17:33:33 +0200417 },
418};
Gregory CLEMENT5ffeb5f2017-05-30 17:46:06 +0200419builtin_platform_driver(cp110_syscon_legacy_driver);
420
421static const struct of_device_id cp110_clock_of_match[] = {
422 { .compatible = "marvell,cp110-clock", },
423 { }
424};
425
426static struct platform_driver cp110_clock_driver = {
427 .probe = cp110_clk_probe,
428 .driver = {
429 .name = "marvell-cp110-clock",
430 .of_match_table = cp110_clock_of_match,
431 .suppress_bind_attrs = true,
432 },
433};
434builtin_platform_driver(cp110_clock_driver);