mcclock_jensenio.c revision 1.11
11.11Sthorpej/* $NetBSD: mcclock_jensenio.c,v 1.11 2021/05/07 16:58:34 thorpej 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 * 191.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 301.1Sthorpej */ 311.1Sthorpej 321.1Sthorpej/* 331.1Sthorpej * Copyright (c) 1995, 1996 Carnegie-Mellon University. 341.1Sthorpej * All rights reserved. 351.1Sthorpej * 361.1Sthorpej * Author: Chris G. Demetriou 371.1Sthorpej * 381.1Sthorpej * Permission to use, copy, modify and distribute this software and 391.1Sthorpej * its documentation is hereby granted, provided that both the copyright 401.1Sthorpej * notice and this permission notice appear in all copies of the 411.1Sthorpej * software, derivative works or modified versions, and any portions 421.1Sthorpej * thereof, and that both notices appear in supporting documentation. 431.1Sthorpej * 441.1Sthorpej * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 451.1Sthorpej * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 461.1Sthorpej * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 471.1Sthorpej * 481.1Sthorpej * Carnegie Mellon requests users of this software to return to 491.1Sthorpej * 501.1Sthorpej * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 511.1Sthorpej * School of Computer Science 521.1Sthorpej * Carnegie Mellon University 531.1Sthorpej * Pittsburgh PA 15213-3890 541.1Sthorpej * 551.1Sthorpej * any improvements or extensions that they make and grant Carnegie the 561.1Sthorpej * rights to redistribute these changes. 571.1Sthorpej */ 581.1Sthorpej 591.1Sthorpej#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 601.1Sthorpej 611.11Sthorpej__KERNEL_RCSID(0, "$NetBSD: mcclock_jensenio.c,v 1.11 2021/05/07 16:58:34 thorpej Exp $"); 621.1Sthorpej 631.1Sthorpej#include <sys/param.h> 641.1Sthorpej#include <sys/kernel.h> 651.1Sthorpej#include <sys/systm.h> 661.1Sthorpej#include <sys/device.h> 671.1Sthorpej 681.10Sdyoung#include <sys/bus.h> 691.1Sthorpej 701.5Stsutsui#include <dev/clock_subr.h> 711.5Stsutsui 721.1Sthorpej#include <dev/ic/mc146818reg.h> 731.5Stsutsui#include <dev/ic/mc146818var.h> 741.1Sthorpej#include <dev/eisa/eisavar.h> 751.1Sthorpej#include <dev/isa/isavar.h> 761.1Sthorpej#include <alpha/jensenio/jenseniovar.h> 771.5Stsutsui#include <alpha/alpha/mcclockvar.h> 781.1Sthorpej 791.1Sthorpejstruct mcclock_jensenio_softc { 801.5Stsutsui struct mc146818_softc sc_mc146818; 811.1Sthorpej 821.1Sthorpej bus_space_handle_t sc_std_rtc_ioh; 831.1Sthorpej}; 841.1Sthorpej 851.11Sthorpejstatic int mcclock_jensenio_match(device_t, cfdata_t, void *); 861.11Sthorpejstatic void mcclock_jensenio_attach(device_t, device_t, void *); 871.1Sthorpej 881.7StsutsuiCFATTACH_DECL_NEW(mcclock_jensenio, sizeof(struct mcclock_jensenio_softc), 891.4Sthorpej mcclock_jensenio_match, mcclock_jensenio_attach, NULL, NULL); 901.1Sthorpej 911.11Sthorpejstatic void mcclock_jensenio_write(struct mc146818_softc *, u_int, u_int); 921.11Sthorpejstatic u_int mcclock_jensenio_read(struct mc146818_softc *, u_int); 931.1Sthorpej 941.1Sthorpej 951.11Sthorpejstatic int 961.7Stsutsuimcclock_jensenio_match(device_t parent, cfdata_t cf, void *aux) 971.1Sthorpej{ 981.1Sthorpej struct jensenio_attach_args *ja = aux; 991.1Sthorpej 1001.1Sthorpej /* Always present. */ 1011.7Stsutsui if (strcmp(ja->ja_name, cf->cf_name) == 0) 1021.1Sthorpej return (1); 1031.1Sthorpej 1041.1Sthorpej return (0); 1051.1Sthorpej} 1061.1Sthorpej 1071.11Sthorpejstatic void 1081.7Stsutsuimcclock_jensenio_attach(device_t parent, device_t self, void *aux) 1091.1Sthorpej{ 1101.7Stsutsui struct mcclock_jensenio_softc *jsc = device_private(self); 1111.1Sthorpej struct jensenio_attach_args *ja = aux; 1121.5Stsutsui struct mc146818_softc *sc = &jsc->sc_mc146818; 1131.1Sthorpej 1141.8Stsutsui sc->sc_dev = self; 1151.5Stsutsui sc->sc_bst = ja->ja_iot; 1161.5Stsutsui if (bus_space_map(sc->sc_bst, ja->ja_ioaddr, 0x02, 0, 1171.5Stsutsui &sc->sc_bsh)) 1181.1Sthorpej panic("mcclock_jensenio_attach: couldn't map clock I/O space"); 1191.1Sthorpej 1201.1Sthorpej /* 1211.1Sthorpej * Map the I/O space normally used by the ISA RTC (port 0x70) so 1221.1Sthorpej * as to avoid a false match at that address, as well. 1231.1Sthorpej */ 1241.5Stsutsui (void)bus_space_map(sc->sc_bst, 0x70, 0x02, 0, 1251.5Stsutsui &jsc->sc_std_rtc_ioh); 1261.5Stsutsui 1271.5Stsutsui sc->sc_mcread = mcclock_jensenio_read; 1281.5Stsutsui sc->sc_mcwrite = mcclock_jensenio_write; 1291.1Sthorpej 1301.5Stsutsui mcclock_attach(sc); 1311.1Sthorpej} 1321.1Sthorpej 1331.11Sthorpejstatic void 1341.5Stsutsuimcclock_jensenio_write(struct mc146818_softc *sc, u_int reg, u_int datum) 1351.1Sthorpej{ 1361.5Stsutsui bus_space_tag_t iot = sc->sc_bst; 1371.5Stsutsui bus_space_handle_t ioh = sc->sc_bsh; 1381.1Sthorpej 1391.1Sthorpej bus_space_write_1(iot, ioh, 0, reg); 1401.1Sthorpej bus_space_write_1(iot, ioh, 1, datum); 1411.1Sthorpej} 1421.1Sthorpej 1431.11Sthorpejstatic u_int 1441.5Stsutsuimcclock_jensenio_read(struct mc146818_softc *sc, u_int reg) 1451.1Sthorpej{ 1461.5Stsutsui bus_space_tag_t iot = sc->sc_bst; 1471.5Stsutsui bus_space_handle_t ioh = sc->sc_bsh; 1481.1Sthorpej 1491.1Sthorpej bus_space_write_1(iot, ioh, 0, reg); 1501.1Sthorpej return bus_space_read_1(iot, ioh, 1); 1511.1Sthorpej} 152