mcclock_jensenio.c revision 1.5
11.5Stsutsui/* $NetBSD: mcclock_jensenio.c,v 1.5 2007/07/21 11:59:57 tsutsui Exp $ */ 21.1Sthorpej 31.1Sthorpej/*- 41.1Sthorpej * Copyright (c) 1999 The NetBSD Foundation, Inc. 51.1Sthorpej * All rights reserved. 61.1Sthorpej * 71.1Sthorpej * This code is derived from software contributed to The NetBSD Foundation 81.1Sthorpej * by Jason R. Thorpe. 91.1Sthorpej * 101.1Sthorpej * Redistribution and use in source and binary forms, with or without 111.1Sthorpej * modification, are permitted provided that the following conditions 121.1Sthorpej * are met: 131.1Sthorpej * 1. Redistributions of source code must retain the above copyright 141.1Sthorpej * notice, this list of conditions and the following disclaimer. 151.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 161.1Sthorpej * notice, this list of conditions and the following disclaimer in the 171.1Sthorpej * documentation and/or other materials provided with the distribution. 181.1Sthorpej * 3. All advertising materials mentioning features or use of this software 191.1Sthorpej * must display the following acknowledgement: 201.1Sthorpej * This product includes software developed by the NetBSD 211.1Sthorpej * Foundation, Inc. and its contributors. 221.1Sthorpej * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Sthorpej * contributors may be used to endorse or promote products derived 241.1Sthorpej * from this software without specific prior written permission. 251.1Sthorpej * 261.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 371.1Sthorpej */ 381.1Sthorpej 391.1Sthorpej/* 401.1Sthorpej * Copyright (c) 1995, 1996 Carnegie-Mellon University. 411.1Sthorpej * All rights reserved. 421.1Sthorpej * 431.1Sthorpej * Author: Chris G. Demetriou 441.1Sthorpej * 451.1Sthorpej * Permission to use, copy, modify and distribute this software and 461.1Sthorpej * its documentation is hereby granted, provided that both the copyright 471.1Sthorpej * notice and this permission notice appear in all copies of the 481.1Sthorpej * software, derivative works or modified versions, and any portions 491.1Sthorpej * thereof, and that both notices appear in supporting documentation. 501.1Sthorpej * 511.1Sthorpej * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 521.1Sthorpej * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 531.1Sthorpej * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 541.1Sthorpej * 551.1Sthorpej * Carnegie Mellon requests users of this software to return to 561.1Sthorpej * 571.1Sthorpej * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 581.1Sthorpej * School of Computer Science 591.1Sthorpej * Carnegie Mellon University 601.1Sthorpej * Pittsburgh PA 15213-3890 611.1Sthorpej * 621.1Sthorpej * any improvements or extensions that they make and grant Carnegie the 631.1Sthorpej * rights to redistribute these changes. 641.1Sthorpej */ 651.1Sthorpej 661.1Sthorpej#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 671.1Sthorpej 681.5Stsutsui__KERNEL_RCSID(0, "$NetBSD: mcclock_jensenio.c,v 1.5 2007/07/21 11:59:57 tsutsui Exp $"); 691.1Sthorpej 701.1Sthorpej#include <sys/param.h> 711.1Sthorpej#include <sys/kernel.h> 721.1Sthorpej#include <sys/systm.h> 731.1Sthorpej#include <sys/device.h> 741.1Sthorpej 751.1Sthorpej#include <machine/bus.h> 761.1Sthorpej 771.5Stsutsui#include <dev/clock_subr.h> 781.5Stsutsui 791.1Sthorpej#include <dev/ic/mc146818reg.h> 801.5Stsutsui#include <dev/ic/mc146818var.h> 811.1Sthorpej#include <dev/eisa/eisavar.h> 821.1Sthorpej#include <dev/isa/isavar.h> 831.1Sthorpej#include <alpha/jensenio/jenseniovar.h> 841.5Stsutsui#include <alpha/alpha/mcclockvar.h> 851.1Sthorpej 861.1Sthorpejstruct mcclock_jensenio_softc { 871.5Stsutsui struct mc146818_softc sc_mc146818; 881.1Sthorpej 891.1Sthorpej bus_space_handle_t sc_std_rtc_ioh; 901.1Sthorpej}; 911.1Sthorpej 921.1Sthorpejint mcclock_jensenio_match(struct device *, struct cfdata *, void *); 931.1Sthorpejvoid mcclock_jensenio_attach(struct device *, struct device *, void *); 941.1Sthorpej 951.4SthorpejCFATTACH_DECL(mcclock_jensenio, sizeof (struct mcclock_jensenio_softc), 961.4Sthorpej mcclock_jensenio_match, mcclock_jensenio_attach, NULL, NULL); 971.1Sthorpej 981.5Stsutsuivoid mcclock_jensenio_write(struct mc146818_softc *, u_int, u_int); 991.5Stsutsuiu_int mcclock_jensenio_read(struct mc146818_softc *, u_int); 1001.1Sthorpej 1011.1Sthorpej 1021.1Sthorpejint 1031.1Sthorpejmcclock_jensenio_match(struct device *parent, struct cfdata *match, void *aux) 1041.1Sthorpej{ 1051.1Sthorpej struct jensenio_attach_args *ja = aux; 1061.1Sthorpej 1071.1Sthorpej /* Always present. */ 1081.2Sthorpej if (strcmp(ja->ja_name, match->cf_name) == 0) 1091.1Sthorpej return (1); 1101.1Sthorpej 1111.1Sthorpej return (0); 1121.1Sthorpej} 1131.1Sthorpej 1141.1Sthorpejvoid 1151.1Sthorpejmcclock_jensenio_attach(struct device *parent, struct device *self, void *aux) 1161.1Sthorpej{ 1171.1Sthorpej struct jensenio_attach_args *ja = aux; 1181.5Stsutsui struct mcclock_jensenio_softc *jsc = (void *)self; 1191.5Stsutsui struct mc146818_softc *sc = &jsc->sc_mc146818; 1201.1Sthorpej 1211.5Stsutsui sc->sc_bst = ja->ja_iot; 1221.5Stsutsui if (bus_space_map(sc->sc_bst, ja->ja_ioaddr, 0x02, 0, 1231.5Stsutsui &sc->sc_bsh)) 1241.1Sthorpej panic("mcclock_jensenio_attach: couldn't map clock I/O space"); 1251.1Sthorpej 1261.1Sthorpej /* 1271.1Sthorpej * Map the I/O space normally used by the ISA RTC (port 0x70) so 1281.1Sthorpej * as to avoid a false match at that address, as well. 1291.1Sthorpej */ 1301.5Stsutsui (void)bus_space_map(sc->sc_bst, 0x70, 0x02, 0, 1311.5Stsutsui &jsc->sc_std_rtc_ioh); 1321.5Stsutsui 1331.5Stsutsui sc->sc_mcread = mcclock_jensenio_read; 1341.5Stsutsui sc->sc_mcwrite = mcclock_jensenio_write; 1351.1Sthorpej 1361.5Stsutsui mcclock_attach(sc); 1371.1Sthorpej} 1381.1Sthorpej 1391.1Sthorpejvoid 1401.5Stsutsuimcclock_jensenio_write(struct mc146818_softc *sc, u_int reg, u_int datum) 1411.1Sthorpej{ 1421.5Stsutsui bus_space_tag_t iot = sc->sc_bst; 1431.5Stsutsui bus_space_handle_t ioh = sc->sc_bsh; 1441.1Sthorpej 1451.1Sthorpej bus_space_write_1(iot, ioh, 0, reg); 1461.1Sthorpej bus_space_write_1(iot, ioh, 1, datum); 1471.1Sthorpej} 1481.1Sthorpej 1491.1Sthorpeju_int 1501.5Stsutsuimcclock_jensenio_read(struct mc146818_softc *sc, u_int reg) 1511.1Sthorpej{ 1521.5Stsutsui bus_space_tag_t iot = sc->sc_bst; 1531.5Stsutsui bus_space_handle_t ioh = sc->sc_bsh; 1541.1Sthorpej 1551.1Sthorpej bus_space_write_1(iot, ioh, 0, reg); 1561.1Sthorpej return bus_space_read_1(iot, ioh, 1); 1571.1Sthorpej} 158