Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Tegra K1 RTC driver.
details: https://anonhg.NetBSD.org/src/rev/b997177bf770
branches: trunk
changeset: 337967:b997177bf770
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Tue May 05 00:25:44 2015 +0000
description:
Tegra K1 RTC driver.
diffstat:
sys/arch/arm/nvidia/files.tegra | 7 +-
sys/arch/arm/nvidia/tegra_io.c | 6 +-
sys/arch/arm/nvidia/tegra_rtc.c | 127 +++++++++++++++++++++++++++++++++++++
sys/arch/arm/nvidia/tegra_rtcreg.h | 50 ++++++++++++++
sys/arch/evbarm/conf/JETSONTK1 | 5 +-
5 files changed, 191 insertions(+), 4 deletions(-)
diffs (253 lines):
diff -r 9563ba28dfcd -r b997177bf770 sys/arch/arm/nvidia/files.tegra
--- a/sys/arch/arm/nvidia/files.tegra Mon May 04 23:51:25 2015 +0000
+++ b/sys/arch/arm/nvidia/files.tegra Tue May 05 00:25:44 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.tegra,v 1.6 2015/05/03 01:07:44 jmcneill Exp $
+# $NetBSD: files.tegra,v 1.7 2015/05/05 00:25:44 jmcneill Exp $
#
# Configuration info for NVIDIA Tegra ARM Peripherals
#
@@ -45,6 +45,11 @@
attach com at tegraio with tegra_com
file arch/arm/nvidia/tegra_com.c tegra_com needs-flag
+# RTC
+device tegrartc
+attach tegrartc at tegraio with tegra_rtc
+file arch/arm/nvidia/tegra_rtc.c tegra_rtc
+
# USB 2.0
attach ehci at tegraio with tegra_ehci
file arch/arm/nvidia/tegra_ehci.c tegra_ehci
diff -r 9563ba28dfcd -r b997177bf770 sys/arch/arm/nvidia/tegra_io.c
--- a/sys/arch/arm/nvidia/tegra_io.c Mon May 04 23:51:25 2015 +0000
+++ b/sys/arch/arm/nvidia/tegra_io.c Tue May 05 00:25:44 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tegra_io.c,v 1.5 2015/05/03 01:07:44 jmcneill Exp $ */
+/* $NetBSD: tegra_io.c,v 1.6 2015/05/05 00:25:44 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
#include "opt_tegra.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tegra_io.c,v 1.5 2015/05/03 01:07:44 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tegra_io.c,v 1.6 2015/05/05 00:25:44 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -81,6 +81,8 @@
TEGRA_UARTC_OFFSET, TEGRA_UARTC_SIZE, 2, TEGRA_INTR_UARTC },
{ "com",
TEGRA_UARTD_OFFSET, TEGRA_UARTD_SIZE, 3, TEGRA_INTR_UARTD },
+ { "tegrartc",
+ TEGRA_RTC_OFFSET, TEGRA_RTC_SIZE, NOPORT, NOINTR },
{ "sdhc",
TEGRA_SDMMC1_OFFSET, TEGRA_SDMMC1_SIZE, 0, TEGRA_INTR_SDMMC1 },
{ "sdhc",
diff -r 9563ba28dfcd -r b997177bf770 sys/arch/arm/nvidia/tegra_rtc.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/nvidia/tegra_rtc.c Tue May 05 00:25:44 2015 +0000
@@ -0,0 +1,127 @@
+/* $NetBSD: tegra_rtc.c,v 1.1 2015/05/05 00:25:44 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "locators.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: tegra_rtc.c,v 1.1 2015/05/05 00:25:44 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/intr.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+
+#include <dev/clock_subr.h>
+
+#include <arm/nvidia/tegra_reg.h>
+#include <arm/nvidia/tegra_rtcreg.h>
+#include <arm/nvidia/tegra_var.h>
+
+static int tegra_rtc_match(device_t, cfdata_t, void *);
+static void tegra_rtc_attach(device_t, device_t, void *);
+
+struct tegra_rtc_softc {
+ device_t sc_dev;
+ bus_space_tag_t sc_bst;
+ bus_space_handle_t sc_bsh;
+
+ struct todr_chip_handle sc_todr;
+};
+
+static int tegra_rtc_gettime(todr_chip_handle_t, struct timeval *);
+static int tegra_rtc_settime(todr_chip_handle_t, struct timeval *);
+
+CFATTACH_DECL_NEW(tegra_rtc, sizeof(struct tegra_rtc_softc),
+ tegra_rtc_match, tegra_rtc_attach, NULL, NULL);
+
+#define RTC_READ(sc, reg) \
+ bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
+#define RTC_WRITE(sc, reg, val) \
+ bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
+
+static int
+tegra_rtc_match(device_t parent, cfdata_t cf, void *aux)
+{
+ return 1;
+}
+
+static void
+tegra_rtc_attach(device_t parent, device_t self, void *aux)
+{
+ struct tegra_rtc_softc * const sc = device_private(self);
+ struct tegraio_attach_args * const tio = aux;
+ const struct tegra_locators * const loc = &tio->tio_loc;
+
+ sc->sc_dev = self;
+ sc->sc_bst = tio->tio_bst;
+ bus_space_subregion(tio->tio_bst, tio->tio_bsh,
+ loc->loc_offset, loc->loc_size, &sc->sc_bsh);
+
+ aprint_naive("\n");
+ aprint_normal(": RTC\n");
+
+ sc->sc_todr.todr_gettime = tegra_rtc_gettime;
+ sc->sc_todr.todr_settime = tegra_rtc_settime;
+ sc->sc_todr.cookie = sc;
+ todr_attach(&sc->sc_todr);
+}
+
+static int
+tegra_rtc_gettime(todr_chip_handle_t tch, struct timeval *tv)
+{
+ struct tegra_rtc_softc * const sc = tch->cookie;
+
+ tv->tv_sec = RTC_READ(sc, RTC_SECONDS_REG);
+ tv->tv_usec = 0;
+
+ return 0;
+}
+
+static int
+tegra_rtc_settime(todr_chip_handle_t tch, struct timeval *tv)
+{
+ struct tegra_rtc_softc * const sc = tch->cookie;
+ int retry = 500;
+
+ while (--retry > 0) {
+ if ((RTC_READ(sc, RTC_BUSY_REG) & RTC_BUSY_STATUS) == 0)
+ break;
+ delay(1);
+ }
+ if (retry == 0) {
+ device_printf(sc->sc_dev, "RTC write failed (BUSY)\n");
+ return ETIMEDOUT;
+ }
+
+ RTC_WRITE(sc, RTC_SECONDS_REG, tv->tv_sec);
+
+ return 0;
+}
diff -r 9563ba28dfcd -r b997177bf770 sys/arch/arm/nvidia/tegra_rtcreg.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/nvidia/tegra_rtcreg.h Tue May 05 00:25:44 2015 +0000
@@ -0,0 +1,50 @@
+/* $NetBSD: tegra_rtcreg.h,v 1.1 2015/05/05 00:25:44 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _ARM_TEGRA_RTCREG_H
+#define _ARM_TEGRA_RTCREG_H
+
+#define RTC_CONTROL_REG 0x00
+#define RTC_BUSY_REG 0x04
+#define RTC_SECONDS_REG 0x08
+#define RTC_SHADOW_SECONDS_REG 0x0c
+#define RTC_MILLI_SECONDS_REG 0x10
+#define RTC_SECONDS_ALARM0_REG 0x14
+#define RTC_SECONDS_ALARM1_REG 0x18
+#define RTC_MILLI_SECONDS_ALARM_REG 0x1c
+#define RTC_SECONDS_COUNTDOWN_ALARM_REG 0x20
+#define RTC_MILLI_SECONDS_COUNTDOW_ALARM_REG 0x24
+#define RTC_INTR_MASK_REG 0x28
+#define RTC_INTR_STATUS_REG 0x2c
+#define RTC_INTR_SOURCE_REG 0x30
+#define RTC_INTR_SET_REG 0x34
+#define RTC_CORRECTION_FACTOR_REG 0x38
+
+#define RTC_BUSY_STATUS __BIT(0)
+
+#endif /* _ARM_TEGRA_RTCREG_H */
diff -r 9563ba28dfcd -r b997177bf770 sys/arch/evbarm/conf/JETSONTK1
--- a/sys/arch/evbarm/conf/JETSONTK1 Mon May 04 23:51:25 2015 +0000
+++ b/sys/arch/evbarm/conf/JETSONTK1 Tue May 05 00:25:44 2015 +0000
@@ -1,5 +1,5 @@
#
-# $NetBSD: JETSONTK1,v 1.10 2015/05/03 18:49:28 jmcneill Exp $
+# $NetBSD: JETSONTK1,v 1.11 2015/05/05 00:25:44 jmcneill Exp $
#
# NVIDIA Jetson TK1 - Tegra K1 development kit
# https://developer.nvidia.com/jetson-tk1
@@ -64,6 +64,9 @@
com3 at tegraio? port 3 # UART-D
options CONSADDR=0x70006300, CONSPEED=115200
+# RTC
+tegrartc0 at tegraio? # RTC
+
# SDMMC
sdhc2 at tegraio? port 2 # SDMMC3 (SD card)
sdmmc2 at sdhc2
Home |
Main Index |
Thread Index |
Old Index