Statistics
| Branch: | Revision:

root / hw / smbus.h @ 079d0b7f

History | View | Annotate | Download (3.5 kB)

1 b5ea9327 Anthony Liguori
#ifndef QEMU_SMBUS_H
2 b5ea9327 Anthony Liguori
#define QEMU_SMBUS_H
3 b5ea9327 Anthony Liguori
4 3fffc223 ths
/*
5 3fffc223 ths
 * QEMU SMBus API
6 5fafdf24 ths
 *
7 3fffc223 ths
 * Copyright (c) 2007 Arastra, Inc.
8 5fafdf24 ths
 *
9 3fffc223 ths
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 3fffc223 ths
 * of this software and associated documentation files (the "Software"), to deal
11 3fffc223 ths
 * in the Software without restriction, including without limitation the rights
12 3fffc223 ths
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 3fffc223 ths
 * copies of the Software, and to permit persons to whom the Software is
14 3fffc223 ths
 * furnished to do so, subject to the following conditions:
15 3fffc223 ths
 *
16 3fffc223 ths
 * The above copyright notice and this permission notice shall be included in
17 3fffc223 ths
 * all copies or substantial portions of the Software.
18 3fffc223 ths
 *
19 3fffc223 ths
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 3fffc223 ths
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 3fffc223 ths
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 3fffc223 ths
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 3fffc223 ths
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 3fffc223 ths
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 3fffc223 ths
 * THE SOFTWARE.
26 3fffc223 ths
 */
27 3fffc223 ths
28 87ecb68b pbrook
#include "i2c.h"
29 3fffc223 ths
30 b5ea9327 Anthony Liguori
#define TYPE_SMBUS_DEVICE "smbus-device"
31 b5ea9327 Anthony Liguori
#define SMBUS_DEVICE(obj) \
32 b5ea9327 Anthony Liguori
     OBJECT_CHECK(SMBusDevice, (obj), TYPE_SMBUS_DEVICE)
33 b5ea9327 Anthony Liguori
#define SMBUS_DEVICE_CLASS(klass) \
34 b5ea9327 Anthony Liguori
     OBJECT_CLASS_CHECK(SMBusDeviceClass, (klass), TYPE_SMBUS_DEVICE)
35 b5ea9327 Anthony Liguori
#define SMBUS_DEVICE_GET_CLASS(obj) \
36 b5ea9327 Anthony Liguori
     OBJECT_GET_CLASS(SMBusDeviceClass, (obj), TYPE_SMBUS_DEVICE)
37 1ea96673 Paul Brook
38 b5ea9327 Anthony Liguori
typedef struct SMBusDeviceClass
39 b5ea9327 Anthony Liguori
{
40 b5ea9327 Anthony Liguori
    I2CSlaveClass parent_class;
41 81a322d4 Gerd Hoffmann
    int (*init)(SMBusDevice *dev);
42 3fffc223 ths
    void (*quick_cmd)(SMBusDevice *dev, uint8_t read);
43 3fffc223 ths
    void (*send_byte)(SMBusDevice *dev, uint8_t val);
44 3fffc223 ths
    uint8_t (*receive_byte)(SMBusDevice *dev);
45 0ff596d0 pbrook
    /* We can't distinguish between a word write and a block write with
46 0ff596d0 pbrook
       length 1, so pass the whole data block including the length byte
47 0ff596d0 pbrook
       (if present).  The device is responsible figuring out what type of
48 0ff596d0 pbrook
       command  this is.  */
49 0ff596d0 pbrook
    void (*write_data)(SMBusDevice *dev, uint8_t cmd, uint8_t *buf, int len);
50 3f582262 balrog
    /* Likewise we can't distinguish between different reads, or even know
51 0ff596d0 pbrook
       the length of the read until the read is complete, so read data a
52 0ff596d0 pbrook
       byte at a time.  The device is responsible for adding the length
53 0ff596d0 pbrook
       byte on block reads.  */
54 0ff596d0 pbrook
    uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n);
55 b5ea9327 Anthony Liguori
} SMBusDeviceClass;
56 0ff596d0 pbrook
57 b5ea9327 Anthony Liguori
struct SMBusDevice {
58 b5ea9327 Anthony Liguori
    /* The SMBus protocol is implemented on top of I2C.  */
59 b5ea9327 Anthony Liguori
    I2CSlave i2c;
60 b5ea9327 Anthony Liguori
61 b5ea9327 Anthony Liguori
    /* Remaining fields for internal use only.  */
62 b5ea9327 Anthony Liguori
    int mode;
63 b5ea9327 Anthony Liguori
    int data_len;
64 b5ea9327 Anthony Liguori
    uint8_t data_buf[34]; /* command + len + 32 bytes of data.  */
65 b5ea9327 Anthony Liguori
    uint8_t command;
66 b5ea9327 Anthony Liguori
};
67 b5ea9327 Anthony Liguori
68 0ff596d0 pbrook
/* Master device commands.  */
69 5b7f5327 Juan Quintela
void smbus_quick_command(i2c_bus *bus, uint8_t addr, int read);
70 5b7f5327 Juan Quintela
uint8_t smbus_receive_byte(i2c_bus *bus, uint8_t addr);
71 5b7f5327 Juan Quintela
void smbus_send_byte(i2c_bus *bus, uint8_t addr, uint8_t data);
72 5b7f5327 Juan Quintela
uint8_t smbus_read_byte(i2c_bus *bus, uint8_t addr, uint8_t command);
73 5b7f5327 Juan Quintela
void smbus_write_byte(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t data);
74 5b7f5327 Juan Quintela
uint16_t smbus_read_word(i2c_bus *bus, uint8_t addr, uint8_t command);
75 5b7f5327 Juan Quintela
void smbus_write_word(i2c_bus *bus, uint8_t addr, uint8_t command, uint16_t data);
76 5b7f5327 Juan Quintela
int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data);
77 5b7f5327 Juan Quintela
void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
78 0ff596d0 pbrook
                       int len);
79 a88df0b9 Isaku Yamahata
80 a88df0b9 Isaku Yamahata
void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
81 a88df0b9 Isaku Yamahata
                       const uint8_t *eeprom_spd, int size);
82 b5ea9327 Anthony Liguori
83 b5ea9327 Anthony Liguori
#endif