Skip to content

Commit

Permalink
usb: typec: Registering real device entries for the muxes
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Tested-by: Hans de Goede <[email protected]>
Signed-off-by: Rafael J. Wysocki <[email protected]>
  • Loading branch information
Heikki Krogerus authored and rafaeljw committed Jun 3, 2019
1 parent fde7777 commit 3370db3
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 123 deletions.
4 changes: 2 additions & 2 deletions drivers/platform/x86/intel_cht_int33fe.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ static int cht_int33fe_probe(struct platform_device *pdev)
}

data->connections[0].endpoint[0] = "port0";
data->connections[0].endpoint[1] = "i2c-pi3usb30532";
data->connections[0].endpoint[1] = "i2c-pi3usb30532-switch";
data->connections[0].id = "orientation-switch";
data->connections[1].endpoint[0] = "port0";
data->connections[1].endpoint[1] = "i2c-pi3usb30532";
data->connections[1].endpoint[1] = "i2c-pi3usb30532-mux";
data->connections[1].id = "mode-switch";
data->connections[2].endpoint[0] = "i2c-fusb302";
data->connections[2].endpoint[1] = "intel_xhci_usb_sw-role-switch";
Expand Down
15 changes: 15 additions & 0 deletions drivers/usb/typec/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,19 @@ extern const struct device_type typec_port_dev_type;
#define is_typec_altmode(_dev_) (_dev_->type == &typec_altmode_dev_type)
#define is_typec_port(_dev_) (_dev_->type == &typec_port_dev_type)

extern struct class typec_mux_class;

struct typec_switch {
struct device dev;
typec_switch_set_fn_t set;
};

struct typec_mux {
struct device dev;
typec_mux_set_fn_t set;
};

#define to_typec_switch(_dev_) container_of(_dev_, struct typec_switch, dev)
#define to_typec_mux(_dev_) container_of(_dev_, struct typec_mux, dev)

#endif /* __USB_TYPEC_ALTMODE_H__ */
17 changes: 15 additions & 2 deletions drivers/usb/typec/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -1646,13 +1646,25 @@ static int __init typec_init(void)
if (ret)
return ret;

ret = class_register(&typec_mux_class);
if (ret)
goto err_unregister_bus;

typec_class = class_create(THIS_MODULE, "typec");
if (IS_ERR(typec_class)) {
bus_unregister(&typec_bus);
return PTR_ERR(typec_class);
ret = PTR_ERR(typec_class);
goto err_unregister_mux_class;
}

return 0;

err_unregister_mux_class:
class_unregister(&typec_mux_class);

err_unregister_bus:
bus_unregister(&typec_bus);

return ret;
}
subsys_initcall(typec_init);

Expand All @@ -1661,6 +1673,7 @@ static void __exit typec_exit(void)
class_destroy(typec_class);
ida_destroy(&typec_index_ida);
bus_unregister(&typec_bus);
class_unregister(&typec_mux_class);
}
module_exit(typec_exit);

Expand Down
Loading

0 comments on commit 3370db3

Please sign in to comment.