Skip to contentSkip to conversation

cpufreq: tegra: add regulator dependency for T124

PATCH Applied Arnd Bergmann 5 participants 10 messages Dec 8, 2015 – Dec 12, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: tegra: add regulator dependency for T124

This driver is the only one that calls regulator_sync_voltage(), but it can currently be built with CONFIG_REGULATOR disabled, producing this build error:

drivers/cpufreq/tegra124-cpufreq.c: In function 'tegra124_cpu_switch_to_pllx':
drivers/cpufreq/tegra124-cpufreq.c:68:2: error: implicit declaration of function 'regulator_sync_voltage' [-Werror=implicit-function-declaration]
regulator_sync_voltage(priv->vdd_cpu_reg);

My first attempt was to implement a helper for this function for regulator_sync_voltage, but Mark Brown explained:

We don't do this for *all* regulator API functions - there's some where using them strongly suggests that there is actually a dependency on the regulator API. This does seem like it might be falling into the specialist category [...]
Looking at the code I'm pretty unclear on what the authors think the use of _sync_voltage() is doing in the first place so it may be even better to just remove the call. It seems to have been included in the first commit so there's not changelog explaining things and there's no comment either. I'd *expect* it to be a noop as far as I can see.

This adds the dependency to make the driver always build successfully or not be enabled at all. Alternatively, we could investigate if the driver should stop calling regulator_sync_voltage instead.

drivers/cpufreq/Kconfig.arm +1 -1
index 235a1ba73d92..b1f8a73e5a94 100644
@@ -226,7 +226,7 @@ config ARM_TEGRA20_CPUFREQ
 
 config ARM_TEGRA124_CPUFREQ
 	tristate "Tegra124 CPUFreq support"
-	depends on ARCH_TEGRA && CPUFREQ_DT
+	depends on ARCH_TEGRA && CPUFREQ_DT && REGULATOR
 	default y
 	help
 	  This adds the CPUFreq driver support for Tegra124 SOCs.
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 32 lines · Arnd Bergmann

This driver is the only one that calls regulator_sync_voltage(), but it can currently be built with CONFIG_REGULATOR disabled, producing this build error:

drivers/cpufreq/tegra124-cpufreq.c: In function 'tegra124_cpu_switch_to_pllx':
drivers/cpufreq/tegra124-cpufreq.c:68:2: error: implicit declaration of function 'regulator_sync_voltage' [-Werror=implicit-function-declaration]
regulator_sync_voltage(priv->vdd_cpu_reg);

My first attempt was to implement a helper for this function for regulator_sync_voltage, but Mark Brown explained:

We don't do this for *all* regulator API functions - there's some where using them strongly suggests that there is actually a dependency on the regulator API. This does seem like it might be falling into the specialist category [...]
Looking at the code I'm pretty unclear on what the authors think the use of _sync_voltage() is doing in the first place so it may be even better to just remove the call. It seems to have been included in the first commit so there's not changelog explaining things and there's no comment either. I'd *expect* it to be a noop as far as I can see.

This adds the dependency to make the driver always build successfully or not be enabled at all. Alternatively, we could investigate if the driver should stop calling regulator_sync_voltage instead.

drivers/cpufreq/Kconfig.arm +0 -0
index 235a1ba73d92..b1f8a73e5a94 100644

drivers/cpufreq/Kconfig.arm config ARM_TEGRA20_CPUFREQ · line 232

Quoted 8 lines
drivers/cpufreq/Kconfig.arm +1 -1
@@ -226,7 +226,7 @@ config ARM_TEGRA20_CPUFREQ
 
 config ARM_TEGRA124_CPUFREQ
 	tristate "Tegra124 CPUFreq support"
-	depends on ARCH_TEGRA && CPUFREQ_DT
+	depends on ARCH_TEGRA && CPUFREQ_DT && REGULATOR
 	default y
 	help
 	  This adds the CPUFreq driver support for Tegra124 SOCs.
Signature · 1 line
viresh
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann

Hi Arnd,

Quoted 11 lines · Arnd Bergmann

