Skip to content

Commit 9136a39

Browse files
Uwe Kleine-Königthierryreding
Uwe Kleine-König
authored andcommitted
pwm: lpc18xx-sct: Simplify driver by not using pwm_[gs]et_chip_data()
The per-channel data is available directly in the driver data struct. So use it without making use of pwm_[gs]et_chip_data(). The relevant change introduced by this patch to lpc18xx_pwm_disable() at the assembler level (for an arm lpc18xx_defconfig build) is: push {r3, r4, r5, lr} mov r4, r0 mov r0, r1 mov r5, r1 bl 0 <pwm_get_chip_data> ldr r3, [r0, #0] changes to ldr r3, [r1, torvalds#8] push {r4, lr} add.w r3, r0, r3, lsl #2 ldr r3, [r3, torvalds#92] ; 0x5c So this reduces stack usage, has an improved runtime behavior because of better pipeline usage, doesn't branch to an external function and the generated code is a bit smaller occupying less memory. The codesize of lpc18xx_pwm_probe() is reduced by 32 bytes. Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 20d9de9 commit 9136a39

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

drivers/pwm/pwm-lpc18xx-sct.c

+6-17
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static void lpc18xx_pwm_config_duty(struct pwm_chip *chip,
166166
struct pwm_device *pwm, int duty_ns)
167167
{
168168
struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
169-
struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm);
169+
struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm];
170170
u64 val;
171171

172172
val = (u64)duty_ns * lpc18xx_pwm->clk_rate;
@@ -236,7 +236,7 @@ static int lpc18xx_pwm_set_polarity(struct pwm_chip *chip,
236236
static int lpc18xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
237237
{
238238
struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
239-
struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm);
239+
struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm];
240240
enum lpc18xx_pwm_res_action res_action;
241241
unsigned int set_event, clear_event;
242242

@@ -271,7 +271,7 @@ static int lpc18xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
271271
static void lpc18xx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
272272
{
273273
struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
274-
struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm);
274+
struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm];
275275

276276
lpc18xx_pwm_writel(lpc18xx_pwm,
277277
LPC18XX_PWM_EVCTRL(lpc18xx_data->duty_event), 0);
@@ -282,7 +282,7 @@ static void lpc18xx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
282282
static int lpc18xx_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
283283
{
284284
struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
285-
struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm);
285+
struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm];
286286
unsigned long event;
287287

288288
event = find_first_zero_bit(&lpc18xx_pwm->event_map,
@@ -303,7 +303,7 @@ static int lpc18xx_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
303303
static void lpc18xx_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
304304
{
305305
struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
306-
struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm);
306+
struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm];
307307

308308
clear_bit(lpc18xx_data->duty_event, &lpc18xx_pwm->event_map);
309309
}
@@ -327,8 +327,7 @@ MODULE_DEVICE_TABLE(of, lpc18xx_pwm_of_match);
327327
static int lpc18xx_pwm_probe(struct platform_device *pdev)
328328
{
329329
struct lpc18xx_pwm_chip *lpc18xx_pwm;
330-
struct pwm_device *pwm;
331-
int ret, i;
330+
int ret;
332331
u64 val;
333332

334333
lpc18xx_pwm = devm_kzalloc(&pdev->dev, sizeof(*lpc18xx_pwm),
@@ -398,16 +397,6 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev)
398397
lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_LIMIT,
399398
BIT(lpc18xx_pwm->period_event));
400399

401-
for (i = 0; i < lpc18xx_pwm->chip.npwm; i++) {
402-
struct lpc18xx_pwm_data *data;
403-
404-
pwm = &lpc18xx_pwm->chip.pwms[i];
405-
406-
data = &lpc18xx_pwm->channeldata[i];
407-
408-
pwm_set_chip_data(pwm, data);
409-
}
410-
411400
val = lpc18xx_pwm_readl(lpc18xx_pwm, LPC18XX_PWM_CTRL);
412401
val &= ~LPC18XX_PWM_BIDIR;
413402
val &= ~LPC18XX_PWM_CTRL_HALT;

0 commit comments

Comments
 (0)