From patchwork Fri May 3 09:31:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Hsiung Wang X-Patchwork-Id: 10928165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 214E71395 for ; Fri, 3 May 2019 09:44:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 109D8284C4 for ; Fri, 3 May 2019 09:44:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04108284C8; Fri, 3 May 2019 09:44:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A40CA284C4 for ; Fri, 3 May 2019 09:44:05 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=RVvaWEis1iYl4qDNDL1dF4h9uiziroJidA1anhvPcAw=; b=dM1D0/1UdC5Zve WXqfN6+IGey56JaQtKlofo+IrNj7Ho6QpZXqLz7fU3jcC7GXSEyiDBqeNGloyu53gDAFs9pkmVOYP 5OcKVUVP0PmTkKVMwv0oy5u7Nm+Zf38BOMYzBd81h0slInvJmYSmGbqQ52dfUmePYD1DoWs9CR+Tk HMjf5LQiQD5VzDWjj3ji9CFrtaCMrVH7YcDjP+XTA2Q8jqh+GDVYDq/zfmqjRa/CsTV1GP9jQVwkK AOt/utBV4hO3KeLlHlBQNjy+VHYFXbev4DPFqB1Y4zRFGtXkTWZ4oOXAqu8arnXNqBLPZi5Co9LoZ 4GVyKWhoDG2dJ56cHLbA==; 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 1hMUjT-0000VU-2Q; Fri, 03 May 2019 09:43:55 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMUYs-0001LH-As; Fri, 03 May 2019 09:33:03 +0000 X-UUID: cca1d406c30147c4b7b1f2286389dcaa-20190503 X-UUID: cca1d406c30147c4b7b1f2286389dcaa-20190503 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1019782503; Fri, 03 May 2019 01:32:53 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 3 May 2019 02:32:52 -0700 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 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 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190503_023258_709041_2F9BC012 X-CRM114-Status: GOOD ( 15.64 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Alessandro Zummo , Alexandre Belloni , srv_heupstream@mediatek.com, devicetree@vger.kernel.org, Ran Bi , Sean Wang , Liam Girdwood , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Eddie Huang , Hsin-Hsiung Wang , linux-rtc@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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",