@@ -35,6 +36,7 @@ static int sdw_slave_add(struct sdw_bus *bus,
slave->dev.release = sdw_slave_release;
slave->dev.bus = &sdw_bus_type;
+ slave->dev.of_node = of_node_get(to_of_node(fwnode));
slave->bus = bus;
slave->status = SDW_SLAVE_UNATTACHED;
slave->dev_num = 0;
@@ -112,3 +114,48 @@ int sdw_acpi_find_slaves(struct sdw_bus *bus)
}
#endif
+
+/*
+ * sdw_of_find_slaves() - Find Slave devices in master device tree node
+ * @bus: SDW bus instance
+ *
+ * Scans Master DT node for SDW child Slave devices and registers it.
+ */
+int sdw_of_find_slaves(struct sdw_bus *bus)
+{
+ struct device *dev = bus->dev;
+ struct device_node *node;
+
+ for_each_child_of_node(bus->dev->of_node, node) {
+ struct sdw_slave_id id;
+ const char *compat = NULL;
+ int unique_id, ret;
+ int ver, mfg_id, part_id, class_id;
+
+ compat = of_get_property(node, "compatible", NULL);
+ if (!compat)
+ continue;
+
+ ret = sscanf(compat, "sdw%x,%x,%x,%x",
+ &ver, &mfg_id, &part_id, &class_id);
+ if (ret != 4) {
+ dev_err(dev, "Manf ID & Product code not found %s\n",
+ compat);
+ continue;
+ }
+
+ ret = of_property_read_u32(node, "sdw-instance-id", &unique_id);
+ if (ret) {
+ dev_err(dev, "Instance id not found:%d\n", ret);
+ continue;
+ }
+
+ id.sdw_version = ver - 0xF;
+ id.unique_id = unique_id;
+ id.mfg_id = mfg_id;
+ id.part_id = part_id;
+ id.class_id = class_id;
+ sdw_slave_add(bus, &id, of_fwnode_handle(node));
+ }
+ return 0;
+}