mcclock_jensenio.c revision 1.7
1/* $NetBSD: mcclock_jensenio.c,v 1.7 2008/03/28 19:05:49 tsutsui Exp $ */ 2 3/*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39/* 40 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 41 * All rights reserved. 42 * 43 * Author: Chris G. Demetriou 44 * 45 * Permission to use, copy, modify and distribute this software and 46 * its documentation is hereby granted, provided that both the copyright 47 * notice and this permission notice appear in all copies of the 48 * software, derivative works or modified versions, and any portions 49 * thereof, and that both notices appear in supporting documentation. 50 * 51 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 52 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 53 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 54 * 55 * Carnegie Mellon requests users of this software to return to 56 * 57 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 58 * School of Computer Science 59 * Carnegie Mellon University 60 * Pittsburgh PA 15213-3890 61 * 62 * any improvements or extensions that they make and grant Carnegie the 63 * rights to redistribute these changes. 64 */ 65 66#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 67 68__KERNEL_RCSID(0, "$NetBSD: mcclock_jensenio.c,v 1.7 2008/03/28 19:05:49 tsutsui Exp $"); 69 70#include <sys/param.h> 71#include <sys/kernel.h> 72#include <sys/systm.h> 73#include <sys/device.h> 74 75#include <machine/bus.h> 76 77#include <dev/clock_subr.h> 78 79#include <dev/ic/mc146818reg.h> 80#include <dev/ic/mc146818var.h> 81#include <dev/eisa/eisavar.h> 82#include <dev/isa/isavar.h> 83#include <alpha/jensenio/jenseniovar.h> 84#include <alpha/alpha/mcclockvar.h> 85 86struct mcclock_jensenio_softc { 87 struct mc146818_softc sc_mc146818; 88 89 bus_space_handle_t sc_std_rtc_ioh; 90}; 91 92int mcclock_jensenio_match(device_t, cfdata_t, void *); 93void mcclock_jensenio_attach(device_t, device_t, void *); 94 95CFATTACH_DECL_NEW(mcclock_jensenio, sizeof(struct mcclock_jensenio_softc), 96 mcclock_jensenio_match, mcclock_jensenio_attach, NULL, NULL); 97 98void mcclock_jensenio_write(struct mc146818_softc *, u_int, u_int); 99u_int mcclock_jensenio_read(struct mc146818_softc *, u_int); 100 101 102int 103mcclock_jensenio_match(device_t parent, cfdata_t cf, void *aux) 104{ 105 struct jensenio_attach_args *ja = aux; 106 107 /* Always present. */ 108 if (strcmp(ja->ja_name, cf->cf_name) == 0) 109 return (1); 110 111 return (0); 112} 113 114void 115mcclock_jensenio_attach(device_t parent, device_t self, void *aux) 116{ 117 struct mcclock_jensenio_softc *jsc = device_private(self); 118 struct jensenio_attach_args *ja = aux; 119 struct mc146818_softc *sc = &jsc->sc_mc146818; 120 121 sc->sc_bst = ja->ja_iot; 122 if (bus_space_map(sc->sc_bst, ja->ja_ioaddr, 0x02, 0, 123 &sc->sc_bsh)) 124 panic("mcclock_jensenio_attach: couldn't map clock I/O space"); 125 126 /* 127 * Map the I/O space normally used by the ISA RTC (port 0x70) so 128 * as to avoid a false match at that address, as well. 129 */ 130 (void)bus_space_map(sc->sc_bst, 0x70, 0x02, 0, 131 &jsc->sc_std_rtc_ioh); 132 133 sc->sc_mcread = mcclock_jensenio_read; 134 sc->sc_mcwrite = mcclock_jensenio_write; 135 136 mcclock_attach(sc); 137} 138 139void 140mcclock_jensenio_write(struct mc146818_softc *sc, u_int reg, u_int datum) 141{ 142 bus_space_tag_t iot = sc->sc_bst; 143 bus_space_handle_t ioh = sc->sc_bsh; 144 145 bus_space_write_1(iot, ioh, 0, reg); 146 bus_space_write_1(iot, ioh, 1, datum); 147} 148 149u_int 150mcclock_jensenio_read(struct mc146818_softc *sc, u_int reg) 151{ 152 bus_space_tag_t iot = sc->sc_bst; 153 bus_space_handle_t ioh = sc->sc_bsh; 154 155 bus_space_write_1(iot, ioh, 0, reg); 156 return bus_space_read_1(iot, ioh, 1); 157} 158