From patchwork Thu Jan 25 12:09: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: 13530874 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 23D38C47258 for ; Thu, 25 Jan 2024 14:07: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=bJqtg7+LM2P3eOGciaOzpZUHDpnAvu3LjFZWYSicnxk=; b=mGJet/osw7+Xvt 2LfgJXtm5H5bAWCVYAQDYNbeToiQpg3/olziz1AyJMCLf/wfPdNoxyPVbEeyc+2kRhQNjUc7ufT/j QRCTCV2yBnB5+jWDjOYchh9O+xsek4gh2WuEyzBpjEmNVYp6MP8P5+QHd90wHD3AiNH+6g3lQve36 vM9L0wOcMr5ZkjRqzwbt4X0Wp32TBMwfH/MuDeE6M2zm10TNVG65kQdrmOAHxi5c1jEImx7ulzuH2 9Kzy9l/w2IvcFwHVeoBDAQPuLkGaccoh5v9I130o3XO0AQCyA3WQq/Ad0Ax7+5jRC7u6SJEekbZUb 8ciCvOfGkZLITOS5Li/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT0OB-00000000EZ5-1yOg; Thu, 25 Jan 2024 14:07:31 +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 1rT0O8-00000000EVS-1ed9 for linux-riscv@bombadil.infradead.org; Thu, 25 Jan 2024 14:07:28 +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=Bn9kDxJy1pO+sAPG8zXCttMRlxzUXx0A9P02WuS+FmQ=; b=uGO+f4b9l2uaJ4ioq9kCrlVExt ZzIGkpIKud4QboztoZ6Mmn/JenNaQRhXuVcCR4BojLaQMRTaGssuC/XSjDeArknWUrp5s7ERefIp4 2t0fYu5th1X8AWP1aCxTlxSYfFUODmuIV0d38L406q6h1AMV7/ro4rzx1fdfGpg8XUYD+AVIZFZp+ n+YF3+ouVho+hiJaNCana6DIHK78v1Jjt1pVIET7FQkEKkfMMxwHtpPCvUd96HE/jOwh9RCVY48x6 9lMTL25GQro5veJjnidvW+nbioLuCCA74WaZJeWXMuAjqeCCgrVXJFYwKw0/E867WpHs3sFxekl7m wuLl1vkg==; 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 1rSybZ-00000009sDU-3CHw for linux-riscv@lists.infradead.org; Thu, 25 Jan 2024 12:13:21 +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 1rSyZO-0004X2-Fs; Thu, 25 Jan 2024 13:10:58 +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 1rSyZM-002HUF-Pb; Thu, 25 Jan 2024 13:10:56 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rSyZM-007n3s-2J; Thu, 25 Jan 2024 13:10:56 +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 v5 086/111] pwm: sifive: Make use of devm_pwmchip_alloc() function Date: Thu, 25 Jan 2024 13:09:48 +0100 Message-ID: <1758e7c75c4a573c01e430c4b13619b5ee11ca11.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=3195; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=KJEuGC/52+vOnMm9CNKDLGMayPv+GmDgxwikRzww63k=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlsk+fXRBe1dlXQzxd4bAHXKAnQxtLUVnGVrumk 3H6DoKuetCJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZbJPnwAKCRCPgPtYfRL+ Tro8CACrgRebmLSi4QmerWXLYIeCpCfjEBL/pkMgGZM5Q0yNcJn8W81vn0uUa4tMK0BD6Czsbjk HgnPcx8kkl0sIJhZC1CdVWQkdjaOIeU1zvSd/BdBJcMraVsqupJQh4Xl5Fsd1MNKlyNVhv0XVmQ NsLKWVuJv8ey5LNOkdsPsO5IxKiZKCJU60i1wb13+0vxBH3XAUxWxmG6RNlf+hQjwh01yE2Wi1E joE31JHn2W53hzluHlc13jJClBQ9uSfhu0ql18L+vwZR+3ef0TGDgsUTPfY+mr/OVKWNpQcC5+v pq+fWS+ubX73ivgYKYIF+WO2DiQKDkETtvsD5JF416U8ORON 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-20240125_121315_203580_2CDFB43A X-CRM114-Status: GOOD ( 12.56 ) 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 pwm-sifive 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-sifive.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index c1b412905d9e..cf3fcffe7b3a 100644 --- a/drivers/pwm/pwm-sifive.c +++ b/drivers/pwm/pwm-sifive.c @@ -41,7 +41,7 @@ #define PWM_SIFIVE_DEFAULT_PERIOD 10000000 struct pwm_sifive_ddata { - struct pwm_chip chip; + struct pwm_chip *chip; struct mutex lock; /* lock to protect user_count and approx_period */ struct notifier_block notifier; struct clk *clk; @@ -54,7 +54,7 @@ struct pwm_sifive_ddata { static inline struct pwm_sifive_ddata *pwm_sifive_chip_to_ddata(struct pwm_chip *chip) { - return container_of(chip, struct pwm_sifive_ddata, chip); + return pwmchip_get_drvdata(chip); } static int pwm_sifive_request(struct pwm_chip *chip, struct pwm_device *pwm) @@ -102,7 +102,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(pwmchip_parent(&ddata->chip), + dev_dbg(pwmchip_parent(ddata->chip), "New real_period = %u ns\n", ddata->real_period); } @@ -230,15 +230,14 @@ static int pwm_sifive_probe(struct platform_device *pdev) u32 val; unsigned int enabled_pwms = 0, enabled_clks = 1; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); - if (!ddata) - return -ENOMEM; + chip = devm_pwmchip_alloc(dev, 4, sizeof(*ddata)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + ddata = pwm_sifive_chip_to_ddata(chip); + ddata->chip = chip; mutex_init(&ddata->lock); - chip = &ddata->chip; - chip->dev = dev; chip->ops = &pwm_sifive_ops; - chip->npwm = 4; ddata->regs = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(ddata->regs)) @@ -296,7 +295,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 +313,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); }