This driver is the only one that calls regulator_sync_voltage(), but it can currently be built with CONFIG_REGULATOR disabled, producing this build error:

drivers/cpufreq/tegra124-cpufreq.c: In function 'tegra124_cpu_switch_to_pllx':
drivers/cpufreq/tegra124-cpufreq.c:68:2: error: implicit declaration of function 'regulator_sync_voltage' [-Werror=implicit-function-declaration]
regulator_sync_voltage(priv->vdd_cpu_reg);

My first attempt was to implement a helper for this function for regulator_sync_voltage, but Mark Brown explained:

Quoted 9 lines

We don't do this for *all* regulator API functions - there's some where using them strongly suggests that there is actually a dependency on the regulator API. This does seem like it might be falling into the specialist category [...]
Looking at the code I'm pretty unclear on what the authors think the use of _sync_voltage() is doing in the first place so it may be even better to just remove the call. It seems to have been included in the first commit so there's not changelog explaining things and there's no comment either. I'd *expect* it to be a noop as far as I can see.

In this sequence we are switching from the DFLL clock source (which directly controls the voltage) back to a PLL (which does not control the voltage directly). What we want to do is to restore the voltage back to the voltage it was operating at before we switched to the DFLL clock (which could have changed it).

I am not familiar with regulator_sync_voltage() but from the comment it does say that it will re-apply the last voltage that was configured for the regulator. So I can see what they were doing. The question I have is, if the consumer has not explicitly called regulator_set_voltage() then what does regulator_sync_voltage() do? I am wondering if we should have been doing a regulator_get_voltage() during the probe and a regulator_set_voltage() when switching back?

Quoted 11 lines

This adds the dependency to make the driver always build successfully or not be enabled at all. Alternatively, we could investigate if the driver should stop calling regulator_sync_voltage instead.

drivers/cpufreq/Kconfig.arm +0 -0
index 235a1ba73d92..b1f8a73e5a94 100644

drivers/cpufreq/Kconfig.arm config ARM_TEGRA20_CPUFREQ · line 232

Quoted 8 lines
drivers/cpufreq/Kconfig.arm +1 -1
@@ -226,7 +226,7 @@ config ARM_TEGRA20_CPUFREQ
 
 config ARM_TEGRA124_CPUFREQ
 	tristate "Tegra124 CPUFreq support"
-	depends on ARCH_TEGRA && CPUFREQ_DT
+	depends on ARCH_TEGRA && CPUFREQ_DT && REGULATOR
 	default y
 	help
 	  This adds the CPUFreq driver support for Tegra124 SOCs.

Cheers
Jon

#3 lore raw
Quoted 15 lines · Jon Hunter
Quoted 12 lines · Arnd Bergmann

My first attempt was to implement a helper for this function for regulator_sync_voltage, but Mark Brown explained:

We don't do this for *all* regulator API functions - there's some where using them strongly suggests that there is actually a dependency on the regulator API. This does seem like it might be falling into the specialist category [...]
Looking at the code I'm pretty unclear on what the authors think the use of _sync_voltage() is doing in the first place so it may be even better to just remove the call. It seems to have been included in the first commit so there's not changelog explaining things and there's no comment either. I'd *expect* it to be a noop as far as I can see.

Quoted 5 lines

In this sequence we are switching from the DFLL clock source (which directly controls the voltage) back to a PLL (which does not control the voltage directly). What we want to do is to restore the voltage back to the voltage it was operating at before we switched to the DFLL clock (which could have changed it).

If changes implemented by the clock driver are trashing the regulator settings I would expect the clock driver to be responsible for fixing things up rather than another driver that happens to use the clock. I'd also expect some kind of internal documentation explaining what's going on, and possibly

Quoted 7 lines

I am not familiar with regulator_sync_voltage() but from the comment it does say that it will re-apply the last voltage that was configured for the regulator. So I can see what they were doing. The question I have is, if the consumer has not explicitly called regulator_set_voltage() then what does regulator_sync_voltage() do? I am wondering if we should have been doing a regulator_get_voltage() during the probe and a regulator_set_voltage() when switching back?

