Module Name:    src
Committed By:   nisimura
Date:           Tue Feb  7 09:06:05 UTC 2012

Modified Files:
        src/distrib/utils/sysinst/arch/evbarm: Makefile md.c md.h
        src/sys/arch/arm/s3c2xx0: files.s3c2440 s3c2440reg.h s3c24x0_clk.c
            s3c2800_clk.c sscom.c sscom_s3c2440.c
Added Files:
        src/sys/arch/arm/s3c2xx0: s3c2440_rtc.c

Log Message:
- add MBR editing menu to sysinst.
- fix typos in timecounter names.
- make sure to drain Tx FIFO to avoid clobbering
  kernel boot messages.
- allow to have the 3rd UART.
- add missing time-of-day clock support.

Ok by releng.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/distrib/utils/sysinst/arch/evbarm/Makefile
cvs rdiff -u -r1.25 -r1.26 src/distrib/utils/sysinst/arch/evbarm/md.c
cvs rdiff -u -r1.18 -r1.19 src/distrib/utils/sysinst/arch/evbarm/md.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/s3c2xx0/files.s3c2440 \
    src/sys/arch/arm/s3c2xx0/s3c2440reg.h \
    src/sys/arch/arm/s3c2xx0/sscom_s3c2440.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/s3c2xx0/s3c2440_rtc.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/s3c2xx0/s3c24x0_clk.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/s3c2xx0/s3c2800_clk.c
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/arm/s3c2xx0/sscom.c

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

Modified files:

Index: src/distrib/utils/sysinst/arch/evbarm/Makefile
diff -u src/distrib/utils/sysinst/arch/evbarm/Makefile:1.5 src/distrib/utils/sysinst/arch/evbarm/Makefile:1.6
--- src/distrib/utils/sysinst/arch/evbarm/Makefile:1.5	Sat Feb 19 17:00:39 2005
+++ src/distrib/utils/sysinst/arch/evbarm/Makefile	Tue Feb  7 09:06:04 2012
@@ -1,8 +1,10 @@
-#	$NetBSD: Makefile,v 1.5 2005/02/19 17:00:39 dsl Exp $
+#	$NetBSD: Makefile,v 1.6 2012/02/07 09:06:04 nisimura Exp $
 #
 # Makefile for evbarm
 #
 
+MENUS_MD= menus.md.${SYSINSTLANG} menus.mbr
+MSG_MD= msg.md.${SYSINSTLANG} msg.mbr.${SYSINSTLANG}
 MD_OPTIONS=	AOUT2ELF
 
 .include "../../Makefile.inc"

Index: src/distrib/utils/sysinst/arch/evbarm/md.c
diff -u src/distrib/utils/sysinst/arch/evbarm/md.c:1.25 src/distrib/utils/sysinst/arch/evbarm/md.c:1.26
--- src/distrib/utils/sysinst/arch/evbarm/md.c:1.25	Fri Nov  4 11:27:02 2011
+++ src/distrib/utils/sysinst/arch/evbarm/md.c	Tue Feb  7 09:06:04 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: md.c,v 1.25 2011/11/04 11:27:02 martin Exp $ */
+/*	$NetBSD: md.c,v 1.26 2012/02/07 09:06:04 nisimura Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -67,6 +67,15 @@ md_get_info(void)
 	int fd;
 	char dev_name[100];
 
+	if (no_mbr)
+		return 1;
+
+	if (read_mbr(diskdev, &mbr) < 0)
+		memset(&mbr.mbr, 0, sizeof(mbr.mbr)-2);
+
+	if (edit_mbr(&mbr) == 0)
+		return 0;
+
 	if (strncmp(diskdev, "wd", 2) == 0)
 		disktype = "ST506";
 	else
@@ -131,6 +140,17 @@ md_check_partitions(void)
 int
 md_pre_disklabel(void)
 {
+	if (no_mbr)
+		return 0;
+
+	msg_display(MSG_dofdisk);
+
+	/* write edited MBR onto disk. */
+	if (write_mbr(diskdev, &mbr, 1) != 0) {
+		msg_display(MSG_wmbrfail);
+		process_menu(MENU_ok, NULL);
+		return 1;
+	}
 	return 0;
 }
 
