aboutsummaryrefslogtreecommitdiff
path: root/include/hw/i2c
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2021-04-12 12:45:20 -0700
committerCorey Minyard <cminyard@mvista.com>2021-04-15 07:10:06 -0500
commit513ca82d8982463aca98aa01dcf584e0b4fc0982 (patch)
tree6653797e4ea6b778f9a10f73926ebc2415a424b4 /include/hw/i2c
parentb98ec6896ee88f1dcdd7098af25bcb6ee0fc50f0 (diff)
hw/i2c: add match method for device search
At the start of an i2c transaction, the i2c bus searches its list of children to identify which devices correspond to the address (or broadcast). Now the I2CSlave device has a method "match" that encapsulates the lookup behavior. This allows the behavior to be changed to support devices, such as i2c muxes. Tested: A BMC firmware was booted to userspace and i2c devices were detected. Signed-off-by: Patrick Venture <venture@google.com> Reviewed-by: Hao Wu <wuhaotsh@google.com> Message-Id: <20210412194522.664594-3-venture@google.com> Signed-off-by: Corey Minyard <cminyard@mvista.com>
Diffstat (limited to 'include/hw/i2c')
-rw-r--r--include/hw/i2c/i2c.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h
index 1f7c268c86..9b8b95ff4a 100644
--- a/include/hw/i2c/i2c.h
+++ b/include/hw/i2c/i2c.h
@@ -16,6 +16,7 @@ enum i2c_event {
I2C_NACK /* Masker NACKed a receive byte. */
};
+typedef struct I2CNodeList I2CNodeList;
#define TYPE_I2C_SLAVE "i2c-slave"
OBJECT_DECLARE_TYPE(I2CSlave, I2CSlaveClass,
@@ -39,6 +40,16 @@ struct I2CSlaveClass {
* return code is not used and should be zero.
*/
int (*event)(I2CSlave *s, enum i2c_event event);
+
+ /*
+ * Check if this device matches the address provided. Returns bool of
+ * true if it matches (or broadcast), and updates the device list, false
+ * otherwise.
+ *
+ * If broadcast is true, match should add the device and return true.
+ */
+ bool (*match_and_add)(I2CSlave *candidate, uint8_t address, bool broadcast,
+ I2CNodeList *current_devs);
};
struct I2CSlave {