This *is* the sort of thing _sync() is intended for, though it's mainly expected to be used in cases like suspend where things have been powered off. As you can see from the code it's based on the settings that software made, but then if nothing in software has any need to configure anything then why do we even care that the hardware changed anything?

Setting the voltage you've read back sounds broken, if the hardware
might randomly change things how do you know the settings we read were
sane? Shouldn't we know what voltage range the device requires in a
given mode and set that - that's much more normal?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151209/29aea2c8/attachment.sig>

maintainer
#4 lore raw
Quoted 24 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 15 lines · Jon Hunter
Quoted 12 lines · Arnd Bergmann

My first attempt was to implement a helper for this function for regulator_sync_voltage, but Mark Brown explained:

We don't do this for *all* regulator API functions - there's some where using them strongly suggests that there is actually a dependency on the regulator API. This does seem like it might be falling into the specialist category [...]
Looking at the code I'm pretty unclear on what the authors think the use of _sync_voltage() is doing in the first place so it may be even better to just remove the call. It seems to have been included in the first commit so there's not changelog explaining things and there's no comment either. I'd *expect* it to be a noop as far as I can see.

Quoted 5 lines

In this sequence we are switching from the DFLL clock source (which directly controls the voltage) back to a PLL (which does not control the voltage directly). What we want to do is to restore the voltage back to the voltage it was operating at before we switched to the DFLL clock (which could have changed it).

Quoted 5 lines

If changes implemented by the clock driver are trashing the regulator settings I would expect the clock driver to be responsible for fixing things up rather than another driver that happens to use the clock. I'd also expect some kind of internal documentation explaining what's going on, and possibly

Yes, the DFLL clock driver could restore the voltage, however, that does not guarantee that the voltage is still sufficient for the other clock source.

Quoted 8 lines
Quoted 7 lines

I am not familiar with regulator_sync_voltage() but from the comment it does say that it will re-apply the last voltage that was configured for the regulator. So I can see what they were doing. The question I have is, if the consumer has not explicitly called regulator_set_voltage() then what does regulator_sync_voltage() do? I am wondering if we should have been doing a regulator_get_voltage() during the probe and a regulator_set_voltage() when switching back?

Quoted 5 lines

This *is* the sort of thing _sync() is intended for, though it's mainly expected to be used in cases like suspend where things have been powered off. As you can see from the code it's based on the settings that software made, but then if nothing in software has any need to configure anything then why do we even care that the hardware changed anything?

Yes, that's my point. When switching between these clock sources, I think that software does need to set something and so we should care.

Quoted 4 lines

Setting the voltage you've read back sounds broken, if the hardware might randomly change things how do you know the settings we read were sane? Shouldn't we know what voltage range the device requires in a given mode and set that - that's much more normal?

The hardware will not randomly change the voltage until the DFLL is enabled and so you would have to do this before.

Yes, setting the frequency and voltage as defined by a given operating mode would make sense. However, I am not sure we have those defined in the kernel for this PLL and would have to be added.

I was thinking that during boot we could read the default voltage and frequency set by the bootloader and use this as it should not be changing dynamically at this point because the cpufreq driver has not been activated yet.

Jon

#5 lore raw
Quoted 11 lines · Jon Hunter
Quoted 5 lines · Mark Brown

If changes implemented by the clock driver are trashing the regulator settings I would expect the clock driver to be responsible for fixing things up rather than another driver that happens to use the clock. I'd also expect some kind of internal documentation explaining what's going on, and possibly

Yes, the DFLL clock driver could restore the voltage, however, that does not guarantee that the voltage is still sufficient for the other clock source.

But the code we've got won't do that either - it'l just set the voltage to whatever the last thing the regulator API had that might have been within its constraints.

Quoted 7 lines
Quoted 4 lines

Setting the voltage you've read back sounds broken, if the hardware might randomly change things how do you know the settings we read were sane? Shouldn't we know what voltage range the device requires in a given mode and set that - that's much more normal?

The hardware will not randomly change the voltage until the DFLL is enabled and so you would have to do this before.

I'm not clear that there's even a guarantee that the kernel will ever have seen this configuration, consider for example what happens if someone uses kexec?

