Commit 0f14aca0 authored by Uwe Kleine-König's avatar Uwe Kleine-König

pwm: sprd: Rework how the available channels are counted

To be able to convert the sprd driver to pwmchip_alloc() the number of
PWM channels must be known when the driver private data is allocated. So
make sprd_pwm_clk_init() not take a struct sprd_pwm_chip. On the plus
side this allows to drop a member of said driver private data.
Reviewed-by: default avatarChunyan Zhang <zhang.lyra@gmail.com>
Link: https://lore.kernel.org/r/682cbbafbfc4982383d66c3871bb9e52d4e03195.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent 792bc125
......@@ -36,7 +36,6 @@ struct sprd_pwm_chip {
void __iomem *base;
struct device *dev;
struct pwm_chip chip;
int num_pwms;
struct sprd_pwm_chn chn[SPRD_PWM_CHN_NUM];
};
......@@ -215,45 +214,48 @@ static const struct pwm_ops sprd_pwm_ops = {
.get_state = sprd_pwm_get_state,
};
static int sprd_pwm_clk_init(struct sprd_pwm_chip *spc)
static int sprd_pwm_clk_init(struct device *dev,
struct sprd_pwm_chn chn[SPRD_PWM_CHN_NUM])
{
struct clk *clk_pwm;
int ret, i;
for (i = 0; i < SPRD_PWM_CHN_NUM; i++) {
struct sprd_pwm_chn *chn = &spc->chn[i];
int j;
for (j = 0; j < SPRD_PWM_CHN_CLKS_NUM; ++j)
chn->clks[j].id =
chn[i].clks[j].id =
sprd_pwm_clks[i * SPRD_PWM_CHN_CLKS_NUM + j];
ret = devm_clk_bulk_get(spc->dev, SPRD_PWM_CHN_CLKS_NUM,
chn->clks);
ret = devm_clk_bulk_get(dev, SPRD_PWM_CHN_CLKS_NUM,
chn[i].clks);
if (ret) {
if (ret == -ENOENT)
break;
return dev_err_probe(spc->dev, ret,
return dev_err_probe(dev, ret,
"failed to get channel clocks\n");
}
clk_pwm = chn->clks[SPRD_PWM_CHN_OUTPUT_CLK].clk;
chn->clk_rate = clk_get_rate(clk_pwm);
clk_pwm = chn[i].clks[SPRD_PWM_CHN_OUTPUT_CLK].clk;
chn[i].clk_rate = clk_get_rate(clk_pwm);
}
if (!i)
return dev_err_probe(spc->dev, -ENODEV, "no available PWM channels\n");
return dev_err_probe(dev, -ENODEV, "no available PWM channels\n");
spc->num_pwms = i;
return 0;
return i;
}
static int sprd_pwm_probe(struct platform_device *pdev)
{
struct sprd_pwm_chip *spc;
int ret;
struct sprd_pwm_chn chn[SPRD_PWM_CHN_NUM];
int ret, npwm;
npwm = sprd_pwm_clk_init(&pdev->dev, chn);
if (npwm < 0)
return npwm;
spc = devm_kzalloc(&pdev->dev, sizeof(*spc), GFP_KERNEL);
if (!spc)
......@@ -264,14 +266,11 @@ static int sprd_pwm_probe(struct platform_device *pdev)
return PTR_ERR(spc->base);
spc->dev = &pdev->dev;
ret = sprd_pwm_clk_init(spc);
if (ret)
return ret;
memcpy(spc->chn, chn, sizeof(chn));
spc->chip.dev = &pdev->dev;
spc->chip.ops = &sprd_pwm_ops;
spc->chip.npwm = spc->num_pwms;
spc->chip.npwm = npwm;
ret = devm_pwmchip_add(&pdev->dev, &spc->chip);
if (ret)
......
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