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: 161240 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp5877634jan; Tue, 26 Mar 2019 18:02:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEVUxcZ0SNPNnuNiyJm03QKkpP3piGm7gaOUegcr2Ol1w3vI6vDgXMYKwYmZ2xzDIeGQ7C X-Received: by 2002:a17:902:8697:: with SMTP id g23mr35052651plo.30.1553648557147; Tue, 26 Mar 2019 18:02:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553648557; cv=none; d=google.com; s=arc-20160816; b=d6oWPbozA5cnr7Ss+81q0+CZXs8rSY/fBAF7q+T/u0oaJzYR1CjO2hDfsVlcoEKjd4 uWjc6rr443qZmT2JkrfkE8V77i77y9gVcL7QjwH8yU9Td+vP91aOgWaGn1InjC8XXCWY BwhmDvbwqJC4sPpRcWJXe0rJgZUx7wIO2QQpAC5vpooH4bbLfsVXTiHtNHB0cG8JdE8l xA1k/Z3BhG19hyQedjZysJoA9dMdf+DqN92+v1uUeeTWQlxDDK6qU8pvW0ZGJ50bO+gy APCCECYgyYn4A8rbSOp7ZlMZD8Lhqx/7e8zAqKdAFA3dfxxtmV7rPcvM2e4kWgJgYas3 2iOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BSwFhYguijpTFoY9p4NUWZwAj7qdGw4AZTrGKzgCdaM=; b=nabdypqEkFOYW3bUYxPyUax3FDXsD2CLM5BKt5aRLmmoOtVbSlUA1RV42rfCzkrvU3 wdqYHP2hZV9ENRJbThlFBZ+M5+UD0lydWQ5MbPThdZc0glSBjH29TpKBrsaTfubj9dPQ RHvuOiP2UqEK+QsqijTpSVvsRmUcaZAvCfHikKa4RNH3b4eAymF9Rf4Z0R8pQ+emieeT 9M+c/Km5t69hGJ39OfrWbfxnvmoiZh0EvOM1THm8hArrGOKCEqWqc/mC87p+YZXO9poN Pd3LjKxL/mCXnhRwxax4DTOVFB0AyHaAB8odlvEgVsplOBnTIYLxAX3XQME7WbiA29JQ 8DLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=QHVz2e2P; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 p6si17853827plo.4.2019.03.26.18.02.36; Tue, 26 Mar 2019 18:02:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=QHVz2e2P; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731664AbfC0BCg (ORCPT + 7 others); Tue, 26 Mar 2019 21:02:36 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45178 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727483AbfC0BCg (ORCPT ); Tue, 26 Mar 2019 21:02:36 -0400 Received: by mail-pl1-f194.google.com with SMTP id bf11so2458510plb.12; Tue, 26 Mar 2019 18:02:35 -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=XZO+4mHXLztbQnVJKpQU+sXhunRcTLREM9bejZfnpIaFz3SRPyci5IA8kTkUEWkeug i6C8Iz8ftR2Kb85q+DDMWZI5DOqDY4eGtZCSOUspRjNE4uwQ+wXfC70S/VCaIhGZ4e93 wGYAjB+xfT5PPI2i523dqrhpG/E2+zcMDNCs5eGbqYe5LQWnNBonLkOKXuPOO1UV4295 PrXf/epi+oOIGO9SrXwEh+kFDVEeuMhlGRNvXxsm4bRUHrK/zWdnA6GKh55ToOoqwYwk qNecgp/p83Sr6uwsCB2dRX0qYSidO1QqZubDySDW9xr4wRcNEIGrkVk2sXBrmAsvrDwe znsg== X-Gm-Message-State: APjAAAUMrV7ZYa8skt2KCLWkPYgMCxhAMmmIXNC4x+XbAAtjp3ZXSx2u DQI1cdoACE8soBDI2IRCgRmZ/JPi 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 Cc: Andrew Jeffery , linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org 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 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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 -- 2.20.1 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: 161241 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp5877779jan; Tue, 26 Mar 2019 18:02:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4cSh85nRVXNDKYXxnp5Bzic12NfaVyNGIWIf4sH0gxvDiH5RBpgqpkCUNd8HW4NgjMu1L X-Received: by 2002:a62:6d81:: with SMTP id i123mr32382623pfc.235.1553648566043; Tue, 26 Mar 2019 18:02:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553648566; cv=none; d=google.com; s=arc-20160816; b=PwLz6U7nrc31Z+F0FTOWpxfSzoSVSEsEAkOQkEKb68uZ2zppEPMj0x1LktvWs8Z/O1 qBc3erNjQKbH4XiyvUn7s/h4ZgvjSn6QilyN0KLpXkMnvK2IN0F16bONKR6DKssfnMI1 /KvFoEg2oZMkJV3k0OG2/ury0CkM2OO5yTWa/bS6yR10YSfwkl9Wjbmoe5Lo+dqrLErb DY6qfdw8SJc4vEIdp17l+xpeC2mssU4YTdviH9OanbSMDIMkZzBvgoMuhG8+Bbdk+Toy Q+RU1at6Ft08oRINv45b+Zl4be19VODAHvxlTmS3nk7wfH5vLrMyBqFFDSIh+lvD4TCu BiPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8tmMfQn1gHrDTKbMhj8QQMWSpJCPqH7E8kvRJN759W0=; b=alBt8rBbQHB3Q7Cq+5EPRt69vZWkIdwWPljiMhhV1woZ8oVz9hAl/7HwAp6xaLMzIW 7nCbMV/seStS7mNNt5UDmLH4HHQpbjpw6+cfvZ2o/J0S3IuxiRM7rPeGqrTNaoMQksUc zkb1UDv3XD90rUKIB3q+fsQMgkhpU3VpqpPBpNHMN/uZQVfUgXkicJ4eGgombfmoPIQi ZyiSbqWBBwyU9JLbVTlW2VEb0HKMmQyx8UxEInT4vvYR1aIBZ8cylZXxCdp+NcLQ4Dkx omSLpJoDvMYi9mCU5PaYfIXfzLYC2FpNUghKatQpLaVmiLp57szyuIb/QCPz1wWgVPri cI3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=duYZu0Aa; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 p6si17853827plo.4.2019.03.26.18.02.45; Tue, 26 Mar 2019 18:02:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=duYZu0Aa; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731934AbfC0BCp (ORCPT + 7 others); Tue, 26 Mar 2019 21:02:45 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:39555 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727483AbfC0BCp (ORCPT ); Tue, 26 Mar 2019 21:02:45 -0400 Received: by mail-pl1-f195.google.com with SMTP id b65so2458077plb.6; 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=taQyZWdDao6yOFSOljR90DW56YWzemdfTLLKBYpgulFnPLD5s3SptUbSfl1zT5CyJu aqQuMphRlKlhmbK83w0XFDy3f3d3WetpFCgtF0dVbX+RMHvMxLeMvuw2Woby63TjqSQA 6e3ZhdmRueDPuvejGt+bv6PyEQyFVfy5RznXlErh2KZGNYlTy4C/fJtVw3W9j/JfRNRT q0352ZTcpS461ZC4CMihmkalR0AWjYU+u69oxxzubiOI00eJBwQwxJitbiF7M2gUgVvZ TfgTBpGtA4WTbL7hvcmM2EuPhtvYPxUU2KHJr6KbJdzZ6/Muc+HPOx85yCJ7q1ufHPz5 DWYA== X-Gm-Message-State: APjAAAU0f+mnmHvStsjIcV22gjj695HkKsF6O3Srf9ztCgHvZoeudm3N jOYUXVKZr543f3v3ECh38uY= 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 Cc: Andrew Jeffery , linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org 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 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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 -- 2.20.1 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");