17a880d93SLaurent Vivier /* 27a880d93SLaurent Vivier * QEMU ADB emulation shared definitions and prototypes 37a880d93SLaurent Vivier * 47a880d93SLaurent Vivier * Copyright (c) 2004-2007 Fabrice Bellard 57a880d93SLaurent Vivier * Copyright (c) 2007 Jocelyn Mayer 67a880d93SLaurent Vivier * 77a880d93SLaurent Vivier * Permission is hereby granted, free of charge, to any person obtaining a copy 87a880d93SLaurent Vivier * of this software and associated documentation files (the "Software"), to deal 97a880d93SLaurent Vivier * in the Software without restriction, including without limitation the rights 107a880d93SLaurent Vivier * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 117a880d93SLaurent Vivier * copies of the Software, and to permit persons to whom the Software is 127a880d93SLaurent Vivier * furnished to do so, subject to the following conditions: 137a880d93SLaurent Vivier * 147a880d93SLaurent Vivier * The above copyright notice and this permission notice shall be included in 157a880d93SLaurent Vivier * all copies or substantial portions of the Software. 167a880d93SLaurent Vivier * 177a880d93SLaurent Vivier * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 187a880d93SLaurent Vivier * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 197a880d93SLaurent Vivier * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 207a880d93SLaurent Vivier * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 217a880d93SLaurent Vivier * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 227a880d93SLaurent Vivier * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 237a880d93SLaurent Vivier * THE SOFTWARE. 247a880d93SLaurent Vivier */ 257a880d93SLaurent Vivier 262a6a4076SMarkus Armbruster #ifndef ADB_H 272a6a4076SMarkus Armbruster #define ADB_H 287a880d93SLaurent Vivier 29a27bd6c7SMarkus Armbruster #include "hw/qdev-core.h" 3084ede329SAndreas Färber 317a880d93SLaurent Vivier #define MAX_ADB_DEVICES 16 327a880d93SLaurent Vivier 337a880d93SLaurent Vivier #define ADB_MAX_OUT_LEN 16 347a880d93SLaurent Vivier 3584ede329SAndreas Färber typedef struct ADBBusState ADBBusState; 367a880d93SLaurent Vivier typedef struct ADBDevice ADBDevice; 377a880d93SLaurent Vivier 387a880d93SLaurent Vivier /* buf = NULL means polling */ 397a880d93SLaurent Vivier typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out, 407a880d93SLaurent Vivier const uint8_t *buf, int len); 412e4a7c9cSAndreas Färber 42969ca2f7SMark Cave-Ayland typedef bool ADBDeviceHasData(ADBDevice *d); 43969ca2f7SMark Cave-Ayland 442e4a7c9cSAndreas Färber #define TYPE_ADB_DEVICE "adb-device" 452e4a7c9cSAndreas Färber #define ADB_DEVICE(obj) OBJECT_CHECK(ADBDevice, (obj), TYPE_ADB_DEVICE) 467a880d93SLaurent Vivier 477a880d93SLaurent Vivier struct ADBDevice { 482e4a7c9cSAndreas Färber /*< private >*/ 492e4a7c9cSAndreas Färber DeviceState parent_obj; 502e4a7c9cSAndreas Färber /*< public >*/ 512e4a7c9cSAndreas Färber 527a880d93SLaurent Vivier int devaddr; 537a880d93SLaurent Vivier int handler; 547a880d93SLaurent Vivier }; 557a880d93SLaurent Vivier 562e4a7c9cSAndreas Färber #define ADB_DEVICE_CLASS(cls) \ 572e4a7c9cSAndreas Färber OBJECT_CLASS_CHECK(ADBDeviceClass, (cls), TYPE_ADB_DEVICE) 582e4a7c9cSAndreas Färber #define ADB_DEVICE_GET_CLASS(obj) \ 592e4a7c9cSAndreas Färber OBJECT_GET_CLASS(ADBDeviceClass, (obj), TYPE_ADB_DEVICE) 602e4a7c9cSAndreas Färber 612e4a7c9cSAndreas Färber typedef struct ADBDeviceClass { 622e4a7c9cSAndreas Färber /*< private >*/ 632e4a7c9cSAndreas Färber DeviceClass parent_class; 642e4a7c9cSAndreas Färber /*< public >*/ 652e4a7c9cSAndreas Färber 662e4a7c9cSAndreas Färber ADBDeviceRequest *devreq; 67969ca2f7SMark Cave-Ayland ADBDeviceHasData *devhasdata; 682e4a7c9cSAndreas Färber } ADBDeviceClass; 692e4a7c9cSAndreas Färber 7084ede329SAndreas Färber #define TYPE_ADB_BUS "apple-desktop-bus" 7184ede329SAndreas Färber #define ADB_BUS(obj) OBJECT_CHECK(ADBBusState, (obj), TYPE_ADB_BUS) 7284ede329SAndreas Färber 73*3fe02cc8SMark Cave-Ayland #define ADB_STATUS_BUSTIMEOUT 0x1 74*3fe02cc8SMark Cave-Ayland #define ADB_STATUS_POLLREPLY 0x2 75*3fe02cc8SMark Cave-Ayland 7684ede329SAndreas Färber struct ADBBusState { 7784ede329SAndreas Färber /*< private >*/ 7884ede329SAndreas Färber BusState parent_obj; 7984ede329SAndreas Färber /*< public >*/ 8084ede329SAndreas Färber 812e4a7c9cSAndreas Färber ADBDevice *devices[MAX_ADB_DEVICES]; 82244a0ee9SMark Cave-Ayland uint16_t pending; 837a880d93SLaurent Vivier int nb_devices; 847a880d93SLaurent Vivier int poll_index; 85*3fe02cc8SMark Cave-Ayland uint8_t status; 86da52c083SMark Cave-Ayland 87da52c083SMark Cave-Ayland QEMUTimer *autopoll_timer; 88da52c083SMark Cave-Ayland bool autopoll_enabled; 89da52c083SMark Cave-Ayland uint8_t autopoll_rate_ms; 90da52c083SMark Cave-Ayland uint16_t autopoll_mask; 91da52c083SMark Cave-Ayland void (*autopoll_cb)(void *opaque); 92da52c083SMark Cave-Ayland void *autopoll_cb_opaque; 9384ede329SAndreas Färber }; 947a880d93SLaurent Vivier 957a880d93SLaurent Vivier int adb_request(ADBBusState *s, uint8_t *buf_out, 967a880d93SLaurent Vivier const uint8_t *buf, int len); 97216c906eSHervé Poussineau int adb_poll(ADBBusState *s, uint8_t *buf_out, uint16_t poll_mask); 987a880d93SLaurent Vivier 99da52c083SMark Cave-Ayland void adb_set_autopoll_enabled(ADBBusState *s, bool enabled); 100da52c083SMark Cave-Ayland void adb_set_autopoll_rate_ms(ADBBusState *s, int rate_ms); 101da52c083SMark Cave-Ayland void adb_set_autopoll_mask(ADBBusState *s, uint16_t mask); 102da52c083SMark Cave-Ayland void adb_register_autopoll_callback(ADBBusState *s, void (*cb)(void *opaque), 103da52c083SMark Cave-Ayland void *opaque); 104da52c083SMark Cave-Ayland 1052e4a7c9cSAndreas Färber #define TYPE_ADB_KEYBOARD "adb-keyboard" 1062e4a7c9cSAndreas Färber #define TYPE_ADB_MOUSE "adb-mouse" 1077a880d93SLaurent Vivier 1082a6a4076SMarkus Armbruster #endif /* ADB_H */ 109