xref: /netbsd-src/sys/arch/amiga/dev/a2kbbc.c (revision a25b458635809cc8e737dd7a033de293a67c8a01)
1*a25b4586Srkujawa /*	$NetBSD: a2kbbc.c,v 1.26 2013/01/27 19:58:04 rkujawa Exp $ */
2aad01611Sagc 
3aad01611Sagc /*
49b6bd2d9Srmind  * Copyright (c) 1988 University of Utah.
5aad01611Sagc  * Copyright (c) 1982, 1990 The Regents of the University of California.
6aad01611Sagc  * All rights reserved.
7aad01611Sagc  *
8aad01611Sagc  * This code is derived from software contributed to Berkeley by
9aad01611Sagc  * the Systems Programming Group of the University of Utah Computer
10aad01611Sagc  * Science Department.
11aad01611Sagc  *
12aad01611Sagc  * Redistribution and use in source and binary forms, with or without
13aad01611Sagc  * modification, are permitted provided that the following conditions
14aad01611Sagc  * are met:
15aad01611Sagc  * 1. Redistributions of source code must retain the above copyright
16aad01611Sagc  *    notice, this list of conditions and the following disclaimer.
17aad01611Sagc  * 2. Redistributions in binary form must reproduce the above copyright
18aad01611Sagc  *    notice, this list of conditions and the following disclaimer in the
19aad01611Sagc  *    documentation and/or other materials provided with the distribution.
20aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
21aad01611Sagc  *    may be used to endorse or promote products derived from this software
22aad01611Sagc  *    without specific prior written permission.
23aad01611Sagc  *
24aad01611Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25aad01611Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26aad01611Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27aad01611Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28aad01611Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29aad01611Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30aad01611Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31aad01611Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32aad01611Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33aad01611Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34aad01611Sagc  * SUCH DAMAGE.
35aad01611Sagc  *
36aad01611Sagc  * from: Utah $Hdr: clock.c 1.18 91/01/21$
37aad01611Sagc  *
38aad01611Sagc  *	@(#)clock.c	7.6 (Berkeley) 5/7/91
39aad01611Sagc  */
404d8c2c35Sis 
411ea4df81Saymeric #include <sys/cdefs.h>
42*a25b4586Srkujawa __KERNEL_RCSID(0, "$NetBSD: a2kbbc.c,v 1.26 2013/01/27 19:58:04 rkujawa Exp $");
431ea4df81Saymeric 
444d8c2c35Sis #include <sys/param.h>
454d8c2c35Sis #include <sys/kernel.h>
464d8c2c35Sis #include <sys/device.h>
474d8c2c35Sis #include <sys/systm.h>
4815d04dfeSrkujawa #include <sys/bus.h>
494d8c2c35Sis #include <machine/psl.h>
504d8c2c35Sis #include <machine/cpu.h>
514d8c2c35Sis #include <amiga/amiga/device.h>
524d8c2c35Sis #include <amiga/amiga/custom.h>
534d8c2c35Sis #include <amiga/amiga/cia.h>
544d8c2c35Sis #include <amiga/dev/zbusvar.h>
554d8c2c35Sis 
564d8c2c35Sis #include <dev/clock_subr.h>
574d8c2c35Sis 
5815d04dfeSrkujawa #include <dev/ic/msm6242bvar.h>
5915d04dfeSrkujawa #include <dev/ic/msm6242breg.h>
604d8c2c35Sis 
6115d04dfeSrkujawa #define	A2KBBC_ADDR	0xDC0000	/* XXX: possible D80000 on A2000 "A"? */
6215d04dfeSrkujawa 
6315d04dfeSrkujawa static int a2kbbc_match(device_t, cfdata_t, void *);
6415d04dfeSrkujawa static void a2kbbc_attach(device_t, device_t, void *);
6515d04dfeSrkujawa 
6615d04dfeSrkujawa struct a2kbbc_softc {
6715d04dfeSrkujawa 	struct msm6242b_softc sc_msm6242b;
6815d04dfeSrkujawa 	struct bus_space_tag sc_bst;
6915d04dfeSrkujawa };
7015d04dfeSrkujawa 
7115d04dfeSrkujawa CFATTACH_DECL_NEW(a2kbbc, sizeof(struct a2kbbc_softc),
72c5e91d44Sthorpej     a2kbbc_match, a2kbbc_attach, NULL, NULL);
734d8c2c35Sis 
7415d04dfeSrkujawa static int
a2kbbc_match(device_t parent,cfdata_t cf,void * aux)75cbab9cadSchs a2kbbc_match(device_t parent, cfdata_t cf, void *aux)
764d8c2c35Sis {
7716343055Skleink 	static int a2kbbc_matched = 0;
7816343055Skleink 
79cbab9cadSchs 	if (!matchname("a2kbbc", aux))
804d8c2c35Sis 		return (0);
814d8c2c35Sis 
8216343055Skleink 	/* Allow only one instance. */
8316343055Skleink 	if (a2kbbc_matched)
8416343055Skleink 		return (0);
854d8c2c35Sis 
8625d10d43Sis 	if (/* is_a1200() || */ is_a3000() || is_a4000()
87181debe5Sis #ifdef DRACO
88181debe5Sis 	    || is_draco()
89181debe5Sis #endif
90181debe5Sis 	    )
914d8c2c35Sis 		return (0);
924d8c2c35Sis 
9316343055Skleink 	a2kbbc_matched = 1;
944d8c2c35Sis 	return (1);
954d8c2c35Sis }
964d8c2c35Sis 
974d8c2c35Sis /*
984d8c2c35Sis  * Attach us to the rtc function pointers.
994d8c2c35Sis  */
1004d8c2c35Sis void
a2kbbc_attach(device_t parent,device_t self,void * aux)101cbab9cadSchs a2kbbc_attach(device_t parent, device_t self, void *aux)
1024d8c2c35Sis {
10315d04dfeSrkujawa 	struct a2kbbc_softc *sc;
10415d04dfeSrkujawa 	struct msm6242b_softc *msc;
1054d8c2c35Sis 
10615d04dfeSrkujawa 	sc = device_private(self);
10715d04dfeSrkujawa 	msc = &sc->sc_msm6242b;
10815d04dfeSrkujawa 	msc->sc_dev = self;
10915d04dfeSrkujawa 
11015d04dfeSrkujawa 	sc->sc_bst.base = (bus_addr_t) __UNVOLATILE(ztwomap(A2KBBC_ADDR+1));
11115d04dfeSrkujawa 	sc->sc_bst.absm = &amiga_bus_stride_4;
11215d04dfeSrkujawa 
11315d04dfeSrkujawa 	msc->sc_iot = &sc->sc_bst;
11415d04dfeSrkujawa 
11515d04dfeSrkujawa 	if (bus_space_map(msc->sc_iot, 0, MSM6242B_SIZE, 0, &msc->sc_ioh)) {
11615d04dfeSrkujawa 		aprint_error_dev(msc->sc_dev, "couldn't map registers\n");
11715d04dfeSrkujawa 		return;
1184d8c2c35Sis 	}
1194d8c2c35Sis 
12015d04dfeSrkujawa 	msm6242b_attach(msc);
1214d8c2c35Sis }
1224d8c2c35Sis 
1234d8c2c35Sis 
124