From patchwork Mon Mar 25 13:31:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 161110 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3976703jan; Mon, 25 Mar 2019 06:32:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjCeRebzj5LGV3EAjaIPP7W/l79bZ/mXf5qPgyN50yVD7mrXhmNGX3DTipDLpdLlLwrF/x X-Received: by 2002:a62:524e:: with SMTP id g75mr4819436pfb.106.1553520743558; Mon, 25 Mar 2019 06:32:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553520743; cv=none; d=google.com; s=arc-20160816; b=hNeTexygpJvZHbPhFLEcWGMzWF5KgNOcvKTqBNVG4XkH84PlE9Dw8qGfZd1llMcVOb DlcEkG89n/QuthPK6s0zKEu+yfH3HlW0PxmZ+zxnCnjiO+5oPlQF4jY/lnM9Bi0CShTH VQn6OLu+jrfCRV2JqpOAqs2MItQU5WQ4wIECUUNnEXBFHePcFj3+3rgqqbX0vOMNSBiY xY4CzrgE3NJ94SLD6xPFkQNU33QBx1PSHJSpOnflqNWg3AqHwC8NJs0yHhlS8oKfbznn Qd4DExqwcGE+lwnxUqit2dLw4ouOmO8dAmQnUlb4lzsYPSxAiqzg8oXu2SA93cK/O9hR bHOg== 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=aaOBUNSIm700DIjLJCNpAtOm6+4HU//hwZxNLzJTwfU=; b=p4H9z7+PQJCr8Sf5SrT+SIg/fpeXMiEDRzNCO0gP4tSO52dIx1wsK5wgmQ38FzkMvs gpK7qZfNaD137JAWZ7tMMWcLtnYuZLPcAY0gVUmWQNEIQ6FYvjQmW5MbLcu/+qnDhufN 5Dq/BWeqA/yTiNGkZGsCHO0pTzL7ZGbWrMG/5RECGZLi42b2Q/m6aFpP6Us7ogdHNM1G gVMAQuPyB32Y6txD+eTW2+kEmUkE4TdQjbjazcSe6g3DcXTnE623kEjLZbWVAauQhId7 DecYvuBGAF2WuskFxDk1Of0TVU1ntwv0ADpV4dvXUWlI/74Cp+IoKMRFAJ/SAKVrNtq/ 1eNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="Rccxnf/6"; 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 z31si11829560plb.333.2019.03.25.06.32.23; Mon, 25 Mar 2019 06:32:23 -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="Rccxnf/6"; 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 S1728818AbfCYNcW (ORCPT + 7 others); Mon, 25 Mar 2019 09:32:22 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43212 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbfCYNcW (ORCPT ); Mon, 25 Mar 2019 09:32:22 -0400 Received: by mail-pf1-f195.google.com with SMTP id c8so6431659pfd.10; Mon, 25 Mar 2019 06:32:22 -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=aaOBUNSIm700DIjLJCNpAtOm6+4HU//hwZxNLzJTwfU=; b=Rccxnf/68/ixRAquiQh3RRHlW7JmLn9sjD5e/NIcZ7HLkQvoBYfcu2nGAsBDcCUC8d vwokpxlhKSv0kIiiBOlBGMTB9v6bEHVg9avdoo7z4YOV8QHQq0tuMgqdWfu+fjR5AJB0 KyKl5mUUb0mSfvsLsBVENt+R2gIP98Kp6OTPdtnESLgy3nkeAWsHSro5bFhxsP9G5kNm VGrZ6Gx43n9CKoWsWBhEQOzn/kzZ5uF6gpw0jbuCZOiPSCiVT/DfP0zQ+0TXBCMFOBU2 NPTLiAv/G/Tm2DtWJ303YhtvzfdULch6jpQcGPBgoMwB0B3SfL5hPL/QWZPKHi398zv1 FS7w== 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=aaOBUNSIm700DIjLJCNpAtOm6+4HU//hwZxNLzJTwfU=; b=qy/QXAUqrLyMTM765gOWlbsXiM0Z8f3Un1uf9qS1fZrgu8eUcIQ3MKjWFAwAIU9jSK Lygx1ivQpR72YjPtaS5H0+3E7QfSTb2updU6XXiUfXc0iNlWNsCGKiFQus6XVy5bqFsZ HZpQaemwlydLR7WQ+9Ww9OOqq6SKAqsjaAkvCAxrwy7Mv3bLEcvYNEevgpc7zCMtJV8x hDt9tlOFqZ4ufA2LyLtcwEc5+eSOuJ6dDgFO5cBikPa0oo/T3CFlsvv9it4IHACMkTv9 BsVOgytzYc9fD+2hICGa5jIqqXi5Qvd17f9yB4fKwgpHfzkSjXw3VX2qYh/rHgKAc9EK hVTA== X-Gm-Message-State: APjAAAVDGr3dTDH8PC6CtQGPQ0IIMnzZR4Ttuxcoo54UisXTAa657Kn/ 9+q2NVlzazlRH1FNHE6zspk= X-Received: by 2002:a62:ea0f:: with SMTP id t15mr24500488pfh.124.1553520741971; Mon, 25 Mar 2019 06:32:21 -0700 (PDT) Received: from voyager.jms.id.au ([45.124.203.18]) by smtp.gmail.com with ESMTPSA id m25sm7947423pfa.175.2019.03.25.06.32.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Mar 2019 06:32:21 -0700 (PDT) Received: by voyager.jms.id.au (sSMTP sendmail emulation); Tue, 26 Mar 2019 00:02:13 +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 v2 1/2] dt-bindings: rtc: Add on-chip ASPEED RTC documentation Date: Tue, 26 Mar 2019 00:01:58 +1030 Message-Id: <20190325133159.10653-2-joel@jms.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190325133159.10653-1-joel@jms.id.au> References: <20190325133159.10653-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 --- .../devicetree/bindings/rtc/rtc-aspeed.txt | 19 +++++++++++++++++++ 1 file changed, 19 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..f9f7defd557e --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt @@ -0,0 +1,19 @@ +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 + +Example: + + rtc@1e781000 { + compatible = "aspeed,ast2400-rtc"; + reg = <0x1e781000 0x18>; + status = "disabled"; + }; From patchwork Mon Mar 25 13:31:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 161111 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3976886jan; Mon, 25 Mar 2019 06:32:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2JtUNxwI6cnosXGljkj248fUvqdnmgJaIqzTFKJfzls26ej9Pl2ZoYoST9UifH3ugaJ3F X-Received: by 2002:a65:63d9:: with SMTP id n25mr23783033pgv.243.1553520753278; Mon, 25 Mar 2019 06:32:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553520753; cv=none; d=google.com; s=arc-20160816; b=QgFvyKs4vxFLhcD2BG469ODF0Yr6wE9BlSlovuBUQFJn18Vhcl8agCSpoMojrd426w vWTNVe28PZg1hy4YvP317rMvtW1GSPbmHrTSe2Ya/vo/ruNnfu0LqKxF50UxyyZ2hC3k eVBH/x9pSWeyWNYF9hVuVjJyMud97NL67i9qn6ELeRj5vSoKSHMSxMp1sUwhDFLfqN8T N1wo89SXsLzuvHLBwk5Q8lMfXOYCXLGcg8weRfjd2IDu6rxU2nWRNYdKZcYCagbPadyI UIuVEHrbybGb+PfyMBLq3o3zYhGNZtajfhW8wRG1lKAZQy57yOcmgkgthyiaBnQLyR9d hPCw== 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=ZNMynFsYBw4bJOkRxzZKAehBFlMsAcqfPwZnt4LHr6Y=; b=e3q64NWP+eArCwWYDJ+REeG/dNBjIFrcs+/0+/H+2F8RERPU6bAoEgwHhRcduNYhWt 0HR8Bq2VSeqA8BBI4u6jqYWliah+d3uWxbxo9VcYp3f00kh+H0cfpJwkoNDtGqB6CsXg U3+Nj5rO2pNiG4L+T6JOd1RMrPdNOabZybZ87B6P9YQg6sENYAtK7GRB4AvaB7N4Rzkd Pzo5fjnn4ZbubtBKruX+lB6GFiolnxYv1RyZhVvMtF5PhD5sgCeLk9QrR5UXj5QJH8N6 lHiY3bxMrOv+qZip/9KtiTbVu+wsTgPkJ7ptTOcGFmoUelSGE1fc6359j4ANZUOUXgZh neKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Tkn4zj8x; 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 e96si14561196plb.123.2019.03.25.06.32.33; Mon, 25 Mar 2019 06:32:33 -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=Tkn4zj8x; 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 S1728963AbfCYNcc (ORCPT + 7 others); Mon, 25 Mar 2019 09:32:32 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37379 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbfCYNcb (ORCPT ); Mon, 25 Mar 2019 09:32:31 -0400 Received: by mail-pf1-f196.google.com with SMTP id 8so6442998pfr.4; Mon, 25 Mar 2019 06:32:31 -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=ZNMynFsYBw4bJOkRxzZKAehBFlMsAcqfPwZnt4LHr6Y=; b=Tkn4zj8xOHgJLuaEbb8YRTPlsm7DpDp0dRUqUw2uFQaqihw44lfAPUcbw8Q++btstd kAqqVEP5d9cEEOyEOdeBQreb4sUh6xCU7Od2IZbnlpCMKgcL0xHDE1GDT22WnhRBfuJy cMzpnJjo8GtlrejLgOwfvvrC37HDuuaDZY23FM7t1A2GByWfzM1dnnzW0hubcIn+jMEJ EsVFPahDyTRsMaCLKPoF1U/hVnIykOjjDwuzjEfbrOeeAWYm3dKiUuY/Dd9qDcTpqZWn UWhexXpFKA3bCwKv7Ah50TE0W/NpYWjBgvYxgt9+cK+0jB1JbtRlYVYsrN8eItUyDZe/ P8RQ== 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=ZNMynFsYBw4bJOkRxzZKAehBFlMsAcqfPwZnt4LHr6Y=; b=ELV+s4B9fsk4Cqc7LANm0AParJsgx7T6NUXffkhAfkHERwNwMXMkrv8UcJE2aIH7Lu BERzdt8tZuJyKXbBONtKCez4tEpbovBt5ye+QPuB+JjY4zG7WipLkxaxwC/iuFseGmJC D58RlL3jYLfWre1Mf8U1wv37HWB0pAmP0ft53cgWtoKMy+eLxbF7eSW7gk80nR1hgoZO DZk8Q6o7EkcP27DTAY+YQzh1Vj8VfuNIY5Jc5SJ0C9HKgPZr/x6/e9m+6d70NjDGww8+ A+ha5/KoSmlo253KQ1c2nUXiv62oaP3Pt75JMvqGYIvFUws3WZZzKVSk8EZhjXxTHXVy EHTQ== X-Gm-Message-State: APjAAAXjE4pVIgt6uuZ/3bpS61P1jiHnndmDkM7VAv6tagu/8psY8Ub8 LRoazluHrwfCmfiEPTGab0M= X-Received: by 2002:a63:28c:: with SMTP id 134mr18182510pgc.278.1553520750567; Mon, 25 Mar 2019 06:32:30 -0700 (PDT) Received: from voyager.jms.id.au ([45.124.203.18]) by smtp.gmail.com with ESMTPSA id i64sm23498107pfb.112.2019.03.25.06.32.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Mar 2019 06:32:29 -0700 (PDT) Received: by voyager.jms.id.au (sSMTP sendmail emulation); Tue, 26 Mar 2019 00:02:22 +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 v2 2/2] rtc: Add ASPEED RTC driver Date: Tue, 26 Mar 2019 00:01:59 +1030 Message-Id: <20190325133159.10653-3-joel@jms.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190325133159.10653-1-joel@jms.id.au> References: <20190325133159.10653-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 --- 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/ Signed-off-by: Joel Stanley --- drivers/rtc/Kconfig | 10 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-aspeed.c | 152 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 drivers/rtc/rtc-aspeed.c -- 2.20.1 diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index dc0d66e80038..2d0482bc468b 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -1841,6 +1841,16 @@ 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 ARCH_ASPEED || COMPILE_TEST + help + If you say yes here you get support for the ASPEED AST2400 and + AST2500 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..9ddb3121b30d --- /dev/null +++ b/drivers/rtc/rtc-aspeed.c @@ -0,0 +1,152 @@ +// 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; + spinlock_t lock; +}; + +#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; + + spin_lock_irqsave(&rtc->lock, flags); + + if (!(readl(rtc->base + RTC_CTRL) & RTC_ENABLE)) { + spin_unlock_irqrestore(&rtc->lock, flags); + 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: %4d-%02d-%02d %02d:%02d:%02d\n", __func__, + 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec); + + spin_unlock_irqrestore(&rtc->lock, flags); + + 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); + + spin_lock_irqsave(&rtc->lock, flags); + + 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); + + spin_unlock_irqrestore(&rtc->lock, flags); + + 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; + + spin_lock_init(&rtc->lock); + + 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");