Home | History | Annotate | Line # | Download | only in dev
ds17485.c revision 1.2.4.3
      1  1.2.4.3  yamt /*	$NetBSD: ds17485.c,v 1.2.4.3 2008/01/21 09:36:20 yamt Exp $	*/
      2  1.2.4.2  yamt 
      3  1.2.4.2  yamt /*
      4  1.2.4.2  yamt  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  1.2.4.2  yamt  * All rights reserved.
      6  1.2.4.2  yamt  *
      7  1.2.4.2  yamt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.4.2  yamt  * by Lennart Augustsson (lennart (at) augustsson.net) at Sandburst Corp.
      9  1.2.4.2  yamt  *
     10  1.2.4.2  yamt  * Redistribution and use in source and binary forms, with or without
     11  1.2.4.2  yamt  * modification, are permitted provided that the following conditions
     12  1.2.4.2  yamt  * are met:
     13  1.2.4.2  yamt  * 1. Redistributions of source code must retain the above copyright
     14  1.2.4.2  yamt  *    notice, this list of conditions and the following disclaimer.
     15  1.2.4.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.4.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.4.2  yamt  *    documentation and/or other materials provided with the distribution.
     18  1.2.4.2  yamt  * 3. All advertising materials mentioning features or use of this software
     19  1.2.4.2  yamt  *    must display the following acknowledgement:
     20  1.2.4.2  yamt  *        This product includes software developed by the NetBSD
     21  1.2.4.2  yamt  *        Foundation, Inc. and its contributors.
     22  1.2.4.2  yamt  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2.4.2  yamt  *    contributors may be used to endorse or promote products derived
     24  1.2.4.2  yamt  *    from this software without specific prior written permission.
     25  1.2.4.2  yamt  *
     26  1.2.4.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2.4.2  yamt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2.4.2  yamt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2.4.2  yamt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2.4.2  yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2.4.2  yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2.4.2  yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2.4.2  yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2.4.2  yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2.4.2  yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2.4.2  yamt  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2.4.2  yamt  */
     38  1.2.4.2  yamt 
     39  1.2.4.2  yamt /*-
     40  1.2.4.2  yamt  * Copyright (c) 1990 The Regents of the University of California.
     41  1.2.4.2  yamt  * All rights reserved.
     42  1.2.4.2  yamt  *
     43  1.2.4.2  yamt  * This code is derived from software contributed to Berkeley by
     44  1.2.4.2  yamt  * William Jolitz and Don Ahn.
     45  1.2.4.2  yamt  *
     46  1.2.4.2  yamt  * Redistribution and use in source and binary forms, with or without
     47  1.2.4.2  yamt  * modification, are permitted provided that the following conditions
     48  1.2.4.2  yamt  * are met:
     49  1.2.4.2  yamt  * 1. Redistributions of source code must retain the above copyright
     50  1.2.4.2  yamt  *    notice, this list of conditions and the following disclaimer.
     51  1.2.4.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.2.4.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     53  1.2.4.2  yamt  *    documentation and/or other materials provided with the distribution.
     54  1.2.4.2  yamt  * 3. Neither the name of the University nor the names of its contributors
     55  1.2.4.2  yamt  *    may be used to endorse or promote products derived from this software
     56  1.2.4.2  yamt  *    without specific prior written permission.
     57  1.2.4.2  yamt  *
     58  1.2.4.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  1.2.4.2  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  1.2.4.2  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  1.2.4.2  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  1.2.4.2  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  1.2.4.2  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  1.2.4.2  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  1.2.4.2  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  1.2.4.2  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  1.2.4.2  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  1.2.4.2  yamt  * SUCH DAMAGE.
     69  1.2.4.2  yamt  *
     70  1.2.4.2  yamt  *	@(#)clock.c	7.2 (Berkeley) 5/12/91
     71  1.2.4.2  yamt  */
     72  1.2.4.2  yamt /*-
     73  1.2.4.2  yamt  * Copyright (c) 1993, 1994 Charles M. Hannum.
     74  1.2.4.2  yamt  *
     75  1.2.4.2  yamt  * This code is derived from software contributed to Berkeley by
     76  1.2.4.2  yamt  * William Jolitz and Don Ahn.
     77  1.2.4.2  yamt  *
     78  1.2.4.2  yamt  * Redistribution and use in source and binary forms, with or without
     79  1.2.4.2  yamt  * modification, are permitted provided that the following conditions
     80  1.2.4.2  yamt  * are met:
     81  1.2.4.2  yamt  * 1. Redistributions of source code must retain the above copyright
     82  1.2.4.2  yamt  *    notice, this list of conditions and the following disclaimer.
     83  1.2.4.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     84  1.2.4.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     85  1.2.4.2  yamt  *    documentation and/or other materials provided with the distribution.
     86  1.2.4.2  yamt  * 3. All advertising materials mentioning features or use of this software
     87  1.2.4.2  yamt  *    must display the following acknowledgement:
     88  1.2.4.2  yamt  *	This product includes software developed by the University of
     89  1.2.4.2  yamt  *	California, Berkeley and its contributors.
     90  1.2.4.2  yamt  * 4. Neither the name of the University nor the names of its contributors
     91  1.2.4.2  yamt  *    may be used to endorse or promote products derived from this software
     92  1.2.4.2  yamt  *    without specific prior written permission.
     93  1.2.4.2  yamt  *
     94  1.2.4.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     95  1.2.4.2  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     96  1.2.4.2  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     97  1.2.4.2  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     98  1.2.4.2  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     99  1.2.4.2  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    100  1.2.4.2  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    101  1.2.4.2  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    102  1.2.4.2  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    103  1.2.4.2  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    104  1.2.4.2  yamt  * SUCH DAMAGE.
    105  1.2.4.2  yamt  *
    106  1.2.4.2  yamt  *	@(#)clock.c	7.2 (Berkeley) 5/12/91
    107  1.2.4.2  yamt  */
    108  1.2.4.2  yamt /*
    109  1.2.4.2  yamt  * Mach Operating System
    110  1.2.4.2  yamt  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
    111  1.2.4.2  yamt  * All Rights Reserved.
    112  1.2.4.2  yamt  *
    113  1.2.4.2  yamt  * Permission to use, copy, modify and distribute this software and its
    114  1.2.4.2  yamt  * documentation is hereby granted, provided that both the copyright
    115  1.2.4.2  yamt  * notice and this permission notice appear in all copies of the
    116  1.2.4.2  yamt  * software, derivative works or modified versions, and any portions
    117  1.2.4.2  yamt  * thereof, and that both notices appear in supporting documentation.
    118  1.2.4.2  yamt  *
    119  1.2.4.2  yamt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
    120  1.2.4.2  yamt  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
    121  1.2.4.2  yamt  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
    122  1.2.4.2  yamt  *
    123  1.2.4.2  yamt  * Carnegie Mellon requests users of this software to return to
    124  1.2.4.2  yamt  *
    125  1.2.4.2  yamt  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
    126  1.2.4.2  yamt  *  School of Computer Science
    127  1.2.4.2  yamt  *  Carnegie Mellon University
    128  1.2.4.2  yamt  *  Pittsburgh PA 15213-3890
    129  1.2.4.2  yamt  *
    130  1.2.4.2  yamt  * any improvements or extensions that they make and grant Carnegie Mellon
    131  1.2.4.2  yamt  * the rights to redistribute these changes.
    132  1.2.4.2  yamt  */
    133  1.2.4.2  yamt /*
    134  1.2.4.2  yamt   Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
    135  1.2.4.2  yamt 
    136  1.2.4.2  yamt 		All Rights Reserved
    137  1.2.4.2  yamt 
    138  1.2.4.2  yamt Permission to use, copy, modify, and distribute this software and
    139  1.2.4.2  yamt its documentation for any purpose and without fee is hereby
    140  1.2.4.2  yamt granted, provided that the above copyright notice appears in all
    141  1.2.4.2  yamt copies and that both the copyright notice and this permission notice
    142  1.2.4.2  yamt appear in supporting documentation, and that the name of Intel
    143  1.2.4.2  yamt not be used in advertising or publicity pertaining to distribution
    144  1.2.4.2  yamt of the software without specific, written prior permission.
    145  1.2.4.2  yamt 
    146  1.2.4.2  yamt INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
    147  1.2.4.2  yamt INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
    148  1.2.4.2  yamt IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
    149  1.2.4.2  yamt CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    150  1.2.4.2  yamt LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
    151  1.2.4.2  yamt NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
    152  1.2.4.2  yamt WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    153  1.2.4.2  yamt */
    154  1.2.4.2  yamt 
    155  1.2.4.2  yamt /*
    156  1.2.4.2  yamt  * Primitive clock interrupt routines.
    157  1.2.4.2  yamt  */
    158  1.2.4.2  yamt 
    159  1.2.4.2  yamt #include <sys/cdefs.h>
    160  1.2.4.3  yamt __KERNEL_RCSID(0, "$NetBSD: ds17485.c,v 1.2.4.3 2008/01/21 09:36:20 yamt Exp $");
    161  1.2.4.2  yamt 
    162  1.2.4.2  yamt #include <sys/param.h>
    163  1.2.4.2  yamt #include <sys/systm.h>
    164  1.2.4.2  yamt #include <sys/kernel.h>
    165  1.2.4.2  yamt #include <sys/device.h>
    166  1.2.4.2  yamt 
    167  1.2.4.2  yamt #include <machine/cpu.h>
    168  1.2.4.2  yamt #include <machine/intr.h>
    169  1.2.4.2  yamt #include <machine/bus.h>
    170  1.2.4.2  yamt 
    171  1.2.4.2  yamt #include <dev/clock_subr.h>
    172  1.2.4.2  yamt #include <dev/ic/mc146818reg.h>
    173  1.2.4.2  yamt #include <dev/ic/mc146818var.h>
    174  1.2.4.2  yamt 
    175  1.2.4.2  yamt #include <arch/evbppc/pmppc/dev/mainbus.h>
    176  1.2.4.2  yamt #include <machine/pmppc.h>
    177  1.2.4.2  yamt 
    178  1.2.4.2  yamt static int	rtc_match(struct device *, struct cfdata *, void *);
    179  1.2.4.2  yamt static void	rtc_attach(struct device *, struct device *, void *);
    180  1.2.4.2  yamt 
    181  1.2.4.2  yamt static u_int rtc_read(struct mc146818_softc *, u_int);
    182  1.2.4.2  yamt static void rtc_write(struct mc146818_softc *, u_int, u_int);
    183  1.2.4.2  yamt 
    184  1.2.4.2  yamt CFATTACH_DECL(rtc, sizeof(struct mc146818_softc),
    185  1.2.4.2  yamt     rtc_match, rtc_attach, NULL, NULL);
    186  1.2.4.2  yamt 
    187  1.2.4.2  yamt static int	rtc_attached = 0;
    188  1.2.4.2  yamt int
    189  1.2.4.2  yamt rtc_match(struct device *parent, struct cfdata *cf, void *aux)
    190  1.2.4.2  yamt {
    191  1.2.4.2  yamt 	struct mainbus_attach_args *maa = aux;
    192  1.2.4.2  yamt 
    193  1.2.4.2  yamt 	return (!rtc_attached && strcmp(maa->mb_name, "rtc") == 0);
    194  1.2.4.2  yamt }
    195  1.2.4.2  yamt 
    196  1.2.4.2  yamt void
    197  1.2.4.2  yamt rtc_attach(struct device *parent, struct device *self, void *aux)
    198  1.2.4.2  yamt {
    199  1.2.4.2  yamt 	struct mc146818_softc *sc = (struct mc146818_softc *)self;
    200  1.2.4.2  yamt 	struct mainbus_attach_args *maa = aux;
    201  1.2.4.2  yamt 
    202  1.2.4.2  yamt 	sc->sc_bst = maa->mb_bt;
    203  1.2.4.2  yamt 	if (bus_space_map(sc->sc_bst, maa->mb_addr, PMPPC_RTC_SIZE, 0,
    204  1.2.4.2  yamt 			  &sc->sc_bsh)) {
    205  1.2.4.2  yamt 		printf("%s: can't map i/o space\n", self->dv_xname);
    206  1.2.4.2  yamt 		return;
    207  1.2.4.2  yamt 	}
    208  1.2.4.2  yamt 
    209  1.2.4.2  yamt 	rtc_attached = 1;
    210  1.2.4.2  yamt #ifdef DEBUG
    211  1.2.4.2  yamt 	rtc_print();
    212  1.2.4.2  yamt #endif
    213  1.2.4.2  yamt 	rtc_write(sc, MC_REGA, MC_BASE_32_KHz | MC_RATE_1024_Hz);
    214  1.2.4.2  yamt 	rtc_write(sc, MC_REGB, MC_REGB_24HR);
    215  1.2.4.2  yamt 
    216  1.2.4.2  yamt 	sc->sc_mcread = rtc_read;
    217  1.2.4.2  yamt 	sc->sc_mcwrite = rtc_write;
    218  1.2.4.2  yamt 	sc->sc_flag = 0;
    219  1.2.4.2  yamt 	sc->sc_year0 = 1900;
    220  1.2.4.2  yamt 	mc146818_attach(sc);
    221  1.2.4.2  yamt 
    222  1.2.4.2  yamt 	/* printf(": Dallas Semiconductor DS17485\n"); */
    223  1.2.4.2  yamt 	printf("\n");
    224  1.2.4.2  yamt }
    225  1.2.4.2  yamt 
    226  1.2.4.2  yamt u_int
    227  1.2.4.2  yamt rtc_read(struct mc146818_softc  *sc, u_int reg)
    228  1.2.4.2  yamt {
    229  1.2.4.2  yamt 
    230  1.2.4.2  yamt 	return (bus_space_read_1(sc->sc_bst, sc->sc_bsh, reg));
    231  1.2.4.2  yamt }
    232  1.2.4.2  yamt 
    233  1.2.4.2  yamt void
    234  1.2.4.2  yamt rtc_write(struct mc146818_softc *sc, u_int reg, u_int datum)
    235  1.2.4.2  yamt {
    236  1.2.4.2  yamt 
    237  1.2.4.2  yamt 	bus_space_write_1(sc->sc_bst, sc->sc_bsh, reg, datum);
    238  1.2.4.2  yamt }
    239