Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3827387imu; Fri, 18 Jan 2019 18:57:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN55+cz2SjwBiqliPbZ+PsdbFLEy2Ow9xDP+AspCdD1BTSYXwDBtK6bbtG4OktOtbQijRysr X-Received: by 2002:a17:902:7588:: with SMTP id j8mr21815069pll.215.1547866638235; Fri, 18 Jan 2019 18:57:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547866638; cv=none; d=google.com; s=arc-20160816; b=hc2j7fOz5NH812S7XtxCVWD0v9zdxGJSMqW0eFjHekFrgwBoA2Zpr9G9pmz+25guCQ rpcTD2JEYQXnT2zLBcQ39WhJx65WNgB/sDpmwuK4kfSFVxK6PynW14A9yLZAaD59PvXT opHIlb7X/E/U3ByMwMSpsaSjMX1ZobnkHmrDR/ephnXkXmqs2QE+Uw81tWyRQNu4K/cW vo/278mvT6sjAKtXwzsye8WMQ1Aj9VtaZ3cMLswlqUU1RYabYo8Lp8OLDEzeEqMvHkYK W1oHiWWdQKEFlWDSJNcR3Cmbs9LONWVWDdQ3XeLsuD2M9mW+hQgIIkeggdjgaaC9dUOd C6Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id; bh=C4o/bSv7fsDSnnFchsqp8L82MS0TfoTv3pQltKd3GOM=; b=XW4Khcx0U1Z7zlz2NepjYqwKqmu280x3Zoxm9Ctq4ZHhVN3mPduat7PhPrvvH898ii kkws2gEEGSxtW7Ef2UlNmKAVHDjEfrc4jIEQWY1bQ4tDGEKowNyIAbaMwehI9EzWhlpL 8V8/m4b2ml3s3eEbtn5+4EuK0XbqoyWmb3C5/d047EDDaXcwv06Jzsrs1h7gu6xlzmeA 5Kd1ANHSAs6+Wmy/cWtoq7ymgN4wjhY86fQMwoGSy0jkYHArspkEXNX4joexLLalLdCU 98wC4/IOKVHX5O+kULPsSyGGaLExSFX3XXvVAdHd/0ItCiZUYdSk2fDjSxnqYRSXTGgI ii1g== 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 s11si6714267pgi.324.2019.01.18.18.56.46; Fri, 18 Jan 2019 18:57:18 -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 S1730390AbfASCy4 (ORCPT + 99 others); Fri, 18 Jan 2019 21:54:56 -0500 Received: from mailgw02.mediatek.com ([1.203.163.81]:53964 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729963AbfASCyz (ORCPT ); Fri, 18 Jan 2019 21:54:55 -0500 X-UUID: f327d05bb91348bb9364fa396c7f6d65-20190119 X-UUID: f327d05bb91348bb9364fa396c7f6d65-20190119 Received: from mtkcas35.mediatek.inc [(172.27.4.250)] by mailgw02.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLS) with ESMTP id 945006064; Sat, 19 Jan 2019 10:54:49 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by MTKMBS31N1.mediatek.inc (172.27.4.69) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Sat, 19 Jan 2019 10:54:47 +0800 Received: from [172.21.77.33] (172.21.77.33) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Sat, 19 Jan 2019 10:54:48 +0800 Message-ID: <1547866487.14213.10.camel@mtkswgap22> Subject: Re: [PATCH v1 1/5] pwm: mediatek: add a property "mediatek,num-pwms" From: Ryder Lee To: Matthias Brugger CC: Thierry Reding , , , Sean Wang , Weijie Gao , , , Date: Sat, 19 Jan 2019 10:54:47 +0800 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2019-01-18 at 09:43 +0100, Matthias Brugger wrote: > > On 18/01/2019 04:24, Ryder Lee wrote: > > This adds a property "mediatek,num-pwms" to avoid having an endless > > list of compatibles with no differences for the same driver. > > > > Thus, the driver should have backwards compatibility to older DTs. > > > > Signed-off-by: Ryder Lee > > --- > > Changes since v1: add some checks for backwards compatibility. > > --- > > drivers/pwm/pwm-mediatek.c | 27 ++++++++++++++++++--------- > > 1 file changed, 18 insertions(+), 9 deletions(-) > > > > diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c > > index eb6674c..81b7e5e 100644 > > --- a/drivers/pwm/pwm-mediatek.c > > +++ b/drivers/pwm/pwm-mediatek.c > > @@ -55,7 +55,7 @@ enum { > > }; > > > > struct mtk_pwm_platform_data { > > - unsigned int num_pwms; > > + unsigned int num_pwms; /* it should not be used in the future SoCs */ > > bool pwm45_fixup; > > bool has_clks; > > }; > > @@ -226,27 +226,36 @@ static void mtk_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) > > > > static int mtk_pwm_probe(struct platform_device *pdev) > > { > > - const struct mtk_pwm_platform_data *data; > > + struct device_node *np = pdev->dev.of_node; > > struct mtk_pwm_chip *pc; > > struct resource *res; > > - unsigned int i; > > + unsigned int i, num_pwms; > > int ret; > > > > pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); > > if (!pc) > > return -ENOMEM; > > > > - data = of_device_get_match_data(&pdev->dev); > > - if (data == NULL) > > - return -EINVAL; > > - pc->soc = data; > > + pc->soc = of_device_get_match_data(&pdev->dev); > > > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > pc->regs = devm_ioremap_resource(&pdev->dev, res); > > if (IS_ERR(pc->regs)) > > return PTR_ERR(pc->regs); > > > > - for (i = 0; i < data->num_pwms + 2 && pc->soc->has_clks; i++) { > > + /* Check if we have set 'num-pwms' in DTs. */ > > + ret = of_property_read_u32(np, "mediatek,num-pwms", &num_pwms); > > + if (ret < 0) { > > + /* If no, fallback to use SoC data for backwards compatibility. */ > > + if (pc->soc->num_pwms) { > > + num_pwms = pc->soc->num_pwms; > > Maybe that's bike shedding, but I think it would be better to carve out the > num_pwms from the mtk_pwm_platform_data and check against the compatible here. I'm not sure how to properly curve it out? I think we still need this variable to save the specific value for some legacy SoCs (with older DTs). > With a expressive comment it will help other driver developers to not start > adding num_pwms in the platform data in their first attempt. Definitely. Ryder > > > + } else { > > + dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret); > > + return ret; > > + } > > + } > > + > > + for (i = 0; i < num_pwms + 2 && pc->soc->has_clks; 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", > > @@ -260,7 +269,7 @@ static int mtk_pwm_probe(struct platform_device *pdev) > > pc->chip.dev = &pdev->dev; > > pc->chip.ops = &mtk_pwm_ops; > > pc->chip.base = -1; > > - pc->chip.npwm = data->num_pwms; > > + pc->chip.npwm = num_pwms; > > > > ret = pwmchip_add(&pc->chip); > > if (ret < 0) { > >