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>
This commit is contained in:
parent
06cc476775
commit
ec63391a0d
@ -85,6 +85,7 @@ struct tpu_device {
|
||||
|
||||
void __iomem *base;
|
||||
struct clk *clk;
|
||||
struct tpu_pwm_device tpd[TPU_CHANNEL_MAX];
|
||||
};
|
||||
|
||||
#define to_tpu_device(c) container_of(c, struct tpu_device, chip)
|
||||
@ -215,9 +216,7 @@ static int tpu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
if (pwm->hwpwm >= TPU_CHANNEL_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
tpd = kzalloc(sizeof(*tpd), GFP_KERNEL);
|
||||
if (tpd == NULL)
|
||||
return -ENOMEM;
|
||||
tpd = &tpu->tpd[pwm->hwpwm];
|
||||
|
||||
tpd->tpu = tpu;
|
||||
tpd->channel = pwm->hwpwm;
|
||||
@ -228,24 +227,22 @@ static int tpu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
|
||||
tpd->timer_on = false;
|
||||
|
||||
pwm_set_chip_data(pwm, tpd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tpu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
{
|
||||
struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm);
|
||||
struct tpu_device *tpu = to_tpu_device(chip);
|
||||
struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm];
|
||||
|
||||
tpu_pwm_timer_stop(tpd);
|
||||
kfree(tpd);
|
||||
}
|
||||
|
||||
static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
u64 duty_ns, u64 period_ns, bool enabled)
|
||||
{
|
||||
struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm);
|
||||
struct tpu_device *tpu = to_tpu_device(chip);
|
||||
struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm];
|
||||
unsigned int prescaler;
|
||||
bool duty_only = false;
|
||||
u32 clk_rate;
|
||||
@ -353,7 +350,8 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
static int tpu_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
enum pwm_polarity polarity)
|
||||
{
|
||||
struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm);
|
||||
struct tpu_device *tpu = to_tpu_device(chip);
|
||||
struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm];
|
||||
|
||||
tpd->polarity = polarity;
|
||||
|
||||
@ -362,7 +360,8 @@ static int tpu_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
|
||||
static int tpu_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
{
|
||||
struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm);
|
||||
struct tpu_device *tpu = to_tpu_device(chip);
|
||||
struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm];
|
||||
int ret;
|
||||
|
||||
ret = tpu_pwm_timer_start(tpd);
|
||||
@ -384,7 +383,8 @@ static int tpu_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
|
||||
static void tpu_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
{
|
||||
struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm);
|
||||
struct tpu_device *tpu = to_tpu_device(chip);
|
||||
struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm];
|
||||
|
||||
/* The timer must be running to modify the pin output configuration. */
|
||||
tpu_pwm_timer_start(tpd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user