[Skiboot] [PATCH 09/22] hw/p8-i2c: Add p8_i2c_find_bus_by_port()

Vasant Hegde hegdevasant at linux.vnet.ibm.com
Fri Jun 25 16:19:24 AEST 2021


From: Oliver O'Halloran <oohall at gmail.com>

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 eb9bbf55d..40d9ae48b 100644
--- a/hw/p8-i2c.c
+++ b/hw/p8-i2c.c
@@ -1606,3 +1606,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 2c67a0ea2..8ec32ad1c 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.31.1



More information about the Skiboot mailing list