Lines Matching +full:reg +full:- +full:init

1 // SPDX-License-Identifier: GPL-2.0-only
10 #include <linux/clk-provider.h>
29 * |-------RESRVED------|-NOUPDATE-|-BYPASS-|-EDGE-|--HIGHTIME--|--LOWTIME--|
34 * reg should be an u32 variable.
37 #define PLL_REG_GET_LOW(reg) \ argument
38 (((reg) & (0x3F << 0)) >> 0)
39 #define PLL_REG_GET_HIGH(reg) \ argument
40 (((reg) & (0x3F << 6)) >> 6)
41 #define PLL_REG_GET_EDGE(reg) \ argument
42 (((reg) & (BIT(12))) ? 1 : 0)
43 #define PLL_REG_GET_BYPASS(reg) \ argument
44 (((reg) & (BIT(13))) ? 1 : 0)
45 #define PLL_REG_GET_NOUPD(reg) \ argument
46 (((reg) & (BIT(14))) ? 1 : 0)
47 #define PLL_REG_GET_PAD(reg) \ argument
48 (((reg) & (0x1FFFF << 15)) >> 15)
50 #define PLL_REG_SET_LOW(reg, value) \ argument
51 { reg |= (((value) & 0x3F) << 0); }
52 #define PLL_REG_SET_HIGH(reg, value) \ argument
53 { reg |= (((value) & 0x3F) << 6); }
54 #define PLL_REG_SET_EDGE(reg, value) \ argument
55 { reg |= (((value) & 0x01) << 12); }
56 #define PLL_REG_SET_BYPASS(reg, value) \ argument
57 { reg |= (((value) & 0x01) << 13); }
58 #define PLL_REG_SET_NOUPD(reg, value) \ argument
59 { reg |= (((value) & 0x01) << 14); }
60 #define PLL_REG_SET_PAD(reg, value) \ argument
61 { reg |= (((value) & 0x1FFFF) << 15); }
99 static inline void axs10x_pll_write(struct axs10x_pll_clk *clk, u32 reg, in axs10x_pll_write() argument
102 iowrite32(val, clk->base + reg); in axs10x_pll_write()
105 static inline u32 axs10x_pll_read(struct axs10x_pll_clk *clk, u32 reg) in axs10x_pll_read() argument
107 return ioread32(clk->base + reg); in axs10x_pll_read()
115 static inline u32 axs10x_div_get_value(u32 reg) in axs10x_div_get_value() argument
117 if (PLL_REG_GET_BYPASS(reg)) in axs10x_div_get_value()
120 return PLL_REG_GET_HIGH(reg) + PLL_REG_GET_LOW(reg); in axs10x_div_get_value()
159 const struct axs10x_pll_cfg *pll_cfg = clk->pll_cfg; in axs10x_pll_round_rate()
162 return -EINVAL; in axs10x_pll_round_rate()
167 if (abs(rate - pll_cfg[i].rate) < abs(rate - best_rate)) in axs10x_pll_round_rate()
179 const struct axs10x_pll_cfg *pll_cfg = clk->pll_cfg; in axs10x_pll_set_rate()
195 if (!(ioread32(clk->lock) & PLL_LOCK)) in axs10x_pll_set_rate()
196 return -ETIMEDOUT; in axs10x_pll_set_rate()
198 if (ioread32(clk->lock) & PLL_ERROR) in axs10x_pll_set_rate()
199 return -EINVAL; in axs10x_pll_set_rate()
205 dev_err(clk->dev, "invalid rate=%ld, parent_rate=%ld\n", rate, in axs10x_pll_set_rate()
207 return -EINVAL; in axs10x_pll_set_rate()
218 struct device *dev = &pdev->dev; in axs10x_pll_clk_probe()
221 struct clk_init_data init = { }; in axs10x_pll_clk_probe() local
226 return -ENOMEM; in axs10x_pll_clk_probe()
228 pll_clk->base = devm_platform_ioremap_resource(pdev, 0); in axs10x_pll_clk_probe()
229 if (IS_ERR(pll_clk->base)) in axs10x_pll_clk_probe()
230 return PTR_ERR(pll_clk->base); in axs10x_pll_clk_probe()
232 pll_clk->lock = devm_platform_ioremap_resource(pdev, 1); in axs10x_pll_clk_probe()
233 if (IS_ERR(pll_clk->lock)) in axs10x_pll_clk_probe()
234 return PTR_ERR(pll_clk->lock); in axs10x_pll_clk_probe()
236 init.name = dev->of_node->name; in axs10x_pll_clk_probe()
237 init.ops = &axs10x_pll_ops; in axs10x_pll_clk_probe()
238 parent_name = of_clk_get_parent_name(dev->of_node, 0); in axs10x_pll_clk_probe()
239 init.parent_names = &parent_name; in axs10x_pll_clk_probe()
240 init.num_parents = 1; in axs10x_pll_clk_probe()
241 pll_clk->hw.init = &init; in axs10x_pll_clk_probe()
242 pll_clk->dev = dev; in axs10x_pll_clk_probe()
243 pll_clk->pll_cfg = of_device_get_match_data(dev); in axs10x_pll_clk_probe()
245 if (!pll_clk->pll_cfg) { in axs10x_pll_clk_probe()
247 return -EINVAL; in axs10x_pll_clk_probe()
250 ret = devm_clk_hw_register(dev, &pll_clk->hw); in axs10x_pll_clk_probe()
252 dev_err(dev, "failed to register %s clock\n", init.name); in axs10x_pll_clk_probe()
256 return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, in axs10x_pll_clk_probe()
257 &pll_clk->hw); in axs10x_pll_clk_probe()
262 of_clk_del_provider(pdev->dev.of_node); in axs10x_pll_clk_remove()
270 struct clk_init_data init = { }; in of_axs10x_pll_clk_setup() local
277 pll_clk->base = of_iomap(node, 0); in of_axs10x_pll_clk_setup()
278 if (!pll_clk->base) { in of_axs10x_pll_clk_setup()
283 pll_clk->lock = of_iomap(node, 1); in of_axs10x_pll_clk_setup()
284 if (!pll_clk->lock) { in of_axs10x_pll_clk_setup()
289 init.name = node->name; in of_axs10x_pll_clk_setup()
290 init.ops = &axs10x_pll_ops; in of_axs10x_pll_clk_setup()
292 init.parent_names = &parent_name; in of_axs10x_pll_clk_setup()
293 init.num_parents = parent_name ? 1 : 0; in of_axs10x_pll_clk_setup()
294 pll_clk->hw.init = &init; in of_axs10x_pll_clk_setup()
295 pll_clk->pll_cfg = arc_pll_cfg; in of_axs10x_pll_clk_setup()
297 ret = clk_hw_register(NULL, &pll_clk->hw); in of_axs10x_pll_clk_setup()
303 ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, &pll_clk->hw); in of_axs10x_pll_clk_setup()
312 clk_hw_unregister(&pll_clk->hw); in of_axs10x_pll_clk_setup()
314 iounmap(pll_clk->lock); in of_axs10x_pll_clk_setup()
316 iounmap(pll_clk->base); in of_axs10x_pll_clk_setup()
320 CLK_OF_DECLARE(axs10x_pll_clock, "snps,axs10x-arc-pll-clock",
324 { .compatible = "snps,axs10x-pgu-pll-clock", .data = &pgu_pll_cfg},
331 .name = "axs10x-pll-clock",