Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5151098imu; Tue, 13 Nov 2018 01:53:59 -0800 (PST) X-Google-Smtp-Source: AJdET5ctFK7a6qlC+xYnKkdZfbueD2Sw4rXIRsiSadroK2uhbwKWJExWP9FTai65CcUGvUBgX6Dz X-Received: by 2002:a62:1049:: with SMTP id y70-v6mr4473118pfi.113.1542102839355; Tue, 13 Nov 2018 01:53:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542102839; cv=none; d=google.com; s=arc-20160816; b=zxY8AEJuvhy9/jfugcdEVerOVsfn4m+xYHT2VAbzGFRmzIkzKavRi+5Vc17FHjcoLw g7NUjJxmlWyCwSMvXzbTd+JOHtxbw5B+VlyPYSyDxOeHrmtajiVdRuOWs2Wt9ggL0A17 lGNjFWZm+q4Ex7z5TcwlqTObholSimLdOZ3yWOcQCfTK/zS2nCbuqjNnsdgEqvWoQj8I 7hpw1bkDI1th+3hTqe58F6IpgVFQpYsQQ5M5poDFbH5Rfm2J9aMzc1Rm/ZN5a0WA9yJ/ /H/GPhuSb/uN4Wql9RSMJxfSUDp8mg0Zv3rZMJJi0EFeu4o+NhkkB1+MvKv/KJlA4PnV DXIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=whilzAhAcYEvXgRq9ewcivop9CdGr6edD8PDipeEJo4=; b=vHM3k3xmPLdQkzwckhY3BwsiAfBBhBBhz+SzMfcCbEZs54BsVMHBFJ0QherJ2axxD/ EAzJoWwWzy4jHEsXSal11BnC+/97bm0WSk01Ijc2xIXhYQxP9sNEkEz6dCdnCcFR54IZ tRHQhpbKNqtlsysQ/8TGz1BartkdCVMJU//zUsLCUuk3cEPkYXAskIXG9sIbCGLZJCwt SZ2uv1bj9gWbDqReu5RRxTmXH+neb0FVNfVMCNs1a/WW7kvEFQ6Kq/vfICURvTU13U69 9Eqdg0UbM03aMWGoOp6N4af3aAvAHl+29+NE+k4ds4WiYG3yInvjI4sc2LRarRYK8MJm bVug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q14si19329487pgq.197.2018.11.13.01.53.44; Tue, 13 Nov 2018 01:53:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731985AbeKMTt4 (ORCPT + 99 others); Tue, 13 Nov 2018 14:49:56 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:50757 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731624AbeKMTt4 (ORCPT ); Tue, 13 Nov 2018 14:49:56 -0500 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gMVMj-0007Vp-Vh; Tue, 13 Nov 2018 10:52:13 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1gMVMg-0002fM-Q5; Tue, 13 Nov 2018 10:52:10 +0100 Date: Tue, 13 Nov 2018 10:52:10 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Ryder Lee Cc: Thierry Reding , Rob Herring , linux-pwm@vger.kernel.org, Weijie Gao , Roy Luo , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, John Crispin , kernel@pengutronix.de, linux-clk@vger.kernel.org, Michael Turquette , Stephen Boyd Subject: Re: [resend PATCH 1/3] pwm: mediatek: drop flag 'has_clks' Message-ID: <20181113095210.mh3iy5tcsu6w6tem@pengutronix.de> References: <4c9044427b1aab373acd6ac76f0c905e2be79784.1542074855.git.ryder.lee@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4c9044427b1aab373acd6ac76f0c905e2be79784.1542074855.git.ryder.lee@mediatek.com> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Tue, Nov 13, 2018 at 10:08:22AM +0800, Ryder Lee wrote: > The flag 'has_clks' and related checks are superfluous as the CCF > subsystem does this for you. I'd write instead: Handle optional clocks by using NULL as clk instead of a separate bool field in the device's platform data. There is a semantic difference this patch introduces (i.e. if on mt2712 there are no provided clocks, the driver now successfully binds while before it failed with -ENOENT. And for mt7628 it's the other way round). IMHO this should be noted in the commit log, too. Otherwise it sounds as if this patch was just an optimisation without side effects. > --- > drivers/pwm/pwm-mediatek.c | 20 +++++--------------- > 1 file changed, 5 insertions(+), 15 deletions(-) > > diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c > index eb6674c..9400c41 100644 > --- a/drivers/pwm/pwm-mediatek.c > +++ b/drivers/pwm/pwm-mediatek.c > @@ -57,7 +57,6 @@ enum { > struct mtk_pwm_platform_data { > unsigned int num_pwms; > bool pwm45_fixup; > - bool has_clks; > }; > > /** > @@ -87,9 +86,6 @@ static int mtk_pwm_clk_enable(struct pwm_chip *chip, struct pwm_device *pwm) > struct mtk_pwm_chip *pc = to_mtk_pwm_chip(chip); > int ret; > > - if (!pc->soc->has_clks) > - return 0; > - > ret = clk_prepare_enable(pc->clks[MTK_CLK_TOP]); > if (ret < 0) > return ret; > @@ -116,9 +112,6 @@ static void mtk_pwm_clk_disable(struct pwm_chip *chip, struct pwm_device *pwm) > { > struct mtk_pwm_chip *pc = to_mtk_pwm_chip(chip); > > - if (!pc->soc->has_clks) > - return; > - > clk_disable_unprepare(pc->clks[MTK_CLK_PWM1 + pwm->hwpwm]); > clk_disable_unprepare(pc->clks[MTK_CLK_MAIN]); > clk_disable_unprepare(pc->clks[MTK_CLK_TOP]); > @@ -246,12 +239,13 @@ static int mtk_pwm_probe(struct platform_device *pdev) > if (IS_ERR(pc->regs)) > return PTR_ERR(pc->regs); > > - for (i = 0; i < data->num_pwms + 2 && pc->soc->has_clks; i++) { > + for (i = 0; i < data->num_pwms + 2; i++) { > pc->clks[i] = devm_clk_get(&pdev->dev, mtk_pwm_clk_name[i]); > if (IS_ERR(pc->clks[i])) { > - dev_err(&pdev->dev, "clock: %s fail: %ld\n", > - mtk_pwm_clk_name[i], PTR_ERR(pc->clks[i])); > - return PTR_ERR(pc->clks[i]); > + if (PTR_ERR(pc->clks[i]) == -EPROBE_DEFER) > + return -EPROBE_DEFER; > + > + pc->clks[i] = NULL; I'd prefer the following instead: pc->clks[i] = devm_clk_get(&pdev->dev, mtk_pwm_clk_name[i]); if (IS_ERR(pc->clks[i])) { if (PTR_ERR(pc->clks[i]) == -ENODEV) { pc->clks[i] = NULL; } else { if (PTR_ERR(pc->clks[i]) == -EPROBE_DEFER) dev_err(...); return PTR_ERR(pc->clks[i]); } This way you only handle "There is no such clock" and are not ignoring say an IO error. I wonder if it would make sense to introduce functions like: struct clk *clk_get_optional(struct device *dev, const char *id) that return NULL instead of ERR_PTR(-ENODEV). Then the above would simplify to: pc->clks[i] = devm_clk_get_optional(&pdev->dev, mtk_pwm_clk_name[i]); if (IS_ERR(pc->clks[i]) { if (PTR_ERR(pc->clks[i]) == -EPROBE_DEFER) dev_err(...); return PTR_ERR(pc->clks[i]); } (added the clk people to Cc for this question). Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |