]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/soundwire/slave.c
Merge tag 'upstream-5.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs
[linux.git] / drivers / soundwire / slave.c
index 6473fa602f82cc81b745f97cca97df1323618939..19919975bb6da4c73c9b6861492f86d44b586dc7 100644 (file)
@@ -29,10 +29,17 @@ static int sdw_slave_add(struct sdw_bus *bus,
        slave->dev.parent = bus->dev;
        slave->dev.fwnode = fwnode;
 
-       /* name shall be sdw:link:mfg:part:class:unique */
-       dev_set_name(&slave->dev, "sdw:%x:%x:%x:%x:%x",
-                    bus->link_id, id->mfg_id, id->part_id,
-                    id->class_id, id->unique_id);
+       if (id->unique_id == SDW_IGNORED_UNIQUE_ID) {
+               /* name shall be sdw:link:mfg:part:class */
+               dev_set_name(&slave->dev, "sdw:%x:%x:%x:%x",
+                            bus->link_id, id->mfg_id, id->part_id,
+                            id->class_id);
+       } else {
+               /* name shall be sdw:link:mfg:part:class:unique */
+               dev_set_name(&slave->dev, "sdw:%x:%x:%x:%x:%x",
+                            bus->link_id, id->mfg_id, id->part_id,
+                            id->class_id, id->unique_id);
+       }
 
        slave->dev.release = sdw_slave_release;
        slave->dev.bus = &sdw_bus_type;
@@ -64,6 +71,36 @@ static int sdw_slave_add(struct sdw_bus *bus,
 }
 
 #if IS_ENABLED(CONFIG_ACPI)
+
+static bool find_slave(struct sdw_bus *bus,
+                      struct acpi_device *adev,
+                      struct sdw_slave_id *id)
+{
+       unsigned long long addr;
+       unsigned int link_id;
+       acpi_status status;
+
+       status = acpi_evaluate_integer(adev->handle,
+                                      METHOD_NAME__ADR, NULL, &addr);
+
+       if (ACPI_FAILURE(status)) {
+               dev_err(bus->dev, "_ADR resolution failed: %x\n",
+                       status);
+               return false;
+       }
+
+       /* Extract link id from ADR, Bit 51 to 48 (included) */
+       link_id = (addr >> 48) & GENMASK(3, 0);
+
+       /* Check for link_id match */
+       if (link_id != bus->link_id)
+               return false;
+
+       sdw_extract_slave_id(bus, addr, id);
+
+       return true;
+}
+
 /*
  * sdw_acpi_find_slaves() - Find Slave devices in Master ACPI node
  * @bus: SDW bus instance
@@ -73,6 +110,7 @@ static int sdw_slave_add(struct sdw_bus *bus,
 int sdw_acpi_find_slaves(struct sdw_bus *bus)
 {
        struct acpi_device *adev, *parent;
+       struct acpi_device *adev2, *parent2;
 
        parent = ACPI_COMPANION(bus->dev);
        if (!parent) {
@@ -81,28 +119,46 @@ int sdw_acpi_find_slaves(struct sdw_bus *bus)
        }
 
        list_for_each_entry(adev, &parent->children, node) {
-               unsigned long long addr;
                struct sdw_slave_id id;
-               unsigned int link_id;
-               acpi_status status;
+               struct sdw_slave_id id2;
+               bool ignore_unique_id = true;
 
-               status = acpi_evaluate_integer(adev->handle,
-                                              METHOD_NAME__ADR, NULL, &addr);
+               if (!find_slave(bus, adev, &id))
+                       continue;
 
-               if (ACPI_FAILURE(status)) {
-                       dev_err(bus->dev, "_ADR resolution failed: %x\n",
-                               status);
-                       return status;
+               /* brute-force O(N^2) search for duplicates */
+               parent2 = parent;
+               list_for_each_entry(adev2, &parent2->children, node) {
+
+                       if (adev == adev2)
+                               continue;
+
+                       if (!find_slave(bus, adev2, &id2))
+                               continue;
+
+                       if (id.sdw_version != id2.sdw_version ||
+                           id.mfg_id != id2.mfg_id ||
+                           id.part_id != id2.part_id ||
+                           id.class_id != id2.class_id)
+                               continue;
+
+                       if (id.unique_id != id2.unique_id) {
+                               dev_dbg(bus->dev,
+                                       "Valid unique IDs %x %x for Slave mfg %x part %d\n",
+                                       id.unique_id, id2.unique_id,
+                                       id.mfg_id, id.part_id);
+                               ignore_unique_id = false;
+                       } else {
+                               dev_err(bus->dev,
+                                       "Invalid unique IDs %x %x for Slave mfg %x part %d\n",
+                                       id.unique_id, id2.unique_id,
+                                       id.mfg_id, id.part_id);
+                               return -ENODEV;
+                       }
                }
 
-               /* Extract link id from ADR, Bit 51 to 48 (included) */
-               link_id = (addr >> 48) & GENMASK(3, 0);
-
-               /* Check for link_id match */
-               if (link_id != bus->link_id)
-                       continue;
-
-               sdw_extract_slave_id(bus, addr, &id);
+               if (ignore_unique_id)
+                       id.unique_id = SDW_IGNORED_UNIQUE_ID;
 
                /*
                 * don't error check for sdw_slave_add as we want to continue