Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openhackware / src / dev / bus / adb.h
1 /*
2  * ADB bus definitions for Open Hack'Ware
3  *
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
9  *
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.
14  *
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
18  */
19
20 #if !defined(__OHW_ADB_H__)
21 #define __OHW_ADB_H__
22
23 typedef struct adb_bus_t adb_bus_t;
24 typedef struct adb_dev_t adb_dev_t;
25
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;
31 };
32
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;
39 };
40
41 #define ADB_BUF_SIZE 8
42
43 /* ADB commands */
44 enum {
45     ADB_SEND_RESET = 0x00,
46     ADB_FLUSH      = 0x01,
47     ADB_LISTEN     = 0x08,
48     ADB_TALK       = 0x0C,
49 };
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,
59 };
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,
66 };
67
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);
75
76 static inline int adb_reset (adb_bus_t *bus)
77 {
78     adb_dev_t fake_device;
79     
80     memset(&fake_device, 0, sizeof(adb_dev_t));
81     fake_device.bus = bus;
82
83     return adb_cmd(&fake_device, ADB_SEND_RESET, 0, NULL, 0);
84 }
85
86 static inline int adb_flush (adb_dev_t *dev)
87 {
88     return adb_cmd(dev, ADB_FLUSH, 0, NULL, 0);
89 }
90
91 static inline int adb_reg_get (adb_dev_t *dev, uint8_t reg, uint8_t *buf)
92 {
93     return adb_cmd(dev, ADB_TALK, reg, buf, 0);
94 }
95
96 static inline int adb_reg_set (adb_dev_t *dev, uint8_t reg,
97                                uint8_t *buf, int len)
98 {
99     return adb_cmd(dev, ADB_LISTEN, reg, buf, len);
100 }
101
102 #endif /* !defined(__OHW_ADB_H__) */