From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D033EC43387 for ; Fri, 18 Jan 2019 03:25:18 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8EA102086D for ; Fri, 18 Jan 2019 03:25:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="vB4WlZHd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8EA102086D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=MbhS/VCD6tWSEF/Cy9/t1/BKC1ofjNpwKDj2O/7f+PM=; b=vB4WlZHdKDX46P LF/kRos9v75si7amVydUJ+rB1KHLW6m6hVeVlfbttGUgC8NP+DmW+a2rKr6oH+Jws4ZzWA61AruAG 4GvyPIZwflx3DaKaBRF6iMRUc5LHXLctTMNIIHBDrlwQOhEH5wnpu/QCBEyXessIE4ZPZtj84vpSa 0fvVxAqZYMdfT+SsHxmNumy9nVFSlz6q97udgyyJvrVUl1UM+nas8EM+6r5MNJ1M0GL+9vyq71kMp 5HcqXCP+h1BnU4FVn8KLBZ9uEV7G5lHSPBX2gbWsPSO4Gs3x6+K3RG3DtxYgJf2/0Lyc2O1gfX4hj 7Z+qedYI1pHt/bwwd3uQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkKmP-0002bJ-H2; Fri, 18 Jan 2019 03:25:13 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkKm6-0001nu-E6; Fri, 18 Jan 2019 03:24:56 +0000 X-UUID: 62bef760d384434d8a55d888766391ed-20190117 X-UUID: 62bef760d384434d8a55d888766391ed-20190117 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 856093635; Thu, 17 Jan 2019 19:24:50 -0800 Received: from mtkmbs08n1.mediatek.inc (172.21.101.55) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 17 Jan 2019 19:24:48 -0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 18 Jan 2019 11:24:47 +0800 Received: from mtkslt306.mediatek.inc (10.21.14.136) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 18 Jan 2019 11:24:47 +0800 From: Ryder Lee To: Thierry Reding Subject: [PATCH v1 1/5] pwm: mediatek: add a property "mediatek,num-pwms" Date: Fri, 18 Jan 2019 11:24:41 +0800 Message-ID: X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190117_192454_490943_30D2B142 X-CRM114-Status: GOOD ( 13.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, Ryder Lee , devicetree@vger.kernel.org, Sean Wang , Weijie Gao , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; + } 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) { -- 1.9.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel