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
1496{1496{
1497 struct typec_altmode *adev;1497 struct typec_altmode *adev;
1498 struct typec_mux *mux;1498 struct typec_mux *mux;
1499 char id[10];
1500 1499
1501 sprintf(id, "id%04xm%02x", desc->svid, desc->mode);1500 mux = typec_mux_get(&port->dev, desc);
1502
1503 mux = typec_mux_get(&port->dev, id);
1504 if (IS_ERR(mux))1501 if (IS_ERR(mux))
1505 return ERR_CAST(mux);1502 return ERR_CAST(mux);
1506 1503
@@ -1593,7 +1590,7 @@ struct typec_port *typec_register_port(struct device *parent, · 86 unmodified lines
1593 return ERR_CAST(port->sw);1590 return ERR_CAST(port->sw);
1594 }1591 }
1595 1592
1596 port->mux = typec_mux_get(&port->dev, "typec-mux");1593 port->mux = typec_mux_get(&port->dev, NULL);
1597 if (IS_ERR(port->mux)) {1594 if (IS_ERR(port->mux)) {
1598 put_device(&port->dev);1595 put_device(&port->dev);
1599 return ERR_CAST(port->mux);1596 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
48 struct typec_switch *sw;48 struct typec_switch *sw;
49 49
50 mutex_lock(&switch_lock);50 mutex_lock(&switch_lock);
51 sw = device_connection_find_match(dev, "typec-switch", NULL,51 sw = device_connection_find_match(dev, "orientation-switch", NULL,
52 typec_switch_match);52 typec_switch_match);
53 if (!IS_ERR_OR_NULL(sw)) {53 if (!IS_ERR_OR_NULL(sw)) {
54 WARN_ON(!try_module_get(sw->dev->driver->owner));54 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
128/**128/**
129 * typec_mux_get - Find USB Type-C Multiplexer129 * typec_mux_get - Find USB Type-C Multiplexer
130 * @dev: The caller device130 * @dev: The caller device
131 * @name: Mux identifier131 * @desc: Alt Mode description
132 *132 *
133 * Finds a mux linked to the caller. This function is primarily meant for the133 * Finds a mux linked to the caller. This function is primarily meant for the
134 * Type-C drivers. Returns a reference to the mux on success, NULL if no134 * Type-C drivers. Returns a reference to the mux on success, NULL if no
135 * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection135 * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection
136 * was found but the mux has not been enumerated yet.136 * was found but the mux has not been enumerated yet.
137 */137 */
138struct typec_mux *typec_mux_get(struct device *dev, const char *name)138struct typec_mux *typec_mux_get(struct device *dev,
139 const struct typec_altmode_desc *desc)
139{140{
140 struct typec_mux *mux;141 struct typec_mux *mux;
141 142
142 mutex_lock(&mux_lock);143 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);
144 if (!IS_ERR_OR_NULL(mux)) {146 if (!IS_ERR_OR_NULL(mux)) {
145 WARN_ON(!try_module_get(mux->dev->driver->owner));147 WARN_ON(!try_module_get(mux->dev->driver->owner));
146 get_device(mux->dev);148 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
47int typec_switch_register(struct typec_switch *sw);47int typec_switch_register(struct typec_switch *sw);
48void typec_switch_unregister(struct typec_switch *sw);48void typec_switch_unregister(struct typec_switch *sw);
49 49
50struct typec_mux *typec_mux_get(struct device *dev, const char *name);50struct typec_mux *
51typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc);
51void typec_mux_put(struct typec_mux *mux);52void typec_mux_put(struct typec_mux *mux);
52int typec_mux_register(struct typec_mux *mux);53int typec_mux_register(struct typec_mux *mux);
53void typec_mux_unregister(struct typec_mux *mux);54void 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