xref: /netbsd-src/sys/arch/algor/dev/mcclock_mainbus.c (revision f5439ed7d3afb5ce0ef10071715eacf53104122d)
1*f5439ed7Smatt /*	$NetBSD: mcclock_mainbus.c,v 1.12 2011/07/09 16:03:01 matt Exp $	*/
271cb790fSthorpej 
371cb790fSthorpej /*
471cb790fSthorpej  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
571cb790fSthorpej  * All rights reserved.
671cb790fSthorpej  *
771cb790fSthorpej  * Author: Chris G. Demetriou
871cb790fSthorpej  *
971cb790fSthorpej  * Permission to use, copy, modify and distribute this software and
1071cb790fSthorpej  * its documentation is hereby granted, provided that both the copyright
1171cb790fSthorpej  * notice and this permission notice appear in all copies of the
1271cb790fSthorpej  * software, derivative works or modified versions, and any portions
1371cb790fSthorpej  * thereof, and that both notices appear in supporting documentation.
1471cb790fSthorpej  *
1571cb790fSthorpej  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
1671cb790fSthorpej  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
1771cb790fSthorpej  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1871cb790fSthorpej  *
1971cb790fSthorpej  * Carnegie Mellon requests users of this software to return to
2071cb790fSthorpej  *
2171cb790fSthorpej  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
2271cb790fSthorpej  *  School of Computer Science
2371cb790fSthorpej  *  Carnegie Mellon University
2471cb790fSthorpej  *  Pittsburgh PA 15213-3890
2571cb790fSthorpej  *
2671cb790fSthorpej  * any improvements or extensions that they make and grant Carnegie the
2771cb790fSthorpej  * rights to redistribute these changes.
2871cb790fSthorpej  */
2971cb790fSthorpej 
3071cb790fSthorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
3171cb790fSthorpej 
32*f5439ed7Smatt __KERNEL_RCSID(0, "$NetBSD: mcclock_mainbus.c,v 1.12 2011/07/09 16:03:01 matt Exp $");
3371cb790fSthorpej 
3471cb790fSthorpej #include <sys/param.h>
35*f5439ed7Smatt #include <sys/bus.h>
36*f5439ed7Smatt #include <sys/device.h>
3771cb790fSthorpej #include <sys/kernel.h>
3871cb790fSthorpej #include <sys/systm.h>
3971cb790fSthorpej 
40*f5439ed7Smatt #include <algor/autoconf.h>
4171cb790fSthorpej 
42c1194014Sgdamore #include <dev/clock_subr.h>
43*f5439ed7Smatt 
4471cb790fSthorpej #include <dev/ic/mc146818reg.h>
45c1194014Sgdamore #include <dev/ic/mc146818var.h>
4671cb790fSthorpej 
47048fb884Stsutsui int	mcclock_mainbus_match(device_t, cfdata_t, void *);
48048fb884Stsutsui void	mcclock_mainbus_attach(device_t, device_t, void *);
4971cb790fSthorpej 
50048fb884Stsutsui CFATTACH_DECL_NEW(mcclock_mainbus, sizeof(struct mc146818_softc),
515a9ddc14Sthorpej     mcclock_mainbus_match, mcclock_mainbus_attach, NULL, NULL);
5271cb790fSthorpej 
53c1194014Sgdamore void	mcclock_mainbus_write(struct mc146818_softc *, u_int, u_int);
54c1194014Sgdamore u_int	mcclock_mainbus_read(struct mc146818_softc *, u_int);
5571cb790fSthorpej 
5671cb790fSthorpej int
mcclock_mainbus_match(device_t parent,cfdata_t cf,void * aux)57048fb884Stsutsui mcclock_mainbus_match(device_t parent, cfdata_t cf, void *aux)
5871cb790fSthorpej {
5971cb790fSthorpej 	struct mainbus_attach_args *ma = aux;
6071cb790fSthorpej 
61048fb884Stsutsui 	if (strcmp(ma->ma_name, cf->cf_name) == 0)
6271cb790fSthorpej 		return (1);
6371cb790fSthorpej 
6471cb790fSthorpej 	return (0);
6571cb790fSthorpej }
6671cb790fSthorpej 
6771cb790fSthorpej void
mcclock_mainbus_attach(device_t parent,device_t self,void * aux)68048fb884Stsutsui mcclock_mainbus_attach(device_t parent, device_t self, void *aux)
6971cb790fSthorpej {
70048fb884Stsutsui 	struct mc146818_softc *sc = device_private(self);
7171cb790fSthorpej 	struct mainbus_attach_args *ma = aux;
7271cb790fSthorpej 
734090172bStsutsui 	sc->sc_dev = self;
74c1194014Sgdamore 	sc->sc_bst = ma->ma_st;
75c1194014Sgdamore 	if (bus_space_map(sc->sc_bst, ma->ma_addr, 2, 0, &sc->sc_bsh))
7671cb790fSthorpej 		panic("mcclock_mainbus_attach: couldn't map clock I/O space");
7771cb790fSthorpej 
78c1194014Sgdamore 	/*
79c1194014Sgdamore 	 * Turn interrupts off, just in case.  Need to leave the SQWE
80c1194014Sgdamore 	 * set, because that's the DRAM refresh signal on Rev. B boards.
81c1194014Sgdamore 	 */
82c1194014Sgdamore 	mcclock_mainbus_write(sc, MC_REGB, MC_REGB_SQWE | MC_REGB_BINARY |
83c1194014Sgdamore 	    MC_REGB_24HR);
84c1194014Sgdamore 
85c1194014Sgdamore 	sc->sc_mcread = mcclock_mainbus_read;
86c1194014Sgdamore 	sc->sc_mcwrite = mcclock_mainbus_write;
87c1194014Sgdamore 	sc->sc_getcent = NULL;
88c1194014Sgdamore 	sc->sc_setcent = NULL;
89c1194014Sgdamore 	sc->sc_flag = 0;
90c1194014Sgdamore 
91c1194014Sgdamore 	/* Algor uses year 1980 as offset */
9281ce14a3Stsutsui 	sc->sc_year0 = 1980;
93c1194014Sgdamore 
94c1194014Sgdamore 	mc146818_attach(sc);
9581ce14a3Stsutsui 
9681ce14a3Stsutsui 	aprint_normal("\n");
9771cb790fSthorpej }
9871cb790fSthorpej 
9971cb790fSthorpej void
mcclock_mainbus_write(struct mc146818_softc * sc,u_int reg,u_int datum)100c1194014Sgdamore mcclock_mainbus_write(struct mc146818_softc *sc, u_int reg, u_int datum)
10171cb790fSthorpej {
102c1194014Sgdamore 	bus_space_tag_t iot = sc->sc_bst;
103c1194014Sgdamore 	bus_space_handle_t ioh = sc->sc_bsh;
10471cb790fSthorpej 
10571cb790fSthorpej 	bus_space_write_1(iot, ioh, 0, reg);
10671cb790fSthorpej 	bus_space_write_1(iot, ioh, 1, datum);
10771cb790fSthorpej }
10871cb790fSthorpej 
10971cb790fSthorpej u_int
mcclock_mainbus_read(struct mc146818_softc * sc,u_int reg)110c1194014Sgdamore mcclock_mainbus_read(struct mc146818_softc *sc, u_int reg)
11171cb790fSthorpej {
112c1194014Sgdamore 	bus_space_tag_t iot = sc->sc_bst;
113c1194014Sgdamore 	bus_space_handle_t ioh = sc->sc_bsh;
11471cb790fSthorpej 
11571cb790fSthorpej 	bus_space_write_1(iot, ioh, 0, reg);
11671cb790fSthorpej 	return bus_space_read_1(iot, ioh, 1);
11771cb790fSthorpej }
118