NVIDIA Tegra devfreq improvements and Tegra20/30 support
Subsystems (3)
Dmitry Osipenko
maintainerv3 cover NVIDIA Tegra devfreq improvements and Tegra20/30 support
Changelog:
v3: Addressed all review comments that were made by Chanwoo Choi to v2.
Patch "Synchronize IRQ after masking it in hardware" morphed into "Properly disable interrupts", which disables interrupts more solidly.
Added new minor patch: "Rename tegra-devfreq.c to tegra30-devfreq.c".
Added missed error handlings for dev_pm_opp_add().
v2: The patchset was quite heavily reworked since v1, few patches we
dropped or squashed into the new ones and more patches we added. In a result more bugs and potential problems are fixed now, driver's code got more clean up.
The Tegra20 driver-addition patch is now a part of this series, it has no changes since v1.
https://patchwork.ozlabs.org/project/linux-tegra/list/?series=102823
Dmitry Osipenko (16):
PM / devfreq: tegra: Fix kHz to Hz conversion
PM / devfreq: tegra: Replace readl-writel with relaxed versions PM / devfreq: tegra: Replace write memory barrier with the read
barrier
PM / devfreq: tegra: Don't ignore clk errors
PM / devfreq: tegra: Don't set EMC clock rate to maximum on probe PM / devfreq: tegra: Drop primary interrupt handler
PM / devfreq: tegra: Properly disable interrupts
PM / devfreq: tegra: Clean up driver's probe / remove
PM / devfreq: tegra: Avoid inconsistency of current frequency value PM / devfreq: tegra: Mark ACTMON's governor as immutable PM / devfreq: tegra: Move governor registration to driver's probe PM / devfreq: tegra: Reconfigure hardware on governor's restart PM / devfreq: tegra: Support Tegra30
PM / devfreq: tegra: Enable COMPILE_TEST for the driver PM / devfreq: tegra: Rename tegra-devfreq.c to tegra30-devfreq.c PM / devfreq: Introduce driver for NVIDIA Tegra20
MAINTAINERS | 8 +
drivers/devfreq/Kconfig | 15 +-
drivers/devfreq/Makefile | 3 +-
drivers/devfreq/tegra20-devfreq.c | 202 +++++++++++
.../{tegra-devfreq.c => tegra30-devfreq.c} | 315 ++++++++----------
5 files changed, 369 insertions(+), 174 deletions(-)
create mode 100644 drivers/devfreq/tegra20-devfreq.c
rename drivers/devfreq/{tegra-devfreq.c => tegra30-devfreq.c} (81%)Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 1/16 PM / devfreq: tegra: Fix kHz to Hz conversion
The kHz to Hz is incorrectly converted in a few places in the code, this results in a wrong frequency being calculated because devfreq core uses OPP frequencies that are given in Hz to clamp the rate, while tegra-devfreq gives to the core value in kHz and then it also expects to receive value in kHz from the core. In a result memory freq is always set to a value which is close to ULONG_MAX because of the bug. Hence the EMC frequency is always capped to the maximum and the driver doesn't do anything useful. This patch was tested on Tegra30 and Tegra124 SoC's, EMC frequency scaling works properly now.
--- drivers/devfreq/tegra-devfreq.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/devfreq/tegra-devfreq.c +5 -7
@@ -486,11 +486,11 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq, {struct tegra_devfreq *tegra =dev_get_drvdata (dev);struct dev_pm_opp *opp; -unsigned long rate = *freq *KHZ ; +unsigned long rate; - opp =devfreq_recommended_opp (dev, &rate, flags); + opp =devfreq_recommended_opp (dev, freq, flags);if (IS_ERR (opp)) { -dev_err (dev,"Failed to find opp for %lu KHz\n" , *freq); +dev_err (dev,"Failed to find opp for %lu Hz\n" , *freq);return PTR_ERR (opp); } rate =dev_pm_opp_get_freq (opp);
@@ -499,8 +499,6 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq,clk_set_min_rate (tegra->emc_clock, rate);clk_set_rate (tegra->emc_clock,0 ); - *freq = rate; -return 0 ; }
@@ -510,7 +508,7 @@ static int tegra_devfreq_get_dev_status(struct device *dev,struct tegra_devfreq *tegra =dev_get_drvdata (dev);struct tegra_devfreq_device *actmon_dev; - stat->current_frequency = tegra->cur_freq; + stat->current_frequency = tegra->cur_freq *KHZ ;/* To be used by the tegra governor */ stat->private_data = tegra;
@@ -565,7 +563,7 @@ static int tegra_governor_get_target(struct devfreq *devfreq, target_freq =max (target_freq, dev->target_freq); } - *freq = target_freq; + *freq = target_freq *KHZ ;return 0 ; }
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 2/16 PM / devfreq: tegra: Replace readl-writel with relaxed versions
In reply to Dmitry OsipenkoThere is no need to insert memory barrier on each readl/writel invocation, hence use the relaxed versions.
--- drivers/devfreq/tegra-devfreq.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/devfreq/tegra-devfreq.c +4 -4
@@ -191,23 +191,23 @@ static struct tegra_actmon_emc_ratio actmon_emc_ratios[] = {static u32 actmon_readl (struct tegra_devfreq *tegra,u32 offset) { -return readl (tegra->regs + offset); +return readl_relaxed (tegra->regs + offset); }static void actmon_writel (struct tegra_devfreq *tegra,u32 val,u32 offset) { -writel (val, tegra->regs + offset); +writel_relaxed (val, tegra->regs + offset); }static u32 device_readl (struct tegra_devfreq_device *dev,u32 offset) { -return readl (dev->regs + offset); +return readl_relaxed (dev->regs + offset); }static void device_writel (struct tegra_devfreq_device *dev,u32 val,u32 offset) { -writel (val, dev->regs + offset); +writel_relaxed (val, dev->regs + offset); }static unsigned long do_percent (unsigned long val,unsigned int pct)
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 3/16 PM / devfreq: tegra: Replace write memory barrier with the read barrier
In reply to Dmitry OsipenkoThe write memory barrier isn't needed because the BUS buffer is flushed by read after write that happens after the removed wmb(), we will also use readl() instead of the relaxed version to ensure that read is indeed completed.
--- drivers/devfreq/tegra-devfreq.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/devfreq/tegra-devfreq.c +1 -2
@@ -243,8 +243,7 @@ static void tegra_devfreq_update_wmark(struct tegra_devfreq *tegra,static void actmon_write_barrier (struct tegra_devfreq *tegra) {/* ensure the update has reached the ACTMON */ -wmb (); -actmon_readl (tegra,ACTMON_GLB_STATUS ); +readl (tegra->regs +ACTMON_GLB_STATUS ); } static void actmon_isr_device(struct tegra_devfreq *tegra,
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 4/16 PM / devfreq: tegra: Don't ignore clk errors
In reply to Dmitry OsipenkoThe clk_set_min_rate() could fail and in this case clk_set_rate() sets rate to 0, which may drop EMC rate to minimum and make machine very difficult to use.
--- drivers/devfreq/tegra-devfreq.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/devfreq/tegra-devfreq.c +14 -2
@@ -484,8 +484,10 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq, u32 flags) {struct tegra_devfreq *tegra =dev_get_drvdata (dev); +struct devfreq *devfreq = tegra->devfreq;struct dev_pm_opp *opp;unsigned long rate; +int err; opp =devfreq_recommended_opp (dev, freq, flags);if (IS_ERR (opp)) {
@@ -495,10 +497,20 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq, rate =dev_pm_opp_get_freq (opp);dev_pm_opp_put (opp); -clk_set_min_rate (tegra->emc_clock, rate); -clk_set_rate (tegra->emc_clock,0 ); + err =clk_set_min_rate (tegra->emc_clock, rate); +if (err) +return err; + + err =clk_set_rate (tegra->emc_clock,0 ); +if (err) + goto restore_min_rate;return 0 ; + +restore_min_rate: +clk_set_min_rate (tegra->emc_clock, devfreq->previous_freq); + +return err; } static int tegra_devfreq_get_dev_status(struct device *dev,
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 5/16 PM / devfreq: tegra: Don't set EMC clock rate to maximum on probe
In reply to Dmitry OsipenkoThere is no real benefit from doing so, hence let's drop that rate setting for consistency.
--- drivers/devfreq/tegra-devfreq.c | 2 -- 1 file changed, 2 deletions(-)
drivers/devfreq/tegra-devfreq.c +0 -2
@@ -653,8 +653,6 @@ static int tegra_devfreq_probe(struct platform_device *pdev)return PTR_ERR (tegra->emc_clock); } -clk_set_rate (tegra->emc_clock,ULONG_MAX ); - tegra->rate_change_nb.notifier_call = tegra_actmon_rate_notify_cb; err =clk_notifier_register (tegra->emc_clock, &tegra->rate_change_nb);if (err) {
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 6/16 PM / devfreq: tegra: Drop primary interrupt handler
In reply to Dmitry OsipenkoThere is no real need in the primary interrupt handler, hence move everything to the secondary (threaded) handler. In a result locking is consistent now and there are no potential races with the interrupt handler because it is protected with the devfreq's mutex.
--- drivers/devfreq/tegra-devfreq.c | 55 +++++++++++---------------------- 1 file changed, 18 insertions(+), 37 deletions(-)
drivers/devfreq/tegra-devfreq.c +18 -37
@@ -144,7 +144,6 @@ static struct tegra_devfreq_device_config actmon_device_configs[] = {struct tegra_devfreq_device {const struct tegra_devfreq_device_config *config;void __iomem *regs; -spinlock_t lock;/* Average event count sampled in the last interrupt */ u32 avg_count;
@@ -249,11 +248,8 @@ static void actmon_write_barrier(struct tegra_devfreq *tegra)static void actmon_isr_device (struct tegra_devfreq *tegra,struct tegra_devfreq_device *dev) { -unsigned long flags;u32 intr_status, dev_ctrl; -spin_lock_irqsave (&dev->lock, flags); - dev->avg_count =device_readl (dev,ACTMON_DEV_AVG_COUNT );tegra_devfreq_update_avg_wmark (tegra, dev);
@@ -302,26 +298,6 @@ static void actmon_isr_device(struct tegra_devfreq *tegra,device_writel (dev,ACTMON_INTR_STATUS_CLEAR ,ACTMON_DEV_INTR_STATUS );actmon_write_barrier (tegra); - -spin_unlock_irqrestore (&dev->lock, flags); -} - -static irqreturn_t actmon_isr (int irq,void *data) -{ -struct tegra_devfreq *tegra = data; -bool handled = false; -unsigned int i; -u32 val; - - val =actmon_readl (tegra,ACTMON_GLB_STATUS ); -for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { -if (val & tegra->devices[i].config->irq_mask) { -actmon_isr_device (tegra, tegra->devices + i); - handled = true; - } - } - -return handled ?IRQ_WAKE_THREAD :IRQ_NONE ; } static unsigned long actmon_cpu_to_emc_rate(struct tegra_devfreq *tegra,
@@ -348,15 +324,12 @@ static void actmon_update_target(struct tegra_devfreq *tegra,unsigned long cpu_freq =0 ;unsigned long static_cpu_emc_freq =0 ;unsigned int avg_sustain_coef; -unsigned long flags;if (dev->config->avg_dependency_threshold) { cpu_freq =cpufreq_get (0 ); static_cpu_emc_freq =actmon_cpu_to_emc_rate (tegra, cpu_freq); } -spin_lock_irqsave (&dev->lock, flags); - dev->target_freq = dev->avg_count /ACTMON_SAMPLING_PERIOD ; avg_sustain_coef =100 *100 / dev->config->boost_up_threshold; dev->target_freq =do_percent (dev->target_freq, avg_sustain_coef);
@@ -364,19 +337,31 @@ static void actmon_update_target(struct tegra_devfreq *tegra,if (dev->avg_count >= dev->config->avg_dependency_threshold) dev->target_freq =max (dev->target_freq, static_cpu_emc_freq); - -spin_unlock_irqrestore (&dev->lock, flags); }static irqreturn_t actmon_thread_isr (int irq,void *data) {struct tegra_devfreq *tegra = data; +bool handled = false; +unsigned int i; +u32 val;mutex_lock (&tegra->devfreq->lock); -update_devfreq (tegra->devfreq); + + val =actmon_readl (tegra,ACTMON_GLB_STATUS ); +for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { +if (val & tegra->devices[i].config->irq_mask) { +actmon_isr_device (tegra, tegra->devices + i); + handled = true; + } + } + +if (handled) +update_devfreq (tegra->devfreq); +mutex_unlock (&tegra->devfreq->lock); -return IRQ_HANDLED ; +return handled ?IRQ_HANDLED :IRQ_NONE ; } static int tegra_actmon_rate_notify_cb(struct notifier_block *nb,
@@ -386,7 +371,6 @@ static int tegra_actmon_rate_notify_cb(struct notifier_block *nb,struct tegra_devfreq *tegra;struct tegra_devfreq_device *dev;unsigned int i; -unsigned long flags;if (action !=POST_RATE_CHANGE )return NOTIFY_OK ;
@@ -398,9 +382,7 @@ static int tegra_actmon_rate_notify_cb(struct notifier_block *nb,for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { dev = &tegra->devices[i]; -spin_lock_irqsave (&dev->lock, flags);tegra_devfreq_update_wmark (tegra, dev); -spin_unlock_irqrestore (&dev->lock, flags); }actmon_write_barrier (tegra);
@@ -682,7 +664,6 @@ static int tegra_devfreq_probe(struct platform_device *pdev) dev = tegra->devices + i; dev->config = actmon_device_configs + i; dev->regs = tegra->regs + dev->config->offset; -spin_lock_init (&dev->lock);tegra_actmon_configure_device (tegra, dev); }
@@ -700,8 +681,8 @@ static int tegra_devfreq_probe(struct platform_device *pdev)platform_set_drvdata (pdev, tegra); - err =devm_request_threaded_irq (&pdev->dev, irq, actmon_isr, - actmon_thread_isr,IRQF_SHARED , + err =devm_request_threaded_irq (&pdev->dev, irq,NULL , + actmon_thread_isr,IRQF_ONESHOT ,"tegra-devfreq" , tegra);if (err) {dev_err (&pdev->dev,"Interrupt request failed\n" );
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 7/16 PM / devfreq: tegra: Properly disable interrupts
In reply to Dmitry OsipenkoThere is no guarantee that interrupt handling isn't running in parallel with tegra_actmon_disable_interrupts(), hence it is necessary to protect DEV_CTRL register accesses and clear IRQ status with ACTMON's IRQ being disabled in the Interrupt Controller in order to ensure that device interrupt is indeed being disabled.
--- drivers/devfreq/tegra-devfreq.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/devfreq/tegra-devfreq.c +15 -6
@@ -171,6 +171,8 @@ struct tegra_devfreq {struct notifier_block rate_change_nb;struct tegra_devfreq_device devices[ARRAY_SIZE (actmon_device_configs)]; + +int irq; };struct tegra_actmon_emc_ratio {
@@ -417,6 +419,8 @@ static void tegra_actmon_disable_interrupts(struct tegra_devfreq *tegra)u32 val;unsigned int i; +disable_irq (tegra->irq); +for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { dev = &tegra->devices[i];
@@ -427,9 +431,14 @@ static void tegra_actmon_disable_interrupts(struct tegra_devfreq *tegra) val &= ~ACTMON_DEV_CTRL_CONSECUTIVE_ABOVE_WMARK_EN ;device_writel (dev, val,ACTMON_DEV_CTRL ); + +device_writel (dev,ACTMON_INTR_STATUS_CLEAR , +ACTMON_DEV_INTR_STATUS ); }actmon_write_barrier (tegra); + +enable_irq (tegra->irq); } static void tegra_actmon_configure_device(struct tegra_devfreq *tegra,
@@ -604,7 +613,6 @@ static int tegra_devfreq_probe(struct platform_device *pdev)struct resource *res;unsigned int i;unsigned long rate; -int irq;int err; tegra =devm_kzalloc (&pdev->dev,sizeof (*tegra),GFP_KERNEL );
@@ -673,15 +681,16 @@ static int tegra_devfreq_probe(struct platform_device *pdev)dev_pm_opp_add (&pdev->dev, rate,0 ); } - irq =platform_get_irq (pdev,0 ); -if (irq <0 ) { -dev_err (&pdev->dev,"Failed to get IRQ: %d\n" , irq); -return irq; + tegra->irq =platform_get_irq (pdev,0 ); +if (tegra->irq <0 ) { + err = tegra->irq; +dev_err (&pdev->dev,"Failed to get IRQ: %d\n" , err); +return err; }platform_set_drvdata (pdev, tegra); - err =devm_request_threaded_irq (&pdev->dev, irq,NULL , + err =devm_request_threaded_irq (&pdev->dev, tegra->irq,NULL , actmon_thread_isr,IRQF_ONESHOT ,"tegra-devfreq" , tegra);if (err) {
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 8/16 PM / devfreq: tegra: Clean up driver's probe / remove
In reply to Dmitry OsipenkoReset hardware, disable ACTMON clock, release OPP's and handle all possible error cases correctly, maintaining the correct tear down order. Also use devm_platform_ioremap_resource() which is now available in the kernel.
--- drivers/devfreq/tegra-devfreq.c | 83 +++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 36 deletions(-)
drivers/devfreq/tegra-devfreq.c +47 -36
@@ -610,7 +610,6 @@ static int tegra_devfreq_probe(struct platform_device *pdev) {struct tegra_devfreq *tegra;struct tegra_devfreq_device *dev; -struct resource *res;unsigned int i;unsigned long rate;int err;
@@ -619,9 +618,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev)if (!tegra)return -ENOMEM ; - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - - tegra->regs =devm_ioremap_resource (&pdev->dev, res); + tegra->regs =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (tegra->regs))return PTR_ERR (tegra->regs);
@@ -643,11 +640,10 @@ static int tegra_devfreq_probe(struct platform_device *pdev)return PTR_ERR (tegra->emc_clock); } - tegra->rate_change_nb.notifier_call = tegra_actmon_rate_notify_cb; - err =clk_notifier_register (tegra->emc_clock, &tegra->rate_change_nb); -if (err) { -dev_err (&pdev->dev, -"Failed to register rate change notifier\n" ); + tegra->irq =platform_get_irq (pdev,0 ); +if (tegra->irq <0 ) { + err = tegra->irq; +dev_err (&pdev->dev,"Failed to get IRQ: %d\n" , err);return err; }
@@ -678,54 +674,69 @@ static int tegra_devfreq_probe(struct platform_device *pdev)for (rate =0 ; rate <= tegra->max_freq *KHZ ; rate++) { rate =clk_round_rate (tegra->emc_clock, rate); -dev_pm_opp_add (&pdev->dev, rate,0 ); - } - tegra->irq =platform_get_irq (pdev,0 ); -if (tegra->irq <0 ) { - err = tegra->irq; -dev_err (&pdev->dev,"Failed to get IRQ: %d\n" , err); -return err; + err =dev_pm_opp_add (&pdev->dev, rate,0 ); +if (err) { +dev_err (&pdev->dev,"Failed to add OPP: %d\n" , err); + goto remove_opps; + } }platform_set_drvdata (pdev, tegra); + tegra->rate_change_nb.notifier_call = tegra_actmon_rate_notify_cb; + err =clk_notifier_register (tegra->emc_clock, &tegra->rate_change_nb); +if (err) { +dev_err (&pdev->dev, +"Failed to register rate change notifier\n" ); + goto remove_opps; + } + + tegra_devfreq_profile.initial_freq =clk_get_rate (tegra->emc_clock); + tegra->devfreq =devfreq_add_device (&pdev->dev, + &tegra_devfreq_profile, +"tegra_actmon" , +NULL ); +if (IS_ERR (tegra->devfreq)) { + err =PTR_ERR (tegra->devfreq); + goto unreg_notifier; + } + err =devm_request_threaded_irq (&pdev->dev, tegra->irq,NULL , actmon_thread_isr,IRQF_ONESHOT ,"tegra-devfreq" , tegra);if (err) { -dev_err (&pdev->dev,"Interrupt request failed\n" ); -return err; +dev_err (&pdev->dev,"Interrupt request failed: %d\n" , err); + goto remove_devfreq; } - tegra_devfreq_profile.initial_freq =clk_get_rate (tegra->emc_clock); - tegra->devfreq =devm_devfreq_add_device (&pdev->dev, - &tegra_devfreq_profile, -"tegra_actmon" , -NULL ); -return 0 ; + +remove_devfreq: +devfreq_remove_device (tegra->devfreq); + +unreg_notifier: +clk_notifier_unregister (tegra->emc_clock, &tegra->rate_change_nb); + +remove_opps: +dev_pm_opp_remove_all_dynamic (&pdev->dev); + +reset_control_reset (tegra->reset); +clk_disable_unprepare (tegra->clock); + +return err; }static int tegra_devfreq_remove (struct platform_device *pdev) {struct tegra_devfreq *tegra =platform_get_drvdata (pdev); -int irq =platform_get_irq (pdev,0 ); -u32 val; -unsigned int i; - -for (i =0 ; i <ARRAY_SIZE (actmon_device_configs); i++) { - val =device_readl (&tegra->devices[i],ACTMON_DEV_CTRL ); - val &= ~ACTMON_DEV_CTRL_ENB ; -device_writel (&tegra->devices[i], val,ACTMON_DEV_CTRL ); - } - -actmon_write_barrier (tegra); -devm_free_irq (&pdev->dev, irq, tegra); +devfreq_remove_device (tegra->devfreq); +dev_pm_opp_remove_all_dynamic (&pdev->dev);clk_notifier_unregister (tegra->emc_clock, &tegra->rate_change_nb); +reset_control_reset (tegra->reset);clk_disable_unprepare (tegra->clock);return 0 ;
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 9/16 PM / devfreq: tegra: Avoid inconsistency of current frequency value
In reply to Dmitry OsipenkoThe frequency value potentially could change in-between. It doesn't cause any real problem at all right now, but that could change in the future. Hence let's avoid the inconsistency.
--- drivers/devfreq/tegra-devfreq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/devfreq/tegra-devfreq.c +4 -2
@@ -509,13 +509,15 @@ static int tegra_devfreq_get_dev_status(struct device *dev, {struct tegra_devfreq *tegra =dev_get_drvdata (dev);struct tegra_devfreq_device *actmon_dev; +unsigned long cur_freq; - stat->current_frequency = tegra->cur_freq *KHZ ; + cur_freq =READ_ONCE (tegra->cur_freq);/* To be used by the tegra governor */ stat->private_data = tegra;/* The below are to be used by the other governors */ + stat->current_frequency = cur_freq *KHZ ; actmon_dev = &tegra->devices[MCALL ];
@@ -526,7 +528,7 @@ static int tegra_devfreq_get_dev_status(struct device *dev, stat->busy_time *=100 /BUS_SATURATION_RATIO ;/* Number of cycles in a sampling period */ - stat->total_time =ACTMON_SAMPLING_PERIOD * tegra->cur_freq; + stat->total_time =ACTMON_SAMPLING_PERIOD * cur_freq; stat->busy_time =min (stat->busy_time, stat->total_time);
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 10/16 PM / devfreq: tegra: Mark ACTMON's governor as immutable
In reply to Dmitry OsipenkoThe ACTMON's governor supports only the Tegra's devfreq device and there is no need to use any other governor, hence let's mark Tegra governor as immutable to permanently stick it with Tegra's devfreq device.
--- drivers/devfreq/Kconfig | 1 - drivers/devfreq/tegra-devfreq.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/devfreq/Kconfig +0 -1
@@ -94,7 +94,6 @@ config ARM_EXYNOS_BUS_DEVFREQ config ARM_TEGRA_DEVFREQ tristate "Tegra DEVFREQ Driver" depends on ARCH_TEGRA_124_SOC - select DEVFREQ_GOV_SIMPLE_ONDEMAND select PM_OPP help This adds the DEVFREQ driver for the Tegra family of SoCs.
drivers/devfreq/tegra-devfreq.c +1 -0
@@ -606,6 +606,7 @@ static struct devfreq_governor tegra_devfreq_governor = { .name = "tegra_actmon", .get_target_freq = tegra_governor_get_target, .event_handler = tegra_governor_event_handler, + .immutable = true, };static int tegra_devfreq_probe (struct platform_device *pdev)
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 11/16 PM / devfreq: tegra: Move governor registration to driver's probe
In reply to Dmitry OsipenkoThere is no need to register the ACTMON's governor separately from the driver, hence let's move the registration into the driver's probe function for consistency and to make code cleaner a tad.
--- drivers/devfreq/tegra-devfreq.c | 43 +++++++++------------------------ 1 file changed, 12 insertions(+), 31 deletions(-)
drivers/devfreq/tegra-devfreq.c +12 -31
@@ -695,6 +695,12 @@ static int tegra_devfreq_probe(struct platform_device *pdev) goto remove_opps; } + err =devfreq_add_governor (&tegra_devfreq_governor); +if (err) { +dev_err (&pdev->dev,"Failed to add governor: %d\n" , err); + goto unreg_notifier; + } + tegra_devfreq_profile.initial_freq =clk_get_rate (tegra->emc_clock); tegra->devfreq = devfreq_add_device(&pdev->dev, &tegra_devfreq_profile,
@@ -702,7 +708,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev) NULL);if (IS_ERR (tegra->devfreq)) { err =PTR_ERR (tegra->devfreq); - goto unreg_notifier; + goto remove_governor; } err = devm_request_threaded_irq(&pdev->dev, tegra->irq, NULL,
@@ -718,6 +724,9 @@ static int tegra_devfreq_probe(struct platform_device *pdev) remove_devfreq:devfreq_remove_device (tegra->devfreq); +remove_governor: +devfreq_remove_governor (&tegra_devfreq_governor); + unreg_notifier:clk_notifier_unregister (tegra->emc_clock, &tegra->rate_change_nb);
@@ -735,6 +744,7 @@ static int tegra_devfreq_remove(struct platform_device *pdev)struct tegra_devfreq *tegra =platform_get_drvdata (pdev);devfreq_remove_device (tegra->devfreq); +devfreq_remove_governor (&tegra_devfreq_governor);dev_pm_opp_remove_all_dynamic (&pdev->dev);clk_notifier_unregister (tegra->emc_clock, &tegra->rate_change_nb);
@@ -760,36 +770,7 @@ static struct platform_driver tegra_devfreq_driver = { .of_match_table = tegra_devfreq_of_match, }, }; - -static int __init tegra_devfreq_init (void ) -{ -int ret =0 ; - - ret =devfreq_add_governor (&tegra_devfreq_governor); -if (ret) { -pr_err ("%s: failed to add governor: %d\n" , __func__, ret); -return ret; - } - - ret =platform_driver_register (&tegra_devfreq_driver); -if (ret) -devfreq_remove_governor (&tegra_devfreq_governor); - -return ret; -} -module_init (tegra_devfreq_init) - -static void __exit tegra_devfreq_exit(void) -{ -int ret =0 ; - -platform_driver_unregister (&tegra_devfreq_driver); - - ret =devfreq_remove_governor (&tegra_devfreq_governor); -if (ret) -pr_err ("%s: failed to remove governor: %d\n" , __func__, ret); -} -module_exit(tegra_devfreq_exit) +module_platform_driver (tegra_devfreq_driver);MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("Tegra devfreq driver" );
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 12/16 PM / devfreq: tegra: Reconfigure hardware on governor's restart
In reply to Dmitry OsipenkoMove hardware configuration to governor's start/resume methods. This allows to re-initialize hardware counters and reconfigure cleanly if governor was stopped/paused. That is needed because we are not aware of all hardware changes that happened while governor was stopped and the paused state may get out of sync with reality, hence it's better to start with a clean slate after the pause. In a result there is no memory bandwidth starvation after resume from suspend-to-ram that results in display controller underflowing that happens on resume because of improper decision made by devfreq about the required memory frequency. This change also cleans up code a tad by moving hardware-configuration code into a single location.
--- drivers/devfreq/tegra-devfreq.c | 98 ++++++++++++++------------------- 1 file changed, 40 insertions(+), 58 deletions(-)
drivers/devfreq/tegra-devfreq.c +40 -58
@@ -392,55 +392,6 @@ static int tegra_actmon_rate_notify_cb(struct notifier_block *nb,return NOTIFY_OK ; } -static void tegra_actmon_enable_interrupts (struct tegra_devfreq *tegra) -{ -struct tegra_devfreq_device *dev; -u32 val; -unsigned int i; - -for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { - dev = &tegra->devices[i]; - - val =device_readl (dev,ACTMON_DEV_CTRL ); - val |=ACTMON_DEV_CTRL_AVG_ABOVE_WMARK_EN ; - val |=ACTMON_DEV_CTRL_AVG_BELOW_WMARK_EN ; - val |=ACTMON_DEV_CTRL_CONSECUTIVE_BELOW_WMARK_EN ; - val |=ACTMON_DEV_CTRL_CONSECUTIVE_ABOVE_WMARK_EN ; - -device_writel (dev, val,ACTMON_DEV_CTRL ); - } - -actmon_write_barrier (tegra); -} - -static void tegra_actmon_disable_interrupts (struct tegra_devfreq *tegra) -{ -struct tegra_devfreq_device *dev; -u32 val; -unsigned int i; - -disable_irq (tegra->irq); - -for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { - dev = &tegra->devices[i]; - - val =device_readl (dev,ACTMON_DEV_CTRL ); - val &= ~ACTMON_DEV_CTRL_AVG_ABOVE_WMARK_EN ; - val &= ~ACTMON_DEV_CTRL_AVG_BELOW_WMARK_EN ; - val &= ~ACTMON_DEV_CTRL_CONSECUTIVE_BELOW_WMARK_EN ; - val &= ~ACTMON_DEV_CTRL_CONSECUTIVE_ABOVE_WMARK_EN ; - -device_writel (dev, val,ACTMON_DEV_CTRL ); - -device_writel (dev,ACTMON_INTR_STATUS_CLEAR , -ACTMON_DEV_INTR_STATUS ); - } - -actmon_write_barrier (tegra); - -enable_irq (tegra->irq); -} -static void tegra_actmon_configure_device (struct tegra_devfreq *tegra,struct tegra_devfreq_device *dev) {
@@ -464,11 +415,47 @@ static void tegra_actmon_configure_device(struct tegra_devfreq *tegra, << ACTMON_DEV_CTRL_CONSECUTIVE_BELOW_WMARK_NUM_SHIFT; val |= (ACTMON_ABOVE_WMARK_WINDOW -1 ) <<ACTMON_DEV_CTRL_CONSECUTIVE_ABOVE_WMARK_NUM_SHIFT ; + val |=ACTMON_DEV_CTRL_AVG_ABOVE_WMARK_EN ; + val |=ACTMON_DEV_CTRL_AVG_BELOW_WMARK_EN ; + val |=ACTMON_DEV_CTRL_CONSECUTIVE_BELOW_WMARK_EN ; + val |=ACTMON_DEV_CTRL_CONSECUTIVE_ABOVE_WMARK_EN ; val |=ACTMON_DEV_CTRL_ENB ;device_writel (dev, val,ACTMON_DEV_CTRL ); +} + +static void tegra_actmon_start (struct tegra_devfreq *tegra) +{ +unsigned int i; + +disable_irq (tegra->irq); + +actmon_writel (tegra,ACTMON_SAMPLING_PERIOD -1 , +ACTMON_GLB_PERIOD_CTRL ); + +for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) +tegra_actmon_configure_device (tegra, &tegra->devices[i]); + +actmon_write_barrier (tegra); + +enable_irq (tegra->irq); +} + +static void tegra_actmon_stop (struct tegra_devfreq *tegra) +{ +unsigned int i; + +disable_irq (tegra->irq); + +for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { +device_writel (&tegra->devices[i],0x00000000 ,ACTMON_DEV_CTRL ); +device_writel (&tegra->devices[i],ACTMON_INTR_STATUS_CLEAR , +ACTMON_DEV_INTR_STATUS ); + }actmon_write_barrier (tegra); + +enable_irq (tegra->irq); } static int tegra_devfreq_target(struct device *dev, unsigned long *freq,
@@ -580,22 +567,22 @@ static int tegra_governor_event_handler(struct devfreq *devfreq,switch (event) {case DEVFREQ_GOV_START :devfreq_monitor_start (devfreq); -tegra_actmon_enable_interrupts (tegra); +tegra_actmon_start (tegra);break ;case DEVFREQ_GOV_STOP : -tegra_actmon_disable_interrupts (tegra); +tegra_actmon_stop (tegra);devfreq_monitor_stop (devfreq);break ;case DEVFREQ_GOV_SUSPEND : -tegra_actmon_disable_interrupts (tegra); +tegra_actmon_stop (tegra);devfreq_monitor_suspend (devfreq);break ;case DEVFREQ_GOV_RESUME :devfreq_monitor_resume (devfreq); -tegra_actmon_enable_interrupts (tegra); +tegra_actmon_start (tegra);break ; }
@@ -664,15 +651,10 @@ static int tegra_devfreq_probe(struct platform_device *pdev) tegra->max_freq =clk_round_rate (tegra->emc_clock,ULONG_MAX ) /KHZ ; tegra->cur_freq =clk_get_rate (tegra->emc_clock) /KHZ ; -actmon_writel (tegra,ACTMON_SAMPLING_PERIOD -1 , -ACTMON_GLB_PERIOD_CTRL ); -for (i =0 ; i <ARRAY_SIZE (actmon_device_configs); i++) { dev = tegra->devices + i; dev->config = actmon_device_configs + i; dev->regs = tegra->regs + dev->config->offset; - -tegra_actmon_configure_device (tegra, dev); }for (rate =0 ; rate <= tegra->max_freq *KHZ ; rate++) {
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 13/16 PM / devfreq: tegra: Support Tegra30
In reply to Dmitry OsipenkoThe devfreq driver can be used on Tegra30 without any code change and it works perfectly fine, the default Tegra124 parameters are good enough for Tegra30.
--- drivers/devfreq/Kconfig | 4 ++-- drivers/devfreq/tegra-devfreq.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/devfreq/Kconfig +2 -2
@@ -92,8 +92,8 @@ config ARM_EXYNOS_BUS_DEVFREQ This does not yet operate with optimal voltages. config ARM_TEGRA_DEVFREQ - tristate "Tegra DEVFREQ Driver" - depends on ARCH_TEGRA_124_SOC + tristate "NVIDIA Tegra30/114/124/210 DEVFREQ Driver" + depends on ARCH_TEGRA select PM_OPP help This adds the DEVFREQ driver for the Tegra family of SoCs.
drivers/devfreq/tegra-devfreq.c +1 -0
@@ -738,6 +738,7 @@ static int tegra_devfreq_remove(struct platform_device *pdev) }static const struct of_device_id tegra_devfreq_of_match[] = { + { .compatible ="nvidia,tegra30-actmon" }, { .compatible ="nvidia,tegra124-actmon" }, { }, };
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 14/16 PM / devfreq: tegra: Enable COMPILE_TEST for the driver
In reply to Dmitry OsipenkoThe driver's compilation doesn't have any specific dependencies, hence the COMPILE_TEST option can be supported in Kconfig.
--- drivers/devfreq/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/devfreq/Kconfig +1 -1
@@ -93,7 +93,7 @@ config ARM_EXYNOS_BUS_DEVFREQ config ARM_TEGRA_DEVFREQ tristate "NVIDIA Tegra30/114/124/210 DEVFREQ Driver" - depends on ARCH_TEGRA + depends on ARCH_TEGRA || COMPILE_TEST select PM_OPP help This adds the DEVFREQ driver for the Tegra family of SoCs.
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 15/16 PM / devfreq: tegra: Rename tegra-devfreq.c to tegra30-devfreq.c
In reply to Dmitry OsipenkoIn order to reflect that driver serves NVIDIA Tegra30 and later SoC generations, let's rename the driver's source file to "tegra30-devfreq.c". This will make driver files to look more consistent after addition of a driver for Tegra20.
---
drivers/devfreq/Makefile | 2 +-
drivers/devfreq/{tegra-devfreq.c => tegra30-devfreq.c} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename drivers/devfreq/{tegra-devfreq.c => tegra30-devfreq.c} (100%)drivers/devfreq/Makefile +1 -1
@@ -10,7 +10,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) += governor_passive.o # DEVFREQ Drivers obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o -obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra-devfreq.o +obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.o # DEVFREQ Event Drivers obj-$(CONFIG_PM_DEVFREQ_EVENT) += event/
drivers/devfreq/tegra30-devfreq.c renamed from drivers/devfreq/tegra-devfreq.c +0 -0
Signature · 1 line
2.21.0
Dmitry Osipenko
maintainerPATCH v3 16/16 PM / devfreq: Introduce driver for NVIDIA Tegra20
In reply to Dmitry OsipenkoAdd devfreq driver for NVIDIA Tegra20 SoC's. The driver periodically reads out Memory Controller counters and adjusts memory frequency based on the memory clients activity.
--- MAINTAINERS | 8 ++ drivers/devfreq/Kconfig | 10 ++ drivers/devfreq/Makefile | 1 + drivers/devfreq/tegra20-devfreq.c | 202 ++++++++++++++++++++++++++++++ 4 files changed, 221 insertions(+) create mode 100644 drivers/devfreq/tegra20-devfreq.c
MAINTAINERS +8 -0
@@ -10070,6 +10070,14 @@ F: include/linux/memblock.h F: mm/memblock.c F: Documentation/core-api/boot-time-mm.rst +MEMORY FREQUENCY SCALING DRIVER FOR NVIDIA TEGRA20 +M: Dmitry Osipenko <[email protected]> +L: [email protected] +L: [email protected] +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mzx/devfreq.git +S: Maintained +F: drivers/devfreq/tegra20-devfreq.c + MEMORY MANAGEMENT L: [email protected] W: http://www.linux-mm.org
drivers/devfreq/Kconfig +10 -0
@@ -100,6 +100,16 @@ config ARM_TEGRA_DEVFREQ It reads ACTMON counters of memory controllers and adjusts the operating frequencies and voltages with OPP support. +config ARM_TEGRA20_DEVFREQ + tristate "NVIDIA Tegra20 DEVFREQ Driver" + depends on (TEGRA_MC && TEGRA20_EMC) || COMPILE_TEST + select DEVFREQ_GOV_SIMPLE_ONDEMAND + select PM_OPP + help + This adds the DEVFREQ driver for the Tegra20 family of SoCs. + It reads Memory Controller counters and adjusts the operating + frequencies and voltages with OPP support. + config ARM_RK3399_DMC_DEVFREQ tristate "ARM RK3399 DMC DEVFREQ Driver" depends on ARCH_ROCKCHIP
drivers/devfreq/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) += governor_passive.o obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.o +obj-$(CONFIG_ARM_TEGRA20_DEVFREQ) += tegra20-devfreq.o # DEVFREQ Event Drivers obj-$(CONFIG_PM_DEVFREQ_EVENT) += event/
drivers/devfreq/tegra20-devfreq.c new file +202 -0
202 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH v3 13/16] PM / devfreq: tegra: Support Tegra30
In reply to Dmitry OsipenkoQuoted 31 lines · Dmitry Osipenko
The devfreq driver can be used on Tegra30 without any code change and it works perfectly fine, the default Tegra124 parameters are good enough for Tegra30.
Signed-off-by Dmitry Osipenko <[email protected]>--- drivers/devfreq/Kconfig | 4 ++-- drivers/devfreq/tegra-devfreq.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)drivers/devfreq/Kconfig +2
-2@@ -92,8 +92,8 @@ config ARM_EXYNOS_BUS_DEVFREQ This does not yet operate with optimal voltages. config ARM_TEGRA_DEVFREQ - tristate "Tegra DEVFREQ Driver" - depends on ARCH_TEGRA_124_SOC + tristate "NVIDIA Tegra30/114/124/210 DEVFREQ Driver" + depends on ARCH_TEGRA select PM_OPP help This adds the DEVFREQ driver for the Tegra family of SoCs.drivers/devfreq/tegra-devfreq.c +0
-0
drivers/devfreq/tegra-devfreq.c static int tegra_devfreq_remove(struct platform_device *pdev) · line 744
Quoted 7 lines
drivers/devfreq/tegra-devfreq.c +1
-0@@ -738,6 +738,7 @@ static int tegra_devfreq_remove(struct platform_device *pdev) }static const struct of_device_id tegra_devfreq_of_match[] = { + { .compatible ="nvidia,tegra30-actmon" }, { .compatible ="nvidia,tegra124-actmon" }, { }, };
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Re: [PATCH v3 15/16] PM / devfreq: tegra: Rename tegra-devfreq.c to tegra30-devfreq.c
In reply to Dmitry Osipenkodrivers/devfreq/tegra30-devfreq.c
Quoted 30 lines · Dmitry Osipenko
In order to reflect that driver serves NVIDIA Tegra30 and later SoC generations, let's rename the driver's source file to "
tegra30-devfreq.c". This will make driver files to look more consistent after addition of a driver for Tegra20.Signed-off-by Dmitry Osipenko <[email protected]>--- drivers/devfreq/Makefile | 2 +- drivers/devfreq/{tegra-devfreq.c => tegra30-devfreq.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename drivers/devfreq/{tegra-devfreq.c => tegra30-devfreq.c} (100%)drivers/devfreq/Makefile +1
-1@@ -10,7 +10,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) += governor_passive.o # DEVFREQ Drivers obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o -obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra-devfreq.o +obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.o # DEVFREQ Event Drivers obj-$(CONFIG_PM_DEVFREQ_EVENT) += event/drivers/devfreq/tegra30-devfreq.c renamed from drivers/devfreq/tegra-devfreq.c +0
-0
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Re: [PATCH v3 04/16] PM / devfreq: tegra: Don't ignore clk errors
In reply to Dmitry OsipenkoQuoted 38 lines · Dmitry Osipenko
The
clk_set_min_rate()could fail and in this caseclk_set_rate()sets rate to 0, which may drop EMC rate to minimum and make machine very difficult to use.Signed-off-by Dmitry Osipenko <[email protected]>--- drivers/devfreq/tegra-devfreq.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/devfreq/tegra-devfreq.c +9
-2@@ -484,8 +484,10 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq, u32 flags) {struct tegra_devfreq *tegra =dev_get_drvdata (dev); +struct devfreq *devfreq = tegra->devfreq;struct dev_pm_opp *opp;unsigned long rate; +int err; opp =devfreq_recommended_opp (dev, freq, flags);if (IS_ERR (opp)) {@@ -495,10 +497,20 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq, rate =dev_pm_opp_get_freq (opp);dev_pm_opp_put (opp); -clk_set_min_rate (tegra->emc_clock, rate); -clk_set_rate (tegra->emc_clock,0 ); + err =clk_set_min_rate (tegra->emc_clock, rate); +if (err) +return err; + + err =clk_set_rate (tegra->emc_clock,0 ); +if (err) + goto restore_min_rate;
drivers/devfreq/tegra-devfreq.c static int tegra_devfreq_target(struct device *dev, unsigned long *freq, · line 516
Quoted 10 lines
drivers/devfreq/tegra-devfreq.c +5
-0return 0 ; + +restore_min_rate: +clk_set_min_rate (tegra->emc_clock, devfreq->previous_freq); + +return err; } static int tegra_devfreq_get_dev_status(struct device *dev,
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Re: [PATCH v3 06/16] PM / devfreq: tegra: Drop primary interrupt handler
In reply to Dmitry OsipenkoQuoted 141 lines · Dmitry Osipenko
There is no real need in the primary interrupt handler, hence move everything to the secondary (threaded) handler. In a result locking is consistent now and there are no potential races with the interrupt handler because it is protected with the devfreq's mutex.
Signed-off-by Dmitry Osipenko <[email protected]>--- drivers/devfreq/tegra-devfreq.c | 55 +++++++++++---------------------- 1 file changed, 18 insertions(+), 37 deletions(-)drivers/devfreq/tegra-devfreq.c +16
-35@@ -144,7 +144,6 @@ static struct tegra_devfreq_device_config actmon_device_configs[] = {struct tegra_devfreq_device {const struct tegra_devfreq_device_config *config;void __iomem *regs; -spinlock_t lock;/* Average event count sampled in the last interrupt */ u32 avg_count;@@ -249,11 +248,8 @@ static void actmon_write_barrier(struct tegra_devfreq *tegra)static void actmon_isr_device (struct tegra_devfreq *tegra,struct tegra_devfreq_device *dev) { -unsigned long flags;u32 intr_status, dev_ctrl; -spin_lock_irqsave (&dev->lock, flags); - dev->avg_count =device_readl (dev,ACTMON_DEV_AVG_COUNT );tegra_devfreq_update_avg_wmark (tegra, dev);@@ -302,26 +298,6 @@ static void actmon_isr_device(struct tegra_devfreq *tegra,device_writel (dev,ACTMON_INTR_STATUS_CLEAR ,ACTMON_DEV_INTR_STATUS );actmon_write_barrier (tegra); - -spin_unlock_irqrestore (&dev->lock, flags); -} - -static irqreturn_t actmon_isr (int irq,void *data) -{ -struct tegra_devfreq *tegra = data; -bool handled = false; -unsigned int i; -u32 val; - - val =actmon_readl (tegra,ACTMON_GLB_STATUS ); -for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { -if (val & tegra->devices[i].config->irq_mask) { -actmon_isr_device (tegra, tegra->devices + i); - handled = true; - } - } - -return handled ?IRQ_WAKE_THREAD :IRQ_NONE ; } static unsigned long actmon_cpu_to_emc_rate(struct tegra_devfreq *tegra,@@ -348,15 +324,12 @@ static void actmon_update_target(struct tegra_devfreq *tegra,unsigned long cpu_freq =0 ;unsigned long static_cpu_emc_freq =0 ;unsigned int avg_sustain_coef; -unsigned long flags;if (dev->config->avg_dependency_threshold) { cpu_freq =cpufreq_get (0 ); static_cpu_emc_freq =actmon_cpu_to_emc_rate (tegra, cpu_freq); } -spin_lock_irqsave (&dev->lock, flags); - dev->target_freq = dev->avg_count /ACTMON_SAMPLING_PERIOD ; avg_sustain_coef =100 *100 / dev->config->boost_up_threshold; dev->target_freq =do_percent (dev->target_freq, avg_sustain_coef);@@ -364,19 +337,31 @@ static void actmon_update_target(struct tegra_devfreq *tegra,if (dev->avg_count >= dev->config->avg_dependency_threshold) dev->target_freq =max (dev->target_freq, static_cpu_emc_freq); - -spin_unlock_irqrestore (&dev->lock, flags); }static irqreturn_t actmon_thread_isr (int irq,void *data) {struct tegra_devfreq *tegra = data; +bool handled = false; +unsigned int i; +u32 val;mutex_lock (&tegra->devfreq->lock); -update_devfreq (tegra->devfreq); + + val =actmon_readl (tegra,ACTMON_GLB_STATUS ); +for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { +if (val & tegra->devices[i].config->irq_mask) { +actmon_isr_device (tegra, tegra->devices + i); + handled = true; + } + } + +if (handled) +update_devfreq (tegra->devfreq); +mutex_unlock (&tegra->devfreq->lock); -return IRQ_HANDLED ; +return handled ?IRQ_HANDLED :IRQ_NONE ; } static int tegra_actmon_rate_notify_cb(struct notifier_block *nb,@@ -386,7 +371,6 @@ static int tegra_actmon_rate_notify_cb(struct notifier_block *nb,struct tegra_devfreq *tegra;struct tegra_devfreq_device *dev;unsigned int i; -unsigned long flags;if (action !=POST_RATE_CHANGE )return NOTIFY_OK ;@@ -398,9 +382,7 @@ static int tegra_actmon_rate_notify_cb(struct notifier_block *nb,for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { dev = &tegra->devices[i]; -spin_lock_irqsave (&dev->lock, flags);tegra_devfreq_update_wmark (tegra, dev); -spin_unlock_irqrestore (&dev->lock, flags); }actmon_write_barrier (tegra);@@ -682,7 +664,6 @@ static int tegra_devfreq_probe(struct platform_device *pdev) dev = tegra->devices + i; dev->config = actmon_device_configs + i; dev->regs = tegra->regs + dev->config->offset; -spin_lock_init (&dev->lock);tegra_actmon_configure_device (tegra, dev); }
drivers/devfreq/tegra-devfreq.c static int tegra_devfreq_probe(struct platform_device *pdev) · line 688
Quoted 10 lines
drivers/devfreq/tegra-devfreq.c +2
-2@@ -700,8 +681,8 @@ static int tegra_devfreq_probe(struct platform_device *pdev)platform_set_drvdata (pdev, tegra); - err =devm_request_threaded_irq (&pdev->dev, irq, actmon_isr, - actmon_thread_isr,IRQF_SHARED , + err =devm_request_threaded_irq (&pdev->dev, irq,NULL , + actmon_thread_isr,IRQF_ONESHOT ,"tegra-devfreq" , tegra);if (err) {dev_err (&pdev->dev,"Interrupt request failed\n" );
Looks good to me.
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Re: [PATCH v3 07/16] PM / devfreq: tegra: Properly disable interrupts
In reply to Dmitry OsipenkoQuoted 69 lines · Dmitry Osipenko
There is no guarantee that interrupt handling isn't running in parallel with
tegra_actmon_disable_interrupts(), hence it is necessary to protectDEV_CTRLregister accesses and clear IRQ status with ACTMON's IRQ being disabled in the Interrupt Controller in order to ensure that device interrupt is indeed being disabled.Signed-off-by Dmitry Osipenko <[email protected]>--- drivers/devfreq/tegra-devfreq.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)drivers/devfreq/tegra-devfreq.c +13
-5@@ -171,6 +171,8 @@ struct tegra_devfreq {struct notifier_block rate_change_nb;struct tegra_devfreq_device devices[ARRAY_SIZE (actmon_device_configs)]; + +int irq; };struct tegra_actmon_emc_ratio {@@ -417,6 +419,8 @@ static void tegra_actmon_disable_interrupts(struct tegra_devfreq *tegra)u32 val;unsigned int i; +disable_irq (tegra->irq); +for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { dev = &tegra->devices[i];@@ -427,9 +431,14 @@ static void tegra_actmon_disable_interrupts(struct tegra_devfreq *tegra) val &= ~ACTMON_DEV_CTRL_CONSECUTIVE_ABOVE_WMARK_EN ;device_writel (dev, val,ACTMON_DEV_CTRL ); + +device_writel (dev,ACTMON_INTR_STATUS_CLEAR , +ACTMON_DEV_INTR_STATUS ); }actmon_write_barrier (tegra); + +enable_irq (tegra->irq); } static void tegra_actmon_configure_device(struct tegra_devfreq *tegra,@@ -604,7 +613,6 @@ static int tegra_devfreq_probe(struct platform_device *pdev)struct resource *res;unsigned int i;unsigned long rate; -int irq;int err; tegra =devm_kzalloc (&pdev->dev,sizeof (*tegra),GFP_KERNEL );@@ -673,15 +681,16 @@ static int tegra_devfreq_probe(struct platform_device *pdev)dev_pm_opp_add (&pdev->dev, rate,0 ); } - irq =platform_get_irq (pdev,0 ); -if (irq <0 ) { -dev_err (&pdev->dev,"Failed to get IRQ: %d\n" , irq); -return irq; + tegra->irq =platform_get_irq (pdev,0 ); +if (tegra->irq <0 ) { + err = tegra->irq; +dev_err (&pdev->dev,"Failed to get IRQ: %d\n" , err);
drivers/devfreq/tegra-devfreq.c static int tegra_devfreq_probe(struct platform_device *pdev) · line 696
Quoted 10 lines
drivers/devfreq/tegra-devfreq.c +2
-1+return err; }platform_set_drvdata (pdev, tegra); - err =devm_request_threaded_irq (&pdev->dev, irq,NULL , + err =devm_request_threaded_irq (&pdev->dev, tegra->irq,NULL , actmon_thread_isr,IRQF_ONESHOT ,"tegra-devfreq" , tegra);if (err) {
It is ok to disable the hardware interrupt line before completing the some operation about registers in order to protect the interrupt occur.
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Re: [PATCH v3 08/16] PM / devfreq: tegra: Clean up driver's probe / remove
In reply to Dmitry OsipenkoHi,
Quoted 131 lines · Dmitry Osipenko
Reset hardware, disable ACTMON clock, release OPP's and handle all possible error cases correctly, maintaining the correct tear down order. Also use
devm_platform_ioremap_resource()which is now available in the kernel.Signed-off-by Dmitry Osipenko <[email protected]>--- drivers/devfreq/tegra-devfreq.c | 83 +++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 36 deletions(-)drivers/devfreq/tegra-devfreq.c +44
-31@@ -610,7 +610,6 @@ static int tegra_devfreq_probe(struct platform_device *pdev) {struct tegra_devfreq *tegra;struct tegra_devfreq_device *dev; -struct resource *res;unsigned int i;unsigned long rate;int err;@@ -619,9 +618,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev)if (!tegra)return -ENOMEM ; - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - - tegra->regs =devm_ioremap_resource (&pdev->dev, res); + tegra->regs =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (tegra->regs))return PTR_ERR (tegra->regs);@@ -643,11 +640,10 @@ static int tegra_devfreq_probe(struct platform_device *pdev)return PTR_ERR (tegra->emc_clock); } - tegra->rate_change_nb.notifier_call = tegra_actmon_rate_notify_cb; - err =clk_notifier_register (tegra->emc_clock, &tegra->rate_change_nb); -if (err) { -dev_err (&pdev->dev, -"Failed to register rate change notifier\n" ); + tegra->irq =platform_get_irq (pdev,0 ); +if (tegra->irq <0 ) { + err = tegra->irq; +dev_err (&pdev->dev,"Failed to get IRQ: %d\n" , err);return err; }@@ -678,54 +674,69 @@ static int tegra_devfreq_probe(struct platform_device *pdev)for (rate =0 ; rate <= tegra->max_freq *KHZ ; rate++) { rate =clk_round_rate (tegra->emc_clock, rate); -dev_pm_opp_add (&pdev->dev, rate,0 ); - } - tegra->irq =platform_get_irq (pdev,0 ); -if (tegra->irq <0 ) { - err = tegra->irq; -dev_err (&pdev->dev,"Failed to get IRQ: %d\n" , err); -return err; + err =dev_pm_opp_add (&pdev->dev, rate,0 ); +if (err) { +dev_err (&pdev->dev,"Failed to add OPP: %d\n" , err); + goto remove_opps; + } }platform_set_drvdata (pdev, tegra); + tegra->rate_change_nb.notifier_call = tegra_actmon_rate_notify_cb; + err =clk_notifier_register (tegra->emc_clock, &tegra->rate_change_nb); +if (err) { +dev_err (&pdev->dev, +"Failed to register rate change notifier\n" ); + goto remove_opps; + } + + tegra_devfreq_profile.initial_freq =clk_get_rate (tegra->emc_clock); + tegra->devfreq =devfreq_add_device (&pdev->dev, + &tegra_devfreq_profile, +"tegra_actmon" , +NULL ); +if (IS_ERR (tegra->devfreq)) { + err =PTR_ERR (tegra->devfreq); + goto unreg_notifier; + } + err =devm_request_threaded_irq (&pdev->dev, tegra->irq,NULL , actmon_thread_isr,IRQF_ONESHOT ,"tegra-devfreq" , tegra);if (err) { -dev_err (&pdev->dev,"Interrupt request failed\n" ); -return err; +dev_err (&pdev->dev,"Interrupt request failed: %d\n" , err); + goto remove_devfreq; } - tegra_devfreq_profile.initial_freq =clk_get_rate (tegra->emc_clock); - tegra->devfreq =devm_devfreq_add_device (&pdev->dev, - &tegra_devfreq_profile, -"tegra_actmon" , -NULL ); -return 0 ; + +remove_devfreq: +devfreq_remove_device (tegra->devfreq); + +unreg_notifier: +clk_notifier_unregister (tegra->emc_clock, &tegra->rate_change_nb); + +remove_opps: +dev_pm_opp_remove_all_dynamic (&pdev->dev); + +reset_control_reset (tegra->reset); +clk_disable_unprepare (tegra->clock); + +return err; }static int tegra_devfreq_remove (struct platform_device *pdev) {struct tegra_devfreq *tegra =platform_get_drvdata (pdev); -int irq =platform_get_irq (pdev,0 ); -u32 val; -unsigned int i; - -for (i =0 ; i <ARRAY_SIZE (actmon_device_configs); i++) { - val =device_readl (&tegra->devices[i],ACTMON_DEV_CTRL ); - val &= ~ACTMON_DEV_CTRL_ENB ;
drivers/devfreq/tegra-devfreq.c static int tegra_devfreq_probe(struct platform_device *pdev) · line 737
Quoted 10 lines
drivers/devfreq/tegra-devfreq.c +2
-5-device_writel (&tegra->devices[i], val,ACTMON_DEV_CTRL ); - } - -actmon_write_barrier (tegra); -devm_free_irq (&pdev->dev, irq, tegra); +devfreq_remove_device (tegra->devfreq); +dev_pm_opp_remove_all_dynamic (&pdev->dev);clk_notifier_unregister (tegra->emc_clock, &tegra->rate_change_nb);
nitpick: the probe function has following call sequence if error case, First, clk_notifier_unregister()
Second, dev_pm_opp_remove_all_dynamic()
If possible, you better to keep the same sequence
in the tegra_devfreq_remove(). But, it is just opinion. If you think that it doesn't break the routine of device removal, jut keep this code.
drivers/devfreq/tegra-devfreq.c static int tegra_devfreq_probe(struct platform_device *pdev)
Quoted 6 lines
drivers/devfreq/tegra-devfreq.c +1
-0+reset_control_reset (tegra->reset);clk_disable_unprepare (tegra->clock);return 0 ;
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Re: [PATCH v3 16/16] PM / devfreq: Introduce driver for NVIDIA Tegra20
In reply to Dmitry OsipenkoHi Dmitry,
Looks good to me. But, just I have one minor comment about '8' divider value in the tegra_devfreq_get_dev_status().
On the next version, you better to add the comment about the meaning of '8' divider value.
Quoted 136 lines · Dmitry Osipenko
Add devfreq driver for NVIDIA Tegra20 SoC's. The driver periodically reads out Memory Controller counters and adjusts memory frequency based on the memory clients activity.
Signed-off-by Dmitry Osipenko <[email protected]>--- MAINTAINERS | 8 ++ drivers/devfreq/Kconfig | 10 ++ drivers/devfreq/Makefile | 1 + drivers/devfreq/tegra20-devfreq.c | 202 ++++++++++++++++++++++++++++++ 4 files changed, 221 insertions(+) create mode 100644 drivers/devfreq/tegra20-devfreq.cMAINTAINERS +8
-0@@ -10070,6 +10070,14 @@ F: include/linux/memblock.h F: mm/memblock.c F: Documentation/core-api/boot-time-mm.rst +MEMORY FREQUENCY SCALING DRIVER FOR NVIDIA TEGRA20 +M: Dmitry Osipenko <[email protected]> +L: [email protected] +L: [email protected] +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mzx/devfreq.git +S: Maintained +F: drivers/devfreq/tegra20-devfreq.c + MEMORY MANAGEMENT L: [email protected] W: http://www.linux-mm.orgdrivers/devfreq/Kconfig +10
-0@@ -100,6 +100,16 @@ config ARM_TEGRA_DEVFREQ It reads ACTMON counters of memory controllers and adjusts the operating frequencies and voltages with OPP support. +config ARM_TEGRA20_DEVFREQ + tristate "NVIDIA Tegra20 DEVFREQ Driver" + depends on (TEGRA_MC && TEGRA20_EMC) || COMPILE_TEST + select DEVFREQ_GOV_SIMPLE_ONDEMAND + select PM_OPP + help + This adds the DEVFREQ driver for the Tegra20 family of SoCs. + It reads Memory Controller counters and adjusts the operating + frequencies and voltages with OPP support. + config ARM_RK3399_DMC_DEVFREQ tristate "ARM RK3399 DMC DEVFREQ Driver" depends on ARCH_ROCKCHIPdrivers/devfreq/Makefile +1
-0@@ -11,6 +11,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) += governor_passive.o obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.o +obj-$(CONFIG_ARM_TEGRA20_DEVFREQ) += tegra20-devfreq.o # DEVFREQ Event Drivers obj-$(CONFIG_PM_DEVFREQ_EVENT) += event/drivers/devfreq/tegra20-devfreq.c new file +65
-0@@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* NVIDIA Tegra20 devfreq driver +* +* Copyright (C) 2019 GRATE-DRIVER project +*/ + +#include <linux/clk.h> +#include <linux/devfreq.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/pm_opp.h> +#include <linux/slab.h> + +#include <soc/tegra/mc.h> + +#include "governor.h" + +#define MC_STAT_CONTROL 0x90 +#define MC_STAT_EMC_CLOCK_LIMIT 0xa0 +#define MC_STAT_EMC_CLOCKS 0xa4 +#define MC_STAT_EMC_CONTROL 0xa8 +#define MC_STAT_EMC_COUNT 0xb8 + +#define EMC_GATHER_CLEAR (1 << 8) +#define EMC_GATHER_ENABLE (3 << 8) + +struct tegra_devfreq { +struct devfreq *devfreq; +struct clk *clk; +void __iomem *regs; +}; + +static int tegra_devfreq_target (struct device *dev,unsigned long *freq, +u32 flags) +{ +struct tegra_devfreq *tegra =dev_get_drvdata (dev); +struct devfreq *devfreq = tegra->devfreq; +struct dev_pm_opp *opp; +unsigned long rate; +int err; + + opp =devfreq_recommended_opp (dev, freq, flags); +if (IS_ERR (opp)) +return PTR_ERR (opp); + + rate =dev_pm_opp_get_freq (opp); +dev_pm_opp_put (opp); + + err =clk_set_min_rate (tegra->clk, rate); +if (err) +return err; + + err =clk_set_rate (tegra->clk,0 ); +if (err) + goto restore_min_rate; + +return 0 ; + +restore_min_rate: +clk_set_min_rate (tegra->clk, devfreq->previous_freq); +
drivers/devfreq/tegra20-devfreq.c line 75
Quoted 10 lines
drivers/devfreq/tegra20-devfreq.c new file +10
-0+return err; +} + +static int tegra_devfreq_get_dev_status (struct device *dev, +struct devfreq_dev_status *stat) +{ +struct tegra_devfreq *tegra =dev_get_drvdata (dev); + + stat->busy_time =readl_relaxed (tegra->regs +MC_STAT_EMC_COUNT ); + stat->total_time =readl_relaxed (tegra->regs +MC_STAT_EMC_CLOCKS ) /8 ;
How about adding the comment why divide with '8' constant value?
Quoted 128 lines
drivers/devfreq/tegra20-devfreq.c new file +127
-0+ stat->current_frequency =clk_get_rate (tegra->clk); + +writel_relaxed (EMC_GATHER_CLEAR , tegra->regs +MC_STAT_CONTROL ); +writel_relaxed (EMC_GATHER_ENABLE , tegra->regs +MC_STAT_CONTROL ); + +return 0 ; +} + +static struct devfreq_dev_profile tegra_devfreq_profile = { + .polling_ms =500 , + .target = tegra_devfreq_target, + .get_dev_status = tegra_devfreq_get_dev_status, +}; + +static struct tegra_mc *tegra_get_memory_controller (void ) +{ +struct platform_device *pdev; +struct device_node *np; +struct tegra_mc *mc; + + np =of_find_compatible_node (NULL ,NULL ,"nvidia,tegra20-mc-gart" ); +if (!np) +return ERR_PTR (-ENOENT ); + + pdev =of_find_device_by_node (np); +of_node_put (np); +if (!pdev) +return ERR_PTR (-ENODEV ); + + mc =platform_get_drvdata (pdev); +if (!mc) +return ERR_PTR (-EPROBE_DEFER ); + +return mc; +} + +static int tegra_devfreq_probe (struct platform_device *pdev) +{ +struct tegra_devfreq *tegra; +struct tegra_mc *mc; +unsigned long max_rate; +unsigned long rate; +int err; + + mc =tegra_get_memory_controller (); +if (IS_ERR (mc)) { + err =PTR_ERR (mc); +dev_err (&pdev->dev,"failed to get memory controller: %d\n" , + err); +return err; + } + + tegra =devm_kzalloc (&pdev->dev,sizeof (*tegra),GFP_KERNEL ); +if (!tegra) +return -ENOMEM ; + +/* EMC is a system-critical clock that is always enabled */ + tegra->clk =devm_clk_get (&pdev->dev,"emc" ); +if (IS_ERR (tegra->clk)) { + err =PTR_ERR (tegra->clk); +dev_err (&pdev->dev,"failed to get emc clock: %d\n" , err); +return err; + } + + tegra->regs = mc->regs; + + max_rate =clk_round_rate (tegra->clk,ULONG_MAX ); + +for (rate =0 ; rate <= max_rate; rate++) { + rate =clk_round_rate (tegra->clk, rate); + + err =dev_pm_opp_add (&pdev->dev, rate,0 ); +if (err) { +dev_err (&pdev->dev,"failed to add opp: %d\n" , err); + goto remove_opps; + } + } + +/* +* Reset statistic gathers state, select global bandwidth for the +* statistics collection mode and set clocks counter saturation +* limit to maximum. +*/ +writel_relaxed (0x00000000 , tegra->regs +MC_STAT_CONTROL ); +writel_relaxed (0x00000000 , tegra->regs +MC_STAT_EMC_CONTROL ); +writel_relaxed (0xffffffff , tegra->regs +MC_STAT_EMC_CLOCK_LIMIT ); + +platform_set_drvdata (pdev, tegra); + + tegra->devfreq =devfreq_add_device (&pdev->dev, &tegra_devfreq_profile, +DEVFREQ_GOV_SIMPLE_ONDEMAND ,NULL ); +if (IS_ERR (tegra->devfreq)) { + err =PTR_ERR (tegra->devfreq); + goto remove_opps; + } + +return 0 ; + +remove_opps: +dev_pm_opp_remove_all_dynamic (&pdev->dev); + +return err; +} + +static int tegra_devfreq_remove (struct platform_device *pdev) +{ +struct tegra_devfreq *tegra =platform_get_drvdata (pdev); + +devfreq_remove_device (tegra->devfreq); +dev_pm_opp_remove_all_dynamic (&pdev->dev); + +return 0 ; +} + +static struct platform_driver tegra_devfreq_driver = { + .probe = tegra_devfreq_probe, + .remove = tegra_devfreq_remove, + .driver = { + .name ="tegra20-devfreq" , + }, +}; +module_platform_driver (tegra_devfreq_driver); + +MODULE_ALIAS ("platform:tegra20-devfreq" ); +MODULE_AUTHOR ("Dmitry Osipenko <[email protected]>" ); +MODULE_DESCRIPTION ("NVIDIA Tegra20 devfreq driver" ); +MODULE_LICENSE ("GPL v2" );
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Re: [PATCH v3 12/16] PM / devfreq: tegra: Reconfigure hardware on governor's restart
In reply to Dmitry OsipenkoHi,
Quoted 91 lines · Dmitry Osipenko
Move hardware configuration to governor's start/resume methods. This allows to re-initialize hardware counters and reconfigure cleanly if governor was stopped/paused. That is needed because we are not aware of all hardware changes that happened while governor was stopped and the paused state may get out of sync with reality, hence it's better to start with a clean slate after the pause. In a result there is no memory bandwidth starvation after resume from suspend-to-ram that results in display controller underflowing that happens on resume because of improper decision made by devfreq about the required memory frequency. This change also cleans up code a tad by moving hardware-configuration code into a single location.
Signed-off-by Dmitry Osipenko <[email protected]>--- drivers/devfreq/tegra-devfreq.c | 98 ++++++++++++++------------------- 1 file changed, 40 insertions(+), 58 deletions(-)drivers/devfreq/tegra-devfreq.c +7
-49@@ -392,55 +392,6 @@ static int tegra_actmon_rate_notify_cb(struct notifier_block *nb,return NOTIFY_OK ; } -static void tegra_actmon_enable_interrupts (struct tegra_devfreq *tegra) -{ -struct tegra_devfreq_device *dev; -u32 val; -unsigned int i; - -for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { - dev = &tegra->devices[i]; - - val =device_readl (dev,ACTMON_DEV_CTRL ); - val |=ACTMON_DEV_CTRL_AVG_ABOVE_WMARK_EN ; - val |=ACTMON_DEV_CTRL_AVG_BELOW_WMARK_EN ; - val |=ACTMON_DEV_CTRL_CONSECUTIVE_BELOW_WMARK_EN ; - val |=ACTMON_DEV_CTRL_CONSECUTIVE_ABOVE_WMARK_EN ; - -device_writel (dev, val,ACTMON_DEV_CTRL ); - } - -actmon_write_barrier (tegra); -} - -static void tegra_actmon_disable_interrupts (struct tegra_devfreq *tegra) -{ -struct tegra_devfreq_device *dev; -u32 val; -unsigned int i; - -disable_irq (tegra->irq); - -for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { - dev = &tegra->devices[i]; - - val =device_readl (dev,ACTMON_DEV_CTRL ); - val &= ~ACTMON_DEV_CTRL_AVG_ABOVE_WMARK_EN ; - val &= ~ACTMON_DEV_CTRL_AVG_BELOW_WMARK_EN ; - val &= ~ACTMON_DEV_CTRL_CONSECUTIVE_BELOW_WMARK_EN ; - val &= ~ACTMON_DEV_CTRL_CONSECUTIVE_ABOVE_WMARK_EN ; - -device_writel (dev, val,ACTMON_DEV_CTRL ); - -device_writel (dev,ACTMON_INTR_STATUS_CLEAR , -ACTMON_DEV_INTR_STATUS ); - } - -actmon_write_barrier (tegra); - -enable_irq (tegra->irq); -} -static void tegra_actmon_configure_device (struct tegra_devfreq *tegra,struct tegra_devfreq_device *dev) {@@ -464,11 +415,47 @@ static void tegra_actmon_configure_device(struct tegra_devfreq *tegra, << ACTMON_DEV_CTRL_CONSECUTIVE_BELOW_WMARK_NUM_SHIFT; val |= (ACTMON_ABOVE_WMARK_WINDOW -1 ) <<ACTMON_DEV_CTRL_CONSECUTIVE_ABOVE_WMARK_NUM_SHIFT ; + val |=ACTMON_DEV_CTRL_AVG_ABOVE_WMARK_EN ; + val |=ACTMON_DEV_CTRL_AVG_BELOW_WMARK_EN ; + val |=ACTMON_DEV_CTRL_CONSECUTIVE_BELOW_WMARK_EN ; + val |=ACTMON_DEV_CTRL_CONSECUTIVE_ABOVE_WMARK_EN ; val |=ACTMON_DEV_CTRL_ENB ;device_writel (dev, val,ACTMON_DEV_CTRL ); +} + +static void tegra_actmon_start (struct tegra_devfreq *tegra)
drivers/devfreq/tegra-devfreq.c static void tegra_actmon_configure_device(struct tegra_devfreq *tegra, · line 437
Quoted 10 lines
drivers/devfreq/tegra-devfreq.c +10
-0+{ +unsigned int i; + +disable_irq (tegra->irq); + +actmon_writel (tegra,ACTMON_SAMPLING_PERIOD -1 , +ACTMON_GLB_PERIOD_CTRL ); + +for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) +tegra_actmon_configure_device (tegra, &tegra->devices[i]);
nitpick.
I agree this patch.
In order to make it more simple, I think that you can remove tegra_actmon_configure() function and then just do some opertion under the for loop in the tegra_actmon_start() to keep
similar style with tegra_actmon_stop(). But there is perfect solution. If you agree, edit it on next patch. If you think that it is not necessary, just keep this code.
Quoted 58 lines
drivers/devfreq/tegra-devfreq.c +23
-6+ +actmon_write_barrier (tegra); + +enable_irq (tegra->irq); +} + +static void tegra_actmon_stop (struct tegra_devfreq *tegra) +{ +unsigned int i; + +disable_irq (tegra->irq); + +for (i =0 ; i <ARRAY_SIZE (tegra->devices); i++) { +device_writel (&tegra->devices[i],0x00000000 ,ACTMON_DEV_CTRL ); +device_writel (&tegra->devices[i],ACTMON_INTR_STATUS_CLEAR , +ACTMON_DEV_INTR_STATUS ); + }actmon_write_barrier (tegra); + +enable_irq (tegra->irq); } static int tegra_devfreq_target(struct device *dev, unsigned long *freq,@@ -580,22 +567,22 @@ static int tegra_governor_event_handler(struct devfreq *devfreq,switch (event) {case DEVFREQ_GOV_START :devfreq_monitor_start (devfreq); -tegra_actmon_enable_interrupts (tegra); +tegra_actmon_start (tegra);break ;case DEVFREQ_GOV_STOP : -tegra_actmon_disable_interrupts (tegra); +tegra_actmon_stop (tegra);devfreq_monitor_stop (devfreq);break ;case DEVFREQ_GOV_SUSPEND : -tegra_actmon_disable_interrupts (tegra); +tegra_actmon_stop (tegra);devfreq_monitor_suspend (devfreq);break ;case DEVFREQ_GOV_RESUME :devfreq_monitor_resume (devfreq); -tegra_actmon_enable_interrupts (tegra); +tegra_actmon_start (tegra);break ; }@@ -664,15 +651,10 @@ static int tegra_devfreq_probe(struct platform_device *pdev) tegra->max_freq =clk_round_rate (tegra->emc_clock,ULONG_MAX ) /KHZ ; tegra->cur_freq =clk_get_rate (tegra->emc_clock) /KHZ ; -actmon_writel (tegra,ACTMON_SAMPLING_PERIOD -1 , -ACTMON_GLB_PERIOD_CTRL );
drivers/devfreq/tegra-devfreq.c static int tegra_devfreq_probe(struct platform_device *pdev) · line 660
Quoted 10 lines
drivers/devfreq/tegra-devfreq.c +0
-3-for (i =0 ; i <ARRAY_SIZE (actmon_device_configs); i++) { dev = tegra->devices + i; dev->config = actmon_device_configs + i; dev->regs = tegra->regs + dev->config->offset; - -tegra_actmon_configure_device (tegra, dev); }for (rate =0 ; rate <= tegra->max_freq *KHZ ; rate++) {
I agree to always initialize the device when START or RESUME and also to reset the device when STOP or SUSPEND.
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics