1 /* $NetBSD: mcclock_mainbus.c,v 1.1 2001/06/01 16:00:04 thorpej 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.1 2001/06/01 16:00:04 thorpej 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/ic/mc146818reg.h> 43 44 #include <algor/algor/clockvar.h> 45 #include <algor/dev/mcclockvar.h> 46 47 struct mcclock_mainbus_softc { 48 struct mcclock_softc sc_mcclock; 49 50 bus_space_tag_t sc_iot; 51 bus_space_handle_t sc_ioh; 52 }; 53 54 int mcclock_mainbus_match(struct device *, struct cfdata *, void *); 55 void mcclock_mainbus_attach(struct device *, struct device *, void *); 56 57 struct cfattach mcclock_mainbus_ca = { 58 sizeof (struct mcclock_mainbus_softc), mcclock_mainbus_match, 59 mcclock_mainbus_attach, 60 }; 61 62 void mcclock_mainbus_write(struct mcclock_softc *, u_int, u_int); 63 u_int mcclock_mainbus_read(struct mcclock_softc *, u_int); 64 65 const struct mcclock_busfns mcclock_mainbus_busfns = { 66 mcclock_mainbus_write, mcclock_mainbus_read, 67 }; 68 69 int 70 mcclock_mainbus_match(struct device *parent, struct cfdata *match, void *aux) 71 { 72 struct mainbus_attach_args *ma = aux; 73 74 if (strcmp(ma->ma_name, match->cf_driver->cd_name) == 0) 75 return (1); 76 77 return (0); 78 } 79 80 void 81 mcclock_mainbus_attach(struct device *parent, struct device *self, void *aux) 82 { 83 struct mainbus_attach_args *ma = aux; 84 struct mcclock_mainbus_softc *sc = (void *)self; 85 86 sc->sc_iot = ma->ma_st; 87 if (bus_space_map(sc->sc_iot, ma->ma_addr, 2, 0, &sc->sc_ioh)) 88 panic("mcclock_mainbus_attach: couldn't map clock I/O space"); 89 90 mcclock_attach(&sc->sc_mcclock, &mcclock_mainbus_busfns); 91 } 92 93 void 94 mcclock_mainbus_write(struct mcclock_softc *mcsc, u_int reg, u_int datum) 95 { 96 struct mcclock_mainbus_softc *sc = (void *)mcsc; 97 bus_space_tag_t iot = sc->sc_iot; 98 bus_space_handle_t ioh = sc->sc_ioh; 99 100 bus_space_write_1(iot, ioh, 0, reg); 101 bus_space_write_1(iot, ioh, 1, datum); 102 } 103 104 u_int 105 mcclock_mainbus_read(struct mcclock_softc *mcsc, u_int reg) 106 { 107 struct mcclock_mainbus_softc *sc = (void *)mcsc; 108 bus_space_tag_t iot = sc->sc_iot; 109 bus_space_handle_t ioh = sc->sc_ioh; 110 111 bus_space_write_1(iot, ioh, 0, reg); 112 return bus_space_read_1(iot, ioh, 1); 113 } 114