1 /* $NetBSD: mcclock.c,v 1.3 2008/03/28 19:05:49 tsutsui Exp $ */
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
7 * Author: Chris G. Demetriou
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.
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.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: mcclock.c,v 1.3 2008/03/28 19:05:49 tsutsui Exp $");
33 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
40 #include <machine/autoconf.h>
41 #include <machine/bus.h>
43 #include <dev/clock_subr.h>
44 #include <dev/ic/mc146818reg.h>
45 #include <dev/ic/mc146818var.h>
47 #define MCCLOCK_NPORTS 2
49 static int mcclock_match(device_t
, cfdata_t
, void *);
50 static void mcclock_attach(device_t
, device_t
, void *);
52 CFATTACH_DECL_NEW(mcclock
, sizeof (struct mc146818_softc
),
53 mcclock_match
, mcclock_attach
, NULL
, NULL
);
55 static void mcclock_write(struct mc146818_softc
*, u_int
, u_int
);
56 static u_int
mcclock_read(struct mc146818_softc
*, u_int
);
60 mcclock_match(device_t parent
, cfdata_t cf
, void *aux
)
62 static int mcclock_found
;
73 mcclock_attach(device_t parent
, device_t self
, void *aux
)
75 struct mc146818_softc
*sc
= device_private(self
);
76 struct mainbus_attach_args
*ma
= aux
;
79 sc
->sc_bst
= ma
->ma_iot
;
80 if (bus_space_map(sc
->sc_bst
, ma
->ma_addr
, MCCLOCK_NPORTS
,
82 aprint_error("mcclock_attach: unable to map registers\n");
87 sc
->sc_mcread
= mcclock_read
;
88 sc
->sc_mcwrite
= mcclock_write
;
89 sc
->sc_flag
= MC146818_BCD
;
94 (*sc
->sc_mcwrite
)(sc
, MC_REGB
, MC_REGB_24HR
);
98 mcclock_write(struct mc146818_softc
*sc
, u_int reg
, u_int datum
)
101 bus_space_handle_t ioh
;
106 bus_space_write_1(iot
, ioh
, 0, reg
);
107 bus_space_write_1(iot
, ioh
, 1, datum
);
111 mcclock_read(struct mc146818_softc
*sc
, u_int reg
)
114 bus_space_handle_t ioh
;
120 bus_space_write_1(iot
, ioh
, 0, reg
);
121 datum
= bus_space_read_1(iot
, ioh
, 1);