usb: typec: Make bus switch code retimer-aware
authorPrashant Malani <pmalani@chromium.org>
Thu, 12 Jan 2023 22:16:08 +0000 (22:16 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 17 Jan 2023 16:29:00 +0000 (17:29 +0100)
Since ports can have retimers associated with them, update the Type-C
alternate mode bus code to also set retimer state when the switch state
is updated.

While we are here, make the typec_retimer_dev_type declaration in the
retimer.h file as extern, so that the header file can be successfully
included in the bus code without redeclaration compilation errors.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20230112221609.540754-4-pmalani@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/bus.c
drivers/usb/typec/retimer.h

index 9f1bbd26ca4787c7330521000ec1f6e7288f17df..0c8d554240be7796593484befa70818f82e9758f 100644 (file)
 #include "bus.h"
 #include "class.h"
 #include "mux.h"
+#include "retimer.h"
+
+static inline int
+typec_altmode_set_retimer(struct altmode *alt, unsigned long conf, void *data)
+{
+       struct typec_retimer_state state;
+
+       if (!alt->retimer)
+               return 0;
+
+       state.alt = &alt->adev;
+       state.mode = conf;
+       state.data = data;
+
+       return typec_retimer_set(alt->retimer, &state);
+}
 
 static inline int
 typec_altmode_set_mux(struct altmode *alt, unsigned long conf, void *data)
@@ -31,6 +47,12 @@ typec_altmode_set_mux(struct altmode *alt, unsigned long conf, void *data)
 static inline int
 typec_altmode_set_switches(struct altmode *alt, unsigned long conf, void *data)
 {
+       int ret;
+
+       ret = typec_altmode_set_retimer(alt, conf, data);
+       if (ret)
+               return ret;
+
        return typec_altmode_set_mux(alt, conf, data);
 }
 
index e34bd23323be50f3d255fbffc51869fd2ed377a2..d6a5ef9881e1f0cbc0cea32ae0c48db435b61171 100644 (file)
@@ -12,7 +12,7 @@ struct typec_retimer {
 
 #define to_typec_retimer(_dev_) container_of(_dev_, struct typec_retimer, dev)
 
-const struct device_type typec_retimer_dev_type;
+extern const struct device_type typec_retimer_dev_type;
 
 #define is_typec_retimer(dev) ((dev)->type == &typec_retimer_dev_type)