tctrl.c revision 1.26 1 1.26 wiz /* $NetBSD: tctrl.c,v 1.26 2004/02/13 11:36:17 wiz Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Matt Thomas.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt * 3. All advertising materials mentioning features or use of this software
19 1.1 matt * must display the following acknowledgement:
20 1.1 matt * This product includes software developed by the NetBSD
21 1.1 matt * Foundation, Inc. and its contributors.
22 1.1 matt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 matt * contributors may be used to endorse or promote products derived
24 1.1 matt * from this software without specific prior written permission.
25 1.1 matt *
26 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
37 1.1 matt */
38 1.25 lukem
39 1.25 lukem #include <sys/cdefs.h>
40 1.26 wiz __KERNEL_RCSID(0, "$NetBSD: tctrl.c,v 1.26 2004/02/13 11:36:17 wiz Exp $");
41 1.1 matt
42 1.1 matt #include <sys/param.h>
43 1.1 matt #include <sys/systm.h>
44 1.8 thorpej #include <sys/callout.h>
45 1.1 matt #include <sys/ioctl.h>
46 1.1 matt #include <sys/select.h>
47 1.1 matt #include <sys/tty.h>
48 1.1 matt #include <sys/proc.h>
49 1.1 matt #include <sys/user.h>
50 1.1 matt #include <sys/conf.h>
51 1.1 matt #include <sys/file.h>
52 1.1 matt #include <sys/uio.h>
53 1.1 matt #include <sys/kernel.h>
54 1.1 matt #include <sys/syslog.h>
55 1.1 matt #include <sys/types.h>
56 1.1 matt #include <sys/device.h>
57 1.4 garbled #include <sys/envsys.h>
58 1.4 garbled #include <sys/poll.h>
59 1.1 matt
60 1.4 garbled #include <machine/apmvar.h>
61 1.1 matt #include <machine/autoconf.h>
62 1.1 matt #include <machine/bus.h>
63 1.11 pk #include <machine/intr.h>
64 1.4 garbled #include <machine/tctrl.h>
65 1.1 matt
66 1.1 matt #include <sparc/dev/ts102reg.h>
67 1.1 matt #include <sparc/dev/tctrlvar.h>
68 1.7 jdc #include <sparc/sparc/auxiotwo.h>
69 1.1 matt
70 1.15 gehenna extern struct cfdriver tctrl_cd;
71 1.4 garbled
72 1.15 gehenna dev_type_open(tctrlopen);
73 1.15 gehenna dev_type_close(tctrlclose);
74 1.15 gehenna dev_type_ioctl(tctrlioctl);
75 1.15 gehenna dev_type_poll(tctrlpoll);
76 1.20 jdolecek dev_type_kqfilter(tctrlkqfilter);
77 1.15 gehenna
78 1.15 gehenna const struct cdevsw tctrl_cdevsw = {
79 1.15 gehenna tctrlopen, tctrlclose, noread, nowrite, tctrlioctl,
80 1.20 jdolecek nostop, notty, tctrlpoll, nommap, tctrlkqfilter,
81 1.15 gehenna };
82 1.4 garbled
83 1.1 matt static const char *tctrl_ext_statuses[16] = {
84 1.1 matt "main power available",
85 1.1 matt "internal battery attached",
86 1.1 matt "external battery attached",
87 1.1 matt "external VGA attached",
88 1.1 matt "external keyboard attached",
89 1.1 matt "external mouse attached",
90 1.1 matt "lid down",
91 1.1 matt "internal battery charging",
92 1.1 matt "external battery charging",
93 1.1 matt "internal battery discharging",
94 1.1 matt "external battery discharging",
95 1.1 matt };
96 1.1 matt
97 1.1 matt struct tctrl_softc {
98 1.4 garbled struct device sc_dev;
99 1.4 garbled bus_space_tag_t sc_memt;
100 1.4 garbled bus_space_handle_t sc_memh;
101 1.4 garbled unsigned int sc_junk;
102 1.4 garbled unsigned int sc_ext_status;
103 1.4 garbled unsigned int sc_flags;
104 1.4 garbled #define TCTRL_SEND_REQUEST 0x0001
105 1.4 garbled #define TCTRL_APM_CTLOPEN 0x0002
106 1.4 garbled unsigned int sc_wantdata;
107 1.6 garbled volatile unsigned short sc_lcdstate;
108 1.1 matt enum { TCTRL_IDLE, TCTRL_ARGS,
109 1.1 matt TCTRL_ACK, TCTRL_DATA } sc_state;
110 1.4 garbled u_int8_t sc_cmdbuf[16];
111 1.4 garbled u_int8_t sc_rspbuf[16];
112 1.4 garbled u_int8_t sc_bitport;
113 1.4 garbled u_int8_t sc_tft_on;
114 1.4 garbled u_int8_t sc_op;
115 1.4 garbled u_int8_t sc_cmdoff;
116 1.4 garbled u_int8_t sc_cmdlen;
117 1.4 garbled u_int8_t sc_rspoff;
118 1.4 garbled u_int8_t sc_rsplen;
119 1.4 garbled /* APM stuff */
120 1.4 garbled #define APM_NEVENTS 16
121 1.4 garbled struct apm_event_info sc_event_list[APM_NEVENTS];
122 1.4 garbled int sc_event_count;
123 1.4 garbled int sc_event_ptr;
124 1.4 garbled struct selinfo sc_rsel;
125 1.4 garbled /* ENVSYS stuff */
126 1.4 garbled #define ENVSYS_NUMSENSORS 3
127 1.4 garbled struct envsys_sensor sc_esensors[ENVSYS_NUMSENSORS];
128 1.1 matt
129 1.4 garbled struct evcnt sc_intrcnt; /* interrupt counting */
130 1.1 matt };
131 1.1 matt
132 1.4 garbled #define TCTRL_STD_DEV 0
133 1.4 garbled #define TCTRL_APMCTL_DEV 8
134 1.1 matt
135 1.9 thorpej static struct callout tctrl_event_ch = CALLOUT_INITIALIZER;
136 1.8 thorpej
137 1.4 garbled static int tctrl_match __P((struct device *parent, struct cfdata *cf,
138 1.4 garbled void *aux));
139 1.4 garbled static void tctrl_attach __P((struct device *parent, struct device *self,
140 1.4 garbled void *aux));
141 1.4 garbled static void tctrl_write __P((struct tctrl_softc *sc, bus_size_t off,
142 1.4 garbled u_int8_t v));
143 1.4 garbled static u_int8_t tctrl_read __P((struct tctrl_softc *sc, bus_size_t off));
144 1.4 garbled static void tctrl_write_data __P((struct tctrl_softc *sc, u_int8_t v));
145 1.4 garbled static u_int8_t tctrl_read_data __P((struct tctrl_softc *sc));
146 1.4 garbled static int tctrl_intr __P((void *arg));
147 1.4 garbled static void tctrl_setup_bitport __P((void));
148 1.4 garbled static void tctrl_setup_bitport_nop __P((void));
149 1.4 garbled static void tctrl_read_ext_status __P((void));
150 1.4 garbled static void tctrl_read_event_status __P((void *arg));
151 1.4 garbled static int tctrl_apm_record_event __P((struct tctrl_softc *sc,
152 1.4 garbled u_int event_type));
153 1.6 garbled static void tctrl_init_lcd __P((void));
154 1.1 matt
155 1.17 thorpej CFATTACH_DECL(tctrl, sizeof(struct tctrl_softc),
156 1.18 thorpej tctrl_match, tctrl_attach, NULL, NULL);
157 1.1 matt
158 1.1 matt extern struct cfdriver tctrl_cd;
159 1.4 garbled /* XXX wtf is this? see i386/apm.c */
160 1.4 garbled int tctrl_apm_evindex;
161 1.1 matt
162 1.1 matt static int
163 1.4 garbled tctrl_match(parent, cf, aux)
164 1.4 garbled struct device *parent;
165 1.4 garbled struct cfdata *cf;
166 1.4 garbled void *aux;
167 1.1 matt {
168 1.1 matt union obio_attach_args *uoba = aux;
169 1.1 matt struct sbus_attach_args *sa = &uoba->uoba_sbus;
170 1.1 matt
171 1.1 matt if (uoba->uoba_isobio4 != 0) {
172 1.1 matt return (0);
173 1.1 matt }
174 1.1 matt
175 1.1 matt /* Tadpole 3GX/3GS uses "uctrl" for the Tadpole Microcontroller
176 1.1 matt * (who's interface is off the TS102 PCMCIA controller but there
177 1.1 matt * exists a OpenProm for microcontroller interface).
178 1.1 matt */
179 1.1 matt return strcmp("uctrl", sa->sa_name) == 0;
180 1.1 matt }
181 1.1 matt
182 1.1 matt static void
183 1.4 garbled tctrl_attach(parent, self, aux)
184 1.4 garbled struct device *parent;
185 1.4 garbled struct device *self;
186 1.4 garbled void *aux;
187 1.1 matt {
188 1.1 matt struct tctrl_softc *sc = (void *)self;
189 1.1 matt union obio_attach_args *uoba = aux;
190 1.1 matt struct sbus_attach_args *sa = &uoba->uoba_sbus;
191 1.2 matt unsigned int i, v;
192 1.2 matt #if 0
193 1.1 matt unsigned int ack, msb, lsb;
194 1.2 matt #endif
195 1.1 matt
196 1.1 matt /* We're living on a sbus slot that looks like an obio that
197 1.1 matt * looks like an sbus slot.
198 1.1 matt */
199 1.1 matt sc->sc_memt = sa->sa_bustag;
200 1.14 pk if (sbus_bus_map(sc->sc_memt,
201 1.14 pk sa->sa_slot,
202 1.14 pk sa->sa_offset - TS102_REG_UCTRL_INT,
203 1.14 pk sa->sa_size,
204 1.14 pk BUS_SPACE_MAP_LINEAR, &sc->sc_memh) != 0) {
205 1.1 matt printf(": can't map registers\n");
206 1.1 matt return;
207 1.1 matt }
208 1.1 matt
209 1.2 matt printf("\n");
210 1.2 matt
211 1.1 matt sc->sc_tft_on = 1;
212 1.2 matt
213 1.1 matt /* clear any pending data.
214 1.1 matt */
215 1.1 matt for (i = 0; i < 10000; i++) {
216 1.4 garbled if ((TS102_UCTRL_STS_RXNE_STA &
217 1.4 garbled tctrl_read(sc, TS102_REG_UCTRL_STS)) == 0) {
218 1.1 matt break;
219 1.1 matt }
220 1.1 matt v = tctrl_read(sc, TS102_REG_UCTRL_DATA);
221 1.2 matt tctrl_write(sc, TS102_REG_UCTRL_STS, TS102_UCTRL_STS_RXNE_STA);
222 1.1 matt }
223 1.1 matt
224 1.3 pk if (sa->sa_nintr != 0) {
225 1.11 pk (void)bus_intr_establish(sc->sc_memt, sa->sa_pri, IPL_NONE,
226 1.22 pk tctrl_intr, sc);
227 1.10 cgd evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
228 1.22 pk sc->sc_dev.dv_xname, "intr");
229 1.3 pk }
230 1.2 matt
231 1.2 matt /* See what the external status is
232 1.2 matt */
233 1.1 matt
234 1.4 garbled tctrl_read_ext_status();
235 1.2 matt if (sc->sc_ext_status != 0) {
236 1.2 matt const char *sep;
237 1.1 matt
238 1.1 matt printf("%s: ", sc->sc_dev.dv_xname);
239 1.2 matt v = sc->sc_ext_status;
240 1.1 matt for (i = 0, sep = ""; v != 0; i++, v >>= 1) {
241 1.1 matt if (v & 1) {
242 1.1 matt printf("%s%s", sep, tctrl_ext_statuses[i]);
243 1.1 matt sep = ", ";
244 1.1 matt }
245 1.1 matt }
246 1.1 matt printf("\n");
247 1.1 matt }
248 1.1 matt
249 1.2 matt /* Get a current of the control bitport;
250 1.2 matt */
251 1.4 garbled tctrl_setup_bitport_nop();
252 1.2 matt tctrl_write(sc, TS102_REG_UCTRL_INT,
253 1.2 matt TS102_UCTRL_INT_RXNE_REQ|TS102_UCTRL_INT_RXNE_MSK);
254 1.1 matt
255 1.4 garbled sc->sc_wantdata = 0;
256 1.4 garbled sc->sc_event_count = 0;
257 1.4 garbled
258 1.4 garbled /* prime the sensor data */
259 1.4 garbled sprintf(sc->sc_esensors[0].desc, "%s", "Internal Unit Temperature");
260 1.4 garbled sc->sc_esensors[0].units = ENVSYS_STEMP;
261 1.4 garbled sprintf(sc->sc_esensors[1].desc, "%s", "Internal Battery Voltage");
262 1.4 garbled sc->sc_esensors[1].units = ENVSYS_SVOLTS_DC;
263 1.4 garbled sprintf(sc->sc_esensors[2].desc, "%s", "DC-In Voltage");
264 1.4 garbled sc->sc_esensors[2].units = ENVSYS_SVOLTS_DC;
265 1.6 garbled
266 1.6 garbled /* initialize the LCD */
267 1.6 garbled tctrl_init_lcd();
268 1.6 garbled
269 1.6 garbled /* initialize sc_lcdstate */
270 1.6 garbled sc->sc_lcdstate = 0;
271 1.6 garbled tctrl_set_lcd(2, 0);
272 1.1 matt }
273 1.1 matt
274 1.1 matt static int
275 1.4 garbled tctrl_intr(arg)
276 1.4 garbled void *arg;
277 1.1 matt {
278 1.1 matt struct tctrl_softc *sc = arg;
279 1.1 matt unsigned int v, d;
280 1.1 matt int progress = 0;
281 1.1 matt
282 1.1 matt again:
283 1.1 matt /* find out the cause(s) of the interrupt */
284 1.12 toddpw v = tctrl_read(sc, TS102_REG_UCTRL_STS) & TS102_UCTRL_STS_MASK;
285 1.1 matt
286 1.1 matt /* clear the cause(s) of the interrupt */
287 1.1 matt tctrl_write(sc, TS102_REG_UCTRL_STS, v);
288 1.1 matt
289 1.2 matt v &= ~(TS102_UCTRL_STS_RXO_STA|TS102_UCTRL_STS_TXE_STA);
290 1.1 matt if (sc->sc_cmdoff >= sc->sc_cmdlen) {
291 1.2 matt v &= ~TS102_UCTRL_STS_TXNF_STA;
292 1.4 garbled if (tctrl_read(sc, TS102_REG_UCTRL_INT) & TS102_UCTRL_INT_TXNF_REQ) {
293 1.4 garbled tctrl_write(sc, TS102_REG_UCTRL_INT, 0);
294 1.4 garbled progress = 1;
295 1.4 garbled }
296 1.1 matt }
297 1.4 garbled if ((v == 0) && ((sc->sc_flags & TCTRL_SEND_REQUEST) == 0 ||
298 1.4 garbled sc->sc_state != TCTRL_IDLE)) {
299 1.4 garbled wakeup(sc);
300 1.1 matt return progress;
301 1.1 matt }
302 1.1 matt
303 1.1 matt progress = 1;
304 1.2 matt if (v & TS102_UCTRL_STS_RXNE_STA) {
305 1.1 matt d = tctrl_read_data(sc);
306 1.1 matt switch (sc->sc_state) {
307 1.1 matt case TCTRL_IDLE:
308 1.2 matt if (d == 0xfa) {
309 1.4 garbled /* external event */
310 1.8 thorpej callout_reset(&tctrl_event_ch, 1,
311 1.8 thorpej tctrl_read_event_status, NULL);
312 1.2 matt } else {
313 1.2 matt printf("%s: (op=0x%02x): unexpected data (0x%02x)\n",
314 1.2 matt sc->sc_dev.dv_xname, sc->sc_op, d);
315 1.1 matt }
316 1.2 matt goto again;
317 1.1 matt case TCTRL_ACK:
318 1.1 matt if (d != 0xfe) {
319 1.2 matt printf("%s: (op=0x%02x): unexpected ack value (0x%02x)\n",
320 1.1 matt sc->sc_dev.dv_xname, sc->sc_op, d);
321 1.1 matt }
322 1.4 garbled #ifdef TCTRLDEBUG
323 1.2 matt printf(" ack=0x%02x", d);
324 1.2 matt #endif
325 1.2 matt sc->sc_rsplen--;
326 1.2 matt sc->sc_rspoff = 0;
327 1.1 matt sc->sc_state = sc->sc_rsplen ? TCTRL_DATA : TCTRL_IDLE;
328 1.4 garbled sc->sc_wantdata = sc->sc_rsplen ? 1 : 0;
329 1.4 garbled #ifdef TCTRLDEBUG
330 1.2 matt if (sc->sc_rsplen > 0) {
331 1.2 matt printf(" [data(%u)]", sc->sc_rsplen);
332 1.2 matt } else {
333 1.2 matt printf(" [idle]\n");
334 1.2 matt }
335 1.2 matt #endif
336 1.2 matt goto again;
337 1.1 matt case TCTRL_DATA:
338 1.1 matt sc->sc_rspbuf[sc->sc_rspoff++] = d;
339 1.4 garbled #ifdef TCTRLDEBUG
340 1.2 matt printf(" [%d]=0x%02x", sc->sc_rspoff-1, d);
341 1.2 matt #endif
342 1.1 matt if (sc->sc_rspoff == sc->sc_rsplen) {
343 1.4 garbled #ifdef TCTRLDEBUG
344 1.2 matt printf(" [idle]\n");
345 1.2 matt #endif
346 1.1 matt sc->sc_state = TCTRL_IDLE;
347 1.4 garbled sc->sc_wantdata = 0;
348 1.1 matt }
349 1.2 matt goto again;
350 1.1 matt default:
351 1.1 matt printf("%s: (op=0x%02x): unexpected data (0x%02x) in state %d\n",
352 1.1 matt sc->sc_dev.dv_xname, sc->sc_op, d, sc->sc_state);
353 1.2 matt goto again;
354 1.1 matt }
355 1.1 matt }
356 1.4 garbled if ((sc->sc_state == TCTRL_IDLE && sc->sc_wantdata == 0) ||
357 1.4 garbled sc->sc_flags & TCTRL_SEND_REQUEST) {
358 1.4 garbled if (sc->sc_flags & TCTRL_SEND_REQUEST) {
359 1.4 garbled sc->sc_flags &= ~TCTRL_SEND_REQUEST;
360 1.4 garbled sc->sc_wantdata = 1;
361 1.4 garbled }
362 1.1 matt if (sc->sc_cmdlen > 0) {
363 1.1 matt tctrl_write(sc, TS102_REG_UCTRL_INT,
364 1.1 matt tctrl_read(sc, TS102_REG_UCTRL_INT)
365 1.1 matt |TS102_UCTRL_INT_TXNF_MSK
366 1.1 matt |TS102_UCTRL_INT_TXNF_REQ);
367 1.1 matt v = tctrl_read(sc, TS102_REG_UCTRL_STS);
368 1.1 matt }
369 1.1 matt }
370 1.2 matt if ((sc->sc_cmdoff < sc->sc_cmdlen) && (v & TS102_UCTRL_STS_TXNF_STA)) {
371 1.1 matt tctrl_write_data(sc, sc->sc_cmdbuf[sc->sc_cmdoff++]);
372 1.4 garbled #ifdef TCTRLDEBUG
373 1.2 matt if (sc->sc_cmdoff == 1) {
374 1.2 matt printf("%s: op=0x%02x(l=%u)", sc->sc_dev.dv_xname,
375 1.2 matt sc->sc_cmdbuf[0], sc->sc_rsplen);
376 1.2 matt } else {
377 1.2 matt printf(" [%d]=0x%02x", sc->sc_cmdoff-1,
378 1.2 matt sc->sc_cmdbuf[sc->sc_cmdoff-1]);
379 1.2 matt }
380 1.2 matt #endif
381 1.1 matt if (sc->sc_cmdoff == sc->sc_cmdlen) {
382 1.1 matt sc->sc_state = sc->sc_rsplen ? TCTRL_ACK : TCTRL_IDLE;
383 1.4 garbled #ifdef TCTRLDEBUG
384 1.2 matt printf(" %s", sc->sc_rsplen ? "[ack]" : "[idle]\n");
385 1.2 matt #endif
386 1.2 matt if (sc->sc_cmdoff == 1) {
387 1.2 matt sc->sc_op = sc->sc_cmdbuf[0];
388 1.2 matt }
389 1.1 matt tctrl_write(sc, TS102_REG_UCTRL_INT,
390 1.1 matt tctrl_read(sc, TS102_REG_UCTRL_INT)
391 1.1 matt & (~TS102_UCTRL_INT_TXNF_MSK
392 1.1 matt |TS102_UCTRL_INT_TXNF_REQ));
393 1.1 matt } else if (sc->sc_state == TCTRL_IDLE) {
394 1.1 matt sc->sc_op = sc->sc_cmdbuf[0];
395 1.1 matt sc->sc_state = TCTRL_ARGS;
396 1.4 garbled #ifdef TCTRLDEBUG
397 1.2 matt printf(" [args]");
398 1.2 matt #endif
399 1.1 matt }
400 1.1 matt }
401 1.1 matt goto again;
402 1.1 matt }
403 1.1 matt
404 1.1 matt static void
405 1.4 garbled tctrl_setup_bitport_nop(void)
406 1.4 garbled {
407 1.4 garbled struct tctrl_softc *sc;
408 1.4 garbled struct tctrl_req req;
409 1.4 garbled int s;
410 1.4 garbled
411 1.4 garbled sc = (struct tctrl_softc *) tctrl_cd.cd_devs[TCTRL_STD_DEV];
412 1.4 garbled req.cmdbuf[0] = TS102_OP_CTL_BITPORT;
413 1.4 garbled req.cmdbuf[1] = 0xff;
414 1.4 garbled req.cmdbuf[2] = 0;
415 1.4 garbled req.cmdlen = 3;
416 1.4 garbled req.rsplen = 2;
417 1.4 garbled req.p = NULL;
418 1.4 garbled tadpole_request(&req, 1);
419 1.4 garbled s = splts102();
420 1.4 garbled sc->sc_bitport = (req.rspbuf[0] & req.cmdbuf[1]) ^ req.cmdbuf[2];
421 1.4 garbled splx(s);
422 1.4 garbled }
423 1.4 garbled
424 1.4 garbled static void
425 1.4 garbled tctrl_setup_bitport(void)
426 1.1 matt {
427 1.4 garbled struct tctrl_softc *sc;
428 1.4 garbled struct tctrl_req req;
429 1.4 garbled int s;
430 1.4 garbled
431 1.4 garbled sc = (struct tctrl_softc *) tctrl_cd.cd_devs[TCTRL_STD_DEV];
432 1.4 garbled s = splts102();
433 1.4 garbled if ((sc->sc_ext_status & TS102_EXT_STATUS_LID_DOWN)
434 1.4 garbled || (!sc->sc_tft_on)) {
435 1.4 garbled req.cmdbuf[2] = TS102_BITPORT_TFTPWR;
436 1.1 matt } else {
437 1.4 garbled req.cmdbuf[2] = 0;
438 1.4 garbled }
439 1.4 garbled req.cmdbuf[0] = TS102_OP_CTL_BITPORT;
440 1.4 garbled req.cmdbuf[1] = ~TS102_BITPORT_TFTPWR;
441 1.4 garbled req.cmdlen = 3;
442 1.4 garbled req.rsplen = 2;
443 1.4 garbled req.p = NULL;
444 1.4 garbled tadpole_request(&req, 1);
445 1.4 garbled s = splts102();
446 1.4 garbled sc->sc_bitport = (req.rspbuf[0] & req.cmdbuf[1]) ^ req.cmdbuf[2];
447 1.4 garbled splx(s);
448 1.4 garbled }
449 1.4 garbled
450 1.6 garbled /*
451 1.6 garbled * The tadpole microcontroller is not preprogrammed with icon
452 1.6 garbled * representations. The machine boots with the DC-IN light as
453 1.6 garbled * a blank (all 0x00) and the other lights, as 4 rows of horizontal
454 1.6 garbled * bars. The below code initializes the icons in the system to
455 1.6 garbled * sane values. Some of these icons could be used for any purpose
456 1.6 garbled * desired, namely the pcmcia, LAN and WAN lights. For the disk spinner,
457 1.6 garbled * only the backslash is unprogrammed. (sigh)
458 1.6 garbled *
459 1.6 garbled * programming the icons is simple. It is a 5x8 matrix, which each row a
460 1.6 garbled * bitfield in the order 0x10 0x08 0x04 0x02 0x01.
461 1.6 garbled */
462 1.6 garbled
463 1.6 garbled static void
464 1.6 garbled tctrl_init_lcd(void)
465 1.6 garbled {
466 1.6 garbled struct tctrl_req req;
467 1.6 garbled
468 1.6 garbled req.cmdbuf[0] = TS102_OP_BLK_DEF_SPCL_CHAR;
469 1.6 garbled req.cmdlen = 11;
470 1.6 garbled req.rsplen = 1;
471 1.6 garbled req.cmdbuf[1] = 0x08; /*len*/
472 1.6 garbled req.cmdbuf[2] = TS102_BLK_OFF_DEF_DC_GOOD;
473 1.6 garbled req.cmdbuf[3] = 0x00; /* ..... */
474 1.6 garbled req.cmdbuf[4] = 0x00; /* ..... */
475 1.6 garbled req.cmdbuf[5] = 0x1f; /* XXXXX */
476 1.6 garbled req.cmdbuf[6] = 0x00; /* ..... */
477 1.6 garbled req.cmdbuf[7] = 0x15; /* X.X.X */
478 1.6 garbled req.cmdbuf[8] = 0x00; /* ..... */
479 1.6 garbled req.cmdbuf[9] = 0x00; /* ..... */
480 1.6 garbled req.cmdbuf[10] = 0x00; /* ..... */
481 1.6 garbled req.p = NULL;
482 1.6 garbled tadpole_request(&req, 1);
483 1.6 garbled
484 1.6 garbled req.cmdbuf[0] = TS102_OP_BLK_DEF_SPCL_CHAR;
485 1.6 garbled req.cmdlen = 11;
486 1.6 garbled req.rsplen = 1;
487 1.6 garbled req.cmdbuf[1] = 0x08; /*len*/
488 1.6 garbled req.cmdbuf[2] = TS102_BLK_OFF_DEF_BACKSLASH;
489 1.6 garbled req.cmdbuf[3] = 0x00; /* ..... */
490 1.6 garbled req.cmdbuf[4] = 0x10; /* X.... */
491 1.6 garbled req.cmdbuf[5] = 0x08; /* .X... */
492 1.6 garbled req.cmdbuf[6] = 0x04; /* ..X.. */
493 1.6 garbled req.cmdbuf[7] = 0x02; /* ...X. */
494 1.6 garbled req.cmdbuf[8] = 0x01; /* ....X */
495 1.6 garbled req.cmdbuf[9] = 0x00; /* ..... */
496 1.6 garbled req.cmdbuf[10] = 0x00; /* ..... */
497 1.6 garbled req.p = NULL;
498 1.6 garbled tadpole_request(&req, 1);
499 1.6 garbled
500 1.6 garbled req.cmdbuf[0] = TS102_OP_BLK_DEF_SPCL_CHAR;
501 1.6 garbled req.cmdlen = 11;
502 1.6 garbled req.rsplen = 1;
503 1.6 garbled req.cmdbuf[1] = 0x08; /*len*/
504 1.6 garbled req.cmdbuf[2] = TS102_BLK_OFF_DEF_WAN1;
505 1.6 garbled req.cmdbuf[3] = 0x0c; /* .XXX. */
506 1.6 garbled req.cmdbuf[4] = 0x16; /* X.XX. */
507 1.6 garbled req.cmdbuf[5] = 0x10; /* X.... */
508 1.6 garbled req.cmdbuf[6] = 0x15; /* X.X.X */
509 1.6 garbled req.cmdbuf[7] = 0x10; /* X.... */
510 1.6 garbled req.cmdbuf[8] = 0x16; /* X.XX. */
511 1.6 garbled req.cmdbuf[9] = 0x0c; /* .XXX. */
512 1.6 garbled req.cmdbuf[10] = 0x00; /* ..... */
513 1.6 garbled req.p = NULL;
514 1.6 garbled tadpole_request(&req, 1);
515 1.6 garbled
516 1.6 garbled req.cmdbuf[0] = TS102_OP_BLK_DEF_SPCL_CHAR;
517 1.6 garbled req.cmdlen = 11;
518 1.6 garbled req.rsplen = 1;
519 1.6 garbled req.cmdbuf[1] = 0x08; /*len*/
520 1.6 garbled req.cmdbuf[2] = TS102_BLK_OFF_DEF_WAN2;
521 1.6 garbled req.cmdbuf[3] = 0x0c; /* .XXX. */
522 1.6 garbled req.cmdbuf[4] = 0x0d; /* .XX.X */
523 1.6 garbled req.cmdbuf[5] = 0x01; /* ....X */
524 1.6 garbled req.cmdbuf[6] = 0x15; /* X.X.X */
525 1.6 garbled req.cmdbuf[7] = 0x01; /* ....X */
526 1.6 garbled req.cmdbuf[8] = 0x0d; /* .XX.X */
527 1.6 garbled req.cmdbuf[9] = 0x0c; /* .XXX. */
528 1.6 garbled req.cmdbuf[10] = 0x00; /* ..... */
529 1.6 garbled req.p = NULL;
530 1.6 garbled tadpole_request(&req, 1);
531 1.6 garbled
532 1.6 garbled req.cmdbuf[0] = TS102_OP_BLK_DEF_SPCL_CHAR;
533 1.6 garbled req.cmdlen = 11;
534 1.6 garbled req.rsplen = 1;
535 1.6 garbled req.cmdbuf[1] = 0x08; /*len*/
536 1.6 garbled req.cmdbuf[2] = TS102_BLK_OFF_DEF_LAN1;
537 1.6 garbled req.cmdbuf[3] = 0x00; /* ..... */
538 1.6 garbled req.cmdbuf[4] = 0x04; /* ..X.. */
539 1.6 garbled req.cmdbuf[5] = 0x08; /* .X... */
540 1.6 garbled req.cmdbuf[6] = 0x13; /* X..XX */
541 1.6 garbled req.cmdbuf[7] = 0x08; /* .X... */
542 1.6 garbled req.cmdbuf[8] = 0x04; /* ..X.. */
543 1.6 garbled req.cmdbuf[9] = 0x00; /* ..... */
544 1.6 garbled req.cmdbuf[10] = 0x00; /* ..... */
545 1.6 garbled req.p = NULL;
546 1.6 garbled tadpole_request(&req, 1);
547 1.6 garbled
548 1.6 garbled req.cmdbuf[0] = TS102_OP_BLK_DEF_SPCL_CHAR;
549 1.6 garbled req.cmdlen = 11;
550 1.6 garbled req.rsplen = 1;
551 1.6 garbled req.cmdbuf[1] = 0x08; /*len*/
552 1.6 garbled req.cmdbuf[2] = TS102_BLK_OFF_DEF_LAN2;
553 1.6 garbled req.cmdbuf[3] = 0x00; /* ..... */
554 1.6 garbled req.cmdbuf[4] = 0x04; /* ..X.. */
555 1.6 garbled req.cmdbuf[5] = 0x02; /* ...X. */
556 1.6 garbled req.cmdbuf[6] = 0x19; /* XX..X */
557 1.6 garbled req.cmdbuf[7] = 0x02; /* ...X. */
558 1.6 garbled req.cmdbuf[8] = 0x04; /* ..X.. */
559 1.6 garbled req.cmdbuf[9] = 0x00; /* ..... */
560 1.6 garbled req.cmdbuf[10] = 0x00; /* ..... */
561 1.6 garbled req.p = NULL;
562 1.6 garbled tadpole_request(&req, 1);
563 1.6 garbled
564 1.6 garbled req.cmdbuf[0] = TS102_OP_BLK_DEF_SPCL_CHAR;
565 1.6 garbled req.cmdlen = 11;
566 1.6 garbled req.rsplen = 1;
567 1.6 garbled req.cmdbuf[1] = 0x08; /*len*/
568 1.6 garbled req.cmdbuf[2] = TS102_BLK_OFF_DEF_PCMCIA;
569 1.6 garbled req.cmdbuf[3] = 0x00; /* ..... */
570 1.6 garbled req.cmdbuf[4] = 0x0c; /* .XXX. */
571 1.6 garbled req.cmdbuf[5] = 0x1f; /* XXXXX */
572 1.6 garbled req.cmdbuf[6] = 0x1f; /* XXXXX */
573 1.6 garbled req.cmdbuf[7] = 0x1f; /* XXXXX */
574 1.6 garbled req.cmdbuf[8] = 0x1f; /* XXXXX */
575 1.6 garbled req.cmdbuf[9] = 0x00; /* ..... */
576 1.6 garbled req.cmdbuf[10] = 0x00; /* ..... */
577 1.6 garbled req.p = NULL;
578 1.6 garbled tadpole_request(&req, 1);
579 1.6 garbled }
580 1.6 garbled
581 1.6 garbled
582 1.6 garbled
583 1.6 garbled /*
584 1.6 garbled * set the blinken-lights on the lcd. what:
585 1.6 garbled * what = 0 off, what = 1 on, what = 2 toggle
586 1.6 garbled */
587 1.6 garbled
588 1.6 garbled void
589 1.6 garbled tctrl_set_lcd(what, which)
590 1.6 garbled int what;
591 1.6 garbled unsigned short which;
592 1.6 garbled {
593 1.6 garbled struct tctrl_softc *sc;
594 1.6 garbled struct tctrl_req req;
595 1.6 garbled int s;
596 1.6 garbled
597 1.6 garbled sc = (struct tctrl_softc *) tctrl_cd.cd_devs[TCTRL_STD_DEV];
598 1.6 garbled s = splts102();
599 1.6 garbled
600 1.26 wiz /* provide a quick exit to save CPU time */
601 1.6 garbled if ((what == 1 && sc->sc_lcdstate & which) ||
602 1.6 garbled (what == 0 && !(sc->sc_lcdstate & which))) {
603 1.6 garbled splx(s);
604 1.6 garbled return;
605 1.6 garbled }
606 1.6 garbled /*
607 1.6 garbled * the mask setup on this particular command is *very* bizzare
608 1.6 garbled * and totally undocumented.
609 1.6 garbled */
610 1.6 garbled if ((what == 1) || (what == 2 && !(sc->sc_lcdstate & which))) {
611 1.6 garbled req.cmdbuf[2] = (u_int8_t)(which&0xff);
612 1.6 garbled req.cmdbuf[3] = (u_int8_t)(which>>8);
613 1.6 garbled } else {
614 1.6 garbled req.cmdbuf[2] = 0;
615 1.6 garbled req.cmdbuf[3] = 0;
616 1.6 garbled }
617 1.6 garbled req.cmdbuf[0] = TS102_OP_CTL_LCD;
618 1.6 garbled req.cmdbuf[4] = (u_int8_t)(~which>>8);
619 1.6 garbled req.cmdbuf[1] = (u_int8_t)(~which&0xff);
620 1.6 garbled
621 1.13 wiz /* XXX this thing is weird.... */
622 1.6 garbled req.cmdlen = 3;
623 1.6 garbled req.rsplen = 2;
624 1.6 garbled #if 0
625 1.6 garbled req.cmdlen = 5;
626 1.6 garbled req.rsplen = 4;
627 1.6 garbled #endif
628 1.6 garbled req.p = NULL;
629 1.6 garbled tadpole_request(&req, 1);
630 1.6 garbled s = splts102();
631 1.6 garbled sc->sc_lcdstate = (unsigned short)req.rspbuf[0];
632 1.6 garbled splx(s);
633 1.6 garbled }
634 1.6 garbled
635 1.4 garbled static void
636 1.4 garbled tctrl_read_ext_status(void)
637 1.4 garbled {
638 1.4 garbled struct tctrl_softc *sc;
639 1.4 garbled struct tctrl_req req;
640 1.4 garbled int s;
641 1.4 garbled
642 1.4 garbled sc = (struct tctrl_softc *) tctrl_cd.cd_devs[TCTRL_STD_DEV];
643 1.4 garbled req.cmdbuf[0] = TS102_OP_RD_EXT_STATUS;
644 1.4 garbled req.cmdlen = 1;
645 1.4 garbled req.rsplen = 3;
646 1.4 garbled req.p = NULL;
647 1.4 garbled #ifdef TCTRLDEBUG
648 1.4 garbled printf("pre read: sc->sc_ext_status = 0x%x\n", sc->sc_ext_status);
649 1.4 garbled #endif
650 1.4 garbled tadpole_request(&req, 1);
651 1.4 garbled s = splts102();
652 1.4 garbled sc->sc_ext_status = req.rspbuf[0] * 256 + req.rspbuf[1];
653 1.4 garbled splx(s);
654 1.4 garbled #ifdef TCTRLDEBUG
655 1.4 garbled printf("post read: sc->sc_ext_status = 0x%x\n", sc->sc_ext_status);
656 1.4 garbled #endif
657 1.4 garbled }
658 1.4 garbled
659 1.4 garbled /*
660 1.4 garbled * return 0 if the user will notice and handle the event,
661 1.4 garbled * return 1 if the kernel driver should do so.
662 1.4 garbled */
663 1.4 garbled static int
664 1.4 garbled tctrl_apm_record_event(sc, event_type)
665 1.4 garbled struct tctrl_softc *sc;
666 1.4 garbled u_int event_type;
667 1.4 garbled {
668 1.4 garbled struct apm_event_info *evp;
669 1.4 garbled
670 1.4 garbled if ((sc->sc_flags & TCTRL_APM_CTLOPEN) &&
671 1.4 garbled (sc->sc_event_count < APM_NEVENTS)) {
672 1.4 garbled evp = &sc->sc_event_list[sc->sc_event_ptr];
673 1.4 garbled sc->sc_event_count++;
674 1.4 garbled sc->sc_event_ptr++;
675 1.4 garbled sc->sc_event_ptr %= APM_NEVENTS;
676 1.4 garbled evp->type = event_type;
677 1.4 garbled evp->index = ++tctrl_apm_evindex;
678 1.20 jdolecek selnotify(&sc->sc_rsel, 0);
679 1.4 garbled return(sc->sc_flags & TCTRL_APM_CTLOPEN) ? 0 : 1;
680 1.1 matt }
681 1.4 garbled return(1);
682 1.1 matt }
683 1.1 matt
684 1.1 matt static void
685 1.4 garbled tctrl_read_event_status(arg)
686 1.4 garbled void *arg;
687 1.1 matt {
688 1.4 garbled struct tctrl_softc *sc;
689 1.4 garbled struct tctrl_req req;
690 1.4 garbled int s;
691 1.4 garbled unsigned int v;
692 1.4 garbled
693 1.4 garbled sc = (struct tctrl_softc *) tctrl_cd.cd_devs[TCTRL_STD_DEV];
694 1.4 garbled req.cmdbuf[0] = TS102_OP_RD_EVENT_STATUS;
695 1.4 garbled req.cmdlen = 1;
696 1.4 garbled req.rsplen = 3;
697 1.4 garbled req.p = NULL;
698 1.4 garbled tadpole_request(&req, 1);
699 1.4 garbled s = splts102();
700 1.4 garbled v = req.rspbuf[0] * 256 + req.rspbuf[1];
701 1.4 garbled if (v & TS102_EVENT_STATUS_SHUTDOWN_REQUEST) {
702 1.4 garbled printf("%s: SHUTDOWN REQUEST!\n", sc->sc_dev.dv_xname);
703 1.4 garbled }
704 1.4 garbled if (v & TS102_EVENT_STATUS_VERY_LOW_POWER_WARNING) {
705 1.4 garbled /*printf("%s: VERY LOW POWER WARNING!\n", sc->sc_dev.dv_xname);*/
706 1.4 garbled /* according to a tadpole header, and observation */
707 1.4 garbled #ifdef TCTRLDEBUG
708 1.4 garbled printf("%s: Battery charge level change\n", sc->sc_dev.dv_xname);
709 1.4 garbled #endif
710 1.1 matt }
711 1.4 garbled if (v & TS102_EVENT_STATUS_LOW_POWER_WARNING) {
712 1.4 garbled if (tctrl_apm_record_event(sc, APM_BATTERY_LOW))
713 1.1 matt printf("%s: LOW POWER WARNING!\n", sc->sc_dev.dv_xname);
714 1.4 garbled }
715 1.4 garbled if (v & TS102_EVENT_STATUS_DC_STATUS_CHANGE) {
716 1.4 garbled splx(s);
717 1.4 garbled tctrl_read_ext_status();
718 1.4 garbled s = splts102();
719 1.4 garbled if (tctrl_apm_record_event(sc, APM_POWER_CHANGE))
720 1.1 matt printf("%s: main power %s\n", sc->sc_dev.dv_xname,
721 1.4 garbled (sc->sc_ext_status &
722 1.4 garbled TS102_EXT_STATUS_MAIN_POWER_AVAILABLE) ?
723 1.4 garbled "restored" : "removed");
724 1.4 garbled }
725 1.4 garbled if (v & TS102_EVENT_STATUS_LID_STATUS_CHANGE) {
726 1.4 garbled splx(s);
727 1.4 garbled tctrl_read_ext_status();
728 1.4 garbled tctrl_setup_bitport();
729 1.4 garbled #ifdef TCTRLDEBUG
730 1.4 garbled printf("%s: lid %s\n", sc->sc_dev.dv_xname,
731 1.4 garbled (sc->sc_ext_status & TS102_EXT_STATUS_LID_DOWN)
732 1.4 garbled ? "closed" : "opened");
733 1.2 matt #endif
734 1.1 matt }
735 1.4 garbled splx(s);
736 1.1 matt }
737 1.1 matt
738 1.1 matt void
739 1.4 garbled tadpole_request(req, spin)
740 1.4 garbled struct tctrl_req *req;
741 1.4 garbled int spin;
742 1.1 matt {
743 1.1 matt struct tctrl_softc *sc;
744 1.1 matt int i, s;
745 1.1 matt
746 1.1 matt if (tctrl_cd.cd_devs == NULL
747 1.1 matt || tctrl_cd.cd_ndevs == 0
748 1.4 garbled || tctrl_cd.cd_devs[TCTRL_STD_DEV] == NULL) {
749 1.1 matt return;
750 1.1 matt }
751 1.1 matt
752 1.4 garbled sc = (struct tctrl_softc *) tctrl_cd.cd_devs[TCTRL_STD_DEV];
753 1.4 garbled while (sc->sc_wantdata != 0) {
754 1.4 garbled if (req->p != NULL)
755 1.4 garbled tsleep(&sc->sc_wantdata, PLOCK, "tctrl_lock", 10);
756 1.4 garbled else
757 1.4 garbled DELAY(1);
758 1.4 garbled }
759 1.4 garbled if (spin)
760 1.4 garbled s = splhigh();
761 1.4 garbled else
762 1.4 garbled s = splts102();
763 1.4 garbled sc->sc_flags |= TCTRL_SEND_REQUEST;
764 1.4 garbled memcpy(sc->sc_cmdbuf, req->cmdbuf, req->cmdlen);
765 1.4 garbled sc->sc_wantdata = 1;
766 1.4 garbled sc->sc_rsplen = req->rsplen;
767 1.4 garbled sc->sc_cmdlen = req->cmdlen;
768 1.4 garbled sc->sc_cmdoff = sc->sc_rspoff = 0;
769 1.4 garbled
770 1.4 garbled /* we spin for certain commands, like poweroffs */
771 1.4 garbled if (spin) {
772 1.6 garbled /* for (i = 0; i < 30000; i++) {*/
773 1.6 garbled while (sc->sc_wantdata == 1) {
774 1.4 garbled tctrl_intr(sc);
775 1.4 garbled DELAY(1);
776 1.4 garbled }
777 1.4 garbled } else {
778 1.1 matt tctrl_intr(sc);
779 1.5 garbled i = 0;
780 1.5 garbled while (((sc->sc_rspoff != sc->sc_rsplen) ||
781 1.5 garbled (sc->sc_cmdoff != sc->sc_cmdlen)) &&
782 1.5 garbled (i < (5 * sc->sc_rsplen + sc->sc_cmdlen)))
783 1.5 garbled if (req->p != NULL) {
784 1.5 garbled tsleep(sc, PWAIT, "tctrl_data", 15);
785 1.5 garbled i++;
786 1.5 garbled }
787 1.4 garbled else
788 1.4 garbled DELAY(1);
789 1.1 matt }
790 1.5 garbled /*
791 1.5 garbled * we give the user a reasonable amount of time for a command
792 1.5 garbled * to complete. If it doesn't complete in time, we hand them
793 1.5 garbled * garbage. This is here to stop things like setting the
794 1.5 garbled * rsplen too long, and sleeping forever in a CMD_REQ ioctl.
795 1.5 garbled */
796 1.5 garbled sc->sc_wantdata = 0;
797 1.4 garbled memcpy(req->rspbuf, sc->sc_rspbuf, req->rsplen);
798 1.1 matt splx(s);
799 1.1 matt }
800 1.1 matt
801 1.1 matt void
802 1.4 garbled tadpole_powerdown(void)
803 1.4 garbled {
804 1.4 garbled struct tctrl_req req;
805 1.4 garbled
806 1.4 garbled req.cmdbuf[0] = TS102_OP_ADMIN_POWER_OFF;
807 1.4 garbled req.cmdlen = 1;
808 1.4 garbled req.rsplen = 1;
809 1.4 garbled req.p = NULL;
810 1.4 garbled tadpole_request(&req, 1);
811 1.4 garbled }
812 1.4 garbled
813 1.4 garbled void
814 1.4 garbled tadpole_set_video(enabled)
815 1.4 garbled int enabled;
816 1.1 matt {
817 1.1 matt struct tctrl_softc *sc;
818 1.4 garbled struct tctrl_req req;
819 1.1 matt int s;
820 1.1 matt
821 1.4 garbled sc = (struct tctrl_softc *) tctrl_cd.cd_devs[TCTRL_STD_DEV];
822 1.4 garbled while (sc->sc_wantdata != 0)
823 1.4 garbled DELAY(1);
824 1.4 garbled s = splts102();
825 1.4 garbled req.p = NULL;
826 1.4 garbled if ((sc->sc_ext_status & TS102_EXT_STATUS_LID_DOWN && !enabled)
827 1.4 garbled || (sc->sc_tft_on)) {
828 1.4 garbled req.cmdbuf[2] = TS102_BITPORT_TFTPWR;
829 1.4 garbled } else {
830 1.4 garbled req.cmdbuf[2] = 0;
831 1.1 matt }
832 1.4 garbled req.cmdbuf[0] = TS102_OP_CTL_BITPORT;
833 1.4 garbled req.cmdbuf[1] = ~TS102_BITPORT_TFTPWR;
834 1.4 garbled req.cmdlen = 3;
835 1.4 garbled req.rsplen = 2;
836 1.1 matt
837 1.1 matt if ((sc->sc_tft_on && !enabled) || (!sc->sc_tft_on && enabled)) {
838 1.1 matt sc->sc_tft_on = enabled;
839 1.1 matt if (sc->sc_ext_status & TS102_EXT_STATUS_LID_DOWN) {
840 1.1 matt splx(s);
841 1.1 matt return;
842 1.1 matt }
843 1.4 garbled tadpole_request(&req, 1);
844 1.4 garbled sc->sc_bitport =
845 1.4 garbled (req.rspbuf[0] & req.cmdbuf[1]) ^ req.cmdbuf[2];
846 1.1 matt }
847 1.1 matt splx(s);
848 1.1 matt }
849 1.1 matt
850 1.1 matt static void
851 1.4 garbled tctrl_write_data(sc, v)
852 1.4 garbled struct tctrl_softc *sc;
853 1.4 garbled u_int8_t v;
854 1.1 matt {
855 1.1 matt unsigned int i;
856 1.4 garbled
857 1.1 matt for (i = 0; i < 100; i++) {
858 1.2 matt if (TS102_UCTRL_STS_TXNF_STA & tctrl_read(sc, TS102_REG_UCTRL_STS))
859 1.1 matt break;
860 1.1 matt }
861 1.1 matt tctrl_write(sc, TS102_REG_UCTRL_DATA, v);
862 1.1 matt }
863 1.1 matt
864 1.1 matt static u_int8_t
865 1.4 garbled tctrl_read_data(sc)
866 1.4 garbled struct tctrl_softc *sc;
867 1.4 garbled {
868 1.1 matt unsigned int i, v;
869 1.1 matt
870 1.1 matt for (i = 0; i < 100000; i++) {
871 1.2 matt if (TS102_UCTRL_STS_RXNE_STA & tctrl_read(sc, TS102_REG_UCTRL_STS))
872 1.1 matt break;
873 1.1 matt DELAY(1);
874 1.1 matt }
875 1.1 matt
876 1.1 matt v = tctrl_read(sc, TS102_REG_UCTRL_DATA);
877 1.2 matt tctrl_write(sc, TS102_REG_UCTRL_STS, TS102_UCTRL_STS_RXNE_STA);
878 1.1 matt return v;
879 1.1 matt }
880 1.1 matt
881 1.1 matt static u_int8_t
882 1.4 garbled tctrl_read(sc, off)
883 1.4 garbled struct tctrl_softc *sc;
884 1.4 garbled bus_size_t off;
885 1.1 matt {
886 1.4 garbled
887 1.2 matt sc->sc_junk = bus_space_read_1(sc->sc_memt, sc->sc_memh, off);
888 1.1 matt return sc->sc_junk;
889 1.1 matt }
890 1.1 matt
891 1.1 matt static void
892 1.4 garbled tctrl_write(sc, off, v)
893 1.4 garbled struct tctrl_softc *sc;
894 1.4 garbled bus_size_t off;
895 1.4 garbled u_int8_t v;
896 1.1 matt {
897 1.4 garbled
898 1.1 matt sc->sc_junk = v;
899 1.2 matt bus_space_write_1(sc->sc_memt, sc->sc_memh, off, v);
900 1.4 garbled }
901 1.4 garbled
902 1.4 garbled int
903 1.24 fvdl tctrlopen(dev, flags, mode, p)
904 1.4 garbled dev_t dev;
905 1.4 garbled int flags, mode;
906 1.24 fvdl struct proc *p;
907 1.4 garbled {
908 1.4 garbled int unit = (minor(dev)&0xf0);
909 1.4 garbled int ctl = (minor(dev)&0x0f);
910 1.4 garbled struct tctrl_softc *sc;
911 1.4 garbled
912 1.4 garbled if (unit >= tctrl_cd.cd_ndevs)
913 1.4 garbled return(ENXIO);
914 1.4 garbled sc = tctrl_cd.cd_devs[TCTRL_STD_DEV];
915 1.4 garbled if (!sc)
916 1.4 garbled return(ENXIO);
917 1.4 garbled
918 1.4 garbled switch (ctl) {
919 1.4 garbled case TCTRL_STD_DEV:
920 1.4 garbled break;
921 1.4 garbled case TCTRL_APMCTL_DEV:
922 1.4 garbled if (!(flags & FWRITE))
923 1.4 garbled return(EINVAL);
924 1.4 garbled if (sc->sc_flags & TCTRL_APM_CTLOPEN)
925 1.4 garbled return(EBUSY);
926 1.4 garbled sc->sc_flags |= TCTRL_APM_CTLOPEN;
927 1.4 garbled break;
928 1.4 garbled default:
929 1.4 garbled return(ENXIO);
930 1.4 garbled break;
931 1.4 garbled }
932 1.4 garbled
933 1.4 garbled return(0);
934 1.4 garbled }
935 1.4 garbled
936 1.4 garbled int
937 1.24 fvdl tctrlclose(dev, flags, mode, p)
938 1.4 garbled dev_t dev;
939 1.4 garbled int flags, mode;
940 1.24 fvdl struct proc *p;
941 1.4 garbled {
942 1.4 garbled int ctl = (minor(dev)&0x0f);
943 1.4 garbled struct tctrl_softc *sc;
944 1.4 garbled
945 1.4 garbled sc = tctrl_cd.cd_devs[TCTRL_STD_DEV];
946 1.4 garbled if (!sc)
947 1.4 garbled return(ENXIO);
948 1.4 garbled
949 1.4 garbled switch (ctl) {
950 1.4 garbled case TCTRL_STD_DEV:
951 1.4 garbled break;
952 1.4 garbled case TCTRL_APMCTL_DEV:
953 1.4 garbled sc->sc_flags &= ~TCTRL_APM_CTLOPEN;
954 1.4 garbled break;
955 1.4 garbled }
956 1.4 garbled return(0);
957 1.4 garbled }
958 1.4 garbled
959 1.4 garbled int
960 1.24 fvdl tctrlioctl(dev, cmd, data, flags, p)
961 1.4 garbled dev_t dev;
962 1.4 garbled u_long cmd;
963 1.4 garbled caddr_t data;
964 1.4 garbled int flags;
965 1.24 fvdl struct proc *p;
966 1.4 garbled {
967 1.4 garbled struct tctrl_req req, *reqn;
968 1.7 jdc struct tctrl_pwr *pwrreq;
969 1.4 garbled envsys_range_t *envrange;
970 1.4 garbled envsys_temp_data_t *envdata;
971 1.4 garbled envsys_temp_info_t *envinfo;
972 1.4 garbled struct apm_power_info *powerp;
973 1.4 garbled struct apm_event_info *evp;
974 1.4 garbled struct tctrl_softc *sc;
975 1.4 garbled int i;
976 1.4 garbled u_int j;
977 1.4 garbled u_int16_t a;
978 1.4 garbled u_int8_t c;
979 1.4 garbled
980 1.4 garbled if (tctrl_cd.cd_devs == NULL
981 1.4 garbled || tctrl_cd.cd_ndevs == 0
982 1.4 garbled || tctrl_cd.cd_devs[TCTRL_STD_DEV] == NULL) {
983 1.4 garbled return ENXIO;
984 1.4 garbled }
985 1.4 garbled sc = (struct tctrl_softc *) tctrl_cd.cd_devs[TCTRL_STD_DEV];
986 1.4 garbled switch (cmd) {
987 1.4 garbled
988 1.4 garbled case APM_IOC_STANDBY:
989 1.4 garbled return(EOPNOTSUPP); /* for now */
990 1.4 garbled
991 1.4 garbled case APM_IOC_SUSPEND:
992 1.4 garbled return(EOPNOTSUPP); /* for now */
993 1.4 garbled
994 1.19 takemura case OAPM_IOC_GETPOWER:
995 1.4 garbled case APM_IOC_GETPOWER:
996 1.4 garbled powerp = (struct apm_power_info *)data;
997 1.4 garbled req.cmdbuf[0] = TS102_OP_RD_INT_CHARGE_RATE;
998 1.4 garbled req.cmdlen = 1;
999 1.4 garbled req.rsplen = 2;
1000 1.4 garbled req.p = p;
1001 1.4 garbled tadpole_request(&req, 0);
1002 1.4 garbled if (req.rspbuf[0] > 0x00)
1003 1.4 garbled powerp->battery_state = APM_BATT_CHARGING;
1004 1.4 garbled req.cmdbuf[0] = TS102_OP_RD_INT_CHARGE_LEVEL;
1005 1.4 garbled req.cmdlen = 1;
1006 1.4 garbled req.rsplen = 3;
1007 1.4 garbled req.p = p;
1008 1.4 garbled tadpole_request(&req, 0);
1009 1.4 garbled c = req.rspbuf[0];
1010 1.4 garbled powerp->battery_life = c;
1011 1.6 garbled if (c > 0x70) /* the tadpole sometimes dips below zero, and */
1012 1.6 garbled c = 0; /* into the 255 range. */
1013 1.4 garbled powerp->minutes_left = (45 * c) / 100; /* XXX based on 45 min */
1014 1.4 garbled if (powerp->battery_state != APM_BATT_CHARGING) {
1015 1.4 garbled if (c < 0x20)
1016 1.4 garbled powerp->battery_state = APM_BATT_CRITICAL;
1017 1.4 garbled else if (c < 0x40)
1018 1.4 garbled powerp->battery_state = APM_BATT_LOW;
1019 1.4 garbled else if (c < 0x66)
1020 1.4 garbled powerp->battery_state = APM_BATT_HIGH;
1021 1.4 garbled else
1022 1.4 garbled powerp->battery_state = APM_BATT_UNKNOWN;
1023 1.4 garbled }
1024 1.4 garbled req.cmdbuf[0] = TS102_OP_RD_EXT_STATUS;
1025 1.4 garbled req.cmdlen = 1;
1026 1.4 garbled req.rsplen = 3;
1027 1.4 garbled req.p = p;
1028 1.4 garbled tadpole_request(&req, 0);
1029 1.4 garbled a = req.rspbuf[0] * 256 + req.rspbuf[1];
1030 1.4 garbled if (a & TS102_EXT_STATUS_MAIN_POWER_AVAILABLE)
1031 1.4 garbled powerp->ac_state = APM_AC_ON;
1032 1.4 garbled else
1033 1.4 garbled powerp->ac_state = APM_AC_OFF;
1034 1.4 garbled break;
1035 1.4 garbled
1036 1.4 garbled case APM_IOC_NEXTEVENT:
1037 1.4 garbled if (!sc->sc_event_count)
1038 1.4 garbled return EAGAIN;
1039 1.4 garbled
1040 1.4 garbled evp = (struct apm_event_info *)data;
1041 1.4 garbled i = sc->sc_event_ptr + APM_NEVENTS - sc->sc_event_count;
1042 1.4 garbled i %= APM_NEVENTS;
1043 1.4 garbled *evp = sc->sc_event_list[i];
1044 1.4 garbled sc->sc_event_count--;
1045 1.4 garbled return(0);
1046 1.4 garbled
1047 1.4 garbled /* this ioctl assumes the caller knows exactly what he is doing */
1048 1.4 garbled case TCTRL_CMD_REQ:
1049 1.4 garbled reqn = (struct tctrl_req *)data;
1050 1.4 garbled if ((i = suser(p->p_ucred, &p->p_acflag)) != 0 &&
1051 1.4 garbled (reqn->cmdbuf[0] == TS102_OP_CTL_BITPORT ||
1052 1.4 garbled (reqn->cmdbuf[0] >= TS102_OP_CTL_WATCHDOG &&
1053 1.4 garbled reqn->cmdbuf[0] <= TS102_OP_CTL_SECURITY_KEY) ||
1054 1.4 garbled reqn->cmdbuf[0] == TS102_OP_CTL_TIMEZONE ||
1055 1.4 garbled reqn->cmdbuf[0] == TS102_OP_CTL_DIAGNOSTIC_MODE ||
1056 1.4 garbled reqn->cmdbuf[0] == TS102_OP_CMD_SOFTWARE_RESET ||
1057 1.4 garbled (reqn->cmdbuf[0] >= TS102_OP_CMD_SET_RTC &&
1058 1.4 garbled reqn->cmdbuf[0] < TS102_OP_RD_INT_CHARGE_LEVEL) ||
1059 1.4 garbled reqn->cmdbuf[0] > TS102_OP_RD_EXT_CHARGE_LEVEL))
1060 1.4 garbled return(i);
1061 1.4 garbled reqn->p = p;
1062 1.4 garbled tadpole_request(reqn, 0);
1063 1.4 garbled break;
1064 1.4 garbled
1065 1.4 garbled case ENVSYS_VERSION:
1066 1.4 garbled *(int32_t *)data = 1000;
1067 1.4 garbled break;
1068 1.4 garbled
1069 1.4 garbled case ENVSYS_GRANGE:
1070 1.4 garbled envrange = (envsys_range_t *)data;
1071 1.4 garbled i = 0;
1072 1.4 garbled envrange->high = envrange->low = 0;
1073 1.4 garbled for (j=0; j < ENVSYS_NUMSENSORS; j++) {
1074 1.4 garbled if (!i && envrange->units == sc->sc_esensors[j].units) {
1075 1.4 garbled envrange->low = j;
1076 1.4 garbled i++;
1077 1.4 garbled }
1078 1.4 garbled if (i && envrange->units == sc->sc_esensors[j].units)
1079 1.4 garbled envrange->high = j;
1080 1.4 garbled }
1081 1.4 garbled if (!i) {
1082 1.4 garbled envrange->high = 0;
1083 1.4 garbled envrange->low = 1;
1084 1.4 garbled }
1085 1.4 garbled break;
1086 1.4 garbled
1087 1.4 garbled case ENVSYS_GTREDATA:
1088 1.4 garbled envdata = (envsys_temp_data_t *)data;
1089 1.4 garbled if (envdata->sensor >= ENVSYS_NUMSENSORS) {
1090 1.4 garbled envdata->validflags = 0;
1091 1.4 garbled break;
1092 1.4 garbled }
1093 1.4 garbled envdata->warnflags = ENVSYS_WARN_OK;
1094 1.4 garbled if (envdata->sensor == 0) {
1095 1.4 garbled envdata->validflags |= ENVSYS_FVALID;
1096 1.4 garbled req.cmdbuf[0] = TS102_OP_RD_CURRENT_TEMP;
1097 1.4 garbled req.cmdlen = 1;
1098 1.4 garbled req.rsplen = 2;
1099 1.4 garbled req.p = p;
1100 1.4 garbled tadpole_request(&req, 0);
1101 1.4 garbled envdata->cur.data_us = /* 273160? */
1102 1.6 garbled (u_int32_t)((int)((int)req.rspbuf[0]-32)*5000000/9+273150000);
1103 1.4 garbled envdata->validflags |= ENVSYS_FCURVALID;
1104 1.4 garbled req.cmdbuf[0] = TS102_OP_RD_MAX_TEMP;
1105 1.4 garbled req.cmdlen = 1;
1106 1.4 garbled req.rsplen = 2;
1107 1.4 garbled req.p = p;
1108 1.4 garbled tadpole_request(&req, 0);
1109 1.4 garbled envdata->max.data_us =
1110 1.6 garbled (u_int32_t)((int)((int)req.rspbuf[0]-32)*5000000/9+273150000);
1111 1.4 garbled envdata->validflags |= ENVSYS_FMAXVALID;
1112 1.4 garbled req.cmdbuf[0] = TS102_OP_RD_MIN_TEMP;
1113 1.4 garbled req.cmdlen = 1;
1114 1.4 garbled req.rsplen = 2;
1115 1.4 garbled req.p = p;
1116 1.4 garbled tadpole_request(&req, 0);
1117 1.4 garbled envdata->min.data_us =
1118 1.6 garbled (u_int32_t)((int)((int)req.rspbuf[0]-32)*5000000/9+273150000);
1119 1.4 garbled envdata->validflags |= ENVSYS_FMINVALID;
1120 1.4 garbled envdata->units = sc->sc_esensors[envdata->sensor].units;
1121 1.4 garbled break;
1122 1.4 garbled } else if (envdata->sensor == 1 || envdata->sensor == 2) {
1123 1.4 garbled envdata->validflags = ENVSYS_FVALID|ENVSYS_FCURVALID;
1124 1.4 garbled envdata->units = sc->sc_esensors[envdata->sensor].units;
1125 1.4 garbled if (envdata->sensor == 1)
1126 1.4 garbled req.cmdbuf[0] = TS102_OP_RD_INT_BATT_VLT;
1127 1.4 garbled else
1128 1.4 garbled req.cmdbuf[0] = TS102_OP_RD_DC_IN_VLT;
1129 1.4 garbled req.cmdlen = 1;
1130 1.4 garbled req.rsplen = 2;
1131 1.4 garbled req.p = p;
1132 1.4 garbled tadpole_request(&req, 0);
1133 1.6 garbled envdata->cur.data_s = (int32_t)req.rspbuf[0]*1000000/11;
1134 1.4 garbled break;
1135 1.4 garbled }
1136 1.4 garbled break;
1137 1.4 garbled
1138 1.4 garbled case ENVSYS_GTREINFO:
1139 1.4 garbled envinfo = (envsys_temp_info_t *)data;
1140 1.4 garbled if (envinfo->sensor >= ENVSYS_NUMSENSORS) {
1141 1.4 garbled envinfo->validflags = 0;
1142 1.4 garbled break;
1143 1.4 garbled }
1144 1.4 garbled envinfo->units = sc->sc_esensors[envinfo->sensor].units;
1145 1.4 garbled memcpy(envinfo->desc, sc->sc_esensors[envinfo->sensor].desc,
1146 1.4 garbled sizeof(sc->sc_esensors[envinfo->sensor].desc) >
1147 1.4 garbled sizeof(envinfo->desc) ? sizeof(envinfo->desc) :
1148 1.4 garbled sizeof(sc->sc_esensors[envinfo->sensor].desc));
1149 1.4 garbled if (envinfo->units == ENVSYS_STEMP) {
1150 1.4 garbled envinfo->validflags = ENVSYS_FVALID|ENVSYS_FCURVALID|
1151 1.4 garbled ENVSYS_FMINVALID|ENVSYS_FMAXVALID;
1152 1.4 garbled } else if (envinfo->units == ENVSYS_SVOLTS_DC) {
1153 1.4 garbled envinfo->validflags = ENVSYS_FVALID|ENVSYS_FCURVALID;
1154 1.4 garbled } else
1155 1.4 garbled envinfo->validflags = 0;
1156 1.4 garbled break;
1157 1.4 garbled
1158 1.4 garbled case ENVSYS_STREINFO:
1159 1.4 garbled envinfo = (envsys_temp_info_t *)data;
1160 1.4 garbled if (envinfo->sensor >= ENVSYS_NUMSENSORS) {
1161 1.4 garbled envinfo->validflags = 0;
1162 1.4 garbled break;
1163 1.4 garbled }
1164 1.4 garbled if (envinfo->units == sc->sc_esensors[envinfo->sensor].units)
1165 1.4 garbled memcpy(sc->sc_esensors[envinfo->sensor].desc,
1166 1.4 garbled envinfo->desc,
1167 1.4 garbled sizeof(envinfo->desc) > sizeof(char)*32 ?
1168 1.4 garbled sizeof(char)*32 : sizeof(envinfo->desc) );
1169 1.4 garbled if (envinfo->units == ENVSYS_STEMP) {
1170 1.4 garbled envinfo->validflags = ENVSYS_FVALID|ENVSYS_FCURVALID|
1171 1.4 garbled ENVSYS_FMINVALID|ENVSYS_FMAXVALID;
1172 1.4 garbled } else if (envinfo->units == ENVSYS_SVOLTS_DC) {
1173 1.4 garbled envinfo->validflags = ENVSYS_FVALID|ENVSYS_FCURVALID;
1174 1.4 garbled } else
1175 1.4 garbled envinfo->validflags = 0;
1176 1.4 garbled break;
1177 1.7 jdc
1178 1.7 jdc /* serial power mode (via auxiotwo) */
1179 1.7 jdc case TCTRL_SERIAL_PWR:
1180 1.7 jdc pwrreq = (struct tctrl_pwr *)data;
1181 1.7 jdc if (pwrreq->rw)
1182 1.7 jdc pwrreq->state = auxiotwoserialgetapm();
1183 1.7 jdc else
1184 1.7 jdc auxiotwoserialsetapm(pwrreq->state);
1185 1.7 jdc break;
1186 1.7 jdc
1187 1.7 jdc /* modem power mode (via auxio) */
1188 1.7 jdc case TCTRL_MODEM_PWR:
1189 1.7 jdc return(EOPNOTSUPP); /* for now */
1190 1.7 jdc break;
1191 1.4 garbled
1192 1.4 garbled
1193 1.4 garbled default:
1194 1.4 garbled return (ENOTTY);
1195 1.4 garbled }
1196 1.4 garbled return (0);
1197 1.4 garbled }
1198 1.4 garbled
1199 1.4 garbled int
1200 1.24 fvdl tctrlpoll(dev, events, p)
1201 1.4 garbled dev_t dev;
1202 1.4 garbled int events;
1203 1.24 fvdl struct proc *p;
1204 1.4 garbled {
1205 1.4 garbled struct tctrl_softc *sc = tctrl_cd.cd_devs[TCTRL_STD_DEV];
1206 1.4 garbled int revents = 0;
1207 1.4 garbled
1208 1.4 garbled if (events & (POLLIN | POLLRDNORM)) {
1209 1.4 garbled if (sc->sc_event_count)
1210 1.4 garbled revents |= events & (POLLIN | POLLRDNORM);
1211 1.4 garbled else
1212 1.24 fvdl selrecord(p, &sc->sc_rsel);
1213 1.4 garbled }
1214 1.4 garbled
1215 1.4 garbled return (revents);
1216 1.1 matt }
1217 1.20 jdolecek
1218 1.20 jdolecek static void
1219 1.20 jdolecek filt_tctrlrdetach(struct knote *kn)
1220 1.20 jdolecek {
1221 1.20 jdolecek struct tctrl_softc *sc = kn->kn_hook;
1222 1.20 jdolecek int s;
1223 1.20 jdolecek
1224 1.20 jdolecek s = splts102();
1225 1.21 christos SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
1226 1.20 jdolecek splx(s);
1227 1.20 jdolecek }
1228 1.20 jdolecek
1229 1.20 jdolecek static int
1230 1.20 jdolecek filt_tctrlread(struct knote *kn, long hint)
1231 1.20 jdolecek {
1232 1.20 jdolecek struct tctrl_softc *sc = kn->kn_hook;
1233 1.20 jdolecek
1234 1.20 jdolecek kn->kn_data = sc->sc_event_count;
1235 1.20 jdolecek return (kn->kn_data > 0);
1236 1.20 jdolecek }
1237 1.20 jdolecek
1238 1.20 jdolecek static const struct filterops tctrlread_filtops =
1239 1.20 jdolecek { 1, NULL, filt_tctrlrdetach, filt_tctrlread };
1240 1.20 jdolecek
1241 1.20 jdolecek int
1242 1.20 jdolecek tctrlkqfilter(dev_t dev, struct knote *kn)
1243 1.20 jdolecek {
1244 1.20 jdolecek struct tctrl_softc *sc = tctrl_cd.cd_devs[TCTRL_STD_DEV];
1245 1.20 jdolecek struct klist *klist;
1246 1.20 jdolecek int s;
1247 1.20 jdolecek
1248 1.20 jdolecek switch (kn->kn_filter) {
1249 1.20 jdolecek case EVFILT_READ:
1250 1.21 christos klist = &sc->sc_rsel.sel_klist;
1251 1.20 jdolecek kn->kn_fop = &tctrlread_filtops;
1252 1.20 jdolecek break;
1253 1.20 jdolecek
1254 1.20 jdolecek default:
1255 1.20 jdolecek return (1);
1256 1.20 jdolecek }
1257 1.20 jdolecek
1258 1.20 jdolecek kn->kn_hook = sc;
1259 1.20 jdolecek
1260 1.20 jdolecek s = splts102();
1261 1.20 jdolecek SLIST_INSERT_HEAD(klist, kn, kn_selnext);
1262 1.20 jdolecek splx(s);
1263 1.20 jdolecek
1264 1.20 jdolecek return (0);
1265 1.20 jdolecek }
1266 1.20 jdolecek
1267 1.6 garbled /* DO NOT SET THIS OPTION */
1268 1.6 garbled #ifdef TADPOLE_BLINK
1269 1.6 garbled void
1270 1.6 garbled cpu_disk_unbusy(busy)
1271 1.6 garbled int busy;
1272 1.6 garbled {
1273 1.6 garbled static struct timeval tctrl_ds_timestamp;
1274 1.6 garbled struct timeval dv_time, diff_time;
1275 1.6 garbled struct tctrl_softc *sc;
1276 1.6 garbled
1277 1.6 garbled sc = (struct tctrl_softc *) tctrl_cd.cd_devs[TCTRL_STD_DEV];
1278 1.6 garbled
1279 1.6 garbled /* quickly bail */
1280 1.6 garbled if (!(sc->sc_lcdstate & TS102_LCD_DISK_ACTIVE) || busy > 0)
1281 1.6 garbled return;
1282 1.6 garbled
1283 1.6 garbled /* we aren't terribly concerned with precision here */
1284 1.6 garbled dv_time = mono_time;
1285 1.6 garbled timersub(&dv_time, &tctrl_ds_timestamp, &diff_time);
1286 1.6 garbled
1287 1.6 garbled if (diff_time.tv_sec > 0) {
1288 1.6 garbled tctrl_set_lcd(0, TS102_LCD_DISK_ACTIVE);
1289 1.6 garbled tctrl_ds_timestamp = mono_time;
1290 1.6 garbled }
1291 1.6 garbled }
1292 1.6 garbled #endif
1293