From patchwork Thu Jan 25 12:08:25 2024 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: 13530851 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31C79C48260 for ; Thu, 25 Jan 2024 13:55:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=F49QszODc/AnLpGtuh+ZigTtyyoue0kZnTQSbluFtHw=; b=eIRePVeMPjr2Nm oSvIvQkAjQhmAvO6XT49Og3IL0qjhVWHzyU0K1oHMJ0W/RJCw8eUIHgjYobqyYy2QNQdEClxBrZIV lM/hBAQ9n3ML3/0pUk3ZOz7GEGoOUg+sPIgXNGYv4orZMuSV4qb42hzm62+mVmO13w/WbsUVhoLxh GHymWqQJ71LBSEjZaEg2LiiifryWYZ0n+U17OMGXcZqADp4oF0mJ7OMWsfxyYPZjAkKsAW+0tFDZ7 S0I3VbG/Zw9d2/PeildgOLZuggBObyc03XJUGkA+rum+hsEMRsb2EQCdXBBIVAMe1t753ElA1HYSh gIkN2kKSFvSHJk0PgK1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT0C1-000000009pJ-3Hev; Thu, 25 Jan 2024 13:54:57 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT0Bz-000000009oP-31Bs for linux-amlogic@bombadil.infradead.org; Thu, 25 Jan 2024 13:54:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=DooyQrtizpQPYQvg3orF2s8x816HvpICh5L6Gs5NXqE=; b=kUUuQF4zYvYcU0/pHTfUBJZhk5 2xmvbu5K/Tq/xSZ0dOmFXWWtrFNhbjlfEtXkLqXT1ysyKxNt3yH5umPlgVCNlEM00/NztWxEXEVzL lkDB+Ev4XKo5lpgFj2ndcOdr3aIxP/hgPDNbbrFB6dshvHzUELceb0440cSZR20pnQF1sjL5ua6zx lvqmDqmf4FKEdwGS8lGnS9erLaz5YehaZr74giogBTLBtFbGDe0aDSPG34nyWdHyXGwelN+k+WxiV nGm1QlKXi59H28MtzG/vcvCX4EM9lMgWQkBw/oF6rEKWrKSx/tPAE2WfhwiKvUPoXVdmqUDyBu8E5 i8GhkyCw==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rSybt-00000005HqI-3iCf for linux-amlogic@lists.infradead.org; Thu, 25 Jan 2024 12:13:35 +0000 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 1rSyZB-0003Ze-Mz; Thu, 25 Jan 2024 13:10:45 +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 1rSyZ6-002HOt-Gy; Thu, 25 Jan 2024 13:10:40 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rSyZ6-007myG-1E; Thu, 25 Jan 2024 13:10:40 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: linux-pwm@vger.kernel.org, Claudiu Beznea , Nicolas Ferre , Alexandre Belloni , Florian Fainelli , Ray Jui , Scott Branden , Benson Leung , Shawn Guo , Sascha Hauer , Paul Cercueil , Matthias Brugger , AngeloGioacchino Del Regno , Neil Armstrong , Kevin Hilman , Krzysztof Kozlowski , Palmer Dabbelt , Paul Walmsley , Fabrice Gasnier , Maxime Coquelin , Alexandre Torgue , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andrzej Hajda , Robert Foss , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Johan Hovold , Alex Elder , Greg Kroah-Hartman Cc: kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, Broadcom internal kernel review list , Guenter Roeck , chrome-platform@lists.linux.dev, Fabio Estevam , NXP Linux Team , linux-mips@vger.kernel.org, linux-mediatek@lists.infradead.org, Jerome Brunet , Martin Blumenstingl , linux-amlogic@lists.infradead.org, linux-rpi-kernel@lists.infradead.org, Alim Akhtar , linux-samsung-soc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev, Douglas Anderson , Laurent Pinchart , Jonas Karlman , dri-devel@lists.freedesktop.org, greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev Subject: [PATCH v5 003/111] pwm: Provide a macro to get the parent device of a given chip Date: Thu, 25 Jan 2024 13:08:25 +0100 Message-ID: <1cae6f73264ab313205eaa9483251f7aaf259cb4.1706182805.git.u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=988; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=SfOslAbsyBLEr/955V0luBriAR1MBuqlRLojueDMWPA=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlsk89sMCb69Ns1+4RognQQiOh0kwtwTRgZqZe7 Qr1BL64ZR+JATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZbJPPQAKCRCPgPtYfRL+ Tm5ICACqUZnuAnSjFfXrvBpLBI7tlj8WA+HQMKQ6Zc+N4XX6ETnakaKJsM+x6j+q4etOxq2c/gZ zxT7BpN14RbPiCl4D8hdIHJMFSxpOXgFMhHn6G0CiQZKij7FYNQcIit0BAKORd4VGZ3VwABrQ/Y OjjIIjxHWR1qdMK2N2kNbFpbTf4/2PRkxMHdXTJcAMAnSGWqM6H23gUlqytwn6NbEab8dDUgmkC dj7M9Z8Ubq9AofnoudLfMHIY54wLfZ0PkykBosZOeOLWLjqyM0qMfK6/MVn1CgVUVr75LWffVka lOK3tBDX44i4Xzm74nXYI2dfx77u3aY3K3mXE4UoCo8Z6Cl7 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-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_121333_971981_A40BC9D0 X-CRM114-Status: GOOD ( 13.33 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org Currently a pwm_chip stores in its struct device *dev member a pointer to the parent device. Preparing a change that embeds a full struct device in struct pwm_chip, this accessor macro should be used in all drivers directly accessing chip->dev now. This way struct pwm_chip and this macro can be changed without having to touch all drivers in the same change set. Signed-off-by: Uwe Kleine-König Reviewed-by: AngeloGioacchino Del Regno --- include/linux/pwm.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 8ffe9ae7a23a..d7966918f301 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -289,6 +289,11 @@ struct pwm_chip { struct pwm_device *pwms; }; +static inline struct device *pwmchip_parent(struct pwm_chip *chip) +{ + return chip->dev; +} + #if IS_ENABLED(CONFIG_PWM) /* PWM user APIs */ int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state); From patchwork Thu Jan 25 12:08:41 2024 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: 13530839 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1DE2C48285 for ; Thu, 25 Jan 2024 13:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kT+pVeBtcInoz9JK+DeSi/B3xZoWkSdO7gMxJNMqwxQ=; b=pFdwDZT+XYT7F0 y069DlTdlKZEyyWxoBiUf4r15ZYGEbl8IHsbUnVxUrANKozo8lLuIFEKEdZd70BJTEaQoFWX0jhuZ K4gMV8Ho3eSCPSr6PvvYaqSl9aAIa4u+qYSMUADk2O5UkUjP8tfWyejp5Zsq2e8PxHDr8xA+F5NPQ m2TNq/U+Hm5CM2ODbpgRlLflwO5nYmb/GHUt5rLrbyjD98/YV3mu0Clal7lCQQWyGk1sH3Sd9W5RO sYqgsrQ7S+c4kgU+zPaOhbC5tuzXp2lUPF1uzMO6UqDFcCOrSPlJ6rZvXREhEFLf/Atea5Yibzr25 71MKJQGs209BX4dx5o9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT07e-000000008Ac-0Tn3; Thu, 25 Jan 2024 13:50:26 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT07Y-0000000086o-03Xu for linux-amlogic@bombadil.infradead.org; Thu, 25 Jan 2024 13:50:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=TGAZAvuxvzR0Z6dpggwwsh9bgXH1N7rswlHIcwoZm74=; b=Xt+zpJplSgW8ajvWKxZv3244fo 2gnFPMfgotPCKBHyG8ZxzSRa8tgA1Jg2L8/QRqxEPK8Awd9Mfzy+OMpATVTbdKZIVzaoCA0Sl2/Uf cNYuUYiWcFEdDufyBnOUx2ENJdUXxqCq3SKZ6iOcoLZ/MKWP9gM1oueXNIIRQKRzsIVT+jfDNNWLL x3bYjkqI3Q/Bx30KC85yWfnGZ5xxHdWS0Ea7nPL0P+/j35FhwBzNyeR20kVKpnfsVgQTTcvxHGHB9 imggJvuh865x5j4TnOySponVbbW8hXS2j3K/voUNZtuJn6uXVwM1tJ9DF2ewgwWQ2tqO+ZecmaqYx HKyLUWTg==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rSybQ-00000005Hfz-1OKb for linux-amlogic@lists.infradead.org; Thu, 25 Jan 2024 12:13:07 +0000 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 1rSyZA-0003j5-0T; Thu, 25 Jan 2024 13:10:44 +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 1rSyZ9-002HPu-Jh; Thu, 25 Jan 2024 13:10:43 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rSyZ9-007mzN-1i; Thu, 25 Jan 2024 13:10:43 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Neil Armstrong , Kevin Hilman , linux-pwm@vger.kernel.org Cc: Jerome Brunet , Martin Blumenstingl , linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, kernel@pengutronix.de Subject: [PATCH v5 019/111] pwm: meson: Make use of pwmchip_parent() macro Date: Thu, 25 Jan 2024 13:08:41 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5214; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=R+qmHnPJHXiOMTExINSGoYHhLOryMHBoLVU0lUzmjkM=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlsk9PZruxaLIqpTlyQIEgdXq4dp7BHpKxf+JAt 0X9o0tM8CiJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZbJPTwAKCRCPgPtYfRL+ Tp6IB/42RtqLmGDC00nfkrEoDG7kY5jWJL+kPhKnNq4MuFDAs4GyGLD1q3Wlo3D1/w70bl3TQCA L97ik+Mf61dx517Ph/TE6ZyUcZb2YQTAWcJq0IU9qkoAc93Kn1gT4AoqVCITKhvuxrWqgVc9VqY 1Sw6R+0d2wBjxEylRvDLifeMXmy21kx0fCQfaIcOssNHDTj8x9f50yDwPgyY4oujfL+vgBp/EhI VI9T7o5r9I8DJyUUdqu8+MMQ7bwq/PoYU/Jz1bTPsZw2leiEMTANRlUFThVuIynOejUY9Dwmo36 eR1Wyu6xstLJrwSr4e4VkkYkuAZyC8Q/B0YOESOqJSNVGdjM 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-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_121304_481727_57E499CA X-CRM114-Status: GOOD ( 16.38 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org struct pwm_chip::dev is about to change. To not have to touch this driver in the same commit as struct pwm_chip::dev, use the macro provided for exactly this purpose. Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-meson.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 2971bbf3b5e7..dd0e18437be9 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -122,7 +122,7 @@ static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) { struct meson_pwm *meson = to_meson_pwm(chip); struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; - struct device *dev = chip->dev; + struct device *dev = pwmchip_parent(chip); int err; err = clk_prepare_enable(channel->clk); @@ -143,9 +143,10 @@ static void meson_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) clk_disable_unprepare(channel->clk); } -static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, +static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) { + struct meson_pwm *meson = to_meson_pwm(chip); struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; unsigned int cnt, duty_cnt; unsigned long fin_freq; @@ -169,19 +170,19 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, fin_freq = clk_round_rate(channel->clk, freq); if (fin_freq == 0) { - dev_err(meson->chip.dev, "invalid source clock frequency\n"); + dev_err(pwmchip_parent(chip), "invalid source clock frequency\n"); return -EINVAL; } - dev_dbg(meson->chip.dev, "fin_freq: %lu Hz\n", fin_freq); + dev_dbg(pwmchip_parent(chip), "fin_freq: %lu Hz\n", fin_freq); cnt = div_u64(fin_freq * period, NSEC_PER_SEC); if (cnt > 0xffff) { - dev_err(meson->chip.dev, "unable to get period cnt\n"); + dev_err(pwmchip_parent(chip), "unable to get period cnt\n"); return -EINVAL; } - dev_dbg(meson->chip.dev, "period=%llu cnt=%u\n", period, cnt); + dev_dbg(pwmchip_parent(chip), "period=%llu cnt=%u\n", period, cnt); if (duty == period) { channel->hi = cnt; @@ -192,7 +193,7 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, } else { duty_cnt = div_u64(fin_freq * duty, NSEC_PER_SEC); - dev_dbg(meson->chip.dev, "duty=%llu duty_cnt=%u\n", duty, duty_cnt); + dev_dbg(pwmchip_parent(chip), "duty=%llu duty_cnt=%u\n", duty, duty_cnt); channel->hi = duty_cnt; channel->lo = cnt - duty_cnt; @@ -203,8 +204,9 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, return 0; } -static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) +static void meson_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) { + struct meson_pwm *meson = to_meson_pwm(chip); struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; struct meson_pwm_channel_data *channel_data; unsigned long flags; @@ -215,7 +217,7 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) err = clk_set_rate(channel->clk, channel->rate); if (err) - dev_err(meson->chip.dev, "setting clock rate failed\n"); + dev_err(pwmchip_parent(chip), "setting clock rate failed\n"); spin_lock_irqsave(&meson->lock, flags); @@ -230,8 +232,9 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) spin_unlock_irqrestore(&meson->lock, flags); } -static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm) +static void meson_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) { + struct meson_pwm *meson = to_meson_pwm(chip); unsigned long flags; u32 value; @@ -269,16 +272,16 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, channel->hi = ~0; channel->lo = 0; - meson_pwm_enable(meson, pwm); + meson_pwm_enable(chip, pwm); } else { - meson_pwm_disable(meson, pwm); + meson_pwm_disable(chip, pwm); } } else { - err = meson_pwm_calc(meson, pwm, state); + err = meson_pwm_calc(chip, pwm, state); if (err < 0) return err; - meson_pwm_enable(meson, pwm); + meson_pwm_enable(chip, pwm); } return 0; @@ -432,10 +435,11 @@ static const struct of_device_id meson_pwm_matches[] = { }; MODULE_DEVICE_TABLE(of, meson_pwm_matches); -static int meson_pwm_init_channels(struct meson_pwm *meson) +static int meson_pwm_init_channels(struct pwm_chip *chip) { + struct meson_pwm *meson = to_meson_pwm(chip); struct clk_parent_data mux_parent_data[MESON_MAX_MUX_PARENTS] = {}; - struct device *dev = meson->chip.dev; + struct device *dev = pwmchip_parent(chip); unsigned int i; char name[255]; int err; @@ -543,7 +547,7 @@ static int meson_pwm_probe(struct platform_device *pdev) meson->data = of_device_get_match_data(&pdev->dev); - err = meson_pwm_init_channels(meson); + err = meson_pwm_init_channels(&meson->chip); if (err < 0) return err; From patchwork Thu Jan 25 12:09:01 2024 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: 13530884 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6E9BC48260 for ; Thu, 25 Jan 2024 14:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AMY6d4VeMjdFyyx/XSN4yNzXm/lz0U7+kmlvtJQlAOA=; b=bLvISm4e+InDTi rmnjaaMLiUgStm6XDf5FHseDdeFd42XyS2KTTH+ZZWj0NYUiBVtuFWS3ZHt6EwKL0WvbTskd0BYSt h83KwwGO7PpSE7EgaTvHfEG2/KZeyRZqPDAzM7/p0V0ApuLMhvVsmwLsDA567D8QodlVP3RieTwKR jAK/TKFOJOAJVS+nuyPdfGxRVijDPLDAqRIWQD/DRQXXEMFtU5mkttP3Ks1NANlDOP3ajayer4BHv twmtvwNomOh/fnzEISzg5fvMTubkOy4ca8V1F8fH+AsG6J9b/pGtsVu+RqbeyfFCE+M1Ok5M6Q8Xy Th86XBz6xl+NBEPBr4QQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT0SM-00000000HZe-3jKS; Thu, 25 Jan 2024 14:11:50 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT0Rf-00000000H0g-3thX for linux-amlogic@bombadil.infradead.org; Thu, 25 Jan 2024 14:11:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=uzdazEjK7i6wQKTTtvn9MrsdfGievWnGtyE6FJBzIUQ=; b=abfGbK+SbiWIL1tkcqw+s9Dqph lBc8fbelEiPlRvnPpn5SNoBrxEhShBdLWdCTUxk6sQZxtGwfC0bU5QcuZZzFAazKJATO7Rx4CWILt 8cyKptGUSipdOcpPbxD5LwBj/utQJk8pb/4V2Mm5EWvY7VZXOinDb6PhE/JrVqfZ4g9RuTifm9tzG cGJszJ2NnLx0sxb4S3Jrw/qXpJLs7kmBna2FM4ohJISr35AgnyLkcd9LJHuvPO8oVg4YsKgIhg6RJ xyrcnEPpnvwbSAHf+iCNb4UrZvahtzAvPpddrOOZESZK8+PWJs0uStDslxlnX9nQVyCPEjAEERReD BkqsSRMQ==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rSycM-00000005Hvk-3ac4 for linux-amlogic@lists.infradead.org; Thu, 25 Jan 2024 12:14:06 +0000 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 1rSyZH-00048C-Nh; Thu, 25 Jan 2024 13:10:51 +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 1rSyZD-002HR8-To; Thu, 25 Jan 2024 13:10:47 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rSyZD-007n0k-2K; Thu, 25 Jan 2024 13:10:47 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: linux-pwm@vger.kernel.org, Hector Martin , Sven Peter , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Florian Fainelli , Ray Jui , Scott Branden , Alexander Shiyan , Benson Leung , Shawn Guo , Sascha Hauer , Paul Cercueil , Vladimir Zapolskiy , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Matthias Brugger , AngeloGioacchino Del Regno , Neil Armstrong , Kevin Hilman , Conor Dooley , Daire McNamara , =?utf-8?q?Jonathan_Neusch?= =?utf-8?q?=C3=A4fer?= , Heiko Stuebner , Krzysztof Kozlowski , Palmer Dabbelt , Paul Walmsley , Michael Walle , Orson Zhai , Baolin Wang , Chunyan Zhang , Fabrice Gasnier , Maxime Coquelin , Alexandre Torgue , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Hammer Hsieh , Thierry Reding , Jonathan Hunter , Nobuhiro Iwamatsu , Sean Anderson , Michal Simek , Linus Walleij , Bartosz Golaszewski , Andrzej Hajda , Robert Foss , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Pavel Machek , Lee Jones , Anjelique Melendez , Andi Shyti , Lu Hongfei , Bjorn Andersson , Luca Weiss , Johan Hovold , Alex Elder , Greg Kroah-Hartman Cc: kernel@pengutronix.de, Alyssa Rosenzweig , asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Broadcom internal kernel review list , linux-rpi-kernel@lists.infradead.org, Guenter Roeck , chrome-platform@lists.linux.dev, Fabio Estevam , NXP Linux Team , linux-mips@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-mediatek@lists.infradead.org, Jerome Brunet , Martin Blumenstingl , linux-amlogic@lists.infradead.org, linux-riscv@lists.infradead.org, linux-rockchip@lists.infradead.org, Alim Akhtar , linux-samsung-soc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-gpio@vger.kernel.org, Douglas Anderson , Laurent Pinchart , Jonas Karlman , dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org, greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev Subject: [PATCH v5 039/111] pwm: Provide wrappers for storing and getting driver private data Date: Thu, 25 Jan 2024 13:09:01 +0100 Message-ID: <1c873808bfc93ab51f49be799334dee6e8ab398a.1706182805.git.u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1920; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=xFZHrY/7C9PRNt99L0vl8g6j3yX1l4H0eIirFXKiC6s=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlsk9naZ43cfZqRmm0PAwRVRHazfdHqUBSCmiRl 7SkEynbJGKJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZbJPZwAKCRCPgPtYfRL+ TqyWB/0Xq9H2qxz5a4NBliO3W2OBOYrNCAIPS+YFIK+/psR+8hFCNvRcL8LkTcvrGhz+wH1p+Pb F64/cTSgbYddbvZjoDx1kSNtuKvpvYsZy3B/swnxRBzzhjM4qRl0nLRqI7tuxKsMoJ6KChrenmP ZHuoEbNaT3Jq0uJ3jCQX+OWAPfMUgSkbUr5A7m+b7JrBvE1+EcTZ0ltF9cqru7Gex1/GIk5STLR s4XqyNlr+QqQS2lKFYFTNPQKFohdM4YpL+GcQjYEZZG2zihg6J+r6Mx1mefplrODntBtd+WIXCL uGNCMjCbN1xcJ1N2Xx2QisJNxxGcBaZCqQD7Iqx5HLe1eACQ 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-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_121402_976481_0CF15600 X-CRM114-Status: GOOD ( 15.50 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org These functions are useful to store and query driver private data a After struct pwm_chip got its own struct device, this can make use of dev_get_drvdata() and dev_set_drvdata() on that device. These functions are required already now to convert drivers to pwmchip_alloc() which must happen before changing pwm_chip::dev. Signed-off-by: Uwe Kleine-König Reviewed-by: AngeloGioacchino Del Regno --- include/linux/pwm.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/pwm.h b/include/linux/pwm.h index d7966918f301..2c49d2fe2fe7 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -272,6 +272,7 @@ struct pwm_ops { * @npwm: number of PWMs controlled by this chip * @of_xlate: request a PWM device given a device tree PWM specifier * @atomic: can the driver's ->apply() be called in atomic context + * @driver_data: Private pointer for driver specific info * @pwms: array of PWM devices allocated by the framework */ struct pwm_chip { @@ -286,6 +287,7 @@ struct pwm_chip { bool atomic; /* only used internally by the PWM framework */ + void *driver_data; struct pwm_device *pwms; }; @@ -294,6 +296,24 @@ static inline struct device *pwmchip_parent(struct pwm_chip *chip) return chip->dev; } +static inline void *pwmchip_get_drvdata(struct pwm_chip *chip) +{ + /* + * After pwm_chip got a dedicated struct device, this can be replaced by + * dev_get_drvdata(&chip->dev); + */ + return chip->driver_data; +} + +static inline void pwmchip_set_drvdata(struct pwm_chip *chip, void *data) +{ + /* + * After pwm_chip got a dedicated struct device, this can be replaced by + * dev_set_drvdata(&chip->dev, data); + */ + chip->driver_data = data; +} + #if IS_ENABLED(CONFIG_PWM) /* PWM user APIs */ int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state); From patchwork Thu Jan 25 12:09:02 2024 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: 13569568 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF23CC54E4A for ; Fri, 23 Feb 2024 17:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IO8xlTw6e85SSpOBsPg7wZzVpYLXeQvHxUpB0Mts8Bo=; b=cAd+N0E7M0vMhK 0aGAqkAebenBmDI8IKgs8AlKuHBZpWSCI9T+u0uoBdFfL+zM1PDRSwsJgEDCaEEhIVxYaQvqn6d50 q0vRNe+AFwT47PnitGKZTwhb5KNoLEAeU2FZYuvftTONar75KJbjhoLkSIbhsG0Z0+MFzk1AsPREk FqOfAeEN44SppH2eG97L5PC31zTGbMoboobxhnK+En5Kd/Md4M1HUZJtfktyHTU41vxUr3f7c+GIM OvXjy7RWWHJgVRZZL3u4y2MIe20YLs7WZ8nxGZmYF0+eAp/rwAZiVh+UnjasqqhDPUoq1mVpHbmTM cEhGiktDF6XwYq9HLyug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdZ5G-0000000AOsp-1iNT; Fri, 23 Feb 2024 17:11:38 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT0Ob-00000000Evw-3eyp for linux-amlogic@bombadil.infradead.org; Thu, 25 Jan 2024 14:07:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=C6dz9YpfHmCugtCNf7g+GN9sHtNvRm2IMzaj5KwHZ1s=; b=dlOEfzRzoY0BTcaVGDzW7cVLaB PM9yPdpmxKOGXbJs4aj4EuQTJCuQdi/rqz0iPzVbnwPMpD+enMYP8tk5PiOyI3igLnNDeiS75Xu2J omJ/quUirmON1zukvCxdhxQof18MAmV9Wo6nMjMGy/W94+4vOxrbH4e2aXDUs8YLDoKdRvgprV6No 0yikSyljp7ax2xyrYMaCWkojNlbwxIgJiRQXPZd8z2mqZqZPHZPKn1i7dRAmJKYsR5Rk8XRGQveoq Jp+ZFbnieh3X42J2HFmVbG/OH7vaSmKrJBu8DbmR+mzWfwJoWQhvvKxfhfhTA4flbLR7YA2gPok3m HQcjHUoA==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rSycX-00000005HzE-1F8s for linux-amlogic@lists.infradead.org; Thu, 25 Jan 2024 12:14:15 +0000 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 1rSyZH-00049s-NK; Thu, 25 Jan 2024 13:10:51 +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 1rSyZE-002HRD-5b; Thu, 25 Jan 2024 13:10:48 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rSyZD-007n0n-33; Thu, 25 Jan 2024 13:10:47 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Jonathan Corbet , Greg Kroah-Hartman , Andy Shevchenko , Jonathan Cameron , Bjorn Helgaas , James Clark , linux-pwm@vger.kernel.org, Hector Martin , Sven Peter , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Florian Fainelli , Ray Jui , Scott Branden , Alexander Shiyan , Benson Leung , Shawn Guo , Sascha Hauer , Paul Cercueil , Vladimir Zapolskiy , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Matthias Brugger , AngeloGioacchino Del Regno , Neil Armstrong , Kevin Hilman , Conor Dooley , Daire McNamara , =?utf-8?q?Jonathan_Neusch?= =?utf-8?q?=C3=A4fer?= , Heiko Stuebner , Krzysztof Kozlowski , Palmer Dabbelt , Paul Walmsley , Michael Walle , Orson Zhai , Baolin Wang , Chunyan Zhang , Fabrice Gasnier , Maxime Coquelin , Alexandre Torgue , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Hammer Hsieh , Thierry Reding , Jonathan Hunter , Nobuhiro Iwamatsu , Sean Anderson , Michal Simek , Linus Walleij , Bartosz Golaszewski , Andrzej Hajda , Robert Foss , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Pavel Machek , Lee Jones , Anjelique Melendez , Andi Shyti , Lu Hongfei , Bjorn Andersson , Luca Weiss , Johan Hovold , Alex Elder Cc: linux-doc@vger.kernel.org, kernel@pengutronix.de, Alyssa Rosenzweig , asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Broadcom internal kernel review list , linux-rpi-kernel@lists.infradead.org, Guenter Roeck , chrome-platform@lists.linux.dev, Fabio Estevam , NXP Linux Team , linux-mips@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-mediatek@lists.infradead.org, Jerome Brunet , Martin Blumenstingl , linux-amlogic@lists.infradead.org, linux-riscv@lists.infradead.org, linux-rockchip@lists.infradead.org, Alim Akhtar , linux-samsung-soc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-gpio@vger.kernel.org, Douglas Anderson , Laurent Pinchart , Jonas Karlman , dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org, greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev Subject: [PATCH v5 040/111] pwm: Provide devm_pwmchip_alloc() function Date: Thu, 25 Jan 2024 13:09:02 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4472; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=Y70kt1S+wDMGZ2Y6dT7JBGkOh38DPB/mz0c9lW1w+go=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlsk9o1J7Qn6pSUgc2O5FQOVH47M2tNWcGfyzpg KqN39khZuCJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZbJPaAAKCRCPgPtYfRL+ Tl7sCACDg65PvULF2T57x8s2GOVh8qHAOM4G2fEdFZQeFhZiTply5wW+kG5bIM1JAdU3cAiM96g uzfqnkdy2Mt6/lWu6ZhjqOk/xYUO80eOZ5e8cyRhQLGb4VsogRhDSOKSAf4k0fkzTYCdCM3jfwP QGXt5GRUeYGJVhDmUC7m1wai9vWlfWG8IXkVbSYnX3LqEAl0A40uaffDMUtp2bFtgHNqtqbGhx6 bM/vJXjzuqiGa8jiFMTuJ50PRpeh9o/6cre0EhT+nv5GQHpRaGSKnNf/E7Q0CK0tiRGYs7M9t6g 2w/lsv8+vxgUQ7yjIC7YwrqDMXW1+x7YTS/xwh76REfV7L9/ 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-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_121413_393078_CA5A98A9 X-CRM114-Status: GOOD ( 21.78 ) X-Mailman-Approved-At: Fri, 23 Feb 2024 09:11:35 -0800 X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org This function allocates a struct pwm_chip and driver data. Compared to the status quo the split into pwm_chip and driver data is new, otherwise it doesn't change anything relevant (yet). The intention is that after all drivers are switched to use this allocation function, its possible to add a struct device to struct pwm_chip to properly track the latter's lifetime without touching all drivers again. Proper lifetime tracking is a necessary precondition to introduce character device support for PWMs (that implements atomic setting and doesn't suffer from the sysfs overhead of the /sys/class/pwm userspace support). The new function pwmchip_priv() (obviously?) only works for chips allocated with devm_pwmchip_alloc(). Signed-off-by: Uwe Kleine-König --- .../driver-api/driver-model/devres.rst | 1 + Documentation/driver-api/pwm.rst | 10 ++++---- drivers/pwm/core.c | 25 +++++++++++++++++++ include/linux/pwm.h | 2 ++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index c5f99d834ec5..e4df72c408d2 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -420,6 +420,7 @@ POWER devm_reboot_mode_unregister() PWM + devm_pwmchip_alloc() devm_pwmchip_add() devm_pwm_get() devm_fwnode_pwm_get() diff --git a/Documentation/driver-api/pwm.rst b/Documentation/driver-api/pwm.rst index 3c28ccc4b611..cee66c7f0335 100644 --- a/Documentation/driver-api/pwm.rst +++ b/Documentation/driver-api/pwm.rst @@ -143,11 +143,11 @@ to implement the pwm_*() functions itself. This means that it's impossible to have multiple PWM drivers in the system. For this reason it's mandatory for new drivers to use the generic PWM framework. -A new PWM controller/chip can be added using pwmchip_add() and removed -again with pwmchip_remove(). pwmchip_add() takes a filled in struct -pwm_chip as argument which provides a description of the PWM chip, the -number of PWM devices provided by the chip and the chip-specific -implementation of the supported PWM operations to the framework. +A new PWM controller/chip can be allocated using devm_pwmchip_alloc, then added +using pwmchip_add() and removed again with pwmchip_remove(). pwmchip_add() +takes a filled in struct pwm_chip as argument which provides a description of +the PWM chip, the number of PWM devices provided by the chip and the +chip-specific implementation of the supported PWM operations to the framework. When implementing polarity support in a PWM driver, make sure to respect the signal conventions in the PWM framework. By definition, normal polarity diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 1b4c3d0caa82..b821a2b0b172 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -454,6 +454,31 @@ of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args) } EXPORT_SYMBOL_GPL(of_pwm_single_xlate); +static void *pwmchip_priv(struct pwm_chip *chip) +{ + return (void *)chip + sizeof(*chip); +} + +struct pwm_chip *devm_pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv) +{ + struct pwm_chip *chip; + size_t alloc_size; + + alloc_size = size_add(sizeof(*chip), sizeof_priv); + + chip = devm_kzalloc(parent, alloc_size, GFP_KERNEL); + if (!chip) + return ERR_PTR(-ENOMEM); + + chip->dev = parent; + chip->npwm = npwm; + + pwmchip_set_drvdata(chip, pwmchip_priv(chip)); + + return chip; +} +EXPORT_SYMBOL_GPL(devm_pwmchip_alloc); + static void of_pwmchip_add(struct pwm_chip *chip) { if (!chip->dev || !chip->dev->of_node) diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 2c49d2fe2fe7..8bc7504aa7d4 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -403,6 +403,8 @@ static inline bool pwm_might_sleep(struct pwm_device *pwm) int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result, unsigned long timeout); +struct pwm_chip *devm_pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv); + int __pwmchip_add(struct pwm_chip *chip, struct module *owner); #define pwmchip_add(chip) __pwmchip_add(chip, THIS_MODULE) void pwmchip_remove(struct pwm_chip *chip); From patchwork Thu Jan 25 12:09:34 2024 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: 13530883 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8606C48260 for ; Thu, 25 Jan 2024 14:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pmscLgaBK1U/+A/XXQvWWCwvuby0NTXaOc6Im8Od42c=; b=Kw1E4QR+Podewo S64ZyLaEYFAIwr1xhAsfjHCV/0mPQ1vp4vH4w6blCOvs6lr1TY4zT1ZIngbZH5j3/qbcu/KF8ssy8 oktIFwlx2X/eSWcZn+6Fg7LQSwEHl1tdjKYF/Lg8ZdTYw+lQpvvzQog1AmIUbqTfP17udTy/RcDm0 IM6NVafvqP92IcrKARrx5GyWS/AKXvIore6O+c7KNtbXoBwwqD2+9Q1OhKwdzbYs3DzJHqPpNIF3L ASgWD0wnIdvdT4iIA6mexeTttL7B5jZZSeA3iYFsRLlXJAEXT8wUJzvGlqn7ik0DSAr5YOyM1H37z tAprWqH6fWLXx1FlZ3Sw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT0PM-00000000FHJ-05Gh; Thu, 25 Jan 2024 14:08:44 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT0Oe-00000000Exx-46nv for linux-amlogic@bombadil.infradead.org; Thu, 25 Jan 2024 14:08:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description; bh=DoBDSizlhGxg56AeVJwqv1E1op+2VJ/F7USVHLvNloM=; b=so5DE47wgPcktlEwtbxCDuT44I zDMoj9XPlvQZxbvlz504QJEm3/ar+cSvTWMux9dO9Zvw+42aNgN6GzmDF9bhXnaVqKjy4Apn2Lab9 FOz9w3EC1ZRrP7YuMVIqRKHGDYQs7ReC86oN3ySeQ2gTxfZswY0D/ifginQzkK9UcZizfrIHSlh7M SolI41quM/uyl/5QFhRpclmq2MAgkKbcLLTRHxPQ5NqE+FX2v89V7NH5WF9hv4xcilYNLeuT+uxKc GCYkzn/l4fJDrsAqfY2eYbRQPTrUAascyNRnseThohBttZuqyLGKIf/82ybh4uzRt3lhqZyHLAFNo +kg9xK8A==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by casper.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rSybh-00000009sDZ-3gNT for linux-amlogic@lists.infradead.org; Thu, 25 Jan 2024 12:13:25 +0000 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 1rSyZL-0004RC-OT; Thu, 25 Jan 2024 13:10:55 +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 1rSyZK-002HTN-8J; Thu, 25 Jan 2024 13:10:54 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rSyZK-007n2y-0X; Thu, 25 Jan 2024 13:10:54 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Neil Armstrong , Kevin Hilman , linux-pwm@vger.kernel.org Cc: Jerome Brunet , Martin Blumenstingl , linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, kernel@pengutronix.de Subject: [PATCH v5 072/111] pwm: meson: Make use of devm_pwmchip_alloc() function Date: Thu, 25 Jan 2024 13:09:34 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2615; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=tbf+Q2Gxrb81SZI03PQrpWoV9hGmidTqVonqvgzF990=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlsk+Ps9GWUz16FfY73NvDjTCMhYVcOfguNy68z bzG8PvGCR2JATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZbJPjwAKCRCPgPtYfRL+ TqjuCACTkTZutcwEYIAetP5/AnxvzOgESXYd5G4R2im/Y3HsmdptBtCo5AOOfuzXrbfejfnh74I iG5FTd+XcdAShxd3o91Yiv5Fc6ktPwv3ckxk+GDnd/y0+EKX9jAlgMP7ggC14b0Xg7MCL253ufx q0lV7JWwmrNn9n82i9O6PrzwH1IjQ5ZT6gNjm6ANh7oqn728Wk09If78UNy1De8YxVH+XLA5Bqz FLdS4pu+lb/I1bpLoTRfLI3rTuNAD3HGo6E/fAbexVkcUT0hJGYBbHEjJd7Y1NQ5YvDDwR169/2 DpoAM+Klwutd44wmbOSqFnbswNBAsYTAcmSJbij2W7ACJO0E 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-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_121323_573711_D1EF2747 X-CRM114-Status: GOOD ( 12.16 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org This prepares the pwm-meson 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/pwm/pwm-meson.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index dd0e18437be9..40a5b64c26f5 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -102,7 +102,6 @@ struct meson_pwm_data { }; struct meson_pwm { - struct pwm_chip chip; const struct meson_pwm_data *data; struct meson_pwm_channel channels[MESON_NUM_PWMS]; void __iomem *base; @@ -115,7 +114,7 @@ struct meson_pwm { static inline struct meson_pwm *to_meson_pwm(struct pwm_chip *chip) { - return container_of(chip, struct meson_pwm, chip); + return pwmchip_get_drvdata(chip); } static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) @@ -449,7 +448,7 @@ static int meson_pwm_init_channels(struct pwm_chip *chip) mux_parent_data[i].name = meson->data->parent_names[i]; } - for (i = 0; i < meson->chip.npwm; i++) { + for (i = 0; i < chip->npwm; i++) { struct meson_pwm_channel *channel = &meson->channels[i]; struct clk_parent_data div_parent = {}, gate_parent = {}; struct clk_init_data init = {}; @@ -529,29 +528,29 @@ static int meson_pwm_init_channels(struct pwm_chip *chip) static int meson_pwm_probe(struct platform_device *pdev) { + struct pwm_chip *chip; struct meson_pwm *meson; int err; - meson = devm_kzalloc(&pdev->dev, sizeof(*meson), GFP_KERNEL); - if (!meson) - return -ENOMEM; + chip = devm_pwmchip_alloc(&pdev->dev, MESON_NUM_PWMS, sizeof(*meson)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + meson = to_meson_pwm(chip); meson->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(meson->base)) return PTR_ERR(meson->base); spin_lock_init(&meson->lock); - meson->chip.dev = &pdev->dev; - meson->chip.ops = &meson_pwm_ops; - meson->chip.npwm = MESON_NUM_PWMS; + chip->ops = &meson_pwm_ops; meson->data = of_device_get_match_data(&pdev->dev); - err = meson_pwm_init_channels(&meson->chip); + err = meson_pwm_init_channels(chip); if (err < 0) return err; - err = devm_pwmchip_add(&pdev->dev, &meson->chip); + err = devm_pwmchip_add(&pdev->dev, chip); if (err < 0) return dev_err_probe(&pdev->dev, err, "failed to register PWM chip\n");