adb_bus.c (b4dbc59983da8183f4903279f079a2ad354a1011) adb_bus.c (014186973a878597d8ed7f51429ee4309b917f97)
1/*-
2 * Copyright (C) 2008 Nathan Whitehorn
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 30 unchanged lines hidden (view full) ---

39#include <vm/pmap.h>
40
41#include "adb.h"
42#include "adbvar.h"
43
44static int adb_bus_probe(device_t dev);
45static int adb_bus_attach(device_t dev);
46static int adb_bus_detach(device_t dev);
1/*-
2 * Copyright (C) 2008 Nathan Whitehorn
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 30 unchanged lines hidden (view full) ---

39#include <vm/pmap.h>
40
41#include "adb.h"
42#include "adbvar.h"
43
44static int adb_bus_probe(device_t dev);
45static int adb_bus_attach(device_t dev);
46static int adb_bus_detach(device_t dev);
47static void adb_bus_enumerate(void *xdev);
47static void adb_probe_nomatch(device_t dev, device_t child);
48static int adb_print_child(device_t dev, device_t child);
49
50static int adb_send_raw_packet_sync(device_t dev, uint8_t to, uint8_t command, uint8_t reg, int len, u_char *data);
51
52static char *adb_device_string[] = {
53 "HOST", "dongle", "keyboard", "mouse", "tablet", "modem", "RESERVED", "misc"
54};

--- 28 unchanged lines hidden (view full) ---

83 device_set_desc(dev, "Apple Desktop Bus");
84 return (0);
85}
86
87static int
88adb_bus_attach(device_t dev)
89{
90 struct adb_softc *sc = device_get_softc(dev);
48static void adb_probe_nomatch(device_t dev, device_t child);
49static int adb_print_child(device_t dev, device_t child);
50
51static int adb_send_raw_packet_sync(device_t dev, uint8_t to, uint8_t command, uint8_t reg, int len, u_char *data);
52
53static char *adb_device_string[] = {
54 "HOST", "dongle", "keyboard", "mouse", "tablet", "modem", "RESERVED", "misc"
55};

--- 28 unchanged lines hidden (view full) ---

84 device_set_desc(dev, "Apple Desktop Bus");
85 return (0);
86}
87
88static int
89adb_bus_attach(device_t dev)
90{
91 struct adb_softc *sc = device_get_softc(dev);
92 sc->enum_hook.ich_func = adb_bus_enumerate;
93 sc->enum_hook.ich_arg = dev;
94
95 /*
96 * We should wait until interrupts are enabled to try to probe
97 * the bus. Enumerating the ADB involves receiving packets,
98 * which works best with interrupts enabled.
99 */
100
101 if (config_intrhook_establish(&sc->enum_hook) != 0)
102 return (ENOMEM);
103
104 return (0);
105}
106
107static void
108adb_bus_enumerate(void *xdev)
109{
110 device_t dev = (device_t)xdev;
111
112 struct adb_softc *sc = device_get_softc(dev);
91 uint8_t i, next_free;
92 uint16_t r3;
93
94 sc->sc_dev = dev;
95 sc->parent = device_get_parent(dev);
96
97 sc->packet_reply = 0;
98 sc->autopoll_mask = 0;

--- 61 unchanged lines hidden (view full) ---

160
161 for (i = 0; i < 16; i++) {
162 if (sc->devinfo[i].default_address) {
163 sc->children[i] = device_add_child(dev, NULL, -1);
164 device_set_ivars(sc->children[i], &sc->devinfo[i]);
165 }
166 }
167
113 uint8_t i, next_free;
114 uint16_t r3;
115
116 sc->sc_dev = dev;
117 sc->parent = device_get_parent(dev);
118
119 sc->packet_reply = 0;
120 sc->autopoll_mask = 0;

--- 61 unchanged lines hidden (view full) ---

182
183 for (i = 0; i < 16; i++) {
184 if (sc->devinfo[i].default_address) {
185 sc->children[i] = device_add_child(dev, NULL, -1);
186 device_set_ivars(sc->children[i], &sc->devinfo[i]);
187 }
188 }
189
168 return (bus_generic_attach(dev));
190 bus_generic_attach(dev);
191
192 config_intrhook_disestablish(&sc->enum_hook);
169}
170
171static int adb_bus_detach(device_t dev)
172{
173 struct adb_softc *sc = device_get_softc(dev);
174
175 mtx_destroy(&sc->sc_sync_mtx);
176

--- 133 unchanged lines hidden (view full) ---

310 mtx_lock(&sc->sc_sync_mtx);
311
312 sc->packet_reply = 0;
313 sc->sync_packet = command_byte;
314
315 ADB_HB_SEND_RAW_PACKET(sc->parent, command_byte, len, data, 1);
316
317 while (!atomic_fetchadd_int(&sc->packet_reply,0)) {
193}
194
195static int adb_bus_detach(device_t dev)
196{
197 struct adb_softc *sc = device_get_softc(dev);
198
199 mtx_destroy(&sc->sc_sync_mtx);
200

--- 133 unchanged lines hidden (view full) ---

334 mtx_lock(&sc->sc_sync_mtx);
335
336 sc->packet_reply = 0;
337 sc->sync_packet = command_byte;
338
339 ADB_HB_SEND_RAW_PACKET(sc->parent, command_byte, len, data, 1);
340
341 while (!atomic_fetchadd_int(&sc->packet_reply,0)) {
318 /* Sometimes CUDA controllers hang up during cold boots.
319 Try poking them. */
320 if (i > 10)
321 ADB_HB_CONTROLLER_POLL(sc->parent);
342 /*
343 * Maybe the command got lost? Try resending and polling the
344 * controller.
345 */
346 if (i > 40)
347 ADB_HB_SEND_RAW_PACKET(sc->parent, command_byte,
348 len, data, 1);
322
323 DELAY(100);
324 i++;
325 }
326
327 result = sc->packet_reply - 1;
328
329 /* Clear packet sync */

--- 55 unchanged lines hidden ---
349
350 DELAY(100);
351 i++;
352 }
353
354 result = sc->packet_reply - 1;
355
356 /* Clear packet sync */

--- 55 unchanged lines hidden ---