Module Name:    src
Committed By:   tsutsui
Date:           Sat Apr 19 05:37:54 UTC 2014

Modified Files:
        src/sys/arch/hp300/conf: GENERIC INSTALL files.hp300
        src/sys/arch/hp300/dev: frodo.c frodoreg.h rtc.c
Added Files:
        src/sys/arch/hp300/dev: mcclock_frodo.c

Log Message:
Add proper RealTime Clock support for HP9000/425e.

As the OpenBSD/hp300 page says 425e doesn't have the traditional
RTC at intio (as it also lacks DCA 16550 serial at intio?),
but after a few hour investigation it turns out that
425e uses mc146818 compatible calendar clock in
the Apollo "frodo" utility chip and the frodo chip on
425e actually has the 32kHz OSC and is actually backed up
by the onboard lithium battery.

Tested on HP425e (with mcclock) and HP362 (with old rtc).


To generate a diff of this commit:
cvs rdiff -u -r1.180 -r1.181 src/sys/arch/hp300/conf/GENERIC
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/hp300/conf/INSTALL
cvs rdiff -u -r1.86 -r1.87 src/sys/arch/hp300/conf/files.hp300
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/hp300/dev/frodo.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/hp300/dev/frodoreg.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/hp300/dev/mcclock_frodo.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/hp300/dev/rtc.c

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/hp300/conf/GENERIC
diff -u src/sys/arch/hp300/conf/GENERIC:1.180 src/sys/arch/hp300/conf/GENERIC:1.181
--- src/sys/arch/hp300/conf/GENERIC:1.180	Fri Aug 16 13:39:47 2013
+++ src/sys/arch/hp300/conf/GENERIC	Sat Apr 19 05:37:54 2014
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.180 2013/08/16 13:39:47 tsutsui Exp $
+# $NetBSD: GENERIC,v 1.181 2014/04/19 05:37:54 tsutsui Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@ include 	"arch/hp300/conf/std.hp300"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.180 $"
+#ident 		"GENERIC-$Revision: 1.181 $"
 
 maxusers	32		# estimated number of users
 
@@ -213,6 +213,9 @@ wskbd*		at dnkbd? mux 1
 wsmouse*	at dnkbd? mux 0
 com*		at frodo? offset ?	# tty flavor
 
+# mc146818-like real time clock found on 425e
+mcclock0	at frodo? offset 0x80
+
 dvbox*		at intio?		# Davinci framebuffer
 dvbox*		at dio? scode ?
 wsdisplay*	at dvbox?

Index: src/sys/arch/hp300/conf/INSTALL
diff -u src/sys/arch/hp300/conf/INSTALL:1.55 src/sys/arch/hp300/conf/INSTALL:1.56
--- src/sys/arch/hp300/conf/INSTALL:1.55	Sun Jun 30 21:38:57 2013
+++ src/sys/arch/hp300/conf/INSTALL	Sat Apr 19 05:37:54 2014
@@ -1,4 +1,4 @@
-# $NetBSD: INSTALL,v 1.55 2013/06/30 21:38:57 rmind Exp $
+# $NetBSD: INSTALL,v 1.56 2014/04/19 05:37:54 tsutsui Exp $
 #
 # INSTALL machine description file
 #
@@ -157,6 +157,9 @@ frodo*		at intio?
 #wskbd*		at dnkbd? mux 1
 com*		at frodo? offset ?	# tty flavor
 
+# mc146818-like real time clock found on 425e
+mcclock0	at frodo? offset 0x80
+
 # Davinci framebuffer
 dvbox*		at intio?
 dvbox*		at dio? scode ?

Index: src/sys/arch/hp300/conf/files.hp300
diff -u src/sys/arch/hp300/conf/files.hp300:1.86 src/sys/arch/hp300/conf/files.hp300:1.87
--- src/sys/arch/hp300/conf/files.hp300:1.86	Fri Aug 16 13:39:47 2013
+++ src/sys/arch/hp300/conf/files.hp300	Sat Apr 19 05:37:54 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files.hp300,v 1.86 2013/08/16 13:39:47 tsutsui Exp $
+#	$NetBSD: files.hp300,v 1.87 2014/04/19 05:37:54 tsutsui Exp $
 #
 # hp300-specific configuration info
 
@@ -85,6 +85,11 @@ attach	dnkbd at frodo
 file	arch/hp300/dev/dnkbd.c			dnkbd	needs-flag
 file	arch/hp300/dev/dnkbdmap.c		dnkbd
 
+# An mc146818-like calendar on 425e
+device	mcclock: mc146818
+attach mcclock at frodo with mcclock_frodo
+file	arch/hp300/dev/mcclock_frodo.c		mcclock_frodo
+
 #
 # Frame buffer devices on Internal I/O and the DIO bus
 #

Index: src/sys/arch/hp300/dev/frodo.c
diff -u src/sys/arch/hp300/dev/frodo.c:1.30 src/sys/arch/hp300/dev/frodo.c:1.31
--- src/sys/arch/hp300/dev/frodo.c:1.30	Sat Feb 12 22:48:04 2011
+++ src/sys/arch/hp300/dev/frodo.c	Sat Apr 19 05:37:54 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: frodo.c,v 1.30 2011/02/12 22:48:04 tsutsui Exp $	*/
+/*	$NetBSD: frodo.c,v 1.31 2014/04/19 05:37:54 tsutsui Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: frodo.c,v 1.30 2011/02/12 22:48:04 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frodo.c,v 1.31 2014/04/19 05:37:54 tsutsui Exp $");
 
 #define	_HP300_INTR_H_PRIVATE
 
@@ -117,6 +117,7 @@ static const struct frodo_device frodo_s
 	{ "com",	FRODO_APCI_OFFSET(1),	FRODO_INTR_APCI1 },
 	{ "com",	FRODO_APCI_OFFSET(2),	FRODO_INTR_APCI2 },
 	{ "com",	FRODO_APCI_OFFSET(3),	FRODO_INTR_APCI3 },
+	{ "mcclock",	FRODO_CALENDAR,		FRODO_INTR_CALENDAR },
 	{ NULL,		0,			0 }
 };
 

Index: src/sys/arch/hp300/dev/frodoreg.h
diff -u src/sys/arch/hp300/dev/frodoreg.h:1.4 src/sys/arch/hp300/dev/frodoreg.h:1.5
--- src/sys/arch/hp300/dev/frodoreg.h:1.4	Wed Jul 19 17:21:23 2006
+++ src/sys/arch/hp300/dev/frodoreg.h	Sat Apr 19 05:37:54 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: frodoreg.h,v 1.4 2006/07/19 17:21:23 tsutsui Exp $	*/
+/*	$NetBSD: frodoreg.h,v 1.5 2014/04/19 05:37:54 tsutsui Exp $	*/
 
 /*
  * Copyright (c) 1997 Michael Smith.  All rights reserved.
@@ -36,7 +36,7 @@
  * Other items in the Frodo part
  */
 
-/* An mc146818-like calendar, but no battery... lame */
+/* An mc146818-like calendar.  Only 425e has a battery and an oscillator. */
 #define	FRODO_CALENDAR		0x80
 
 #define	FRODO_TIMER		0xa0	/* 8254-like timer */

Index: src/sys/arch/hp300/dev/rtc.c
diff -u src/sys/arch/hp300/dev/rtc.c:1.20 src/sys/arch/hp300/dev/rtc.c:1.21
--- src/sys/arch/hp300/dev/rtc.c:1.20	Tue Feb  8 20:20:13 2011
+++ src/sys/arch/hp300/dev/rtc.c	Sat Apr 19 05:37:54 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtc.c,v 1.20 2011/02/08 20:20:13 rmind Exp $	*/
+/*	$NetBSD: rtc.c,v 1.21 2014/04/19 05:37:54 tsutsui Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtc.c,v 1.20 2011/02/08 20:20:13 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtc.c,v 1.21 2014/04/19 05:37:54 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -79,6 +79,10 @@ rtcmatch(device_t parent, cfdata_t cf, v
 {
 	struct intio_attach_args *ia = aux;
 
+	/* 425e doesn't have the traditional RTC at intio */
+	if (machineid == HP_425 && mmuid == MMUID_425_E)
+		return 0;
+
 	if (strcmp("rtc", ia->ia_modname) != 0)
 		return 0;
 

Added files:

