mcclock_jensenio.c revision 1.8
11.8Stsutsui/* $NetBSD: mcclock_jensenio.c,v 1.8 2008/03/29 05:42:45 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.8Stsutsui__KERNEL_RCSID(0, "$NetBSD: mcclock_jensenio.c,v 1.8 2008/03/29 05:42:45 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.7Stsutsuiint mcclock_jensenio_match(device_t, cfdata_t, void *); 931.7Stsutsuivoid mcclock_jensenio_attach(device_t, device_t, void *); 941.1Sthorpej 951.7StsutsuiCFATTACH_DECL_NEW(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.7Stsutsuimcclock_jensenio_match(device_t parent, cfdata_t cf, void *aux) 1041.1Sthorpej{ 1051.1Sthorpej struct jensenio_attach_args *ja = aux; 1061.1Sthorpej 1071.1Sthorpej /* Always present. */ 1081.7Stsutsui if (strcmp(ja->ja_name, cf->cf_name) == 0) 1091.1Sthorpej return (1); 1101.1Sthorpej 1111.1Sthorpej return (0); 1121.1Sthorpej} 1131.1Sthorpej 1141.1Sthorpejvoid 1151.7Stsutsuimcclock_jensenio_attach(device_t parent, device_t self, void *aux) 1161.1Sthorpej{ 1171.7Stsutsui struct mcclock_jensenio_softc *jsc = device_private(self); 1181.1Sthorpej struct jensenio_attach_args *ja = aux; 1191.5Stsutsui struct mc146818_softc *sc = &jsc->sc_mc146818; 1201.1Sthorpej 1211.8Stsutsui sc->sc_dev = self; 1221.5Stsutsui sc->sc_bst = ja->ja_iot; 1231.5Stsutsui if (bus_space_map(sc->sc_bst, ja->ja_ioaddr, 0x02, 0, 1241.5Stsutsui &sc->sc_bsh)) 1251.1Sthorpej panic("mcclock_jensenio_attach: couldn't map clock I/O space"); 1261.1Sthorpej 1271.1Sthorpej /* 1281.1Sthorpej * Map the I/O space normally used by the ISA RTC (port 0x70) so 1291.1Sthorpej * as to avoid a false match at that address, as well. 1301.1Sthorpej */ 1311.5Stsutsui (void)bus_space_map(sc->sc_bst, 0x70, 0x02, 0, 1321.5Stsutsui &jsc->sc_std_rtc_ioh); 1331.5Stsutsui 1341.5Stsutsui sc->sc_mcread = mcclock_jensenio_read; 1351.5Stsutsui sc->sc_mcwrite = mcclock_jensenio_write; 1361.1Sthorpej 1371.5Stsutsui mcclock_attach(sc); 1381.1Sthorpej} 1391.1Sthorpej 1401.1Sthorpejvoid 1411.5Stsutsuimcclock_jensenio_write(struct mc146818_softc *sc, u_int reg, u_int datum) 1421.1Sthorpej{ 1431.5Stsutsui bus_space_tag_t iot = sc->sc_bst; 1441.5Stsutsui bus_space_handle_t ioh = sc->sc_bsh; 1451.1Sthorpej 1461.1Sthorpej bus_space_write_1(iot, ioh, 0, reg); 1471.1Sthorpej bus_space_write_1(iot, ioh, 1, datum); 1481.1Sthorpej} 1491.1Sthorpej 1501.1Sthorpeju_int 1511.5Stsutsuimcclock_jensenio_read(struct mc146818_softc *sc, u_int reg) 1521.1Sthorpej{ 1531.5Stsutsui bus_space_tag_t iot = sc->sc_bst; 1541.5Stsutsui bus_space_handle_t ioh = sc->sc_bsh; 1551.1Sthorpej 1561.1Sthorpej bus_space_write_1(iot, ioh, 0, reg); 1571.1Sthorpej return bus_space_read_1(iot, ioh, 1); 1581.1Sthorpej} 159