Module Name:    src
Committed By:   tsutsui
Date:           Wed Sep  1 17:06:00 UTC 2010

Modified Files:
        src/sys/arch/dreamcast/dev/g2: g2rtc.c

Log Message:
- split device_t/softc
- allocate struct todr_chip_handle in per-device softc
- some cosmetics


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/dreamcast/dev/g2/g2rtc.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/dreamcast/dev/g2/g2rtc.c
diff -u src/sys/arch/dreamcast/dev/g2/g2rtc.c:1.4 src/sys/arch/dreamcast/dev/g2/g2rtc.c:1.5
--- src/sys/arch/dreamcast/dev/g2/g2rtc.c:1.4	Sat Dec 12 14:44:09 2009
+++ src/sys/arch/dreamcast/dev/g2/g2rtc.c	Wed Sep  1 17:06:00 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: g2rtc.c,v 1.4 2009/12/12 14:44:09 tsutsui Exp $ */
+/* $NetBSD: g2rtc.c,v 1.5 2010/09/01 17:06:00 tsutsui Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: g2rtc.c,v 1.4 2009/12/12 14:44:09 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: g2rtc.c,v 1.5 2010/09/01 17:06:00 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -46,36 +46,30 @@
 #define G2RTC_OFFSET	(20 * SECYR + 5 * SECDAY)
 
 struct g2rtc_softc {
-	struct device sc_dev;
+	device_t sc_dev;
 
 	bus_space_tag_t sc_bt;
 	bus_space_handle_t sc_bh;
+	struct todr_chip_handle sc_tch;
 };
 
 /* autoconf glue */
-static int g2rtc_match(struct device *, struct cfdata *, void *);
-static void g2rtc_attach(struct device *, struct device *, void *);
+static int g2rtc_match(device_t, cfdata_t, void *);
+static void g2rtc_attach(device_t, device_t, void *);
 
-CFATTACH_DECL(g2rtc, sizeof(struct g2rtc_softc),
-	      g2rtc_match, g2rtc_attach, NULL, NULL);
+CFATTACH_DECL_NEW(g2rtc, sizeof(struct g2rtc_softc),
+    g2rtc_match, g2rtc_attach, NULL, NULL);
 
 
 /* todr(9) methods */
 static int g2rtc_todr_gettime(todr_chip_handle_t, struct timeval *);
 static int g2rtc_todr_settime(todr_chip_handle_t, struct timeval *);
 
-static struct todr_chip_handle g2rtc_todr_handle = {
-	.cookie       = NULL,	/* set on attach */
-	.todr_gettime = g2rtc_todr_gettime,
-	.todr_settime = g2rtc_todr_settime,
-};
-
-
 static inline uint32_t g2rtc_read(bus_space_tag_t, bus_space_handle_t);
 
 
 static int
-g2rtc_match(struct device *parent, struct cfdata *cf, void *aux)
+g2rtc_match(device_t parent, cfdata_t cf, void *aux)
 {
 	static int g2rtc_matched = 0;
 
@@ -88,22 +82,26 @@
 
 
 static void
-g2rtc_attach(struct device *parent, struct device *self, void *aux)
+g2rtc_attach(device_t parent, device_t self, void *aux)
 {
-	struct g2rtc_softc *sc = (void *)self;
+	struct g2rtc_softc *sc = device_private(self);
 	struct g2bus_attach_args *ga = aux;
+	todr_chip_handle_t tch;
 
+	sc->sc_dev = self;
 	sc->sc_bt = ga->ga_memt;
 	if (bus_space_map(sc->sc_bt, G2RTC_REG_BASE, G2RTC_REG_SIZE, 0,
-			  &sc->sc_bh) != 0)
-	{
+	    &sc->sc_bh) != 0) {
 		printf(": unable to map registers\n");
 		return;
 	}
 	printf(": time-of-day clock\n");
 
-	g2rtc_todr_handle.cookie = sc;
-	todr_attach(&g2rtc_todr_handle);
+	tch = &sc->sc_tch;
+	tch->cookie = sc;
+	tch->todr_gettime = g2rtc_todr_gettime,
+	tch->todr_settime = g2rtc_todr_settime,
+	todr_attach(tch);
 }
 
 
@@ -112,7 +110,7 @@
 {
 	
 	return ((bus_space_read_4(bt, bh, 0) & 0xffff) << 16)
-		| (bus_space_read_4(bt, bh, 4) & 0xffff);
+	    | (bus_space_read_4(bt, bh, 4) & 0xffff);
 }
 
 
@@ -173,5 +171,4 @@
 	}
 
 	return EIO;
-
 }

Reply via email to