]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/soundwire/slave.c
soundwire: slave: fix scanf format
[linux.git] / drivers / soundwire / slave.c
index f39a5815e25dcf4b98e8cc270659d7968d20c71f..6473fa602f82cc81b745f97cca97df1323618939 100644 (file)
@@ -2,6 +2,7 @@
 // Copyright(c) 2015-17 Intel Corporation.
 
 #include <linux/acpi.h>
+#include <linux/of.h>
 #include <linux/soundwire/sdw.h>
 #include <linux/soundwire/sdw_type.h>
 #include "bus.h"
@@ -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;
@@ -56,6 +58,7 @@ static int sdw_slave_add(struct sdw_bus *bus,
                mutex_unlock(&bus->bus_lock);
                put_device(&slave->dev);
        }
+       sdw_slave_debugfs_init(slave);
 
        return ret;
 }
@@ -112,3 +115,54 @@ 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) {
+               int link_id, ret, len;
+               unsigned int sdw_version;
+               const char *compat = NULL;
+               struct sdw_slave_id id;
+               const __be32 *addr;
+
+               compat = of_get_property(node, "compatible", NULL);
+               if (!compat)
+                       continue;
+
+               ret = sscanf(compat, "sdw%01x%04hx%04hx%02hhx", &sdw_version,
+                            &id.mfg_id, &id.part_id, &id.class_id);
+
+               if (ret != 4) {
+                       dev_err(dev, "Invalid compatible string found %s\n",
+                               compat);
+                       continue;
+               }
+
+               addr = of_get_property(node, "reg", &len);
+               if (!addr || (len < 2 * sizeof(u32))) {
+                       dev_err(dev, "Invalid Link and Instance ID\n");
+                       continue;
+               }
+
+               link_id = be32_to_cpup(addr++);
+               id.unique_id = be32_to_cpup(addr);
+               id.sdw_version = sdw_version;
+
+               /* Check for link_id match */
+               if (link_id != bus->link_id)
+                       continue;
+
+               sdw_slave_add(bus, &id, of_fwnode_handle(node));
+       }
+
+       return 0;
+}