Skip to content

Commit

Permalink
usb: typec: Add typec_find_orientation()
Browse files Browse the repository at this point in the history
Function that converts orientation string into orientation
value.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20200507150900.12102-2-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Heikki Krogerus authored and Greg Kroah-Hartman committed May 13, 2020
1 parent 3e63cff commit 8c49c9e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
36 changes: 24 additions & 12 deletions drivers/usb/typec/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,12 @@ EXPORT_SYMBOL_GPL(typec_unregister_cable);
/* ------------------------------------------------------------------------- */
/* USB Type-C ports */

static const char * const typec_orientations[] = {
[TYPEC_ORIENTATION_NONE] = "unknown",
[TYPEC_ORIENTATION_NORMAL] = "normal",
[TYPEC_ORIENTATION_REVERSE] = "reverse",
};

static const char * const typec_roles[] = {
[TYPEC_SINK] = "sink",
[TYPEC_SOURCE] = "source",
Expand Down Expand Up @@ -1248,18 +1254,9 @@ static ssize_t orientation_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct typec_port *p = to_typec_port(dev);
enum typec_orientation orientation = typec_get_orientation(p);

switch (orientation) {
case TYPEC_ORIENTATION_NORMAL:
return sprintf(buf, "%s\n", "normal");
case TYPEC_ORIENTATION_REVERSE:
return sprintf(buf, "%s\n", "reverse");
case TYPEC_ORIENTATION_NONE:
default:
return sprintf(buf, "%s\n", "unknown");
}
struct typec_port *port = to_typec_port(dev);

return sprintf(buf, "%s\n", typec_orientations[port->orientation]);
}
static DEVICE_ATTR_RO(orientation);

Expand Down Expand Up @@ -1451,6 +1448,21 @@ void typec_set_pwr_opmode(struct typec_port *port,
}
EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);

/**
* typec_find_orientation - Convert orientation string to enum typec_orientation
* @name: Orientation string
*
* This routine is used to find the typec_orientation by its string name @name.
*
* Returns the orientation value on success, otherwise negative error code.
*/
int typec_find_orientation(const char *name)
{
return match_string(typec_orientations, ARRAY_SIZE(typec_orientations),
name);
}
EXPORT_SYMBOL_GPL(typec_find_orientation);

/**
* typec_find_port_power_role - Get the typec port power capability
* @name: port power capability string
Expand Down
1 change: 1 addition & 0 deletions include/linux/usb/typec.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ int typec_set_mode(struct typec_port *port, int mode);

void *typec_get_drvdata(struct typec_port *port);

int typec_find_orientation(const char *name);
int typec_find_port_power_role(const char *name);
int typec_find_power_role(const char *name);
int typec_find_port_data_role(const char *name);
Expand Down

0 comments on commit 8c49c9e

Please sign in to comment.