Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.1.4.2
      1  1.1.4.2  ad /*	$NetBSD: mcclock_isa.c,v 1.1.4.2 2006/11/18 21:29:30 ad Exp $	*/
      2  1.1.4.2  ad 
      3  1.1.4.2  ad /*-
      4  1.1.4.2  ad  * Copyright (c) 1990 The Regents of the University of California.
      5  1.1.4.2  ad  * All rights reserved.
      6  1.1.4.2  ad  *
      7  1.1.4.2  ad  * This code is derived from software contributed to Berkeley by
      8  1.1.4.2  ad  * William Jolitz and Don Ahn.
      9  1.1.4.2  ad  *
     10  1.1.4.2  ad  * Redistribution and use in source and binary forms, with or without
     11  1.1.4.2  ad  * modification, are permitted provided that the following conditions
     12  1.1.4.2  ad  * are met:
     13  1.1.4.2  ad  * 1. Redistributions of source code must retain the above copyright
     14  1.1.4.2  ad  *    notice, this list of conditions and the following disclaimer.
     15  1.1.4.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.4.2  ad  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.4.2  ad  *    documentation and/or other materials provided with the distribution.
     18  1.1.4.2  ad  * 3. Neither the name of the University nor the names of its contributors
     19  1.1.4.2  ad  *    may be used to endorse or promote products derived from this software
     20  1.1.4.2  ad  *    without specific prior written permission.
     21  1.1.4.2  ad  *
     22  1.1.4.2  ad  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.1.4.2  ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1.4.2  ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1.4.2  ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.1.4.2  ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1.4.2  ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1.4.2  ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1.4.2  ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1.4.2  ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1.4.2  ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1.4.2  ad  * SUCH DAMAGE.
     33  1.1.4.2  ad  *
     34  1.1.4.2  ad  *	@(#)clock.c	7.2 (Berkeley) 5/12/91
     35  1.1.4.2  ad  */
     36  1.1.4.2  ad /*-
     37  1.1.4.2  ad  * Copyright (c) 1993, 1994 Charles M. Hannum.
     38  1.1.4.2  ad  *
     39  1.1.4.2  ad  * This code is derived from software contributed to Berkeley by
     40  1.1.4.2  ad  * William Jolitz and Don Ahn.
     41  1.1.4.2  ad  *
     42  1.1.4.2  ad  * Redistribution and use in source and binary forms, with or without
     43  1.1.4.2  ad  * modification, are permitted provided that the following conditions
     44  1.1.4.2  ad  * are met:
     45  1.1.4.2  ad  * 1. Redistributions of source code must retain the above copyright
     46  1.1.4.2  ad  *    notice, this list of conditions and the following disclaimer.
     47  1.1.4.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     48  1.1.4.2  ad  *    notice, this list of conditions and the following disclaimer in the
     49  1.1.4.2  ad  *    documentation and/or other materials provided with the distribution.
     50  1.1.4.2  ad  * 3. All advertising materials mentioning features or use of this software
     51  1.1.4.2  ad  *    must display the following acknowledgement:
     52  1.1.4.2  ad  *	This product includes software developed by the University of
     53  1.1.4.2  ad  *	California, Berkeley and its contributors.
     54  1.1.4.2  ad  * 4. Neither the name of the University nor the names of its contributors
     55  1.1.4.2  ad  *    may be used to endorse or promote products derived from this software
     56  1.1.4.2  ad  *    without specific prior written permission.
     57  1.1.4.2  ad  *
     58  1.1.4.2  ad  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  1.1.4.2  ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  1.1.4.2  ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  1.1.4.2  ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  1.1.4.2  ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  1.1.4.2  ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  1.1.4.2  ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  1.1.4.2  ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  1.1.4.2  ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  1.1.4.2  ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  1.1.4.2  ad  * SUCH DAMAGE.
     69  1.1.4.2  ad  *
     70  1.1.4.2  ad  *	@(#)clock.c	7.2 (Berkeley) 5/12/91
     71  1.1.4.2  ad  */
     72  1.1.4.2  ad /*
     73  1.1.4.2  ad  * Mach Operating System
     74  1.1.4.2  ad  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
     75  1.1.4.2  ad  * All Rights Reserved.
     76  1.1.4.2  ad  *
     77  1.1.4.2  ad  * Permission to use, copy, modify and distribute this software and its
     78  1.1.4.2  ad  * documentation is hereby granted, provided that both the copyright
     79  1.1.4.2  ad  * notice and this permission notice appear in all copies of the
     80  1.1.4.2  ad  * software, derivative works or modified versions, and any portions
     81  1.1.4.2  ad  * thereof, and that both notices appear in supporting documentation.
     82  1.1.4.2  ad  *
     83  1.1.4.2  ad  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     84  1.1.4.2  ad  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     85  1.1.4.2  ad  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     86  1.1.4.2  ad  *
     87  1.1.4.2  ad  * Carnegie Mellon requests users of this software to return to
     88  1.1.4.2  ad  *
     89  1.1.4.2  ad  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     90  1.1.4.2  ad  *  School of Computer Science
     91  1.1.4.2  ad  *  Carnegie Mellon University
     92  1.1.4.2  ad  *  Pittsburgh PA 15213-3890
     93  1.1.4.2  ad  *
     94  1.1.4.2  ad  * any improvements or extensions that they make and grant Carnegie Mellon
     95  1.1.4.2  ad  * the rights to redistribute these changes.
     96  1.1.4.2  ad  */
     97  1.1.4.2  ad /*
     98  1.1.4.2  ad   Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
     99  1.1.4.2  ad 
    100  1.1.4.2  ad 		All Rights Reserved
    101  1.1.4.2  ad 
    102  1.1.4.2  ad Permission to use, copy, modify, and distribute this software and
    103  1.1.4.2  ad its documentation for any purpose and without fee is hereby
    104  1.1.4.2  ad granted, provided that the above copyright notice appears in all
    105  1.1.4.2  ad copies and that both the copyright notice and this permission notice
    106  1.1.4.2  ad appear in supporting documentation, and that the name of Intel
    107  1.1.4.2  ad not be used in advertising or publicity pertaining to distribution
    108  1.1.4.2  ad of the software without specific, written prior permission.
    109  1.1.4.2  ad 
    110  1.1.4.2  ad INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
    111  1.1.4.2  ad INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
    112  1.1.4.2  ad IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
    113  1.1.4.2  ad CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    114  1.1.4.2  ad LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
    115  1.1.4.2  ad NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
    116  1.1.4.2  ad WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    117  1.1.4.2  ad */
    118  1.1.4.2  ad 
    119  1.1.4.2  ad #include <sys/cdefs.h>
    120  1.1.4.2  ad __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.1.4.2 2006/11/18 21:29:30 ad Exp $");
    121  1.1.4.2  ad 
    122  1.1.4.2  ad #include <sys/param.h>
    123  1.1.4.2  ad #include <sys/systm.h>
    124  1.1.4.2  ad #include <sys/kernel.h>
    125  1.1.4.2  ad #include <sys/device.h>
    126  1.1.4.2  ad #include <sys/time.h>
    127  1.1.4.2  ad 
    128  1.1.4.2  ad #include <machine/bus.h>
    129  1.1.4.2  ad 
    130  1.1.4.2  ad #include <dev/clock_subr.h>
    131  1.1.4.2  ad #include <dev/isa/isareg.h>
    132  1.1.4.2  ad #include <dev/isa/isavar.h>
    133  1.1.4.2  ad #include <dev/ic/mc146818reg.h>
    134  1.1.4.2  ad #include <dev/ic/mc146818var.h>
    135  1.1.4.2  ad 
    136  1.1.4.2  ad /*
    137  1.1.4.2  ad  * We only deal with the RTC portion of the mc146818 right now.  Later
    138  1.1.4.2  ad  * we might want to add support for the NVRAM portion, since it
    139  1.1.4.2  ad  * appears that some systems use that.
    140  1.1.4.2  ad  */
    141  1.1.4.2  ad 
    142  1.1.4.2  ad static int mcclock_isa_probe(struct device *, struct cfdata *, void *);
    143  1.1.4.2  ad static void mcclock_isa_attach(struct device *, struct device *, void *);
    144  1.1.4.2  ad 
    145  1.1.4.2  ad CFATTACH_DECL(mcclock_isa, sizeof(struct mc146818_softc),
    146  1.1.4.2  ad     mcclock_isa_probe, mcclock_isa_attach, NULL, NULL);
    147  1.1.4.2  ad 
    148  1.1.4.2  ad static unsigned
    149  1.1.4.2  ad mcclock_isa_read(struct mc146818_softc *sc, unsigned reg)
    150  1.1.4.2  ad {
    151  1.1.4.2  ad 
    152  1.1.4.2  ad 	bus_space_write_1(sc->sc_bst, sc->sc_bsh, 0, reg);
    153  1.1.4.2  ad 	return bus_space_read_1(sc->sc_bst, sc->sc_bsh, 1);
    154  1.1.4.2  ad }
    155  1.1.4.2  ad 
    156  1.1.4.2  ad static void
    157  1.1.4.2  ad mcclock_isa_write(struct mc146818_softc *sc, unsigned reg, unsigned datum)
    158  1.1.4.2  ad {
    159  1.1.4.2  ad 
    160  1.1.4.2  ad 	bus_space_write_1(sc->sc_bst, sc->sc_bsh, 0, reg);
    161  1.1.4.2  ad 	bus_space_write_1(sc->sc_bst, sc->sc_bsh, 1, datum);
    162  1.1.4.2  ad }
    163  1.1.4.2  ad 
    164  1.1.4.2  ad int
    165  1.1.4.2  ad mcclock_isa_probe(struct device *parent, struct cfdata *match, void *aux)
    166  1.1.4.2  ad {
    167  1.1.4.2  ad 	struct isa_attach_args *ia = aux;
    168  1.1.4.2  ad 	bus_space_handle_t ioh;
    169  1.1.4.2  ad 
    170  1.1.4.2  ad 	if (ia->ia_nio < 1)
    171  1.1.4.2  ad 		return 0;
    172  1.1.4.2  ad 
    173  1.1.4.2  ad 	if (ISA_DIRECT_CONFIG(ia))
    174  1.1.4.2  ad 		return 0;
    175  1.1.4.2  ad 
    176  1.1.4.2  ad 	if ((ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT) &&
    177  1.1.4.2  ad 	    (ia->ia_io[0].ir_addr != IO_RTC))
    178  1.1.4.2  ad 		return 0;
    179  1.1.4.2  ad 
    180  1.1.4.2  ad 	if (ia->ia_niomem > 0 &&
    181  1.1.4.2  ad 	    (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
    182  1.1.4.2  ad 		return 0;
    183  1.1.4.2  ad 
    184  1.1.4.2  ad 	if (ia->ia_nirq > 0 &&
    185  1.1.4.2  ad 	    (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
    186  1.1.4.2  ad 		return 0;
    187  1.1.4.2  ad 
    188  1.1.4.2  ad 	if (ia->ia_ndrq > 0 &&
    189  1.1.4.2  ad 	    (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
    190  1.1.4.2  ad 		return 0;
    191  1.1.4.2  ad 
    192  1.1.4.2  ad 	if (bus_space_map(ia->ia_iot, IO_RTC, 2, 0, &ioh))
    193  1.1.4.2  ad 		return 0;
    194  1.1.4.2  ad 	bus_space_unmap(ia->ia_iot, ioh, 2);
    195  1.1.4.2  ad 
    196  1.1.4.2  ad 	ia->ia_io[0].ir_addr = IO_RTC;
    197  1.1.4.2  ad 	ia->ia_io[0].ir_size = 2;
    198  1.1.4.2  ad 	ia->ia_nio = 1;
    199  1.1.4.2  ad 
    200  1.1.4.2  ad 	ia->ia_niomem = 0;
    201  1.1.4.2  ad 	ia->ia_nirq = 0;
    202  1.1.4.2  ad 	ia->ia_ndrq = 0;
    203  1.1.4.2  ad 
    204  1.1.4.2  ad 	return 1;
    205  1.1.4.2  ad }
    206  1.1.4.2  ad 
    207  1.1.4.2  ad void
    208  1.1.4.2  ad mcclock_isa_attach(struct device *parent, struct device *self, void *aux)
    209  1.1.4.2  ad {
    210  1.1.4.2  ad 	struct mc146818_softc *sc = (struct mc146818_softc *)self;
    211  1.1.4.2  ad 	struct isa_attach_args *ia = aux;
    212  1.1.4.2  ad 
    213  1.1.4.2  ad 	sc->sc_bst = ia->ia_iot;
    214  1.1.4.2  ad 	if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
    215  1.1.4.2  ad 		ia->ia_io[0].ir_size, 0, &sc->sc_bsh)) {
    216  1.1.4.2  ad 		printf(": can't map registers!\n");
    217  1.1.4.2  ad 		return;
    218  1.1.4.2  ad 	}
    219  1.1.4.2  ad 
    220  1.1.4.2  ad 	/*
    221  1.1.4.2  ad 	 * Select a 32KHz crystal, periodic interrupt every 1024 Hz.
    222  1.1.4.2  ad 	 * XXX: We disable periodic interrupts, so why set a rate?
    223  1.1.4.2  ad 	 */
    224  1.1.4.2  ad 	mcclock_isa_write(sc, MC_REGA, MC_BASE_32_KHz | MC_RATE_1024_Hz);
    225  1.1.4.2  ad 
    226  1.1.4.2  ad 	/*
    227  1.1.4.2  ad 	 * 24 Hour clock, no interrupts please.
    228  1.1.4.2  ad 	 */
    229  1.1.4.2  ad 	mcclock_isa_write(sc, MC_REGB, MC_REGB_24HR);
    230  1.1.4.2  ad 
    231  1.1.4.2  ad 	sc->sc_year0 = 1900;
    232  1.1.4.2  ad 	sc->sc_flag = 0;
    233  1.1.4.2  ad 	sc->sc_mcread = mcclock_isa_read;
    234  1.1.4.2  ad 	sc->sc_mcwrite = mcclock_isa_write;
    235  1.1.4.2  ad #if 0
    236  1.1.4.2  ad 	/*
    237  1.1.4.2  ad 	 * XXX: perhaps on some systems we should manage the century byte?
    238  1.1.4.2  ad 	 * For now we don't worry about it.  (Ugly MD code.)
    239  1.1.4.2  ad 	 */
    240  1.1.4.2  ad 	sc->sc_getcent = mcclock_isa_getcent;
    241  1.1.4.2  ad 	sc->sc_setcent = mcclock_isa_setcent;
    242  1.1.4.2  ad #endif
    243  1.1.4.2  ad 	mc146818_attach(sc);
    244  1.1.4.2  ad 	printf("\n");
    245  1.1.4.2  ad 
    246  1.1.4.2  ad 	todr_attach(&sc->sc_handle);
    247  1.1.4.2  ad }
    248