mcclock_mainbus.c revision 1.2
11.2Sthorpej/*	$NetBSD: mcclock_mainbus.c,v 1.2 2002/09/27 02:24:07 thorpej Exp $	*/
21.1Sthorpej
31.1Sthorpej/*
41.1Sthorpej * Copyright (c) 1995, 1996 Carnegie-Mellon University.
51.1Sthorpej * All rights reserved.
61.1Sthorpej *
71.1Sthorpej * Author: Chris G. Demetriou
81.1Sthorpej *
91.1Sthorpej * Permission to use, copy, modify and distribute this software and
101.1Sthorpej * its documentation is hereby granted, provided that both the copyright
111.1Sthorpej * notice and this permission notice appear in all copies of the
121.1Sthorpej * software, derivative works or modified versions, and any portions
131.1Sthorpej * thereof, and that both notices appear in supporting documentation.
141.1Sthorpej *
151.1Sthorpej * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
161.1Sthorpej * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
171.1Sthorpej * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
181.1Sthorpej *
191.1Sthorpej * Carnegie Mellon requests users of this software to return to
201.1Sthorpej *
211.1Sthorpej *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
221.1Sthorpej *  School of Computer Science
231.1Sthorpej *  Carnegie Mellon University
241.1Sthorpej *  Pittsburgh PA 15213-3890
251.1Sthorpej *
261.1Sthorpej * any improvements or extensions that they make and grant Carnegie the
271.1Sthorpej * rights to redistribute these changes.
281.1Sthorpej */
291.1Sthorpej
301.1Sthorpej#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
311.1Sthorpej
321.2Sthorpej__KERNEL_RCSID(0, "$NetBSD: mcclock_mainbus.c,v 1.2 2002/09/27 02:24:07 thorpej Exp $");
331.1Sthorpej
341.1Sthorpej#include <sys/param.h>
351.1Sthorpej#include <sys/kernel.h>
361.1Sthorpej#include <sys/systm.h>
371.1Sthorpej#include <sys/device.h>
381.1Sthorpej
391.1Sthorpej#include <machine/autoconf.h>
401.1Sthorpej#include <machine/bus.h>
411.1Sthorpej
421.1Sthorpej#include <dev/ic/mc146818reg.h>
431.1Sthorpej
441.1Sthorpej#include <algor/algor/clockvar.h>
451.1Sthorpej#include <algor/dev/mcclockvar.h>
461.1Sthorpej
471.1Sthorpejstruct mcclock_mainbus_softc {
481.1Sthorpej	struct mcclock_softc	sc_mcclock;
491.1Sthorpej
501.1Sthorpej	bus_space_tag_t		sc_iot;
511.1Sthorpej	bus_space_handle_t	sc_ioh;
521.1Sthorpej};
531.1Sthorpej
541.1Sthorpejint	mcclock_mainbus_match(struct device *, struct cfdata *, void *);
551.1Sthorpejvoid	mcclock_mainbus_attach(struct device *, struct device *, void *);
561.1Sthorpej
571.1Sthorpejstruct cfattach mcclock_mainbus_ca = {
581.1Sthorpej	sizeof (struct mcclock_mainbus_softc), mcclock_mainbus_match,
591.1Sthorpej	    mcclock_mainbus_attach,
601.1Sthorpej};
611.1Sthorpej
621.1Sthorpejvoid	mcclock_mainbus_write(struct mcclock_softc *, u_int, u_int);
631.1Sthorpeju_int	mcclock_mainbus_read(struct mcclock_softc *, u_int);
641.1Sthorpej
651.1Sthorpejconst struct mcclock_busfns mcclock_mainbus_busfns = {
661.1Sthorpej	mcclock_mainbus_write, mcclock_mainbus_read,
671.1Sthorpej};
681.1Sthorpej
691.1Sthorpejint
701.1Sthorpejmcclock_mainbus_match(struct device *parent, struct cfdata *match, void *aux)
711.1Sthorpej{
721.1Sthorpej	struct mainbus_attach_args *ma = aux;
731.1Sthorpej
741.2Sthorpej	if (strcmp(ma->ma_name, match->cf_name) == 0)
751.1Sthorpej		return (1);
761.1Sthorpej
771.1Sthorpej	return (0);
781.1Sthorpej}
791.1Sthorpej
801.1Sthorpejvoid
811.1Sthorpejmcclock_mainbus_attach(struct device *parent, struct device *self, void *aux)
821.1Sthorpej{
831.1Sthorpej	struct mainbus_attach_args *ma = aux;
841.1Sthorpej	struct mcclock_mainbus_softc *sc = (void *)self;
851.1Sthorpej
861.1Sthorpej	sc->sc_iot = ma->ma_st;
871.1Sthorpej	if (bus_space_map(sc->sc_iot, ma->ma_addr, 2, 0, &sc->sc_ioh))
881.1Sthorpej		panic("mcclock_mainbus_attach: couldn't map clock I/O space");
891.1Sthorpej
901.1Sthorpej	mcclock_attach(&sc->sc_mcclock, &mcclock_mainbus_busfns);
911.1Sthorpej}
921.1Sthorpej
931.1Sthorpejvoid
941.1Sthorpejmcclock_mainbus_write(struct mcclock_softc *mcsc, u_int reg, u_int datum)
951.1Sthorpej{
961.1Sthorpej	struct mcclock_mainbus_softc *sc = (void *)mcsc;
971.1Sthorpej	bus_space_tag_t iot = sc->sc_iot;
981.1Sthorpej	bus_space_handle_t ioh = sc->sc_ioh;
991.1Sthorpej
1001.1Sthorpej	bus_space_write_1(iot, ioh, 0, reg);
1011.1Sthorpej	bus_space_write_1(iot, ioh, 1, datum);
1021.1Sthorpej}
1031.1Sthorpej
1041.1Sthorpeju_int
1051.1Sthorpejmcclock_mainbus_read(struct mcclock_softc *mcsc, u_int reg)
1061.1Sthorpej{
1071.1Sthorpej	struct mcclock_mainbus_softc *sc = (void *)mcsc;
1081.1Sthorpej	bus_space_tag_t iot = sc->sc_iot;
1091.1Sthorpej	bus_space_handle_t ioh = sc->sc_ioh;
1101.1Sthorpej
1111.1Sthorpej	bus_space_write_1(iot, ioh, 0, reg);
1121.1Sthorpej	return bus_space_read_1(iot, ioh, 1);
1131.1Sthorpej}
114