Skip to content

Commit e3fe982

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: samsung: Put per-channel data into driver data
Instead of allocating extra data in .request() provide the needed memory in struct samsung_pwm_chip. This reduces the number of allocations. Even though now all 5 channel structs are allocated this is probably outweighed by the reduced overhead to track up to 6 smaller allocations. 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 1b2af7b commit e3fe982

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

drivers/pwm/pwm-samsung.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct samsung_pwm_chip {
8888
struct clk *base_clk;
8989
struct clk *tclk0;
9090
struct clk *tclk1;
91+
struct samsung_pwm_channel channel[SAMSUNG_PWM_NUM];
9192
};
9293

9394
#ifndef CONFIG_CLKSRC_SAMSUNG_PWM
@@ -228,7 +229,6 @@ static unsigned long pwm_samsung_calc_tin(struct samsung_pwm_chip *chip,
228229
static int pwm_samsung_request(struct pwm_chip *chip, struct pwm_device *pwm)
229230
{
230231
struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip);
231-
struct samsung_pwm_channel *our_chan;
232232

233233
if (!(our_chip->variant.output_mask & BIT(pwm->hwpwm))) {
234234
dev_warn(chip->dev,
@@ -237,20 +237,11 @@ static int pwm_samsung_request(struct pwm_chip *chip, struct pwm_device *pwm)
237237
return -EINVAL;
238238
}
239239

240-
our_chan = kzalloc(sizeof(*our_chan), GFP_KERNEL);
241-
if (!our_chan)
242-
return -ENOMEM;
243-
244-
pwm_set_chip_data(pwm, our_chan);
240+
memset(&our_chip->channel[pwm->hwpwm], 0, sizeof(our_chip->channel[pwm->hwpwm]));
245241

246242
return 0;
247243
}
248244

249-
static void pwm_samsung_free(struct pwm_chip *chip, struct pwm_device *pwm)
250-
{
251-
kfree(pwm_get_chip_data(pwm));
252-
}
253-
254245
static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm)
255246
{
256247
struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip);
@@ -318,7 +309,7 @@ static int __pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm,
318309
int duty_ns, int period_ns, bool force_period)
319310
{
320311
struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip);
321-
struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm);
312+
struct samsung_pwm_channel *chan = &our_chip->channel[pwm->hwpwm];
322313
u32 tin_ns = chan->tin_ns, tcnt, tcmp, oldtcmp;
323314

324315
tcnt = readl(our_chip->base + REG_TCNTB(pwm->hwpwm));
@@ -473,7 +464,6 @@ static int pwm_samsung_apply(struct pwm_chip *chip, struct pwm_device *pwm,
473464

474465
static const struct pwm_ops pwm_samsung_ops = {
475466
.request = pwm_samsung_request,
476-
.free = pwm_samsung_free,
477467
.apply = pwm_samsung_apply,
478468
};
479469

@@ -638,9 +628,9 @@ static int pwm_samsung_resume(struct device *dev)
638628

639629
for (i = 0; i < SAMSUNG_PWM_NUM; i++) {
640630
struct pwm_device *pwm = &chip->pwms[i];
641-
struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm);
631+
struct samsung_pwm_channel *chan = &our_chip->channel[i];
642632

643-
if (!chan)
633+
if (!(pwm->flags & PWMF_REQUESTED))
644634
continue;
645635

646636
if (our_chip->variant.output_mask & BIT(i))

0 commit comments

Comments
 (0)