Commit 896c4509 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Thierry Reding

pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe()

Using devm_pwmchip_add() allows to drop pwmchip_remove() from the remove
function which makes this function empty. Then there is no user of
drvdata left and platform_set_drvdata() can be dropped, too.

Further simplify and improve error returning using dev_err_probe().

Link: https://lore.kernel.org/r/20230929161918.2410424-12-u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent 9608405b
...@@ -265,10 +265,8 @@ static int cros_ec_pwm_probe(struct platform_device *pdev) ...@@ -265,10 +265,8 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
struct pwm_chip *chip; struct pwm_chip *chip;
int ret; int ret;
if (!ec) { if (!ec)
dev_err(dev, "no parent EC device\n"); return dev_err_probe(dev, -EINVAL, "no parent EC device\n");
return -EINVAL;
}
ec_pwm = devm_kzalloc(dev, sizeof(*ec_pwm), GFP_KERNEL); ec_pwm = devm_kzalloc(dev, sizeof(*ec_pwm), GFP_KERNEL);
if (!ec_pwm) if (!ec_pwm)
...@@ -289,10 +287,8 @@ static int cros_ec_pwm_probe(struct platform_device *pdev) ...@@ -289,10 +287,8 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
chip->npwm = CROS_EC_PWM_DT_COUNT; chip->npwm = CROS_EC_PWM_DT_COUNT;
} else { } else {
ret = cros_ec_num_pwms(ec_pwm); ret = cros_ec_num_pwms(ec_pwm);
if (ret < 0) { if (ret < 0)
dev_err(dev, "Couldn't find PWMs: %d\n", ret); return dev_err_probe(dev, ret, "Couldn't find PWMs\n");
return ret;
}
chip->npwm = ret; chip->npwm = ret;
} }
...@@ -303,23 +299,11 @@ static int cros_ec_pwm_probe(struct platform_device *pdev) ...@@ -303,23 +299,11 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
dev_dbg(dev, "Probed %u PWMs\n", chip->npwm); dev_dbg(dev, "Probed %u PWMs\n", chip->npwm);
ret = pwmchip_add(chip); ret = devm_pwmchip_add(dev, chip);
if (ret < 0) { if (ret < 0)
dev_err(dev, "cannot register PWM: %d\n", ret); return dev_err_probe(dev, ret, "cannot register PWM\n");
return ret;
}
platform_set_drvdata(pdev, ec_pwm);
return ret;
}
static void cros_ec_pwm_remove(struct platform_device *dev)
{
struct cros_ec_pwm_device *ec_pwm = platform_get_drvdata(dev);
struct pwm_chip *chip = &ec_pwm->chip;
pwmchip_remove(chip); return 0;
} }
#ifdef CONFIG_OF #ifdef CONFIG_OF
...@@ -333,7 +317,6 @@ MODULE_DEVICE_TABLE(of, cros_ec_pwm_of_match); ...@@ -333,7 +317,6 @@ MODULE_DEVICE_TABLE(of, cros_ec_pwm_of_match);
static struct platform_driver cros_ec_pwm_driver = { static struct platform_driver cros_ec_pwm_driver = {
.probe = cros_ec_pwm_probe, .probe = cros_ec_pwm_probe,
.remove_new = cros_ec_pwm_remove,
.driver = { .driver = {
.name = "cros-ec-pwm", .name = "cros-ec-pwm",
.of_match_table = of_match_ptr(cros_ec_pwm_of_match), .of_match_table = of_match_ptr(cros_ec_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