From: Theodore Oviguian <[email protected]>
eHRPWM driver was disabling the module clock at every channel disable, thats a bad idea because if the other chanel is enabled that froze it. Signed-off-by: Theodore Oviguian <[email protected]> Cc: Tom Rini <[email protected]> Cc: Lukasz Majewski <[email protected]> Cc: Neha Malcom Francis <[email protected]> --- V2: (Removed a trailing whitespace in the patch) V3: Remove a useless comment (sinc there an equivalent some lines before) Remove a useless loop : for (uint i = 0; i < TI_EHRPWM_NUM_CHANNELS; i++) priv->enabled[i] = false; Since as remarked by Neha Malcom Francis alloc_priv already use calloc or memset zero. Thanks to Neha Malcom Francis for the quality and speed of the reviews drivers/pwm/pwm-ti-ehrpwm.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/pwm-ti-ehrpwm.c b/drivers/pwm/pwm-ti-ehrpwm.c index 135ea3b4321..a74d59a71df 100644 --- a/drivers/pwm/pwm-ti-ehrpwm.c +++ b/drivers/pwm/pwm-ti-ehrpwm.c @@ -101,6 +101,7 @@ struct ti_ehrpwm_priv { struct clk tbclk; unsigned long period_cycles[TI_EHRPWM_NUM_CHANNELS]; bool polarity_reversed[TI_EHRPWM_NUM_CHANNELS]; + bool enabled[TI_EHRPWM_NUM_CHANNELS]; }; static void ti_ehrpwm_modify(u16 val, u16 mask, fdt_addr_t reg) @@ -333,7 +334,16 @@ static int ti_ehrpwm_disable(struct udevice *dev, uint channel) ti_ehrpwm_modify(aqcsfrc_val, aqcsfrc_mask, priv->regs + TI_EHRPWM_AQCSFRC); - /* Disabling TBCLK on PWM disable */ + /* + * Disabling TBCLK on PWM disable + * Only if all channels are disabled + */ + priv->enabled[channel] = false; + for (uint i = 0; i < TI_EHRPWM_NUM_CHANNELS; i++) { + if (priv->enabled[i]) + return 0; + } + err = clk_disable(&priv->tbclk); if (err) { dev_err(dev, "failed to disable tbclk\n"); @@ -377,7 +387,7 @@ static int ti_ehrpwm_enable(struct udevice *dev, uint channel) dev_err(dev, "failed to enable tbclk\n"); return err; } - + priv->enabled[channel] = true; return 0; } @@ -399,7 +409,7 @@ static int ti_ehrpwm_of_to_plat(struct udevice *dev) return -EINVAL; } - dev_dbg(dev, "regs=0x%08x\n", priv->regs); + dev_dbg(dev, "regs=0x%08llx\n", priv->regs); return 0; } -- 2.43.0

