From patchwork Wed Feb 14 09:32:03 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: 13556208 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 63AE3C48BEB for ; Wed, 14 Feb 2024 09:41:46 +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=E5DwCA2F1ajNwbamzHudfue6jWy9/YZl6Uoxfmm8WWI=; b=lkOV+Z2dY4hvRY 3xH+9X3G3g7HhYhDi9cI9op9ldDehytOqxrwfmFsVIZ+yauiDUMpM5P8QYAVm9ZTns3B8a4jlvgRq ILqiIKx5bARVPjc2L08YmOsNH9NNhU6eLzAnAlaspWpSCf3auKVS7wefVbtCT4xOcJ7PJg7L7r+hx XAxHXRblGC15UnxowDIbXT1OMGw3B2zUcRuRQwikr77D2yEeTmkbOTrLH5AwAAIQSn4FLNG1SdERO oSynLnUuF2n7JIlc1HLQxzI5DbJrVKqP1D/1S0Ds9aWPZRUM59FOqR+Qb3F3sU7iUDUB00MZKuwhd jPHEtWIiz2Bp5yk/Qnkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raBll-0000000CPRG-49K2; Wed, 14 Feb 2024 09:41:34 +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 1raBfJ-0000000CKe7-0fKu for linux-arm-kernel@bombadil.infradead.org; Wed, 14 Feb 2024 09:34:53 +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=uixPPOrgUYEQZA1oMU3R/Fh5vj7TchLmGyW+OZ9eafA=; b=SpEexI+GxKwXdTXjUh5y80ZuE3 3+ZSUTEHb0Q7xnYNVSBw9HsSbsTyCCbcTL5WJ939f9GJCnVC5EloYvwWygC1O3He7ooJ30SjNjdpn 9QHwYycgFvsQT/WI9gMHsrSy33TiIrvoxT3hgg/fZlLM05DICsjsNC3kCNHwMey+f4KkOSLVz05ut AmxElaRai2TXgvg8OO7s+ZkfAvuEsNX89pWv2mJiUp+RHSxwJmJQMPrugmri5QlB7x6eBP+rw/P5w SCmo+k1M0BkOSSw6SmekI76ZLpd2UbgVhiZkctsQGEztbxHG9yT3aqsRZeeVXjttMnU/A30kbtr1J wTcGBxOw==; 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-0000000GAX8-28pD for linux-arm-kernel@lists.infradead.org; Wed, 14 Feb 2024 09:34:51 +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-0005BL-OR; 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-000fDT-Nj; 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-004Y4t-26; Wed, 14 Feb 2024 10:34:29 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Shawn Guo , Sascha Hauer , linux-pwm@vger.kernel.org Cc: Fabio Estevam , NXP Linux Team , linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de Subject: [PATCH v6 076/164] pwm: mxs: Make use of devm_pwmchip_alloc() function Date: Wed, 14 Feb 2024 10:32:03 +0100 Message-ID: <39203f3bfbf4e97654db78bdc7e0c9a2b72c1368.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=2683; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=J7Q/ySzr1SnXL3Xb1UpGW2qKuGEU0uAEaDqOHNNsQbA=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlzIiienos8NlNA5Wn/vmFIeeF8BMW+W6L88TKE 3qMZVd0uxmJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZcyIogAKCRCPgPtYfRL+ Ts4GB/9mAH5SxUERaXpyeeyvLUo9MhJvj2z0zVnOmGuX5KEtIaKdnf8f/F8f60rXPh2aWZh0AeC vJyCpvuEfUlfxQPcS0TKg0m7BR3RfTCkUL++bwc3bLYEfBKTZIyjZKvedBsrtMUT22czjnpsu50 MT0T8Gc4xApTZGZOxHRDc5evC+4LO4sN7oQzk3pna0nCuAAgbQL4toY0gNGOZXbYdNG2eBB9e36 TxstaeBg6h0pOkTrA6kuK5sSoembDzIJV5XaJkzbeDaXUp/PU7giQDpOLxleOdZv+aHwD098zVL uJVjmjWu/0kahulP8zD7VTtQX6SbDmnUbnKrgutvF39ESc8Z 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-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_093447_867447_62277A5F X-CRM114-Status: GOOD ( 17.12 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This prepares the pwm-mxs 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. Also convert the to_mxs_pwm_chip() helper macro to a static inline to get some type safety. Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-mxs.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c index 1b5e787d78f1..8cad214b1c29 100644 --- a/drivers/pwm/pwm-mxs.c +++ b/drivers/pwm/pwm-mxs.c @@ -37,12 +37,14 @@ static const u8 cdiv_shift[PERIOD_CDIV_MAX] = { }; struct mxs_pwm_chip { - struct pwm_chip chip; struct clk *clk; void __iomem *base; }; -#define to_mxs_pwm_chip(_chip) container_of(_chip, struct mxs_pwm_chip, chip) +static inline struct mxs_pwm_chip *to_mxs_pwm_chip(struct pwm_chip *chip) +{ + return pwmchip_get_drvdata(chip); +} static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) @@ -120,12 +122,21 @@ static const struct pwm_ops mxs_pwm_ops = { static int mxs_pwm_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; + struct pwm_chip *chip; struct mxs_pwm_chip *mxs; + u32 npwm; int ret; - mxs = devm_kzalloc(&pdev->dev, sizeof(*mxs), GFP_KERNEL); - if (!mxs) - return -ENOMEM; + ret = of_property_read_u32(np, "fsl,pwm-number", &npwm); + if (ret < 0) { + dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret); + return ret; + } + + chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*mxs)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + mxs = to_mxs_pwm_chip(chip); mxs->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(mxs->base)) @@ -135,21 +146,14 @@ static int mxs_pwm_probe(struct platform_device *pdev) if (IS_ERR(mxs->clk)) return PTR_ERR(mxs->clk); - mxs->chip.dev = &pdev->dev; - mxs->chip.ops = &mxs_pwm_ops; - - ret = of_property_read_u32(np, "fsl,pwm-number", &mxs->chip.npwm); - if (ret < 0) { - dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret); - return ret; - } + chip->ops = &mxs_pwm_ops; /* FIXME: Only do this if the PWM isn't already running */ ret = stmp_reset_block(mxs->base); if (ret) return dev_err_probe(&pdev->dev, ret, "failed to reset PWM\n"); - ret = devm_pwmchip_add(&pdev->dev, &mxs->chip); + ret = devm_pwmchip_add(&pdev->dev, chip); if (ret < 0) { dev_err(&pdev->dev, "failed to add pwm chip %d\n", ret); return ret;