Skip to content

Commit ab23315

Browse files
ukleinekgregkh
authored andcommitted
pwm: mediatek: Handle hardware enable and clock enable separately
commit 704d918 upstream. Stop handling the clocks in pwm_mediatek_enable() and pwm_mediatek_disable(). This is a preparing change for the next commit that requires that clocks and the enable bit are handled separately. Also move these two functions a bit further up in the source file to make them usable in pwm_mediatek_config(), which is needed in the next commit, too. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Link: https://lore.kernel.org/r/55c94fe2917ece152ee1e998f4675642a7716f13.1753717973.git.u.kleine-koenig@baylibre.com Cc: stable@vger.kernel.org Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e50917d commit ab23315

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

drivers/pwm/pwm-mediatek.c

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ static inline void pwm_mediatek_writel(struct pwm_mediatek_chip *chip,
115115
writel(value, chip->regs + chip->soc->reg_offset[num] + offset);
116116
}
117117

118+
static void pwm_mediatek_enable(struct pwm_chip *chip, struct pwm_device *pwm)
119+
{
120+
struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
121+
u32 value;
122+
123+
value = readl(pc->regs);
124+
value |= BIT(pwm->hwpwm);
125+
writel(value, pc->regs);
126+
}
127+
128+
static void pwm_mediatek_disable(struct pwm_chip *chip, struct pwm_device *pwm)
129+
{
130+
struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
131+
u32 value;
132+
133+
value = readl(pc->regs);
134+
value &= ~BIT(pwm->hwpwm);
135+
writel(value, pc->regs);
136+
}
137+
118138
static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
119139
int duty_ns, int period_ns)
120140
{
@@ -177,35 +197,6 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
177197
return ret;
178198
}
179199

180-
static int pwm_mediatek_enable(struct pwm_chip *chip, struct pwm_device *pwm)
181-
{
182-
struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
183-
u32 value;
184-
int ret;
185-
186-
ret = pwm_mediatek_clk_enable(chip, pwm);
187-
if (ret < 0)
188-
return ret;
189-
190-
value = readl(pc->regs);
191-
value |= BIT(pwm->hwpwm);
192-
writel(value, pc->regs);
193-
194-
return 0;
195-
}
196-
197-
static void pwm_mediatek_disable(struct pwm_chip *chip, struct pwm_device *pwm)
198-
{
199-
struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
200-
u32 value;
201-
202-
value = readl(pc->regs);
203-
value &= ~BIT(pwm->hwpwm);
204-
writel(value, pc->regs);
205-
206-
pwm_mediatek_clk_disable(chip, pwm);
207-
}
208-
209200
static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
210201
const struct pwm_state *state)
211202
{
@@ -215,8 +206,10 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
215206
return -EINVAL;
216207

217208
if (!state->enabled) {
218-
if (pwm->state.enabled)
209+
if (pwm->state.enabled) {
219210
pwm_mediatek_disable(chip, pwm);
211+
pwm_mediatek_clk_disable(chip, pwm);
212+
}
220213

221214
return 0;
222215
}
@@ -225,8 +218,11 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
225218
if (err)
226219
return err;
227220

228-
if (!pwm->state.enabled)
229-
err = pwm_mediatek_enable(chip, pwm);
221+
if (!pwm->state.enabled) {
222+
err = pwm_mediatek_clk_enable(chip, pwm);
223+
if (!err)
224+
pwm_mediatek_enable(chip, pwm);
225+
}
230226

231227
return err;
232228
}

0 commit comments

Comments
 (0)