Module Name:    src
Committed By:   jmcneill
Date:           Tue May  5 00:25:44 UTC 2015

Modified Files:
        src/sys/arch/arm/nvidia: files.tegra tegra_io.c
        src/sys/arch/evbarm/conf: JETSONTK1
Added Files:
        src/sys/arch/arm/nvidia: tegra_rtc.c tegra_rtcreg.h

Log Message:
Tegra K1 RTC driver.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/nvidia/files.tegra
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/nvidia/tegra_io.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/nvidia/tegra_rtc.c \
    src/sys/arch/arm/nvidia/tegra_rtcreg.h
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/evbarm/conf/JETSONTK1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/nvidia/files.tegra
diff -u src/sys/arch/arm/nvidia/files.tegra:1.6 src/sys/arch/arm/nvidia/files.tegra:1.7
--- src/sys/arch/arm/nvidia/files.tegra:1.6	Sun May  3 01:07:44 2015
+++ src/sys/arch/arm/nvidia/files.tegra	Tue May  5 00:25:44 2015
@@ -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 @@ file	arch/arm/nvidia/tegra_gpio.c		tegra
 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

Index: src/sys/arch/arm/nvidia/tegra_io.c
diff -u src/sys/arch/arm/nvidia/tegra_io.c:1.5 src/sys/arch/arm/nvidia/tegra_io.c:1.6
--- src/sys/arch/arm/nvidia/tegra_io.c:1.5	Sun May  3 01:07:44 2015
+++ src/sys/arch/arm/nvidia/tegra_io.c	Tue May  5 00:25:44 2015
@@ -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 <[email protected]>
@@ -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 @@ static const struct tegra_locators tegra
     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",

Index: src/sys/arch/evbarm/conf/JETSONTK1
diff -u src/sys/arch/evbarm/conf/JETSONTK1:1.10 src/sys/arch/evbarm/conf/JETSONTK1:1.11
--- src/sys/arch/evbarm/conf/JETSONTK1:1.10	Sun May  3 18:49:28 2015
+++ src/sys/arch/evbarm/conf/JETSONTK1	Tue May  5 00:25:44 2015
@@ -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 @@ ukphy*		at mii? phy ?
 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

Added files:

Index: src/sys/arch/arm/nvidia/tegra_rtc.c
diff -u /dev/null src/sys/arch/arm/nvidia/tegra_rtc.c:1.1
--- /dev/null	Tue May  5 00:25:44 2015
+++ src/sys/arch/arm/nvidia/tegra_rtc.c	Tue May  5 00:25:44 2015
@@ -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 <[email protected]>
+ * 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;
+}
Index: src/sys/arch/arm/nvidia/tegra_rtcreg.h
diff -u /dev/null src/sys/arch/arm/nvidia/tegra_rtcreg.h:1.1
--- /dev/null	Tue May  5 00:25:44 2015
+++ src/sys/arch/arm/nvidia/tegra_rtcreg.h	Tue May  5 00:25:44 2015
@@ -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 <[email protected]>
+ * 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 */

Reply via email to