diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2008-04-07 22:36:27 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2008-04-07 22:36:27 +0000 |
commit | 3b155998b905d3951937b9aa72b3f53c5f07d8e0 (patch) | |
tree | 061ae6fc56aedda76be31d0b725648489a9da07c /sys | |
parent | af4c22c8744ba408af707eee2bc811951090c4cc (diff) |
Split clock attachment in two parts: a timecounter attachment (at mainbus),
and a time-of-day chip (wherever it gets found).
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/mips64/dev/clockvar.h | 40 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/clock.c | 120 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/mainbus.c | 4 | ||||
-rw-r--r-- | sys/arch/sgi/conf/GENERIC | 5 | ||||
-rw-r--r-- | sys/arch/sgi/conf/RAMDISK | 5 | ||||
-rw-r--r-- | sys/arch/sgi/conf/files.sgi | 54 | ||||
-rw-r--r-- | sys/arch/sgi/dev/dsrtc.c | 252 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/clock_md.c | 170 |
8 files changed, 353 insertions, 297 deletions
diff --git a/sys/arch/mips64/dev/clockvar.h b/sys/arch/mips64/dev/clockvar.h index b892fea6181..dcfc0be64c0 100644 --- a/sys/arch/mips64/dev/clockvar.h +++ b/sys/arch/mips64/dev/clockvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: clockvar.h,v 1.4 2007/12/18 08:07:53 jsing Exp $ */ +/* $OpenBSD: clockvar.h,v 1.5 2008/04/07 22:36:24 miod Exp $ */ /* * Copyright (c) 1994, 1995 Carnegie-Mellon University. @@ -29,13 +29,13 @@ */ /* - * Definitions for "cpu-independent" clock handling for the mips arc arch. + * Definitions for "cpu-independent" clock handling. */ /* - * clocktime structure: + * tod_time structure: * - * structure passed to TOY clocks when setting them. broken out this + * structure passed to TOD clocks when setting them. broken out this * way, so that the time_t -> field conversion can be shared. */ struct tod_time { @@ -49,32 +49,16 @@ struct tod_time { }; /* - * clockdesc structure: + * tod_desc structure: * - * provides clock-specific functions to do necessary operations. + * provides tod-specific functions to do necessary operations. */ -struct clock_softc; -struct clock_desc { - void (*clk_attach)(struct device *, struct device *, void *); - void (*clk_init)(struct clock_softc *); - void (*clk_get)(struct clock_softc *, time_t, struct tod_time *); - void (*clk_set)(struct clock_softc *, struct tod_time *); - int clk_hz; - int clk_stathz; - int clk_profhz; +struct tod_desc { + void *tod_cookie; + void (*tod_get)(void *, time_t, struct tod_time *); + void (*tod_set)(void *, struct tod_time *); + int tod_valid; }; -struct clock_softc { - struct device sc_dev; - struct clock_desc sc_clock; - int sc_initted; - bus_space_tag_t sc_clk_t; - bus_space_handle_t sc_clk_h; - void *ih; -}; - -/* XXX Handle to clock address space. */ -bus_space_handle_t clock_h; - -void md_clk_attach(struct device *, struct device *, void *); +extern struct tod_desc sys_tod; diff --git a/sys/arch/mips64/mips64/clock.c b/sys/arch/mips64/mips64/clock.c index d74a86852a2..9873d17b70a 100644 --- a/sys/arch/mips64/mips64/clock.c +++ b/sys/arch/mips64/mips64/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.19 2008/02/20 18:46:18 miod Exp $ */ +/* $OpenBSD: clock.c,v 1.20 2008/04/07 22:36:26 miod Exp $ */ /* * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -41,21 +41,20 @@ static struct evcount clk_count; static int clk_irq = 5; -/* Definition of the driver for autoconfig. */ int clockmatch(struct device *, void *, void *); void clockattach(struct device *, struct device *, void *); -intrmask_t clock_int5_dummy(intrmask_t, struct trap_frame *); -intrmask_t clock_int5(intrmask_t, struct trap_frame *); -void clock_int5_init(struct clock_softc *); struct cfdriver clock_cd = { NULL, "clock", DV_DULL }; struct cfattach clock_ca = { - sizeof(struct clock_softc), clockmatch, clockattach + sizeof(struct device), clockmatch, clockattach }; +intrmask_t clock_int5(intrmask_t, struct trap_frame *); +void clock_int5_init(void); + int clock_started = 0; u_int32_t cpu_counter_last; u_int32_t cpu_counter_interval; @@ -80,50 +79,21 @@ struct timecounter cp0_timecounter = { (((year) + 1900) % 400) == 0)) ? 366 : 365) int -clockmatch(struct device *parent, void *cfdata, void *aux) +clockmatch(struct device *parent, void *vcf, void *aux) { - struct confargs *ca = aux; - struct cfdata *cf = cfdata; + struct confargs *ca = aux; - /* Make sure that we're looking for a clock. */ - if (strcmp(ca->ca_name, clock_cd.cd_name) != 0) - return (0); - - if (cf->cf_unit > 0) + if (strcmp(ca->ca_name, clock_cd.cd_name) != 0) return 0; + return 10; /* Try to get clock early */ } void clockattach(struct device *parent, struct device *self, void *aux) { - struct clock_softc *sc; - - md_clk_attach(parent, self, aux); - sc = (struct clock_softc *)self; - - switch (sys_config.system_type) { -#if 0 - case ALGOR_P4032: - case ALGOR_P5064: - case MOMENTUM_CP7000: - case MOMENTUM_CP7000G: - case MOMENTUM_JAGUAR: - case GALILEO_EV64240: -#endif - case SGI_INDY: - case SGI_O2: - case SGI_O200: - case SGI_OCTANE: - printf(" ticker on int5 using count register"); - set_intr(INTPRI_CLOCK, CR_INT_5, clock_int5); - break; - - default: - panic("system clock handling code is missing"); - } - - printf("\n"); + printf(": ticker on int5 using count register\n"); + set_intr(INTPRI_CLOCK, CR_INT_5, clock_int5); } /* @@ -135,10 +105,16 @@ clockattach(struct device *parent, struct device *self, void *aux) * The code is enabled by setting 'cpu_counter_interval'. */ void -clock_int5_init(struct clock_softc *sc) +clock_int5_init() { int s; + hz = 100; + profhz = 100; + stathz = 0; /* XXX no stat clock yet */ + + evcount_attach(&clk_count, "clock", (void *)&clk_irq, &evcount_intr); + s = splclock(); cpu_counter_interval = sys_config.cpu[0].clock / (hz * 2); cpu_counter_last = cp0_get_count() + cpu_counter_interval * 4; @@ -147,17 +123,6 @@ clock_int5_init(struct clock_softc *sc) } /* - * Dummy count register interrupt handler used on some targets. - * Just resets the compare register and acknowledge the interrupt. - */ -intrmask_t -clock_int5_dummy(intrmask_t mask, struct trap_frame *tf) -{ - cp0_set_compare(0); /* Shut up counter int's for a while */ - return CR_INT_5; /* Clock is always on 5 */ -} - -/* * Interrupt handler for targets using the internal count register * as interval clock. Normally the system is run with the clock * interrupt always enabled. Masking is done here and if the clock @@ -245,6 +210,8 @@ nanodelay(int n) * Mips machine independent clock routines. */ +struct tod_desc sys_tod; + /* * Start the real-time and statistics clocks. Leave stathz 0 since there * are no other timers available. @@ -252,38 +219,31 @@ nanodelay(int n) void cpu_initclocks() { - struct clock_softc *sc = (struct clock_softc *)clock_cd.cd_devs[0]; + struct tod_desc *cd = &sys_tod; struct tod_time ct; u_int first_cp0, second_cp0, cycles_per_sec; int first_sec; - hz = sc->sc_clock.clk_hz; - stathz = sc->sc_clock.clk_stathz; - profhz = sc->sc_clock.clk_profhz; - - evcount_attach(&clk_count, "clock", (void *)&clk_irq, &evcount_intr); - - /* Start the clock. */ - if (sc->sc_clock.clk_init != NULL) - (*sc->sc_clock.clk_init)(sc); + /* Start the clock. */ + clock_int5_init(); /* * Calibrate the cycle counter frequency. */ - if (sc->sc_clock.clk_get != NULL) { - (*sc->sc_clock.clk_get)(sc, 0, &ct); + if (cd->tod_get != NULL) { + (*cd->tod_get)(cd->tod_cookie, 0, &ct); first_sec = ct.sec; /* Let the clock tick one second. */ do { first_cp0 = cp0_get_count(); - (*sc->sc_clock.clk_get)(sc, 0, &ct); + (*cd->tod_get)(cd->tod_cookie, 0, &ct); } while (ct.sec == first_sec); first_sec = ct.sec; /* Let the clock tick one more second. */ do { second_cp0 = cp0_get_count(); - (*sc->sc_clock.clk_get)(sc, 0, &ct); + (*cd->tod_get)(cd->tod_cookie, 0, &ct); } while (ct.sec == first_sec); cycles_per_sec = second_cp0 - first_cp0; @@ -326,15 +286,15 @@ inittodr(time_t base) { struct timespec ts; struct tod_time c; - struct clock_softc *sc = (struct clock_softc *)clock_cd.cd_devs[0]; + struct tod_desc *cd = &sys_tod; int days, yr; ts.tv_nsec = 0; - if (base < 15*SECYR) { + if (base < 35 * SECYR) { printf("WARNING: preposterous time in file system"); /* read the system clock anyway */ - base = 17*SECYR + 186*SECDAY + SECDAY/2; + base = 38 * SECYR; /* 2008 */ } /* @@ -342,8 +302,8 @@ inittodr(time_t base) * for sanity checking clock. Dates after 19991231 should be * returned as year >= 100. */ - if (sc->sc_clock.clk_get) { - (*sc->sc_clock.clk_get)(sc, base, &c); + if (cd->tod_get) { + (*cd->tod_get)(cd->tod_cookie, base, &c); } else { printf("WARNING: No TOD clock, believing file system.\n"); goto bad; @@ -362,7 +322,7 @@ inittodr(time_t base) /* now have days since Jan 1, 1970; the rest is easy... */ ts.tv_sec = days * SECDAY + c.hour * 3600 + c.min * 60 + c.sec; tc_setclock(&ts); - sc->sc_initted = 1; + cd->tod_valid = 1; /* * See if we gained/lost time. @@ -379,7 +339,7 @@ inittodr(time_t base) bad: ts.tv_sec = base; tc_setclock(&ts); - sc->sc_initted = 1; + cd->tod_valid = 1; printf("WARNING: CHECK AND RESET THE DATE!\n"); } @@ -391,15 +351,14 @@ void resettodr() { struct tod_time c; - struct clock_softc *sc = (struct clock_softc *)clock_cd.cd_devs[0]; + struct tod_desc *cd = &sys_tod; register int t, t2; /* - * Don't reset clock if time has not been set! + * Don't reset TOD if time has not been set! */ - if (!sc->sc_initted) { + if (!cd->tod_valid) return; - } /* compute the day of week. 1 is Sunday*/ t2 = time_second / SECDAY; @@ -432,9 +391,8 @@ resettodr() c.min = t / 60; c.sec = t % 60; - if (sc->sc_clock.clk_set) { - (*sc->sc_clock.clk_set)(sc, &c); - } + if (cd->tod_set) + (*cd->tod_set)(cd->tod_cookie, &c); } u_int diff --git a/sys/arch/mips64/mips64/mainbus.c b/sys/arch/mips64/mips64/mainbus.c index 40776b1cfa4..2966533e719 100644 --- a/sys/arch/mips64/mips64/mainbus.c +++ b/sys/arch/mips64/mips64/mainbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mainbus.c,v 1.5 2008/02/20 18:46:18 miod Exp $ */ +/* $OpenBSD: mainbus.c,v 1.6 2008/04/07 22:36:26 miod Exp $ */ /* * Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -72,6 +72,8 @@ mbattach(struct device *parent, struct device *self, void *aux) bzero(&nca, sizeof nca); nca.ca_name = "cpu"; config_found(self, &nca, mbprint); + nca.ca_name = "clock"; + config_found(self, &nca, mbprint); switch (sys_config.system_type) { #ifdef TGT_O2 diff --git a/sys/arch/sgi/conf/GENERIC b/sys/arch/sgi/conf/GENERIC index e296c984d14..c1ffa9f7361 100644 --- a/sys/arch/sgi/conf/GENERIC +++ b/sys/arch/sgi/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.28 2008/02/20 18:46:20 miod Exp $ +# $OpenBSD: GENERIC,v 1.29 2008/04/07 22:36:26 miod Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -39,6 +39,7 @@ config bsd swap generic # mainbus0 at root cpu* at mainbus0 +clock0 at mainbus0 #### Main local buses macebus0 at mainbus0 # MACE controller localbus. @@ -47,12 +48,12 @@ macebus0 at mainbus0 # MACE controller localbus. gbe0 at mainbus0 # Localbus devices -clock0 at macebus0 mec0 at macebus0 base 0x00280000 irq 4 mavb0 at macebus0 base 0x00300000 irq 7 mkbc0 at macebus0 base 0x00320000 irq 6 com0 at macebus0 base 0x00390000 irq 5 com1 at macebus0 base 0x00398000 irq 5 +dsrtc0 at macebus0 power0 at macebus0 irq 6 #### PCI Bus diff --git a/sys/arch/sgi/conf/RAMDISK b/sys/arch/sgi/conf/RAMDISK index e432ceb51e2..19d44e9346a 100644 --- a/sys/arch/sgi/conf/RAMDISK +++ b/sys/arch/sgi/conf/RAMDISK @@ -1,4 +1,4 @@ -# $OpenBSD: RAMDISK,v 1.17 2008/02/20 18:46:20 miod Exp $ +# $OpenBSD: RAMDISK,v 1.18 2008/04/07 22:36:26 miod Exp $ # machine sgi mips64 @@ -43,6 +43,7 @@ config bsd root on rd0a swap on rd0b # mainbus0 at root cpu* at mainbus0 +clock0 at mainbus0 #### Main local buses macebus0 at mainbus0 # MACE controller localbus. @@ -51,11 +52,11 @@ macebus0 at mainbus0 # MACE controller localbus. gbe0 at mainbus0 #### Localbus devices -clock0 at macebus0 mec0 at macebus0 base 0x00280000 irq 4 mkbc0 at macebus0 base 0x00320000 irq 6 com0 at macebus0 base 0x00390000 irq 5 com1 at macebus0 base 0x00398000 irq 5 +dsrtc0 at mainbus0 #### PCI Bus macepcibr0 at macebus0 # MACE controller PCI Bus bridge. diff --git a/sys/arch/sgi/conf/files.sgi b/sys/arch/sgi/conf/files.sgi index ef8b5f3dd1f..32b91e8b92c 100644 --- a/sys/arch/sgi/conf/files.sgi +++ b/sys/arch/sgi/conf/files.sgi @@ -1,4 +1,4 @@ -# $OpenBSD: files.sgi,v 1.21 2008/04/07 22:32:44 miod Exp $ +# $OpenBSD: files.sgi,v 1.22 2008/04/07 22:36:26 miod Exp $ # # maxpartitions must be first item in files.${ARCH} # @@ -43,6 +43,10 @@ attach mainbus at root device cpu attach cpu at mainbus +# Clock device +device clock +attach clock at mainbus + # # O2 MACE localbus autoconfiguration devices # @@ -55,10 +59,14 @@ file arch/sgi/localbus/macectrl.S macebus # # Origin200/Origin2000 XBOW mux bridge # -define xbowmux {[sys = - 1], [base = -1], [irq = -1]} -device xbowmux -attach xbowmux at mainbus -file arch/sgi/localbus/xbowmux.c xbowmux +define xbow {[vendor = -1], [product = -1]} +device xbow +attach xbow at mainbus +file arch/sgi/xbow/xbow.c xbow + +include "dev/onewire/files.onewire" + +include "arch/sgi/xbow/files.xbow" # # PCI Bus bridges @@ -68,10 +76,6 @@ attach macepcibr at macebus file arch/sgi/pci/macepcibridge.c macepcibr needs-flag file arch/sgi/pci/macepcimap.c macepcibr -device xiopcibr {} : pcibus -attach xiopcibr at xbowmux -file arch/sgi/pci/xiopcibridge.c xiopcibr needs-flag - # Use machine independent SCSI driver routines include "scsi/files.scsi" major {sd = 0} @@ -81,10 +85,21 @@ include "dev/i2o/files.i2o" include "dev/pci/files.pci" -# Clock device -device clock -attach clock at macebus -file arch/sgi/sgi/clock_md.c clock +# IOC3 +define ioc {[base = -1], [irq = -1]} +device ioc: onewirebus +attach ioc at pci +file arch/sgi/pci/ioc.c ioc + +# IOC3 serial ports +attach com at ioc with com_ioc +file arch/sgi/dev/com_ioc.c com_ioc + +# DS1687 Time-Of-Day calendar device +device dsrtc +attach dsrtc at macebus with dsrtc_macebus +attach dsrtc at ioc with dsrtc_ioc +file arch/sgi/dev/dsrtc.c dsrtc # GBE framebuffer device gbe: wsemuldisplaydev, rasops8, rasops16, rasops32 @@ -135,6 +150,19 @@ include "dev/wscons/files.wscons" include "dev/usb/files.usb" # +# Number-In-a-Can containers +# +# Ethernet address +device owmac +attach owmac at onewire +file arch/sgi/dev/owmac.c owmac +# Serial numbers +device owserial +attach owserial at onewire +file arch/sgi/dev/owserial.c owserial +file arch/sgi/dev/owmem_subr.c owmac | owserial + +# # Specials. # # RAM disk for boot diff --git a/sys/arch/sgi/dev/dsrtc.c b/sys/arch/sgi/dev/dsrtc.c new file mode 100644 index 00000000000..a739a04c3b9 --- /dev/null +++ b/sys/arch/sgi/dev/dsrtc.c @@ -0,0 +1,252 @@ +/* $OpenBSD: dsrtc.c,v 1.1 2008/04/07 22:36:26 miod Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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/param.h> +#include <sys/kernel.h> +#include <sys/systm.h> +#include <sys/device.h> + +#include <dev/ic/ds1687reg.h> + +#include <machine/autoconf.h> +#include <machine/bus.h> + +#include <mips64/archtype.h> +#include <mips64/dev/clockvar.h> + +#include <sgi/localbus/macebus.h> +#include <sgi/pci/iocreg.h> +#include <sgi/pci/iocvar.h> + +bus_space_handle_t clock_h; /* XXX */ + +struct dsrtc_softc { + struct device sc_dev; + bus_space_tag_t sc_clkt; + bus_space_handle_t sc_clkh, sc_clkh2; + + int (*read)(struct dsrtc_softc *, int); + void (*write)(struct dsrtc_softc *, int, int); +}; + +int dsrtc_match_ioc(struct device *, void *, void *); +void dsrtc_attach_ioc(struct device *, struct device *, void *); +int dsrtc_match_macebus(struct device *, void *, void *); +void dsrtc_attach_macebus(struct device *, struct device *, void *); + +struct cfdriver dsrtc_cd = { + NULL, "dsrtc", DV_DULL +}; + +struct cfattach dsrtc_macebus_ca = { + sizeof(struct dsrtc_softc), dsrtc_match_macebus, dsrtc_attach_macebus +}; + +struct cfattach dsrtc_ioc_ca = { + sizeof(struct dsrtc_softc), dsrtc_match_ioc, dsrtc_attach_ioc +}; + +int ip32_dsrtc_read(struct dsrtc_softc *, int); +void ip32_dsrtc_write(struct dsrtc_softc *, int, int); +int ip30_dsrtc_read(struct dsrtc_softc *, int); +void ip30_dsrtc_write(struct dsrtc_softc *, int, int); + +void ds1687_get(void *, time_t, struct tod_time *); +void ds1687_set(void *, struct tod_time *); + +static inline int frombcd(int); +static inline int tobcd(int); +static inline int +frombcd(int x) +{ + return (x >> 4) * 10 + (x & 0xf); +} +static inline int +tobcd(int x) +{ + return (x / 10 * 16) + (x % 10); +} + +int +dsrtc_match_ioc(struct device *parent, void *match, void *aux) +{ + if (sys_config.system_type != SGI_OCTANE) + return 0; + + return 1; +} + +void +dsrtc_attach_ioc(struct device *parent, struct device *self, void *aux) +{ + struct dsrtc_softc *sc = (void *)self; + struct ioc_attach_args *iaa = aux; + + sc->sc_clkt = iaa->iaa_memt; + if (bus_space_map(sc->sc_clkt, IOC3_BYTEBUS_1, 1, 0, &sc->sc_clkh) || + bus_space_map(sc->sc_clkt, IOC3_BYTEBUS_2, 1, 0, &sc->sc_clkh2)) { + printf(": can't map registers\n"); + return; + } + + printf(": DS1687\n"); + + sc->read = ip30_dsrtc_read; + sc->write = ip30_dsrtc_write; + + sys_tod.tod_cookie = self; + sys_tod.tod_get = ds1687_get; + sys_tod.tod_set = ds1687_set; +} + +int +dsrtc_match_macebus(struct device *parent, void *match, void *aux) +{ + return 1; +} + +void +dsrtc_attach_macebus(struct device *parent, struct device *self, void *aux) +{ + struct dsrtc_softc *sc = (void *)self; + struct confargs *ca = aux; + + sc->sc_clkt = ca->ca_iot; + if (bus_space_map(sc->sc_clkt, MACE_ISA_RTC_OFFS, 128*256, 0, + &sc->sc_clkh)) { + printf(": can't map registers\n"); + return; + } + + printf(": DS1687\n"); + + sc->read = ip32_dsrtc_read; + sc->write = ip32_dsrtc_write; + + sys_tod.tod_cookie = self; + sys_tod.tod_get = ds1687_get; + sys_tod.tod_set = ds1687_set; + + /* + * XXX Expose the clock address space so that it can be used + * outside of clock(4). This is rather inelegant, however it + * will have to do for now... + */ + clock_h = sc->sc_clkh; +} + +int +ip32_dsrtc_read(struct dsrtc_softc *sc, int reg) +{ + return bus_space_read_1(sc->sc_clkt, sc->sc_clkh, reg); +} + +void +ip32_dsrtc_write(struct dsrtc_softc *sc, int reg, int val) +{ + bus_space_write_1(sc->sc_clkt, sc->sc_clkh, reg, val); +} + +int +ip30_dsrtc_read(struct dsrtc_softc *sc, int reg) +{ + bus_space_write_1(sc->sc_clkt, sc->sc_clkh, 0, reg); + return bus_space_read_1(sc->sc_clkt, sc->sc_clkh2, 0); +} + +void +ip30_dsrtc_write(struct dsrtc_softc *sc, int reg, int val) +{ + bus_space_write_1(sc->sc_clkt, sc->sc_clkh, 0, reg); + bus_space_write_1(sc->sc_clkt, sc->sc_clkh2, 0, val); +} + +/* + * Dallas clock driver. + */ +void +ds1687_get(void *v, time_t base, struct tod_time *ct) +{ + struct dsrtc_softc *sc = v; + int ctrl, century; + + /* Select bank 1. */ + ctrl = (*sc->read)(sc, DS1687_CTRL_A); + (*sc->write)(sc, DS1687_CTRL_A, ctrl | DS1687_BANK_1); + + /* Wait for no update in progress. */ + while ((*sc->read)(sc, DS1687_CTRL_A) & DS1687_UIP) + /* Do nothing. */; + + /* Read the RTC. */ + ct->sec = frombcd((*sc->read)(sc, DS1687_SEC)); + ct->min = frombcd((*sc->read)(sc, DS1687_MIN)); + ct->hour = frombcd((*sc->read)(sc, DS1687_HOUR)); + ct->day = frombcd((*sc->read)(sc, DS1687_DAY)); + ct->mon = frombcd((*sc->read)(sc, DS1687_MONTH)); + ct->year = frombcd((*sc->read)(sc, DS1687_YEAR)); + century = frombcd((*sc->read)(sc, DS1687_CENTURY)); + + ct->year += 100 * (century - 19); +} + +void +ds1687_set(void *v, struct tod_time *ct) +{ + struct dsrtc_softc *sc = v; + int year, century, ctrl; + + century = ct->year / 100 + 19; + year = ct->year % 100; + + /* Select bank 1. */ + ctrl = (*sc->read)(sc, DS1687_CTRL_A); + (*sc->write)(sc, DS1687_CTRL_A, ctrl | DS1687_BANK_1); + + /* Select data mode 0 (BCD) and 24 hour time. */ + ctrl = (*sc->read)(sc, DS1687_CTRL_B); + (*sc->write)(sc, DS1687_CTRL_B, + (ctrl & ~DS1687_DM_1) | DS1687_24_HR); + + /* Prevent updates. */ + ctrl = (*sc->read)(sc, DS1687_CTRL_B); + (*sc->write)(sc, DS1687_CTRL_B, ctrl | DS1687_SET_CLOCK); + + /* Update the RTC. */ + (*sc->write)(sc, DS1687_SEC, tobcd(ct->sec)); + (*sc->write)(sc, DS1687_MIN, tobcd(ct->min)); + (*sc->write)(sc, DS1687_HOUR, tobcd(ct->hour)); + (*sc->write)(sc, DS1687_DOW, tobcd(ct->dow)); + (*sc->write)(sc, DS1687_DAY, tobcd(ct->day)); + (*sc->write)(sc, DS1687_MONTH, tobcd(ct->mon)); + (*sc->write)(sc, DS1687_YEAR, tobcd(year)); + (*sc->write)(sc, DS1687_CENTURY, tobcd(century)); + + /* Enable updates. */ + (*sc->write)(sc, DS1687_CTRL_B, ctrl); +} diff --git a/sys/arch/sgi/sgi/clock_md.c b/sys/arch/sgi/sgi/clock_md.c deleted file mode 100644 index 95b6626f4e9..00000000000 --- a/sys/arch/sgi/sgi/clock_md.c +++ /dev/null @@ -1,170 +0,0 @@ -/* $OpenBSD: clock_md.c,v 1.12 2008/03/27 14:36:11 jsing Exp $ */ - -/* - * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) - * - * 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/param.h> -#include <sys/kernel.h> -#include <sys/systm.h> -#include <sys/device.h> - -#include <dev/ic/ds1687reg.h> - -#include <machine/autoconf.h> -#include <machine/bus.h> - -#include <mips64/archtype.h> -#include <mips64/dev/clockvar.h> - -#include <sgi/localbus/macebus.h> - -extern int clockmatch(struct device *, void *, void *); -extern void clockattach(struct device *, struct device *, void *); -extern void clock_int5_init(struct clock_softc *); -extern int clock_started; - -#define FROMBCD(x) (((x) >> 4) * 10 + ((x) & 0xf)) -#define TOBCD(x) (((x) / 10 * 16) + ((x) % 10)) - -void ds1687_get(struct clock_softc *, time_t, struct tod_time *); -void ds1687_set(struct clock_softc *, struct tod_time *); - -void -md_clk_attach(struct device *parent, struct device *self, void *aux) -{ - struct clock_softc *sc = (struct clock_softc *)self; - struct confargs *ca = aux; - - switch (sys_config.system_type) { - case SGI_O2: - sc->sc_clock.clk_get = ds1687_get; - sc->sc_clock.clk_set = ds1687_set; - sc->sc_clock.clk_init = clock_int5_init; - sc->sc_clock.clk_hz = 100; - sc->sc_clock.clk_profhz = 100; - sc->sc_clock.clk_stathz = 0; /* XXX no stat clock yet */ - sc->sc_clk_t = ca->ca_iot; - if (bus_space_map(sc->sc_clk_t, MACE_ISA_RTC_OFFS, 128*256, 0, - &sc->sc_clk_h)) - printf("UH!? Can't map clock device!\n"); - printf(": TOD with DS1687,"); - - /* - * XXX Expose the clock address space so that it can be used - * outside of clock(4). This is rather inelegant, however it - * will have to do for now... - */ - clock_h = sc->sc_clk_h; - - break; - - case SGI_O200: - sc->sc_clock.clk_init = clock_int5_init; - sc->sc_clock.clk_hz = 100; - sc->sc_clock.clk_profhz = 100; - sc->sc_clock.clk_stathz = 0; /* XXX no stat clock yet */ - /* XXX MK48T35 */ - break; - - case SGI_OCTANE: - sc->sc_clock.clk_init = clock_int5_init; - sc->sc_clock.clk_hz = 100; - sc->sc_clock.clk_profhz = 100; - sc->sc_clock.clk_stathz = 0; /* XXX no stat clock yet */ - /* XXX DS1687 */ - break; - - default: - panic("don't know how to set up clock."); - } -} - -/* - * Dallas clock driver. - */ -void -ds1687_get(struct clock_softc *sc, time_t base, struct tod_time *ct) -{ - bus_space_tag_t clk_t = sc->sc_clk_t; - bus_space_handle_t clk_h = sc->sc_clk_h; - int ctrl, century; - - /* Select bank 1. */ - ctrl = bus_space_read_1(clk_t, clk_h, DS1687_CTRL_A); - bus_space_write_1(clk_t, clk_h, DS1687_CTRL_A, ctrl | DS1687_BANK_1); - - /* Wait for no update in progress. */ - while (bus_space_read_1(clk_t, clk_h, DS1687_CTRL_A) & DS1687_UIP) - /* Do nothing. */; - - /* Read the RTC. */ - ct->sec = FROMBCD(bus_space_read_1(clk_t, clk_h, DS1687_SEC)); - ct->min = FROMBCD(bus_space_read_1(clk_t, clk_h, DS1687_MIN)); - ct->hour = FROMBCD(bus_space_read_1(clk_t, clk_h, DS1687_HOUR)); - ct->day = FROMBCD(bus_space_read_1(clk_t, clk_h, DS1687_DAY)); - ct->mon = FROMBCD(bus_space_read_1(clk_t, clk_h, DS1687_MONTH)); - ct->year = FROMBCD(bus_space_read_1(clk_t, clk_h, DS1687_YEAR)); - century = FROMBCD(bus_space_read_1(clk_t, clk_h, DS1687_CENTURY)); - - ct->year += 100 * (century - 19); -} - -void -ds1687_set(struct clock_softc *sc, struct tod_time *ct) -{ - bus_space_tag_t clk_t = sc->sc_clk_t; - bus_space_handle_t clk_h = sc->sc_clk_h; - int year, century, ctrl; - - century = ct->year / 100 + 19; - year = ct->year % 100; - - /* Select bank 1. */ - ctrl = bus_space_read_1(clk_t, clk_h, DS1687_CTRL_A); - bus_space_write_1(clk_t, clk_h, DS1687_CTRL_A, ctrl | DS1687_BANK_1); - - /* Select data mode 0 (BCD) and 24 hour time. */ - ctrl = bus_space_read_1(clk_t, clk_h, DS1687_CTRL_B); - bus_space_write_1(clk_t, clk_h, DS1687_CTRL_B, - (ctrl & ~DS1687_DM_1) | DS1687_24_HR); - - /* Prevent updates. */ - ctrl = bus_space_read_1(clk_t, clk_h, DS1687_CTRL_B); - bus_space_write_1(clk_t, clk_h, DS1687_CTRL_B, ctrl | DS1687_SET_CLOCK); - - /* Update the RTC. */ - bus_space_write_1(clk_t, clk_h, DS1687_SEC, TOBCD(ct->sec)); - bus_space_write_1(clk_t, clk_h, DS1687_MIN, TOBCD(ct->min)); - bus_space_write_1(clk_t, clk_h, DS1687_HOUR, TOBCD(ct->hour)); - bus_space_write_1(clk_t, clk_h, DS1687_DOW, TOBCD(ct->dow)); - bus_space_write_1(clk_t, clk_h, DS1687_DAY, TOBCD(ct->day)); - bus_space_write_1(clk_t, clk_h, DS1687_MONTH, TOBCD(ct->mon)); - bus_space_write_1(clk_t, clk_h, DS1687_YEAR, TOBCD(year)); - bus_space_write_1(clk_t, clk_h, DS1687_CENTURY, TOBCD(century)); - - /* Enable updates. */ - bus_space_write_1(clk_t, clk_h, DS1687_CTRL_B, ctrl); -} |