Lines Matching refs:tegra
181 static u32 actmon_readl(struct tegra_devfreq *tegra, u32 offset) in actmon_readl() argument
183 return readl_relaxed(tegra->regs + offset); in actmon_readl()
186 static void actmon_writel(struct tegra_devfreq *tegra, u32 val, u32 offset) in actmon_writel() argument
188 writel_relaxed(val, tegra->regs + offset); in actmon_writel()
207 static void tegra_devfreq_update_avg_wmark(struct tegra_devfreq *tegra, in tegra_devfreq_update_avg_wmark() argument
211 u32 avg_band_freq = tegra->max_freq * ACTMON_DEFAULT_AVG_BAND / KHZ; in tegra_devfreq_update_avg_wmark()
220 static void tegra_devfreq_update_wmark(struct tegra_devfreq *tegra, in tegra_devfreq_update_wmark() argument
223 u32 val = tegra->cur_freq * ACTMON_SAMPLING_PERIOD; in tegra_devfreq_update_wmark()
232 static void actmon_write_barrier(struct tegra_devfreq *tegra) in actmon_write_barrier() argument
235 readl(tegra->regs + ACTMON_GLB_STATUS); in actmon_write_barrier()
238 static void actmon_isr_device(struct tegra_devfreq *tegra, in actmon_isr_device() argument
244 tegra_devfreq_update_avg_wmark(tegra, dev); in actmon_isr_device()
259 if (dev->boost_freq >= tegra->max_freq) in actmon_isr_device()
260 dev->boost_freq = tegra->max_freq; in actmon_isr_device()
290 actmon_write_barrier(tegra); in actmon_isr_device()
293 static unsigned long actmon_cpu_to_emc_rate(struct tegra_devfreq *tegra, in actmon_cpu_to_emc_rate() argument
301 if (ratio->emc_freq >= tegra->max_freq) in actmon_cpu_to_emc_rate()
302 return tegra->max_freq; in actmon_cpu_to_emc_rate()
311 static void actmon_update_target(struct tegra_devfreq *tegra, in actmon_update_target() argument
320 static_cpu_emc_freq = actmon_cpu_to_emc_rate(tegra, cpu_freq); in actmon_update_target()
334 struct tegra_devfreq *tegra = data; in actmon_thread_isr() local
339 mutex_lock(&tegra->devfreq->lock); in actmon_thread_isr()
341 val = actmon_readl(tegra, ACTMON_GLB_STATUS); in actmon_thread_isr()
342 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in actmon_thread_isr()
343 if (val & tegra->devices[i].config->irq_mask) { in actmon_thread_isr()
344 actmon_isr_device(tegra, tegra->devices + i); in actmon_thread_isr()
350 update_devfreq(tegra->devfreq); in actmon_thread_isr()
352 mutex_unlock(&tegra->devfreq->lock); in actmon_thread_isr()
361 struct tegra_devfreq *tegra; in tegra_actmon_rate_notify_cb() local
368 tegra = container_of(nb, struct tegra_devfreq, rate_change_nb); in tegra_actmon_rate_notify_cb()
370 tegra->cur_freq = data->new_rate / KHZ; in tegra_actmon_rate_notify_cb()
372 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in tegra_actmon_rate_notify_cb()
373 dev = &tegra->devices[i]; in tegra_actmon_rate_notify_cb()
375 tegra_devfreq_update_wmark(tegra, dev); in tegra_actmon_rate_notify_cb()
378 actmon_write_barrier(tegra); in tegra_actmon_rate_notify_cb()
383 static void tegra_actmon_configure_device(struct tegra_devfreq *tegra, in tegra_actmon_configure_device() argument
388 dev->target_freq = tegra->cur_freq; in tegra_actmon_configure_device()
390 dev->avg_count = tegra->cur_freq * ACTMON_SAMPLING_PERIOD; in tegra_actmon_configure_device()
393 tegra_devfreq_update_avg_wmark(tegra, dev); in tegra_actmon_configure_device()
394 tegra_devfreq_update_wmark(tegra, dev); in tegra_actmon_configure_device()
415 static void tegra_actmon_start(struct tegra_devfreq *tegra) in tegra_actmon_start() argument
419 disable_irq(tegra->irq); in tegra_actmon_start()
421 actmon_writel(tegra, ACTMON_SAMPLING_PERIOD - 1, in tegra_actmon_start()
424 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) in tegra_actmon_start()
425 tegra_actmon_configure_device(tegra, &tegra->devices[i]); in tegra_actmon_start()
427 actmon_write_barrier(tegra); in tegra_actmon_start()
429 enable_irq(tegra->irq); in tegra_actmon_start()
432 static void tegra_actmon_stop(struct tegra_devfreq *tegra) in tegra_actmon_stop() argument
436 disable_irq(tegra->irq); in tegra_actmon_stop()
438 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in tegra_actmon_stop()
439 device_writel(&tegra->devices[i], 0x00000000, ACTMON_DEV_CTRL); in tegra_actmon_stop()
440 device_writel(&tegra->devices[i], ACTMON_INTR_STATUS_CLEAR, in tegra_actmon_stop()
444 actmon_write_barrier(tegra); in tegra_actmon_stop()
446 enable_irq(tegra->irq); in tegra_actmon_stop()
452 struct tegra_devfreq *tegra = dev_get_drvdata(dev); in tegra_devfreq_target() local
453 struct devfreq *devfreq = tegra->devfreq; in tegra_devfreq_target()
466 err = clk_set_min_rate(tegra->emc_clock, rate); in tegra_devfreq_target()
470 err = clk_set_rate(tegra->emc_clock, 0); in tegra_devfreq_target()
477 clk_set_min_rate(tegra->emc_clock, devfreq->previous_freq); in tegra_devfreq_target()
485 struct tegra_devfreq *tegra = dev_get_drvdata(dev); in tegra_devfreq_get_dev_status() local
489 cur_freq = READ_ONCE(tegra->cur_freq); in tegra_devfreq_get_dev_status()
492 stat->private_data = tegra; in tegra_devfreq_get_dev_status()
497 actmon_dev = &tegra->devices[MCALL]; in tegra_devfreq_get_dev_status()
523 struct tegra_devfreq *tegra; in tegra_governor_get_target() local
535 tegra = stat->private_data; in tegra_governor_get_target()
537 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in tegra_governor_get_target()
538 dev = &tegra->devices[i]; in tegra_governor_get_target()
540 actmon_update_target(tegra, dev); in tegra_governor_get_target()
553 struct tegra_devfreq *tegra = dev_get_drvdata(devfreq->dev.parent); in tegra_governor_event_handler() local
558 tegra_actmon_start(tegra); in tegra_governor_event_handler()
562 tegra_actmon_stop(tegra); in tegra_governor_event_handler()
567 tegra_actmon_stop(tegra); in tegra_governor_event_handler()
573 tegra_actmon_start(tegra); in tegra_governor_event_handler()
589 struct tegra_devfreq *tegra; in tegra_devfreq_probe() local
595 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); in tegra_devfreq_probe()
596 if (!tegra) in tegra_devfreq_probe()
599 tegra->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_devfreq_probe()
600 if (IS_ERR(tegra->regs)) in tegra_devfreq_probe()
601 return PTR_ERR(tegra->regs); in tegra_devfreq_probe()
603 tegra->reset = devm_reset_control_get(&pdev->dev, "actmon"); in tegra_devfreq_probe()
604 if (IS_ERR(tegra->reset)) { in tegra_devfreq_probe()
606 return PTR_ERR(tegra->reset); in tegra_devfreq_probe()
609 tegra->clock = devm_clk_get(&pdev->dev, "actmon"); in tegra_devfreq_probe()
610 if (IS_ERR(tegra->clock)) { in tegra_devfreq_probe()
612 return PTR_ERR(tegra->clock); in tegra_devfreq_probe()
615 tegra->emc_clock = devm_clk_get(&pdev->dev, "emc"); in tegra_devfreq_probe()
616 if (IS_ERR(tegra->emc_clock)) { in tegra_devfreq_probe()
618 return PTR_ERR(tegra->emc_clock); in tegra_devfreq_probe()
621 tegra->irq = platform_get_irq(pdev, 0); in tegra_devfreq_probe()
622 if (tegra->irq < 0) { in tegra_devfreq_probe()
623 err = tegra->irq; in tegra_devfreq_probe()
628 reset_control_assert(tegra->reset); in tegra_devfreq_probe()
630 err = clk_prepare_enable(tegra->clock); in tegra_devfreq_probe()
637 reset_control_deassert(tegra->reset); in tegra_devfreq_probe()
639 tegra->max_freq = clk_round_rate(tegra->emc_clock, ULONG_MAX) / KHZ; in tegra_devfreq_probe()
640 tegra->cur_freq = clk_get_rate(tegra->emc_clock) / KHZ; in tegra_devfreq_probe()
643 dev = tegra->devices + i; in tegra_devfreq_probe()
645 dev->regs = tegra->regs + dev->config->offset; in tegra_devfreq_probe()
648 for (rate = 0; rate <= tegra->max_freq * KHZ; rate++) { in tegra_devfreq_probe()
649 rate = clk_round_rate(tegra->emc_clock, rate); in tegra_devfreq_probe()
658 platform_set_drvdata(pdev, tegra); in tegra_devfreq_probe()
660 tegra->rate_change_nb.notifier_call = tegra_actmon_rate_notify_cb; in tegra_devfreq_probe()
661 err = clk_notifier_register(tegra->emc_clock, &tegra->rate_change_nb); in tegra_devfreq_probe()
674 tegra_devfreq_profile.initial_freq = clk_get_rate(tegra->emc_clock); in tegra_devfreq_probe()
675 tegra->devfreq = devfreq_add_device(&pdev->dev, in tegra_devfreq_probe()
679 if (IS_ERR(tegra->devfreq)) { in tegra_devfreq_probe()
680 err = PTR_ERR(tegra->devfreq); in tegra_devfreq_probe()
684 err = devm_request_threaded_irq(&pdev->dev, tegra->irq, NULL, in tegra_devfreq_probe()
686 "tegra-devfreq", tegra); in tegra_devfreq_probe()
695 devfreq_remove_device(tegra->devfreq); in tegra_devfreq_probe()
701 clk_notifier_unregister(tegra->emc_clock, &tegra->rate_change_nb); in tegra_devfreq_probe()
706 reset_control_reset(tegra->reset); in tegra_devfreq_probe()
707 clk_disable_unprepare(tegra->clock); in tegra_devfreq_probe()
714 struct tegra_devfreq *tegra = platform_get_drvdata(pdev); in tegra_devfreq_remove() local
716 devfreq_remove_device(tegra->devfreq); in tegra_devfreq_remove()
719 clk_notifier_unregister(tegra->emc_clock, &tegra->rate_change_nb); in tegra_devfreq_remove()
722 reset_control_reset(tegra->reset); in tegra_devfreq_remove()
723 clk_disable_unprepare(tegra->clock); in tegra_devfreq_remove()