Index: src/sys/arch/hp300/dev/mcclock_frodo.c
diff -u /dev/null src/sys/arch/hp300/dev/mcclock_frodo.c:1.1
--- /dev/null	Sat Apr 19 05:37:54 2014
+++ src/sys/arch/hp300/dev/mcclock_frodo.c	Sat Apr 19 05:37:54 2014
@@ -0,0 +1,141 @@
+/*	$NetBSD: mcclock_frodo.c,v 1.1 2014/04/19 05:37:54 tsutsui Exp $	*/
+/*-
+ * Copyright (c) 2014 Izumi Tsutsui.  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 <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: mcclock_frodo.c,v 1.1 2014/04/19 05:37:54 tsutsui Exp $");
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/bus.h>
+
+#include <machine/cpu.h>
+
+#include <dev/clock_subr.h>
+#include <dev/ic/mc146818reg.h>
+#include <dev/ic/mc146818var.h>
+
+#include <hp300/dev/frodoreg.h>
+#include <hp300/dev/frodovar.h>
+
+#include "ioconf.h"
+
+static int	mcclock_frodo_probe(device_t, cfdata_t, void *);
+static void	mcclock_frodo_attach(device_t, device_t, void *);
+
+static u_int	mcclock_frodo_read(struct mc146818_softc *, u_int);
+static void	mcclock_frodo_write(struct mc146818_softc *, u_int, u_int);
+
+CFATTACH_DECL_NEW(mcclock_frodo, sizeof(struct mc146818_softc),
+    mcclock_frodo_probe, mcclock_frodo_attach, NULL, NULL);
+
+#define	MCCLOCK_FRODO_NPORTS	2
+
+static int
+mcclock_frodo_probe(device_t parent, cfdata_t cf, void *aux)
+{
+	struct frodo_attach_args *fa = aux;
+
+	/* only 425e has a valid mcclock */
+	if (machineid != HP_425 || mmuid != MMUID_425_E)
+		return 0;
+
+	if (strcmp(fa->fa_name, mcclock_cd.cd_name) != 0)
+		return 0;
+
+	if (fa->fa_offset != FRODO_CALENDAR)
+		return 0;
+
+	return 1;
+}
+
+static void
+mcclock_frodo_attach(device_t parent, device_t self, void *aux)
+{
+	struct mc146818_softc *sc = device_private(self);
+	struct frodo_attach_args *fa = aux;
+
+	sc->sc_dev = self;
+	sc->sc_bst = fa->fa_bst;
+
+	if (bus_space_map(sc->sc_bst, fa->fa_base + fa->fa_offset,
+	    MCCLOCK_FRODO_NPORTS << 2, 0, &sc->sc_bsh) != 0) {
+		aprint_error(": can't map register\n");
+		return;
+	}
+
+	sc->sc_year0 = 1900;
+	sc->sc_mcread = mcclock_frodo_read;
+	sc->sc_mcwrite = mcclock_frodo_write;
+	sc->sc_flag = 0;
+	mc146818_attach(sc);
+
+	aprint_normal("\n");
+
+	/* XXX: not sure which mode (BINARY or BCD) is used on HP-UX */
+	mcclock_frodo_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
+
+	/* make sure to start the 32.768kHz OSC */
+	mcclock_frodo_write(sc, MC_REGA, 
+	    (mcclock_frodo_read(sc, MC_REGA) & ~MC_REGA_DVMASK) |
+	    MC_BASE_32_KHz);
+}
+
+/*
+ * mc146818 calendar chip in the frodo utility chip is can be accessed
+ * via register port at offset 0x80 and data port at offset 0x84.
+ *
+ * Note 4 byte offset stride is handled by frodo bus_space(9) layer,
+ * so bus_space_read(9) and bus_space_write(9) takes 0 or 1 as offset
+ * to access these registers.
+ */
+
+static void
+mcclock_frodo_write(struct mc146818_softc *sc, u_int reg, u_int datum)
+{
+	bus_space_tag_t iot;
+	bus_space_handle_t ioh;
+
+	iot = sc->sc_bst;
+	ioh = sc->sc_bsh;
+
+	bus_space_write_1(iot, ioh, 0, reg);
+	bus_space_write_1(iot, ioh, 1, datum);
+}
+
+static u_int
+mcclock_frodo_read(struct mc146818_softc *sc, u_int reg)
+{
+	bus_space_tag_t iot;
+	bus_space_handle_t ioh;
+	u_int datum;
+
+	iot = sc->sc_bst;
+	ioh = sc->sc_bsh;
+
+	bus_space_write_1(iot, ioh, 0, reg);
+	datum = bus_space_read_1(iot, ioh, 1);
+
+	return datum;
+}

Reply via email to