Lines Matching +full:tegra124 +full:- +full:emc
1 // SPDX-License-Identifier: GPL-2.0-only
76 * struct tegra_devfreq_device_config - configuration specific to an ACTMON
96 * increasing the EMC frequency when the CPU is very busy but not
152 * struct tegra_devfreq_device - state specific to an ACTMON device
220 return readl_relaxed(tegra->regs + offset); in actmon_readl()
225 writel_relaxed(val, tegra->regs + offset); in actmon_writel()
230 return readl_relaxed(dev->regs + offset); in device_readl()
236 writel_relaxed(val, dev->regs + offset); in device_writel()
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()
258 avg = min(dev->avg_count, U32_MAX - band); in tegra_devfreq_update_avg_wmark()
261 avg = max(dev->avg_count, band); in tegra_devfreq_update_avg_wmark()
262 device_writel(dev, avg - band, ACTMON_DEV_AVG_LOWER_WMARK); in tegra_devfreq_update_avg_wmark()
268 u32 val = tegra->cur_freq * tegra->devfreq->profile->polling_ms; in tegra_devfreq_update_wmark()
270 device_writel(dev, do_percent(val, dev->config->boost_up_threshold), in tegra_devfreq_update_wmark()
273 device_writel(dev, do_percent(val, dev->config->boost_down_threshold), in tegra_devfreq_update_wmark()
282 dev->avg_count = device_readl(dev, ACTMON_DEV_AVG_COUNT); in actmon_isr_device()
292 dev->boost_freq = do_percent(dev->boost_freq, in actmon_isr_device()
293 dev->config->boost_up_coeff); in actmon_isr_device()
294 dev->boost_freq += ACTMON_BOOST_FREQ_STEP; 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()
307 dev->boost_freq = do_percent(dev->boost_freq, in actmon_isr_device()
308 dev->config->boost_down_coeff); in actmon_isr_device()
312 if (dev->boost_freq < (ACTMON_BOOST_FREQ_STEP >> 1)) { in actmon_isr_device()
314 dev->boost_freq = 0; in actmon_isr_device()
330 if (cpu_freq >= ratio->cpu_freq) { in actmon_cpu_to_emc_rate()
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()
334 return ratio->emc_freq; in actmon_cpu_to_emc_rate()
347 target_freq = dev->avg_count / tegra->devfreq->profile->polling_ms; in actmon_device_target_freq()
348 avg_sustain_coef = 100 * 100 / dev->config->boost_up_threshold; in actmon_device_target_freq()
360 dev->target_freq = actmon_device_target_freq(tegra, dev); in actmon_update_target()
362 if (dev->config->avg_dependency_threshold && in actmon_update_target()
363 dev->config->avg_dependency_threshold <= dev->target_freq) { in actmon_update_target()
367 dev->target_freq += dev->boost_freq; in actmon_update_target()
368 dev->target_freq = max(dev->target_freq, static_cpu_emc_freq); in actmon_update_target()
370 dev->target_freq += dev->boost_freq; in actmon_update_target()
381 mutex_lock(&tegra->devfreq->lock); 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()
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()
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()
437 struct tegra_devfreq_device *actmon_dev = &tegra->devices[MCCPU]; in tegra_actmon_cpufreq_contribution()
443 if (dev_freq < actmon_dev->config->avg_dependency_threshold) in tegra_actmon_cpufreq_contribution()
448 if (dev_freq + actmon_dev->boost_freq >= static_cpu_emc_freq) in tegra_actmon_cpufreq_contribution()
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()
478 * state because ISR will re-check CPU's frequency on the in tegra_actmon_cpu_notify_cb()
492 schedule_delayed_work(&tegra->cpufreq_update_work, delay); in tegra_actmon_cpu_notify_cb()
503 dev->boost_freq = 0; in tegra_actmon_configure_device()
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()
508 device_writel(dev, dev->avg_count, ACTMON_DEV_INIT_AVG); in tegra_actmon_configure_device()
513 device_writel(dev, tegra->soc->count_weight, ACTMON_DEV_COUNT_WEIGHT); in tegra_actmon_configure_device()
517 val |= (ACTMON_AVERAGE_WINDOW_LOG2 - 1) in tegra_actmon_configure_device()
519 val |= (ACTMON_BELOW_WMARK_WINDOW - 1) in tegra_actmon_configure_device()
521 val |= (ACTMON_ABOVE_WMARK_WINDOW - 1) in tegra_actmon_configure_device()
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()
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()
594 clk_notifier_unregister(tegra->emc_clock, &tegra->clk_rate_change_nb); in tegra_actmon_resume()
603 if (!tegra->started) { in tegra_actmon_start()
604 tegra->started = true; in tegra_actmon_start()
608 tegra->started = false; in tegra_actmon_start()
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()
628 clk_notifier_unregister(tegra->emc_clock, &tegra->clk_rate_change_nb); in tegra_actmon_pause()
634 tegra->started = false; in tegra_actmon_stop()
662 cur_freq = READ_ONCE(tegra->cur_freq); in tegra_devfreq_get_dev_status()
665 stat->private_data = tegra; in tegra_devfreq_get_dev_status()
668 stat->current_frequency = cur_freq * KHZ; in tegra_devfreq_get_dev_status()
670 actmon_dev = &tegra->devices[MCALL]; in tegra_devfreq_get_dev_status()
673 stat->busy_time = device_readl(actmon_dev, ACTMON_DEV_AVG_COUNT); in tegra_devfreq_get_dev_status()
676 stat->busy_time *= 100 / BUS_SATURATION_RATIO; in tegra_devfreq_get_dev_status()
679 stat->total_time = tegra->devfreq->profile->polling_ms * cur_freq; in tegra_devfreq_get_dev_status()
681 stat->busy_time = min(stat->busy_time, stat->total_time); in tegra_devfreq_get_dev_status()
707 stat = &devfreq->last_status; in tegra_governor_get_target()
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()
716 target_freq = max(target_freq, dev->target_freq); 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()
737 * Couple devfreq-device with the governor early because it is in tegra_governor_event_handler()
740 tegra->devfreq = devfreq; in tegra_governor_event_handler()
759 ret = -EINVAL; in tegra_governor_event_handler()
795 reset_control_reset(tegra->reset); in devm_tegra_devfreq_deinit_hw()
796 clk_disable_unprepare(tegra->clock); in devm_tegra_devfreq_deinit_hw()
804 err = clk_prepare_enable(tegra->clock); in devm_tegra_devfreq_init_hw()
815 err = reset_control_reset(tegra->reset); in devm_tegra_devfreq_init_hw()
850 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); in tegra_devfreq_probe()
852 return -ENOMEM; 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()
862 dev_err(&pdev->dev, "Failed to get reset\n"); 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()
868 dev_err(&pdev->dev, "Failed to get actmon clock\n"); 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()
875 "Failed to get emc clock\n"); 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()
889 dev_err(&pdev->dev, "Interrupt request failed: %d\n", err); in tegra_devfreq_probe()
893 err = devm_pm_opp_set_config(&pdev->dev, &config); in tegra_devfreq_probe()
895 dev_err(&pdev->dev, "Failed to set OPP config: %d\n", err); in tegra_devfreq_probe()
899 err = devm_pm_opp_of_add_table_indexed(&pdev->dev, 0); in tegra_devfreq_probe()
901 dev_err(&pdev->dev, "Failed to add OPP table: %d\n", err); 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()
911 dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate); in tegra_devfreq_probe()
912 return rate ?: -EINVAL; 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()
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()
931 err = devm_devfreq_add_governor(&pdev->dev, &tegra_devfreq_governor); in tegra_devfreq_probe()
933 dev_err(&pdev->dev, "Failed to add governor: %d\n", err); in tegra_devfreq_probe()
937 tegra_devfreq_profile.initial_freq = clk_get_rate(tegra->emc_clock); in tegra_devfreq_probe()
939 devfreq = devm_devfreq_add_device(&pdev->dev, &tegra_devfreq_profile, in tegra_devfreq_probe()
942 dev_err(&pdev->dev, "Failed to add device: %pe\n", devfreq); in tegra_devfreq_probe()
954 * and each transaction takes 4 EMC clocks.
965 { .compatible = "nvidia,tegra30-actmon", .data = &tegra30_soc, },
966 { .compatible = "nvidia,tegra124-actmon", .data = &tegra124_soc, },
975 .name = "tegra-devfreq",