1/*	$NetBSD: a2kbbc.c,v 1.25 2012/11/14 01:55:25 rkujawa Exp $ */
2
3/*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1982, 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: Utah $Hdr: clock.c 1.18 91/01/21$
37 *
38 *	@(#)clock.c	7.6 (Berkeley) 5/7/91
39 */
40
41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: a2kbbc.c,v 1.25 2012/11/14 01:55:25 rkujawa Exp $");
43
44#include <sys/param.h>
45#include <sys/kernel.h>
46#include <sys/device.h>
47#include <sys/systm.h>
48#include <sys/bus.h>
49#include <machine/psl.h>
50#include <machine/cpu.h>
51#include <amiga/amiga/device.h>
52#include <amiga/amiga/custom.h>
53#include <amiga/amiga/cia.h>
54#include <amiga/dev/zbusvar.h>
55
56#include <dev/clock_subr.h>
57
58#include <dev/ic/msm6242bvar.h>
59#include <dev/ic/msm6242breg.h>
60
61#define	A2KBBC_ADDR	0xDC0000	/* XXX: possible D80000 on A2000 "A"? */
62
63static int a2kbbc_match(device_t, cfdata_t, void *);
64static void a2kbbc_attach(device_t, device_t, void *);
65
66struct a2kbbc_softc {
67	struct msm6242b_softc sc_msm6242b;
68	struct bus_space_tag sc_bst;
69};
70
71CFATTACH_DECL_NEW(a2kbbc, sizeof(struct a2kbbc_softc),
72    a2kbbc_match, a2kbbc_attach, NULL, NULL);
73
74static int
75a2kbbc_match(device_t parent, cfdata_t cf, void *aux)
76{
77	static int a2kbbc_matched = 0;
78
79	if (!matchname("a2kbbc", aux))
80		return (0);
81
82	/* Allow only one instance. */
83	if (a2kbbc_matched)
84		return (0);
85
86	if (/* is_a1200() || */ is_a3000() || is_a4000()
87#ifdef DRACO
88	    || is_draco()
89#endif
90	    )
91		return (0);
92
93	a2kbbc_matched = 1;
94	return (1);
95}
96
97/*
98 * Attach us to the rtc function pointers.
99 */
100void
101a2kbbc_attach(device_t parent, device_t self, void *aux)
102{
103	struct a2kbbc_softc *sc;
104	struct msm6242b_softc *msc;
105
106	sc = device_private(self);
107	msc = &sc->sc_msm6242b;
108	msc->sc_dev = self;
109
110	sc->sc_bst.base = (bus_addr_t) __UNVOLATILE(ztwomap(A2KBBC_ADDR+1));
111	sc->sc_bst.absm = &amiga_bus_stride_4;
112
113	msc->sc_iot = &sc->sc_bst;
114
115	if (bus_space_map(msc->sc_iot, 0, MSM6242B_SIZE, 0, &msc->sc_ioh)) {
116		aprint_error_dev(msc->sc_dev, "couldn't map registers\n");
117		return;
118	}
119
120	msm6242b_attach(msc);
121}
122
123
124