Quoted 3 lines

Yes, setting the frequency and voltage as defined by a given operating mode would make sense. However, I am not sure we have those defined in the kernel for this PLL and would have to be added.

I think given how you're describing the hardware that this will be required in order to provide something robust (and also to get the best power savings from the hardware).

Quoted 4 lines

I was thinking that during boot we could read the default voltage and frequency set by the bootloader and use this as it should not be changing dynamically at this point because the cpufreq driver has not been activated yet.

I'm a bit confused here, we're talking about a change to the cpufreq
driver here aren't we? Or alternatively why are we manipulating the
clock tree like this if we don't yet have support for the hardware?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151209/fd5be391/attachment-0001.sig>

maintainer
#6 lore raw
Quoted 11 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 7 lines · Jon Hunter
Quoted 5 lines · Mark Brown

If changes implemented by the clock driver are trashing the regulator settings I would expect the clock driver to be responsible for fixing things up rather than another driver that happens to use the clock. I'd also expect some kind of internal documentation explaining what's going on, and possibly

Quoted 7 lines
Quoted 3 lines

Yes, the DFLL clock driver could restore the voltage, however, that does not guarantee that the voltage is still sufficient for the other clock source.

But the code we've got won't do that either - it'l just set the voltage to whatever the last thing the regulator API had that might have been within its constraints.

Today yes, however, I meant that we *could* change it to restore the previous voltage before the DFLL was enabled.

Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

Setting the voltage you've read back sounds broken, if the hardware might randomly change things how do you know the settings we read were sane? Shouldn't we know what voltage range the device requires in a given mode and set that - that's much more normal?

The hardware will not randomly change the voltage until the DFLL is enabled and so you would have to do this before.

I'm not clear that there's even a guarantee that the kernel will ever have seen this configuration, consider for example what happens if someone uses kexec?

True. I have not played around with kexec, but with something like the DFLL, we would need to make sure that this get disabled. Looks like the reboot notifier gets called by kexec and so I guess that could be used to disable the DFLL and switch back to the PLL.

Quoted 7 lines
Quoted 3 lines

Yes, setting the frequency and voltage as defined by a given operating mode would make sense. However, I am not sure we have those defined in the kernel for this PLL and would have to be added.

I think given how you're describing the hardware that this will be required in order to provide something robust (and also to get the best power savings from the hardware).

Yes I agree it would be more robust. However, if you care about power savings then you should be using the DFLL/cpufreq anyway.

Quoted 8 lines
Quoted 4 lines

I was thinking that during boot we could read the default voltage and frequency set by the bootloader and use this as it should not be changing dynamically at this point because the cpufreq driver has not been activated yet.

I'm a bit confused here, we're talking about a change to the cpufreq driver here aren't we? Or alternatively why are we manipulating the clock tree like this if we don't yet have support for the hardware?

Yes, a change to the cpu-freq driver. When probing the cpufreq driver, we can query the clock-source, clock frequency and voltage and save this, so that if we ever disable the DFLL/cpufreq, we can switch back to the initial configuration.

Quoted 1 line

From testing the t124 jetson and nyan-big, both of these boards have a

different configuration for the PLL at boot time, so although we could pick a safe operating point for all t124 boards, I was thinking of just restoring their initial configuration.

Jon

#7 lore raw
Quoted 7 lines · Jon Hunter
Quoted 5 lines · Mark Brown
Quoted 3 lines · Jon Hunter

Yes, setting the frequency and voltage as defined by a given operating mode would make sense. However, I am not sure we have those defined in the kernel for this PLL and would have to be added.

Quoted 6 lines
Quoted 3 lines

I think given how you're describing the hardware that this will be required in order to provide something robust (and also to get the best power savings from the hardware).

Yes I agree it would be more robust. However, if you care about power savings then you should be using the DFLL/cpufreq anyway.

Without knowing anything about the hardware this is all a bit confusing I'm afraid. What is "DFLL/cpufreq" as opposed to "the PLL"?

Quoted 4 lines

