diff mbox series

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

Message ID 20210625061937.47314-10-hegdevasant@linux.vnet.ibm.com
State Accepted
Headers show
Series P9 cleanup and fixes | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (9d52c580d3fabbea6b276b98f925ab0fceebb96c)
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present

Commit Message

Vasant Hegde June 25, 2021, 6:19 a.m. UTC
From: Oliver O'Halloran <oohall@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@gmail.com>
---
 hw/p8-i2c.c   | 26 ++++++++++++++++++++++++++
 include/i2c.h |  3 +++
 2 files changed, 29 insertions(+)
diff mbox series

Patch

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)