Import of openhackware-0.4.1
[openhackware.git] / src / dev / bus / adb.h
blobe48b120f2310f91bcfd68f58149730b401d90c0b
1 /*
2 * ADB bus definitions for Open Hack'Ware
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License V2
8 * as published by the Free Software Foundation
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #if !defined(__OHW_ADB_H__)
21 #define __OHW_ADB_H__
23 typedef struct adb_bus_t adb_bus_t;
24 typedef struct adb_dev_t adb_dev_t;
26 #define ADB_BUF_SIZE 8
27 struct adb_bus_t {
28 void *host;
29 int (*req)(void *host, const uint8_t *snd_buf, int len, uint8_t *rcv_buf);
30 adb_dev_t *devices;
33 struct adb_dev_t {
34 adb_dev_t *next;
35 adb_bus_t *bus;
36 uint8_t addr;
37 uint8_t type;
38 uint32_t state;
41 #define ADB_BUF_SIZE 8
43 /* ADB commands */
44 enum {
45 ADB_SEND_RESET = 0x00,
46 ADB_FLUSH = 0x01,
47 ADB_LISTEN = 0x08,
48 ADB_TALK = 0x0C,
50 /* ADB default IDs before relocation */
51 enum {
52 ADB_PROTECT = 0x01,
53 ADB_KEYBD = 0x02,
54 ADB_MOUSE = 0x03,
55 ADB_ABS = 0x04,
56 ADB_MODEM = 0x05,
57 ADB_RES = 0x06,
58 ADB_MISC = 0x07,
60 /* ADB special device handlers IDs */
61 enum {
62 ADB_CHADDR = 0x00,
63 ADB_CHADDR_ACTIV = 0xFD,
64 ADB_CHADDR_NOCOLL = 0xFE,
65 ADB_SELF_TEST = 0xFF,
68 int adb_cmd (adb_dev_t *dev, uint8_t cmd, uint8_t reg,
69 uint8_t *buf, int len);
70 void adb_bus_reset (adb_bus_t *bus);
71 adb_bus_t *adb_bus_new (void *host,
72 int (*req)(void *host, const uint8_t *snd_buf,
73 int len, uint8_t *rcv_buf));
74 int adb_bus_init (adb_bus_t *bus);
76 static inline int adb_reset (adb_bus_t *bus)
78 adb_dev_t fake_device;
80 memset(&fake_device, 0, sizeof(adb_dev_t));
81 fake_device.bus = bus;
83 return adb_cmd(&fake_device, ADB_SEND_RESET, 0, NULL, 0);
86 static inline int adb_flush (adb_dev_t *dev)
88 return adb_cmd(dev, ADB_FLUSH, 0, NULL, 0);
91 static inline int adb_reg_get (adb_dev_t *dev, uint8_t reg, uint8_t *buf)
93 return adb_cmd(dev, ADB_TALK, reg, buf, 0);
96 static inline int adb_reg_set (adb_dev_t *dev, uint8_t reg,
97 uint8_t *buf, int len)
99 return adb_cmd(dev, ADB_LISTEN, reg, buf, len);
102 #endif /* !defined(__OHW_ADB_H__) */