Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pwm: renesas: Drop usage of pwm_[gs]et_chip_data()

Instead of distributing the driver's bookkeeping over 5 (i.e.
TPU_CHANNEL_MAX + 1) separately allocated memory chunks, put all together
in struct tpu_device. This reduces the number of memory allocations and
so fragmentation and maybe even the number of cache misses. Also
&tpu->tpd[pwm->hwpwm] is cheaper to evaluate than pwm_get_chip_data(pwm)
as the former is just an addition in machine code while the latter involves
a function call.

Link: https://lore.kernel.org/r/20230705080650.2353391-6-u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Uwe Kleine-König and committed by
Thierry Reding
ec63391a 06cc4767

+11 -11
+11 -11
drivers/pwm/pwm-renesas-tpu.c
··· 85 85 86 86 void __iomem *base; 87 87 struct clk *clk; 88 + struct tpu_pwm_device tpd[TPU_CHANNEL_MAX]; 88 89 }; 89 90 90 91 #define to_tpu_device(c) container_of(c, struct tpu_device, chip) ··· 216 215 if (pwm->hwpwm >= TPU_CHANNEL_MAX) 217 216 return -EINVAL; 218 217 219 - tpd = kzalloc(sizeof(*tpd), GFP_KERNEL); 220 - if (tpd == NULL) 221 - return -ENOMEM; 218 + tpd = &tpu->tpd[pwm->hwpwm]; 222 219 223 220 tpd->tpu = tpu; 224 221 tpd->channel = pwm->hwpwm; ··· 227 228 228 229 tpd->timer_on = false; 229 230 230 - pwm_set_chip_data(pwm, tpd); 231 - 232 231 return 0; 233 232 } 234 233 235 234 static void tpu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 236 235 { 237 - struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm); 236 + struct tpu_device *tpu = to_tpu_device(chip); 237 + struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; 238 238 239 239 tpu_pwm_timer_stop(tpd); 240 - kfree(tpd); 241 240 } 242 241 243 242 static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 244 243 u64 duty_ns, u64 period_ns, bool enabled) 245 244 { 246 - struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm); 247 245 struct tpu_device *tpu = to_tpu_device(chip); 246 + struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; 248 247 unsigned int prescaler; 249 248 bool duty_only = false; 250 249 u32 clk_rate; ··· 350 353 static int tpu_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, 351 354 enum pwm_polarity polarity) 352 355 { 353 - struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm); 356 + struct tpu_device *tpu = to_tpu_device(chip); 357 + struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; 354 358 355 359 tpd->polarity = polarity; 356 360 ··· 360 362 361 363 static int tpu_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) 362 364 { 363 - struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm); 365 + struct tpu_device *tpu = to_tpu_device(chip); 366 + struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; 364 367 int ret; 365 368 366 369 ret = tpu_pwm_timer_start(tpd); ··· 383 384 384 385 static void tpu_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) 385 386 { 386 - struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm); 387 + struct tpu_device *tpu = to_tpu_device(chip); 388 + struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; 387 389 388 390 /* The timer must be running to modify the pin output configuration. */ 389 391 tpu_pwm_timer_start(tpd);