Lines Matching +full:x1000 +full:- +full:ost

1 // SPDX-License-Identifier: GPL-2.0
10 #include <linux/clk-provider.h>
21 #include <dt-bindings/clock/ingenic,sysost.h>
23 /* OST register offsets */
69 struct ingenic_ost *ost; member
95 const struct ingenic_ost_clk_info *info = ost_clk->info; in ingenic_ost_percpu_timer_recalc_rate()
98 prescale = readl(ost_clk->ost->base + info->ostccr_reg); in ingenic_ost_percpu_timer_recalc_rate()
109 const struct ingenic_ost_clk_info *info = ost_clk->info; in ingenic_ost_global_timer_recalc_rate()
112 prescale = readl(ost_clk->ost->base + info->ostccr_reg); in ingenic_ost_global_timer_recalc_rate()
148 const struct ingenic_ost_clk_info *info = ost_clk->info; in ingenic_ost_percpu_timer_set_rate()
152 val = readl(ost_clk->ost->base + info->ostccr_reg); in ingenic_ost_percpu_timer_set_rate()
155 writel(val, ost_clk->ost->base + info->ostccr_reg); in ingenic_ost_percpu_timer_set_rate()
164 const struct ingenic_ost_clk_info *info = ost_clk->info; in ingenic_ost_global_timer_set_rate()
168 val = readl(ost_clk->ost->base + info->ostccr_reg); in ingenic_ost_global_timer_set_rate()
171 writel(val, ost_clk->ost->base + info->ostccr_reg); in ingenic_ost_global_timer_set_rate()
216 struct ingenic_ost *ost = ingenic_ost; in ingenic_ost_global_timer_read_cntl() local
219 count = readl(ost->base + OST_REG_OST2CNTL); in ingenic_ost_global_timer_read_cntl()
236 struct ingenic_ost *ost = to_ingenic_ost(evt); in ingenic_ost_cevt_set_state_shutdown() local
238 writel(OSTECR_OST1ENC, ost->base + OST_REG_OSTECR); in ingenic_ost_cevt_set_state_shutdown()
246 struct ingenic_ost *ost = to_ingenic_ost(evt); in ingenic_ost_cevt_set_next() local
248 writel((u32)~OSTFR_FFLAG, ost->base + OST_REG_OSTFR); in ingenic_ost_cevt_set_next()
249 writel(next, ost->base + OST_REG_OST1DFR); in ingenic_ost_cevt_set_next()
250 writel(OSTCR_OST1CLR, ost->base + OST_REG_OSTCR); in ingenic_ost_cevt_set_next()
251 writel(OSTESR_OST1ENS, ost->base + OST_REG_OSTESR); in ingenic_ost_cevt_set_next()
252 writel((u32)~OSTMR_FMASK, ost->base + OST_REG_OSTMR); in ingenic_ost_cevt_set_next()
260 struct ingenic_ost *ost = to_ingenic_ost(evt); in ingenic_ost_cevt_cb() local
262 writel(OSTECR_OST1ENC, ost->base + OST_REG_OSTECR); in ingenic_ost_cevt_cb()
264 if (evt->event_handler) in ingenic_ost_cevt_cb()
265 evt->event_handler(evt); in ingenic_ost_cevt_cb()
270 static int __init ingenic_ost_register_clock(struct ingenic_ost *ost, in ingenic_ost_register_clock() argument
279 return -ENOMEM; in ingenic_ost_register_clock()
281 ost_clk->hw.init = &info->init_data; in ingenic_ost_register_clock()
282 ost_clk->idx = idx; in ingenic_ost_register_clock()
283 ost_clk->info = info; in ingenic_ost_register_clock()
284 ost_clk->ost = ost; in ingenic_ost_register_clock()
287 val = readl(ost->base + info->ostccr_reg); in ingenic_ost_register_clock()
289 writel(val, ost->base + info->ostccr_reg); in ingenic_ost_register_clock()
291 err = clk_hw_register(NULL, &ost_clk->hw); in ingenic_ost_register_clock()
297 clocks->hws[idx] = &ost_clk->hw; in ingenic_ost_register_clock()
314 struct ingenic_ost *ost) in ingenic_ost_percpu_timer_init() argument
320 ost->percpu_timer_clk = ingenic_ost_get_clock(np, channel); in ingenic_ost_percpu_timer_init()
321 if (IS_ERR(ost->percpu_timer_clk)) in ingenic_ost_percpu_timer_init()
322 return PTR_ERR(ost->percpu_timer_clk); in ingenic_ost_percpu_timer_init()
324 err = clk_prepare_enable(ost->percpu_timer_clk); in ingenic_ost_percpu_timer_init()
328 rate = clk_get_rate(ost->percpu_timer_clk); in ingenic_ost_percpu_timer_init()
330 err = -EINVAL; in ingenic_ost_percpu_timer_init()
336 err = -EINVAL; in ingenic_ost_percpu_timer_init()
340 snprintf(ost->name, sizeof(ost->name), "OST percpu timer"); in ingenic_ost_percpu_timer_init()
343 ost->name, &ost->cevt); in ingenic_ost_percpu_timer_init()
347 ost->cevt.cpumask = cpumask_of(smp_processor_id()); in ingenic_ost_percpu_timer_init()
348 ost->cevt.features = CLOCK_EVT_FEAT_ONESHOT; in ingenic_ost_percpu_timer_init()
349 ost->cevt.name = ost->name; in ingenic_ost_percpu_timer_init()
350 ost->cevt.rating = 400; in ingenic_ost_percpu_timer_init()
351 ost->cevt.set_state_shutdown = ingenic_ost_cevt_set_state_shutdown; in ingenic_ost_percpu_timer_init()
352 ost->cevt.set_next_event = ingenic_ost_cevt_set_next; in ingenic_ost_percpu_timer_init()
354 clockevents_config_and_register(&ost->cevt, rate, 4, 0xffffffff); in ingenic_ost_percpu_timer_init()
361 clk_disable_unprepare(ost->percpu_timer_clk); in ingenic_ost_percpu_timer_init()
363 clk_put(ost->percpu_timer_clk); in ingenic_ost_percpu_timer_init()
368 struct ingenic_ost *ost) in ingenic_ost_global_timer_init() argument
371 struct clocksource *cs = &ost->cs; in ingenic_ost_global_timer_init()
375 ost->global_timer_clk = ingenic_ost_get_clock(np, channel); in ingenic_ost_global_timer_init()
376 if (IS_ERR(ost->global_timer_clk)) in ingenic_ost_global_timer_init()
377 return PTR_ERR(ost->global_timer_clk); in ingenic_ost_global_timer_init()
379 err = clk_prepare_enable(ost->global_timer_clk); in ingenic_ost_global_timer_init()
383 rate = clk_get_rate(ost->global_timer_clk); in ingenic_ost_global_timer_init()
385 err = -EINVAL; in ingenic_ost_global_timer_init()
390 writel(OSTCR_OST2CLR, ost->base + OST_REG_OSTCR); in ingenic_ost_global_timer_init()
392 /* Enable OST channel */ in ingenic_ost_global_timer_init()
393 writel(OSTESR_OST2ENS, ost->base + OST_REG_OSTESR); in ingenic_ost_global_timer_init()
395 cs->name = "ingenic-ost"; in ingenic_ost_global_timer_init()
396 cs->rating = 400; in ingenic_ost_global_timer_init()
397 cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; in ingenic_ost_global_timer_init()
398 cs->mask = CLOCKSOURCE_MASK(32); in ingenic_ost_global_timer_init()
399 cs->read = ingenic_ost_clocksource_read; in ingenic_ost_global_timer_init()
408 clk_disable_unprepare(ost->global_timer_clk); in ingenic_ost_global_timer_init()
410 clk_put(ost->global_timer_clk); in ingenic_ost_global_timer_init()
419 { .compatible = "ingenic,x1000-ost", .data = &x1000_soc_info },
426 struct ingenic_ost *ost; in ingenic_ost_probe() local
430 ost = kzalloc(sizeof(*ost), GFP_KERNEL); in ingenic_ost_probe()
431 if (!ost) in ingenic_ost_probe()
432 return -ENOMEM; in ingenic_ost_probe()
434 ost->base = of_io_request_and_map(np, 0, of_node_full_name(np)); in ingenic_ost_probe()
435 if (IS_ERR(ost->base)) { in ingenic_ost_probe()
436 pr_err("%s: Failed to map OST registers\n", __func__); in ingenic_ost_probe()
437 ret = PTR_ERR(ost->base); in ingenic_ost_probe()
441 ost->clk = of_clk_get_by_name(np, "ost"); in ingenic_ost_probe()
442 if (IS_ERR(ost->clk)) { in ingenic_ost_probe()
443 ret = PTR_ERR(ost->clk); in ingenic_ost_probe()
444 pr_crit("%s: Cannot get OST clock\n", __func__); in ingenic_ost_probe()
448 ret = clk_prepare_enable(ost->clk); in ingenic_ost_probe()
450 pr_crit("%s: Unable to enable OST clock\n", __func__); in ingenic_ost_probe()
454 ost->soc_info = id->data; in ingenic_ost_probe()
456 ost->clocks = kzalloc(struct_size(ost->clocks, hws, ost->soc_info->num_channels), in ingenic_ost_probe()
458 if (!ost->clocks) { in ingenic_ost_probe()
459 ret = -ENOMEM; in ingenic_ost_probe()
463 ost->clocks->num = ost->soc_info->num_channels; in ingenic_ost_probe()
465 for (i = 0; i < ost->clocks->num; i++) { in ingenic_ost_probe()
466 ret = ingenic_ost_register_clock(ost, i, &x1000_ost_clk_info[i], ost->clocks); in ingenic_ost_probe()
473 ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, ost->clocks); in ingenic_ost_probe()
479 ingenic_ost = ost; in ingenic_ost_probe()
484 for (i = 0; i < ost->clocks->num; i++) in ingenic_ost_probe()
485 if (ost->clocks->hws[i]) in ingenic_ost_probe()
486 clk_hw_unregister(ost->clocks->hws[i]); in ingenic_ost_probe()
487 kfree(ost->clocks); in ingenic_ost_probe()
489 clk_disable_unprepare(ost->clk); in ingenic_ost_probe()
491 clk_put(ost->clk); in ingenic_ost_probe()
493 kfree(ost); in ingenic_ost_probe()
499 struct ingenic_ost *ost; in ingenic_ost_init() local
505 pr_crit("%s: Failed to initialize OST clocks: %d\n", __func__, ret); in ingenic_ost_init()
511 ost = ingenic_ost; in ingenic_ost_init()
512 if (IS_ERR(ost)) in ingenic_ost_init()
513 return PTR_ERR(ost); in ingenic_ost_init()
515 ret = ingenic_ost_global_timer_init(np, ost); in ingenic_ost_init()
521 ret = ingenic_ost_percpu_timer_init(np, ost); in ingenic_ost_init()
526 rate = clk_get_rate(ost->global_timer_clk); in ingenic_ost_init()
532 clocksource_unregister(&ost->cs); in ingenic_ost_init()
533 clk_disable_unprepare(ost->global_timer_clk); in ingenic_ost_init()
534 clk_put(ost->global_timer_clk); in ingenic_ost_init()
536 kfree(ost); in ingenic_ost_init()
540 TIMER_OF_DECLARE(x1000_ost, "ingenic,x1000-ost", ingenic_ost_init);