@@ -187,3 +207,15 @@ md_pre_mount()
 {
 	return 0;
 }
+
+int
+md_check_mbr(mbr_info_t *mbri)
+{
+	return 2;
+}
+
+int
+md_mbr_use_wholedisk(mbr_info_t *mbri)
+{
+	return mbr_use_wholedisk(mbri);
+}

Index: src/distrib/utils/sysinst/arch/evbarm/md.h
diff -u src/distrib/utils/sysinst/arch/evbarm/md.h:1.18 src/distrib/utils/sysinst/arch/evbarm/md.h:1.19
--- src/distrib/utils/sysinst/arch/evbarm/md.h:1.18	Fri Feb  3 00:35:35 2012
+++ src/distrib/utils/sysinst/arch/evbarm/md.h	Tue Feb  7 09:06:04 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: md.h,v 1.18 2012/02/03 00:35:35 nisimura Exp $	*/
+/*	$NetBSD: md.h,v 1.19 2012/02/07 09:06:04 nisimura Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -35,11 +35,15 @@
 
 /* md.h -- Machine specific definitions for evbarm */
 
+#include "mbr.h"
+
 /* Constants and defines */
 
 /* Megs required for a full X installation. */
 #define XNEEDMB 60
 
+#define HAVE_UFS2_BOOT
+
 /*
  *  Default filesets to fetch and install during installation
  *  or upgrade. The standard sets are:

Index: src/sys/arch/arm/s3c2xx0/files.s3c2440
diff -u src/sys/arch/arm/s3c2xx0/files.s3c2440:1.1 src/sys/arch/arm/s3c2xx0/files.s3c2440:1.2
--- src/sys/arch/arm/s3c2xx0/files.s3c2440:1.1	Mon Jan 30 03:28:33 2012
+++ src/sys/arch/arm/s3c2xx0/files.s3c2440	Tue Feb  7 09:06:04 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: files.s3c2440,v 1.1 2012/01/30 03:28:33 nisimura Exp $
+#	$NetBSD: files.s3c2440,v 1.2 2012/02/07 09:06:04 nisimura Exp $
 #
 # Configuration info for Samsung S3C2440
 #
@@ -49,3 +49,8 @@ file	arch/arm/s3c2xx0/s3c2440_i2s.c		ssi
 device	sstouch: wsmousedev, tpcalib
 attach	sstouch at ssio
 file	arch/arm/s3c2xx0/s3c2440_touch.c	sstouch
+
+# RTC
+device ssrtc
+attach ssrtc at ssio
+file	arch/arm/s3c2xx0/s3c2440_rtc.c		ssrtc
Index: src/sys/arch/arm/s3c2xx0/s3c2440reg.h
diff -u src/sys/arch/arm/s3c2xx0/s3c2440reg.h:1.1 src/sys/arch/arm/s3c2xx0/s3c2440reg.h:1.2
--- src/sys/arch/arm/s3c2xx0/s3c2440reg.h:1.1	Mon Jan 30 03:28:33 2012
+++ src/sys/arch/arm/s3c2xx0/s3c2440reg.h	Tue Feb  7 09:06:05 2012
@@ -102,6 +102,8 @@
 #define	S3C2440_IIS_BASE 	0x55000000
 #define	S3C2440_GPIO_BASE	0x56000000
 #define	S3C2440_GPIO_SIZE	0xd0
+#define S3C2440_RTC_BASE	0x57000000
+#define S3C2440_RTC_SIZE	0x8B
 #define	S3C2440_ADC_BASE 	0x58000000
 #define	S3C2440_ADC_SIZE 	0x18
 #define	S3C2440_SPI0_BASE 	0x59000000
@@ -228,6 +230,23 @@
 #define	 EXTINTR_RISING  0x04
 #define	 EXTINTR_BOTH    0x06
 
+/* RTC */
+#define RTC_RTCCON		0x40
+#define  RTCCON_CLKRST		(1<<3)
+#define  RTCCON_CNTSEL		(1<<2)
+#define  RTCCON_CLKSEL		(1<<1)
+#define  RTCCON_RTCEN		(1<<0)
+#define RTC_TICNT		0x44
+#define  TICNT_INT		0x80
+#define  TICNT_COUNT_MASK	0x7F
+#define RTC_BCDSEC		0x70
+#define RTC_BCDMIN		0x74
+#define RTC_BCDHOUR		0x78
+#define RTC_BCDDATE		0x7C
+#define RTC_BCDDAY		0x80
+#define RTC_BCDMON		0x84
+#define RTC_BCDYEAR		0x88
+
 /* UART */
 #undef UFCON_TXTRIGGER_0
 #undef UFCON_TXTRIGGER_4
