1 /* $NetBSD: mcclock_mainbus.c,v 1.10 2008/03/29 05:42:45 tsutsui Exp $ */ 2 3 /* 4 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 5 * All rights reserved. 6 * 7 * Author: Chris G. Demetriou 8 * 9 * Permission to use, copy, modify and distribute this software and 10 * its documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie the 27 * rights to redistribute these changes. 28 */ 29 30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 31 32 __KERNEL_RCSID(0, "$NetBSD: mcclock_mainbus.c,v 1.10 2008/03/29 05:42:45 tsutsui Exp $"); 33 34 #include <sys/param.h> 35 #include <sys/kernel.h> 36 #include <sys/systm.h> 37 #include <sys/device.h> 38 39 #include <machine/autoconf.h> 40 #include <machine/bus.h> 41 42 #include <dev/clock_subr.h> 43 #include <dev/ic/mc146818reg.h> 44 #include <dev/ic/mc146818var.h> 45 46 int mcclock_mainbus_match(device_t, cfdata_t, void *); 47 void mcclock_mainbus_attach(device_t, device_t, void *); 48 49 CFATTACH_DECL_NEW(mcclock_mainbus, sizeof(struct mc146818_softc), 50 mcclock_mainbus_match, mcclock_mainbus_attach, NULL, NULL); 51 52 void mcclock_mainbus_write(struct mc146818_softc *, u_int, u_int); 53 u_int mcclock_mainbus_read(struct mc146818_softc *, u_int); 54 55 int 56 mcclock_mainbus_match(device_t parent, cfdata_t cf, void *aux) 57 { 58 struct mainbus_attach_args *ma = aux; 59 60 if (strcmp(ma->ma_name, cf->cf_name) == 0) 61 return (1); 62 63 return (0); 64 } 65 66 void 67 mcclock_mainbus_attach(device_t parent, device_t self, void *aux) 68 { 69 struct mc146818_softc *sc = device_private(self); 70 struct mainbus_attach_args *ma = aux; 71 72 sc->sc_dev = self; 73 sc->sc_bst = ma->ma_st; 74 if (bus_space_map(sc->sc_bst, ma->ma_addr, 2, 0, &sc->sc_bsh)) 75 panic("mcclock_mainbus_attach: couldn't map clock I/O space"); 76 77 /* 78 * Turn interrupts off, just in case. Need to leave the SQWE 79 * set, because that's the DRAM refresh signal on Rev. B boards. 80 */ 81 mcclock_mainbus_write(sc, MC_REGB, MC_REGB_SQWE | MC_REGB_BINARY | 82 MC_REGB_24HR); 83 84 sc->sc_mcread = mcclock_mainbus_read; 85 sc->sc_mcwrite = mcclock_mainbus_write; 86 sc->sc_getcent = NULL; 87 sc->sc_setcent = NULL; 88 sc->sc_flag = 0; 89 90 /* Algor uses year 1980 as offset */ 91 sc->sc_year0 = 1980; 92 93 mc146818_attach(sc); 94 95 aprint_normal("\n"); 96 } 97 98 void 99 mcclock_mainbus_write(struct mc146818_softc *sc, u_int reg, u_int datum) 100 { 101 bus_space_tag_t iot = sc->sc_bst; 102 bus_space_handle_t ioh = sc->sc_bsh; 103 104 bus_space_write_1(iot, ioh, 0, reg); 105 bus_space_write_1(iot, ioh, 1, datum); 106 } 107 108 u_int 109 mcclock_mainbus_read(struct mc146818_softc *sc, u_int reg) 110 { 111 bus_space_tag_t iot = sc->sc_bst; 112 bus_space_handle_t ioh = sc->sc_bsh; 113 114 bus_space_write_1(iot, ioh, 0, reg); 115 return bus_space_read_1(iot, ioh, 1); 116 } 117