mcclock_gbus.c revision 1.3
1/* $NetBSD: mcclock_gbus.c,v 1.3 2024/03/06 05:44:44 thorpej Exp $ */ 2 3/* 4 * Copyright (c) 1997 by Matthew Jacob 5 * NASA AMES Research Center. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice immediately at the beginning of the file, without modification, 13 * 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. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 34 35__KERNEL_RCSID(0, "$NetBSD: mcclock_gbus.c,v 1.3 2024/03/06 05:44:44 thorpej Exp $"); 36 37#include <sys/param.h> 38#include <sys/kernel.h> 39#include <sys/systm.h> 40#include <sys/device.h> 41 42#include <sys/bus.h> 43 44#include <alpha/gbus/gbusvar.h> 45 46#include <dev/clock_subr.h> 47 48#include <dev/ic/mc146818reg.h> 49#include <dev/ic/mc146818var.h> 50 51#include <alpha/alpha/mcclockvar.h> 52 53#include "ioconf.h" 54 55static int mcclock_gbus_match(device_t, cfdata_t, void *); 56static void mcclock_gbus_attach(device_t, device_t, void *); 57 58CFATTACH_DECL_NEW(mcclock_gbus, sizeof(struct mc146818_softc), 59 mcclock_gbus_match, mcclock_gbus_attach, NULL, NULL); 60 61static void mcclock_gbus_write(struct mc146818_softc *, u_int, u_int); 62static u_int mcclock_gbus_read(struct mc146818_softc *, u_int); 63 64static int 65mcclock_gbus_match(device_t parent, cfdata_t cf, void *aux) 66{ 67 struct gbus_attach_args *ga = aux; 68 69 if (strcmp(ga->ga_name, mcclock_cd.cd_name)) 70 return (0); 71 return (1); 72} 73 74static void 75mcclock_gbus_attach(device_t parent, device_t self, void *aux) 76{ 77 struct mc146818_softc *sc = device_private(self); 78 struct gbus_attach_args *ga = aux; 79 80 sc->sc_dev = self; 81 sc->sc_bst = ga->ga_iot; 82 83 if (bus_space_map(sc->sc_bst, ga->ga_offset, MC_NREGS+MC_NVRAM_SIZE, 84 0, &sc->sc_bsh) != 0) { 85 panic("mcclock_gbus_attach: couldn't map clock I/O space"); 86 } 87 88 sc->sc_mcread = mcclock_gbus_read; 89 sc->sc_mcwrite = mcclock_gbus_write; 90 91 mcclock_attach(sc); 92} 93 94static void 95mcclock_gbus_write(struct mc146818_softc *sc, u_int reg, u_int val) 96{ 97 bus_space_write_1(sc->sc_bst, sc->sc_bsh, reg, (uint8_t)val); 98} 99 100static u_int 101mcclock_gbus_read(struct mc146818_softc *sc, u_int reg) 102{ 103 return bus_space_read_1(sc->sc_bst, sc->sc_bsh, reg); 104} 105