From patchwork Tue Jul 18 14:06:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13317336 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3D4AC0015E for ; Tue, 18 Jul 2023 14:06:29 +0000 (UTC) Received: from relmlie5.idc.renesas.com (relmlie5.idc.renesas.com [210.160.252.171]) by mx.groups.io with SMTP id smtpd.web11.8427.1689689188746596640 for ; Tue, 18 Jul 2023 07:06:28 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: bp.renesas.com, ip: 210.160.252.171, mailfrom: biju.das.jz@bp.renesas.com) X-IronPort-AV: E=Sophos;i="6.01,214,1684767600"; d="scan'208";a="169767880" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 18 Jul 2023 23:06:27 +0900 Received: from localhost.localdomain (unknown [10.226.92.137]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 7CB8B42167F6; Tue, 18 Jul 2023 23:06:25 +0900 (JST) From: Biju Das To: cip-dev@lists.cip-project.org, Nobuhiro Iwamatsu , Pavel Machek Cc: Biju Das , Fabrizio Castro Subject: [PATCH 5.10.y-cip 07/13] pwm: Add a device-managed function to add PWM chips Date: Tue, 18 Jul 2023 15:06:02 +0100 Message-Id: <20230718140608.119449-8-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230718140608.119449-1-biju.das.jz@bp.renesas.com> References: <20230718140608.119449-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 18 Jul 2023 14:06:29 -0000 X-Groupsio-URL: https://lists.cip-project.org/g/cip-dev/message/12384 From: Uwe Kleine-König commit bcda91bf86c1ff7647df85029d69f2aed80f210e upstream. This potentially simplifies low-level PWM drivers. Signed-off-by: Uwe Kleine-König Signed-off-by: Thierry Reding Signed-off-by: Biju Das --- drivers/pwm/core.c | 19 +++++++++++++++++++ include/linux/pwm.h | 3 +++ 2 files changed, 22 insertions(+) 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);