1 1.19 thorpej /* $NetBSD: mcclock_ioasic.c,v 1.19 2024/03/06 06:30:49 thorpej Exp $ */ 2 1.2 cgd 3 1.2 cgd /* 4 1.2 cgd * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. 5 1.2 cgd * All rights reserved. 6 1.2 cgd * 7 1.2 cgd * Author: Chris G. Demetriou 8 1.2 cgd * 9 1.2 cgd * Permission to use, copy, modify and distribute this software and 10 1.2 cgd * its documentation is hereby granted, provided that both the copyright 11 1.2 cgd * notice and this permission notice appear in all copies of the 12 1.2 cgd * software, derivative works or modified versions, and any portions 13 1.2 cgd * thereof, and that both notices appear in supporting documentation. 14 1.2 cgd * 15 1.2 cgd * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 1.2 cgd * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 1.2 cgd * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 1.2 cgd * 19 1.2 cgd * Carnegie Mellon requests users of this software to return to 20 1.2 cgd * 21 1.2 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU 22 1.2 cgd * School of Computer Science 23 1.2 cgd * Carnegie Mellon University 24 1.2 cgd * Pittsburgh PA 15213-3890 25 1.2 cgd * 26 1.2 cgd * any improvements or extensions that they make and grant Carnegie the 27 1.2 cgd * rights to redistribute these changes. 28 1.2 cgd */ 29 1.5 cgd 30 1.6 cgd #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 31 1.6 cgd 32 1.19 thorpej __KERNEL_RCSID(0, "$NetBSD: mcclock_ioasic.c,v 1.19 2024/03/06 06:30:49 thorpej Exp $"); 33 1.1 cgd 34 1.1 cgd #include <sys/param.h> 35 1.1 cgd #include <sys/kernel.h> 36 1.1 cgd #include <sys/systm.h> 37 1.1 cgd #include <sys/device.h> 38 1.1 cgd 39 1.16 dyoung #include <sys/bus.h> 40 1.12 tsutsui 41 1.12 tsutsui #include <dev/clock_subr.h> 42 1.12 tsutsui 43 1.1 cgd #include <dev/ic/mc146818reg.h> 44 1.12 tsutsui #include <dev/ic/mc146818var.h> 45 1.17 matt #include <dev/tc/tcvar.h> 46 1.1 cgd #include <dev/tc/ioasicvar.h> /* XXX */ 47 1.1 cgd 48 1.12 tsutsui #include <alpha/alpha/mcclockvar.h> 49 1.12 tsutsui 50 1.1 cgd struct mcclock_ioasic_clockdatum { 51 1.1 cgd u_char datum; 52 1.1 cgd char pad[3]; 53 1.1 cgd }; 54 1.1 cgd 55 1.1 cgd struct mcclock_ioasic_softc { 56 1.19 thorpej struct mcclock_softc sc_mcclock; 57 1.1 cgd 58 1.1 cgd struct mcclock_ioasic_clockdatum *sc_dp; 59 1.1 cgd }; 60 1.1 cgd 61 1.18 thorpej static int mcclock_ioasic_match(device_t, cfdata_t, void *); 62 1.18 thorpej static void mcclock_ioasic_attach(device_t, device_t, void *); 63 1.1 cgd 64 1.14 tsutsui CFATTACH_DECL_NEW(mcclock_ioasic, sizeof(struct mcclock_ioasic_softc), 65 1.11 thorpej mcclock_ioasic_match, mcclock_ioasic_attach, NULL, NULL); 66 1.1 cgd 67 1.18 thorpej static void mcclock_ioasic_write(struct mc146818_softc *, u_int, u_int); 68 1.18 thorpej static u_int mcclock_ioasic_read(struct mc146818_softc *, u_int); 69 1.1 cgd 70 1.18 thorpej static int 71 1.14 tsutsui mcclock_ioasic_match(device_t parent, cfdata_t cf, void *aux) 72 1.1 cgd { 73 1.1 cgd struct ioasicdev_attach_args *d = aux; 74 1.1 cgd 75 1.1 cgd if (strncmp("TOY_RTC ", d->iada_modname, TC_ROM_LLEN)) 76 1.1 cgd return (0); 77 1.1 cgd 78 1.1 cgd return (1); 79 1.1 cgd } 80 1.1 cgd 81 1.18 thorpej static void 82 1.14 tsutsui mcclock_ioasic_attach(device_t parent, device_t self, void *aux) 83 1.1 cgd { 84 1.14 tsutsui struct mcclock_ioasic_softc *isc = device_private(self); 85 1.1 cgd struct ioasicdev_attach_args *ioasicdev = aux; 86 1.19 thorpej struct mc146818_softc *sc = &isc->sc_mcclock.sc_mc146818; 87 1.12 tsutsui 88 1.12 tsutsui /* XXX no bus_space(9) for TURBOchannel yet */ 89 1.12 tsutsui isc->sc_dp = (void *)ioasicdev->iada_addr; 90 1.1 cgd 91 1.15 tsutsui sc->sc_dev = self; 92 1.12 tsutsui sc->sc_mcread = mcclock_ioasic_read; 93 1.12 tsutsui sc->sc_mcwrite = mcclock_ioasic_write; 94 1.1 cgd 95 1.12 tsutsui /* call alpha common mcclock attachment */ 96 1.19 thorpej mcclock_attach(&isc->sc_mcclock); 97 1.1 cgd } 98 1.1 cgd 99 1.18 thorpej static void 100 1.12 tsutsui mcclock_ioasic_write(struct mc146818_softc *sc, u_int reg, u_int datum) 101 1.1 cgd { 102 1.12 tsutsui struct mcclock_ioasic_softc *isc = (void *)sc; 103 1.1 cgd 104 1.12 tsutsui isc->sc_dp[reg].datum = datum; 105 1.1 cgd } 106 1.1 cgd 107 1.18 thorpej static u_int 108 1.12 tsutsui mcclock_ioasic_read(struct mc146818_softc *sc, u_int reg) 109 1.1 cgd { 110 1.12 tsutsui struct mcclock_ioasic_softc *isc = (void *)sc; 111 1.1 cgd 112 1.12 tsutsui return isc->sc_dp[reg].datum; 113 1.1 cgd } 114