Index: src/sys/arch/arm/s3c2xx0/sscom_s3c2440.c
diff -u src/sys/arch/arm/s3c2xx0/sscom_s3c2440.c:1.1 src/sys/arch/arm/s3c2xx0/sscom_s3c2440.c:1.2
--- src/sys/arch/arm/s3c2xx0/sscom_s3c2440.c:1.1	Mon Jan 30 03:28:33 2012
+++ src/sys/arch/arm/s3c2xx0/sscom_s3c2440.c	Tue Feb  7 09:06:05 2012
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sscom_s3c2440.c,v 1.1 2012/01/30 03:28:33 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sscom_s3c2440.c,v 1.2 2012/02/07 09:06:05 nisimura Exp $");
 
 #include "opt_sscom.h"
 #include "opt_ddb.h"
@@ -70,36 +70,24 @@ __KERNEL_RCSID(0, "$NetBSD: sscom_s3c244
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#include <sys/ioctl.h>
-#include <sys/select.h>
-#include <sys/tty.h>
-#include <sys/proc.h>
-#include <sys/conf.h>
-#include <sys/file.h>
-#include <sys/uio.h>
-#include <sys/kernel.h>
-#include <sys/syslog.h>
-#include <sys/types.h>
 #include <sys/device.h>
-#include <sys/malloc.h>
-#include <sys/timepps.h>
-#include <sys/vnode.h>
 
-#include <machine/intr.h>
 #include <sys/bus.h>
+#include <machine/intr.h>
 
 #include <arm/s3c2xx0/s3c2440reg.h>
 #include <arm/s3c2xx0/s3c2440var.h>
 #include <arm/s3c2xx0/sscom_var.h>
-#include <sys/termios.h>
 
-static int sscom_match(struct device *, struct cfdata *, void *);
-static void sscom_attach(struct device *, struct device *, void *);
+#include "locators.h"
+
+static int sscom_match(device_t, struct cfdata *, void *);
+static void sscom_attach(device_t, struct device *, void *);
 
 CFATTACH_DECL_NEW(sscom, sizeof(struct sscom_softc), sscom_match,
     sscom_attach, NULL, NULL);
 
-const struct sscom_uart_info s3c2440_uart_config[] = {
+const static struct sscom_uart_info s3c2440_uart_config[] = {
 	/* UART 0 */
 	{
 		0,
@@ -125,33 +113,38 @@ const struct sscom_uart_info s3c2440_uar
 		S3C2440_UART_BASE(2),
 	},
 };
+static int found;
 
 static int
-sscom_match(struct device *parent, struct cfdata *cf, void *aux)
+sscom_match(device_t parent, struct cfdata *cf, void *aux)
 {
 	struct s3c2xx0_attach_args *sa = aux;
 	int unit = sa->sa_index;
 
-	return unit == 0 || unit == 1;
+	if (unit == SSIOCF_INDEX_DEFAULT && found == 0)
+		return 1;
+	return (unit == 0 || unit == 1 || unit == 2);
 }
 
 static void
-sscom_attach(struct device *parent, struct device *self, void *aux)
+sscom_attach(device_t parent, struct device *self, void *aux)
 {
 	struct sscom_softc *sc = device_private(self);
 	struct s3c2xx0_attach_args *sa = aux;
-	int unit = sa->sa_index;
-	bus_addr_t iobase = s3c2440_uart_config[unit].iobase;
+	int unit;
+	bus_addr_t iobase;
 
-	printf( ": UART%d addr=%lx", sa->sa_index, iobase );
+	found = 1;
+	unit = (sa->sa_index == SSIOCF_INDEX_DEFAULT) ? 0 : sa->sa_index;
+	iobase = s3c2440_uart_config[unit].iobase;
 
 	sc->sc_dev = self;
 	sc->sc_iot = s3c2xx0_softc->sc_iot;
 	sc->sc_unit = unit;
 	sc->sc_frequency = s3c2xx0_softc->sc_pclk;
 
-	sc->sc_rx_irqno = s3c2440_uart_config[sa->sa_index].rx_int;
-	sc->sc_tx_irqno = s3c2440_uart_config[sa->sa_index].tx_int;
+	sc->sc_rx_irqno = s3c2440_uart_config[unit].rx_int;
+	sc->sc_tx_irqno = s3c2440_uart_config[unit].tx_int;
 
 	if (bus_space_map(sc->sc_iot, iobase, SSCOM_SIZE, 0, &sc->sc_ioh)) {
 		printf( ": failed to map registers\n" );
@@ -171,8 +164,6 @@ sscom_attach(struct device *parent, stru
 	sscom_attach_subr(sc);
 }
 
-
-
 int
 s3c2440_sscom_cnattach(bus_space_tag_t iot, int unit, int rate,
     int frequency, tcflag_t cflag)

Index: src/sys/arch/arm/s3c2xx0/s3c24x0_clk.c
diff -u src/sys/arch/arm/s3c2xx0/s3c24x0_clk.c:1.12 src/sys/arch/arm/s3c2xx0/s3c24x0_clk.c:1.13
--- src/sys/arch/arm/s3c2xx0/s3c24x0_clk.c:1.12	Mon Jan 30 03:28:33 2012
+++ src/sys/arch/arm/s3c2xx0/s3c24x0_clk.c	Tue Feb  7 09:06:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: s3c24x0_clk.c,v 1.12 2012/01/30 03:28:33 nisimura Exp $ */
+/*	$NetBSD: s3c24x0_clk.c,v 1.13 2012/02/07 09:06:05 nisimura Exp $ */
 
 /*
  * Copyright (c) 2003  Genetec corporation.  All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: s3c24x0_clk.c,v 1.12 2012/01/30 03:28:33 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: s3c24x0_clk.c,v 1.13 2012/02/07 09:06:05 nisimura Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -70,7 +70,7 @@ static struct timecounter s3c24x0_timeco
 	0,			/* no poll_pps */
 	0xfff,			/* counter_mask */
 	0,			/* frequency */
-	"s3c234x0",		/* name */
+	"s3c24x0",		/* name */
 	100,			/* quality */
 	NULL,			/* prev */
 	NULL,			/* next */

Index: src/sys/arch/arm/s3c2xx0/s3c2800_clk.c
diff -u src/sys/arch/arm/s3c2xx0/s3c2800_clk.c:1.16 src/sys/arch/arm/s3c2xx0/s3c2800_clk.c:1.17
--- src/sys/arch/arm/s3c2xx0/s3c2800_clk.c:1.16	Fri Jul  1 20:31:39 2011
+++ src/sys/arch/arm/s3c2xx0/s3c2800_clk.c	Tue Feb  7 09:06:05 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: s3c2800_clk.c,v 1.16 2011/07/01 20:31:39 dyoung Exp $ */
+/* $NetBSD: s3c2800_clk.c,v 1.17 2012/02/07 09:06:05 nisimura Exp $ */
 
 /*
  * Copyright (c) 2002 Fujitsu Component Limited
@@ -34,7 +34,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: s3c2800_clk.c,v 1.16 2011/07/01 20:31:39 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: s3c2800_clk.c,v 1.17 2012/02/07 09:06:05 nisimura Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -73,8 +73,8 @@ static struct timecounter s3c2800_timeco
 	s3c2800_get_timecount,	/* get_timecount */
 	0,			/* no poll_pps */
 	0xffffffff,		/* counter_mask */
-	0,		/* frequency */
-	"s3c23800",		/* name */
+	0,			/* frequency */
+	"s3c2800",		/* name */
 	100,			/* quality */
 	NULL,			/* prev */
 	NULL,			/* next */

Index: src/sys/arch/arm/s3c2xx0/sscom.c
diff -u src/sys/arch/arm/s3c2xx0/sscom.c:1.36 src/sys/arch/arm/s3c2xx0/sscom.c:1.37
--- src/sys/arch/arm/s3c2xx0/sscom.c:1.36	Sat Feb  4 18:50:42 2012
+++ src/sys/arch/arm/s3c2xx0/sscom.c	Tue Feb  7 09:06:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sscom.c,v 1.36 2012/02/04 18:50:42 christos Exp $ */
+/*	$NetBSD: sscom.c,v 1.37 2012/02/07 09:06:05 nisimura Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 Fujitsu Component Limited
@@ -98,7 +98,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sscom.c,v 1.36 2012/02/04 18:50:42 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sscom.c,v 1.37 2012/02/07 09:06:05 nisimura Exp $");
 
 #include "opt_sscom.h"
 #include "opt_ddb.h"
@@ -430,13 +430,19 @@ sscom_attach_subr(struct sscom_softc *sc
 #endif
 
 	if (unit == sscomconsunit) {
-		sscomconsattached = 1;
+		int timo, stat;
 
+		sscomconsattached = 1;
 		sscomconstag = iot;
 		sscomconsioh = ioh;
 
+		/* wait for this transmission to complete */
+		timo = 1500000;
+		do {
+			stat = bus_space_read_1(iot, ioh, SSCOM_UTRSTAT);
+		} while ((stat & UTRSTAT_TXEMPTY) == 0 && --timo > 0);
+
 		/* Make sure the console is always "hardwired". */
-		delay(1000);			/* XXX: wait for output to finish */
 		SET(sc->sc_hwflags, SSCOM_HW_CONSOLE);
 		SET(sc->sc_swflags, TIOCFLAG_SOFTCAR);
 

Added files:

Index: src/sys/arch/arm/s3c2xx0/s3c2440_rtc.c
diff -u /dev/null src/sys/arch/arm/s3c2xx0/s3c2440_rtc.c:1.1
--- /dev/null	Tue Feb  7 09:06:05 2012
+++ src/sys/arch/arm/s3c2xx0/s3c2440_rtc.c	Tue Feb  7 09:06:04 2012
@@ -0,0 +1,173 @@
+/*--
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Paul Fleischer <p...@xpg.dk>
+ *
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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 <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/bus.h>
+#include <sys/time.h>
+
+#include <dev/clock_subr.h>
+
+#include <arm/s3c2xx0/s3c24x0var.h>
+#include <arm/s3c2xx0/s3c2440var.h>
+#include <arm/s3c2xx0/s3c2440reg.h>
+
+#ifdef SSRTC_DEBUG
+#define DPRINTF(s) do { printf s; } while (/*CONSTCOND*/0)
+#else
+#define DPRINTF(s) do {} while (/*CONSTCOND*/0)
+#endif
+
+/* As the RTC keeps track of Leap years, we need to use the right zero-year */
+#define SSRTC_YEAR_ZERO 2000
+
+struct ssrtc_softc {
+	device_t		sc_dev;
+	bus_space_tag_t		sc_iot;
+	bus_space_handle_t	sc_ioh;
+	struct todr_chip_handle	sc_todr;
+};
+
+static int  ssrtc_match(device_t, cfdata_t, void *);
+static void ssrtc_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(ssrtc, sizeof(struct ssrtc_softc),
+  ssrtc_match, ssrtc_attach, NULL, NULL);
+
+static int ssrtc_todr_gettime(struct todr_chip_handle *, struct timeval *);
+static int ssrtc_todr_settime(struct todr_chip_handle *, struct timeval *);
+
+static int
+ssrtc_match(device_t parent, cfdata_t cf, void *aux)
+{
+	return 1;
+}
+
+static void
+ssrtc_attach(device_t parent, device_t self, void *aux)
+{
+	struct ssrtc_softc *sc = device_private(self);
+	struct s3c2xx0_attach_args *sa = aux;
+
+	sc->sc_dev = self;
+	sc->sc_iot = sa->sa_iot;
+
+	if (bus_space_map(sc->sc_iot, S3C2440_RTC_BASE,
+			  S3C2440_RTC_SIZE, 0, &sc->sc_ioh)) {
+		aprint_error(": failed to map registers");
+		return;
+	}
+	aprint_normal(": RTC \n");
+
+	sc->sc_todr.cookie = sc;
+	sc->sc_todr.todr_gettime = ssrtc_todr_gettime;
+	sc->sc_todr.todr_settime = ssrtc_todr_settime;
+	sc->sc_todr.todr_setwen = NULL;
+
+	todr_attach(&sc->sc_todr);
+}
+
+static int
+ssrtc_todr_gettime(struct todr_chip_handle *h, struct timeval *tv)
+{
+	struct ssrtc_softc *sc = h->cookie;
+	struct clock_ymdhms dt;
+	uint8_t reg;
+
+	reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, RTC_BCDSEC);
+	DPRINTF(("BCDSEC: %02X\n", reg));
+	dt.dt_sec = FROMBCD(reg);
+
+	reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, RTC_BCDMIN);
+	DPRINTF(("BCDMIN: %02X\n", reg));
+	dt.dt_min = FROMBCD(reg);
+
+	reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, RTC_BCDHOUR);
+	DPRINTF(("BCDHOUR: %02X\n", reg));
+	dt.dt_hour = FROMBCD(reg);
+
+	reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, RTC_BCDDATE);
+	DPRINTF(("BCDDATE: %02X\n", reg));
+	dt.dt_day = FROMBCD(reg);
+
+	reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, RTC_BCDDAY);
+	DPRINTF(("BCDDAY: %02X\n", reg));
+	dt.dt_wday = FROMBCD(reg);
+
+	reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, RTC_BCDMON);
+	DPRINTF(("BCDMON: %02X\n", reg));
+	dt.dt_mon = FROMBCD(reg);
+
+	reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, RTC_BCDYEAR);
+	DPRINTF(("BCDYEAR: %02X\n", reg));
+	dt.dt_year = SSRTC_YEAR_ZERO + FROMBCD(reg);
+
+	DPRINTF(("Seconds: %d\n", dt.dt_sec));
+	DPRINTF(("Minutes: %d\n", dt.dt_min));
+	DPRINTF(("Hour: %d\n", dt.dt_hour));
+	DPRINTF(("Mon: %d\n", dt.dt_mon));
+	DPRINTF(("Date: %d\n", dt.dt_day));
+	DPRINTF(("Day: %d\n", dt.dt_wday));
+	DPRINTF(("Year: %d\n", dt.dt_year));
+
+	tv->tv_sec = clock_ymdhms_to_secs(&dt);
+	tv->tv_usec = 0;
+
+	return 0;
+}
+
+static int
+ssrtc_todr_settime(struct todr_chip_handle *h, struct timeval *tv)
+{
+	struct ssrtc_softc *sc = h->cookie;
+	struct clock_ymdhms dt;
+	uint8_t reg;
+
+	clock_secs_to_ymdhms(tv->tv_sec, &dt);
+
+	DPRINTF(("ssrtc_todr_settime"));
+
+	/* Set RTCEN */
+	reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, RTC_RTCCON);
+	bus_space_write_1(sc->sc_iot, sc->sc_ioh, RTC_RTCCON, reg | RTCCON_RTCEN);
+
+	bus_space_write_1(sc->sc_iot, sc->sc_ioh, RTC_BCDSEC, TOBCD(dt.dt_sec));
+	bus_space_write_1(sc->sc_iot, sc->sc_ioh, RTC_BCDMIN, TOBCD(dt.dt_min));
+	bus_space_write_1(sc->sc_iot, sc->sc_ioh, RTC_BCDHOUR, TOBCD(dt.dt_hour));
+	bus_space_write_1(sc->sc_iot, sc->sc_ioh, RTC_BCDDATE, TOBCD(dt.dt_day));
+	bus_space_write_1(sc->sc_iot, sc->sc_ioh, RTC_BCDDAY, TOBCD(dt.dt_wday));
+	bus_space_write_1(sc->sc_iot, sc->sc_ioh, RTC_BCDMON, TOBCD(dt.dt_mon));
+	bus_space_write_1(sc->sc_iot, sc->sc_ioh, RTC_BCDYEAR, TOBCD(dt.dt_year-SSRTC_YEAR_ZERO));
+
+	/* Clear RTCEN */
+	reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, RTC_RTCCON);
+	bus_space_write_1(sc->sc_iot, sc->sc_ioh, RTC_RTCCON, reg & ~RTCCON_RTCEN);
+	return 0;
+}

Reply via email to