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