Commit 78dca23b authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Thierry Reding

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: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: default avatarClaudiu Beznea <claudiu.beznea@tuxon.dev>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent c1162232
...@@ -56,7 +56,7 @@ struct atmel_tcb_pwm_chip { ...@@ -56,7 +56,7 @@ struct atmel_tcb_pwm_chip {
struct clk *clk; struct clk *clk;
struct clk *gclk; struct clk *gclk;
struct clk *slow_clk; struct clk *slow_clk;
struct atmel_tcb_pwm_device *pwms[NPWM]; struct atmel_tcb_pwm_device pwms[NPWM];
struct atmel_tcb_channel bkup; struct atmel_tcb_channel bkup;
}; };
...@@ -72,7 +72,7 @@ static int atmel_tcb_pwm_set_polarity(struct pwm_chip *chip, ...@@ -72,7 +72,7 @@ static int atmel_tcb_pwm_set_polarity(struct pwm_chip *chip,
enum pwm_polarity polarity) enum pwm_polarity polarity)
{ {
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip); struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm]; struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
tcbpwm->polarity = polarity; tcbpwm->polarity = polarity;
...@@ -83,19 +83,13 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip, ...@@ -83,19 +83,13 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip,
struct pwm_device *pwm) struct pwm_device *pwm)
{ {
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip); struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
struct atmel_tcb_pwm_device *tcbpwm; struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
unsigned cmr; unsigned cmr;
int ret; int ret;
tcbpwm = devm_kzalloc(chip->dev, sizeof(*tcbpwm), GFP_KERNEL);
if (!tcbpwm)
return -ENOMEM;
ret = clk_prepare_enable(tcbpwmc->clk); ret = clk_prepare_enable(tcbpwmc->clk);
if (ret) { if (ret)
devm_kfree(chip->dev, tcbpwm);
return ret; return ret;
}
tcbpwm->polarity = PWM_POLARITY_NORMAL; tcbpwm->polarity = PWM_POLARITY_NORMAL;
tcbpwm->duty = 0; tcbpwm->duty = 0;
...@@ -130,25 +124,20 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip, ...@@ -130,25 +124,20 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip,
regmap_write(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), cmr); regmap_write(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), cmr);
spin_unlock(&tcbpwmc->lock); spin_unlock(&tcbpwmc->lock);
tcbpwmc->pwms[pwm->hwpwm] = tcbpwm;
return 0; return 0;
} }
static void atmel_tcb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) static void atmel_tcb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
{ {
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip); struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
clk_disable_unprepare(tcbpwmc->clk); clk_disable_unprepare(tcbpwmc->clk);
tcbpwmc->pwms[pwm->hwpwm] = NULL;
devm_kfree(chip->dev, tcbpwm);
} }
static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
{ {
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip); struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm]; struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
unsigned cmr; unsigned cmr;
enum pwm_polarity polarity = tcbpwm->polarity; enum pwm_polarity polarity = tcbpwm->polarity;
...@@ -205,7 +194,7 @@ static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) ...@@ -205,7 +194,7 @@ static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
static int atmel_tcb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) static int atmel_tcb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
{ {
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip); struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm]; struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
u32 cmr; u32 cmr;
enum pwm_polarity polarity = tcbpwm->polarity; enum pwm_polarity polarity = tcbpwm->polarity;
...@@ -290,7 +279,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -290,7 +279,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns) int duty_ns, int period_ns)
{ {
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip); struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm]; struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
struct atmel_tcb_pwm_device *atcbpwm = NULL; struct atmel_tcb_pwm_device *atcbpwm = NULL;
int i = 0; int i = 0;
int slowclk = 0; int slowclk = 0;
...@@ -337,9 +326,9 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -337,9 +326,9 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
period = div_u64(period_ns, min); period = div_u64(period_ns, min);
if (pwm->hwpwm == 0) if (pwm->hwpwm == 0)
atcbpwm = tcbpwmc->pwms[1]; atcbpwm = &tcbpwmc->pwms[1];
else else
atcbpwm = tcbpwmc->pwms[0]; atcbpwm = &tcbpwmc->pwms[0];
/* /*
* PWM devices provided by the TCB driver are grouped by 2. * PWM devices provided by the TCB driver are grouped by 2.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment