1*ce099b40Smartin /* $NetBSD: mkclock_hb.c,v 1.15 2008/04/28 20:23:30 martin Exp $ */
2d49986b1Stsutsui
3d49986b1Stsutsui /*-
4d49986b1Stsutsui * Copyright (c) 1996 The NetBSD Foundation, Inc.
5d49986b1Stsutsui * All rights reserved.
6d49986b1Stsutsui *
7d49986b1Stsutsui * This code is derived from software contributed to The NetBSD Foundation
8d49986b1Stsutsui * by Jason R. Thorpe.
9d49986b1Stsutsui *
10d49986b1Stsutsui * Redistribution and use in source and binary forms, with or without
11d49986b1Stsutsui * modification, are permitted provided that the following conditions
12d49986b1Stsutsui * are met:
13d49986b1Stsutsui * 1. Redistributions of source code must retain the above copyright
14d49986b1Stsutsui * notice, this list of conditions and the following disclaimer.
15d49986b1Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
16d49986b1Stsutsui * notice, this list of conditions and the following disclaimer in the
17d49986b1Stsutsui * documentation and/or other materials provided with the distribution.
18d49986b1Stsutsui *
19d49986b1Stsutsui * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20d49986b1Stsutsui * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21d49986b1Stsutsui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22d49986b1Stsutsui * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23d49986b1Stsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24d49986b1Stsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25d49986b1Stsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26d49986b1Stsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27d49986b1Stsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28d49986b1Stsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29d49986b1Stsutsui * POSSIBILITY OF SUCH DAMAGE.
30d49986b1Stsutsui */
31d49986b1Stsutsui
32ed517291Slukem #include <sys/cdefs.h>
33*ce099b40Smartin __KERNEL_RCSID(0, "$NetBSD: mkclock_hb.c,v 1.15 2008/04/28 20:23:30 martin Exp $");
34ed517291Slukem
35d49986b1Stsutsui #include <sys/param.h>
36d49986b1Stsutsui #include <sys/kernel.h>
37d49986b1Stsutsui #include <sys/systm.h>
38d49986b1Stsutsui #include <sys/device.h>
39d49986b1Stsutsui
40d49986b1Stsutsui #include <machine/cpu.h>
41d49986b1Stsutsui #include <machine/bus.h>
42d49986b1Stsutsui
43d49986b1Stsutsui #include <dev/clock_subr.h>
44d49986b1Stsutsui #include <dev/ic/mk48txxreg.h>
45164022f5Stsutsui #include <dev/ic/mk48txxvar.h>
46d49986b1Stsutsui
47d49986b1Stsutsui #include <news68k/news68k/clockvar.h>
48d49986b1Stsutsui
49d49986b1Stsutsui #include <news68k/dev/hbvar.h>
50d49986b1Stsutsui
51378871cdStsutsui #include "ioconf.h"
52378871cdStsutsui
5303bb6cc8Stsutsui static int mkclock_hb_match(device_t, cfdata_t, void *);
5403bb6cc8Stsutsui static void mkclock_hb_attach(device_t, device_t, void *);
55d49986b1Stsutsui
5603bb6cc8Stsutsui CFATTACH_DECL_NEW(mkclock_hb, sizeof(struct mk48txx_softc),
57021b694dSthorpej mkclock_hb_match, mkclock_hb_attach, NULL, NULL);
58d49986b1Stsutsui
5952b46dcfStsutsui static int
mkclock_hb_match(device_t parent,cfdata_t cf,void * aux)6003bb6cc8Stsutsui mkclock_hb_match(device_t parent, cfdata_t cf, void *aux)
61d49986b1Stsutsui {
62d49986b1Stsutsui struct hb_attach_args *ha = aux;
63d49986b1Stsutsui static int mkclock_hb_matched;
64d49986b1Stsutsui
65d49986b1Stsutsui /* Only one clock, please. */
66d49986b1Stsutsui if (mkclock_hb_matched)
6752b46dcfStsutsui return 0;
68d49986b1Stsutsui
69d49986b1Stsutsui if (strcmp(ha->ha_name, mkclock_cd.cd_name))
7052b46dcfStsutsui return 0;
71d49986b1Stsutsui
72d49986b1Stsutsui ha->ha_size = MK48T02_CLKSZ;
73d49986b1Stsutsui
74d49986b1Stsutsui mkclock_hb_matched = 1;
75d49986b1Stsutsui
76d49986b1Stsutsui return 1;
77d49986b1Stsutsui }
78d49986b1Stsutsui
7952b46dcfStsutsui static void
mkclock_hb_attach(device_t parent,device_t self,void * aux)8003bb6cc8Stsutsui mkclock_hb_attach(device_t parent, device_t self, void *aux)
81d49986b1Stsutsui {
8203bb6cc8Stsutsui struct mk48txx_softc *sc = device_private(self);
83d49986b1Stsutsui struct hb_attach_args *ha = aux;
84d49986b1Stsutsui
854090172bStsutsui sc->sc_dev = self;
86164022f5Stsutsui sc->sc_bst = ha->ha_bust;
87164022f5Stsutsui if (bus_space_map(sc->sc_bst, (bus_addr_t)ha->ha_address, ha->ha_size,
88164022f5Stsutsui 0, &sc->sc_bsh) != 0)
8903bb6cc8Stsutsui aprint_error("can't map device space\n");
90d49986b1Stsutsui
91164022f5Stsutsui sc->sc_model = "mk48t02";
92164022f5Stsutsui sc->sc_year0 = 1900;
93164022f5Stsutsui mk48txx_attach(sc);
94d49986b1Stsutsui
9503bb6cc8Stsutsui aprint_normal("\n");
96d49986b1Stsutsui }
97