usb: typec: Add a sysfs node to manage port type
Subsystems (2)
PATCH v6 1/1 usb: typec: Add a sysfs node to manage port type
User space applications in some cases have the need to enforce a specific port type(DFP/UFP/DRP). This change allows userspace to attempt setting the desired port type. Low level drivers can however reject the request if the specific port type is not supported.
---
Changelog since v1:
- introduced a new variable port_type in struct typec_port to track the current port type instead of changing type member in typec_capability to address Heikki Krogerus comments.
- changed the output format and strings that would be displayed as suggested by Heikki Krogerus.
Changelog since v2:
- introduced a new mutex lock to protect port_type for addressing the race conditions identified by Guenter Roeck
- added typec_port_types_drp for printing port_type when cap->type is TYPE_PORT_DRP as suggested by Guenter Roeck
- Power role swap and data role swaps would be rejected unless port port_type == TYPE_PORT_DRP
- port_type_store would return immediately if the current port_type is same as the new port_type as suggested by Guenter Roeck
Changelog since v3:
- Moved as much as code outside port_type_lock as suggested by Guenter Roeck
- Removed Change-Id line from commit message identified by Greg Kroah-Hartman
Changelog since v4:
- Corrected return value and moved moved one more line of code outside port_type_lock in the port_type_store function as suggested by Guenter Roeck
Changelog since v6:
- Added back the ABI Documentation which was dropped accidentally during patch revisions.
Documentation/ABI/testing/sysfs-class-typec | 15 ++++ drivers/usb/typec/typec.c | 106 +++++++++++++++++++++++++--- include/linux/usb/typec.h | 4 ++ 3 files changed, 115 insertions(+), 10 deletions(-)
Documentation/ABI/testing/sysfs-class-typec +15 -0
@@ -30,6 +30,21 @@ Description: Valid values: source, sink +What: /sys/class/typec/<port>/port_type +Date: May 2017 +Contact: Badhri Jagan Sridharan <[email protected]> +Description: + Indicates the type of the port. This attribute can be used for + requesting a change in the port type. Port type change is + supported as a synchronous operation, so write(2) to the + attribute will not return until the operation has finished. + + Valid values: + - source (The port will behave as source only DFP port) + - sink (The port will behave as sink only UFP port) + - dual (The port will behave as dual-role-data and + dual-role-power port) + What: /sys/class/typec/<port>/vconn_source Date: April 2017 Contact: Heikki Krogerus <[email protected]>
drivers/usb/typec/typec.c +96 -10
172 lines not on this page · raw message
include/linux/usb/typec.h +4 -0
@@ -190,6 +190,7 @@ struct typec_partner_desc {* @pr_set: Set Power Role * @vconn_set: Set VCONN Role * @activate_mode: Enter/exit given Alternate Mode +* @port_type_set: Set port type * * Static capabilities of a single USB Type-C port. */
@@ -214,6 +215,9 @@ struct typec_capability {int (*activate_mode)(const struct typec_capability *,int mode,int activate); +int (*port_type_set)(const struct typec_capability *, +enum typec_port_type ); + };/* Specific to try_role(). Indicates the user want's to clear the preference. */
Signature · 1 line
2.13.0.219.gdb65acc882-goog
Hi,
Sorry for the late reply. I was unable to follow my email last week.
Quoted 7 lines · Badhri Jagan Sridharan
User space applications in some cases have the need to enforce a specific port type(DFP/UFP/DRP). This change allows userspace to attempt setting the desired port type. Low level drivers can however reject the request if the specific port type is not supported.
Signed-off-by Badhri Jagan Sridharan <[email protected]>Reviewed-by Guenter Roeck <[email protected]>
It looks good to me. In case Greg has not yet picked this:
Thanks,
Signature · 1 line
heikki
Hi Heikki,
Greg has already picked the change.
I got emails on Jun 3rd saying it has been picked on usb-next branch. I do see it there as well.
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/commit/?h=usb-next&id=bab3548078237706f53baafe43ae58257225549d
Happy to know that you are good with the CL as well :)
Thanks,
Badhri.
Quoted 22 lines · Heikki Krogerus
Hi,
Sorry for the late reply. I was unable to follow my email last week.
Quoted 7 lines · Badhri Jagan Sridharan
User space applications in some cases have the need to enforce a specific port type(DFP/UFP/DRP). This change allows userspace to attempt setting the desired port type. Low level drivers can however reject the request if the specific port type is not supported.
Signed-off-by Badhri Jagan Sridharan <[email protected]>Reviewed-by Guenter Roeck <[email protected]>It looks good to me. In case Greg has not yet picked this:
Acked-by Heikki Krogerus <[email protected]>Thanks,
--
heikki