Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp638444ybl; Wed, 14 Aug 2019 03:45:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyc/jaQ6v4D5NGCIb9v50hn3dtNKiAcXnO21kYA5YgMmOc55Lw/aPHTpZoMM11e1HzFpXJt X-Received: by 2002:a17:90a:974c:: with SMTP id i12mr6679492pjw.12.1565779515275; Wed, 14 Aug 2019 03:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565779515; cv=none; d=google.com; s=arc-20160816; b=ncVX8SudbxhwYE04vkxIWYFn/9TQADMc65hSoSJ7Kp279dJZub13VedfPdBfuoYAmM Od4svrG+KWRZHdJaQRKDaUR94qKmJWt5Q6AEYc4bFhJvR1DhDVPp4ENW6WJsw4bH0OnZ 3wqfHcQhdG8ZO70rthwrqWqC96/X/I4MNL4Zv0pqki24IPwnStVjfzfO0F3D5o2tOdHM rUTisgc1ylXfmLSrMEaU+1etsZdGVHRB8mrIcapKwCzzCF22o5AYLgXuCO1kRyQRDoDK qxEV8owMmV0roLiteUXSq8/n+9IGqQem/6Wm90QE+IJhqtalTncL7PnU6U3ICXMacYes 4YKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=Sw//lXatyCs9W5u4uL3dadChbFUd0DzSGBZAhxA3yg4=; b=Ek7lSgHlExByXS0WS2CCKt3ra/DSKMdgi4wxL85Yl8fldPqZ1EMfHyvCLrF39WYUwa dj3RJeH3fOaBF3BuaSp8TS7Yxheey9fiDeDmDRKl8TCcQvUIj9JTo9D4lD6n52v5PhfS df+oF/Mp0haXrZE+vsVQdW0WayAbmlBvnvkzfZZckKEW/9xi/PPBgy9+ijNJM+eDc6Zr UDG9dQn/ht7SLE2JEwkdw8JrWZFAIMhFWPQUNGaluAHAbN7xuZScvRAtqGDoK0JQAqG7 TSue6be1zeUvv0qQ2Fr94N7TKVy2tBjn7buu/c3cquByRo2GkUkrw5rxZHPHLBQQ1q3d ie5w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j25si66481719pfr.11.2019.08.14.03.44.58; Wed, 14 Aug 2019 03:45:15 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727220AbfHNKoR (ORCPT + 99 others); Wed, 14 Aug 2019 06:44:17 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:50282 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726265AbfHNKoP (ORCPT ); Wed, 14 Aug 2019 06:44:15 -0400 X-UUID: 0a008f327833440c839a7017977fb0af-20190814 X-UUID: 0a008f327833440c839a7017977fb0af-20190814 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0707 with TLS) with ESMTP id 356022096; Wed, 14 Aug 2019 18:44:06 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 14 Aug 2019 18:44:01 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 14 Aug 2019 18:44:02 +0800 From: Sam Shih To: Rob Herring , Mark Rutland , Matthias Brugger , Thierry Reding CC: Ryder Lee , John Crispin , , , , , Sam Shih Subject: [PATCH v2 1/10] pwm: mediatek: add a property "num-pwms" Date: Wed, 14 Aug 2019 18:43:31 +0800 Message-ID: <621e49c01b943edb6ddac9182f34719eb0727f01.1548313019.git.ryder.lee@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: C210467220D08AB4A2720086E49BB2C845657508C5D2C45C5876C5C23677EC2D2000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ryder Lee This adds a property "num-pwms" to avoid having an endless list of compatibles with no differences for the same driver. Signed-off-by: Ryder Lee Signed-off-by: Sam Shih --- Used: https://patchwork.kernel.org/project/linux-mediatek/list/?series=68207 Changes since v2: - use num-pwms instead of mediatek,num-pwms. - rename the member from num_pwms to fallback_num_pwms to make it more obvious that it doesn't represent the actually used value. - add a dev_warn and a expressive comment to help other developers to not start adding num_pwms in the compatible_data. Changes since v1: - add some checks for backwards compatibility. --- drivers/pwm/pwm-mediatek.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c index eb6674c..f9d67fb 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 fallback_npwms; 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, npwms; 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++) { + ret = of_property_read_u32(np, "num-pwms", &npwms); + if (ret < 0) { + /* It's deprecated, we should specify num_pwms via DT now. */ + if (pc->soc->fallback_npwms) { + npwms = pc->soc->fallback_npwms; + dev_warn(&pdev->dev, "DT is outdated, please update it\n"); + } else { + dev_err(&pdev->dev, "failed to get number of PWMs\n"); + return ret; + } + } + + for (i = 0; i < npwms + 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 = npwms; ret = pwmchip_add(&pc->chip); if (ret < 0) { @@ -279,25 +288,25 @@ static int mtk_pwm_remove(struct platform_device *pdev) } static const struct mtk_pwm_platform_data mt2712_pwm_data = { - .num_pwms = 8, + .fallback_npwms = 8, .pwm45_fixup = false, .has_clks = true, }; static const struct mtk_pwm_platform_data mt7622_pwm_data = { - .num_pwms = 6, + .fallback_npwms = 6, .pwm45_fixup = false, .has_clks = true, }; static const struct mtk_pwm_platform_data mt7623_pwm_data = { - .num_pwms = 5, + .fallback_npwms = 5, .pwm45_fixup = true, .has_clks = true, }; static const struct mtk_pwm_platform_data mt7628_pwm_data = { - .num_pwms = 4, + .fallback_npwms = 4, .pwm45_fixup = true, .has_clks = false, }; -- 1.9.1