xref: /netbsd-src/sys/arch/newsmips/dev/mkclock_hb.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /*	$NetBSD: mkclock_hb.c,v 1.8 2008/04/28 20:23:30 martin Exp $	*/
262c9f076Stsutsui 
362c9f076Stsutsui /*-
462c9f076Stsutsui  * Copyright (c) 1996 The NetBSD Foundation, Inc.
562c9f076Stsutsui  * All rights reserved.
662c9f076Stsutsui  *
762c9f076Stsutsui  * This code is derived from software contributed to The NetBSD Foundation
862c9f076Stsutsui  * by Jason R. Thorpe.
962c9f076Stsutsui  *
1062c9f076Stsutsui  * Redistribution and use in source and binary forms, with or without
1162c9f076Stsutsui  * modification, are permitted provided that the following conditions
1262c9f076Stsutsui  * are met:
1362c9f076Stsutsui  * 1. Redistributions of source code must retain the above copyright
1462c9f076Stsutsui  *    notice, this list of conditions and the following disclaimer.
1562c9f076Stsutsui  * 2. Redistributions in binary form must reproduce the above copyright
1662c9f076Stsutsui  *    notice, this list of conditions and the following disclaimer in the
1762c9f076Stsutsui  *    documentation and/or other materials provided with the distribution.
1862c9f076Stsutsui  *
1962c9f076Stsutsui  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2062c9f076Stsutsui  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2162c9f076Stsutsui  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2262c9f076Stsutsui  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2362c9f076Stsutsui  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2462c9f076Stsutsui  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2562c9f076Stsutsui  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2662c9f076Stsutsui  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2762c9f076Stsutsui  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2862c9f076Stsutsui  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2962c9f076Stsutsui  * POSSIBILITY OF SUCH DAMAGE.
3062c9f076Stsutsui  */
3162c9f076Stsutsui 
3262c9f076Stsutsui #include <sys/cdefs.h>
33*ce099b40Smartin __KERNEL_RCSID(0, "$NetBSD: mkclock_hb.c,v 1.8 2008/04/28 20:23:30 martin Exp $");
3462c9f076Stsutsui 
3562c9f076Stsutsui #include <sys/param.h>
3662c9f076Stsutsui #include <sys/kernel.h>
3762c9f076Stsutsui #include <sys/systm.h>
3862c9f076Stsutsui #include <sys/device.h>
3962c9f076Stsutsui 
4062c9f076Stsutsui #include <machine/cpu.h>
4162c9f076Stsutsui #include <machine/bus.h>
4262c9f076Stsutsui 
4362c9f076Stsutsui #include <dev/clock_subr.h>
4462c9f076Stsutsui #include <dev/ic/mk48txxreg.h>
452ddfa78dStsutsui #include <dev/ic/mk48txxvar.h>
4662c9f076Stsutsui 
4762c9f076Stsutsui #include <newsmips/dev/hbvar.h>
4862c9f076Stsutsui 
4903bb6cc8Stsutsui #include "ioconf.h"
5062c9f076Stsutsui 
5103bb6cc8Stsutsui int  mkclock_hb_match(device_t, cfdata_t, void *);
5203bb6cc8Stsutsui void mkclock_hb_attach(device_t, device_t, void *);
5303bb6cc8Stsutsui 
5403bb6cc8Stsutsui CFATTACH_DECL_NEW(mkclock_hb, sizeof(struct mk48txx_softc),
5562c9f076Stsutsui     mkclock_hb_match, mkclock_hb_attach, NULL, NULL);
5662c9f076Stsutsui 
5762c9f076Stsutsui int
mkclock_hb_match(device_t parent,cfdata_t cf,void * aux)5803bb6cc8Stsutsui mkclock_hb_match(device_t parent, cfdata_t cf, void *aux)
5962c9f076Stsutsui {
6062c9f076Stsutsui 	struct hb_attach_args *ha = aux;
6162c9f076Stsutsui 	static int mkclock_hb_matched;
6262c9f076Stsutsui 
6362c9f076Stsutsui 	/* Only one clock, please. */
6462c9f076Stsutsui 	if (mkclock_hb_matched)
65fd4afa03Stsutsui 		return 0;
6662c9f076Stsutsui 
6762c9f076Stsutsui 	if (strcmp(ha->ha_name, mkclock_cd.cd_name))
68fd4afa03Stsutsui 		return 0;
6962c9f076Stsutsui 
7062c9f076Stsutsui 	mkclock_hb_matched = 1;
7162c9f076Stsutsui 
7262c9f076Stsutsui 	return 1;
7362c9f076Stsutsui }
7462c9f076Stsutsui 
7562c9f076Stsutsui void
mkclock_hb_attach(device_t parent,device_t self,void * aux)7603bb6cc8Stsutsui mkclock_hb_attach(device_t parent, device_t self, void *aux)
7762c9f076Stsutsui {
7803bb6cc8Stsutsui 	struct mk48txx_softc *sc = device_private(self);
7962c9f076Stsutsui 	struct hb_attach_args *ha = aux;
8062c9f076Stsutsui 
814090172bStsutsui 	sc->sc_dev = self;
822ddfa78dStsutsui 	if (bus_space_map(sc->sc_bst, (bus_addr_t)ha->ha_addr, MK48T02_CLKSZ,
832ddfa78dStsutsui 	    0, &sc->sc_bsh) != 0)
8403bb6cc8Stsutsui 		aprint_error(": can't map device space\n");
8562c9f076Stsutsui 
862ddfa78dStsutsui 	sc->sc_model = "mk48t02";
872ddfa78dStsutsui 	sc->sc_year0 = 1900;
882ddfa78dStsutsui 	mk48txx_attach(sc);
8962c9f076Stsutsui 
9003bb6cc8Stsutsui 	aprint_normal("\n");
9162c9f076Stsutsui }
92