Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp326468yba; Fri, 3 May 2019 02:36:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyf7tcYjLB9lBe60z8zk2X3XRUUm6EwxNp0AIAsw/0ffZj0DESVPeTJCyN8HrZNm/xYwcqa X-Received: by 2002:a65:5181:: with SMTP id h1mr9086362pgq.167.1556876176812; Fri, 03 May 2019 02:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556876176; cv=none; d=google.com; s=arc-20160816; b=NJPirYE8Og9yJijkvrEILEC/x5xXTtNiB8yawI7yQ1rJxGvugX08mswCdJC01SwWxB aYvBId6r5AqHHSVnTENwxLE8Mxi/7BKOUGqw9uBzXgWey6B1AbJpba2VkizsOagYH7Wy knvNz+Z3wQzVvRhf/ORSgEmxuhtcqbPiP/wVxtKnGiS5wElHsi9UlX0HiO9JqY4lJq+Q gPVNvrsJNEj/XjvKYj+Ed795JyzPFPgoXPFsTE96VS3Qe4JnntMEPTSxdeoiYtsHtO+V 0ywEVwtWJA4YcRoQE8z9Ok2Z6w6ent7PVK/59iekyhbdh3uyVW2CtcGOPdsWN4tnNQC/ 8oyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=6zzq1bK8/1KjxCCS2XINuDFBTkdmUrINR9pm3C0kMtc=; b=0shm+8BWBSA6/TWsFjjW+8iPWhRWQxikOA6etFzciJLbRo1o07D6AQXzWXBHfGZgEB eKyLlR+fpEhyigcmBntJTu2Y3nvV2pYarvKwhNd2b3R9U3Upg5k7HovwWdJkwrakzxfe 1Ow2XSRmFFD2dvttsLDLBkI4QZGeOeqSDONy6C4XfFPoU8P4Jt4Ap3bz8yLcOIrBjZ+i b/DLTyidMRyRwChTOrTYT7YdWCCuEmA8qiNjC9bsIeXzy7swtkt2L4GYfUJ63xnQkFDL O/5cGh0ZYpUwgf5KPjvDLQ2dHrqHr+XAqP1atLE6YBNCgkP1YSPGfaQdN1EADgI6ARTd WzUA== 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 73si1597758pgb.414.2019.05.03.02.36.01; Fri, 03 May 2019 02:36:16 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727532AbfECJdI (ORCPT + 99 others); Fri, 3 May 2019 05:33:08 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:24171 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727474AbfECJdB (ORCPT ); Fri, 3 May 2019 05:33:01 -0400 X-UUID: 1f96bc06db644d2c84d2a755c9dc402a-20190503 X-UUID: 1f96bc06db644d2c84d2a755c9dc402a-20190503 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1390216758; Fri, 03 May 2019 17:32:50 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 3 May 2019 17:32:41 +0800 Received: from mtkslt302.mediatek.inc (10.21.14.115) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 3 May 2019 17:32:41 +0800 From: Hsin-Hsiung Wang To: Lee Jones , Rob Herring , Mark Brown , Matthias Brugger CC: Liam Girdwood , Mark Rutland , Eddie Huang , Sean Wang , Alessandro Zummo , Alexandre Belloni , Hsin-Hsiung Wang , , , , , , , Ran Bi Subject: [PATCH v3 10/10] rtc: Add support for the MediaTek MT6358 RTC Date: Fri, 3 May 2019 17:31:17 +0800 Message-ID: <20190503093117.54830-11-hsin-hsiung.wang@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190503093117.54830-1-hsin-hsiung.wang@mediatek.com> References: <20190503093117.54830-1-hsin-hsiung.wang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ran Bi This add support for the MediaTek MT6358 RTC. Driver using compatible data to store different RTC_WRTGR address offset. Signed-off-by: Ran Bi --- drivers/rtc/rtc-mt6397.c | 43 ++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c index f85f1fc29e32..3476e29db87c 100644 --- a/drivers/rtc/rtc-mt6397.c +++ b/drivers/rtc/rtc-mt6397.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,8 @@ #define RTC_BBPU 0x0000 #define RTC_BBPU_CBUSY BIT(6) -#define RTC_WRTGR 0x003c +#define RTC_WRTGR_MT6358 0x3a +#define RTC_WRTGR_MT6397 0x3c #define RTC_IRQ_STA 0x0002 #define RTC_IRQ_STA_AL BIT(0) @@ -71,6 +73,10 @@ #define RTC_NUM_YEARS 128 #define RTC_MIN_YEAR_OFFSET (RTC_MIN_YEAR - RTC_BASE_YEAR) +struct mtk_rtc_compatible { + u32 wrtgr_addr; +}; + struct mt6397_rtc { struct device *dev; struct rtc_device *rtc_dev; @@ -78,7 +84,25 @@ struct mt6397_rtc { struct regmap *regmap; int irq; u32 addr_base; + const struct mtk_rtc_compatible *dev_comp; +}; + +static const struct mtk_rtc_compatible mt6358_rtc_compat = { + .wrtgr_addr = RTC_WRTGR_MT6358, +}; + +static const struct mtk_rtc_compatible mt6397_rtc_compat = { + .wrtgr_addr = RTC_WRTGR_MT6397, +}; + +static const struct of_device_id mt6397_rtc_of_match[] = { + { .compatible = "mediatek,mt6358-rtc", + .data = (void *)&mt6358_rtc_compat, }, + { .compatible = "mediatek,mt6397-rtc", + .data = (void *)&mt6397_rtc_compat, }, + {} }; +MODULE_DEVICE_TABLE(of, mt6397_rtc_of_match); static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc) { @@ -86,7 +110,8 @@ static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc) int ret; u32 data; - ret = regmap_write(rtc->regmap, rtc->addr_base + RTC_WRTGR, 1); + ret = regmap_write(rtc->regmap, + rtc->addr_base + rtc->dev_comp->wrtgr_addr, 1); if (ret < 0) return ret; @@ -332,6 +357,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) struct resource *res; struct mt6397_chip *mt6397_chip = dev_get_drvdata(pdev->dev.parent); struct mt6397_rtc *rtc; + const struct of_device_id *of_id; int ret; rtc = devm_kzalloc(&pdev->dev, sizeof(struct mt6397_rtc), GFP_KERNEL); @@ -341,6 +367,13 @@ static int mtk_rtc_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); rtc->addr_base = res->start; + of_id = of_match_device(mt6397_rtc_of_match, &pdev->dev); + if (!of_id) { + dev_err(&pdev->dev, "Failed to probe of_node\n"); + return -EINVAL; + } + rtc->dev_comp = of_id->data; + rtc->irq = platform_get_irq(pdev, 0); if (rtc->irq < 0) return rtc->irq; @@ -419,12 +452,6 @@ static int mt6397_rtc_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_rtc_suspend, mt6397_rtc_resume); -static const struct of_device_id mt6397_rtc_of_match[] = { - { .compatible = "mediatek,mt6397-rtc", }, - { } -}; -MODULE_DEVICE_TABLE(of, mt6397_rtc_of_match); - static struct platform_driver mtk_rtc_driver = { .driver = { .name = "mt6397-rtc", -- 2.18.0