xref: /qemu/include/hw/i2c/smbus_slave.h (revision 031ac49886684ae6d6b88f37779cad2ffd1e4d9b)
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);
499cf27d74SCorey Minyard 
509cf27d74SCorey Minyard     /*
519cf27d74SCorey Minyard      * We can't distinguish between a word write and a block write with
529cf27d74SCorey Minyard      * length 1, so pass the whole data block including the length byte
539cf27d74SCorey Minyard      * (if present).  The device is responsible figuring out what type of
549cf27d74SCorey Minyard      * command this is.
559cf27d74SCorey Minyard      * This may be NULL if no data is written to the device.  Writes
569cf27d74SCorey Minyard      * will be ignore in that case.
579cf27d74SCorey Minyard      */
589cf27d74SCorey Minyard     int (*write_data)(SMBusDevice *dev, uint8_t *buf, uint8_t len);
599cf27d74SCorey Minyard 
60*031ac498SCorey Minyard     /*
61*031ac498SCorey Minyard      * Likewise we can't distinguish between different reads, or even know
62*031ac498SCorey Minyard      * the length of the read until the read is complete, so read data a
63*031ac498SCorey Minyard      * byte at a time.  The device is responsible for adding the length
64*031ac498SCorey Minyard      * byte on block reads.  This call cannot fail, it should return
65*031ac498SCorey Minyard      * something, preferably 0xff if nothing is available.
66*031ac498SCorey Minyard      * This may be NULL if no data is read from the device.  Reads will
67*031ac498SCorey Minyard      * return 0xff in that case.
68*031ac498SCorey Minyard      */
69*031ac498SCorey Minyard     uint8_t (*receive_byte)(SMBusDevice *dev);
70b5ea9327SAnthony Liguori } SMBusDeviceClass;
710ff596d0Spbrook 
72b5ea9327SAnthony Liguori struct SMBusDevice {
73b5ea9327SAnthony Liguori     /* The SMBus protocol is implemented on top of I2C.  */
74b5ea9327SAnthony Liguori     I2CSlave i2c;
75b5ea9327SAnthony Liguori 
76b5ea9327SAnthony Liguori     /* Remaining fields for internal use only.  */
77b5ea9327SAnthony Liguori     int mode;
78b5ea9327SAnthony Liguori     int data_len;
79b5ea9327SAnthony Liguori     uint8_t data_buf[34]; /* command + len + 32 bytes of data.  */
80b5ea9327SAnthony Liguori };
81b5ea9327SAnthony Liguori 
82b5ea9327SAnthony Liguori #endif
83