Skip to content

Commit 1b2af7b

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: berlin: Put per-channel config into driver data
Instead of allocating extra data in .request() provide the needed memory in struct berlin_pwm_chip. This reduces the number of allocations. A side effect is that on suspend and resume the state for all four channels is always saved and restored. This is easier (and probably quicker) than looking up the matching pwm_device and checking its PWMF_REQUESTED bit. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 91a69d3 commit 1b2af7b

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

drivers/pwm/pwm-berlin.c

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#define BERLIN_PWM_TCNT 0xc
4040
#define BERLIN_PWM_MAX_TCNT 65535
4141

42+
#define BERLIN_PWM_NUMPWMS 4
43+
4244
struct berlin_pwm_channel {
4345
u32 enable;
4446
u32 ctrl;
@@ -50,6 +52,7 @@ struct berlin_pwm_chip {
5052
struct pwm_chip chip;
5153
struct clk *clk;
5254
void __iomem *base;
55+
struct berlin_pwm_channel channel[BERLIN_PWM_NUMPWMS];
5356
};
5457

5558
static inline struct berlin_pwm_chip *to_berlin_pwm_chip(struct pwm_chip *chip)
@@ -70,24 +73,6 @@ static inline void berlin_pwm_writel(struct berlin_pwm_chip *bpc,
7073
writel_relaxed(value, bpc->base + channel * 0x10 + offset);
7174
}
7275

73-
static int berlin_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
74-
{
75-
struct berlin_pwm_channel *channel;
76-
77-
channel = kzalloc(sizeof(*channel), GFP_KERNEL);
78-
if (!channel)
79-
return -ENOMEM;
80-
81-
return pwm_set_chip_data(pwm, channel);
82-
}
83-
84-
static void berlin_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
85-
{
86-
struct berlin_pwm_channel *channel = pwm_get_chip_data(pwm);
87-
88-
kfree(channel);
89-
}
90-
9176
static int berlin_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
9277
u64 duty_ns, u64 period_ns)
9378
{
@@ -202,8 +187,6 @@ static int berlin_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
202187
}
203188

204189
static const struct pwm_ops berlin_pwm_ops = {
205-
.request = berlin_pwm_request,
206-
.free = berlin_pwm_free,
207190
.apply = berlin_pwm_apply,
208191
};
209192

@@ -236,7 +219,7 @@ static int berlin_pwm_probe(struct platform_device *pdev)
236219

237220
bpc->chip.dev = &pdev->dev;
238221
bpc->chip.ops = &berlin_pwm_ops;
239-
bpc->chip.npwm = 4;
222+
bpc->chip.npwm = BERLIN_PWM_NUMPWMS;
240223

241224
ret = pwmchip_add(&bpc->chip);
242225
if (ret < 0) {
@@ -266,11 +249,7 @@ static int berlin_pwm_suspend(struct device *dev)
266249
unsigned int i;
267250

268251
for (i = 0; i < bpc->chip.npwm; i++) {
269-
struct berlin_pwm_channel *channel;
270-
271-
channel = pwm_get_chip_data(&bpc->chip.pwms[i]);
272-
if (!channel)
273-
continue;
252+
struct berlin_pwm_channel *channel = &bpc->channel[i];
274253

275254
channel->enable = berlin_pwm_readl(bpc, i, BERLIN_PWM_ENABLE);
276255
channel->ctrl = berlin_pwm_readl(bpc, i, BERLIN_PWM_CONTROL);
@@ -294,11 +273,7 @@ static int berlin_pwm_resume(struct device *dev)
294273
return ret;
295274

296275
for (i = 0; i < bpc->chip.npwm; i++) {
297-
struct berlin_pwm_channel *channel;
298-
299-
channel = pwm_get_chip_data(&bpc->chip.pwms[i]);
300-
if (!channel)
301-
continue;
276+
struct berlin_pwm_channel *channel = &bpc->channel[i];
302277

303278
berlin_pwm_writel(bpc, i, channel->ctrl, BERLIN_PWM_CONTROL);
304279
berlin_pwm_writel(bpc, i, channel->duty, BERLIN_PWM_DUTY);

0 commit comments

Comments
 (0)