platform/chrome: cros_ec_typec: Make sure the USB role switch has PLD
authorHeikki Krogerus <heikki.krogerus@linux.intel.com>
Tue, 13 Feb 2024 13:00:18 +0000 (15:00 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 17 Feb 2024 16:02:42 +0000 (17:02 +0100)
The USB role switch does not always have the _PLD (Physical
Location of Device) in ACPI tables. If it's missing,
assigning the PLD hash of the port to the switch. That
should guarantee that the USB Type-C port mapping code is
always able to find the connection between the two (the port
and the switch).

Tested-by: Uday Bhat <uday.m.bhat@intel.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20240213130018.3029991-3-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/platform/chrome/cros_ec_typec.c

index 2b2f14a1b71193ca62319a24a5384aa541835eec..4d305876ec08f6d87e7f2d6c3bb5478d26e1db36 100644 (file)
 #define DP_PORT_VDO    (DP_CONF_SET_PIN_ASSIGN(BIT(DP_PIN_ASSIGN_C) | BIT(DP_PIN_ASSIGN_D)) | \
                                DP_CAP_DFP_D | DP_CAP_RECEPTACLE)
 
+static void cros_typec_role_switch_quirk(struct fwnode_handle *fwnode)
+{
+#ifdef CONFIG_ACPI
+       struct fwnode_handle *switch_fwnode;
+
+       /* Supply the USB role switch with the correct pld_crc if it's missing. */
+       switch_fwnode = fwnode_find_reference(fwnode, "usb-role-switch", 0);
+       if (!IS_ERR_OR_NULL(switch_fwnode)) {
+               struct acpi_device *adev = to_acpi_device_node(switch_fwnode);
+
+               if (adev && !adev->pld_crc)
+                       adev->pld_crc = to_acpi_device_node(fwnode)->pld_crc;
+               fwnode_handle_put(switch_fwnode);
+       }
+#endif
+}
+
 static int cros_typec_parse_port_props(struct typec_capability *cap,
                                       struct fwnode_handle *fwnode,
                                       struct device *dev)
@@ -66,6 +83,8 @@ static int cros_typec_parse_port_props(struct typec_capability *cap,
                cap->prefer_role = ret;
        }
 
+       cros_typec_role_switch_quirk(fwnode);
+
        cap->fwnode = fwnode;
 
        return 0;