Skip to content

Commit 3370db3

Browse files
Heikki Krogerusrafaeljw
authored andcommitted
usb: typec: Registering real device entries for the muxes
Registering real device entries (struct device) for the mode muxes as well as for the orientation switches. The Type-C mux code was deliberately attempting to avoid creation of separate device entries for the orientation switch and the mode switch (alternate modes) because they are not physical devices. They are functions of a single physical multiplexer/demultiplexer switch device. Unfortunately because of the dependency we still have on the underlying mux device driver, we had to put in hacks like the one in the commit 3e3b819 ("usb: typec: mux: Take care of driver module reference counting") to make sure the driver does not disappear from underneath us. Even with those hacks we were still left with a potential NUll pointer dereference scenario, so just creating the device entries, and letting the core take care of the dependencies. No more hacks needed. Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Tested-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent fde7777 commit 3370db3

File tree

6 files changed

+259
-123
lines changed

6 files changed

+259
-123
lines changed

drivers/platform/x86/intel_cht_int33fe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ static int cht_int33fe_probe(struct platform_device *pdev)
173173
}
174174

175175
data->connections[0].endpoint[0] = "port0";
176-
data->connections[0].endpoint[1] = "i2c-pi3usb30532";
176+
data->connections[0].endpoint[1] = "i2c-pi3usb30532-switch";
177177
data->connections[0].id = "orientation-switch";
178178
data->connections[1].endpoint[0] = "port0";
179-
data->connections[1].endpoint[1] = "i2c-pi3usb30532";
179+
data->connections[1].endpoint[1] = "i2c-pi3usb30532-mux";
180180
data->connections[1].id = "mode-switch";
181181
data->connections[2].endpoint[0] = "i2c-fusb302";
182182
data->connections[2].endpoint[1] = "intel_xhci_usb_sw-role-switch";

drivers/usb/typec/bus.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,19 @@ extern const struct device_type typec_port_dev_type;
3535
#define is_typec_altmode(_dev_) (_dev_->type == &typec_altmode_dev_type)
3636
#define is_typec_port(_dev_) (_dev_->type == &typec_port_dev_type)
3737

38+
extern struct class typec_mux_class;
39+
40+
struct typec_switch {
41+
struct device dev;
42+
typec_switch_set_fn_t set;
43+
};
44+
45+
struct typec_mux {
46+
struct device dev;
47+
typec_mux_set_fn_t set;
48+
};
49+
50+
#define to_typec_switch(_dev_) container_of(_dev_, struct typec_switch, dev)
51+
#define to_typec_mux(_dev_) container_of(_dev_, struct typec_mux, dev)
52+
3853
#endif /* __USB_TYPEC_ALTMODE_H__ */

drivers/usb/typec/class.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,13 +1646,25 @@ static int __init typec_init(void)
16461646
if (ret)
16471647
return ret;
16481648

1649+
ret = class_register(&typec_mux_class);
1650+
if (ret)
1651+
goto err_unregister_bus;
1652+
16491653
typec_class = class_create(THIS_MODULE, "typec");
16501654
if (IS_ERR(typec_class)) {
1651-
bus_unregister(&typec_bus);
1652-
return PTR_ERR(typec_class);
1655+
ret = PTR_ERR(typec_class);
1656+
goto err_unregister_mux_class;
16531657
}
16541658

16551659
return 0;
1660+
1661+
err_unregister_mux_class:
1662+
class_unregister(&typec_mux_class);
1663+
1664+
err_unregister_bus:
1665+
bus_unregister(&typec_bus);
1666+
1667+
return ret;
16561668
}
16571669
subsys_initcall(typec_init);
16581670

@@ -1661,6 +1673,7 @@ static void __exit typec_exit(void)
16611673
class_destroy(typec_class);
16621674
ida_destroy(&typec_index_ida);
16631675
bus_unregister(&typec_bus);
1676+
class_unregister(&typec_mux_class);
16641677
}
16651678
module_exit(typec_exit);
16661679

0 commit comments

Comments
 (0)