1*6aef9a4eSmpi /* $OpenBSD: mcclock_ioasic.c,v 1.7 2022/03/13 08:04:13 mpi Exp $ */
2aa76beb5Smiod /* $NetBSD: mcclock_ioasic.c,v 1.9 2000/07/04 02:37:51 nisimura Exp $ */
3417eba8cSderaadt
4417eba8cSderaadt /*
5417eba8cSderaadt * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
6417eba8cSderaadt * All rights reserved.
7417eba8cSderaadt *
8417eba8cSderaadt * Author: Chris G. Demetriou
9417eba8cSderaadt *
10417eba8cSderaadt * Permission to use, copy, modify and distribute this software and
11417eba8cSderaadt * its documentation is hereby granted, provided that both the copyright
12417eba8cSderaadt * notice and this permission notice appear in all copies of the
13417eba8cSderaadt * software, derivative works or modified versions, and any portions
14417eba8cSderaadt * thereof, and that both notices appear in supporting documentation.
15417eba8cSderaadt *
16417eba8cSderaadt * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17417eba8cSderaadt * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18417eba8cSderaadt * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19417eba8cSderaadt *
20417eba8cSderaadt * Carnegie Mellon requests users of this software to return to
21417eba8cSderaadt *
22417eba8cSderaadt * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
23417eba8cSderaadt * School of Computer Science
24417eba8cSderaadt * Carnegie Mellon University
25417eba8cSderaadt * Pittsburgh PA 15213-3890
26417eba8cSderaadt *
27417eba8cSderaadt * any improvements or extensions that they make and grant Carnegie the
28417eba8cSderaadt * rights to redistribute these changes.
29417eba8cSderaadt */
30417eba8cSderaadt
31417eba8cSderaadt #include <sys/param.h>
32417eba8cSderaadt #include <sys/kernel.h>
33417eba8cSderaadt #include <sys/systm.h>
34417eba8cSderaadt #include <sys/device.h>
35417eba8cSderaadt
36aa76beb5Smiod #include <dev/dec/clockvar.h>
37aa76beb5Smiod #include <dev/dec/mcclockvar.h>
38417eba8cSderaadt #include <dev/ic/mc146818reg.h>
39417eba8cSderaadt #include <dev/tc/tcvar.h>
40417eba8cSderaadt #include <dev/tc/ioasicvar.h> /* XXX */
41417eba8cSderaadt
42417eba8cSderaadt struct mcclock_ioasic_clockdatum {
43417eba8cSderaadt u_char datum;
44417eba8cSderaadt char pad[3];
45417eba8cSderaadt };
46417eba8cSderaadt
47417eba8cSderaadt struct mcclock_ioasic_softc {
48417eba8cSderaadt struct mcclock_softc sc_mcclock;
49417eba8cSderaadt
50417eba8cSderaadt struct mcclock_ioasic_clockdatum *sc_dp;
51417eba8cSderaadt };
52417eba8cSderaadt
53c4071fd1Smillert int mcclock_ioasic_match(struct device *, void *, void *);
54c4071fd1Smillert void mcclock_ioasic_attach(struct device *, struct device *, void *);
55417eba8cSderaadt
56*6aef9a4eSmpi const struct cfattach mcclock_ioasic_ca = {
57417eba8cSderaadt sizeof (struct mcclock_ioasic_softc), mcclock_ioasic_match,
58417eba8cSderaadt mcclock_ioasic_attach,
59417eba8cSderaadt };
60417eba8cSderaadt
61c4071fd1Smillert void mcclock_ioasic_write(struct mcclock_softc *, u_int, u_int);
62c4071fd1Smillert u_int mcclock_ioasic_read(struct mcclock_softc *, u_int);
63417eba8cSderaadt
64417eba8cSderaadt const struct mcclock_busfns mcclock_ioasic_busfns = {
65417eba8cSderaadt mcclock_ioasic_write, mcclock_ioasic_read,
66417eba8cSderaadt };
67417eba8cSderaadt
68417eba8cSderaadt int
mcclock_ioasic_match(parent,match,aux)69417eba8cSderaadt mcclock_ioasic_match(parent, match, aux)
70417eba8cSderaadt struct device *parent;
71aa76beb5Smiod void *match, *aux;
72417eba8cSderaadt {
73417eba8cSderaadt struct ioasicdev_attach_args *d = aux;
74417eba8cSderaadt
75417eba8cSderaadt if (strncmp("TOY_RTC ", d->iada_modname, TC_ROM_LLEN))
76417eba8cSderaadt return (0);
77417eba8cSderaadt
78417eba8cSderaadt return (1);
79417eba8cSderaadt }
80417eba8cSderaadt
81417eba8cSderaadt void
mcclock_ioasic_attach(parent,self,aux)82417eba8cSderaadt mcclock_ioasic_attach(parent, self, aux)
83417eba8cSderaadt struct device *parent, *self;
84417eba8cSderaadt void *aux;
85417eba8cSderaadt {
86417eba8cSderaadt struct ioasicdev_attach_args *ioasicdev = aux;
87417eba8cSderaadt struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)self;
88417eba8cSderaadt
89417eba8cSderaadt sc->sc_dp = (struct mcclock_ioasic_clockdatum *)ioasicdev->iada_addr;
90417eba8cSderaadt
91417eba8cSderaadt mcclock_attach(&sc->sc_mcclock, &mcclock_ioasic_busfns);
92417eba8cSderaadt }
93417eba8cSderaadt
94417eba8cSderaadt void
mcclock_ioasic_write(dev,reg,datum)95417eba8cSderaadt mcclock_ioasic_write(dev, reg, datum)
96417eba8cSderaadt struct mcclock_softc *dev;
97417eba8cSderaadt u_int reg, datum;
98417eba8cSderaadt {
99417eba8cSderaadt struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;
100417eba8cSderaadt
101417eba8cSderaadt sc->sc_dp[reg].datum = datum;
102417eba8cSderaadt }
103417eba8cSderaadt
104417eba8cSderaadt u_int
mcclock_ioasic_read(dev,reg)105417eba8cSderaadt mcclock_ioasic_read(dev, reg)
106417eba8cSderaadt struct mcclock_softc *dev;
107417eba8cSderaadt u_int reg;
108417eba8cSderaadt {
109417eba8cSderaadt struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;
110417eba8cSderaadt
111417eba8cSderaadt return (sc->sc_dp[reg].datum);
112417eba8cSderaadt }
113