I’m attempting to modify the default PWM behaviour for an imx8mp module.
Background: There is a fan on PWM1 which is driven by low side switching and functions when configured as such in the device tree. The PWM is inverted, so a value of 0 corresponds to “full on”. There is a 100K pull-up on the pin.
However, it gets interesting when the module is placed into sleep mode (systemctl suspend). The fan will come on full blast (which appears to be expected since the system seems to pull the pin down while sleeping rather than tri-stating). And on resume, the PWM restores with a duty cycle of 50% (which is unexpected).
I’ve been reading and found that it appears to be possible to define pin configs for suspend by adding an additional pinctrl node with the name “sleep”, but I have not managed to get this to work - I’ve tried several config values (pull up, no pull up, weak pull up), but the pin always goes low when entering suspend - so I’m probably doing something wrong.
Note I’ve also tried changing the pad definition to GPIO instead of PWM in supend without any success either.
The “50% on resume” seems to be either a bug or quirk in the implementation of the pwm-fan.c driver we are using to integrate this fan into the system’s thermal control, as a “normal” PWM channel that is unbound does not appear to exhibit this behaviour.
I also found notes on having PWM “active” during suspend that suggest changing the oscillator and/or ensuring that it is active when sleeping. Can you refer me to some more detailed information on how that’s done? I found the clock specifications in the dts already, but am unsure what one would change them to or how to ensure a selected clock is active in sleep.
Unfortunately that change did not have the desired effect, the PWM pin still drops to 0v when I issue systemctl suspend. I found a note in the PWM driver as follows which suggests this might be a PWM driver limitation:
* Limitations:
* - When disabled the output is driven to 0 independent of the configured
* polarity.
I have indeed suggested making it non-inverting as a possible future board revision, but regardless of whether we address that in hardware or software, I’m also still interested in whether the PWM can be set to some fixed value while sleeping - There’s a possibility that some components will generate enough heat to require a small degree of cooling (but significantly less than the fan’s maximum airflow/power.
If it can be set to e.g a duty cycle of 10 or 20% that would address both concerns at the same time.
I couldn’t find any reference to the pinctrl “sleep” that you mentioned on the device tree. Checking the Refernece Manual fro the iMX8M Plus, it appears to be possible, since the sleep mode apparently doesn’t disable the PWM peripheral, although is not clear how to do that.
Can you please share you software version? Is it BSP 6? Kernel 5.15?
but at the time I also recall finding notes indicating that generally speaking, “sleep” was one of the allowed pinctrl state names for this purpose at the kernel level, rather than e.g. something driver specific, which led me to think that it would he handled by the kernel.
After some research, I have some thoughts on this issue. From what I could see, there is no mention of sleep function and callbacks on the PWM IMX driver from NXP. Also, there is no mention of sleep on the IMX PWM documentation.
For example, the driver for the STM32 mentions a function from the linux kernel that enabled sleep support:
static int __maybe_unused stm32_pwm_suspend(struct device *dev)
{
struct stm32_pwm *priv = dev_get_drvdata(dev);
unsigned int i;
u32 ccer, mask;
/* Look for active channels */
ccer = active_channels(priv);
for (i = 0; i < priv->chip.npwm; i++) {
mask = TIM_CCER_CC1E << (i * 4);
if (ccer & mask) {
dev_err(dev, "PWM %u still in use by consumer %s\n",
i, priv->chip.pwms[i].label);
return -EBUSY;
}
}
return pinctrl_pm_select_sleep_state(dev);
}
static int __maybe_unused stm32_pwm_resume(struct device *dev)
{
struct stm32_pwm *priv = dev_get_drvdata(dev);
int ret;
ret = pinctrl_pm_select_default_state(dev);
if (ret)
return ret;
/* restore breakinput registers that may have been lost in low power */
return stm32_pwm_apply_breakinputs(priv);
}
by searching for drivers inside the PWM folder that uses this function called “pinctrl_pm_select_sleep_state”, we can see that it doesn’t find anything for IMX:
As you previously mentioned, we can also see that the Tegra board supports this feature.
That being said, apparently, the iMX doesn’t support that. This function “pinctrl_pm_select_sleep_state” probably will search for the sleep state defined under the device tree, so it must be necessary for the sleep state.
If you still want to try and test something, I recommend you post a question on the NXP community, so they can better guide you through their drivers.
I’m happy to report that adding the PM functions (using stm32-pwm-lp as a reference) to the imx driver works just fine, now the fan stays off in sleep mode (or rather, it respects the “sleep” definition in the device-tree). It still comes out of suspend at 40%, but I suspect that is a bug in the pwm-fan driver.
Presumably with further modifications specific to our application it might be possible to set an actual PWM value during sleep.