xref: /netbsd-src/sys/arch/mvme68k/dev/timekeeper.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /*	$NetBSD: timekeeper.c,v 1.13 2008/04/28 20:23:29 martin Exp $	*/
2e9261b9fSscw 
3e9261b9fSscw /*-
4e9261b9fSscw  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5e9261b9fSscw  * All rights reserved.
6e9261b9fSscw  *
7e9261b9fSscw  * This code is derived from software contributed to The NetBSD Foundation
8e9261b9fSscw  * by Steve C. Woodford.
9e9261b9fSscw  *
10e9261b9fSscw  * Redistribution and use in source and binary forms, with or without
11e9261b9fSscw  * modification, are permitted provided that the following conditions
12e9261b9fSscw  * are met:
13e9261b9fSscw  * 1. Redistributions of source code must retain the above copyright
14e9261b9fSscw  *    notice, this list of conditions and the following disclaimer.
15e9261b9fSscw  * 2. Redistributions in binary form must reproduce the above copyright
16e9261b9fSscw  *    notice, this list of conditions and the following disclaimer in the
17e9261b9fSscw  *    documentation and/or other materials provided with the distribution.
18e9261b9fSscw  *
19e9261b9fSscw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20e9261b9fSscw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21e9261b9fSscw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22e9261b9fSscw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23e9261b9fSscw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24e9261b9fSscw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25e9261b9fSscw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26e9261b9fSscw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27e9261b9fSscw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28e9261b9fSscw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29e9261b9fSscw  * POSSIBILITY OF SUCH DAMAGE.
30e9261b9fSscw  */
31e9261b9fSscw 
32e9261b9fSscw /*
33e9261b9fSscw  * Attachment interface for the Time-Keeper RAMs on mvme boards.
34e9261b9fSscw  *
35e9261b9fSscw  * XXXSCW: Needs to be extended to allow read/write to NVRAM by
36e9261b9fSscw  * userland application.
37e9261b9fSscw  */
38e9261b9fSscw 
394b2744bfSlukem #include <sys/cdefs.h>
40*ce099b40Smartin __KERNEL_RCSID(0, "$NetBSD: timekeeper.c,v 1.13 2008/04/28 20:23:29 martin Exp $");
414b2744bfSlukem 
42e9261b9fSscw #include <sys/param.h>
43e9261b9fSscw #include <sys/systm.h>
44e9261b9fSscw #include <sys/device.h>
45e9261b9fSscw #include <sys/conf.h>
46e9261b9fSscw 
47e9261b9fSscw #include <machine/cpu.h>
48e9261b9fSscw #include <machine/bus.h>
49e9261b9fSscw 
505bd17a12Sscw #include <dev/mvme/clockvar.h>
51e9261b9fSscw 
5297717cc9Stsutsui #include <dev/ic/mk48txxreg.h>
5397717cc9Stsutsui #include <dev/ic/mk48txxvar.h>
54e9261b9fSscw 
5597717cc9Stsutsui #include <mvme68k/dev/mainbus.h>
56e9261b9fSscw 
5703bb6cc8Stsutsui #include "ioconf.h"
58e9261b9fSscw 
5903bb6cc8Stsutsui int timekeeper_match(device_t, cfdata_t, void *);
6003bb6cc8Stsutsui void timekeeper_attach(device_t, device_t, void *);
6103bb6cc8Stsutsui 
6203bb6cc8Stsutsui CFATTACH_DECL_NEW(timekeeper, sizeof(struct mk48txx_softc),
63c5e91d44Sthorpej     timekeeper_match, timekeeper_attach, NULL, NULL);
64e9261b9fSscw 
65e9261b9fSscw int
timekeeper_match(device_t parent,cfdata_t cf,void * aux)6603bb6cc8Stsutsui timekeeper_match(device_t parent, cfdata_t cf, void *aux)
67e9261b9fSscw {
68e9261b9fSscw 	struct mainbus_attach_args *ma = aux;
69e9261b9fSscw 
70e9261b9fSscw 	if (strcmp(ma->ma_name, timekeeper_cd.cd_name))
71e9261b9fSscw 		return (0);
72e9261b9fSscw 
73e9261b9fSscw 	return (1);
74e9261b9fSscw }
75e9261b9fSscw 
76e9261b9fSscw void
timekeeper_attach(device_t parent,device_t self,void * aux)7703bb6cc8Stsutsui timekeeper_attach(device_t parent, device_t self, void *aux)
78e9261b9fSscw {
7903bb6cc8Stsutsui 	struct mk48txx_softc *sc = device_private(self);
80e9261b9fSscw 	struct mainbus_attach_args *ma = aux;
8197717cc9Stsutsui 	bus_size_t size;
82e9261b9fSscw 
834090172bStsutsui 	sc->sc_dev = self;
8497717cc9Stsutsui 	sc->sc_bst = ma->ma_bust;
85e9261b9fSscw 
86e9261b9fSscw 	if (machineid == MVME_147) {
8797717cc9Stsutsui 		size = MK48T02_CLKSZ;
8897717cc9Stsutsui 		sc->sc_model = "mk48t02";
89e9261b9fSscw 	} else {
9097717cc9Stsutsui 		size = MK48T08_CLKSZ;
9197717cc9Stsutsui 		sc->sc_model = "mk48t08";
92e9261b9fSscw 	}
93e9261b9fSscw 
9497717cc9Stsutsui 	bus_space_map(sc->sc_bst, ma->ma_offset, size, 0, &sc->sc_bsh);
95e9261b9fSscw 
9697717cc9Stsutsui 	sc->sc_year0 = YEAR0;
9797717cc9Stsutsui 	mk48txx_attach(sc);
98e9261b9fSscw 
9903bb6cc8Stsutsui 	aprint_normal(" Time-Keeper RAM\n");
10003bb6cc8Stsutsui 	aprint_normal_dev(self, "%ld bytes NVRAM plus Realtime Clock\n",
10103bb6cc8Stsutsui 	    sc->sc_nvramsz);
102e9261b9fSscw }
103