root / hw / smbus.h @ 477afee3
History | View | Annotate | Download (3.1 kB)
1 | 3fffc223 | ths | /*
|
---|---|---|---|
2 | 3fffc223 | ths | * QEMU SMBus API
|
3 | 5fafdf24 | ths | *
|
4 | 3fffc223 | ths | * Copyright (c) 2007 Arastra, Inc.
|
5 | 5fafdf24 | ths | *
|
6 | 3fffc223 | ths | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 3fffc223 | ths | * of this software and associated documentation files (the "Software"), to deal
|
8 | 3fffc223 | ths | * in the Software without restriction, including without limitation the rights
|
9 | 3fffc223 | ths | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 3fffc223 | ths | * copies of the Software, and to permit persons to whom the Software is
|
11 | 3fffc223 | ths | * furnished to do so, subject to the following conditions:
|
12 | 3fffc223 | ths | *
|
13 | 3fffc223 | ths | * The above copyright notice and this permission notice shall be included in
|
14 | 3fffc223 | ths | * all copies or substantial portions of the Software.
|
15 | 3fffc223 | ths | *
|
16 | 3fffc223 | ths | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 3fffc223 | ths | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 3fffc223 | ths | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 3fffc223 | ths | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 3fffc223 | ths | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 3fffc223 | ths | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 3fffc223 | ths | * THE SOFTWARE.
|
23 | 3fffc223 | ths | */
|
24 | 3fffc223 | ths | |
25 | 87ecb68b | pbrook | #include "i2c.h" |
26 | 3fffc223 | ths | |
27 | 3fffc223 | ths | struct SMBusDevice {
|
28 | 0ff596d0 | pbrook | /* The SMBus protocol is implemented on top of I2C. */
|
29 | 0ff596d0 | pbrook | i2c_slave i2c; |
30 | 0ff596d0 | pbrook | |
31 | 0ff596d0 | pbrook | /* Callbacks set by the device. */
|
32 | 3fffc223 | ths | void (*quick_cmd)(SMBusDevice *dev, uint8_t read);
|
33 | 3fffc223 | ths | void (*send_byte)(SMBusDevice *dev, uint8_t val);
|
34 | 3fffc223 | ths | uint8_t (*receive_byte)(SMBusDevice *dev); |
35 | 0ff596d0 | pbrook | /* We can't distinguish between a word write and a block write with
|
36 | 0ff596d0 | pbrook | length 1, so pass the whole data block including the length byte
|
37 | 0ff596d0 | pbrook | (if present). The device is responsible figuring out what type of
|
38 | 0ff596d0 | pbrook | command this is. */
|
39 | 0ff596d0 | pbrook | void (*write_data)(SMBusDevice *dev, uint8_t cmd, uint8_t *buf, int len); |
40 | 3f582262 | balrog | /* Likewise we can't distinguish between different reads, or even know
|
41 | 0ff596d0 | pbrook | the length of the read until the read is complete, so read data a
|
42 | 0ff596d0 | pbrook | byte at a time. The device is responsible for adding the length
|
43 | 0ff596d0 | pbrook | byte on block reads. */
|
44 | 0ff596d0 | pbrook | uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n);
|
45 | 0ff596d0 | pbrook | |
46 | 0ff596d0 | pbrook | /* Remaining fields for internal use only. */
|
47 | 0ff596d0 | pbrook | int mode;
|
48 | 0ff596d0 | pbrook | int data_len;
|
49 | 0ff596d0 | pbrook | uint8_t data_buf[34]; /* command + len + 32 bytes of data. */ |
50 | 0ff596d0 | pbrook | uint8_t command; |
51 | 3fffc223 | ths | }; |
52 | 0ff596d0 | pbrook | |
53 | 0ff596d0 | pbrook | /* Create a slave device. */
|
54 | 0ff596d0 | pbrook | SMBusDevice *smbus_device_init(i2c_bus *bus, int address, int size); |
55 | 0ff596d0 | pbrook | |
56 | 0ff596d0 | pbrook | /* Master device commands. */
|
57 | 0ff596d0 | pbrook | void smbus_quick_command(i2c_bus *bus, int addr, int read); |
58 | 0ff596d0 | pbrook | uint8_t smbus_receive_byte(i2c_bus *bus, int addr);
|
59 | 0ff596d0 | pbrook | void smbus_send_byte(i2c_bus *bus, int addr, uint8_t data); |
60 | 0ff596d0 | pbrook | uint8_t smbus_read_byte(i2c_bus *bus, int addr, uint8_t command);
|
61 | 0ff596d0 | pbrook | void smbus_write_byte(i2c_bus *bus, int addr, uint8_t command, uint8_t data); |
62 | 0ff596d0 | pbrook | uint16_t smbus_read_word(i2c_bus *bus, int addr, uint8_t command);
|
63 | 0ff596d0 | pbrook | void smbus_write_word(i2c_bus *bus, int addr, uint8_t command, uint16_t data); |
64 | 0ff596d0 | pbrook | int smbus_read_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data); |
65 | 0ff596d0 | pbrook | void smbus_write_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data, |
66 | 0ff596d0 | pbrook | int len);
|
67 | 0ff596d0 | pbrook | |
68 | 0ff596d0 | pbrook | /* smbus_eeprom.c */
|
69 | 0ff596d0 | pbrook | void smbus_eeprom_device_init(i2c_bus *bus, uint8_t addr, uint8_t *buf);
|