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