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