Commit d1c6a769 authored by Heikki Krogerus's avatar Heikki Krogerus Committed by Greg Kroah-Hartman

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: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20200302135353.56659-4-heikki.krogerus@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 774a9df6
...@@ -49,26 +49,26 @@ static void *typec_switch_match(struct device_connection *con, int ep, ...@@ -49,26 +49,26 @@ static void *typec_switch_match(struct device_connection *con, int ep,
} }
/** /**
* typec_switch_get - Find USB Type-C orientation switch * fwnode_typec_switch_get - Find USB Type-C orientation switch
* @dev: The caller device * @fwnode: The caller device node
* *
* Finds a switch linked with @dev. Returns a reference to the switch on * Finds a switch linked with @dev. Returns a reference to the switch on
* success, NULL if no matching connection was found, or * success, NULL if no matching connection was found, or
* ERR_PTR(-EPROBE_DEFER) when a connection was found but the switch * ERR_PTR(-EPROBE_DEFER) when a connection was found but the switch
* has not been enumerated yet. * has not been enumerated yet.
*/ */
struct typec_switch *typec_switch_get(struct device *dev) struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
{ {
struct typec_switch *sw; struct typec_switch *sw;
sw = device_connection_find_match(dev, "orientation-switch", NULL, sw = fwnode_connection_find_match(fwnode, "orientation-switch", NULL,
typec_switch_match); typec_switch_match);
if (!IS_ERR_OR_NULL(sw)) if (!IS_ERR_OR_NULL(sw))
WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
return sw; return sw;
} }
EXPORT_SYMBOL_GPL(typec_switch_get); EXPORT_SYMBOL_GPL(fwnode_typec_switch_get);
/** /**
* typec_put_switch - Release USB Type-C orientation switch * typec_put_switch - Release USB Type-C orientation switch
...@@ -241,8 +241,8 @@ static void *typec_mux_match(struct device_connection *con, int ep, void *data) ...@@ -241,8 +241,8 @@ static void *typec_mux_match(struct device_connection *con, int ep, void *data)
} }
/** /**
* typec_mux_get - Find USB Type-C Multiplexer * fwnode_typec_mux_get - Find USB Type-C Multiplexer
* @dev: The caller device * @fwnode: The caller device node
* @desc: Alt Mode description * @desc: Alt Mode description
* *
* Finds a mux linked to the caller. This function is primarily meant for the * Finds a mux linked to the caller. This function is primarily meant for the
...@@ -250,19 +250,19 @@ static void *typec_mux_match(struct device_connection *con, int ep, void *data) ...@@ -250,19 +250,19 @@ static void *typec_mux_match(struct device_connection *con, int ep, void *data)
* matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection
* was found but the mux has not been enumerated yet. * was found but the mux has not been enumerated yet.
*/ */
struct typec_mux *typec_mux_get(struct device *dev, struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode,
const struct typec_altmode_desc *desc) const struct typec_altmode_desc *desc)
{ {
struct typec_mux *mux; struct typec_mux *mux;
mux = device_connection_find_match(dev, "mode-switch", (void *)desc, mux = fwnode_connection_find_match(fwnode, "mode-switch", (void *)desc,
typec_mux_match); typec_mux_match);
if (!IS_ERR_OR_NULL(mux)) if (!IS_ERR_OR_NULL(mux))
WARN_ON(!try_module_get(mux->dev.parent->driver->owner)); WARN_ON(!try_module_get(mux->dev.parent->driver->owner));
return mux; return mux;
} }
EXPORT_SYMBOL_GPL(typec_mux_get); EXPORT_SYMBOL_GPL(fwnode_typec_mux_get);
/** /**
* typec_mux_put - Release handle to a Multiplexer * typec_mux_put - Release handle to a Multiplexer
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#ifndef __USB_TYPEC_MUX #ifndef __USB_TYPEC_MUX
#define __USB_TYPEC_MUX #define __USB_TYPEC_MUX
#include <linux/property.h>
#include <linux/usb/typec.h> #include <linux/usb/typec.h>
struct device; struct device;
...@@ -21,11 +22,16 @@ struct typec_switch_desc { ...@@ -21,11 +22,16 @@ struct typec_switch_desc {
void *drvdata; void *drvdata;
}; };
struct typec_switch *typec_switch_get(struct device *dev); struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode);
void typec_switch_put(struct typec_switch *sw); void typec_switch_put(struct typec_switch *sw);
int typec_switch_set(struct typec_switch *sw, int typec_switch_set(struct typec_switch *sw,
enum typec_orientation orientation); enum typec_orientation orientation);
static inline struct typec_switch *typec_switch_get(struct device *dev)
{
return fwnode_typec_switch_get(dev_fwnode(dev));
}
struct typec_switch * struct typec_switch *
typec_switch_register(struct device *parent, typec_switch_register(struct device *parent,
const struct typec_switch_desc *desc); const struct typec_switch_desc *desc);
...@@ -50,11 +56,17 @@ struct typec_mux_desc { ...@@ -50,11 +56,17 @@ struct typec_mux_desc {
void *drvdata; void *drvdata;
}; };
struct typec_mux * struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode,
typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc); const struct typec_altmode_desc *desc);
void typec_mux_put(struct typec_mux *mux); void typec_mux_put(struct typec_mux *mux);
int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state); int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state);
static inline struct typec_mux *
typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc)
{
return fwnode_typec_mux_get(dev_fwnode(dev), desc);
}
struct typec_mux * struct typec_mux *
typec_mux_register(struct device *parent, const struct typec_mux_desc *desc); typec_mux_register(struct device *parent, const struct typec_mux_desc *desc);
void typec_mux_unregister(struct typec_mux *mux); void typec_mux_unregister(struct typec_mux *mux);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment