Lines Matching defs:tegra

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