Lines Matching full:tegra
3 * A devfreq driver for NVIDIA Tegra SoCs
22 #include <soc/tegra/fuse.h>
218 static u32 actmon_readl(struct tegra_devfreq *tegra, u32 offset) in actmon_readl() argument
220 return readl_relaxed(tegra->regs + offset); in actmon_readl()
223 static void actmon_writel(struct tegra_devfreq *tegra, u32 val, u32 offset) in actmon_writel() argument
225 writel_relaxed(val, tegra->regs + offset); in actmon_writel()
251 static void tegra_devfreq_update_avg_wmark(struct tegra_devfreq *tegra, in tegra_devfreq_update_avg_wmark() argument
254 u32 avg_band_freq = tegra->max_freq * ACTMON_DEFAULT_AVG_BAND / KHZ; in tegra_devfreq_update_avg_wmark()
255 u32 band = avg_band_freq * tegra->devfreq->profile->polling_ms; in tegra_devfreq_update_avg_wmark()
265 static void tegra_devfreq_update_wmark(struct tegra_devfreq *tegra, in tegra_devfreq_update_wmark() argument
268 u32 val = tegra->cur_freq * tegra->devfreq->profile->polling_ms; in tegra_devfreq_update_wmark()
277 static void actmon_isr_device(struct tegra_devfreq *tegra, in actmon_isr_device() argument
283 tegra_devfreq_update_avg_wmark(tegra, dev); in actmon_isr_device()
298 if (dev->boost_freq >= tegra->max_freq) { in actmon_isr_device()
300 dev->boost_freq = tegra->max_freq; in actmon_isr_device()
323 static unsigned long actmon_cpu_to_emc_rate(struct tegra_devfreq *tegra, in actmon_cpu_to_emc_rate() argument
331 if (ratio->emc_freq >= tegra->max_freq) in actmon_cpu_to_emc_rate()
332 return tegra->max_freq; in actmon_cpu_to_emc_rate()
341 static unsigned long actmon_device_target_freq(struct tegra_devfreq *tegra, in actmon_device_target_freq() argument
347 target_freq = dev->avg_count / tegra->devfreq->profile->polling_ms; in actmon_device_target_freq()
354 static void actmon_update_target(struct tegra_devfreq *tegra, in actmon_update_target() argument
360 dev->target_freq = actmon_device_target_freq(tegra, dev); in actmon_update_target()
365 static_cpu_emc_freq = actmon_cpu_to_emc_rate(tegra, cpu_freq); in actmon_update_target()
376 struct tegra_devfreq *tegra = data; in actmon_thread_isr() local
381 mutex_lock(&tegra->devfreq->lock); in actmon_thread_isr()
383 val = actmon_readl(tegra, ACTMON_GLB_STATUS); in actmon_thread_isr()
384 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in actmon_thread_isr()
385 if (val & tegra->devices[i].config->irq_mask) { in actmon_thread_isr()
386 actmon_isr_device(tegra, tegra->devices + i); in actmon_thread_isr()
392 update_devfreq(tegra->devfreq); in actmon_thread_isr()
394 mutex_unlock(&tegra->devfreq->lock); in actmon_thread_isr()
403 struct tegra_devfreq *tegra; in tegra_actmon_clk_notify_cb() local
410 tegra = container_of(nb, struct tegra_devfreq, clk_rate_change_nb); in tegra_actmon_clk_notify_cb()
412 tegra->cur_freq = data->new_rate / KHZ; in tegra_actmon_clk_notify_cb()
414 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in tegra_actmon_clk_notify_cb()
415 dev = &tegra->devices[i]; in tegra_actmon_clk_notify_cb()
417 tegra_devfreq_update_wmark(tegra, dev); in tegra_actmon_clk_notify_cb()
425 struct tegra_devfreq *tegra = container_of(work, struct tegra_devfreq, in tegra_actmon_delayed_update() local
428 mutex_lock(&tegra->devfreq->lock); in tegra_actmon_delayed_update()
429 update_devfreq(tegra->devfreq); in tegra_actmon_delayed_update()
430 mutex_unlock(&tegra->devfreq->lock); in tegra_actmon_delayed_update()
434 tegra_actmon_cpufreq_contribution(struct tegra_devfreq *tegra, in tegra_actmon_cpufreq_contribution() argument
437 struct tegra_devfreq_device *actmon_dev = &tegra->devices[MCCPU]; in tegra_actmon_cpufreq_contribution()
440 dev_freq = actmon_device_target_freq(tegra, actmon_dev); in tegra_actmon_cpufreq_contribution()
446 static_cpu_emc_freq = actmon_cpu_to_emc_rate(tegra, cpu_freq); in tegra_actmon_cpufreq_contribution()
458 struct tegra_devfreq *tegra; in tegra_actmon_cpu_notify_cb() local
464 tegra = container_of(nb, struct tegra_devfreq, cpu_rate_change_nb); in tegra_actmon_cpu_notify_cb()
470 if (mutex_trylock(&tegra->devfreq->lock)) { in tegra_actmon_cpu_notify_cb()
471 old = tegra_actmon_cpufreq_contribution(tegra, freqs->old); in tegra_actmon_cpu_notify_cb()
472 new = tegra_actmon_cpufreq_contribution(tegra, freqs->new); in tegra_actmon_cpu_notify_cb()
473 mutex_unlock(&tegra->devfreq->lock); in tegra_actmon_cpu_notify_cb()
492 schedule_delayed_work(&tegra->cpufreq_update_work, delay); in tegra_actmon_cpu_notify_cb()
497 static void tegra_actmon_configure_device(struct tegra_devfreq *tegra, in tegra_actmon_configure_device() argument
505 dev->target_freq = tegra->cur_freq; in tegra_actmon_configure_device()
507 dev->avg_count = tegra->cur_freq * tegra->devfreq->profile->polling_ms; in tegra_actmon_configure_device()
510 tegra_devfreq_update_avg_wmark(tegra, dev); in tegra_actmon_configure_device()
511 tegra_devfreq_update_wmark(tegra, dev); in tegra_actmon_configure_device()
513 device_writel(dev, tegra->soc->count_weight, ACTMON_DEV_COUNT_WEIGHT); in tegra_actmon_configure_device()
531 static void tegra_actmon_stop_devices(struct tegra_devfreq *tegra) in tegra_actmon_stop_devices() argument
533 struct tegra_devfreq_device *dev = tegra->devices; in tegra_actmon_stop_devices()
536 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++, dev++) { in tegra_actmon_stop_devices()
543 static int tegra_actmon_resume(struct tegra_devfreq *tegra) in tegra_actmon_resume() argument
548 if (!tegra->devfreq->profile->polling_ms || !tegra->started) in tegra_actmon_resume()
551 actmon_writel(tegra, tegra->devfreq->profile->polling_ms - 1, in tegra_actmon_resume()
559 err = clk_notifier_register(tegra->emc_clock, in tegra_actmon_resume()
560 &tegra->clk_rate_change_nb); in tegra_actmon_resume()
562 dev_err(tegra->devfreq->dev.parent, in tegra_actmon_resume()
567 tegra->cur_freq = clk_get_rate(tegra->emc_clock) / KHZ; in tegra_actmon_resume()
569 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) in tegra_actmon_resume()
570 tegra_actmon_configure_device(tegra, &tegra->devices[i]); in tegra_actmon_resume()
579 err = cpufreq_register_notifier(&tegra->cpu_rate_change_nb, in tegra_actmon_resume()
582 dev_err(tegra->devfreq->dev.parent, in tegra_actmon_resume()
587 enable_irq(tegra->irq); in tegra_actmon_resume()
592 tegra_actmon_stop_devices(tegra); in tegra_actmon_resume()
594 clk_notifier_unregister(tegra->emc_clock, &tegra->clk_rate_change_nb); in tegra_actmon_resume()
599 static int tegra_actmon_start(struct tegra_devfreq *tegra) in tegra_actmon_start() argument
603 if (!tegra->started) { in tegra_actmon_start()
604 tegra->started = true; in tegra_actmon_start()
606 ret = tegra_actmon_resume(tegra); in tegra_actmon_start()
608 tegra->started = false; in tegra_actmon_start()
614 static void tegra_actmon_pause(struct tegra_devfreq *tegra) in tegra_actmon_pause() argument
616 if (!tegra->devfreq->profile->polling_ms || !tegra->started) in tegra_actmon_pause()
619 disable_irq(tegra->irq); in tegra_actmon_pause()
621 cpufreq_unregister_notifier(&tegra->cpu_rate_change_nb, in tegra_actmon_pause()
624 cancel_delayed_work_sync(&tegra->cpufreq_update_work); in tegra_actmon_pause()
626 tegra_actmon_stop_devices(tegra); in tegra_actmon_pause()
628 clk_notifier_unregister(tegra->emc_clock, &tegra->clk_rate_change_nb); in tegra_actmon_pause()
631 static void tegra_actmon_stop(struct tegra_devfreq *tegra) in tegra_actmon_stop() argument
633 tegra_actmon_pause(tegra); in tegra_actmon_stop()
634 tegra->started = false; in tegra_actmon_stop()
658 struct tegra_devfreq *tegra = dev_get_drvdata(dev); in tegra_devfreq_get_dev_status() local
662 cur_freq = READ_ONCE(tegra->cur_freq); in tegra_devfreq_get_dev_status()
664 /* To be used by the tegra governor */ in tegra_devfreq_get_dev_status()
665 stat->private_data = tegra; in tegra_devfreq_get_dev_status()
670 actmon_dev = &tegra->devices[MCALL]; in tegra_devfreq_get_dev_status()
679 stat->total_time = tegra->devfreq->profile->polling_ms * cur_freq; in tegra_devfreq_get_dev_status()
697 struct tegra_devfreq *tegra; in tegra_governor_get_target() local
709 tegra = stat->private_data; in tegra_governor_get_target()
711 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in tegra_governor_get_target()
712 dev = &tegra->devices[i]; in tegra_governor_get_target()
714 actmon_update_target(tegra, dev); in tegra_governor_get_target()
720 * tegra-devfreq driver operates with KHz units, while OPP table in tegra_governor_get_target()
732 struct tegra_devfreq *tegra = dev_get_drvdata(devfreq->dev.parent); in tegra_governor_event_handler() local
740 tegra->devfreq = devfreq; in tegra_governor_event_handler()
745 ret = tegra_actmon_start(tegra); in tegra_governor_event_handler()
749 tegra_actmon_stop(tegra); in tegra_governor_event_handler()
763 tegra_actmon_pause(tegra); in tegra_governor_event_handler()
765 ret = tegra_actmon_resume(tegra); in tegra_governor_event_handler()
769 tegra_actmon_stop(tegra); in tegra_governor_event_handler()
775 ret = tegra_actmon_start(tegra); in tegra_governor_event_handler()
793 struct tegra_devfreq *tegra = data; in devm_tegra_devfreq_deinit_hw() local
795 reset_control_reset(tegra->reset); in devm_tegra_devfreq_deinit_hw()
796 clk_disable_unprepare(tegra->clock); in devm_tegra_devfreq_deinit_hw()
800 struct tegra_devfreq *tegra) in devm_tegra_devfreq_init_hw() argument
804 err = clk_prepare_enable(tegra->clock); in devm_tegra_devfreq_init_hw()
811 tegra); in devm_tegra_devfreq_init_hw()
815 err = reset_control_reset(tegra->reset); in devm_tegra_devfreq_init_hw()
837 struct tegra_devfreq *tegra; in tegra_devfreq_probe() local
850 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); in tegra_devfreq_probe()
851 if (!tegra) in tegra_devfreq_probe()
854 tegra->soc = of_device_get_match_data(&pdev->dev); in tegra_devfreq_probe()
856 tegra->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_devfreq_probe()
857 if (IS_ERR(tegra->regs)) in tegra_devfreq_probe()
858 return PTR_ERR(tegra->regs); in tegra_devfreq_probe()
860 tegra->reset = devm_reset_control_get(&pdev->dev, "actmon"); in tegra_devfreq_probe()
861 if (IS_ERR(tegra->reset)) { in tegra_devfreq_probe()
863 return PTR_ERR(tegra->reset); in tegra_devfreq_probe()
866 tegra->clock = devm_clk_get(&pdev->dev, "actmon"); in tegra_devfreq_probe()
867 if (IS_ERR(tegra->clock)) { in tegra_devfreq_probe()
869 return PTR_ERR(tegra->clock); in tegra_devfreq_probe()
872 tegra->emc_clock = devm_clk_get(&pdev->dev, "emc"); in tegra_devfreq_probe()
873 if (IS_ERR(tegra->emc_clock)) in tegra_devfreq_probe()
874 return dev_err_probe(&pdev->dev, PTR_ERR(tegra->emc_clock), in tegra_devfreq_probe()
881 tegra->irq = err; in tegra_devfreq_probe()
883 irq_set_status_flags(tegra->irq, IRQ_NOAUTOEN); in tegra_devfreq_probe()
885 err = devm_request_threaded_irq(&pdev->dev, tegra->irq, NULL, in tegra_devfreq_probe()
887 "tegra-devfreq", tegra); in tegra_devfreq_probe()
905 err = devm_tegra_devfreq_init_hw(&pdev->dev, tegra); in tegra_devfreq_probe()
909 rate = clk_round_rate(tegra->emc_clock, ULONG_MAX); in tegra_devfreq_probe()
915 tegra->max_freq = rate / KHZ; in tegra_devfreq_probe()
917 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in tegra_devfreq_probe()
918 dev = tegra->devices + i; in tegra_devfreq_probe()
919 dev->config = tegra->soc->configs + i; in tegra_devfreq_probe()
920 dev->regs = tegra->regs + dev->config->offset; in tegra_devfreq_probe()
923 platform_set_drvdata(pdev, tegra); in tegra_devfreq_probe()
925 tegra->clk_rate_change_nb.notifier_call = tegra_actmon_clk_notify_cb; in tegra_devfreq_probe()
926 tegra->cpu_rate_change_nb.notifier_call = tegra_actmon_cpu_notify_cb; in tegra_devfreq_probe()
928 INIT_DELAYED_WORK(&tegra->cpufreq_update_work, in tegra_devfreq_probe()
937 tegra_devfreq_profile.initial_freq = clk_get_rate(tegra->emc_clock); in tegra_devfreq_probe()
975 .name = "tegra-devfreq",
982 MODULE_DESCRIPTION("Tegra devfreq driver");