From testing the t124 jetson and nyan-big, both of these boards have a different configuration for the PLL at boot time, so although we could pick a safe operating point for all t124 boards, I was thinking of just restoring their initial configuration.

This seems more complex, and also makes the idea of relying on the
initial configuration seem slightly concerning - other software seems to
be already changing the configuration before we get to the kernel so if
we don't fully understand the configuration we're doing we seem likely
to find some configuration where we miss things.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151210/11858660/attachment-0001.sig>

maintainer
#8 lore raw
Quoted 14 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 10 lines · Jon Hunter
Quoted 9 lines · Mark Brown
Quoted 3 lines · Jon Hunter

Yes, setting the frequency and voltage as defined by a given operating mode would make sense. However, I am not sure we have those defined in the kernel for this PLL and would have to be added.

I think given how you're describing the hardware that this will be required in order to provide something robust (and also to get the best power savings from the hardware).

Quoted 5 lines
Quoted 2 lines

Yes I agree it would be more robust. However, if you care about power savings then you should be using the DFLL/cpufreq anyway.

Without knowing anything about the hardware this is all a bit confusing I'm afraid. What is "DFLL/cpufreq" as opposed to "the PLL"?

No problem.

The two main clocks sources (there are others) used for the CPU complex are the PLLX and the DFLL. The PLLX is a normal PLL and you can configure to run at various frequencies. However, this PLL requires that you/software set the voltage appropriately. The DFLL has the ability to control the voltage itself per the frequency requested (no software management of the voltage required).

There is no reason why you could not use the PLLX in conjunction with cpufreq, but for T124 we use the DFLL.

Typically, T124 will boot using the PLLX and then if cpufreq is enabled, the DFLL will be enabled and we will switch to this clock.

We would only ever switch back to the PLLX if cpufreq is removed and hence the DFLL is disabled. And this is where this patch comes in and I am wondering if this has ever been tested.

Quoted 10 lines
Quoted 4 lines

From testing the t124 jetson and nyan-big, both of these boards have a different configuration for the PLL at boot time, so although we could pick a safe operating point for all t124 boards, I was thinking of just restoring their initial configuration.

This seems more complex, and also makes the idea of relying on the initial configuration seem slightly concerning - other software seems to be already changing the configuration before we get to the kernel so if we don't fully understand the configuration we're doing we seem likely to find some configuration where we miss things.

I don't think so. At probe time for cpufreq, we know the clock source for the CPU complex and we can query the voltage and frequency. You may say what happens if you are already running from the DFLL that happened to be setup by the bootloader? It is probably not likely as there is more software setup involved before you can enable the DFLL. However, it could be handled.

By the way, I am not saying that we should do this, but if we don't we need to define a safe/default V-F for all devices to operate at. I guess that it could also be specified in the DTB and if not we use a default.

Jon

#9 lore raw
In reply to Arnd Bergmann
Quoted 21 lines · Arnd Bergmann

This driver is the only one that calls regulator_sync_voltage(), but it can currently be built with CONFIG_REGULATOR disabled, producing this build error:

drivers/cpufreq/tegra124-cpufreq.c: In function 'tegra124_cpu_switch_to_pllx':
drivers/cpufreq/tegra124-cpufreq.c:68:2: error: implicit declaration of function 'regulator_sync_voltage' [-Werror=implicit-function-declaration]
regulator_sync_voltage(priv->vdd_cpu_reg);

My first attempt was to implement a helper for this function for regulator_sync_voltage, but Mark Brown explained:

We don't do this for *all* regulator API functions - there's some where using them strongly suggests that there is actually a dependency on the regulator API. This does seem like it might be falling into the specialist category [...]
Looking at the code I'm pretty unclear on what the authors think the use of _sync_voltage() is doing in the first place so it may be even better to just remove the call. It seems to have been included in the first commit so there's not changelog explaining things and there's no comment either. I'd *expect* it to be a noop as far as I can see.

Quoted 5 lines

This adds the dependency to make the driver always build successfully or not be enabled at all. Alternatively, we could investigate if the driver should stop calling regulator_sync_voltage instead.

Applied, thanks!

Rafael