mcclock_mainbus.c revision 1.4
1/*	$NetBSD: mcclock_mainbus.c,v 1.4 2002/10/02 02:26:42 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.4 2002/10/02 02:26:42 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
47struct 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
54int	mcclock_mainbus_match(struct device *, struct cfdata *, void *);
55void	mcclock_mainbus_attach(struct device *, struct device *, void *);
56
57CFATTACH_DECL(mcclock_mainbus, sizeof(struct mcclock_mainbus_softc),
58	mcclock_mainbus_match, mcclock_mainbus_attach, NULL, NULL);
59};
60
61void	mcclock_mainbus_write(struct mcclock_softc *, u_int, u_int);
62u_int	mcclock_mainbus_read(struct mcclock_softc *, u_int);
63
64const struct mcclock_busfns mcclock_mainbus_busfns = {
65	mcclock_mainbus_write, mcclock_mainbus_read,
66};
67
68int
69mcclock_mainbus_match(struct device *parent, struct cfdata *match, void *aux)
70{
71	struct mainbus_attach_args *ma = aux;
72
73	if (strcmp(ma->ma_name, match->cf_name) == 0)
74		return (1);
75
76	return (0);
77}
78
79void
80mcclock_mainbus_attach(struct device *parent, struct device *self, void *aux)
81{
82	struct mainbus_attach_args *ma = aux;
83	struct mcclock_mainbus_softc *sc = (void *)self;
84
85	sc->sc_iot = ma->ma_st;
86	if (bus_space_map(sc->sc_iot, ma->ma_addr, 2, 0, &sc->sc_ioh))
87		panic("mcclock_mainbus_attach: couldn't map clock I/O space");
88
89	mcclock_attach(&sc->sc_mcclock, &mcclock_mainbus_busfns);
90}
91
92void
93mcclock_mainbus_write(struct mcclock_softc *mcsc, u_int reg, u_int datum)
94{
95	struct mcclock_mainbus_softc *sc = (void *)mcsc;
96	bus_space_tag_t iot = sc->sc_iot;
97	bus_space_handle_t ioh = sc->sc_ioh;
98
99	bus_space_write_1(iot, ioh, 0, reg);
100	bus_space_write_1(iot, ioh, 1, datum);
101}
102
103u_int
104mcclock_mainbus_read(struct mcclock_softc *mcsc, u_int reg)
105{
106	struct mcclock_mainbus_softc *sc = (void *)mcsc;
107	bus_space_tag_t iot = sc->sc_iot;
108	bus_space_handle_t ioh = sc->sc_ioh;
109
110	bus_space_write_1(iot, ioh, 0, reg);
111	return bus_space_read_1(iot, ioh, 1);
112}
113