summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2014-04-30 21:37:14 -0700
committerMarc Jones <marc.jones@se-eng.com>2014-12-30 22:11:18 +0100
commitabb001a2fe3ffd88ea170888229ac898b6fbaf80 (patch)
tree4958ec5ac8eaedbfa5896dba9983bddf5f5bc6c2 /src/drivers
parent03abaee2196ef5598742132df0e3c224d1ebd11c (diff)
downloadcoreboot-abb001a2fe3ffd88ea170888229ac898b6fbaf80.tar.xz
rtc: Add an RTC driver for the AS3722 PMIC.
The AS3722 PMIC, like many PMICs, has an RTC built into it. This change adds a driver for it which implements the new RTC API. BUG=None TEST=Built and booted with the event log code modified to use this interface. Verified that events had accurate timestamps. BRANCH=nyan Original-Change-Id: I400adccbf84221dcba8d520276bb91b389f72268 Original-Signed-off-by: Gabe Black <gabeblack@google.com> Original-Reviewed-on: https://chromium-review.googlesource.com/197796 Original-Reviewed-by: Gabe Black <gabeblack@chromium.org> Original-Tested-by: Gabe Black <gabeblack@chromium.org> Original-Commit-Queue: Gabe Black <gabeblack@chromium.org> (cherry picked from commit 011e49beba3a99abbd122866891e3c20bf1188d2) Signed-off-by: Marc Jones <marc.jones@se-eng.com> Change-Id: Ibc1d342062c7853a30d195496c077e37a02b35b0 Reviewed-on: http://review.coreboot.org/7890 Reviewed-by: David Hendricks <dhendrix@chromium.org> Tested-by: build bot (Jenkins) Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Kconfig1
-rw-r--r--src/drivers/Makefile.inc1
-rw-r--r--src/drivers/ams/Kconfig11
-rw-r--r--src/drivers/ams/Makefile.inc1
-rw-r--r--src/drivers/ams/as3722rtc.c91
5 files changed, 105 insertions, 0 deletions
diff --git a/src/drivers/Kconfig b/src/drivers/Kconfig
index 12f9a7941a..08de41557b 100644
--- a/src/drivers/Kconfig
+++ b/src/drivers/Kconfig
@@ -17,6 +17,7 @@
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##
+source src/drivers/ams/Kconfig
source src/drivers/ati/Kconfig
source src/drivers/dec/Kconfig
source src/drivers/elog/Kconfig
diff --git a/src/drivers/Makefile.inc b/src/drivers/Makefile.inc
index 7ae3eb2510..151e3f79ab 100644
--- a/src/drivers/Makefile.inc
+++ b/src/drivers/Makefile.inc
@@ -17,6 +17,7 @@
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##
+subdirs-y += ams
subdirs-y += ati
subdirs-y += dec
subdirs-y += emulation
diff --git a/src/drivers/ams/Kconfig b/src/drivers/ams/Kconfig
new file mode 100644
index 0000000000..44b89c5f0c
--- /dev/null
+++ b/src/drivers/ams/Kconfig
@@ -0,0 +1,11 @@
+config DRIVERS_AS3722_RTC
+ bool "AS3722 RTC support"
+ default n
+
+config DRIVERS_AS3722_RTC_BUS
+ int "AS3722 RTC bus"
+ depends on DRIVERS_AS3722_RTC
+
+config DRIVERS_AS3722_RTC_ADDR
+ hex "AS3722 RTC chip address"
+ depends on DRIVERS_AS3722_RTC
diff --git a/src/drivers/ams/Makefile.inc b/src/drivers/ams/Makefile.inc
new file mode 100644
index 0000000000..cf5183196c
--- /dev/null
+++ b/src/drivers/ams/Makefile.inc
@@ -0,0 +1 @@
+ramstage-$(CONFIG_DRIVERS_AS3722_RTC) += as3722rtc.c
diff --git a/src/drivers/ams/as3722rtc.c b/src/drivers/ams/as3722rtc.c
new file mode 100644
index 0000000000..8fe5748e16
--- /dev/null
+++ b/src/drivers/ams/as3722rtc.c
@@ -0,0 +1,91 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2014 The Chromium OS Authors. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <bcd.h>
+#include <console/console.h>
+#include <device/i2c.h>
+#include <rtc.h>
+#include <stdint.h>
+
+enum AS3722_RTC_REG
+{
+ AS3722_RTC_CONTROL = 0x60,
+ AS3722_RTC_SECOND = 0x61,
+ AS3722_RTC_MINUTE = 0x62,
+ AS3722_RTC_HOUR = 0x63,
+ AS3722_RTC_DAY = 0x64,
+ AS3722_RTC_MONTH = 0x65,
+ AS3722_RTC_YEAR = 0x66
+};
+
+enum {
+ AS3722_RTC_CONTROL_ON = 0x1 << 2
+};
+
+static uint8_t as3722_read(enum AS3722_RTC_REG reg)
+{
+ uint8_t val;
+ i2c_readb(CONFIG_DRIVERS_AS3722_RTC_BUS,
+ CONFIG_DRIVERS_AS3722_RTC_ADDR, reg, &val);
+ return val;
+}
+
+static void as3722_write(enum AS3722_RTC_REG reg, uint8_t val)
+{
+ i2c_writeb(CONFIG_DRIVERS_AS3722_RTC_BUS,
+ CONFIG_DRIVERS_AS3722_RTC_ADDR, reg, val);
+}
+
+static void as3722rtc_init(void)
+{
+ static int initialized;
+ if (initialized)
+ return;
+
+ uint8_t control = as3722_read(AS3722_RTC_CONTROL);
+ as3722_write(AS3722_RTC_CONTROL, control | AS3722_RTC_CONTROL_ON);
+
+ initialized = 1;
+}
+
+int rtc_set(const struct rtc_time *time)
+{
+ as3722rtc_init();
+
+ as3722_write(AS3722_RTC_SECOND, bin2bcd(time->sec));
+ as3722_write(AS3722_RTC_MINUTE, bin2bcd(time->min));
+ as3722_write(AS3722_RTC_HOUR, bin2bcd(time->hour));
+ as3722_write(AS3722_RTC_DAY, bin2bcd(time->mday));
+ as3722_write(AS3722_RTC_MONTH, bin2bcd(time->mon + 1));
+ as3722_write(AS3722_RTC_YEAR, bin2bcd(time->year));
+ return 0;
+}
+
+int rtc_get(struct rtc_time *time)
+{
+ as3722rtc_init();
+
+ time->sec = bcd2bin(as3722_read(AS3722_RTC_SECOND) & 0x7f);
+ time->min = bcd2bin(as3722_read(AS3722_RTC_MINUTE) & 0x7f);
+ time->hour = bcd2bin(as3722_read(AS3722_RTC_HOUR) & 0x3f);
+ time->mday = bcd2bin(as3722_read(AS3722_RTC_DAY) & 0x3f);
+ time->mon = bcd2bin(as3722_read(AS3722_RTC_MONTH) & 0x1f) - 1;
+ time->year = bcd2bin(as3722_read(AS3722_RTC_YEAR) & 0x7f);
+ return 0;
+}