From patchwork Wed Feb 14 09:30:48 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: 13556188 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 69153C48BEB for ; Wed, 14 Feb 2024 09:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type: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=oeFgKpQmukUIaWih2llisrwGBGNK1YRNGjFQ09PzPoY=; b=tW1cz0lt22bNgwdJQGCAOEKNwl A09dOm5+B5ZzfpZ2pxBMnp+2TBdrzlaq1eSvZKPzc55LtaNh/WcAUtA1mgFkJhUirWmXHJwvZVIlQ lJAMwdVpZ/BmYXPwT/Ms/S1qbbXESVa6BVxefzhWBdsKPUlTt8AiNkxfK7cluBFS4p5OAhcr3QI/K lUqUnlUyL7GpqpDKBQ/TR3D6JXB30Bcg/2UgM8PoRolw5MU4zCbiKTisNj4+WMcgx8vBZM5yuFcBD clbGOV7aSph24Fr13ZWDnxQKYwn5pBwy+iuj9u9nmcH+t4Sbf/ZLLDuuWG1iRfHX4NwIRqbqYcJqG avtKPQBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raBkZ-0000000COTE-052K; Wed, 14 Feb 2024 09:40:19 +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 1raBfa-0000000CKwW-0ajp for linux-mediatek@bombadil.infradead.org; Wed, 14 Feb 2024 09:35:10 +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=oeFgKpQmukUIaWih2llisrwGBGNK1YRNGjFQ09PzPoY=; b=IndjrrksWm9D/7Hz8/zJJzSx/y kJFnubEUah0VAM42okUluRoD9GOwMOGVUir5cNVM9eozy/FUu4xB69sxI+PMDVupx3LVxAQMPA6NP fx7o933i4ejXqhMk9+5EVdUBU98tTVxn6n3wi1kxOh2yo0JYdPIcxoYtFRFE/EYDZf6gt/HmVEX9/ XialvzmbIkAoRF3CqjzcZIz05YbJ73n48J4VbX54oaVls7ZDRHfTmmtFcQ+8uik+OILQf5be2HTt0 KY7coRg3VxGkHNsOESTZ0uxx5E+RMYg9wCs9NWUhhSSCdSesvYCMAsGwCdlsfdCL6sJRiL4LIF5HH B6OXl9EA==; 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 1raBfJ-0000000GAcj-37nb for linux-mediatek@lists.infradead.org; Wed, 14 Feb 2024 09:35:08 +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 1raBeo-0004N3-Cv; Wed, 14 Feb 2024 10:34: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 1raBej-000f6R-Uf; Wed, 14 Feb 2024 10:34:17 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1raBej-004XzY-2d; Wed, 14 Feb 2024 10:34:17 +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 , Vladimir Zapolskiy , 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 , 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, greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev Subject: [PATCH v6 001/164] pwm: Provide an inline function to get the parent device of a given chip Date: Wed, 14 Feb 2024 10:30:48 +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=7837; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=VysffgosBaokCEzVr9CapJ6wP73fslCZ+jQWLzJTRHQ=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlzIhM7NlIMX1uF2GQrQA4FrQMoPchi57Yvz/JC blz73iQwb+JATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZcyITAAKCRCPgPtYfRL+ TuB0B/9P6zT5YFj/8ggZu30wuJh2FhhmcK5IFWEAn3eCqQlBR1+3r98RrH73NV8ruZe1t4nFx0t c6OsWCmmaXgE6NDq1aepB6xNx+u8uuL4EVlihT9QJVyAeyufdWSSbztRhUXrDwn+FS86xswU0hQ OCGoK2SmNoffSL++99SaLb6zwKJeLP/OE7OHvKNMeD++iM8d5m969WslaGj106z8byRgfAb+gh6 HV3n2oUDQFI0N4yfDlHO1Kbc0wLdEc4o1zQa3Kh4g0DpRCV9Wh8qYU/HDpDq4cIQi3DHD9CNJns wVoX4dBy6zyY+YlCipT3YD5PfL124GflRsA1quEFk0pOzKp4 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-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_093454_077766_DC92E438 X-CRM114-Status: GOOD ( 23.37 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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 function should be used in all drivers directly accessing chip->dev now. This way struct pwm_chip and this new function can be changed without having to touch all drivers in the same change set. Make use of this function in the framework's core sources. Signed-off-by: Uwe Kleine-König Reviewed-by: Greg Kroah-Hartman --- drivers/pwm/core.c | 42 +++++++++++++++++++++--------------------- drivers/pwm/sysfs.c | 4 ++-- include/linux/pwm.h | 5 +++++ 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 1b4c3d0caa82..830a697826af 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -71,18 +71,18 @@ static void pwm_apply_debug(struct pwm_device *pwm, if (s2.polarity != state->polarity && state->duty_cycle < state->period) - dev_warn(chip->dev, ".apply ignored .polarity\n"); + dev_warn(pwmchip_parent(chip), ".apply ignored .polarity\n"); if (state->enabled && last->polarity == state->polarity && last->period > s2.period && last->period <= state->period) - dev_warn(chip->dev, + dev_warn(pwmchip_parent(chip), ".apply didn't pick the best available period (requested: %llu, applied: %llu, possible: %llu)\n", state->period, s2.period, last->period); if (state->enabled && state->period < s2.period) - dev_warn(chip->dev, + dev_warn(pwmchip_parent(chip), ".apply is supposed to round down period (requested: %llu, applied: %llu)\n", state->period, s2.period); @@ -91,20 +91,20 @@ static void pwm_apply_debug(struct pwm_device *pwm, last->period == s2.period && last->duty_cycle > s2.duty_cycle && last->duty_cycle <= state->duty_cycle) - dev_warn(chip->dev, + dev_warn(pwmchip_parent(chip), ".apply didn't pick the best available duty cycle (requested: %llu/%llu, applied: %llu/%llu, possible: %llu/%llu)\n", state->duty_cycle, state->period, s2.duty_cycle, s2.period, last->duty_cycle, last->period); if (state->enabled && state->duty_cycle < s2.duty_cycle) - dev_warn(chip->dev, + dev_warn(pwmchip_parent(chip), ".apply is supposed to round down duty_cycle (requested: %llu/%llu, applied: %llu/%llu)\n", state->duty_cycle, state->period, s2.duty_cycle, s2.period); if (!state->enabled && s2.enabled && s2.duty_cycle > 0) - dev_warn(chip->dev, + dev_warn(pwmchip_parent(chip), "requested disabled, but yielded enabled with duty > 0\n"); /* reapply the state that the driver reported being configured. */ @@ -112,7 +112,7 @@ static void pwm_apply_debug(struct pwm_device *pwm, trace_pwm_apply(pwm, &s1, err); if (err) { *last = s1; - dev_err(chip->dev, "failed to reapply current setting\n"); + dev_err(pwmchip_parent(chip), "failed to reapply current setting\n"); return; } @@ -127,7 +127,7 @@ static void pwm_apply_debug(struct pwm_device *pwm, s1.polarity != last->polarity || (s1.enabled && s1.period != last->period) || (s1.enabled && s1.duty_cycle != last->duty_cycle)) { - dev_err(chip->dev, + dev_err(pwmchip_parent(chip), ".apply is not idempotent (ena=%d pol=%d %llu/%llu) -> (ena=%d pol=%d %llu/%llu)\n", s1.enabled, s1.polarity, s1.duty_cycle, s1.period, last->enabled, last->polarity, last->duty_cycle, @@ -318,7 +318,7 @@ static struct pwm_chip *pwmchip_find_by_name(const char *name) mutex_lock(&pwm_lock); idr_for_each_entry_ul(&pwm_chips, chip, tmp, id) { - const char *chip_name = dev_name(chip->dev); + const char *chip_name = dev_name(pwmchip_parent(chip)); if (chip_name && strcmp(chip_name, name) == 0) { mutex_unlock(&pwm_lock); @@ -456,19 +456,19 @@ EXPORT_SYMBOL_GPL(of_pwm_single_xlate); static void of_pwmchip_add(struct pwm_chip *chip) { - if (!chip->dev || !chip->dev->of_node) + if (!pwmchip_parent(chip) || !pwmchip_parent(chip)->of_node) return; if (!chip->of_xlate) chip->of_xlate = of_pwm_xlate_with_flags; - of_node_get(chip->dev->of_node); + of_node_get(pwmchip_parent(chip)->of_node); } static void of_pwmchip_remove(struct pwm_chip *chip) { - if (chip->dev) - of_node_put(chip->dev->of_node); + if (pwmchip_parent(chip)) + of_node_put(pwmchip_parent(chip)->of_node); } static bool pwm_ops_check(const struct pwm_chip *chip) @@ -479,7 +479,7 @@ static bool pwm_ops_check(const struct pwm_chip *chip) return false; if (IS_ENABLED(CONFIG_PWM_DEBUG) && !ops->get_state) - dev_warn(chip->dev, + dev_warn(pwmchip_parent(chip), "Please implement the .get_state() callback\n"); return true; @@ -500,7 +500,7 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner) unsigned int i; int ret; - if (!chip || !chip->dev || !chip->ops || !chip->npwm) + if (!chip || !pwmchip_parent(chip) || !chip->ops || !chip->npwm) return -EINVAL; if (!pwm_ops_check(chip)) @@ -594,15 +594,15 @@ static struct device_link *pwm_device_link_add(struct device *dev, * impact the PM sequence ordering: the PWM supplier may get * suspended before the consumer. */ - dev_warn(pwm->chip->dev, + dev_warn(pwmchip_parent(pwm->chip), "No consumer device specified to create a link to\n"); return NULL; } - dl = device_link_add(dev, pwm->chip->dev, DL_FLAG_AUTOREMOVE_CONSUMER); + dl = device_link_add(dev, pwmchip_parent(pwm->chip), DL_FLAG_AUTOREMOVE_CONSUMER); if (!dl) { dev_err(dev, "failed to create device link to %s\n", - dev_name(pwm->chip->dev)); + dev_name(pwmchip_parent(pwm->chip))); return ERR_PTR(-EINVAL); } @@ -617,7 +617,7 @@ static struct pwm_chip *fwnode_to_pwmchip(struct fwnode_handle *fwnode) mutex_lock(&pwm_lock); idr_for_each_entry_ul(&pwm_chips, chip, tmp, id) - if (chip->dev && device_match_fwnode(chip->dev, fwnode)) { + if (pwmchip_parent(chip) && device_match_fwnode(pwmchip_parent(chip), fwnode)) { mutex_unlock(&pwm_lock); return chip; } @@ -1085,8 +1085,8 @@ static int pwm_seq_show(struct seq_file *s, void *v) seq_printf(s, "%s%d: %s/%s, %d PWM device%s\n", (char *)s->private, chip->id, - chip->dev->bus ? chip->dev->bus->name : "no-bus", - dev_name(chip->dev), chip->npwm, + pwmchip_parent(chip)->bus ? pwmchip_parent(chip)->bus->name : "no-bus", + dev_name(pwmchip_parent(chip)), chip->npwm, (chip->npwm != 1) ? "s" : ""); pwm_dbg_show(chip, s); diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index 1698609d91c8..3f434a771fb5 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c @@ -509,10 +509,10 @@ void pwmchip_sysfs_export(struct pwm_chip *chip) * If device_create() fails the pwm_chip is still usable by * the kernel it's just not exported. */ - parent = device_create(&pwm_class, chip->dev, MKDEV(0, 0), chip, + parent = device_create(&pwm_class, pwmchip_parent(chip), MKDEV(0, 0), chip, "pwmchip%d", chip->id); if (IS_ERR(parent)) { - dev_warn(chip->dev, + dev_warn(pwmchip_parent(chip), "device_create failed for pwm_chip sysfs export\n"); } } diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 8ffe9ae7a23a..07af6910bdce 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(const 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 Wed Feb 14 09:30:50 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: 13556190 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 EF4C9C48BED for ; Wed, 14 Feb 2024 09:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type: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=RX8a2Y2ytwxmY6PKETGiawOZZabN9W6u5TeadBpvUYc=; b=oEkDZ2dNG1TKy8WrbM6G6t2r88 6qmeXdqdt2pqfuk0anOuo44v+YsezFWsmPmap7IqBTO80hs/BqqBMcaJrqDZkPTW5QG4Bv3lxRTt7 rDyvsEucV3sqOY4QeS8pZfNjlb28HU15nDn0ri/TjCJrko6v5HDOX+o5rVTNTwbv4rl0rcDm2Z7zR Jgxw6SPNWqt3qfQ04LSpnWOFQ5bjYOkLBCcHnf1HUDyFXiQQR+O2fszNwijLrE6RKL+5kQAy0Lplp nmA+/WdqRAUvcly8omZ/lgnxOByjqt74NnsqCm0hEUWrGiAJA63vBQ0zoEgI/ZB66UyLWB9fnlCNG R1WsMYIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raBkm-0000000COfC-3OYU; Wed, 14 Feb 2024 09:40:32 +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 1raBfw-0000000CLBJ-1aSg for linux-mediatek@bombadil.infradead.org; Wed, 14 Feb 2024 09:35:32 +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=RX8a2Y2ytwxmY6PKETGiawOZZabN9W6u5TeadBpvUYc=; b=p+WM8NmysWJncQrAIe3gdiooBP W8XlXckIvUOltcL5cF9py4dSDRsXntSoFsYxs2hGKJ2Rvas9tDe9epgqLcVkmtDZp6BfRwTyMd0pe 8cwRELuGRnq6NI58sAYotUKONJxvFtjje5BFRP3JfUw6t+nQYN/YW3xyX9jS7LULH4ykzxCf9sRnM Rc9MSRZIgPtIu/HYXnbpZwWAGBLAMEwCf+Bi4OgDnTVHz4AnzcdWd+TSoaXl8N5PHT2o3LioAGjli Zyle/l3vM5ja9jLllZE1d4rd3uDZgGRj62cXUODxf1KTEv0pwVWJ89NyOKg9cmBzXKb4e4KLmCMB4 KpbCbTuQ==; 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 1raBfs-0000000GDzs-00CD for linux-mediatek@lists.infradead.org; Wed, 14 Feb 2024 09:35:31 +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 1raBeq-0004OA-3m; Wed, 14 Feb 2024 10:34:24 +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 1raBek-000f6Z-By; Wed, 14 Feb 2024 10:34:18 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1raBek-004Xzr-0a; Wed, 14 Feb 2024 10:34:18 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Jonathan Corbet , Jonathan Cameron , James Clark , Andy Shevchenko , Mark Brown , linux-pwm@vger.kernel.org, Hector Martin , Sven Peter , Claudiu Beznea , Nicolas Ferre , Alexandre Belloni , Florian Fainelli , Ray Jui , Scott Branden , Alexander Shiyan , Benson Leung , Shawn Guo , Sascha Hauer , Paul Cercueil , Vladimir Zapolskiy , Mika Westerberg , Andy Shevchenko , Linus Walleij , 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 , Bartosz Golaszewski , Pavel Machek , Lee Jones , Anjelique Melendez , Bjorn Andersson , Kees Cook , Rob Herring 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, linux-gpio@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-leds@vger.kernel.org Subject: [PATCH v6 003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it Date: Wed, 14 Feb 2024 10:30:50 +0100 Message-ID: <9577d6053a5a52536057dc8654ff567181c2da82.1707900770.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=6032; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=koAN/+/23sPZAVIjNYgBDfSOCZNuNAYktJbEIstyjSk=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlzIhOy3rMjR1GdjpQaPyoW0nJ56JzUO/rQmlQs ZBM0ZtEf82JATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZcyITgAKCRCPgPtYfRL+ TicEB/0dPx8EojmTD1h+4X2160QdFmhEtr9DkNcgvD4MXbJwi2AR0WTiisK1rsmV+6tCkIK7tJ3 ia8xMZ3BnvofoSfLSnXkboz+RdVSIEA7BqEblHXS94KRpF0kJSfkChuZTlsOibS5ccdLl9keCDp Ln92glGKIspJhlUYHC5XJS/5WgVuJIs2zBZ0mj9ssy1fRc7GPSOATaja3kUzueYK4sFeE9sRycR zgSfTLZglcFmMVV6/V8gfK4IdkOlO88EBryyP7oNNXf0XhDmqRiBNvGBpkzOgQFt0cSSObTgx1d uKdMfoMhlp4iXIRqjo0TrOM/JN49b64qgWPy7mfDaS9UVtMr 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-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_093529_445529_3851EAFD X-CRM114-Status: GOOD ( 21.15 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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 pwmchip_alloc(). Signed-off-by: Uwe Kleine-König --- .../driver-api/driver-model/devres.rst | 1 + Documentation/driver-api/pwm.rst | 11 ++-- drivers/pwm/core.c | 58 +++++++++++++++++++ include/linux/pwm.h | 22 +++++++ 4 files changed, 87 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..b41b1c56477f 100644 --- a/Documentation/driver-api/pwm.rst +++ b/Documentation/driver-api/pwm.rst @@ -143,11 +143,12 @@ 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 pwmchip_alloc(), then +registered using pwmchip_add() and removed again with pwmchip_remove(). To undo +pwmchip_alloc() use pwmchip_put(). 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 830a697826af..9fc6f4fa71d6 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -454,6 +454,64 @@ of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args) } EXPORT_SYMBOL_GPL(of_pwm_single_xlate); +#define PWMCHIP_ALIGN ARCH_DMA_MINALIGN + +static void *pwmchip_priv(struct pwm_chip *chip) +{ + return (void *)chip + ALIGN(sizeof(*chip), PWMCHIP_ALIGN); +} + +/* This is the counterpart to pwmchip_alloc */ +void pwmchip_put(struct pwm_chip *chip) +{ + kfree(chip); +} +EXPORT_SYMBOL_GPL(pwmchip_put); + +struct pwm_chip *pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv) +{ + struct pwm_chip *chip; + size_t alloc_size; + + alloc_size = size_add(ALIGN(sizeof(*chip), PWMCHIP_ALIGN), sizeof_priv); + + chip = kzalloc(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(pwmchip_alloc); + +static void devm_pwmchip_put(void *data) +{ + struct pwm_chip *chip = data; + + pwmchip_put(chip); +} + +struct pwm_chip *devm_pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv) +{ + struct pwm_chip *chip; + int ret; + + chip = pwmchip_alloc(parent, npwm, sizeof_priv); + if (IS_ERR(chip)) + return chip; + + ret = devm_add_action_or_reset(parent, devm_pwmchip_put, chip); + if (ret) + return ERR_PTR(ret); + + return chip; +} +EXPORT_SYMBOL_GPL(devm_pwmchip_alloc); + static void of_pwmchip_add(struct pwm_chip *chip) { if (!pwmchip_parent(chip) || !pwmchip_parent(chip)->of_node) diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 29a7d9140f77..4a6568dfdf3f 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -403,6 +403,10 @@ static inline bool pwm_might_sleep(struct pwm_device *pwm) int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result, unsigned long timeout); +void pwmchip_put(struct pwm_chip *chip); +struct pwm_chip *pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv); +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); @@ -475,6 +479,24 @@ static inline int pwm_capture(struct pwm_device *pwm, return -EINVAL; } +static inline void pwmchip_put(struct pwm_chip *chip) +{ +} + +static inline struct pwm_chip *pwmchip_alloc(struct device *parent, + unsigned int npwm, + size_t sizeof_priv) +{ + return ERR_PTR(-EINVAL); +} + +static inline struct pwm_chip *devm_pwmchip_alloc(struct device *parent, + unsigned int npwm, + size_t sizeof_priv) +{ + return pwmchip_alloc(parent, npwm, sizeof_priv); +} + static inline int pwmchip_add(struct pwm_chip *chip) { return -EINVAL; From patchwork Wed Feb 14 09:31:55 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: 13556125 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 EB5AEC48BEB for ; Wed, 14 Feb 2024 09:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type: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=BcKeOMFeRyLt0DNwQC4iOgRvHayp0Kf3VhyAm9cl0A8=; b=acDwPPwOkRSCUaPZBCsG3ZOWdY AOZUo0JXveIIoU86pDUhHUFuCMFvmWxE0keqIW43M/AGiE0ov2mbBtU1ZJ/ap9TBV7/5BcRm2nSZb 6RrlDEi4DY8kfoRbnwfIwQhwLw+LqKVYtT299WmhYZfMW/VGTN3QE4zHUxLBnP23YFQgYjdLtszVR hMsPBPdIMB2FqyQ83gHDT1l1Dekm3m5jRAK9327ZK4d4iEbzianQDb6zCDdoWcJsqVkSMxmwZM3c0 HjfAqMmWqk5GlUZqPYK91ytP76avI9pHCOeRLnkaSLDs5W0JQBgnGGrR5NPFauvYm1UNvZS//HQqY h1M+w3eA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raBhU-0000000CMd3-3r8L; Wed, 14 Feb 2024 09:37:08 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1raBf8-0000000CKRR-0vaB for linux-mediatek@lists.infradead.org; Wed, 14 Feb 2024 09:34:50 +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 1raBex-00052s-I7; Wed, 14 Feb 2024 10:34:31 +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 1raBeu-000fCx-Er; Wed, 14 Feb 2024 10:34:28 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1raBeu-004Y4N-1C; Wed, 14 Feb 2024 10:34:28 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Matthias Brugger , AngeloGioacchino Del Regno , linux-pwm@vger.kernel.org Cc: kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH v6 068/164] pwm: mediatek: Make use of pwmchip_parent() accessor Date: Wed, 14 Feb 2024 10:31:55 +0100 Message-ID: <819996ee175bec0ab71acc385c78e7233617e136.1707900770.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=891; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=n8WkmK8zXwx0gmZde1hbERzcObCWJ/WjRRDw6pi2QYM=; b=owGbwMvMwMXY3/A7olbonx/jabUkhtQzHTNqnCdu5w6NzOSoYjL7v00q3Pd7/NxNi/zrWKxDV laFysV2MhqzMDByMciKKbLYN67JtKqSi+xc++8yzCBWJpApDFycAjCRV0Hs/xPiQ72OXtl0mivD +1RIt0HttdWHC8XEjvzSPPJw0UTHk87cnSk3YmPW7642fL44ps725xw/gZZNHVk/HqpNqRWPNGG ssXW+19+7jK9m8WqtqGuHtkiv4pm0LJGlIrrN76HpQX29SW4iX9Qdoh//V6vcle7zw8/hepHq09 TnghF7f/wMNXs/50b+KpW37Q9zY3W3d0w1czSW4fS/uEctdVvoLuFItU8TL/M112yWzvTY75Zl6 fv11Tkl86U1fn/icx9VFSzcKanbLNi8Rcq9c4bv1BP8Px2k/QIvNxg/m3ur3/+IIWvpD/GSjIcu xn9XNRfkb3qpWLC3+yGXxQyFC+lui28ER/m/u/P+rN4jAA== 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-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_013442_431924_60F291D2 X-CRM114-Status: GOOD ( 12.45 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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 accessor function provided for exactly this purpose. Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-mediatek.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c index 562102a47ac0..6cf7543a3826 100644 --- a/drivers/pwm/pwm-mediatek.c +++ b/drivers/pwm/pwm-mediatek.c @@ -149,7 +149,7 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm, if (clkdiv > PWM_CLK_DIV_MAX) { pwm_mediatek_clk_disable(chip, pwm); - dev_err(chip->dev, "period of %d ns not supported\n", period_ns); + dev_err(pwmchip_parent(chip), "period of %d ns not supported\n", period_ns); return -EINVAL; } From patchwork Wed Feb 14 09:31:56 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: 13556187 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 EC680C48BC4 for ; Wed, 14 Feb 2024 09:39:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type: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=7PPdCFSTOt8Wh2uj35QYBS1aRoj9Os6L0OTsFQ63VpQ=; b=whU257qw8nRWOK7NoRfCAqi6BG 9CaPGz0r2nSVRZCzoagYmP9q8yn0ki4YIcj7l8xDm/cLobA3gIZg0QIdTGYlKZoXUzqQXTG0/t+Hq N55FgJjRHqcXbiJckQNYc3KPGQLv0jDu9WzSDA1f/4M+JsI7pDpIrUbG2oN8fpgPoW6+TWDjiT9so H0R1INAamRQaGGkeERRRDBfOWzxv2inwSgOFjiQf5ee/or+tpfS1KhQZrufpQhd1TG7LsbvoXT5/X 68sHjI2+PpiX5TijKgVhXp0pM7cxkIH+GcliMgelhNkTHqwhI0OC1Fl8M+7kKKcOo0q9MT3/3/Hip Wr2+f46w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raBjW-0000000CNXq-0Eos; Wed, 14 Feb 2024 09:39:14 +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 1raBfO-0000000CKj3-2gox for linux-mediatek@bombadil.infradead.org; Wed, 14 Feb 2024 09:34: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=7PPdCFSTOt8Wh2uj35QYBS1aRoj9Os6L0OTsFQ63VpQ=; b=n6/iBnGnqu6/7LsjY07tcKKZBO I2NyVvlNhyJ7oho/i1NQK0ydkkcxLDoEz9CUZBkg1z8wNOrE17jvVvMZ06D9DE874Wa/+pwahwsW2 yn7i+zEYFzLaQee5U0DZCcQF7HdW7jKH2+sI3yEic822YvZsb3BImm+nxFTvUPAXX3Bm4r+EgeRA6 H3Rxp25uLaqpVHNDfcjeI+6dHmlvUdx40uwz4RmkmNJ/3TGCE2zR8BiLL1WUnierN44Ci3CiCnoGw gk2YU+f2J2h156ilvBMMUwFRMF2hkovjGrrzCeZfTOx9JWKWeJ0qxD+hvj9ymEmIOT6aeSfdrQJlQ rU+KOKBg==; 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 1raBfE-0000000GAXD-2QJy for linux-mediatek@lists.infradead.org; Wed, 14 Feb 2024 09:34:57 +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 1raBex-000544-Ot; Wed, 14 Feb 2024 10:34:31 +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 1raBeu-000fD0-KV; Wed, 14 Feb 2024 10:34:28 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1raBeu-004Y4R-1k; Wed, 14 Feb 2024 10:34:28 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Matthias Brugger , AngeloGioacchino Del Regno , linux-pwm@vger.kernel.org Cc: kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH v6 069/164] pwm: mediatek: Make use of devm_pwmchip_alloc() function Date: Wed, 14 Feb 2024 10:31:56 +0100 Message-ID: <513b2037c00ebf2f3a69472f4b99adaf4fb40d83.1707900770.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=3214; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=efjqoTt2JNTkS/blkL8nCUoyaB7R1fYI93LJBT5sUFk=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlzIiaeLfnYLOw4DotMB2SXw03iCB2wYUsxsOpk cYDh43ACSaJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZcyImgAKCRCPgPtYfRL+ TnthB/91VfbI7Gnxixao020csS6NwOC2xRsfijHkmra/QOHIKisTw/QsU5yq7ml5F8jBoFb+C1q Gf5s2PPhlexsn8Q3fGs2LISIaseVvU+CfkuZejsVr9oU69DO/bwOPeQM1bvcywQ17fipCSgNEjb 4gfHujipg9I+syZdnxCK9UdvjHQYfUY9rB3SHSBDzWqUfFlnKVu4ZjxKGPZDSAbmTzOlnnc6UUz QOMw3xM1eW2oghJKfENs4NGOuQkGiuu1PZcL3Z9ZDq8X8UO78fFgC/z8GJnzfHYmrubaJ6M17x8 2kjZhLTumvzbtPrCaU/JDtglaKs86O3M6wL7z1dkF4NXD9/v 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-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_093449_010366_88EFB0F2 X-CRM114-Status: GOOD ( 18.40 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org This prepares the pwm-mediatek 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-mediatek.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c index 6cf7543a3826..c5fca0f1ebc7 100644 --- a/drivers/pwm/pwm-mediatek.c +++ b/drivers/pwm/pwm-mediatek.c @@ -42,7 +42,6 @@ struct pwm_mediatek_of_data { /** * struct pwm_mediatek_chip - struct representing PWM chip - * @chip: linux PWM chip representation * @regs: base address of PWM chip * @clk_top: the top clock generator * @clk_main: the clock used by PWM core @@ -50,7 +49,6 @@ struct pwm_mediatek_of_data { * @soc: pointer to chip's platform data */ struct pwm_mediatek_chip { - struct pwm_chip chip; void __iomem *regs; struct clk *clk_top; struct clk *clk_main; @@ -69,7 +67,7 @@ static const unsigned int mtk_pwm_reg_offset_v2[] = { static inline struct pwm_mediatek_chip * to_pwm_mediatek_chip(struct pwm_chip *chip) { - return container_of(chip, struct pwm_mediatek_chip, chip); + return pwmchip_get_drvdata(chip); } static int pwm_mediatek_clk_enable(struct pwm_chip *chip, @@ -232,21 +230,26 @@ static const struct pwm_ops pwm_mediatek_ops = { static int pwm_mediatek_probe(struct platform_device *pdev) { + struct pwm_chip *chip; struct pwm_mediatek_chip *pc; + const struct pwm_mediatek_of_data *soc; unsigned int i; int ret; - pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); - if (!pc) - return -ENOMEM; + soc = of_device_get_match_data(&pdev->dev); - pc->soc = of_device_get_match_data(&pdev->dev); + chip = devm_pwmchip_alloc(&pdev->dev, soc->num_pwms, sizeof(*pc)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + pc = to_pwm_mediatek_chip(chip); + + pc->soc = soc; pc->regs = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(pc->regs)) return PTR_ERR(pc->regs); - pc->clk_pwms = devm_kmalloc_array(&pdev->dev, pc->soc->num_pwms, + pc->clk_pwms = devm_kmalloc_array(&pdev->dev, soc->num_pwms, sizeof(*pc->clk_pwms), GFP_KERNEL); if (!pc->clk_pwms) return -ENOMEM; @@ -261,7 +264,7 @@ static int pwm_mediatek_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_main), "Failed to get main clock\n"); - for (i = 0; i < pc->soc->num_pwms; i++) { + for (i = 0; i < soc->num_pwms; i++) { char name[8]; snprintf(name, sizeof(name), "pwm%d", i + 1); @@ -272,11 +275,9 @@ static int pwm_mediatek_probe(struct platform_device *pdev) "Failed to get %s clock\n", name); } - pc->chip.dev = &pdev->dev; - pc->chip.ops = &pwm_mediatek_ops; - pc->chip.npwm = pc->soc->num_pwms; + chip->ops = &pwm_mediatek_ops; - ret = devm_pwmchip_add(&pdev->dev, &pc->chip); + ret = devm_pwmchip_add(&pdev->dev, chip); if (ret < 0) return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n"); From patchwork Wed Feb 14 09:32: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: 13556126 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 B4116C48BC4 for ; Wed, 14 Feb 2024 09:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type: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=Iu21F9N6AsLJuVDEPF3znjNywYwYrNinglrpyASP1no=; b=uw103NmJM81sb5DijL8IODd93T NVz12FIuvIREhb3nP2IlNqDb387YMXMoEic4UF4Tn4Ax/459LAx+Ydq5xA9qM6YrOmy742nF/hsTz pP52AlifZavx+SsRNZ/DzLccusXmn6bdiukn+QJzWSHnPhKH+t+wSqrevxcmFB2mM38NFkyB88tP0 gjIzrp7X+w6+DyFlMEpe8M4g7fuwVAgaPgLSPQ75JtmAVic0O+pWX4HZVbHaCwLzm3lLREU2sU39b jSLg4v8Tm4QGsqzjhc5k+ixqSqNVzptQj2Zumj9QruSQjc5jE/SAQ5VeynvkZHShbR+pQVAkrHDM9 nXyoKQ7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raBhj-0000000CMpW-3DCK; Wed, 14 Feb 2024 09:37:23 +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 1raBfH-0000000CKcN-16uf for linux-mediatek@bombadil.infradead.org; Wed, 14 Feb 2024 09:34:51 +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=Iu21F9N6AsLJuVDEPF3znjNywYwYrNinglrpyASP1no=; b=mIxVEym6/RhcqQyrlUGGzIWH11 eIxagAOVWxi4WUvXsH0dqehI1Nc0LCB3wkSPYS2wfRuRdx8ovpSP9QZHwTWWy1VjRnJqoxaDGaBbU lgna/1BYRldpJzVlWnoO+KwdCnZ4gx3UB0gutsrs1MAp8I50+2FrSKsUw5iaC7rCL9Fa8q5lPGKpO vHMly0QN822SePZmpQ3wxAM5yulj08WG5+GF2kVcqcKY9yn7qXs6Viq2xcNkJy2nwjIE4OgS9S+/q +PxR8N+7G0AHwieo9p1eu7qPWpq6L3TRsWNlgAWfx2N+K7IreI7TLPLD+irxztUG1pic5lBuu3Is6 GsBJwu+Q==; 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 1raBfD-0000000GAXG-0jQR for linux-mediatek@lists.infradead.org; Wed, 14 Feb 2024 09:34:49 +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 1raBey-00059n-Jr; Wed, 14 Feb 2024 10:34:32 +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 1raBev-000fDL-DC; Wed, 14 Feb 2024 10:34:29 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1raBev-004Y4l-14; Wed, 14 Feb 2024 10:34:29 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Matthias Brugger , AngeloGioacchino Del Regno , linux-pwm@vger.kernel.org Cc: kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH v6 074/164] pwm: mtk-disp: Make use of pwmchip_parent() accessor Date: Wed, 14 Feb 2024 10:32:01 +0100 Message-ID: <93ba7ef22f8d26f17e64326249d5da54ab8014ea.1707900770.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=1790; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=HAz7THBaqE1zk9nd2+emun7+lN7VcaMz4+VVJrgwc3M=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlzIif0wO7RFm/4/BsEVKEHGZ573THDXi+L/vlk Kj9Odwc3S+JATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZcyInwAKCRCPgPtYfRL+ Tmj/B/9Qj8v7A2vPAcgJSB+sK+gj+ELCffwiTM40ITMm/GUjgSRb+fhnLZLulIEs8jCB6xW6jO7 wq97LDk0pK6j0pX6QkFRotwJYQc73WaisDTO0v5BOCVGd0RZxF2rKoVnNh1dMHrvdsq1LOEn6SV zsLrDHGeiHh90fbHGZSAcDRCuj0RWY+Zg6pl0moF2dvaHGpfp6t++1nWNzkdXZsHN5twlq4MzH7 HZAodjYUK0BoQL9nDYwMqE1DU351NtKD5ZpMx/P0yZjOup3LaBqpu+ONzGWdXGUDaEzOFxXL9Er UthAF4IfDBNlVaf13fQcHvAJPP11MpJ6A7Gt6s6BFA3y5dwt 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-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_093447_698410_7BAD82DD X-CRM114-Status: GOOD ( 11.97 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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 accessor function provided for exactly this purpose. Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-mtk-disp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c index a72f7be36996..186aa5c04435 100644 --- a/drivers/pwm/pwm-mtk-disp.c +++ b/drivers/pwm/pwm-mtk-disp.c @@ -91,14 +91,14 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (!mdp->enabled) { err = clk_prepare_enable(mdp->clk_main); if (err < 0) { - dev_err(chip->dev, "Can't enable mdp->clk_main: %pe\n", + dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_main: %pe\n", ERR_PTR(err)); return err; } err = clk_prepare_enable(mdp->clk_mm); if (err < 0) { - dev_err(chip->dev, "Can't enable mdp->clk_mm: %pe\n", + dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_mm: %pe\n", ERR_PTR(err)); clk_disable_unprepare(mdp->clk_main); return err; @@ -181,13 +181,13 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip, err = clk_prepare_enable(mdp->clk_main); if (err < 0) { - dev_err(chip->dev, "Can't enable mdp->clk_main: %pe\n", ERR_PTR(err)); + dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_main: %pe\n", ERR_PTR(err)); return err; } err = clk_prepare_enable(mdp->clk_mm); if (err < 0) { - dev_err(chip->dev, "Can't enable mdp->clk_mm: %pe\n", ERR_PTR(err)); + dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_mm: %pe\n", ERR_PTR(err)); clk_disable_unprepare(mdp->clk_main); return err; } From patchwork Wed Feb 14 09:32: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: 13556124 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 4A42AC48BEB for ; Wed, 14 Feb 2024 09:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type: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=+ZunnpiRJfE0NCCeEhY3kAxlDHpCTJGjQNebbPRR+ww=; b=fLTKXB5gOwhbu8M6nbWxmY3k/3 JAVxasKJsO0WDynyPhRkT2jufqoljFt1IDLkUfmPmp1O8d8g8mkMaLfydm/KAMjzUz3JRhB1v9Iza GCLCovsm5T1OOlpMl6u4sNl3c8HWPwMArqgyJZcqycEkkHn35E9kSgCqm6Hi73LJm/PrxTg9MWeK+ wASumb7u71aKQx3zpS9FjWv2U13lAZ3V93w7In2ykUhU4ZNCN9PdQ+WlskeGWauX1XmyOLld67Cay MuUqTBrW7LnctRWMDrcj/qAD8Xs7v+vT3erlnFaAMaVudd9BsCyjH6K0kf9OySj/2P6clzOjqD7cY 24gQ72pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raBhK-0000000CMSg-0xdx; Wed, 14 Feb 2024 09:36:58 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1raBf7-0000000CKQp-2JEk for linux-mediatek@lists.infradead.org; Wed, 14 Feb 2024 09:34:48 +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 1raBex-0005Ag-K0; Wed, 14 Feb 2024 10:34:31 +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 1raBev-000fDP-IF; Wed, 14 Feb 2024 10:34:29 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1raBev-004Y4p-1Z; Wed, 14 Feb 2024 10:34:29 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Matthias Brugger , AngeloGioacchino Del Regno , linux-pwm@vger.kernel.org Cc: kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH v6 075/164] pwm: mtk-disp: Make use of devm_pwmchip_alloc() function Date: Wed, 14 Feb 2024 10:32: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=2148; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=MbksikhrFe2+cIq8JkZ1a1wrryjv2J/w24px7Bciwsw=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlzIihfEUe+P2Au0+Ds1rdA4i5NuI4cs8yEyfaR 9/IXXjJLX6JATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZcyIoQAKCRCPgPtYfRL+ TgFhB/9RyFBE3JtdEgMwThz2E8luf65p0NdjcC/slHQC/wiczIzYIKItruhFvdHwrGPDwbyzYSa MCK7YoK6vi3C6+bkncYD0gebq+0b4z7Oc36ZmM0oFK1YCeFX/m1mhzFELLRqAB6fatAtXypkQde hsE6PHuPbU0wDnREupWjm6zh8APN0wzxw0cwsIZjbStQGOFLBZlgxVrqpODYZT/Fh34ZN2qaKfj EuxshcqckGZZMozEk7XuKIsQeJJWfEynd3lTnSw2FXBZgLVJBNU0CV/TRPg1Lu0zfe8vcKW3JEN w8LP/r48bgsH99MbUPH1KekHjZhnfOH8FGIoLE341UfNv8WV 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-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_013441_789957_8E503B7E X-CRM114-Status: GOOD ( 15.12 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org This prepares the pwm-mtk-disp 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. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-mtk-disp.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c index 186aa5c04435..bafd6b6195f6 100644 --- a/drivers/pwm/pwm-mtk-disp.c +++ b/drivers/pwm/pwm-mtk-disp.c @@ -42,7 +42,6 @@ struct mtk_pwm_data { }; struct mtk_disp_pwm { - struct pwm_chip chip; const struct mtk_pwm_data *data; struct clk *clk_main; struct clk *clk_mm; @@ -52,7 +51,7 @@ struct mtk_disp_pwm { static inline struct mtk_disp_pwm *to_mtk_disp_pwm(struct pwm_chip *chip) { - return container_of(chip, struct mtk_disp_pwm, chip); + return pwmchip_get_drvdata(chip); } static void mtk_disp_pwm_update_bits(struct mtk_disp_pwm *mdp, u32 offset, @@ -231,12 +230,14 @@ static const struct pwm_ops mtk_disp_pwm_ops = { static int mtk_disp_pwm_probe(struct platform_device *pdev) { + struct pwm_chip *chip; struct mtk_disp_pwm *mdp; int ret; - mdp = devm_kzalloc(&pdev->dev, sizeof(*mdp), GFP_KERNEL); - if (!mdp) - return -ENOMEM; + chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*mdp)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + mdp = to_mtk_disp_pwm(chip); mdp->data = of_device_get_match_data(&pdev->dev); @@ -254,11 +255,9 @@ static int mtk_disp_pwm_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(mdp->clk_mm), "Failed to get mm clock\n"); - mdp->chip.dev = &pdev->dev; - mdp->chip.ops = &mtk_disp_pwm_ops; - mdp->chip.npwm = 1; + chip->ops = &mtk_disp_pwm_ops; - ret = devm_pwmchip_add(&pdev->dev, &mdp->chip); + ret = devm_pwmchip_add(&pdev->dev, chip); if (ret < 0) return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n");