From patchwork Mon Aug 5 05:21:58 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: 11076031 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 626FE912 for ; Mon, 5 Aug 2019 05:23:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B05728833 for ; Mon, 5 Aug 2019 05:23:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 143DB28834; Mon, 5 Aug 2019 05:23:02 +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=ham 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 E1FDC2880D for ; Mon, 5 Aug 2019 05:23:00 +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=nBfgoUVVlABWyjN+/Fos2lwrGM9MhnCIkSqqnwiMSBI=; b=APLqkml/25rfPM X+YNpcA+FxCMqCCArccvQQvoa8s7xJtQRBt/EegL73sBGhdFe0iZ2chvXTtJpAlIh2qqsEXF4/BBj 39MQwmobwhDqpYR3tsKNbcYXD+az8GhCPWvUXa8PIJB5Ag1j95xjnqR0gBo10XzwIefE0A5uZbKxf 7MHJg82Oq3BWoIisttYJSfnjGBGOwuc9i9q7ZYjjvBF71XC26oXzpy0CpID1Rmf/XnH+JWOqlYM5w NKa+3dR9qDBHI8OtkRkzalv252Cjgxhl3eZPajau8any36XtCfFMDV1X0ozyskjfb2TyRSRCb0Gcu mnG3vbJBwwWhu/vVTi3g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1huVSW-00072A-6f; Mon, 05 Aug 2019 05:23:00 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1huVSS-00070P-U4; Mon, 05 Aug 2019 05:22:58 +0000 X-UUID: 3f3394a3f24d4f1383daa72429bfc6c2-20190804 X-UUID: 3f3394a3f24d4f1383daa72429bfc6c2-20190804 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1992297584; Sun, 04 Aug 2019 21:22:54 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Sun, 4 Aug 2019 22:22:53 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 5 Aug 2019 13:22:43 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 5 Aug 2019 13:22:43 +0800 From: Hsin-Hsiung Wang To: Lee Jones , Rob Herring , Matthias Brugger , Mark Brown Subject: [PATCH v4 10/10] rtc: Add support for the MediaTek MT6358 RTC Date: Mon, 5 Aug 2019 13:21:58 +0800 Message-ID: <1564982518-32163-11-git-send-email-hsin-hsiung.wang@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1564982518-32163-1-git-send-email-hsin-hsiung.wang@mediatek.com> References: <1564982518-32163-1-git-send-email-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-20190804_222256_977806_A17C8B72 X-CRM114-Status: GOOD ( 15.78 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 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, Kate Stewart , Sean Wang , Liam Girdwood , linux-kernel@vger.kernel.org, Richard Fontana , linux-mediatek@lists.infradead.org, Allison Randal , linux-rtc@vger.kernel.org, Thomas Gleixner , Eddie Huang , Ran Bi , Hsin-Hsiung Wang , linux-arm-kernel@lists.infradead.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. Review-by: Yingjoe Chen 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 828def7..e23c215 100644 --- a/drivers/rtc/rtc-mt6397.c +++ b/drivers/rtc/rtc-mt6397.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -19,7 +20,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) @@ -63,6 +65,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; @@ -70,7 +76,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) { @@ -78,7 +102,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; @@ -324,6 +349,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); @@ -333,6 +359,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; @@ -408,12 +441,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",