[2/2] OCC: Map OCC sensor to a chip-id

Submitted by Vasant Hegde on July 27, 2017, 8:45 a.m.

Details

Message ID 20170727084518.31710-2-hegdevasant@linux.vnet.ibm.com
State Accepted
Headers show

Commit Message

Vasant Hegde July 27, 2017, 8:45 a.m.
Parse device tree to get chip-id for OCC sensor.

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 hw/ipmi/ipmi-sel.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/hw/ipmi/ipmi-sel.c b/hw/ipmi/ipmi-sel.c
index 5c76647..3386854 100644
--- a/hw/ipmi/ipmi-sel.c
+++ b/hw/ipmi/ipmi-sel.c
@@ -532,9 +532,33 @@  static void sel_power(uint8_t power)
 
 static uint32_t occ_sensor_id_to_chip(uint8_t sensor, uint32_t *chip)
 {
-	/* TODO: Lookup sensor ID node in the DT, and map to a chip id */
-	(void)sensor;
+	struct dt_node *node, *bmc_node, *sensors_node;
+
+	/* Default chip id */
 	*chip = 0;
+
+	bmc_node = dt_find_by_name(dt_root, "bmc");
+	if (!bmc_node)
+		return 0;
+
+	sensors_node = dt_find_by_name(bmc_node, "sensors");
+	if (!sensors_node)
+		return 0;
+
+	node = dt_find_by_name_addr(sensors_node, "sensor", sensor);
+	if (!node) {
+		prlog(PR_DEBUG, "Could not find OCC sensor node. Id : %d\n",
+		      (u32)sensor);
+		return 0;
+	}
+
+	if (!dt_has_node_property(node, "ibm,chip-id", NULL)) {
+		prlog(PR_DEBUG, "Could not find chip-id for OCC sensor : %d\n",
+		      (u32)sensor);
+		return 0;
+	}
+
+	*chip = dt_get_chip_id(node);
 	return 0;
 }