Switch dreamcast to MI todr(9).
Dreamcast does not use SuperH on-chip RTC, so do it seprately from other sh3 ports. Convert dreamcast rtc code into a real device instead of searching/attaching it manually. Tested by Nick Hudson.
This commit is contained in:
parent
ea514e44f5
commit
2a48f4de87
@ -1,4 +1,4 @@
|
||||
# $NetBSD: GENERIC,v 1.74 2006/08/26 20:26:44 christos Exp $
|
||||
# $NetBSD: GENERIC,v 1.75 2006/09/05 11:09:36 uwe Exp $
|
||||
#
|
||||
# GENERIC machine description file
|
||||
#
|
||||
@ -187,6 +187,7 @@ mlcd* at maple? port ? subunit ?
|
||||
gdrom0 at shb?
|
||||
|
||||
g2bus0 at shb?
|
||||
g2rtc0 at g2bus? # time-of-day clock
|
||||
gapspci* at g2bus? # GAPS PCI bridge
|
||||
pci* at gapspci?
|
||||
rtk* at pci? dev ? function ? # SEGA Broadband Adapter
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files.dreamcast,v 1.27 2005/12/11 12:17:06 christos Exp $
|
||||
# $NetBSD: files.dreamcast,v 1.28 2006/09/05 11:09:36 uwe Exp $
|
||||
|
||||
# maxpartitions must be first item in files.${MACHINE}
|
||||
maxpartitions 16
|
||||
@ -90,6 +90,10 @@ attach g2bus at shb
|
||||
file arch/dreamcast/dev/g2/g2bus.c g2bus
|
||||
file arch/dreamcast/dev/g2/g2bus_bus_mem.c g2bus
|
||||
|
||||
device g2rtc
|
||||
attach g2rtc at g2bus
|
||||
file arch/dreamcast/dev/g2/g2rtc.c g2rtc
|
||||
|
||||
device gapspci: pcibus
|
||||
attach gapspci at g2bus
|
||||
file arch/dreamcast/dev/g2/gapspci.c gapspci
|
||||
|
183
sys/arch/dreamcast/dev/g2/g2rtc.c
Normal file
183
sys/arch/dreamcast/dev/g2/g2rtc.c
Normal file
@ -0,0 +1,183 @@
|
||||
/* $NetBSD: g2rtc.c,v 1.1 2006/09/05 11:09:36 uwe Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 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>
|
||||
__KERNEL_RCSID(0, "$NetBSD: g2rtc.c,v 1.1 2006/09/05 11:09:36 uwe Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <dev/clock_subr.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
#include <dreamcast/dev/g2/g2busvar.h>
|
||||
|
||||
|
||||
#define G2RTC_REG_BASE 0x00710000
|
||||
#define G2RTC_REG_SIZE 12
|
||||
|
||||
/* Offset by 20 years, 5 of them are leap */
|
||||
#define G2RTC_OFFSET (20 * SECYR + 5 * SECDAY)
|
||||
|
||||
struct g2rtc_softc {
|
||||
struct device sc_dev;
|
||||
|
||||
bus_space_tag_t sc_bt;
|
||||
bus_space_handle_t sc_bh;
|
||||
};
|
||||
|
||||
/* autoconf glue */
|
||||
static int g2rtc_match(struct device *, struct cfdata *, void *);
|
||||
static void g2rtc_attach(struct device *, struct device *, void *);
|
||||
|
||||
CFATTACH_DECL(g2rtc, sizeof(struct g2rtc_softc),
|
||||
g2rtc_match, g2rtc_attach, NULL, NULL);
|
||||
|
||||
|
||||
/* todr(9) methods */
|
||||
static int g2rtc_todr_gettime(todr_chip_handle_t, volatile struct timeval *);
|
||||
static int g2rtc_todr_settime(todr_chip_handle_t, volatile 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)
|
||||
{
|
||||
static int g2rtc_matched = 0;
|
||||
|
||||
if (g2rtc_matched)
|
||||
return 0;
|
||||
|
||||
g2rtc_matched = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
g2rtc_attach(struct device *parent, struct device *self, void *aux)
|
||||
{
|
||||
struct g2rtc_softc *sc = (void *)self;
|
||||
struct g2bus_attach_args *ga = aux;
|
||||
|
||||
sc->sc_bt = ga->ga_memt;
|
||||
if (bus_space_map(sc->sc_bt, G2RTC_REG_BASE, G2RTC_REG_SIZE, 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);
|
||||
}
|
||||
|
||||
|
||||
static inline uint32_t
|
||||
g2rtc_read(bus_space_tag_t bt, bus_space_handle_t bh)
|
||||
{
|
||||
|
||||
return ((bus_space_read_4(bt, bh, 0) & 0xffff) << 16)
|
||||
| (bus_space_read_4(bt, bh, 4) & 0xffff);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get time-of-day and convert to `struct timeval'.
|
||||
* Return 0 on success; an error number otherwise.
|
||||
*/
|
||||
static int
|
||||
g2rtc_todr_gettime(todr_chip_handle_t handle, volatile struct timeval *tv)
|
||||
{
|
||||
struct g2rtc_softc *sc = handle->cookie;
|
||||
uint32_t new, old;
|
||||
int i;
|
||||
|
||||
for (old = 0;;) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
new = g2rtc_read(sc->sc_bt, sc->sc_bh);
|
||||
if (new != old)
|
||||
break;
|
||||
}
|
||||
if (i < 3)
|
||||
old = new;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
tv->tv_sec = new - G2RTC_OFFSET;
|
||||
tv->tv_usec = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Set the time-of-day clock based on the value of the `struct timeval' arg.
|
||||
* Return 0 on success; an error number otherwise.
|
||||
*/
|
||||
static int
|
||||
g2rtc_todr_settime(todr_chip_handle_t handle, volatile struct timeval *tv)
|
||||
{
|
||||
struct g2rtc_softc *sc = handle->cookie;
|
||||
uint32_t secs;
|
||||
int i, retry;
|
||||
|
||||
secs = (uint32_t)tv->tv_sec + G2RTC_OFFSET;
|
||||
|
||||
for (retry = 0; retry < 5; retry++) {
|
||||
|
||||
/* Don't change the order */
|
||||
bus_space_write_4(sc->sc_bt, sc->sc_bh, 8, 1);
|
||||
bus_space_write_4(sc->sc_bt, sc->sc_bh, 4, secs & 0xffff);
|
||||
bus_space_write_4(sc->sc_bt, sc->sc_bh, 0, secs >> 16);
|
||||
|
||||
/* verify */
|
||||
for (i = 0; i < 3; i++)
|
||||
if (g2rtc_read(sc->sc_bt, sc->sc_bh) == secs)
|
||||
return 0; /* ok */
|
||||
}
|
||||
|
||||
return EIO;
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: clock_machdep.c,v 1.5 2005/12/11 12:17:06 christos Exp $ */
|
||||
/* $NetBSD: clock_machdep.c,v 1.6 2006/09/05 11:09:36 uwe Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
@ -34,7 +34,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: clock_machdep.c,v 1.5 2005/12/11 12:17:06 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: clock_machdep.c,v 1.6 2006/09/05 11:09:36 uwe Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -42,31 +42,18 @@ __KERNEL_RCSID(0, "$NetBSD: clock_machdep.c,v 1.5 2005/12/11 12:17:06 christos E
|
||||
#include <dev/clock_subr.h>
|
||||
#include <sh3/clock.h>
|
||||
|
||||
#include <dreamcast/dev/g2/g2busvar.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#define STATIC
|
||||
#else
|
||||
#define STATIC static
|
||||
#endif
|
||||
|
||||
#define DREAMCAST_RTC 0x00710000
|
||||
|
||||
STATIC void dreamcast_rtc_init(void *);
|
||||
STATIC void dreamcast_rtc_get(void *, time_t, struct clock_ymdhms *);
|
||||
STATIC void dreamcast_rtc_set(void *, struct clock_ymdhms *);
|
||||
|
||||
STATIC uint32_t dreamcast_read_rtc(void);
|
||||
STATIC void dreamcast_write_rtc(uint32_t);
|
||||
|
||||
STATIC struct rtc_ops dreamcast_rtc_ops = {
|
||||
.init = dreamcast_rtc_init,
|
||||
.get = dreamcast_rtc_get,
|
||||
.set = dreamcast_rtc_set
|
||||
};
|
||||
|
||||
static bus_space_tag_t rtc_tag;
|
||||
static bus_space_handle_t rtc_handle;
|
||||
|
||||
void
|
||||
machine_clock_init(void)
|
||||
@ -75,90 +62,7 @@ machine_clock_init(void)
|
||||
sh_clock_init(SH_CLOCK_NORTC, &dreamcast_rtc_ops);
|
||||
}
|
||||
|
||||
void
|
||||
STATIC void
|
||||
dreamcast_rtc_init(void *cookie)
|
||||
{
|
||||
struct device *dv;
|
||||
|
||||
/* Find g2bus device */
|
||||
for (dv = TAILQ_FIRST(&alldevs); dv != NULL;
|
||||
dv = TAILQ_NEXT(dv, dv_list))
|
||||
if (!strcmp(dv->dv_xname, "g2bus0"))
|
||||
break;
|
||||
|
||||
if (!dv)
|
||||
panic("No g2bus!");
|
||||
|
||||
rtc_tag = &((struct g2bus_softc *)dv)->sc_memt;
|
||||
|
||||
bus_space_map(rtc_tag, DREAMCAST_RTC, 12, 0, &rtc_handle);
|
||||
}
|
||||
|
||||
void
|
||||
dreamcast_rtc_get(void *cookie, time_t base, struct clock_ymdhms *dt)
|
||||
{
|
||||
|
||||
clock_secs_to_ymdhms(dreamcast_read_rtc(), dt);
|
||||
}
|
||||
|
||||
void
|
||||
dreamcast_rtc_set(void *cookie, struct clock_ymdhms *dt)
|
||||
{
|
||||
|
||||
dreamcast_write_rtc(clock_ymdhms_to_secs(dt));
|
||||
}
|
||||
|
||||
uint32_t
|
||||
dreamcast_read_rtc(void)
|
||||
{
|
||||
uint32_t new, old;
|
||||
int i;
|
||||
|
||||
for (old = 0;;) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
new = ((bus_space_read_4(rtc_tag, rtc_handle, 0)
|
||||
& 0xffff) << 16)
|
||||
| (bus_space_read_4(rtc_tag, rtc_handle, 4)
|
||||
& 0xffff);
|
||||
if (new != old)
|
||||
break;
|
||||
}
|
||||
if (i < 3)
|
||||
old = new;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
/* offset 20 years */
|
||||
return new - 631152000;
|
||||
}
|
||||
|
||||
void
|
||||
dreamcast_write_rtc(uint32_t secs)
|
||||
{
|
||||
uint32_t new;
|
||||
int i, retry;
|
||||
|
||||
/* offset 20 years */
|
||||
secs += 631152000;
|
||||
|
||||
for (retry = 0; retry < 5; retry++) {
|
||||
|
||||
/* Don't change an order */
|
||||
bus_space_write_4(rtc_tag, rtc_handle, 8, 1);
|
||||
bus_space_write_4(rtc_tag, rtc_handle, 4, secs & 0xffff);
|
||||
bus_space_write_4(rtc_tag, rtc_handle, 0, secs >> 16);
|
||||
|
||||
/* verify */
|
||||
for (i = 0; i < 3; i++) {
|
||||
new = ((bus_space_read_4(rtc_tag, rtc_handle, 0)
|
||||
& 0xffff) << 16)
|
||||
| (bus_space_read_4(rtc_tag, rtc_handle, 4)
|
||||
& 0xffff);
|
||||
if (new == secs)
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* set failure. but nothing to do */
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
/* $NetBSD: types.h,v 1.2 2002/02/28 03:17:26 simonb Exp $ */
|
||||
/* $NetBSD: types.h,v 1.3 2006/09/05 11:09:36 uwe Exp $ */
|
||||
#ifndef _DREAMCAST_TYPES_H_
|
||||
#define _DREAMCAST_TYPES_H_
|
||||
|
||||
#include <sh3/types.h>
|
||||
|
||||
#define __HAVE_GENERIC_TODR
|
||||
|
||||
#endif /* _DREAMCAST_TYPES_H_ */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: clock.c,v 1.31 2006/03/04 01:13:35 uwe Exp $ */
|
||||
/* $NetBSD: clock.c,v 1.32 2006/09/05 11:09:36 uwe Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.31 2006/03/04 01:13:35 uwe Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.32 2006/09/05 11:09:36 uwe Exp $");
|
||||
|
||||
#include "opt_pclock.h"
|
||||
#include "opt_hz.h"
|
||||
@ -297,6 +297,9 @@ cpu_initclocks()
|
||||
sh_clock.rtc.init(sh_clock.rtc._cookie);
|
||||
}
|
||||
|
||||
|
||||
#if !defined(__HAVE_GENERIC_TODR)
|
||||
|
||||
void
|
||||
inittodr(time_t base)
|
||||
{
|
||||
@ -366,6 +369,9 @@ resettodr()
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* __HAVE_GENERIC_TODR */
|
||||
|
||||
|
||||
#ifdef SH3
|
||||
int
|
||||
sh3_clock_intr(void *arg) /* trap frame */
|
||||
|
Loading…
Reference in New Issue
Block a user