Lines Matching refs:tegra
191 static u32 actmon_readl(struct tegra_devfreq *tegra, u32 offset) in actmon_readl() argument
193 return readl(tegra->regs + offset); in actmon_readl()
196 static void actmon_writel(struct tegra_devfreq *tegra, u32 val, u32 offset) in actmon_writel() argument
198 writel(val, tegra->regs + offset); in actmon_writel()
217 static void tegra_devfreq_update_avg_wmark(struct tegra_devfreq *tegra, in tegra_devfreq_update_avg_wmark() argument
221 u32 avg_band_freq = tegra->max_freq * ACTMON_DEFAULT_AVG_BAND / KHZ; in tegra_devfreq_update_avg_wmark()
230 static void tegra_devfreq_update_wmark(struct tegra_devfreq *tegra, in tegra_devfreq_update_wmark() argument
233 u32 val = tegra->cur_freq * ACTMON_SAMPLING_PERIOD; in tegra_devfreq_update_wmark()
242 static void actmon_write_barrier(struct tegra_devfreq *tegra) in actmon_write_barrier() argument
246 actmon_readl(tegra, ACTMON_GLB_STATUS); in actmon_write_barrier()
249 static void actmon_isr_device(struct tegra_devfreq *tegra, in actmon_isr_device() argument
258 tegra_devfreq_update_avg_wmark(tegra, dev); in actmon_isr_device()
273 if (dev->boost_freq >= tegra->max_freq) in actmon_isr_device()
274 dev->boost_freq = tegra->max_freq; in actmon_isr_device()
304 actmon_write_barrier(tegra); in actmon_isr_device()
311 struct tegra_devfreq *tegra = data; in actmon_isr() local
316 val = actmon_readl(tegra, ACTMON_GLB_STATUS); in actmon_isr()
317 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in actmon_isr()
318 if (val & tegra->devices[i].config->irq_mask) { in actmon_isr()
319 actmon_isr_device(tegra, tegra->devices + i); in actmon_isr()
327 static unsigned long actmon_cpu_to_emc_rate(struct tegra_devfreq *tegra, in actmon_cpu_to_emc_rate() argument
335 if (ratio->emc_freq >= tegra->max_freq) in actmon_cpu_to_emc_rate()
336 return tegra->max_freq; in actmon_cpu_to_emc_rate()
345 static void actmon_update_target(struct tegra_devfreq *tegra, in actmon_update_target() argument
355 static_cpu_emc_freq = actmon_cpu_to_emc_rate(tegra, cpu_freq); in actmon_update_target()
373 struct tegra_devfreq *tegra = data; in actmon_thread_isr() local
375 mutex_lock(&tegra->devfreq->lock); in actmon_thread_isr()
376 update_devfreq(tegra->devfreq); in actmon_thread_isr()
377 mutex_unlock(&tegra->devfreq->lock); in actmon_thread_isr()
386 struct tegra_devfreq *tegra; in tegra_actmon_rate_notify_cb() local
394 tegra = container_of(nb, struct tegra_devfreq, rate_change_nb); in tegra_actmon_rate_notify_cb()
396 tegra->cur_freq = data->new_rate / KHZ; in tegra_actmon_rate_notify_cb()
398 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in tegra_actmon_rate_notify_cb()
399 dev = &tegra->devices[i]; in tegra_actmon_rate_notify_cb()
402 tegra_devfreq_update_wmark(tegra, dev); in tegra_actmon_rate_notify_cb()
406 actmon_write_barrier(tegra); in tegra_actmon_rate_notify_cb()
411 static void tegra_actmon_enable_interrupts(struct tegra_devfreq *tegra) in tegra_actmon_enable_interrupts() argument
417 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in tegra_actmon_enable_interrupts()
418 dev = &tegra->devices[i]; in tegra_actmon_enable_interrupts()
429 actmon_write_barrier(tegra); in tegra_actmon_enable_interrupts()
432 static void tegra_actmon_disable_interrupts(struct tegra_devfreq *tegra) in tegra_actmon_disable_interrupts() argument
438 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in tegra_actmon_disable_interrupts()
439 dev = &tegra->devices[i]; in tegra_actmon_disable_interrupts()
450 actmon_write_barrier(tegra); in tegra_actmon_disable_interrupts()
453 static void tegra_actmon_configure_device(struct tegra_devfreq *tegra, in tegra_actmon_configure_device() argument
458 dev->target_freq = tegra->cur_freq; in tegra_actmon_configure_device()
460 dev->avg_count = tegra->cur_freq * ACTMON_SAMPLING_PERIOD; in tegra_actmon_configure_device()
463 tegra_devfreq_update_avg_wmark(tegra, dev); in tegra_actmon_configure_device()
464 tegra_devfreq_update_wmark(tegra, dev); in tegra_actmon_configure_device()
480 actmon_write_barrier(tegra); in tegra_actmon_configure_device()
486 struct tegra_devfreq *tegra = dev_get_drvdata(dev); in tegra_devfreq_target() local
500 clk_set_min_rate(tegra->emc_clock, rate); in tegra_devfreq_target()
501 clk_set_rate(tegra->emc_clock, 0); in tegra_devfreq_target()
509 struct tegra_devfreq *tegra = dev_get_drvdata(dev); in tegra_devfreq_get_dev_status() local
512 stat->current_frequency = tegra->cur_freq; in tegra_devfreq_get_dev_status()
515 stat->private_data = tegra; in tegra_devfreq_get_dev_status()
519 actmon_dev = &tegra->devices[MCALL]; in tegra_devfreq_get_dev_status()
528 stat->total_time = ACTMON_SAMPLING_PERIOD * tegra->cur_freq; in tegra_devfreq_get_dev_status()
545 struct tegra_devfreq *tegra; in tegra_governor_get_target() local
557 tegra = stat->private_data; in tegra_governor_get_target()
559 for (i = 0; i < ARRAY_SIZE(tegra->devices); i++) { in tegra_governor_get_target()
560 dev = &tegra->devices[i]; in tegra_governor_get_target()
562 actmon_update_target(tegra, dev); in tegra_governor_get_target()
575 struct tegra_devfreq *tegra; in tegra_governor_event_handler() local
578 tegra = dev_get_drvdata(devfreq->dev.parent); in tegra_governor_event_handler()
583 tegra_actmon_enable_interrupts(tegra); in tegra_governor_event_handler()
587 tegra_actmon_disable_interrupts(tegra); in tegra_governor_event_handler()
592 tegra_actmon_disable_interrupts(tegra); in tegra_governor_event_handler()
598 tegra_actmon_enable_interrupts(tegra); in tegra_governor_event_handler()
613 struct tegra_devfreq *tegra; in tegra_devfreq_probe() local
621 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); in tegra_devfreq_probe()
622 if (!tegra) in tegra_devfreq_probe()
627 tegra->regs = devm_ioremap_resource(&pdev->dev, res); in tegra_devfreq_probe()
628 if (IS_ERR(tegra->regs)) in tegra_devfreq_probe()
629 return PTR_ERR(tegra->regs); in tegra_devfreq_probe()
631 tegra->reset = devm_reset_control_get(&pdev->dev, "actmon"); in tegra_devfreq_probe()
632 if (IS_ERR(tegra->reset)) { in tegra_devfreq_probe()
634 return PTR_ERR(tegra->reset); in tegra_devfreq_probe()
637 tegra->clock = devm_clk_get(&pdev->dev, "actmon"); in tegra_devfreq_probe()
638 if (IS_ERR(tegra->clock)) { in tegra_devfreq_probe()
640 return PTR_ERR(tegra->clock); in tegra_devfreq_probe()
643 tegra->emc_clock = devm_clk_get(&pdev->dev, "emc"); in tegra_devfreq_probe()
644 if (IS_ERR(tegra->emc_clock)) { in tegra_devfreq_probe()
646 return PTR_ERR(tegra->emc_clock); in tegra_devfreq_probe()
649 clk_set_rate(tegra->emc_clock, ULONG_MAX); in tegra_devfreq_probe()
651 tegra->rate_change_nb.notifier_call = tegra_actmon_rate_notify_cb; in tegra_devfreq_probe()
652 err = clk_notifier_register(tegra->emc_clock, &tegra->rate_change_nb); in tegra_devfreq_probe()
659 reset_control_assert(tegra->reset); in tegra_devfreq_probe()
661 err = clk_prepare_enable(tegra->clock); in tegra_devfreq_probe()
668 reset_control_deassert(tegra->reset); in tegra_devfreq_probe()
670 tegra->max_freq = clk_round_rate(tegra->emc_clock, ULONG_MAX) / KHZ; in tegra_devfreq_probe()
671 tegra->cur_freq = clk_get_rate(tegra->emc_clock) / KHZ; in tegra_devfreq_probe()
673 actmon_writel(tegra, ACTMON_SAMPLING_PERIOD - 1, in tegra_devfreq_probe()
677 dev = tegra->devices + i; in tegra_devfreq_probe()
679 dev->regs = tegra->regs + dev->config->offset; in tegra_devfreq_probe()
682 tegra_actmon_configure_device(tegra, dev); in tegra_devfreq_probe()
685 for (rate = 0; rate <= tegra->max_freq * KHZ; rate++) { in tegra_devfreq_probe()
686 rate = clk_round_rate(tegra->emc_clock, rate); in tegra_devfreq_probe()
696 platform_set_drvdata(pdev, tegra); in tegra_devfreq_probe()
700 "tegra-devfreq", tegra); in tegra_devfreq_probe()
706 tegra_devfreq_profile.initial_freq = clk_get_rate(tegra->emc_clock); in tegra_devfreq_probe()
707 tegra->devfreq = devm_devfreq_add_device(&pdev->dev, in tegra_devfreq_probe()
717 struct tegra_devfreq *tegra = platform_get_drvdata(pdev); in tegra_devfreq_remove() local
723 val = device_readl(&tegra->devices[i], ACTMON_DEV_CTRL); in tegra_devfreq_remove()
725 device_writel(&tegra->devices[i], val, ACTMON_DEV_CTRL); in tegra_devfreq_remove()
728 actmon_write_barrier(tegra); in tegra_devfreq_remove()
730 devm_free_irq(&pdev->dev, irq, tegra); in tegra_devfreq_remove()
732 clk_notifier_unregister(tegra->emc_clock, &tegra->rate_change_nb); in tegra_devfreq_remove()
734 clk_disable_unprepare(tegra->clock); in tegra_devfreq_remove()