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