Statistics
| Branch: | Revision:

root / hw / smbus.h @ 3b2e3dc9

History | View | Annotate | Download (3 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 1ea96673 Paul Brook
    /* Remaining fields for internal use only.  */
32 1ea96673 Paul Brook
    int mode;
33 1ea96673 Paul Brook
    int data_len;
34 1ea96673 Paul Brook
    uint8_t data_buf[34]; /* command + len + 32 bytes of data.  */
35 1ea96673 Paul Brook
    uint8_t command;
36 1ea96673 Paul Brook
};
37 1ea96673 Paul Brook
38 1ea96673 Paul Brook
typedef struct {
39 1ea96673 Paul Brook
    I2CSlaveInfo i2c;
40 81a322d4 Gerd Hoffmann
    int (*init)(SMBusDevice *dev);
41 3fffc223 ths
    void (*quick_cmd)(SMBusDevice *dev, uint8_t read);
42 3fffc223 ths
    void (*send_byte)(SMBusDevice *dev, uint8_t val);
43 3fffc223 ths
    uint8_t (*receive_byte)(SMBusDevice *dev);
44 0ff596d0 pbrook
    /* We can't distinguish between a word write and a block write with
45 0ff596d0 pbrook
       length 1, so pass the whole data block including the length byte
46 0ff596d0 pbrook
       (if present).  The device is responsible figuring out what type of
47 0ff596d0 pbrook
       command  this is.  */
48 0ff596d0 pbrook
    void (*write_data)(SMBusDevice *dev, uint8_t cmd, uint8_t *buf, int len);
49 3f582262 balrog
    /* Likewise we can't distinguish between different reads, or even know
50 0ff596d0 pbrook
       the length of the read until the read is complete, so read data a
51 0ff596d0 pbrook
       byte at a time.  The device is responsible for adding the length
52 0ff596d0 pbrook
       byte on block reads.  */
53 0ff596d0 pbrook
    uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n);
54 1ea96673 Paul Brook
} SMBusDeviceInfo;
55 0ff596d0 pbrook
56 074f2fff Gerd Hoffmann
void smbus_register_device(SMBusDeviceInfo *info);
57 0ff596d0 pbrook
58 0ff596d0 pbrook
/* Master device commands.  */
59 5b7f5327 Juan Quintela
void smbus_quick_command(i2c_bus *bus, uint8_t addr, int read);
60 5b7f5327 Juan Quintela
uint8_t smbus_receive_byte(i2c_bus *bus, uint8_t addr);
61 5b7f5327 Juan Quintela
void smbus_send_byte(i2c_bus *bus, uint8_t addr, uint8_t data);
62 5b7f5327 Juan Quintela
uint8_t smbus_read_byte(i2c_bus *bus, uint8_t addr, uint8_t command);
63 5b7f5327 Juan Quintela
void smbus_write_byte(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t data);
64 5b7f5327 Juan Quintela
uint16_t smbus_read_word(i2c_bus *bus, uint8_t addr, uint8_t command);
65 5b7f5327 Juan Quintela
void smbus_write_word(i2c_bus *bus, uint8_t addr, uint8_t command, uint16_t data);
66 5b7f5327 Juan Quintela
int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data);
67 5b7f5327 Juan Quintela
void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
68 0ff596d0 pbrook
                       int len);