usb: typec: mux: Add helpers for setting the mux state
Adding helpers typec_switch_set() and typec_mux_set() that simply call the ->set callback function of the mux. These functions make it possible to set the mux states also from outside the class code. Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20200302135353.56659-3-heikki.krogerus@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ef441dd6af
commit
774a9df6ae
@ -1510,11 +1510,9 @@ int typec_set_orientation(struct typec_port *port,
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (port->sw) {
|
||||
ret = port->sw->set(port->sw, orientation);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
ret = typec_switch_set(port->sw, orientation);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
port->orientation = orientation;
|
||||
sysfs_notify(&port->dev.kobj, NULL, "orientation");
|
||||
@ -1550,7 +1548,7 @@ int typec_set_mode(struct typec_port *port, int mode)
|
||||
|
||||
state.mode = mode;
|
||||
|
||||
return port->mux ? port->mux->set(port->mux, &state) : 0;
|
||||
return typec_mux_set(port->mux, &state);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(typec_set_mode);
|
||||
|
||||
|
@ -141,6 +141,16 @@ typec_switch_register(struct device *parent,
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(typec_switch_register);
|
||||
|
||||
int typec_switch_set(struct typec_switch *sw,
|
||||
enum typec_orientation orientation)
|
||||
{
|
||||
if (IS_ERR_OR_NULL(sw))
|
||||
return 0;
|
||||
|
||||
return sw->set(sw, orientation);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(typec_switch_set);
|
||||
|
||||
/**
|
||||
* typec_switch_unregister - Unregister USB Type-C orientation switch
|
||||
* @sw: USB Type-C orientation switch
|
||||
@ -269,6 +279,15 @@ void typec_mux_put(struct typec_mux *mux)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(typec_mux_put);
|
||||
|
||||
int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state)
|
||||
{
|
||||
if (IS_ERR_OR_NULL(mux))
|
||||
return 0;
|
||||
|
||||
return mux->set(mux, state);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(typec_mux_set);
|
||||
|
||||
static void typec_mux_release(struct device *dev)
|
||||
{
|
||||
kfree(to_typec_mux(dev));
|
||||
|
@ -23,6 +23,9 @@ struct typec_switch_desc {
|
||||
|
||||
struct typec_switch *typec_switch_get(struct device *dev);
|
||||
void typec_switch_put(struct typec_switch *sw);
|
||||
int typec_switch_set(struct typec_switch *sw,
|
||||
enum typec_orientation orientation);
|
||||
|
||||
struct typec_switch *
|
||||
typec_switch_register(struct device *parent,
|
||||
const struct typec_switch_desc *desc);
|
||||
@ -50,6 +53,8 @@ struct typec_mux_desc {
|
||||
struct typec_mux *
|
||||
typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc);
|
||||
void typec_mux_put(struct typec_mux *mux);
|
||||
int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state);
|
||||
|
||||
struct typec_mux *
|
||||
typec_mux_register(struct device *parent, const struct typec_mux_desc *desc);
|
||||
void typec_mux_unregister(struct typec_mux *mux);
|
||||
|
Loading…
Reference in New Issue
Block a user