Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5984436imu; Mon, 21 Jan 2019 00:53:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN6HxN4Is85+v80qhm+dD4b67xrLSzy9bUMe6R7GtA/um10cJAaKLNdML6QLISCMtxfecouD X-Received: by 2002:a62:2e46:: with SMTP id u67mr28466145pfu.3.1548060782236; Mon, 21 Jan 2019 00:53:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548060782; cv=none; d=google.com; s=arc-20160816; b=fALz8m4C9Ai/jZa3sBr8sI2Hj0UdNNy+sFAlfRtn/gCJN5CX8HX5rdvxTbpfDiCzJL tFG7JKyQS3Xf/p/f/0qogZ4v2pu3t7C1qPJTpSbbB2yfF4ZioZMKoHj/XvfrqK0O2gn5 wVfAHxEGBHUOITBzzRYbywH5l5No9yK1JJHRed7qbQO+osgb3OSn6TDrzOi08SGCf8DM YxnGcEEJEbTMSXZoEqUkV9OpJHb/e7eFP+BB2ziidhfrNECps/QDpQNTWw3kWr2nGJhU KbQJ/TDCNoAVNVkUVz6aBYJ8I/y6KQA2kIdbOqPyMVZ7mx09FA2dJDsIhPImXMG6Quh/ U0kw== 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=TYgJ7hnH6dV1jLs0pi2gFyd490OZGfoTayxI7MEwYIs=; b=gD/RdoivKx2/Pu7mKILzvaPW2wnqeV6FUoPTCaHeD0blPHaHFphE9B+SlKQB2vJNvi jO8p94/fOUhgiA4TAfk27huq3oyPMbS9BKxBdKWWt9xrGSGehikE+baOUaMbYybNjXwI eprafjwtrZ7GvGaRDuDUn1pp4NWB8XNjzT8XTMBJ9RYpWwax0fWuQAFhYyWRdEn5o7Gq Ng1NlIQlpFDVonRBdrEx6/uXejm8GqZhuFmHAcUXAZ1lQJvAUuahu0BRiUr+TffI+wAb xeWoI6t9IaFVY+gEEJpHRItPv+OkslUtlPVjhXO+RKIHySiciAGX8Sn6JhTtalkN8HRS 8OcA== 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 l14si11061849pgi.147.2019.01.21.00.52.46; Mon, 21 Jan 2019 00:53:02 -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 S1729804AbfAUIt6 (ORCPT + 99 others); Mon, 21 Jan 2019 03:49:58 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:56065 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729757AbfAUIt5 (ORCPT ); Mon, 21 Jan 2019 03:49:57 -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 1glVHB-0003tK-74; Mon, 21 Jan 2019 09:49:49 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1glVHA-0000YN-GN; Mon, 21 Jan 2019 09:49:48 +0100 Date: Mon, 21 Jan 2019 09:49:48 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Ryder Lee Cc: Matthias Brugger , Thierry Reding , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, Sean Wang , Weijie Gao , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v1 1/5] pwm: mediatek: add a property "mediatek,num-pwms" Message-ID: <20190121084948.frpcgg6wkdjxkl7k@pengutronix.de> References: <1547866487.14213.10.camel@mtkswgap22> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1547866487.14213.10.camel@mtkswgap22> 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 On Sat, Jan 19, 2019 at 10:54:47AM +0800, Ryder Lee wrote: > 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). I guess he means something like: if (is_compatible_to_variant_A(dev)) num_pwms = 12; else if (is_compatible_to_variant_B(dev)) num_pwms = 2; . In my eyes the bike shed should be light red and I prefer to collect the fallback num_pwms in the compatible_data as is to keep the code simpler. Maybe rename the member from num_pwms to fallback_num_pwms to make it more obvious that it doesn't represent the actually used value. > > 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. My suggestion was to add a dev_warn, which IMHO is still better than a comment. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |