@@ -917,6 +917,12 @@ EXPORT_SYMBOL_GPL(typec_unregister_cable);
917
917
/* ------------------------------------------------------------------------- */
918
918
/* USB Type-C ports */
919
919
920
+ static const char * const typec_orientations [] = {
921
+ [TYPEC_ORIENTATION_NONE ] = "unknown" ,
922
+ [TYPEC_ORIENTATION_NORMAL ] = "normal" ,
923
+ [TYPEC_ORIENTATION_REVERSE ] = "reverse" ,
924
+ };
925
+
920
926
static const char * const typec_roles [] = {
921
927
[TYPEC_SINK ] = "sink" ,
922
928
[TYPEC_SOURCE ] = "source" ,
@@ -1248,18 +1254,9 @@ static ssize_t orientation_show(struct device *dev,
1248
1254
struct device_attribute * attr ,
1249
1255
char * buf )
1250
1256
{
1251
- struct typec_port * p = to_typec_port (dev );
1252
- enum typec_orientation orientation = typec_get_orientation (p );
1253
-
1254
- switch (orientation ) {
1255
- case TYPEC_ORIENTATION_NORMAL :
1256
- return sprintf (buf , "%s\n" , "normal" );
1257
- case TYPEC_ORIENTATION_REVERSE :
1258
- return sprintf (buf , "%s\n" , "reverse" );
1259
- case TYPEC_ORIENTATION_NONE :
1260
- default :
1261
- return sprintf (buf , "%s\n" , "unknown" );
1262
- }
1257
+ struct typec_port * port = to_typec_port (dev );
1258
+
1259
+ return sprintf (buf , "%s\n" , typec_orientations [port -> orientation ]);
1263
1260
}
1264
1261
static DEVICE_ATTR_RO (orientation );
1265
1262
@@ -1451,6 +1448,21 @@ void typec_set_pwr_opmode(struct typec_port *port,
1451
1448
}
1452
1449
EXPORT_SYMBOL_GPL (typec_set_pwr_opmode );
1453
1450
1451
+ /**
1452
+ * typec_find_orientation - Convert orientation string to enum typec_orientation
1453
+ * @name: Orientation string
1454
+ *
1455
+ * This routine is used to find the typec_orientation by its string name @name.
1456
+ *
1457
+ * Returns the orientation value on success, otherwise negative error code.
1458
+ */
1459
+ int typec_find_orientation (const char * name )
1460
+ {
1461
+ return match_string (typec_orientations , ARRAY_SIZE (typec_orientations ),
1462
+ name );
1463
+ }
1464
+ EXPORT_SYMBOL_GPL (typec_find_orientation );
1465
+
1454
1466
/**
1455
1467
* typec_find_port_power_role - Get the typec port power capability
1456
1468
* @name: port power capability string
0 commit comments