diff mbox series

[5.10.y-cip,07/13] pwm: Add a device-managed function to add PWM chips

Message ID 20230718140608.119449-8-biju.das.jz@bp.renesas.com (mailing list archive)
State Superseded
Headers show
Series Add RZ/{G2L,G2LC,V2L} MTU3 support. | expand

Commit Message

Biju Das July 18, 2023, 2:06 p.m. UTC
From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

commit bcda91bf86c1ff7647df85029d69f2aed80f210e upstream.

This potentially simplifies low-level PWM drivers.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/pwm/core.c  | 19 +++++++++++++++++++
 include/linux/pwm.h |  3 +++
 2 files changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 1f16f5365d3c..4817df38086b 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -383,6 +383,25 @@  int pwmchip_remove(struct pwm_chip *chip)
 }
 EXPORT_SYMBOL_GPL(pwmchip_remove);
 
+static void devm_pwmchip_remove(void *data)
+{
+	struct pwm_chip *chip = data;
+
+	pwmchip_remove(chip);
+}
+
+int devm_pwmchip_add(struct device *dev, struct pwm_chip *chip)
+{
+	int ret;
+
+	ret = pwmchip_add(chip);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, devm_pwmchip_remove, chip);
+}
+EXPORT_SYMBOL_GPL(devm_pwmchip_add);
+
 /**
  * pwm_request() - request a PWM device
  * @pwm: global PWM device index
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index a13ff383fa1d..a28b3e1e50b9 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -396,6 +396,9 @@  int pwmchip_add_with_polarity(struct pwm_chip *chip,
 			      enum pwm_polarity polarity);
 int pwmchip_add(struct pwm_chip *chip);
 int pwmchip_remove(struct pwm_chip *chip);
+
+int devm_pwmchip_add(struct device *dev, struct pwm_chip *chip);
+
 struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
 					 unsigned int index,
 					 const char *label);