13fffc223Sths /* 293198b6cSCorey Minyard * QEMU SMBus device (slave) API 33fffc223Sths * 43fffc223Sths * Copyright (c) 2007 Arastra, Inc. 53fffc223Sths * 63fffc223Sths * Permission is hereby granted, free of charge, to any person obtaining a copy 73fffc223Sths * of this software and associated documentation files (the "Software"), to deal 83fffc223Sths * in the Software without restriction, including without limitation the rights 93fffc223Sths * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 103fffc223Sths * copies of the Software, and to permit persons to whom the Software is 113fffc223Sths * furnished to do so, subject to the following conditions: 123fffc223Sths * 133fffc223Sths * The above copyright notice and this permission notice shall be included in 143fffc223Sths * all copies or substantial portions of the Software. 153fffc223Sths * 163fffc223Sths * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 173fffc223Sths * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 183fffc223Sths * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 193fffc223Sths * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 203fffc223Sths * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 213fffc223Sths * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 223fffc223Sths * THE SOFTWARE. 233fffc223Sths */ 243fffc223Sths 2593198b6cSCorey Minyard #ifndef HW_SMBUS_SLAVE_H 2693198b6cSCorey Minyard #define HW_SMBUS_SLAVE_H 2793198b6cSCorey Minyard 280d09e41aSPaolo Bonzini #include "hw/i2c/i2c.h" 293fffc223Sths 30b5ea9327SAnthony Liguori #define TYPE_SMBUS_DEVICE "smbus-device" 31b5ea9327SAnthony Liguori #define SMBUS_DEVICE(obj) \ 32b5ea9327SAnthony Liguori OBJECT_CHECK(SMBusDevice, (obj), TYPE_SMBUS_DEVICE) 33b5ea9327SAnthony Liguori #define SMBUS_DEVICE_CLASS(klass) \ 34b5ea9327SAnthony Liguori OBJECT_CLASS_CHECK(SMBusDeviceClass, (klass), TYPE_SMBUS_DEVICE) 35b5ea9327SAnthony Liguori #define SMBUS_DEVICE_GET_CLASS(obj) \ 36b5ea9327SAnthony Liguori OBJECT_GET_CLASS(SMBusDeviceClass, (obj), TYPE_SMBUS_DEVICE) 370ff596d0Spbrook 38d183b00eSPhilippe Mathieu-Daudé typedef struct SMBusDevice SMBusDevice; 39d183b00eSPhilippe Mathieu-Daudé 40b5ea9327SAnthony Liguori typedef struct SMBusDeviceClass 41b5ea9327SAnthony Liguori { 42b5ea9327SAnthony Liguori I2CSlaveClass parent_class; 43905cec6dSCorey Minyard 44905cec6dSCorey Minyard /* 45905cec6dSCorey Minyard * An operation with no data, special in SMBus. 46905cec6dSCorey Minyard * This may be NULL, quick commands are ignore in that case. 47905cec6dSCorey Minyard */ 483fffc223Sths void (*quick_cmd)(SMBusDevice *dev, uint8_t read); 49*9cf27d74SCorey Minyard 503fffc223Sths uint8_t (*receive_byte)(SMBusDevice *dev); 51*9cf27d74SCorey Minyard 52*9cf27d74SCorey Minyard /* 53*9cf27d74SCorey Minyard * We can't distinguish between a word write and a block write with 54*9cf27d74SCorey Minyard * length 1, so pass the whole data block including the length byte 55*9cf27d74SCorey Minyard * (if present). The device is responsible figuring out what type of 56*9cf27d74SCorey Minyard * command this is. 57*9cf27d74SCorey Minyard * This may be NULL if no data is written to the device. Writes 58*9cf27d74SCorey Minyard * will be ignore in that case. 59*9cf27d74SCorey Minyard */ 60*9cf27d74SCorey Minyard int (*write_data)(SMBusDevice *dev, uint8_t *buf, uint8_t len); 61*9cf27d74SCorey Minyard 623f582262Sbalrog /* Likewise we can't distinguish between different reads, or even know 630ff596d0Spbrook the length of the read until the read is complete, so read data a 640ff596d0Spbrook byte at a time. The device is responsible for adding the length 650ff596d0Spbrook byte on block reads. */ 66*9cf27d74SCorey Minyard uint8_t (*read_data)(SMBusDevice *dev, int n); 67b5ea9327SAnthony Liguori } SMBusDeviceClass; 680ff596d0Spbrook 69b5ea9327SAnthony Liguori struct SMBusDevice { 70b5ea9327SAnthony Liguori /* The SMBus protocol is implemented on top of I2C. */ 71b5ea9327SAnthony Liguori I2CSlave i2c; 72b5ea9327SAnthony Liguori 73b5ea9327SAnthony Liguori /* Remaining fields for internal use only. */ 74b5ea9327SAnthony Liguori int mode; 75b5ea9327SAnthony Liguori int data_len; 76b5ea9327SAnthony Liguori uint8_t data_buf[34]; /* command + len + 32 bytes of data. */ 77b5ea9327SAnthony Liguori }; 78b5ea9327SAnthony Liguori 79b5ea9327SAnthony Liguori #endif 80