Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: typec: mux: Allow the mux handles to be requested with fwnode

Introducing fwnode_typec_switch_get() and
fwnode_typec_mux_get() functions that work just like
typec_switch_get() and typec_mux_get() but they take struct
fwnode_handle as the first parameter instead of struct
device.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20200302135353.56659-4-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Heikki Krogerus and committed by
Greg Kroah-Hartman
d1c6a769 774a9df6

+26 -14
+11 -11
drivers/usb/typec/mux.c
··· 49 49 } 50 50 51 51 /** 52 - * typec_switch_get - Find USB Type-C orientation switch 53 - * @dev: The caller device 52 + * fwnode_typec_switch_get - Find USB Type-C orientation switch 53 + * @fwnode: The caller device node 54 54 * 55 55 * Finds a switch linked with @dev. Returns a reference to the switch on 56 56 * success, NULL if no matching connection was found, or 57 57 * ERR_PTR(-EPROBE_DEFER) when a connection was found but the switch 58 58 * has not been enumerated yet. 59 59 */ 60 - struct typec_switch *typec_switch_get(struct device *dev) 60 + struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode) 61 61 { 62 62 struct typec_switch *sw; 63 63 64 - sw = device_connection_find_match(dev, "orientation-switch", NULL, 64 + sw = fwnode_connection_find_match(fwnode, "orientation-switch", NULL, 65 65 typec_switch_match); 66 66 if (!IS_ERR_OR_NULL(sw)) 67 67 WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); 68 68 69 69 return sw; 70 70 } 71 - EXPORT_SYMBOL_GPL(typec_switch_get); 71 + EXPORT_SYMBOL_GPL(fwnode_typec_switch_get); 72 72 73 73 /** 74 74 * typec_put_switch - Release USB Type-C orientation switch ··· 241 241 } 242 242 243 243 /** 244 - * typec_mux_get - Find USB Type-C Multiplexer 245 - * @dev: The caller device 244 + * fwnode_typec_mux_get - Find USB Type-C Multiplexer 245 + * @fwnode: The caller device node 246 246 * @desc: Alt Mode description 247 247 * 248 248 * Finds a mux linked to the caller. This function is primarily meant for the ··· 250 250 * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection 251 251 * was found but the mux has not been enumerated yet. 252 252 */ 253 - struct typec_mux *typec_mux_get(struct device *dev, 254 - const struct typec_altmode_desc *desc) 253 + struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode, 254 + const struct typec_altmode_desc *desc) 255 255 { 256 256 struct typec_mux *mux; 257 257 258 - mux = device_connection_find_match(dev, "mode-switch", (void *)desc, 258 + mux = fwnode_connection_find_match(fwnode, "mode-switch", (void *)desc, 259 259 typec_mux_match); 260 260 if (!IS_ERR_OR_NULL(mux)) 261 261 WARN_ON(!try_module_get(mux->dev.parent->driver->owner)); 262 262 263 263 return mux; 264 264 } 265 - EXPORT_SYMBOL_GPL(typec_mux_get); 265 + EXPORT_SYMBOL_GPL(fwnode_typec_mux_get); 266 266 267 267 /** 268 268 * typec_mux_put - Release handle to a Multiplexer
+15 -3
include/linux/usb/typec_mux.h
··· 3 3 #ifndef __USB_TYPEC_MUX 4 4 #define __USB_TYPEC_MUX 5 5 6 + #include <linux/property.h> 6 7 #include <linux/usb/typec.h> 7 8 8 9 struct device; ··· 22 21 void *drvdata; 23 22 }; 24 23 25 - struct typec_switch *typec_switch_get(struct device *dev); 24 + struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode); 26 25 void typec_switch_put(struct typec_switch *sw); 27 26 int typec_switch_set(struct typec_switch *sw, 28 27 enum typec_orientation orientation); 28 + 29 + static inline struct typec_switch *typec_switch_get(struct device *dev) 30 + { 31 + return fwnode_typec_switch_get(dev_fwnode(dev)); 32 + } 29 33 30 34 struct typec_switch * 31 35 typec_switch_register(struct device *parent, ··· 56 50 void *drvdata; 57 51 }; 58 52 59 - struct typec_mux * 60 - typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc); 53 + struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode, 54 + const struct typec_altmode_desc *desc); 61 55 void typec_mux_put(struct typec_mux *mux); 62 56 int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state); 57 + 58 + static inline struct typec_mux * 59 + typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc) 60 + { 61 + return fwnode_typec_mux_get(dev_fwnode(dev), desc); 62 + } 63 63 64 64 struct typec_mux * 65 65 typec_mux_register(struct device *parent, const struct typec_mux_desc *desc);