Lines Matching +full:jz4770 +full:- +full:ost
1 // SPDX-License-Identifier: GPL-2.0
8 #include <linux/clk-provider.h>
10 #include <linux/mfd/ingenic-tcu.h>
16 #include <dt-bindings/clock/ingenic,tcu.h>
18 /* 8 channels max + watchdog + OST */
22 #define pr_fmt(fmt) "ingenic-tcu-clk: " fmt
68 const struct ingenic_tcu_clk_info *info = tcu_clk->info; in ingenic_tcu_enable()
69 struct ingenic_tcu *tcu = tcu_clk->tcu; in ingenic_tcu_enable()
71 regmap_write(tcu->map, TCU_REG_TSCR, BIT(info->gate_bit)); in ingenic_tcu_enable()
79 const struct ingenic_tcu_clk_info *info = tcu_clk->info; in ingenic_tcu_disable()
80 struct ingenic_tcu *tcu = tcu_clk->tcu; in ingenic_tcu_disable()
82 regmap_write(tcu->map, TCU_REG_TSSR, BIT(info->gate_bit)); in ingenic_tcu_disable()
88 const struct ingenic_tcu_clk_info *info = tcu_clk->info; in ingenic_tcu_is_enabled()
91 regmap_read(tcu_clk->tcu->map, TCU_REG_TSR, &value); in ingenic_tcu_is_enabled()
93 return !(value & BIT(info->gate_bit)); in ingenic_tcu_is_enabled()
99 const struct ingenic_tcu_clk_info *info = tcu_clk->info; in ingenic_tcu_enable_regs()
100 struct ingenic_tcu *tcu = tcu_clk->tcu; in ingenic_tcu_enable_regs()
108 regmap_write(tcu->map, TCU_REG_TSCR, BIT(info->gate_bit)); in ingenic_tcu_enable_regs()
116 const struct ingenic_tcu_clk_info *info = tcu_clk->info; in ingenic_tcu_disable_regs()
117 struct ingenic_tcu *tcu = tcu_clk->tcu; in ingenic_tcu_disable_regs()
119 regmap_write(tcu->map, TCU_REG_TSSR, BIT(info->gate_bit)); in ingenic_tcu_disable_regs()
125 const struct ingenic_tcu_clk_info *info = tcu_clk->info; in ingenic_tcu_get_parent()
129 ret = regmap_read(tcu_clk->tcu->map, info->tcsr_reg, &val); in ingenic_tcu_get_parent()
130 WARN_ONCE(ret < 0, "Unable to read TCSR %d", tcu_clk->idx); in ingenic_tcu_get_parent()
132 return ffs(val & TCU_TCSR_PARENT_CLOCK_MASK) - 1; in ingenic_tcu_get_parent()
138 const struct ingenic_tcu_clk_info *info = tcu_clk->info; in ingenic_tcu_set_parent()
144 ret = regmap_update_bits(tcu_clk->tcu->map, info->tcsr_reg, in ingenic_tcu_set_parent()
146 WARN_ONCE(ret < 0, "Unable to update TCSR %d", tcu_clk->idx); in ingenic_tcu_set_parent()
158 const struct ingenic_tcu_clk_info *info = tcu_clk->info; in ingenic_tcu_recalc_rate()
162 ret = regmap_read(tcu_clk->tcu->map, info->tcsr_reg, &prescale); in ingenic_tcu_recalc_rate()
163 WARN_ONCE(ret < 0, "Unable to read TCSR %d", tcu_clk->idx); in ingenic_tcu_recalc_rate()
184 unsigned long rate = req->best_parent_rate; in ingenic_tcu_determine_rate()
187 if (req->rate > rate) { in ingenic_tcu_determine_rate()
188 req->rate = rate; in ingenic_tcu_determine_rate()
192 prescale = ingenic_tcu_get_prescale(rate, req->rate); in ingenic_tcu_determine_rate()
194 req->rate = rate >> (prescale * 2); in ingenic_tcu_determine_rate()
202 const struct ingenic_tcu_clk_info *info = tcu_clk->info; in ingenic_tcu_set_rate()
209 ret = regmap_update_bits(tcu_clk->tcu->map, info->tcsr_reg, in ingenic_tcu_set_rate()
212 WARN_ONCE(ret < 0, "Unable to update TCSR %d", tcu_clk->idx); in ingenic_tcu_set_rate()
265 DEF_TIMER("ost", 15, TCU_REG_OST_TCSR);
278 return -ENOMEM; in ingenic_tcu_register_clock()
280 tcu_clk->hw.init = &info->init_data; in ingenic_tcu_register_clock()
281 tcu_clk->idx = idx; in ingenic_tcu_register_clock()
282 tcu_clk->info = info; in ingenic_tcu_register_clock()
283 tcu_clk->tcu = tcu; in ingenic_tcu_register_clock()
286 ingenic_tcu_enable_regs(&tcu_clk->hw); in ingenic_tcu_register_clock()
287 regmap_update_bits(tcu->map, info->tcsr_reg, 0xffff, BIT(parent)); in ingenic_tcu_register_clock()
288 ingenic_tcu_disable_regs(&tcu_clk->hw); in ingenic_tcu_register_clock()
290 err = clk_hw_register(NULL, &tcu_clk->hw); in ingenic_tcu_register_clock()
296 clocks->hws[idx] = &tcu_clk->hw; in ingenic_tcu_register_clock()
321 .has_ost = false, /* X1000 has OST, but it not belong TCU */
327 { .compatible = "ingenic,jz4740-tcu", .data = &jz4740_soc_info, },
328 { .compatible = "ingenic,jz4725b-tcu", .data = &jz4725b_soc_info, },
329 { .compatible = "ingenic,jz4760-tcu", .data = &jz4770_soc_info, },
330 { .compatible = "ingenic,jz4770-tcu", .data = &jz4770_soc_info, },
331 { .compatible = "ingenic,x1000-tcu", .data = &x1000_soc_info, },
349 return -ENOMEM; in ingenic_tcu_probe()
351 tcu->map = map; in ingenic_tcu_probe()
352 tcu->soc_info = id->data; in ingenic_tcu_probe()
354 if (tcu->soc_info->has_tcu_clk) { in ingenic_tcu_probe()
355 tcu->clk = of_clk_get_by_name(np, "tcu"); in ingenic_tcu_probe()
356 if (IS_ERR(tcu->clk)) { in ingenic_tcu_probe()
357 ret = PTR_ERR(tcu->clk); in ingenic_tcu_probe()
366 if (tcu->soc_info->allow_missing_tcu_clk && ret == -EINVAL) { in ingenic_tcu_probe()
368 tcu->clk = NULL; in ingenic_tcu_probe()
374 ret = clk_prepare_enable(tcu->clk); in ingenic_tcu_probe()
382 tcu->clocks = kzalloc(struct_size(tcu->clocks, hws, TCU_CLK_COUNT), in ingenic_tcu_probe()
384 if (!tcu->clocks) { in ingenic_tcu_probe()
385 ret = -ENOMEM; in ingenic_tcu_probe()
389 tcu->clocks->num = TCU_CLK_COUNT; in ingenic_tcu_probe()
391 for (i = 0; i < tcu->soc_info->num_channels; i++) { in ingenic_tcu_probe()
394 tcu->clocks); in ingenic_tcu_probe()
410 tcu->clocks); in ingenic_tcu_probe()
416 if (tcu->soc_info->has_ost) { in ingenic_tcu_probe()
420 tcu->clocks); in ingenic_tcu_probe()
422 pr_crit("cannot register ost clock\n"); in ingenic_tcu_probe()
427 ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, tcu->clocks); in ingenic_tcu_probe()
438 if (tcu->soc_info->has_ost) in ingenic_tcu_probe()
439 clk_hw_unregister(tcu->clocks->hws[i + 1]); in ingenic_tcu_probe()
441 clk_hw_unregister(tcu->clocks->hws[i]); in ingenic_tcu_probe()
443 for (i = 0; i < tcu->clocks->num; i++) in ingenic_tcu_probe()
444 if (tcu->clocks->hws[i]) in ingenic_tcu_probe()
445 clk_hw_unregister(tcu->clocks->hws[i]); in ingenic_tcu_probe()
446 kfree(tcu->clocks); in ingenic_tcu_probe()
448 if (tcu->clk) in ingenic_tcu_probe()
449 clk_disable_unprepare(tcu->clk); in ingenic_tcu_probe()
451 if (tcu->clk) in ingenic_tcu_probe()
452 clk_put(tcu->clk); in ingenic_tcu_probe()
462 if (tcu->clk) in tcu_pm_suspend()
463 clk_disable(tcu->clk); in tcu_pm_suspend()
472 if (tcu->clk) in tcu_pm_resume()
473 clk_enable(tcu->clk); in tcu_pm_resume()
492 CLK_OF_DECLARE_DRIVER(jz4740_cgu, "ingenic,jz4740-tcu", ingenic_tcu_init);
493 CLK_OF_DECLARE_DRIVER(jz4725b_cgu, "ingenic,jz4725b-tcu", ingenic_tcu_init);
494 CLK_OF_DECLARE_DRIVER(jz4760_cgu, "ingenic,jz4760-tcu", ingenic_tcu_init);
495 CLK_OF_DECLARE_DRIVER(jz4770_cgu, "ingenic,jz4770-tcu", ingenic_tcu_init);
496 CLK_OF_DECLARE_DRIVER(x1000_cgu, "ingenic,x1000-tcu", ingenic_tcu_init);