Skip to content

Commit 78dca23

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: atmel-tcb: Put per-channel data into driver data
This simplifies the code, reduces the number of memory allocations and pointer dereferences. Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Claudiu Beznea <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent c116223 commit 78dca23

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

drivers/pwm/pwm-atmel-tcb.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct atmel_tcb_pwm_chip {
5656
struct clk *clk;
5757
struct clk *gclk;
5858
struct clk *slow_clk;
59-
struct atmel_tcb_pwm_device *pwms[NPWM];
59+
struct atmel_tcb_pwm_device pwms[NPWM];
6060
struct atmel_tcb_channel bkup;
6161
};
6262

@@ -72,7 +72,7 @@ static int atmel_tcb_pwm_set_polarity(struct pwm_chip *chip,
7272
enum pwm_polarity polarity)
7373
{
7474
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
75-
struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
75+
struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
7676

7777
tcbpwm->polarity = polarity;
7878

@@ -83,19 +83,13 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip,
8383
struct pwm_device *pwm)
8484
{
8585
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
86-
struct atmel_tcb_pwm_device *tcbpwm;
86+
struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
8787
unsigned cmr;
8888
int ret;
8989

90-
tcbpwm = devm_kzalloc(chip->dev, sizeof(*tcbpwm), GFP_KERNEL);
91-
if (!tcbpwm)
92-
return -ENOMEM;
93-
9490
ret = clk_prepare_enable(tcbpwmc->clk);
95-
if (ret) {
96-
devm_kfree(chip->dev, tcbpwm);
91+
if (ret)
9792
return ret;
98-
}
9993

10094
tcbpwm->polarity = PWM_POLARITY_NORMAL;
10195
tcbpwm->duty = 0;
@@ -130,25 +124,20 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip,
130124
regmap_write(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), cmr);
131125
spin_unlock(&tcbpwmc->lock);
132126

133-
tcbpwmc->pwms[pwm->hwpwm] = tcbpwm;
134-
135127
return 0;
136128
}
137129

138130
static void atmel_tcb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
139131
{
140132
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
141-
struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
142133

143134
clk_disable_unprepare(tcbpwmc->clk);
144-
tcbpwmc->pwms[pwm->hwpwm] = NULL;
145-
devm_kfree(chip->dev, tcbpwm);
146135
}
147136

148137
static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
149138
{
150139
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
151-
struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
140+
struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
152141
unsigned cmr;
153142
enum pwm_polarity polarity = tcbpwm->polarity;
154143

@@ -205,7 +194,7 @@ static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
205194
static int atmel_tcb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
206195
{
207196
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
208-
struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
197+
struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
209198
u32 cmr;
210199
enum pwm_polarity polarity = tcbpwm->polarity;
211200

@@ -290,7 +279,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
290279
int duty_ns, int period_ns)
291280
{
292281
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
293-
struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
282+
struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
294283
struct atmel_tcb_pwm_device *atcbpwm = NULL;
295284
int i = 0;
296285
int slowclk = 0;
@@ -337,9 +326,9 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
337326
period = div_u64(period_ns, min);
338327

339328
if (pwm->hwpwm == 0)
340-
atcbpwm = tcbpwmc->pwms[1];
329+
atcbpwm = &tcbpwmc->pwms[1];
341330
else
342-
atcbpwm = tcbpwmc->pwms[0];
331+
atcbpwm = &tcbpwmc->pwms[0];
343332

344333
/*
345334
* PWM devices provided by the TCB driver are grouped by 2.

0 commit comments

Comments
 (0)