History

usb: typec: Rationalize the API for the muxes

Since with accessory modes there is no need for additional identification when requesting a handle to the mux, we can replace the second parameter that is passed to the typec_mux_get() function with a pointer to alternate mode description structure, and simply passing NULL with accessory modes. This change means the naming of the mux device connections can be updated. Alternate and Accessory Modes will both be handled with muxes named "mode-switch", and the orientation switches will be named "orientation-switch". Future identification of the alternate modes will be later done using device property "svid" of the mux.

Heikki Krogerus committed 7 years ago

Commit 540bfab1 parent 78757323 files · +10 −10Browse files

Unified · Split

3 files
  1. drivers/usb/typec/class.c +2 −5
  2. drivers/usb/typec/mux.c +6 −4
  3. include/linux/usb/typec_mux.h +2 −1
drivers/usb/typec/class.c+2−5
@@ -1496,11 +1496,8 @@ typec_port_register_altmode(struct typec_port *port, · 1495 unmodified lines
14961496 {
14971497 struct typec_altmode *adev;
14981498 struct typec_mux *mux;
1499− char id[10];
15001499
1501− sprintf(id, "id%04xm%02x", desc->svid, desc->mode);
1502−
1503− mux = typec_mux_get(&port->dev, id);
1500+ mux = typec_mux_get(&port->dev, desc);
15041501 if (IS_ERR(mux))
15051502 return ERR_CAST(mux);
15061503
@@ -1593,7 +1590,7 @@ struct typec_port *typec_register_port(struct device *parent, · 86 unmodified lines
15931590 return ERR_CAST(port->sw);
15941591 }
15951592
1596− port->mux = typec_mux_get(&port->dev, "typec-mux");
1593+ port->mux = typec_mux_get(&port->dev, NULL);
15971594 if (IS_ERR(port->mux)) {
15981595 put_device(&port->dev);
15991596 return ERR_CAST(port->mux);
drivers/usb/typec/mux.c+6−4
@@ -48,7 +48,7 @@ struct typec_switch *typec_switch_get(struct device *dev) · 47 unmodified lines
4848 struct typec_switch *sw;
4949
5050 mutex_lock(&switch_lock);
51− sw = device_connection_find_match(dev, "typec-switch", NULL,
51+ sw = device_connection_find_match(dev, "orientation-switch", NULL,
5252 typec_switch_match);
5353 if (!IS_ERR_OR_NULL(sw)) {
5454 WARN_ON(!try_module_get(sw->dev->driver->owner));
@@ -128,19 +128,21 @@ static void *typec_mux_match(struct device_connection *con, int ep, void *data) · 73 unmodified lines
128128 /**
129129 * typec_mux_get - Find USB Type-C Multiplexer
130130 * @dev: The caller device
131− * @name: Mux identifier
131+ * @desc: Alt Mode description
132132 *
133133 * Finds a mux linked to the caller. This function is primarily meant for the
134134 * Type-C drivers. Returns a reference to the mux on success, NULL if no
135135 * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection
136136 * was found but the mux has not been enumerated yet.
137137 */
138−struct typec_mux *typec_mux_get(struct device *dev, const char *name)
138+struct typec_mux *typec_mux_get(struct device *dev,
139+ const struct typec_altmode_desc *desc)
139140 {
140141 struct typec_mux *mux;
141142
142143 mutex_lock(&mux_lock);
143− mux = device_connection_find_match(dev, name, NULL, typec_mux_match);
144+ mux = device_connection_find_match(dev, "mode-switch", (void *)desc,
145+ typec_mux_match);
144146 if (!IS_ERR_OR_NULL(mux)) {
145147 WARN_ON(!try_module_get(mux->dev->driver->owner));
146148 get_device(mux->dev);
include/linux/usb/typec_mux.h+2−1
@@ -47,7 +47,8 @@ void typec_switch_put(struct typec_switch *sw); · 46 unmodified lines
4747 int typec_switch_register(struct typec_switch *sw);
4848 void typec_switch_unregister(struct typec_switch *sw);
4949
50−struct typec_mux *typec_mux_get(struct device *dev, const char *name);
50+struct typec_mux *
51+typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc);
5152 void typec_mux_put(struct typec_mux *mux);
5253 int typec_mux_register(struct typec_mux *mux);
5354 void typec_mux_unregister(struct typec_mux *mux);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t