drbbc.c revision 1.1 1 1.1 is /* $NetBSD: drbbc.c,v 1.1 1997/07/17 23:29:30 is Exp $ */
2 1.1 is
3 1.1 is /*
4 1.1 is * Copyright (c) 1997 Ignatios Souvatzis.
5 1.1 is * All rights reserved.
6 1.1 is *
7 1.1 is * Redistribution and use in source and binary forms, with or without
8 1.1 is * modification, are permitted provided that the following conditions
9 1.1 is * are met:
10 1.1 is * 1. Redistributions of source code must retain the above copyright
11 1.1 is * notice, this list of conditions and the following disclaimer.
12 1.1 is * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 is * notice, this list of conditions and the following disclaimer in the
14 1.1 is * documentation and/or other materials provided with the distribution.
15 1.1 is * 3. All advertising materials mentioning features or use of this software
16 1.1 is * must display the following acknowledgement:
17 1.1 is * This product includes software developed by Ignatios Souvatzis
18 1.1 is * for the NetBSD project.
19 1.1 is * 4. The name of the author may not be used to endorse or promote
20 1.1 is * products derived from this software without specific prior written
21 1.1 is * permission.
22 1.1 is *
23 1.1 is * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
24 1.1 is * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 is * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 is * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
27 1.1 is * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 is * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 is * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 is * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 is * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 is * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 is * SUCH DAMAGE.
34 1.1 is *
35 1.1 is */
36 1.1 is
37 1.1 is #include <sys/param.h>
38 1.1 is #include <sys/kernel.h>
39 1.1 is #include <sys/device.h>
40 1.1 is #include <sys/systm.h>
41 1.1 is #if 0
42 1.1 is #include <machine/psl.h>
43 1.1 is #endif
44 1.1 is #include <machine/cpu.h>
45 1.1 is #include <amiga/amiga/device.h>
46 1.1 is #include <amiga/amiga/custom.h>
47 1.1 is #include <amiga/amiga/cia.h>
48 1.1 is #include <amiga/amiga/drcustom.h>
49 1.1 is #include <amiga/dev/rtc.h>
50 1.1 is
51 1.1 is #include <dev/ic/ds.h>
52 1.1 is
53 1.1 is int draco_ds_read_bit __P((void *));
54 1.1 is void draco_ds_write_bit __P((void *, int));
55 1.1 is void draco_ds_reset __P((void *));
56 1.1 is
57 1.1 is void drbbc_attach __P((struct device *, struct device *, void *));
58 1.1 is int drbbc_match __P((struct device *, struct cfdata *, void *));
59 1.1 is
60 1.1 is time_t dracogettod __P((void));
61 1.1 is #ifdef __NOTYET__
62 1.1 is int dracosettod __P((time_t));
63 1.1 is #endif
64 1.1 is
65 1.1 is struct drbbc_softc {
66 1.1 is struct device sc_dev;
67 1.1 is struct ds_handle sc_dsh;
68 1.1 is };
69 1.1 is
70 1.1 is struct cfattach drbbc_ca = {
71 1.1 is sizeof(struct drbbc_softc),
72 1.1 is drbbc_match,
73 1.1 is drbbc_attach
74 1.1 is };
75 1.1 is
76 1.1 is struct cfdriver drbbc_cd = {
77 1.1 is NULL, "drbbc", DV_DULL, NULL, 0
78 1.1 is };
79 1.1 is
80 1.1 is struct drbbc_softc *drbbc_sc;
81 1.1 is
82 1.1 is int
83 1.1 is drbbc_match(pdp, cfp, auxp)
84 1.1 is struct device *pdp;
85 1.1 is struct cfdata *cfp;
86 1.1 is void *auxp;
87 1.1 is {
88 1.1 is if (is_draco() && matchname(auxp, "drbbc") && (cfp->cf_unit == 0))
89 1.1 is return (1);
90 1.1 is else
91 1.1 is return (0);
92 1.1 is }
93 1.1 is
94 1.1 is void
95 1.1 is drbbc_attach(pdp, dp, auxp)
96 1.1 is struct device *pdp, *dp;
97 1.1 is void *auxp;
98 1.1 is {
99 1.1 is int i;
100 1.1 is struct drbbc_softc *sc;
101 1.1 is u_int8_t rombuf[8];
102 1.1 is
103 1.1 is sc = (struct drbbc_softc *)dp;
104 1.1 is
105 1.1 is sc->sc_dsh.ds_read_bit = draco_ds_read_bit;
106 1.1 is sc->sc_dsh.ds_write_bit = draco_ds_write_bit;
107 1.1 is sc->sc_dsh.ds_reset = draco_ds_reset;
108 1.1 is sc->sc_dsh.ds_hw_handle = (void *)(DRCCADDR + DRIOCTLPG*NBPG);
109 1.1 is
110 1.1 is sc->sc_dsh.ds_reset(sc->sc_dsh.ds_hw_handle);
111 1.1 is
112 1.1 is ds_write_byte(&sc->sc_dsh, DS_ROM_READ);
113 1.1 is for (i=0; i<8; ++i)
114 1.1 is rombuf[i] = ds_read_byte(&sc->sc_dsh);
115 1.1 is
116 1.1 is hostid = (rombuf[3] << 24) + (rombuf[2] << 16) +
117 1.1 is (rombuf[1] << 8) + rombuf[7];
118 1.1 is
119 1.1 is printf(": ROM %02x %02x%02x%02x%02x%02x%02x %02x (DraCo sernum %ld)\n",
120 1.1 is rombuf[7], rombuf[6], rombuf[5], rombuf[4],
121 1.1 is rombuf[3], rombuf[2], rombuf[1], rombuf[0],
122 1.1 is hostid);
123 1.1 is
124 1.1 is gettod = dracogettod;
125 1.1 is settod = (void *)0;
126 1.1 is drbbc_sc = sc;
127 1.1 is }
128 1.1 is
129 1.1 is int
130 1.1 is draco_ds_read_bit(p)
131 1.1 is void *p;
132 1.1 is {
133 1.1 is struct drioct *draco_ioct;
134 1.1 is
135 1.1 is draco_ioct = p;
136 1.1 is
137 1.1 is while (draco_ioct->io_status & DRSTAT_CLKBUSY);
138 1.1 is
139 1.1 is draco_ioct->io_clockw1 = 0;
140 1.1 is
141 1.1 is while (draco_ioct->io_status & DRSTAT_CLKBUSY);
142 1.1 is
143 1.1 is return (draco_ioct->io_status & DRSTAT_CLKDAT);
144 1.1 is }
145 1.1 is
146 1.1 is void
147 1.1 is draco_ds_write_bit(p, b)
148 1.1 is void *p;
149 1.1 is int b;
150 1.1 is {
151 1.1 is struct drioct *draco_ioct;
152 1.1 is
153 1.1 is draco_ioct = p;
154 1.1 is
155 1.1 is while (draco_ioct->io_status & DRSTAT_CLKBUSY);
156 1.1 is
157 1.1 is if (b)
158 1.1 is draco_ioct->io_clockw1 = 0;
159 1.1 is else
160 1.1 is draco_ioct->io_clockw0 = 0;
161 1.1 is }
162 1.1 is
163 1.1 is void
164 1.1 is draco_ds_reset(p)
165 1.1 is void *p;
166 1.1 is {
167 1.1 is struct drioct *draco_ioct;
168 1.1 is
169 1.1 is draco_ioct = p;
170 1.1 is
171 1.1 is draco_ioct->io_clockrst = 0;
172 1.1 is }
173 1.1 is
174 1.1 is /*
175 1.1 is * We could return 1/256 of a seconds, but would need to change the interface
176 1.1 is */
177 1.1 is
178 1.1 is time_t
179 1.1 is dracogettod()
180 1.1 is {
181 1.1 is u_int32_t clkbuf;
182 1.1 is
183 1.1 is drbbc_sc->sc_dsh.ds_reset(drbbc_sc->sc_dsh.ds_hw_handle);
184 1.1 is
185 1.1 is ds_write_byte(&drbbc_sc->sc_dsh, DS_ROM_SKIP);
186 1.1 is
187 1.1 is ds_write_byte(&drbbc_sc->sc_dsh, DS_MEM_READ_MEMORY);
188 1.1 is /* address of full seconds: */
189 1.1 is ds_write_byte(&drbbc_sc->sc_dsh, 0x03);
190 1.1 is ds_write_byte(&drbbc_sc->sc_dsh, 0x02);
191 1.1 is
192 1.1 is clkbuf = ds_read_byte(&drbbc_sc->sc_dsh)
193 1.1 is + (ds_read_byte(&drbbc_sc->sc_dsh)<<8)
194 1.1 is + (ds_read_byte(&drbbc_sc->sc_dsh)<<16)
195 1.1 is + (ds_read_byte(&drbbc_sc->sc_dsh)<<24);
196 1.1 is
197 1.1 is /* BSD time is wr. 1.1.1970; AmigaOS time wrt. 1.1.1978 */
198 1.1 is
199 1.1 is clkbuf += (8*365 + 2) * 86400;
200 1.1 is
201 1.1 is return ((time_t)clkbuf);
202 1.1 is }
203