From patchwork Wed Dec 6 11:43:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 750898 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B288B112 for ; Wed, 6 Dec 2023 03:48:30 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rAqO6-0005yl-Dx; Wed, 06 Dec 2023 12:48:22 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rAqO5-00Dwrd-IN; Wed, 06 Dec 2023 12:48:21 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1rAqO5-00FQwl-8y; Wed, 06 Dec 2023 12:48:21 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Thierry Reding Cc: kernel@pengutronix.de, Pavel Machek , Lee Jones , Jernej Skrabec , Anjelique Melendez , Luca Weiss , Lu Hongfei , Kees Cook , linux-leds@vger.kernel.org Subject: [PATCH v4 005/115] leds: qcom-lpg: Introduce a wrapper for getting driver data from a pwm chip Date: Wed, 6 Dec 2023 12:43:19 +0100 Message-ID: <4785982785812615d15c7dd6d2755270bd8670b2.1701860672.git.u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1897; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=UvHPvfzK4zu0qj3NueYMF9QiGggoolwYvSZ0Joyq9Ow=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlcF5XMttrmsVQY3Yx7JgC/P63fCv4AbvN2VPAc 9dR8f+l/tSJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZXBeVwAKCRCPgPtYfRL+ TlBJB/9n8hJsGTVNWNgb4XnXNUvkwoYr/zPYpWuYGs2QMywhFsHa1SlyfndQGafWbRWf5Io9flL PJs7vxsyH0/gnd7SAiUxLaHJ8QanV609ZhXVsMkxNeMvEZGj6pKTW//XeqwjeoJ6ebBBl4QvZ4Q Lex1wiQBqLdhuhYDVuL1oVeA2leeRaNA9kzMhGpkWU4xK2ErSKdc3m2p3EQGrG9WMrlZ3cvHfmt 5kFZA36sutBsXPxUL8xbWtJ8m8sAukyWveme0THCEWpDgE1x3sXCe1qwNH9LQa5ZyFYWhjrtTC6 DaQJN+RyvxGbdATHsKEUglBMXOioX2mWzfNSAYwfSrmURG0T X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-leds@vger.kernel.org Signed-off-by: Uwe Kleine-König Acked-by: Lee Jones --- Note this patch was already sent out individually, find it at https://lore.kernel.org/linux-leds/20231124215208.616551-3-u.kleine-koenig@pengutronix.de drivers/leds/rgb/leds-qcom-lpg.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c index 54c90ee43ef8..156b73d1f4a2 100644 --- a/drivers/leds/rgb/leds-qcom-lpg.c +++ b/drivers/leds/rgb/leds-qcom-lpg.c @@ -976,9 +976,14 @@ static int lpg_pattern_mc_clear(struct led_classdev *cdev) return lpg_pattern_clear(led); } +static inline struct lpg *lpg_pwm_from_chip(struct pwm_chip *chip) +{ + return container_of(chip, struct lpg, pwm); +} + static int lpg_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) { - struct lpg *lpg = container_of(chip, struct lpg, pwm); + struct lpg *lpg = lpg_pwm_from_chip(chip); struct lpg_channel *chan = &lpg->channels[pwm->hwpwm]; return chan->in_use ? -EBUSY : 0; @@ -994,7 +999,7 @@ static int lpg_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) static int lpg_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) { - struct lpg *lpg = container_of(chip, struct lpg, pwm); + struct lpg *lpg = lpg_pwm_from_chip(chip); struct lpg_channel *chan = &lpg->channels[pwm->hwpwm]; int ret = 0; @@ -1025,7 +1030,7 @@ static int lpg_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, static int lpg_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) { - struct lpg *lpg = container_of(chip, struct lpg, pwm); + struct lpg *lpg = lpg_pwm_from_chip(chip); struct lpg_channel *chan = &lpg->channels[pwm->hwpwm]; unsigned int resolution; unsigned int pre_div; From patchwork Wed Dec 6 11:45:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 750897 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FBAFD45 for ; Wed, 6 Dec 2023 03:48:51 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rAqOP-0007j6-NI; Wed, 06 Dec 2023 12:48:41 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rAqON-00DwyB-QH; Wed, 06 Dec 2023 12:48:39 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1rAqON-00FR3e-Gt; Wed, 06 Dec 2023 12:48:39 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Thierry Reding Cc: kernel@pengutronix.de, Pavel Machek , Lee Jones , Conor Dooley , Anjelique Melendez , Rob Herring , Bjorn Andersson , Kees Cook , Luca Weiss , linux-leds@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v4 108/115] leds: qcom-lpg: Make use of devm_pwmchip_alloc() function Date: Wed, 6 Dec 2023 12:45:02 +0100 Message-ID: <60605623e9e41d6f4b25e9c0eaf09d99bbc825f2.1701860672.git.u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1692; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=pvhY4Y0JLdiqVhBwOjMIbLiR5NL0oEVp+2u1SCdBGyk=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlcF9X2vmR/YE9bA6uWt931rHgfeSo8ftDHS2tD 7l9+gb7i9OJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZXBfVwAKCRCPgPtYfRL+ TrqiB/45axpfyNtYf+7C1G/VIJWVX/ii239LT4Fp4h0AhOHiWH0JfGRchNca4IVSz6ykrreNp7q x3ZBzmIguPHrXbLIB2nEVhmTsHk2020lq8gfm7ztUtDoFVzsRK5E9kyf+TEemf5shzdLiU3n8YN 0pkRP3FmQq9XYn7RU8nyuC2gv+vhZu438vqJ0X7h7CiUXmOrU9guhYVPSB/rRLyuRXLRfsePW7Y 66gCrvTa34U9LNE/E8axYBqv6XWSZVe4JfahnuZ0rU7Ota1Z2aVy6sPgvvrINubhVnXMH9LMMHd dM9UbNF+GYD79neO6yszxU9Rv0TnvLBObXXliwxgRSFtGAMW X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-leds@vger.kernel.org This prepares the pwm sub-driver to further changes of the pwm core outlined in the commit introducing devm_pwmchip_alloc(). There is no intended semantical change and the driver should behave as before. Signed-off-by: Uwe Kleine-König --- drivers/leds/rgb/leds-qcom-lpg.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c index 156b73d1f4a2..0a7acf59a420 100644 --- a/drivers/leds/rgb/leds-qcom-lpg.c +++ b/drivers/leds/rgb/leds-qcom-lpg.c @@ -77,7 +77,7 @@ struct lpg { struct mutex lock; - struct pwm_chip pwm; + struct pwm_chip *pwm; const struct lpg_data *data; @@ -978,7 +978,7 @@ static int lpg_pattern_mc_clear(struct led_classdev *cdev) static inline struct lpg *lpg_pwm_from_chip(struct pwm_chip *chip) { - return container_of(chip, struct lpg, pwm); + return pwmchip_get_drvdata(chip); } static int lpg_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) @@ -1093,13 +1093,17 @@ static const struct pwm_ops lpg_pwm_ops = { static int lpg_add_pwm(struct lpg *lpg) { + struct pwm_chip *chip; int ret; - lpg->pwm.dev = lpg->dev; - lpg->pwm.npwm = lpg->num_channels; - lpg->pwm.ops = &lpg_pwm_ops; + lpg->pwm = chip = devm_pwmchip_alloc(lpg->dev, lpg->num_channels, 0); + if (IS_ERR(chip)) + return PTR_ERR(chip); - ret = devm_pwmchip_add(lpg->dev, &lpg->pwm); + chip->ops = &lpg_pwm_ops; + pwmchip_set_drvdata(chip, lpg); + + ret = devm_pwmchip_add(lpg->dev, chip); if (ret) dev_err_probe(lpg->dev, ret, "failed to add PWM chip\n");