Commit 08a4d8ec authored by Bartlomiej Zolnierkiewicz's avatar Bartlomiej Zolnierkiewicz Committed by Thierry Reding

pwm: pwm-samsung: fix suspend/resume support

Fix suspend/resume support:

- add disabled_mask to struct samsung_pwm_chip to track PWM
  disabled state information in pwm_samsung_{disable,enable}()

- rename pwm_samsung_config() to __pwm_samsung_config() and
  add extra force_period parameter to be used during resume
  (to force tin_ns and tcnt recalculation)

- add pwm_samsung_config() wrapper for preserving old behavior

- properly restore PWM configuration in pwm_samsung_resume()

- remove no longer needed pwm_samsung_suspend()

- update Copyrights
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent 23aa19a2
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* Copyright (c) 2008 Simtec Electronics * Copyright (c) 2008 Simtec Electronics
* Ben Dooks <ben@simtec.co.uk>, <ben-linux@fluff.org> * Ben Dooks <ben@simtec.co.uk>, <ben-linux@fluff.org>
* Copyright (c) 2013 Tomasz Figa <tomasz.figa@gmail.com> * Copyright (c) 2013 Tomasz Figa <tomasz.figa@gmail.com>
* Copyright (c) 2017 Samsung Electronics Co., Ltd.
* *
* PWM driver for Samsung SoCs * PWM driver for Samsung SoCs
* *
...@@ -74,6 +75,7 @@ struct samsung_pwm_channel { ...@@ -74,6 +75,7 @@ struct samsung_pwm_channel {
* @chip: generic PWM chip * @chip: generic PWM chip
* @variant: local copy of hardware variant data * @variant: local copy of hardware variant data
* @inverter_mask: inverter status for all channels - one bit per channel * @inverter_mask: inverter status for all channels - one bit per channel
* @disabled_mask: disabled status for all channels - one bit per channel
* @base: base address of mapped PWM registers * @base: base address of mapped PWM registers
* @base_clk: base clock used to drive the timers * @base_clk: base clock used to drive the timers
* @tclk0: external clock 0 (can be ERR_PTR if not present) * @tclk0: external clock 0 (can be ERR_PTR if not present)
...@@ -83,6 +85,7 @@ struct samsung_pwm_chip { ...@@ -83,6 +85,7 @@ struct samsung_pwm_chip {
struct pwm_chip chip; struct pwm_chip chip;
struct samsung_pwm_variant variant; struct samsung_pwm_variant variant;
u8 inverter_mask; u8 inverter_mask;
u8 disabled_mask;
void __iomem *base; void __iomem *base;
struct clk *base_clk; struct clk *base_clk;
...@@ -257,6 +260,8 @@ static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm) ...@@ -257,6 +260,8 @@ static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm)
tcon |= TCON_START(tcon_chan) | TCON_AUTORELOAD(tcon_chan); tcon |= TCON_START(tcon_chan) | TCON_AUTORELOAD(tcon_chan);
writel(tcon, our_chip->base + REG_TCON); writel(tcon, our_chip->base + REG_TCON);
our_chip->disabled_mask &= ~BIT(pwm->hwpwm);
spin_unlock_irqrestore(&samsung_pwm_lock, flags); spin_unlock_irqrestore(&samsung_pwm_lock, flags);
return 0; return 0;
...@@ -275,6 +280,8 @@ static void pwm_samsung_disable(struct pwm_chip *chip, struct pwm_device *pwm) ...@@ -275,6 +280,8 @@ static void pwm_samsung_disable(struct pwm_chip *chip, struct pwm_device *pwm)
tcon &= ~TCON_AUTORELOAD(tcon_chan); tcon &= ~TCON_AUTORELOAD(tcon_chan);
writel(tcon, our_chip->base + REG_TCON); writel(tcon, our_chip->base + REG_TCON);
our_chip->disabled_mask |= BIT(pwm->hwpwm);
spin_unlock_irqrestore(&samsung_pwm_lock, flags); spin_unlock_irqrestore(&samsung_pwm_lock, flags);
} }
...@@ -297,8 +304,8 @@ static void pwm_samsung_manual_update(struct samsung_pwm_chip *chip, ...@@ -297,8 +304,8 @@ static void pwm_samsung_manual_update(struct samsung_pwm_chip *chip,
spin_unlock_irqrestore(&samsung_pwm_lock, flags); spin_unlock_irqrestore(&samsung_pwm_lock, flags);
} }
static int pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm, static int __pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns) int duty_ns, int period_ns, bool force_period)
{ {
struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip); struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip);
struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm); struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm);
...@@ -319,7 +326,7 @@ static int pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -319,7 +326,7 @@ static int pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm,
++tcnt; ++tcnt;
/* Check to see if we are changing the clock rate of the PWM. */ /* Check to see if we are changing the clock rate of the PWM. */
if (chan->period_ns != period_ns) { if (chan->period_ns != period_ns || force_period) {
unsigned long tin_rate; unsigned long tin_rate;
u32 period; u32 period;
...@@ -378,6 +385,12 @@ static int pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -378,6 +385,12 @@ static int pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm,
return 0; return 0;
} }
static int pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns)
{
return __pwm_samsung_config(chip, pwm, duty_ns, period_ns, false);
}
static void pwm_samsung_set_invert(struct samsung_pwm_chip *chip, static void pwm_samsung_set_invert(struct samsung_pwm_chip *chip,
unsigned int channel, bool invert) unsigned int channel, bool invert)
{ {
...@@ -589,51 +602,41 @@ static int pwm_samsung_remove(struct platform_device *pdev) ...@@ -589,51 +602,41 @@ static int pwm_samsung_remove(struct platform_device *pdev)
} }
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int pwm_samsung_suspend(struct device *dev) static int pwm_samsung_resume(struct device *dev)
{ {
struct samsung_pwm_chip *chip = dev_get_drvdata(dev); struct samsung_pwm_chip *our_chip = dev_get_drvdata(dev);
struct pwm_chip *chip = &our_chip->chip;
unsigned int i; unsigned int i;
/* for (i = 0; i < SAMSUNG_PWM_NUM; i++) {
* No one preserves these values during suspend so reset them. struct pwm_device *pwm = &chip->pwms[i];
* Otherwise driver leaves PWM unconfigured if same values are
* passed to pwm_config() next time.
*/
for (i = 0; i < SAMSUNG_PWM_NUM; ++i) {
struct pwm_device *pwm = &chip->chip.pwms[i];
struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm); struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm);
if (!chan) if (!chan)
continue; continue;
chan->period_ns = 0; if (our_chip->variant.output_mask & BIT(i))
chan->duty_ns = 0; pwm_samsung_set_invert(our_chip, i,
} our_chip->inverter_mask & BIT(i));
return 0;
}
static int pwm_samsung_resume(struct device *dev) if (chan->period_ns) {
{ __pwm_samsung_config(chip, pwm, chan->duty_ns,
struct samsung_pwm_chip *chip = dev_get_drvdata(dev); chan->period_ns, true);
unsigned int chan; /* needed to make PWM disable work on Odroid-XU3 */
pwm_samsung_manual_update(our_chip, pwm);
}
/* if (our_chip->disabled_mask & BIT(i))
* Inverter setting must be preserved across suspend/resume pwm_samsung_disable(chip, pwm);
* as nobody really seems to configure it more than once. else
*/ pwm_samsung_enable(chip, pwm);
for (chan = 0; chan < SAMSUNG_PWM_NUM; ++chan) {
if (chip->variant.output_mask & BIT(chan))
pwm_samsung_set_invert(chip, chan,
chip->inverter_mask & BIT(chan));
} }
return 0; return 0;
} }
#endif #endif
static SIMPLE_DEV_PM_OPS(pwm_samsung_pm_ops, pwm_samsung_suspend, static SIMPLE_DEV_PM_OPS(pwm_samsung_pm_ops, NULL, pwm_samsung_resume);
pwm_samsung_resume);
static struct platform_driver pwm_samsung_driver = { static struct platform_driver pwm_samsung_driver = {
.driver = { .driver = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment