From patchwork Wed Mar 27 01:02:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 10872367 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 CD854139A for ; Wed, 27 Mar 2019 01:02:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B372C28C86 for ; Wed, 27 Mar 2019 01:02:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7C4228CDB; Wed, 27 Mar 2019 01:02:44 +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 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 5CD2E28C86 for ; Wed, 27 Mar 2019 01:02:44 +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=6qKjSDl+dRgO4QEADwCK53qVll3MCQobmIb9u1DpXxA=; b=Q3KqY+MOPeSWLF jU5iG4QzmxI0gkH1lZgw6d2X1LDVFXxe9CJDnE6WUe6qrpnWwtjRieNe/DoO/oIbARb5FsLBYUVBt GNzD0PpNT/1eJ1gAuz1mx4tO1xfUyDyVvjhLXv+whk7djz8ot8zHvldb1f9SMGJQlD4l1RzwAY992 8ety1u2cBsR/oheTTK6E0wjl/0UhyhdezSR3AALkA/pXh/qHpWJjWICQJGe3vgYjvpu1LbJWd0rvr LDLH3z2gwK81JSiDxj93s1fx2n1s6fxb8a8kKzJk+TYuQPwmUZV4QwYxhO5ViGrPsR+xFLfvpHbQw rXMQVege69MoFNjCTBXg==; 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 1h8wxm-0004LL-Ew; Wed, 27 Mar 2019 01:02:42 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8wxg-0004FF-Pb for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 01:02:39 +0000 Received: by mail-pl1-x642.google.com with SMTP id q6so2455749pll.4 for ; Tue, 26 Mar 2019 18:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BSwFhYguijpTFoY9p4NUWZwAj7qdGw4AZTrGKzgCdaM=; b=QHVz2e2PgH2Vw9HKpEFdhwhDg027GlhgmRzKNI8xlxPYgnkDfkOrhlcqe1w3cKe4Ga ibmcQWbb/3NH8bGR+VG/6O819pYB9DuGQKyfUlwu3LpCbYsDXN6p/C43aArw8+q3BIre kdR9o4ZxHu095EaBos2P6DNf8WgPudvtUMDOXJFlhflhlcq8Wzun4jsJopi2SQuMos6v jrlUk6fydWNxN5vXPl70C+Pujts+muIAK+Mq/SgRQ5MREOCYC3KCgxJv/QZY/MaX4mAo ovSiGmWhTbfZFiy6uCrE2Lf0kEPswfee+RiBfmSbSVM9kQ/fwoog2Y54c9J0NixdhkW3 6x0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BSwFhYguijpTFoY9p4NUWZwAj7qdGw4AZTrGKzgCdaM=; b=d7xcOvuRIP0lVE2eu+T+LMD8TKHQE9pbPBXEjQ7jEXv7M3o/D0fBXkkjKkbmNzDnsq bjFUWbQTUrLhmNcJDXjcVRplGECSSzILoB6xJeQzKA/jMWagzlnY/1TpkX6H1/iJYGjs SYk4EFKx+O+ehkdUxDaat+FUvirNBKSUUJw6j4XT9d/9JiNrLw4+bWXqtRZgtZOvhgcb MDjptiGb3D54BBr9uGxcqzXnd5a1SWc3Ba2wMY9V7Mrv14ZPpQxT6AiA6nUdf2TyVOTC sQyqIBRGII1M52I3fSYpdZXIgvaB+osH5FxlGLZhVpthpdwyQcSYTIOaJf7Ew2sId+J9 6fWg== X-Gm-Message-State: APjAAAXln+uXg356+Tzk1G33S4TqILAV5tKfzVUqAYoxjgPZZrW9Ub+0 nJp77y4lNN/6fxcN9PBAfoc= X-Google-Smtp-Source: APXvYqxQfDD/MtGlllmsOymGh+HFy7CB250o5r9o3FQ0CgmvwKzE4j/gSYmiiyE7OFmaKIcgeuv+sA== X-Received: by 2002:a17:902:f084:: with SMTP id go4mr34583963plb.15.1553648555412; Tue, 26 Mar 2019 18:02:35 -0700 (PDT) Received: from voyager.jms.id.au ([45.124.203.18]) by smtp.gmail.com with ESMTPSA id u13sm41111703pfa.169.2019.03.26.18.02.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Mar 2019 18:02:34 -0700 (PDT) Received: by voyager.jms.id.au (sSMTP sendmail emulation); Wed, 27 Mar 2019 11:32:27 +1030 From: Joel Stanley To: Alexandre Belloni , Alessandro Zummo , Rob Herring , Mark Rutland Subject: [PATCH v3 1/2] dt-bindings: rtc: Add on-chip ASPEED RTC documentation Date: Wed, 27 Mar 2019 11:32:14 +1030 Message-Id: <20190327010215.10231-2-joel@jms.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327010215.10231-1-joel@jms.id.au> References: <20190327010215.10231-1-joel@jms.id.au> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_180236_846939_D2B47FF5 X-CRM114-Status: GOOD ( 13.10 ) 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: Andrew Jeffery , linux-rtc@vger.kernel.org, linux-aspeed@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Describe the RTC as used in the ASPEED BMC SoCs. Signed-off-by: Joel Stanley --- v3: Add interrupts property --- .../devicetree/bindings/rtc/rtc-aspeed.txt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-aspeed.txt diff --git a/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt new file mode 100644 index 000000000000..2e956b3dc276 --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt @@ -0,0 +1,22 @@ +ASPEED BMC RTC +============== + +Required properties: + - compatible: should be one of the following + * aspeed,ast2400-rtc for the ast2400 + * aspeed,ast2500-rtc for the ast2500 + * aspeed,ast2600-rtc for the ast2600 + + - reg: physical base address of the controller and length of memory mapped + region + + - interrupts: The interrupt number + +Example: + + rtc@1e781000 { + compatible = "aspeed,ast2400-rtc"; + reg = <0x1e781000 0x18>; + interrupts = <22>; + status = "disabled"; + }; From patchwork Wed Mar 27 01:02:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 10872369 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 B256D139A for ; Wed, 27 Mar 2019 01:03:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97DA228C86 for ; Wed, 27 Mar 2019 01:03:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BBB828CDB; Wed, 27 Mar 2019 01:03:01 +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 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 07CCE28C86 for ; Wed, 27 Mar 2019 01:03:01 +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=9685LA2KhAqoCUrsSGIa31xzl/vsUqMJnrwgHXpHoiA=; b=sh4hK3uDBMPv6e e1R31SOIMiAHRLTcfysZFhd/1ZDNczv+a28cuA3AuxoctBziEef/lJHAlDaqQWtTkNBA8aP6wfU7+ Pv7qnM2vZnGPFKvPkMW4WHSwd85/LyEu5W6iMEbQAhXfEL77eJk4fChUQ688ZmBzq7q9TcP36bPnZ bUMCm6pThwTryTxqKkqZIMnLo8gt8E+vzDdTczdu3LuBdsidkd8vc1+Er6v2Sp9wvlUz6mJ9VlKg4 GPTlol47FTkFjimlZ55z29eAhd3edfsezTmSpSqR6is08KpcVOqmTY+K1aoGrfB46GEz94harzMZY Iq5yVQ2JmRTwPOWCz/Fw==; 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 1h8wy1-0004ba-Ps; Wed, 27 Mar 2019 01:02:57 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8wxp-0004PE-3W for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 01:02:52 +0000 Received: by mail-pl1-x644.google.com with SMTP id m10so2459027plt.10 for ; Tue, 26 Mar 2019 18:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8tmMfQn1gHrDTKbMhj8QQMWSpJCPqH7E8kvRJN759W0=; b=duYZu0AatXPCGNA1BSAUB2Bm4/G4KYZD/DFcofPZ9ynSmQqREeKDkwYL1Ab4MOnA4j m1+Gtjx5Wfn/yWfyuSDhyZ7qtK1XZYOVzkJSORC+GZuhbYtZ42pT+u/C5Id2LYuNYSzP +43AkUmuZXsq52IgZrkxtchB9Q2k5w5y9gOq/rc3fqTd9w+HSVXWZQFHzHlmVp4r55U9 gTFiIm7H+QpdzF5nKaIN9nX0KuVj+4lQECQFi0hA9SUSNcdHznfF7ggjx3rsfignTNMv z29AP7Lf5tRs3OWw5eAMnbVbUOTk0X2I1FCL2RN1vGpjcYbuqvYecAHd/07NOEDCC+n0 xjzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=8tmMfQn1gHrDTKbMhj8QQMWSpJCPqH7E8kvRJN759W0=; b=Ag4FL+9v3sl6QAN8IJNl86MCTYRqCiatyVznSt2f54ymribCMWBEsyG836LnliNrZ8 sPYDaSB+9zbaIJ+/CRch7QiQ1GaoVk/RnvxBhUhnWkSe44abxDhQhe63BLkfLH8+tR06 ycYrWfon2ICZtTqakd145CaEJp/xsuDxLTorERGOYjx0YGZq3E3iESYHQC+31veS1yMz Bc4UFTbeEnpo2co2s2bYIa//G6pxs0PdA31zEVwMOvVtxzhBFnCzqBANQVHFtniBldkP fqmlG5ErL6WNj21iJoOgPy3z62WGwyUcL0AyT4tGf7G4LO88D7P89KqfU6k46TMaY4fx bhqw== X-Gm-Message-State: APjAAAXqTXb6h8x65tTKJBlnBGNusMC1R/XEK7wz8Bb1ZXNkyoS7eB2y wHzuy7gkLj64Ru5gA8iDqVaf/5b5 X-Google-Smtp-Source: APXvYqymbxzy3GtIgR62ALgZsYQCY6HMfQ8XViKR1xDoHaTmnpDRSX90ZvoRo2ftHdUrrgzFF0dzyQ== X-Received: by 2002:a17:902:aa92:: with SMTP id d18mr32732951plr.278.1553648564210; Tue, 26 Mar 2019 18:02:44 -0700 (PDT) Received: from voyager.jms.id.au ([45.124.203.18]) by smtp.gmail.com with ESMTPSA id j20sm37057982pfi.27.2019.03.26.18.02.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Mar 2019 18:02:43 -0700 (PDT) Received: by voyager.jms.id.au (sSMTP sendmail emulation); Wed, 27 Mar 2019 11:32:36 +1030 From: Joel Stanley To: Alexandre Belloni , Alessandro Zummo , Rob Herring , Mark Rutland Subject: [PATCH v3 2/2] rtc: Add ASPEED RTC driver Date: Wed, 27 Mar 2019 11:32:15 +1030 Message-Id: <20190327010215.10231-3-joel@jms.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327010215.10231-1-joel@jms.id.au> References: <20190327010215.10231-1-joel@jms.id.au> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_180245_654687_80FBCF1C X-CRM114-Status: GOOD ( 20.47 ) 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: Andrew Jeffery , linux-rtc@vger.kernel.org, linux-aspeed@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Read and writes the time to the non-battery backed RTC in the ASPEED BMC system on chip families. Signed-off-by: Joel Stanley --- v3: - Use %ptR - Remove spinlock, as callback happen under the rtc_device.ops_lock v2: Address review from Alexandre - Use devm_rtc_allocate_device - Fill in range_min - Direcly fill in tm struct - Return EINVAL when RTC is not enabled v1: https://lore.kernel.org/linux-arm-kernel/20181003133155.27494-2-joel@jms.id.au/ Update kconfig text Signed-off-by: Joel Stanley --- drivers/rtc/Kconfig | 11 ++++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-aspeed.c | 138 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 drivers/rtc/rtc-aspeed.c diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index dc0d66e80038..fd1321875cb1 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -1841,6 +1841,17 @@ config RTC_DRV_RTD119X If you say yes here, you get support for the RTD1295 SoC Real Time Clock. +config RTC_DRV_ASPEED + tristate "ASPEED RTC" + depends on OF + depends on ARCH_ASPEED || COMPILE_TEST + help + If you say yes here you get support for the ASPEED BMC SoC real time + clocks. + + This driver can also be built as a module, if so, the module + will be called "rtc-aspeed". + comment "HID Sensor RTC drivers" config RTC_DRV_HID_SENSOR_TIME diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index fe3962496685..9d997faa2c26 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_DRV_AC100) += rtc-ac100.o obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o obj-$(CONFIG_RTC_DRV_ASM9260) += rtc-asm9260.o +obj-$(CONFIG_RTC_DRV_ASPEED) += rtc-aspeed.o obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o diff --git a/drivers/rtc/rtc-aspeed.c b/drivers/rtc/rtc-aspeed.c new file mode 100644 index 000000000000..bd709feea695 --- /dev/null +++ b/drivers/rtc/rtc-aspeed.c @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright 2015 IBM Corp. + +#include +#include +#include +#include +#include + +struct aspeed_rtc { + struct rtc_device *rtc_dev; + void __iomem *base; +}; + +#define RTC_TIME 0x00 +#define RTC_YEAR 0x04 +#define RTC_CTRL 0x10 + +#define RTC_UNLOCK BIT(1) +#define RTC_ENABLE BIT(0) + +static int aspeed_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct aspeed_rtc *rtc = dev_get_drvdata(dev); + unsigned int cent, year; + unsigned long flags; + u32 reg1, reg2; + + if (!(readl(rtc->base + RTC_CTRL) & RTC_ENABLE)) { + dev_dbg(dev, "%s failing as rtc disabled\n", __func__); + return -EINVAL; + } + + do { + reg2 = readl(rtc->base + RTC_YEAR); + reg1 = readl(rtc->base + RTC_TIME); + } while (reg2 != readl(rtc->base + RTC_YEAR)); + + tm->tm_mday = (reg1 >> 24) & 0x1f; + tm->tm_hour = (reg1 >> 16) & 0x1f; + tm->tm_min = (reg1 >> 8) & 0x3f; + tm->tm_sec = (reg1 >> 0) & 0x3f; + + cent = (reg2 >> 16) & 0x1f; + year = (reg2 >> 8) & 0x7f; + tm->tm_mon = ((reg2 >> 0) & 0x0f) - 1; + tm->tm_year = year + (cent * 100) - 1900; + + dev_dbg(dev, "%s %ptR", __func__, tm); + + return 0; +} + +static int aspeed_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct aspeed_rtc *rtc = dev_get_drvdata(dev); + unsigned long flags; + u32 reg1, reg2, ctrl; + int year, cent; + + cent = (tm->tm_year + 1900) / 100; + year = tm->tm_year % 100; + + reg1 = (tm->tm_mday << 24) | (tm->tm_hour << 16) | (tm->tm_min << 8) | + tm->tm_sec; + + reg2 = ((cent & 0x1f) << 16) | ((year & 0x7f) << 8) | + ((tm->tm_mon + 1) & 0xf); + + ctrl = readl(rtc->base + RTC_CTRL); + writel(ctrl | RTC_UNLOCK, rtc->base + RTC_CTRL); + + writel(reg1, rtc->base + RTC_TIME); + writel(reg2, rtc->base + RTC_YEAR); + + /* Re-lock and ensure enable is set now that a time is programmed */ + writel(ctrl | RTC_ENABLE, rtc->base + RTC_CTRL); + + return 0; +} + +static const struct rtc_class_ops aspeed_rtc_ops = { + .read_time = aspeed_rtc_read_time, + .set_time = aspeed_rtc_set_time, +}; + +static int aspeed_rtc_probe(struct platform_device *pdev) +{ + struct aspeed_rtc *rtc; + struct resource *res; + int ret; + + rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + if (!rtc) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + rtc->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(rtc->base)) + return PTR_ERR(rtc->base); + + rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(rtc->rtc_dev)) + return PTR_ERR(rtc->rtc_dev); + + platform_set_drvdata(pdev, rtc); + + rtc->rtc_dev->ops = &aspeed_rtc_ops; + rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900; + rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */ + + ret = rtc_register_device(rtc->rtc_dev); + if (ret) + return ret; + + return 0; +} + +static const struct of_device_id aspeed_rtc_match[] = { + { .compatible = "aspeed,ast2400-rtc", }, + { .compatible = "aspeed,ast2500-rtc", }, + { .compatible = "aspeed,ast2600-rtc", }, + {} +}; +MODULE_DEVICE_TABLE(of, aspeed_rtc_match); + +static struct platform_driver aspeed_rtc_driver = { + .driver = { + .name = "aspeed-rtc", + .of_match_table = of_match_ptr(aspeed_rtc_match), + }, +}; + +module_platform_driver_probe(aspeed_rtc_driver, aspeed_rtc_probe); + +MODULE_DESCRIPTION("ASPEED RTC driver"); +MODULE_AUTHOR("Joel Stanley "); +MODULE_LICENSE("GPL");