mcclock_gbus.c revision 1.1
11.1Sthorpej/* $NetBSD: mcclock_gbus.c,v 1.1 2024/03/02 19:57:57 thorpej Exp $ */ 21.1Sthorpej 31.1Sthorpej/* 41.1Sthorpej * Copyright (c) 1997 by Matthew Jacob 51.1Sthorpej * NASA AMES Research Center. 61.1Sthorpej * All rights reserved. 71.1Sthorpej * 81.1Sthorpej * Redistribution and use in source and binary forms, with or without 91.1Sthorpej * modification, are permitted provided that the following conditions 101.1Sthorpej * are met: 111.1Sthorpej * 1. Redistributions of source code must retain the above copyright 121.1Sthorpej * notice immediately at the beginning of the file, without modification, 131.1Sthorpej * this list of conditions, and the following disclaimer. 141.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 151.1Sthorpej * notice, this list of conditions and the following disclaimer in the 161.1Sthorpej * documentation and/or other materials provided with the distribution. 171.1Sthorpej * 3. The name of the author may not be used to endorse or promote products 181.1Sthorpej * derived from this software without specific prior written permission. 191.1Sthorpej * 201.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 211.1Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221.1Sthorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231.1Sthorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 241.1Sthorpej * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251.1Sthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261.1Sthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271.1Sthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281.1Sthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291.1Sthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301.1Sthorpej * SUCH DAMAGE. 311.1Sthorpej */ 321.1Sthorpej 331.1Sthorpej#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 341.1Sthorpej 351.1Sthorpej__KERNEL_RCSID(0, "$NetBSD: mcclock_gbus.c,v 1.1 2024/03/02 19:57:57 thorpej Exp $"); 361.1Sthorpej 371.1Sthorpej#include <sys/param.h> 381.1Sthorpej#include <sys/kernel.h> 391.1Sthorpej#include <sys/systm.h> 401.1Sthorpej#include <sys/device.h> 411.1Sthorpej 421.1Sthorpej#include <sys/bus.h> 431.1Sthorpej 441.1Sthorpej#include <alpha/gbus/gbusvar.h> 451.1Sthorpej 461.1Sthorpej#include <alpha/tlsb/tlsbreg.h> /* XXX */ 471.1Sthorpej 481.1Sthorpej#include <dev/clock_subr.h> 491.1Sthorpej 501.1Sthorpej#include <dev/ic/mc146818reg.h> 511.1Sthorpej#include <dev/ic/mc146818var.h> 521.1Sthorpej 531.1Sthorpej#include <alpha/alpha/mcclockvar.h> 541.1Sthorpej 551.1Sthorpej#include "ioconf.h" 561.1Sthorpej 571.1Sthorpej#define KV(_addr) ((void *)ALPHA_PHYS_TO_K0SEG((_addr))) 581.1Sthorpej/* 591.1Sthorpej * Registers are 64 bytes apart (and 1 byte wide) 601.1Sthorpej */ 611.1Sthorpej#define REGSHIFT 6 621.1Sthorpej 631.1Sthorpejstruct mcclock_tlsb_softc { 641.1Sthorpej struct mc146818_softc sc_mc146818; 651.1Sthorpej unsigned long regbase; 661.1Sthorpej}; 671.1Sthorpej 681.1Sthorpejstatic int mcclock_tlsb_match(device_t, cfdata_t, void *); 691.1Sthorpejstatic void mcclock_tlsb_attach(device_t, device_t, void *); 701.1Sthorpej 711.1SthorpejCFATTACH_DECL_NEW(mcclock_gbus, sizeof(struct mcclock_tlsb_softc), 721.1Sthorpej mcclock_tlsb_match, mcclock_tlsb_attach, NULL, NULL); 731.1Sthorpej 741.1Sthorpejstatic void mcclock_tlsb_write(struct mc146818_softc *, u_int, u_int); 751.1Sthorpejstatic u_int mcclock_tlsb_read(struct mc146818_softc *, u_int); 761.1Sthorpej 771.1Sthorpej 781.1Sthorpejstatic int 791.1Sthorpejmcclock_tlsb_match(device_t parent, cfdata_t cf, void *aux) 801.1Sthorpej{ 811.1Sthorpej struct gbus_attach_args *ga = aux; 821.1Sthorpej 831.1Sthorpej if (strcmp(ga->ga_name, mcclock_cd.cd_name)) 841.1Sthorpej return (0); 851.1Sthorpej return (1); 861.1Sthorpej} 871.1Sthorpej 881.1Sthorpejstatic void 891.1Sthorpejmcclock_tlsb_attach(device_t parent, device_t self, void *aux) 901.1Sthorpej{ 911.1Sthorpej struct mcclock_tlsb_softc *tsc = device_private(self); 921.1Sthorpej struct gbus_attach_args *ga = aux; 931.1Sthorpej struct mc146818_softc *sc = &tsc->sc_mc146818; 941.1Sthorpej 951.1Sthorpej /* XXX Should be bus.h'd, so we can accommodate the kn7aa. */ 961.1Sthorpej tsc->regbase = TLSB_GBUS_BASE + ga->ga_offset; 971.1Sthorpej 981.1Sthorpej sc->sc_dev = self; 991.1Sthorpej sc->sc_mcread = mcclock_tlsb_read; 1001.1Sthorpej sc->sc_mcwrite = mcclock_tlsb_write; 1011.1Sthorpej 1021.1Sthorpej mcclock_attach(sc); 1031.1Sthorpej} 1041.1Sthorpej 1051.1Sthorpejstatic void 1061.1Sthorpejmcclock_tlsb_write(struct mc146818_softc *sc, u_int reg, u_int val) 1071.1Sthorpej{ 1081.1Sthorpej struct mcclock_tlsb_softc *tsc = (void *)sc; 1091.1Sthorpej unsigned char *ptr = (unsigned char *) 1101.1Sthorpej KV(tsc->regbase + (reg << REGSHIFT)); 1111.1Sthorpej 1121.1Sthorpej *ptr = val; 1131.1Sthorpej} 1141.1Sthorpej 1151.1Sthorpejstatic u_int 1161.1Sthorpejmcclock_tlsb_read(struct mc146818_softc *sc, u_int reg) 1171.1Sthorpej{ 1181.1Sthorpej struct mcclock_tlsb_softc *tsc = (void *)sc; 1191.1Sthorpej unsigned char *ptr = (unsigned char *) 1201.1Sthorpej KV(tsc->regbase + (reg << REGSHIFT)); 1211.1Sthorpej 1221.1Sthorpej return *ptr; 1231.1Sthorpej} 124