Home | History | Annotate | Line # | Download | only in pnpbus
mcclock_pnpbus.c revision 1.1.2.2
      1  1.1.2.2  chap /* $NetBSD: mcclock_pnpbus.c,v 1.1.2.2 2006/06/19 03:45:06 chap Exp $ */
      2  1.1.2.2  chap /*-
      3  1.1.2.2  chap  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      4  1.1.2.2  chap  * All rights reserved.
      5  1.1.2.2  chap  *
      6  1.1.2.2  chap  * This code is derived from software contributed to The NetBSD Foundation
      7  1.1.2.2  chap  * by Tim Rightnour
      8  1.1.2.2  chap  *
      9  1.1.2.2  chap  * Redistribution and use in source and binary forms, with or without
     10  1.1.2.2  chap  * modification, are permitted provided that the following conditions
     11  1.1.2.2  chap  * are met:
     12  1.1.2.2  chap  * 1. Redistributions of source code must retain the above copyright
     13  1.1.2.2  chap  *    notice, this list of conditions and the following disclaimer.
     14  1.1.2.2  chap  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1.2.2  chap  *    notice, this list of conditions and the following disclaimer in the
     16  1.1.2.2  chap  *    documentation and/or other materials provided with the distribution.
     17  1.1.2.2  chap  * 3. All advertising materials mentioning features or use of this software
     18  1.1.2.2  chap  *    must display the following acknowledgement:
     19  1.1.2.2  chap  *        This product includes software developed by the NetBSD
     20  1.1.2.2  chap  *        Foundation, Inc. and its contributors.
     21  1.1.2.2  chap  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  1.1.2.2  chap  *    contributors may be used to endorse or promote products derived
     23  1.1.2.2  chap  *    from this software without specific prior written permission.
     24  1.1.2.2  chap  *
     25  1.1.2.2  chap  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  1.1.2.2  chap  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1.2.2  chap  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1.2.2  chap  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  1.1.2.2  chap  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1.2.2  chap  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1.2.2  chap  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1.2.2  chap  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1.2.2  chap  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1.2.2  chap  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1.2.2  chap  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1.2.2  chap  */
     37  1.1.2.2  chap 
     38  1.1.2.2  chap /*
     39  1.1.2.2  chap  * PNPBus driver for the mc146818 compatible time-of-day clock found on all
     40  1.1.2.2  chap  * IBM Prep machines.  This one is only discernable from the motorola clock
     41  1.1.2.2  chap  * part by the interface portion of the residual data. (or by the small vendor
     42  1.1.2.2  chap  * item chip id)
     43  1.1.2.2  chap  * NOTE: The IBM machines actually have either a dallas 1385 or a dallas 1585
     44  1.1.2.2  chap  * chip.  This driver should probably be replaced by something that does that
     45  1.1.2.2  chap  * one day.
     46  1.1.2.2  chap  */
     47  1.1.2.2  chap 
     48  1.1.2.2  chap #include <sys/cdefs.h>
     49  1.1.2.2  chap __KERNEL_RCSID(0, "$NetBSD: mcclock_pnpbus.c,v 1.1.2.2 2006/06/19 03:45:06 chap Exp $");
     50  1.1.2.2  chap 
     51  1.1.2.2  chap #include <sys/types.h>
     52  1.1.2.2  chap #include <sys/param.h>
     53  1.1.2.2  chap #include <sys/systm.h>
     54  1.1.2.2  chap #include <sys/device.h>
     55  1.1.2.2  chap #include <sys/malloc.h>
     56  1.1.2.2  chap 
     57  1.1.2.2  chap #include <machine/bus.h>
     58  1.1.2.2  chap #include <machine/intr.h>
     59  1.1.2.2  chap #include <machine/isa_machdep.h>
     60  1.1.2.2  chap #include <machine/residual.h>
     61  1.1.2.2  chap 
     62  1.1.2.2  chap #include <dev/clock_subr.h>
     63  1.1.2.2  chap #include <dev/ic/mc146818reg.h>
     64  1.1.2.2  chap #include <dev/ic/mc146818var.h>
     65  1.1.2.2  chap 
     66  1.1.2.2  chap #include <dev/isa/isavar.h>
     67  1.1.2.2  chap 
     68  1.1.2.2  chap #include <prep/pnpbus/pnpbusvar.h>
     69  1.1.2.2  chap 
     70  1.1.2.2  chap static int	mcclock_pnpbus_probe(struct device *, struct cfdata *, void *);
     71  1.1.2.2  chap static void	mcclock_pnpbus_attach(struct device *, struct device *, void *);
     72  1.1.2.2  chap 
     73  1.1.2.2  chap CFATTACH_DECL(mcclock_pnpbus, sizeof (struct mc146818_softc),
     74  1.1.2.2  chap     mcclock_pnpbus_probe, mcclock_pnpbus_attach, NULL, NULL);
     75  1.1.2.2  chap 
     76  1.1.2.2  chap void	mcclock_pnpbus_write(struct mc146818_softc *, u_int, u_int);
     77  1.1.2.2  chap u_int	mcclock_pnpbus_read(struct mc146818_softc *, u_int);
     78  1.1.2.2  chap 
     79  1.1.2.2  chap static int
     80  1.1.2.2  chap mcclock_pnpbus_probe(struct device *parent, struct cfdata *match, void *aux)
     81  1.1.2.2  chap {
     82  1.1.2.2  chap 	struct pnpbus_dev_attach_args *pna = aux;
     83  1.1.2.2  chap 	int ret = 0;
     84  1.1.2.2  chap 
     85  1.1.2.2  chap 	if (strcmp(pna->pna_devid, "PNP0B00") == 0 &&
     86  1.1.2.2  chap 	    pna->subtype == RealTimeClock && pna->interface == ISA_RTC)
     87  1.1.2.2  chap 		ret = 1;
     88  1.1.2.2  chap 
     89  1.1.2.2  chap 	if (ret)
     90  1.1.2.2  chap 		pnpbus_scan(pna, pna->pna_ppc_dev);
     91  1.1.2.2  chap 	return ret;
     92  1.1.2.2  chap }
     93  1.1.2.2  chap 
     94  1.1.2.2  chap static void
     95  1.1.2.2  chap mcclock_pnpbus_attach(struct device *parent, struct device *self, void *aux)
     96  1.1.2.2  chap {
     97  1.1.2.2  chap 	struct mc146818_softc *sc = (void *)self;
     98  1.1.2.2  chap 	struct pnpbus_dev_attach_args *pna = aux;
     99  1.1.2.2  chap 
    100  1.1.2.2  chap 	sc->sc_bst = pna->pna_iot;
    101  1.1.2.2  chap 	if (pnpbus_io_map(&pna->pna_res, 0, &sc->sc_bst, &sc->sc_bsh)) {
    102  1.1.2.2  chap 		/* XXX should we panic instead? */
    103  1.1.2.2  chap 		aprint_error("%s: couldn't map clock I/O space",
    104  1.1.2.2  chap 		    device_xname(self));
    105  1.1.2.2  chap 		return;
    106  1.1.2.2  chap 	}
    107  1.1.2.2  chap 
    108  1.1.2.2  chap 	sc->sc_year0 = 1900;
    109  1.1.2.2  chap 	sc->sc_mcread = mcclock_pnpbus_read;
    110  1.1.2.2  chap 	sc->sc_mcwrite = mcclock_pnpbus_write;
    111  1.1.2.2  chap 	sc->sc_flag = MC146818_BCD;
    112  1.1.2.2  chap 	mc146818_attach(sc);
    113  1.1.2.2  chap 
    114  1.1.2.2  chap 	aprint_normal("\n");
    115  1.1.2.2  chap 
    116  1.1.2.2  chap 	(*sc->sc_mcwrite)(sc, MC_REGB, MC_REGB_24HR);
    117  1.1.2.2  chap 	todr_attach(&sc->sc_handle);
    118  1.1.2.2  chap }
    119  1.1.2.2  chap 
    120  1.1.2.2  chap void
    121  1.1.2.2  chap mcclock_pnpbus_write(struct mc146818_softc *sc, u_int reg, u_int datum)
    122  1.1.2.2  chap {
    123  1.1.2.2  chap 	bus_space_tag_t iot;
    124  1.1.2.2  chap 	bus_space_handle_t ioh;
    125  1.1.2.2  chap 
    126  1.1.2.2  chap 	iot = sc->sc_bst;
    127  1.1.2.2  chap 	ioh = sc->sc_bsh;
    128  1.1.2.2  chap 
    129  1.1.2.2  chap 	bus_space_write_1(iot, ioh, 0, reg);
    130  1.1.2.2  chap 	bus_space_write_1(iot, ioh, 1, datum);
    131  1.1.2.2  chap }
    132  1.1.2.2  chap 
    133  1.1.2.2  chap u_int
    134  1.1.2.2  chap mcclock_pnpbus_read(struct mc146818_softc *sc, u_int reg)
    135  1.1.2.2  chap {
    136  1.1.2.2  chap 	bus_space_tag_t iot;
    137  1.1.2.2  chap 	bus_space_handle_t ioh;
    138  1.1.2.2  chap 	u_int datum;
    139  1.1.2.2  chap 
    140  1.1.2.2  chap 	iot = sc->sc_bst;
    141  1.1.2.2  chap 	ioh = sc->sc_bsh;
    142  1.1.2.2  chap 
    143  1.1.2.2  chap 	bus_space_write_1(iot, ioh, 0, reg);
    144  1.1.2.2  chap 	datum = bus_space_read_1(iot, ioh, 1);
    145  1.1.2.2  chap 
    146  1.1.2.2  chap 	return (datum);
    147  1.1.2.2  chap }
    148