[Skiboot] [PATCH 05/10] hw/p8-i2c: Add p8_i2c_find_bus_by_port()
Oliver O'Halloran
oohall at gmail.com
Mon Oct 12 13:53:09 AEDT 2020
Adds a way to find the struct i2c_bus for a given chip ID, engine ID,
and port ID. HDAT indicates which I2C master is relevant using this
information so it comes up a fair bit.
Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
hw/p8-i2c.c | 26 ++++++++++++++++++++++++++
include/i2c.h | 3 +++
2 files changed, 29 insertions(+)
diff --git a/hw/p8-i2c.c b/hw/p8-i2c.c
index 40b8dc2167f5..60bea868fda2 100644
--- a/hw/p8-i2c.c
+++ b/hw/p8-i2c.c
@@ -1607,3 +1607,29 @@ void p8_i2c_init(void)
p8_i2c_init_one(i2cm, i);
}
}
+
+struct i2c_bus *p8_i2c_find_bus_by_port(uint32_t chip_id, int eng, int port_num)
+{
+ struct proc_chip *chip = get_chip(chip_id);
+ struct p8_i2c_master *m, *master = NULL;
+ struct p8_i2c_master_port *port;
+
+ if (!chip)
+ return NULL;
+
+ list_for_each(&chip->i2cms, m, link) {
+ if (m->engine_id == eng) {
+ master = m;
+ break;
+ }
+ }
+
+ if (!master)
+ return NULL;
+
+ list_for_each(&master->ports, port, link)
+ if (port->port_num == port_num)
+ return &port->bus;
+
+ return NULL;
+}
diff --git a/include/i2c.h b/include/i2c.h
index 2c67a0ea22ea..8ec32ad1c6f3 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -61,6 +61,9 @@ struct i2c_request {
extern void i2c_add_bus(struct i2c_bus *bus);
extern struct i2c_bus *i2c_find_bus_by_id(uint32_t opal_id);
+/* not generic, but useful */
+struct i2c_bus *p8_i2c_find_bus_by_port(uint32_t chip_id, int eng, int port_id);
+
int64_t i2c_queue_req(struct i2c_request *req);
static inline uint64_t i2c_run_req(struct i2c_request *req)
--
2.26.2
More information about the Skiboot
mailing list