Commit 53784159 authored by Claudiu Beznea's avatar Claudiu Beznea Committed by Thierry Reding

pwm: atmel: Add struct atmel_pwm_data

Add struct atmel_pwm_data to embed different per controller information.
It prepares adding support for another similar controller that needs
additional information. At this stage, embed a member of type struct
atmel_pwm_registers in it.
Signed-off-by: default avatarClaudiu Beznea <claudiu.beznea@microchip.com>
Acked-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent a87b4061
...@@ -65,11 +65,15 @@ struct atmel_pwm_registers { ...@@ -65,11 +65,15 @@ struct atmel_pwm_registers {
u8 duty_upd; u8 duty_upd;
}; };
struct atmel_pwm_data {
struct atmel_pwm_registers regs;
};
struct atmel_pwm_chip { struct atmel_pwm_chip {
struct pwm_chip chip; struct pwm_chip chip;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
const struct atmel_pwm_registers *regs; const struct atmel_pwm_data *data;
unsigned int updated_pwms; unsigned int updated_pwms;
/* ISR is cleared when read, ensure only one thread does that */ /* ISR is cleared when read, ensure only one thread does that */
...@@ -150,15 +154,15 @@ static void atmel_pwm_update_cdty(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -150,15 +154,15 @@ static void atmel_pwm_update_cdty(struct pwm_chip *chip, struct pwm_device *pwm,
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
u32 val; u32 val;
if (atmel_pwm->regs->duty_upd == if (atmel_pwm->data->regs.duty_upd ==
atmel_pwm->regs->period_upd) { atmel_pwm->data->regs.period_upd) {
val = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, PWM_CMR); val = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, PWM_CMR);
val &= ~PWM_CMR_UPD_CDTY; val &= ~PWM_CMR_UPD_CDTY;
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, val); atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, val);
} }
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm,
atmel_pwm->regs->duty_upd, cdty); atmel_pwm->data->regs.duty_upd, cdty);
} }
static void atmel_pwm_set_cprd_cdty(struct pwm_chip *chip, static void atmel_pwm_set_cprd_cdty(struct pwm_chip *chip,
...@@ -168,9 +172,9 @@ static void atmel_pwm_set_cprd_cdty(struct pwm_chip *chip, ...@@ -168,9 +172,9 @@ static void atmel_pwm_set_cprd_cdty(struct pwm_chip *chip,
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm,
atmel_pwm->regs->duty, cdty); atmel_pwm->data->regs.duty, cdty);
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm,
atmel_pwm->regs->period, cprd); atmel_pwm->data->regs.period, cprd);
} }
static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm, static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm,
...@@ -225,7 +229,7 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -225,7 +229,7 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
cstate.polarity == state->polarity && cstate.polarity == state->polarity &&
cstate.period == state->period) { cstate.period == state->period) {
cprd = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, cprd = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm,
atmel_pwm->regs->period); atmel_pwm->data->regs.period);
atmel_pwm_calculate_cdty(state, cprd, &cdty); atmel_pwm_calculate_cdty(state, cprd, &cdty);
atmel_pwm_update_cdty(chip, pwm, cdty); atmel_pwm_update_cdty(chip, pwm, cdty);
return 0; return 0;
...@@ -277,27 +281,31 @@ static const struct pwm_ops atmel_pwm_ops = { ...@@ -277,27 +281,31 @@ static const struct pwm_ops atmel_pwm_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
}; };
static const struct atmel_pwm_registers atmel_pwm_regs_v1 = { static const struct atmel_pwm_data atmel_pwm_data_v1 = {
.period = PWMV1_CPRD, .regs = {
.period_upd = PWMV1_CUPD, .period = PWMV1_CPRD,
.duty = PWMV1_CDTY, .period_upd = PWMV1_CUPD,
.duty_upd = PWMV1_CUPD, .duty = PWMV1_CDTY,
.duty_upd = PWMV1_CUPD,
},
}; };
static const struct atmel_pwm_registers atmel_pwm_regs_v2 = { static const struct atmel_pwm_data atmel_pwm_data_v2 = {
.period = PWMV2_CPRD, .regs = {
.period_upd = PWMV2_CPRDUPD, .period = PWMV2_CPRD,
.duty = PWMV2_CDTY, .period_upd = PWMV2_CPRDUPD,
.duty_upd = PWMV2_CDTYUPD, .duty = PWMV2_CDTY,
.duty_upd = PWMV2_CDTYUPD,
},
}; };
static const struct platform_device_id atmel_pwm_devtypes[] = { static const struct platform_device_id atmel_pwm_devtypes[] = {
{ {
.name = "at91sam9rl-pwm", .name = "at91sam9rl-pwm",
.driver_data = (kernel_ulong_t)&atmel_pwm_regs_v1, .driver_data = (kernel_ulong_t)&atmel_pwm_data_v1,
}, { }, {
.name = "sama5d3-pwm", .name = "sama5d3-pwm",
.driver_data = (kernel_ulong_t)&atmel_pwm_regs_v2, .driver_data = (kernel_ulong_t)&atmel_pwm_data_v2,
}, { }, {
/* sentinel */ /* sentinel */
}, },
...@@ -307,20 +315,20 @@ MODULE_DEVICE_TABLE(platform, atmel_pwm_devtypes); ...@@ -307,20 +315,20 @@ MODULE_DEVICE_TABLE(platform, atmel_pwm_devtypes);
static const struct of_device_id atmel_pwm_dt_ids[] = { static const struct of_device_id atmel_pwm_dt_ids[] = {
{ {
.compatible = "atmel,at91sam9rl-pwm", .compatible = "atmel,at91sam9rl-pwm",
.data = &atmel_pwm_regs_v1, .data = &atmel_pwm_data_v1,
}, { }, {
.compatible = "atmel,sama5d3-pwm", .compatible = "atmel,sama5d3-pwm",
.data = &atmel_pwm_regs_v2, .data = &atmel_pwm_data_v2,
}, { }, {
.compatible = "atmel,sama5d2-pwm", .compatible = "atmel,sama5d2-pwm",
.data = &atmel_pwm_regs_v2, .data = &atmel_pwm_data_v2,
}, { }, {
/* sentinel */ /* sentinel */
}, },
}; };
MODULE_DEVICE_TABLE(of, atmel_pwm_dt_ids); MODULE_DEVICE_TABLE(of, atmel_pwm_dt_ids);
static inline const struct atmel_pwm_registers * static inline const struct atmel_pwm_data *
atmel_pwm_get_driver_data(struct platform_device *pdev) atmel_pwm_get_driver_data(struct platform_device *pdev)
{ {
const struct platform_device_id *id; const struct platform_device_id *id;
...@@ -330,18 +338,18 @@ atmel_pwm_get_driver_data(struct platform_device *pdev) ...@@ -330,18 +338,18 @@ atmel_pwm_get_driver_data(struct platform_device *pdev)
id = platform_get_device_id(pdev); id = platform_get_device_id(pdev);
return (struct atmel_pwm_registers *)id->driver_data; return (struct atmel_pwm_data *)id->driver_data;
} }
static int atmel_pwm_probe(struct platform_device *pdev) static int atmel_pwm_probe(struct platform_device *pdev)
{ {
const struct atmel_pwm_registers *regs; const struct atmel_pwm_data *data;
struct atmel_pwm_chip *atmel_pwm; struct atmel_pwm_chip *atmel_pwm;
struct resource *res; struct resource *res;
int ret; int ret;
regs = atmel_pwm_get_driver_data(pdev); data = atmel_pwm_get_driver_data(pdev);
if (!regs) if (!data)
return -ENODEV; return -ENODEV;
atmel_pwm = devm_kzalloc(&pdev->dev, sizeof(*atmel_pwm), GFP_KERNEL); atmel_pwm = devm_kzalloc(&pdev->dev, sizeof(*atmel_pwm), GFP_KERNEL);
...@@ -373,7 +381,7 @@ static int atmel_pwm_probe(struct platform_device *pdev) ...@@ -373,7 +381,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
atmel_pwm->chip.base = -1; atmel_pwm->chip.base = -1;
atmel_pwm->chip.npwm = 4; atmel_pwm->chip.npwm = 4;
atmel_pwm->regs = regs; atmel_pwm->data = data;
atmel_pwm->updated_pwms = 0; atmel_pwm->updated_pwms = 0;
mutex_init(&atmel_pwm->isr_lock); mutex_init(&atmel_pwm->isr_lock);
......
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