usb: typec: tipd: Fix initialization sequence for cd321x
authorHector Martin <marcan@marcan.st>
Sat, 20 Nov 2021 03:07:17 +0000 (12:07 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 23 Nov 2021 13:08:08 +0000 (14:08 +0100)
The power state switch needs to happen first, as that
kickstarts the firmware into normal mode.

Fixes: c9c14be664cf ("usb: typec: tipd: Switch CD321X power state to S0")
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Sven Peter <sven@svenpeter.dev>
Signed-off-by: Hector Martin <marcan@marcan.st>
Link: https://lore.kernel.org/r/20211120030717.84287-3-marcan@marcan.st
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/tipd/core.c

index 4da5a0b2aed27101ad32ce08874d286b57e74490..6d27a5b5e3cac6beb8df1edce9e59f14e5abb8be 100644 (file)
@@ -707,6 +707,7 @@ static int tps6598x_probe(struct i2c_client *client)
        u32 conf;
        u32 vid;
        int ret;
+       u64 mask1;
 
        tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
        if (!tps)
@@ -730,11 +731,6 @@ static int tps6598x_probe(struct i2c_client *client)
        if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
                tps->i2c_protocol = true;
 
-       /* Make sure the controller has application firmware running */
-       ret = tps6598x_check_mode(tps);
-       if (ret)
-               return ret;
-
        if (np && of_device_is_compatible(np, "apple,cd321x")) {
                /* Switch CD321X chips to the correct system power state */
                ret = cd321x_switch_power_state(tps, TPS_SYSTEM_POWER_STATE_S0);
@@ -742,24 +738,27 @@ static int tps6598x_probe(struct i2c_client *client)
                        return ret;
 
                /* CD321X chips have all interrupts masked initially */
-               ret = tps6598x_write64(tps, TPS_REG_INT_MASK1,
-                                       APPLE_CD_REG_INT_POWER_STATUS_UPDATE |
-                                       APPLE_CD_REG_INT_DATA_STATUS_UPDATE |
-                                       APPLE_CD_REG_INT_PLUG_EVENT);
-               if (ret)
-                       return ret;
+               mask1 = APPLE_CD_REG_INT_POWER_STATUS_UPDATE |
+                       APPLE_CD_REG_INT_DATA_STATUS_UPDATE |
+                       APPLE_CD_REG_INT_PLUG_EVENT;
 
                irq_handler = cd321x_interrupt;
        } else {
                /* Enable power status, data status and plug event interrupts */
-               ret = tps6598x_write64(tps, TPS_REG_INT_MASK1,
-                                      TPS_REG_INT_POWER_STATUS_UPDATE |
-                                      TPS_REG_INT_DATA_STATUS_UPDATE |
-                                      TPS_REG_INT_PLUG_EVENT);
-               if (ret)
-                       return ret;
+               mask1 = TPS_REG_INT_POWER_STATUS_UPDATE |
+                       TPS_REG_INT_DATA_STATUS_UPDATE |
+                       TPS_REG_INT_PLUG_EVENT;
        }
 
+       /* Make sure the controller has application firmware running */
+       ret = tps6598x_check_mode(tps);
+       if (ret)
+               return ret;
+
+       ret = tps6598x_write64(tps, TPS_REG_INT_MASK1, mask1);
+       if (ret)
+               return ret;
+
        ret = tps6598x_read32(tps, TPS_REG_STATUS, &status);
        if (ret < 0)
                return ret;