Skip to content

Commit 704d918

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: mediatek: Handle hardware enable and clock enable separately
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 <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Link: https://lore.kernel.org/r/55c94fe2917ece152ee1e998f4675642a7716f13.1753717973.git.u.kleine-koenig@baylibre.com Cc: [email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 68b9272 commit 704d918

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
@@ -121,6 +121,26 @@ static inline void pwm_mediatek_writel(struct pwm_mediatek_chip *chip,
121121
writel(value, chip->regs + chip->soc->reg_offset[num] + offset);
122122
}
123123

124+
static void pwm_mediatek_enable(struct pwm_chip *chip, struct pwm_device *pwm)
125+
{
126+
struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
127+
u32 value;
128+
129+
value = readl(pc->regs);
130+
value |= BIT(pwm->hwpwm);
131+
writel(value, pc->regs);
132+
}
133+
134+
static void pwm_mediatek_disable(struct pwm_chip *chip, struct pwm_device *pwm)
135+
{
136+
struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
137+
u32 value;
138+
139+
value = readl(pc->regs);
140+
value &= ~BIT(pwm->hwpwm);
141+
writel(value, pc->regs);
142+
}
143+
124144
static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
125145
int duty_ns, int period_ns)
126146
{
@@ -183,35 +203,6 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
183203
return ret;
184204
}
185205

186-
static int pwm_mediatek_enable(struct pwm_chip *chip, struct pwm_device *pwm)
187-
{
188-
struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
189-
u32 value;
190-
int ret;
191-
192-
ret = pwm_mediatek_clk_enable(chip, pwm);
193-
if (ret < 0)
194-
return ret;
195-
196-
value = readl(pc->regs);
197-
value |= BIT(pwm->hwpwm);
198-
writel(value, pc->regs);
199-
200-
return 0;
201-
}
202-
203-
static void pwm_mediatek_disable(struct pwm_chip *chip, struct pwm_device *pwm)
204-
{
205-
struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
206-
u32 value;
207-
208-
value = readl(pc->regs);
209-
value &= ~BIT(pwm->hwpwm);
210-
writel(value, pc->regs);
211-
212-
pwm_mediatek_clk_disable(chip, pwm);
213-
}
214-
215206
static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
216207
const struct pwm_state *state)
217208
{
@@ -221,8 +212,10 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
221212
return -EINVAL;
222213

223214
if (!state->enabled) {
224-
if (pwm->state.enabled)
215+
if (pwm->state.enabled) {
225216
pwm_mediatek_disable(chip, pwm);
217+
pwm_mediatek_clk_disable(chip, pwm);
218+
}
226219

227220
return 0;
228221
}
@@ -231,8 +224,11 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
231224
if (err)
232225
return err;
233226

234-
if (!pwm->state.enabled)
235-
err = pwm_mediatek_enable(chip, pwm);
227+
if (!pwm->state.enabled) {
228+
err = pwm_mediatek_clk_enable(chip, pwm);
229+
if (!err)
230+
pwm_mediatek_enable(chip, pwm);
231+
}
236232

237233
return err;
238234
}

0 commit comments

Comments
 (0)