From patchwork Wed Feb 14 09:32:30 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: 13556178 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 9F44CC48BEE for ; Wed, 14 Feb 2024 09:37:08 +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=w+7wIwLe7tazaqoHbs+XDYt2cA52aWWd/nad9rY4P9M=; b=m3T4+/whj6zqbM sjFk6mVxxXeiuiKGZOb2Cs8+JTcrV0p+mBlPdHnsBMz2VQmzj3fNUscVcj0xsLnsGHN0CZEvyMn6X 94UbGZUEQ5GMdZanq4lcIV8/3k9hKiI6SSFsi5hwbT2qJ1xooQQxoxtJrXZEUbSlF0hHLG/k64qE1 uOKmLO28fKVVtpccdeTUYxACdjZsWup2muH3JxgSUZK40EvsNHTONh9PknzMYGO6aQ7W9R/RLunrC SIiB22WQOEy85Cza7Wm6HsQYGVSCTgciWnIlpX+X63gg0oAbSEGEbijo6mCugXxyqQTiuuYyzHBsg WHoXyQqaX3LngEhb69mQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raBhO-0000000CMXJ-3y2X; Wed, 14 Feb 2024 09:37:02 +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-0000000CKQo-2Hp6 for linux-riscv@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 1raBf3-0005ZL-4w; Wed, 14 Feb 2024 10:34:37 +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 1raBez-000fF7-NF; Wed, 14 Feb 2024 10:34:33 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1raBez-004Y6n-24; Wed, 14 Feb 2024 10:34:33 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Palmer Dabbelt , Paul Walmsley , linux-pwm@vger.kernel.org Cc: linux-riscv@lists.infradead.org, kernel@pengutronix.de Subject: [PATCH v6 103/164] pwm: sifive: Prepare removing pwm_chip from driver data Date: Wed, 14 Feb 2024 10:32:30 +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=2663; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=TS2SuJjkwNJtPUY3FsLwiCtm+q1TFZUqoQ0gsqhcsk4=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlzIjBwJd/Jn3oPTdIFr2TkHHzIyM9JaeylwF63 BUOLSlf5A+JATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZcyIwQAKCRCPgPtYfRL+ Ts0jB/sGYEEaeYWtPA2Dg9FaCXYJzf8tYUyJ72AJZ7KMt8vahWTJgiVMa5ptB3HmBx3VPW3Nutt rwC7cSQKZ7GF5rklLLW9HULeedGp5OYA/oKZYObVJl3pTXzh/vBqPo5SaQpjhv3WE6fmqhStViu 8X27P8tPQuWik1QhXA53L0zTx8HcPx2T4k+FTpNdJ1CYeRJjDkn7qvPyVY+x3/F2PI+uha/RsUk xZt2tuPbvlv8MxIY+9UG9ARypRty9UUdHbyOy+8o+Ik1OpagZhT63mxF8MtpInke9i+m292jDxL CYCbRUu6MFySs+LwmNpybXT9PLlrFCwm1s0PnGQaUi8mB6Fm 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-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_013441_864863_C46C0099 X-CRM114-Status: GOOD ( 15.54 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This prepares the driver for further changes that will drop struct pwm_chip chip from struct pwm_sifive_ddata. Use the pwm_chip as driver data instead of the pwm_sifive_ddata to get access to the pwm_chip in pwm_sifive_remove() without using ddata->chip. In the clock rate notifier it's not possible to get the pwm_chip without adding a pointer to this to struct pwm_sifive_ddata. Instead of that add a parent device pointer which is all that is needed there. Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-sifive.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index cf00f902fc30..ed40a687f909 100644 --- a/drivers/pwm/pwm-sifive.c +++ b/drivers/pwm/pwm-sifive.c @@ -42,6 +42,7 @@ struct pwm_sifive_ddata { struct pwm_chip chip; + struct device *parent; struct mutex lock; /* lock to protect user_count and approx_period */ struct notifier_block notifier; struct clk *clk; @@ -102,7 +103,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, /* As scale <= 15 the shift operation cannot overflow. */ num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); ddata->real_period = div64_ul(num, rate); - dev_dbg(ddata->chip.dev, + dev_dbg(ddata->parent, "New real_period = %u ns\n", ddata->real_period); } @@ -236,7 +237,7 @@ static int pwm_sifive_probe(struct platform_device *pdev) mutex_init(&ddata->lock); chip = &ddata->chip; - chip->dev = dev; + chip->dev = ddata->parent = dev; chip->ops = &pwm_sifive_ops; chip->npwm = 4; @@ -296,7 +297,7 @@ static int pwm_sifive_probe(struct platform_device *pdev) goto unregister_clk; } - platform_set_drvdata(pdev, ddata); + platform_set_drvdata(pdev, chip); dev_dbg(dev, "SiFive PWM chip registered %d PWMs\n", chip->npwm); return 0; @@ -314,15 +315,16 @@ static int pwm_sifive_probe(struct platform_device *pdev) static void pwm_sifive_remove(struct platform_device *dev) { - struct pwm_sifive_ddata *ddata = platform_get_drvdata(dev); + struct pwm_chip *chip = platform_get_drvdata(dev); + struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); struct pwm_device *pwm; int ch; - pwmchip_remove(&ddata->chip); + pwmchip_remove(chip); clk_notifier_unregister(ddata->clk, &ddata->notifier); - for (ch = 0; ch < ddata->chip.npwm; ch++) { - pwm = &ddata->chip.pwms[ch]; + for (ch = 0; ch < chip->npwm; ch++) { + pwm = &chip->pwms[ch]; if (pwm->state.enabled) clk_disable(ddata->clk); }