Commit 3025c9c6 authored by Uwe Kleine-König's avatar Uwe Kleine-König

pwm: sti: Improve error reporting using dev_err_probe()

This has the advantage of handling EPROBE_DEFER correctly and being more
compact.

This change also introduces an error message for a few error paths that
lacked an error indicator before. Also sti_pwm_probe_dt() is renamed to
sti_pwm_probe_regmap() to better fit what it actually does.

Link: https://lore.kernel.org/r/8e540733ab882f2b8873712faf85c4f0cb48133a.1710068192.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent 5bb0b194
...@@ -502,7 +502,7 @@ static irqreturn_t sti_pwm_interrupt(int irq, void *data) ...@@ -502,7 +502,7 @@ static irqreturn_t sti_pwm_interrupt(int irq, void *data)
return ret; return ret;
} }
static int sti_pwm_probe_dt(struct sti_pwm_chip *pc) static int sti_pwm_probe_regmap(struct sti_pwm_chip *pc)
{ {
struct device *dev = pc->dev; struct device *dev = pc->dev;
const struct reg_field *reg_fields; const struct reg_field *reg_fields;
...@@ -570,10 +570,8 @@ static int sti_pwm_probe(struct platform_device *pdev) ...@@ -570,10 +570,8 @@ static int sti_pwm_probe(struct platform_device *pdev)
if (!ret) if (!ret)
cpt_num_devs = num_devs; cpt_num_devs = num_devs;
if (!pwm_num_devs && !cpt_num_devs) { if (!pwm_num_devs && !cpt_num_devs)
dev_err(dev, "No channels configured\n"); return dev_err_probe(dev, -EINVAL, "No channels configured\n");
return -EINVAL;
}
chip = devm_pwmchip_alloc(dev, max(pwm_num_devs, cpt_num_devs), sizeof(*pc)); chip = devm_pwmchip_alloc(dev, max(pwm_num_devs, cpt_num_devs), sizeof(*pc));
if (IS_ERR(chip)) if (IS_ERR(chip))
...@@ -591,7 +589,8 @@ static int sti_pwm_probe(struct platform_device *pdev) ...@@ -591,7 +589,8 @@ static int sti_pwm_probe(struct platform_device *pdev)
pc->regmap = devm_regmap_init_mmio(dev, pc->mmio, pc->regmap = devm_regmap_init_mmio(dev, pc->mmio,
&sti_pwm_regmap_config); &sti_pwm_regmap_config);
if (IS_ERR(pc->regmap)) if (IS_ERR(pc->regmap))
return PTR_ERR(pc->regmap); return dev_err_probe(dev, PTR_ERR(pc->regmap),
"Failed to initialize regmap\n");
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) if (irq < 0)
...@@ -599,10 +598,8 @@ static int sti_pwm_probe(struct platform_device *pdev) ...@@ -599,10 +598,8 @@ static int sti_pwm_probe(struct platform_device *pdev)
ret = devm_request_irq(&pdev->dev, irq, sti_pwm_interrupt, 0, ret = devm_request_irq(&pdev->dev, irq, sti_pwm_interrupt, 0,
pdev->name, pc); pdev->name, pc);
if (ret < 0) { if (ret < 0)
dev_err(&pdev->dev, "Failed to request IRQ\n"); dev_err_probe(&pdev->dev, ret, "Failed to request IRQ\n");
return ret;
}
/* /*
* Setup PWM data with default values: some values could be replaced * Setup PWM data with default values: some values could be replaced
...@@ -619,24 +616,22 @@ static int sti_pwm_probe(struct platform_device *pdev) ...@@ -619,24 +616,22 @@ static int sti_pwm_probe(struct platform_device *pdev)
pc->en_count = 0; pc->en_count = 0;
mutex_init(&pc->sti_pwm_lock); mutex_init(&pc->sti_pwm_lock);
ret = sti_pwm_probe_dt(pc); ret = sti_pwm_probe_regmap(pc);
if (ret) if (ret)
return ret; return dev_err_probe(dev, ret, "Failed to initialize regmap fields\n");
if (cdata->pwm_num_devs) { if (cdata->pwm_num_devs) {
pc->pwm_clk = devm_clk_get_prepared(dev, "pwm"); pc->pwm_clk = devm_clk_get_prepared(dev, "pwm");
if (IS_ERR(pc->pwm_clk)) { if (IS_ERR(pc->pwm_clk))
dev_err(dev, "failed to get PWM clock\n"); return dev_err_probe(dev, PTR_ERR(pc->pwm_clk),
return PTR_ERR(pc->pwm_clk); "failed to get PWM clock\n");
}
} }
if (cdata->cpt_num_devs) { if (cdata->cpt_num_devs) {
pc->cpt_clk = devm_clk_get_prepared(dev, "capture"); pc->cpt_clk = devm_clk_get_prepared(dev, "capture");
if (IS_ERR(pc->cpt_clk)) { if (IS_ERR(pc->cpt_clk))
dev_err(dev, "failed to get PWM capture clock\n"); return dev_err_probe(dev, PTR_ERR(pc->cpt_clk),
return PTR_ERR(pc->cpt_clk); "failed to get PWM capture clock\n");
}
cdata->ddata = devm_kzalloc(dev, cdata->cpt_num_devs * sizeof(*cdata->ddata), GFP_KERNEL); cdata->ddata = devm_kzalloc(dev, cdata->cpt_num_devs * sizeof(*cdata->ddata), GFP_KERNEL);
if (!cdata->ddata) if (!cdata->ddata)
...@@ -652,7 +647,11 @@ static int sti_pwm_probe(struct platform_device *pdev) ...@@ -652,7 +647,11 @@ static int sti_pwm_probe(struct platform_device *pdev)
mutex_init(&ddata->lock); mutex_init(&ddata->lock);
} }
return devm_pwmchip_add(dev, chip); ret = devm_pwmchip_add(dev, chip);
if (ret)
return dev_err_probe(dev, ret, "Failed to register pwm chip\n");
return 0;
} }
static const struct of_device_id sti_pwm_of_match[] = { static const struct of_device_id sti_pwm_of_match[] = {
......
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