USB Type-C Connector class
Subsystems (5)
Heikki Krogerus
maintainerv11 cover USB Type-C Connector class
The USB Type-C class is meant to provide unified interface to the userspace to present the USB Type-C ports in a system.
Changes since v10:
- Using ATTRIBUTE_GROUPS and DEVICE_ATTR marcos everywhere
- Moved sysfs_match_string to lib/string.c
- Rationalized uevents
- Calling ida_destroy
Changes since v9:
- Minor typec_wcove.c cleanup as proposed by Guenter Roeck. No function affect.
Changes since v8:
- checking sysfs_streq() result correctly in sysfs_strmatch
- fixed accessory check in supported_accessory_mode
- using "none" as the only string that can clear the preferred role
Changes since v7:
- Removed "type" attribute from partners
- Added supports_usb_power_delivery attribute for partner and cable
Changes since v6:
- current_vconn_role attr renamed to vconn_source (no API changes)
- Small documentation improvements proposed by Vincent Palatin
Changes since v5:
- Only updating the roles based on driver notifications
- Added MODULE_ALIAS for the WhiskeyCove module
- Including the patch that creates the actual platform device for the WhiskeyCove Type-C PHY in this series.
Changes since v4:
- Remove the port lock completely
Changes since v3:
- Documentation cleanup as proposed by Roger Quadros
- Setting partner altmodes member to NULL on removal and fixing a warning, as proposed by Guenter Roeck
- Added the following attributes for partners and cables:
* supports_usb_power_delivery
* id_header_vdo
- "id_header_vdo" is visible only when the partner or cable supports USB Power Delivery communication.
- Partner attribute "accessory" is hidden when the partner type is not "Accessory".
Changes since v2:
- Notification on role and alternate mode changes
- cleanups
Changes since v1:
- Completely rewrote alternate mode support
- Patners, cables and cable plugs presented as devices.
Heikki Krogerus (3):
lib/string: add sysfs_match_string helper
usb: USB Type-C connector class
usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY
Documentation/ABI/testing/sysfs-class-typec | 222 ++++++ Documentation/usb/typec.txt | 103 +++ MAINTAINERS | 9 + drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/typec/Kconfig | 21 + drivers/usb/typec/Makefile | 2 + drivers/usb/typec/typec.c | 1012 +++++++++++++++++++++++++++ drivers/usb/typec/typec_wcove.c | 372 ++++++++++ include/linux/string.h | 10 + include/linux/usb/typec.h | 252 +++++++ lib/string.c | 26 + 12 files changed, 2033 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-typec create mode 100644 Documentation/usb/typec.txt create mode 100644 drivers/usb/typec/Kconfig create mode 100644 drivers/usb/typec/Makefile create mode 100644 drivers/usb/typec/typec.c create mode 100644 drivers/usb/typec/typec_wcove.c create mode 100644 include/linux/usb/typec.h
Signature · 1 line
2.10.2
Heikki Krogerus
maintainerPATCH v11 1/3 lib/string: add sysfs_match_string helper
Make a simple helper for matching strings with sysfs attribute files. In most parts the same as match_string(), except sysfs_match_string() uses sysfs_streq() instead of strcmp() for matching. This is more convenient when used with sysfs attributes.
--- include/linux/string.h | 10 ++++++++++ lib/string.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
include/linux/string.h +10 -0
@@ -135,6 +135,16 @@ static inline int strtobool(const char *s, bool *res) }int match_string (const char *const *array,size_t n,const char *string); +int __sysfs_match_string (const char *const *array,size_t n,const char *s); + +/** +* sysfs_match_string - matches given string in an array +* @_a: array of strings +* @_s: string to match with +* +* Helper for __sysfs_match_string(). Calculates the size of @a automatically. +*/ +#define sysfs_match_string (_a, _s) __sysfs_match_string(_a, ARRAY_SIZE(_a), _s)#ifdef CONFIG_BINARY_PRINTF int vbin_printf (u32 *bin_buf,size_t size,const char *fmt,va_list args);
lib/string.c +26 -0
@@ -656,6 +656,32 @@ int match_string(const char * const *array, size_t n, const char *string) }EXPORT_SYMBOL (match_string); +/** +* __sysfs_match_string - matches given string in an array +* @array: array of strings +* @n: number of strings in the array or -1 for NULL terminated arrays +* @str: string to match with +* +* Returns index of @str in the @array or -EINVAL, just like match_string(). +* Uses sysfs_streq instead of strcmp for matching. +*/ +int __sysfs_match_string (const char *const *array,size_t n,const char *str) +{ +const char *item; +int index; + +for (index =0 ; index < n; index++) { + item = array[index]; +if (!item) +break ; +if (!sysfs_streq (item, str)) +return index; + } + +return -EINVAL ; +} +EXPORT_SYMBOL (__sysfs_match_string); +#ifndef __HAVE_ARCH_MEMSET/** * memset - Fill a region of memory with the given value
Signature · 1 line
2.10.2
Heikki Krogerus
maintainerPATCH v11 2/3 usb: USB Type-C connector class
In reply to Heikki KrogerusThe purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system, control over data role swapping, and when the port supports USB Power Delivery, also control over power role swapping and Alternate Modes.
--- Documentation/ABI/testing/sysfs-class-typec | 222 ++++++ Documentation/usb/typec.txt | 103 +++ MAINTAINERS | 9 + drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/typec/Kconfig | 7 + drivers/usb/typec/Makefile | 1 + drivers/usb/typec/typec.c | 1012 +++++++++++++++++++++++++++ include/linux/usb/typec.h | 252 +++++++ 9 files changed, 1610 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-typec create mode 100644 Documentation/usb/typec.txt create mode 100644 drivers/usb/typec/Kconfig create mode 100644 drivers/usb/typec/Makefile create mode 100644 drivers/usb/typec/typec.c create mode 100644 include/linux/usb/typec.h
Documentation/ABI/testing/sysfs-class-typec new file +222 -0
@@ -0,0 +1,222 @@ +USB Type-C port devices (eg. /sys/class/typec/usbc0/) + +What: /sys/class/typec/<port>/current_data_role +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + The current USB data role the port is operating in. This + attribute can be used for requesting data role swapping on the + port. Swapping is supported as synchronous operation, so + write(2) to the attribute will not return until the operation + has finished. The attribute is notified about role changes so + that poll(2) on the attribute wakes up. Change on the role will + also generate uevent KOBJ_CHANGE on the port. + + Valid values: + - host + - device + +What: /sys/class/typec/<port>/current_power_role +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + The current power role of the port. This attribute can be used + to request power role swap on the port when the port supports + USB Power Delivery. Swapping is supported as synchronous + operation, so write(2) to the attribute will not return until + the operation has finished. The attribute is notified about role + changes so that poll(2) on the attribute wakes up. Change on the + role will also generate uevent KOBJ_CHANGE. + + Valid values: + - source + - sink + +What: /sys/class/typec/<port>/vconn_source +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows is the port VCONN Source. This attribute can be used to + request VCONN swap to change the VCONN Source during connection + when both the port and the partner support USB Power Delivery. + Swapping is supported as synchronous operation, so write(2) to + the attribute will not return until the operation has finished. + The attribute is notified about VCONN source changes so that + poll(2) on the attribute wakes up. Change on VCONN source also + generates uevent KOBJ_CHANGE. + + Valid values are: + - 0 when the port is not the VCONN Source + - 1 when the port is the VCONN Source + +What: /sys/class/typec/<port>/power_operation_mode +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows the current power operational mode the port is in. + + Valid values: + - USB - Normal power levels defined in USB specifications + - BC1.2 - Power levels defined in Battery Charging Specification + v1.2 + - USB Type-C 1.5A - Higher 1.5A current defined in USB Type-C + specification. + - USB Type-C 3.0A - Higher 3A current defined in USB Type-C + specification. + - USB Power Delivery - The voltages and currents defined in USB + Power Delivery specification + +What: /sys/class/typec/<port>/preferred_role +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + The user space can notify the driver about the preferred role. + It should be handled as enabling of Try.SRC or Try.SNK, as + defined in USB Type-C specification, in the port drivers. By + default there is no preferred role. + + Valid values: + - source + - sink + - none - to remove preference + +What: /sys/class/typec/<port>/supported_accessory_modes +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Lists the Accessory Modes, defined in the USB Type-C + specification, the port supports. + +What: /sys/class/typec/<port>/supported_data_roles +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Lists the USB data roles the port is capable of supporting. + + Valid values: + - device + - host + - device, host (DRD as defined in USB Type-C specification v1.2) + +What: /sys/class/typec/<port>/supported_power_roles +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Lists the power roles the port is capable of supporting. + + Valid values: + - source + - sink + - source, sink (DRP as defined in USB Type-C specification v1.2) + +What: /sys/class/typec/<port>/supports_usb_power_delivery +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the port supports USB Power Delivery. + - 1 if USB Power Delivery is supported + - 0 when it's not + + +USB Type-C partner devices (eg. /sys/class/typec/usbc0-partner/) + +What: /sys/class/typec/<port>-partner/accessory_mode +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows the Accessory Mode name, or "no" when the partner does not + support Accesory Modes. The Accessory Modes are defined in USB + Type-C Specification. + +What: /sys/class/typec/<port>-partner/supports_usb_power_delivery +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the partner supports USB Power Delivery: + - 0 when USB Power Delivery is not supported + - 1 when USB Power Delivery is supported + + +USB Type-C cable devices (eg. /sys/class/typec/usbc0-cable/) + +Note: Electronically Marked Cables will have a device also for one cable plug +(eg. /sys/class/typec/usbc0-plug0). If the cable is active and has also SOP +Double Prime controller (USB Power Deliver specification ch. 2.4) it will have +second device also for the other plug. Both plugs may have their alternate modes +as described in USB Type-C and USB Power Delivery specifications. + +What: /sys/class/typec/<port>-cable/active +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the cable is active or passive. + + Valid values: + - 0 when the cable is passive + - 1 when the cable is active + +What: /sys/class/typec/<port>-cable/plug_type +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows type of the plug on the cable: + - Type-A - Standard A + - Type-B - Standard B + - Type-C - USB Type-C + - Captive - Non-standard + +What: /sys/class/typec/<port>-cable/supports_usb_power_delivery +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the cable supports USB Power Delivery: + - 0 when USB Power Delivery is not supported + - 1 when USB Power Delivery is supported + + +Alternate Mode devices (For example, +/sys/class/typec/usbc0-partner/usbc0-partner.svid:xxxx/). The ports, partners +and cable plugs can have alternate modes. + +What: /sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/active +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the mode is active or not. The attribute can be used + for entering/exiting the mode with partners and cable plugs, and + with the port alternate modes it can be used for disabling + support for specific alternate modes. Entering/exiting modes is + supported as synchronous operation so write(2) to the attribute + does not return until the enter/exit mode operation has + finished. The attribute is notified when the mode is + entered/exited so poll(2) on the attribute wakes up. + Entering/exiting a mode will also generate uevent KOBJ_CHANGE. + + Valid values: + - 0 when the mode is deactive + - 1 when the mode is active + +What: /sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/description +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows description of the mode. The description is optional for + the drivers, just like with the Billboard Devices. + +What: /sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/vdo +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows the VDO in hexadecimal returned from the Discover Modes + command. + +What: /sys/class/typec/<port>/<port>.svid:<svid>/<mode>/supported_roles +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows the roles, source or sink, the mode is supported with. + + This attribute is available for the devices describing the + alternate modes a port supports, and it will not be exposed with + the devices presenting the alternate modes the partners or cable + plugs support.
Documentation/usb/typec.txt new file +103 -0
103 lines not on this page · raw message
MAINTAINERS +9 -0
@@ -12761,6 +12761,15 @@ F: drivers/usb/ F: include/linux/usb.h F: include/linux/usb/ +USB TYPEC SUBSYSTEM +M: Heikki Krogerus <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-class-typec +F: Documentation/usb/typec.txt +F: drivers/usb/typec/ +F: include/linux/usb/typec.h + USB UHCI DRIVER M: Alan Stern <[email protected]> L: [email protected]
drivers/usb/Kconfig +2 -0
@@ -152,6 +152,8 @@ source "drivers/usb/phy/Kconfig" source "drivers/usb/gadget/Kconfig" +source "drivers/usb/typec/Kconfig" + config USB_LED_TRIG bool "USB LED Triggers" depends on LEDS_CLASS && LEDS_TRIGGERS
drivers/usb/Makefile +2 -0
@@ -62,3 +62,5 @@ obj-$(CONFIG_USB_GADGET) += gadget/ obj-$(CONFIG_USB_COMMON) += common/ obj-$(CONFIG_USBIP_CORE) += usbip/ + +obj-$(CONFIG_TYPEC) += typec/
drivers/usb/typec/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ + +menu "USB PD and Type-C drivers" + +config TYPEC + tristate + +endmenu
drivers/usb/typec/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_TYPEC) += typec.o
drivers/usb/typec/typec.c new file +1012 -0
1,012 lines not on this page · raw message
include/linux/usb/typec.h new file +252 -0
252 lines not on this page · raw message
Signature · 1 line
2.10.2
Greg KH
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
Quoted 8 lines · Heikki Krogerus
The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system, control over data role swapping, and when the port supports USB Power Delivery, also control over power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>
I'd like to get some acks or reviewed-by from others, but one thing jumped out at me, which implies you did not run checkpatch.pl on the patch:
644
Quoted 27 lines
drivers/usb/Kconfig +2
-0@@ -152,6 +152,8 @@ source "drivers/usb/phy/Kconfig" source "drivers/usb/gadget/Kconfig" +source "drivers/usb/typec/Kconfig" + config USB_LED_TRIG bool "USB LED Triggers" depends on LEDS_CLASS && LEDS_TRIGGERSdrivers/usb/Makefile +2
-0@@ -62,3 +62,5 @@ obj-$(CONFIG_USB_GADGET) += gadget/ obj-$(CONFIG_USB_COMMON) += common/ obj-$(CONFIG_USBIP_CORE) += usbip/ + +obj-$(CONFIG_TYPEC) += typec/drivers/usb/typec/Kconfig new file +0
-0
drivers/usb/typec/Kconfig line 2
Quoted 2 lines
drivers/usb/typec/Kconfig new file +2
-0@@ -0,0 +1,7 @@ + +menu "USB PD and Type-C drivers"
What is "PD"? (yes, I know, but very few people do...) Spell it out.
drivers/usb/typec/Kconfig line 5
Quoted 3 lines
drivers/usb/typec/Kconfig new file +3
-0+ +config TYPEC + tristate
Hah, that says NOTHING about what this code is at all.
Please fix.
thanks,
greg k-h
Heikki Krogerus
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
Quoted 8 lines · Greg KH
Quoted 7 lines · Heikki Krogerus
The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system, control over data role swapping, and when the port supports USB Power Delivery, also control over power role swapping and Alternate Modes.
Quoted 7 lines
Quoted 1 line
Signed-off-by Heikki Krogerus <[email protected]>I'd like to get some acks or reviewed-by from others, but one thing jumped out at me, which implies you did not run checkpatch.pl on the patch:
644
OK.
Quoted 18 lines
Quoted 18 lines
drivers/usb/Kconfig +2
-0@@ -152,6 +152,8 @@ source "drivers/usb/phy/Kconfig" source "drivers/usb/gadget/Kconfig" +source "drivers/usb/typec/Kconfig" + config USB_LED_TRIG bool "USB LED Triggers" depends on LEDS_CLASS && LEDS_TRIGGERSdrivers/usb/Makefile +0
-0@@ -62,3 +62,5 @@ obj-$(CONFIG_USB_GADGET) += gadget/ obj-$(CONFIG_USB_COMMON) += common/
Quoted 13 lines
drivers/usb/typec/Kconfig line 2
Quoted 11 lines
drivers/usb/Makefile +2
-0obj-$(CONFIG_USBIP_CORE) += usbip/ + +obj-$(CONFIG_TYPEC) += typec/drivers/usb/typec/Kconfig new file +2
-0@@ -0,0 +1,7 @@ + +menu "USB PD and Type-C drivers"What is "PD"? (yes, I know, but very few people do...) Spell it out.
OK.
Quoted 5 lines
drivers/usb/typec/Kconfig line 5
Quoted 3 lines
drivers/usb/typec/Kconfig new file +3
-0+ +config TYPEC + tristateHah, that says NOTHING about what this code is at all.
Alone the class driver does nothing. Why would the user need to be aware of if it when selecting the Type-C drivers, and what can the user use that information for?
Thanks,
Signature · 1 line
heikki
Greg KH
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
Quoted 59 lines · Heikki Krogerus
Quoted 8 lines · Greg KH
Quoted 7 lines · Heikki Krogerus
The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system, control over data role swapping, and when the port supports USB Power Delivery, also control over power role swapping and Alternate Modes.
Quoted 7 lines
Quoted 1 line
Signed-off-by Heikki Krogerus <[email protected]>I'd like to get some acks or reviewed-by from others, but one thing jumped out at me, which implies you did not run checkpatch.pl on the patch:
644
OK.
Quoted 18 lines
Quoted 18 lines
drivers/usb/Kconfig +2
-0@@ -152,6 +152,8 @@ source "drivers/usb/phy/Kconfig" source "drivers/usb/gadget/Kconfig" +source "drivers/usb/typec/Kconfig" + config USB_LED_TRIG bool "USB LED Triggers" depends on LEDS_CLASS && LEDS_TRIGGERSdrivers/usb/Makefile +0
-0@@ -62,3 +62,5 @@ obj-$(CONFIG_USB_GADGET) += gadget/ obj-$(CONFIG_USB_COMMON) += common/Quoted 13 lines
drivers/usb/typec/Kconfig line 2
Quoted 11 lines
drivers/usb/Makefile +2
-0obj-$(CONFIG_USBIP_CORE) += usbip/ + +obj-$(CONFIG_TYPEC) += typec/drivers/usb/typec/Kconfig new file +2
-0@@ -0,0 +1,7 @@ + +menu "USB PD and Type-C drivers"What is "PD"? (yes, I know, but very few people do...) Spell it out.
OK.
Quoted 5 lines
drivers/usb/typec/Kconfig line 5
Quoted 3 lines
drivers/usb/typec/Kconfig new file +3
-0+ +config TYPEC + tristateHah, that says NOTHING about what this code is at all.
Quoted 3 lines
Alone the class driver does nothing. Why would the user need to be aware of if it when selecting the Type-C drivers, and what can the user use that information for?
If you see a blank Kconfig option, what are you supposed to do with it? How do you know if you need to enable it or not? Are you just supposed to guess?
That is what the help text is for...
thanks,
greg k-h
Heikki Krogerus
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
Hi Greg,
Quoted 6 lines · Greg KH
Quoted 6 lines
Quoted 5 lines
drivers/usb/typec/Kconfig line 5
Quoted 3 lines
drivers/usb/typec/Kconfig new file +3
-0+ +config TYPEC + tristateHah, that says NOTHING about what this code is at all.
Quoted 7 lines
Quoted 3 lines
Alone the class driver does nothing. Why would the user need to be aware of if it when selecting the Type-C drivers, and what can the user use that information for?
If you see a blank
Kconfigoption, what are you supposed to do with it? How do you know if you need to enable it or not? Are you just supposed to guess?
But you don't see anything when you are selecting the drivers and that is the point. You now can't select this separately. There is now no option for it.
Why should we bother the user with this? The user is most likely only interested in the drivers and by selecting those the user will get the interface. The drivers will need to have the dependency to the class set correctly in any case.
Thanks,
Signature · 1 line
heikki
Greg KH
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
Quoted 17 lines · Heikki Krogerus
Hi Greg,
Quoted 6 lines · Greg KH
Quoted 6 lines
Quoted 5 lines
drivers/usb/typec/Kconfig line 5
Quoted 3 lines
drivers/usb/typec/Kconfig new file +3
-0+ +config TYPEC + tristateHah, that says NOTHING about what this code is at all.
Quoted 7 lines
Quoted 3 lines
Alone the class driver does nothing. Why would the user need to be aware of if it when selecting the Type-C drivers, and what can the user use that information for?
If you see a blank
Kconfigoption, what are you supposed to do with it? How do you know if you need to enable it or not? Are you just supposed to guess?
Quoted 8 lines
But you don't see anything when you are selecting the drivers and that is the point. You now can't select this separately. There is now no option for it.
Why should we bother the user with this? The user is most likely only interested in the drivers and by selecting those the user will get the interface. The drivers will need to have the dependency to the class set correctly in any case.
So with this patch, no code gets built or asked about in Kconfig?
Odd, if so, sorry for the noise...
greg k-h
Greg KH
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
In reply to Heikki KrogerusQuoted 525 lines · Heikki Krogerus
The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system, control over data role swapping, and when the port supports USB Power Delivery, also control over power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>--- Documentation/ABI/testing/sysfs-class-typec | 222 ++++++ Documentation/usb/typec.txt | 103 +++ MAINTAINERS | 9 + drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/typec/Kconfig | 7 + drivers/usb/typec/Makefile | 1 + drivers/usb/typec/typec.c | 1012 +++++++++++++++++++++++++++ include/linux/usb/typec.h | 252 +++++++ 9 files changed, 1610 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-typec create mode 100644 Documentation/usb/typec.txt create mode 100644 drivers/usb/typec/Kconfig create mode 100644 drivers/usb/typec/Makefile create mode 100644 drivers/usb/typec/typec.c create mode 100644 include/linux/usb/typec.hDocumentation/ABI/testing/sysfs-class-typec new file +222
-0@@ -0,0 +1,222 @@ +USB Type-C port devices (eg. /sys/class/typec/usbc0/) + +What: /sys/class/typec/<port>/current_data_role +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + The current USB data role the port is operating in. This + attribute can be used for requesting data role swapping on the + port. Swapping is supported as synchronous operation, so + write(2) to the attribute will not return until the operation + has finished. The attribute is notified about role changes so + that poll(2) on the attribute wakes up. Change on the role will + also generate uevent KOBJ_CHANGE on the port. + + Valid values: + - host + - device + +What: /sys/class/typec/<port>/current_power_role +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + The current power role of the port. This attribute can be used + to request power role swap on the port when the port supports + USB Power Delivery. Swapping is supported as synchronous + operation, so write(2) to the attribute will not return until + the operation has finished. The attribute is notified about role + changes so that poll(2) on the attribute wakes up. Change on the + role will also generate uevent KOBJ_CHANGE. + + Valid values: + - source + - sink + +What: /sys/class/typec/<port>/vconn_source +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows is the port VCONN Source. This attribute can be used to + request VCONN swap to change the VCONN Source during connection + when both the port and the partner support USB Power Delivery. + Swapping is supported as synchronous operation, so write(2) to + the attribute will not return until the operation has finished. + The attribute is notified about VCONN source changes so that + poll(2) on the attribute wakes up. Change on VCONN source also + generates uevent KOBJ_CHANGE. + + Valid values are: + - 0 when the port is not the VCONN Source + - 1 when the port is the VCONN Source + +What: /sys/class/typec/<port>/power_operation_mode +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows the current power operational mode the port is in. + + Valid values: + - USB - Normal power levels defined in USB specifications + - BC1.2 - Power levels defined in Battery Charging Specification + v1.2 + - USB Type-C 1.5A - Higher 1.5A current defined in USB Type-C + specification. + - USB Type-C 3.0A - Higher 3A current defined in USB Type-C + specification. + - USB Power Delivery - The voltages and currents defined in USB + Power Delivery specification + +What: /sys/class/typec/<port>/preferred_role +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + The user space can notify the driver about the preferred role. + It should be handled as enabling of Try.SRC or Try.SNK, as + defined in USB Type-C specification, in the port drivers. By + default there is no preferred role. + + Valid values: + - source + - sink + - none - to remove preference + +What: /sys/class/typec/<port>/supported_accessory_modes +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Lists the Accessory Modes, defined in the USB Type-C + specification, the port supports. + +What: /sys/class/typec/<port>/supported_data_roles +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Lists the USB data roles the port is capable of supporting. + + Valid values: + - device + - host + - device, host (DRD as defined in USB Type-C specification v1.2) + +What: /sys/class/typec/<port>/supported_power_roles +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Lists the power roles the port is capable of supporting. + + Valid values: + - source + - sink + - source, sink (DRP as defined in USB Type-C specification v1.2) + +What: /sys/class/typec/<port>/supports_usb_power_delivery +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the port supports USB Power Delivery. + - 1 if USB Power Delivery is supported + - 0 when it's not + + +USB Type-C partner devices (eg. /sys/class/typec/usbc0-partner/) + +What: /sys/class/typec/<port>-partner/accessory_mode +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows the Accessory Mode name, or "no" when the partner does not + support Accesory Modes. The Accessory Modes are defined in USB + Type-C Specification. + +What: /sys/class/typec/<port>-partner/supports_usb_power_delivery +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the partner supports USB Power Delivery: + - 0 when USB Power Delivery is not supported + - 1 when USB Power Delivery is supported + + +USB Type-C cable devices (eg. /sys/class/typec/usbc0-cable/) + +Note: Electronically Marked Cables will have a device also for one cable plug +(eg. /sys/class/typec/usbc0-plug0). If the cable is active and has also SOP +Double Prime controller (USB Power Deliver specification ch. 2.4) it will have +second device also for the other plug. Both plugs may have their alternate modes +as described in USB Type-C and USB Power Delivery specifications. + +What: /sys/class/typec/<port>-cable/active +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the cable is active or passive. + + Valid values: + - 0 when the cable is passive + - 1 when the cable is active + +What: /sys/class/typec/<port>-cable/plug_type +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows type of the plug on the cable: + - Type-A - Standard A + - Type-B - Standard B + - Type-C - USB Type-C + - Captive - Non-standard + +What: /sys/class/typec/<port>-cable/supports_usb_power_delivery +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the cable supports USB Power Delivery: + - 0 when USB Power Delivery is not supported + - 1 when USB Power Delivery is supported + + +Alternate Mode devices (For example, +/sys/class/typec/usbc0-partner/usbc0-partner.svid:xxxx/). The ports, partners +and cable plugs can have alternate modes. + +What: /sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/active +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the mode is active or not. The attribute can be used + for entering/exiting the mode with partners and cable plugs, and + with the port alternate modes it can be used for disabling + support for specific alternate modes. Entering/exiting modes is + supported as synchronous operation so write(2) to the attribute + does not return until the enter/exit mode operation has + finished. The attribute is notified when the mode is + entered/exited so poll(2) on the attribute wakes up. + Entering/exiting a mode will also generate uevent KOBJ_CHANGE. + + Valid values: + - 0 when the mode is deactive + - 1 when the mode is active + +What: /sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/description +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows description of the mode. The description is optional for + the drivers, just like with the Billboard Devices. + +What: /sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/vdo +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows the VDO in hexadecimal returned from the Discover Modes + command. + +What: /sys/class/typec/<port>/<port>.svid:<svid>/<mode>/supported_roles +Date: December 2016 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows the roles, source or sink, the mode is supported with. + + This attribute is available for the devices describing the + alternate modes a port supports, and it will not be exposed with + the devices presenting the alternate modes the partners or cable + plugs support.Documentation/usb/typec.txt new file +103
-0@@ -0,0 +1,103 @@ +USB Type-C connector class +========================== + +Introduction +------------ +The typec class is meant for describing the USB Type-C ports in a system to the +user space in unified fashion. The class is designed to provide nothing else +except the user space interface implementation in hope that it can be utilized +on as many platforms as possible. + +The platforms are expected to register every USB Type-C port they have with the +class. In a normal case the registration will be done by a USB Type-C or PD PHY +driver, but it may be a driver for firmware interface such as UCSI, driver for +USB PD controller or even driver for Thunderbolt3 controller. This document +considers the component registering the USB Type-C ports with the class as "port +driver". + +On top of showing the capabilities, the class also offer the user space control +over the roles and alternate modes they support when the port driver is capable +of supporting those features. + +The class provides an API for the port drivers described in this document. The +attributes are described in Documentation/ABI/testing/sysfs-class-typec. + + +Interface +--------- +Every port will be presented as its own device under /sys/class/typec/. The +first port will be named "usbc0", the second "usbc1" and so on. + +When connected, the partner will be presented also as its own device under +/sys/class/typec/. The parent of the partner device will always be the port. The +partner attached to port "usbc0" will be named "usbc0-partner". Full path to the +device would be /sys/class/typec/usb0/usb0-partner/. + +The cable and the two plugs on it may also be optionally presented as their own +devices under /sys/class/typec/. The cable attached to the port "usbc0" port +will be named usbc0-cable and the plug on the SOP Prime end (see USB Power +Delivery Specification ch. 2.4) will be named "usbc-plug0" and on the SOP Double +Prime end "usbc0-plug1". The parent of a cable will always be the port, and the +parent of the cable plugs will always be the cable. + +If the port, partner or cable plug support Alternate Modes, every Alternate Mode +SVID will have their own device describing them. The Alternate Modes will not be +attached to the typec class. For the port's "usbc0" partner, the Alternate Modes +would have devices presented under /sys/class/typec/usbc0-partner/. Every mode +that is supported will have its own group under the Alternate Mode device named +"mode<id>". For example /sys/class/typec/usbc0/usbc0.svid:xxxx/mode0/. The +requests for entering/exiting the modes happens with the "active" attribute in +that group. + + +API +--- + +* Registering the ports + +The port drivers will describe every Type-C port they control with struct +typec_capability data structure, and register them with the following API: + +struct typec_port *typec_register_port(struct device *dev, + const struct typec_capability *cap); + +The class will provide handle to struct typec_port on success and ERR_PTR on +failure. The un-registration of the port happens with the following API: + +void typec_unregister_port(struct typec_port *port); + + +* Notifications + +When connection happens on a port, the port driver fills struct typec_connection +which is passed to the class. The class provides the following API for reporting +connection/disconnection: + +int typec_connect(struct typec_port *port, struct typec_connection *); +void typec_disconnect(struct typec_port *); + +When the partner end has executed a role change, the port driver uses the +following APIs to report it to the class: + +void typec_set_data_role(struct typec_port *, enum typec_data_role); +void typec_set_pwr_role(struct typec_port *, enum typec_role); +void typec_set_vconn_role(struct typec_port *, enum typec_role); +void typec_set_pwr_opmode(struct typec_port *, enum typec_pwr_opmode); + + +* Alternate Modes + +After connection, the port drivers register the alternate modes the partner +and/or cable plugs support. And before reporting disconnection, the port driver +_must_ unregister all the alternate modes registered for the partner and cable +plugs. The API takes the struct device of the partner or the cable plug as +parameter: + +int typec_register_altmodes(struct device *, struct typec_altmode *); +void typec_unregister_altmodes(struct device *); + +When the partner end enters or exits the modes, the port driver needs to notify +the class with the following API: + +void typec_altmode_update_active(struct typec_altmode *alt, int mode, + bool active);MAINTAINERS +9
-0@@ -12761,6 +12761,15 @@ F: drivers/usb/ F: include/linux/usb.h F: include/linux/usb/ +USB TYPEC SUBSYSTEM +M: Heikki Krogerus <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-class-typec +F: Documentation/usb/typec.txt +F: drivers/usb/typec/ +F: include/linux/usb/typec.h + USB UHCI DRIVER M: Alan Stern <[email protected]> L: [email protected]drivers/usb/Kconfig +2
-0@@ -152,6 +152,8 @@ source "drivers/usb/phy/Kconfig" source "drivers/usb/gadget/Kconfig" +source "drivers/usb/typec/Kconfig" + config USB_LED_TRIG bool "USB LED Triggers" depends on LEDS_CLASS && LEDS_TRIGGERSdrivers/usb/Makefile +2
-0@@ -62,3 +62,5 @@ obj-$(CONFIG_USB_GADGET) += gadget/ obj-$(CONFIG_USB_COMMON) += common/ obj-$(CONFIG_USBIP_CORE) += usbip/ + +obj-$(CONFIG_TYPEC) += typec/drivers/usb/typec/Kconfig new file +7
-0@@ -0,0 +1,7 @@ + +menu "USB PD and Type-C drivers" + +config TYPEC + tristate + +endmenudrivers/usb/typec/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_TYPEC) += typec.odrivers/usb/typec/typec.c new file +93
-0@@ -0,0 +1,1012 @@ +/* +* USB Type-C Connector Class +* +* Copyright (C) 2016, Intel Corporation +* Author: Heikki Krogerus <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/usb/typec.h> + +struct typec_port { +unsigned int id; +struct device dev; + +int prefer_role; + +enum typec_data_role data_role; +enum typec_role pwr_role; +enum typec_role vconn_role; +enum typec_pwr_opmode pwr_opmode; + +struct typec_partner *partner; +struct typec_cable *cable; + +unsigned int connected:1 ; + +const struct typec_capability *cap; +}; + +#define to_typec_port (p) container_of(p, struct typec_port, dev) +#define to_typec_plug (p) container_of(p, struct typec_plug, dev) +#define to_typec_cable (p) container_of(p, struct typec_cable, dev) +#define to_typec_partner (p) container_of(p, struct typec_partner, dev) + +static DEFINE_IDA (typec_index_ida); + +static struct class typec_class = { + .name ="typec" , +}; + +static const char *const typec_accessory_modes[] = { + [TYPEC_ACCESSORY_NONE ] ="no" , + [TYPEC_ACCESSORY_AUDIO ] ="Audio Adapter Accessory Mode" , + [TYPEC_ACCESSORY_DEBUG ] ="Debug Accessory Mode" , +}; + +static struct device_type typec_partner_dev_type; +static struct device_type typec_cable_dev_type; +static struct device_type typec_port_dev_type; + +static ssize_t supports_usb_power_delivery_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +if (dev->type == &typec_partner_dev_type) { +struct typec_partner *p =to_typec_partner (dev); + +return sprintf (buf,"%d\n" , p->usb_pd); + }else if (dev->type == &typec_partner_dev_type) { +struct typec_cable *p =to_typec_cable (dev); + +return sprintf (buf,"%d\n" , p->usb_pd); + }else { +struct typec_port *p =to_typec_port (dev); + +return sprintf (buf,"%d\n" , p->cap->usb_pd); + } +} +static DEVICE_ATTR_RO (supports_usb_power_delivery); + +/* ------------------------------------------------------------------------- */ +/* Type-C Partners */ + +static ssize_t accessory_mode_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct typec_partner *p =to_typec_partner (dev); + +return sprintf (buf,"%s\n" , typec_accessory_modes[p->accessory]); +} +static DEVICE_ATTR_RO (accessory_mode); + +static struct attribute *typec_partner_attrs[] = { + &dev_attr_accessory_mode.attr, + &dev_attr_supports_usb_power_delivery.attr, +NULL
drivers/usb/typec/typec.c line 103
Quoted 10 lines
drivers/usb/typec/typec.c new file +10
-0+}; +ATTRIBUTE_GROUPS (typec_partner); + +static void typec_partner_release (struct device *dev) +{ +struct typec_port *port =to_typec_port (dev->parent); + +typec_unregister_altmodes (dev); + port->partner =NULL ; +}
This doesn't feel right, why are you both exporting typec_unregister_altmodes() and also calling it from release callbacks? That implies there is two way to clean stuff up, so what is a driver writer to use? Please simplify and force it to be one way or the other.
Also typec_unregister_altmodes() doesn't free memory, which release is supposed to be doing, which also implies that the reference counting logic is all wrong here. Please fix, like I asked you to previously.
thanks,
greg k-h
Heikki Krogerus
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
Hi Greg,
Quoted 4 lines · Greg KH
Quoted 4 lines
drivers/usb/typec/typec.c new file +4
-0+static void typec_partner_release (struct device *dev) +{ +struct typec_port *port =to_typec_port (dev->parent); +
Quoted 8 lines
drivers/usb/typec/typec.c line 103
Quoted 3 lines
drivers/usb/typec/typec.c new file +3
-0+typec_unregister_altmodes (dev); + port->partner =NULL ; +}This doesn't feel right, why are you both exporting
typec_unregister_altmodes()and also calling it from release callbacks? That implies there is two way to clean stuff up, so what is a driver writer to use? Please simplify and force it to be one way or the other.
OK.
Quoted 3 lines
Also
typec_unregister_altmodes()doesn't free memory, which release is supposed to be doing, which also implies that the reference counting logic is all wrong here. Please fix, like I asked you to previously.
There is nothing wrong with the reference counting, and nothing has been allocated so there is nothing to free.
Please note that the partner device is meant to just represent the partner in user space and not to be actually used for anything. And please also note that there can only be one partner for a port at a time.
We could allocate an extra structure for the partner when typec_connect() is called, but we would do that just for the sake of having something to free in the release hook. It would not be useful for anything. It would not help us increase/decrease the reference count of the device, and the port driver would still have to provide details about the partner capabilities the moment it tells us the partner was connected.
Thanks,
Signature · 1 line
heikki
Heikki Krogerus
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
Quoted 16 lines · Heikki Krogerus
Hi Greg,
Quoted 4 lines · Greg KH
Quoted 4 lines
drivers/usb/typec/typec.c new file +4
-0+static void typec_partner_release (struct device *dev) +{ +struct typec_port *port =to_typec_port (dev->parent); +Quoted 8 lines
drivers/usb/typec/typec.c line 103
Quoted 3 lines
drivers/usb/typec/typec.c new file +3
-0+typec_unregister_altmodes (dev); + port->partner =NULL ; +}This doesn't feel right, why are you both exporting
typec_unregister_altmodes()and also calling it from release callbacks? That implies there is two way to clean stuff up, so what is a driver writer to use? Please simplify and force it to be one way or the other.
Quoted 1 line
OK.
Guenter did you need to also remove the alternate modes in drivers, or can we just do it here?
Thanks,
Signature · 1 line
heikki
Re: [PATCHv11 2/3] usb: USB Type-C connector class
Quoted 17 lines · Heikki Krogerus
Quoted 16 lines · Heikki Krogerus
Hi Greg,
Quoted 12 lines · Greg KH
drivers/usb/typec/typec.c line 103
Quoted 7 lines
drivers/usb/typec/typec.c new file +7
-0+static void typec_partner_release (struct device *dev) +{ +struct typec_port *port =to_typec_port (dev->parent); + +typec_unregister_altmodes (dev); + port->partner =NULL ; +}This doesn't feel right, why are you both exporting
typec_unregister_altmodes()and also calling it from release callbacks? That implies there is two way to clean stuff up, so what is a driver writer to use? Please simplify and force it to be one way or the other.
Quoted 5 lines
Quoted 1 line
OK.
Guenter did you need to also remove the alternate modes in drivers, or can we just do it here?
It is currently called explicitly on a data role change, when executing a hard reset, on detach, and during error recovery. Most of those would also unregister the partner, so I should be able to drop those calls (or maybe I'll have to - I will see when testing), but I am not sure how to handle data role changes.
Guenter
Heikki Krogerus
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
Quoted 24 lines · Guenter Roeck
Quoted 17 lines · Heikki Krogerus
Quoted 16 lines · Heikki Krogerus
Hi Greg,
Quoted 12 lines · Greg KH
drivers/usb/typec/typec.c line 103
Quoted 7 lines
drivers/usb/typec/typec.c new file +7
-0+static void typec_partner_release (struct device *dev) +{ +struct typec_port *port =to_typec_port (dev->parent); + +typec_unregister_altmodes (dev); + port->partner =NULL ; +}This doesn't feel right, why are you both exporting
typec_unregister_altmodes()and also calling it from release callbacks? That implies there is two way to clean stuff up, so what is a driver writer to use? Please simplify and force it to be one way or the other.Quoted 5 lines
Quoted 1 line
OK.
Guenter did you need to also remove the alternate modes in drivers, or can we just do it here?
Quoted 5 lines
It is currently called explicitly on a data role change, when executing a hard reset, on detach, and during error recovery. Most of those would also unregister the partner, so I should be able to drop those calls (or maybe I'll have to - I will see when testing), but I am not sure how to handle data role changes.
Let's keep this in the drivers. Actually, we can't unregister them here. The partner is the parent of the alternate modes devices. Sorry about the hassle.
Thanks,
Signature · 1 line
heikki
Greg KH
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
In reply to Heikki KrogerusQuoted 16 lines · Heikki Krogerus
Hi Greg,
Quoted 4 lines · Greg KH
Quoted 4 lines
drivers/usb/typec/typec.c new file +4
-0+static void typec_partner_release (struct device *dev) +{ +struct typec_port *port =to_typec_port (dev->parent); +Quoted 8 lines
drivers/usb/typec/typec.c line 103
Quoted 3 lines
drivers/usb/typec/typec.c new file +3
-0+typec_unregister_altmodes (dev); + port->partner =NULL ; +}This doesn't feel right, why are you both exporting
typec_unregister_altmodes()and also calling it from release callbacks? That implies there is two way to clean stuff up, so what is a driver writer to use? Please simplify and force it to be one way or the other.
Quoted 8 lines
OK.
Quoted 3 lines
Also
typec_unregister_altmodes()doesn't free memory, which release is supposed to be doing, which also implies that the reference counting logic is all wrong here. Please fix, like I asked you to previously.There is nothing wrong with the reference counting, and nothing has been allocated so there is nothing to free.
The device structure itself that this release call is for needs to be freed, right? If not, something is really wrong...
Quoted 4 lines
Please note that the partner device is meant to just represent the partner in user space and not to be actually used for anything. And please also note that there can only be one partner for a port at a time.
Ok, but these are still reference counted devices, you need to handle that properly.
Quoted 7 lines
We could allocate an extra structure for the partner when
typec_connect()is called, but we would do that just for the sake of having something to free in the release hook. It would not be useful for anything. It would not help us increase/decrease the reference count of the device, and the port driver would still have to provide details about the partner capabilities the moment it tells us the partner was connected.
Again, free the device for which this release function is being called for, that is why it is there.
thanks,
greg k-h
Heikki Krogerus
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
Hi Greg,
Quoted 10 lines · Greg KH
Quoted 7 lines
We could allocate an extra structure for the partner when
typec_connect()is called, but we would do that just for the sake of having something to free in the release hook. It would not be useful for anything. It would not help us increase/decrease the reference count of the device, and the port driver would still have to provide details about the partner capabilities the moment it tells us the partner was connected.Again, free the device for which this release function is being called for, that is why it is there.
The struct device is now member of struct typec_partner. This is what a typical port driver would have (I hope it's readable):
struct my_port {
/* This structure is provided by the class */
struct typec_port *port;
/*
* Don't forget, there can only be one partner at a time
*/
struct typec_partner partner; /* NOTE: this is not a pointer */
};int my_interrupt(...)
{
...
/*
* Connection happened (I'm skipping the typec_connection
* wrapper in this example)
*/
my_port->partner.usb_pd = ...
...
ret = typec_connect(my_port->port, &my_port->partner);
...
/*
* Disconnect
*/
typec_disconnect(my_port->port);
memset(&my_port->partner, 0, sizeof(struct typec_partner));
...
}int my_probe(...)
{
struct my_port *my_port;
...
my_port = devm_kzalloc(...
...
my_port->port = typec_register_port(...
...
}To have something to free when the partner device's reference counter goes to zero and release is called (this happens after all the alternate modes, so the children, and the device are unregistered), we will need an extra structure, just for the fun of having something to free in release.
struct internal_partner_structure {
struct device dev;
struct typec_partner *partner_capabilities; /* port driver provides */
};
Why is this necessary in this case? It is just something extra we have to do, just so we can allocate that when connection happens and the partner device is generated, and so we can then free that thing when release gets called? It does not give us anything. It does not affect anything.
Thanks,
Signature · 1 line
heikki
Heikki Krogerus
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
Quoted 67 lines · Heikki Krogerus
Hi Greg,
Quoted 10 lines · Greg KH
Quoted 7 lines
We could allocate an extra structure for the partner when
typec_connect()is called, but we would do that just for the sake of having something to free in the release hook. It would not be useful for anything. It would not help us increase/decrease the reference count of the device, and the port driver would still have to provide details about the partner capabilities the moment it tells us the partner was connected.Again, free the device for which this release function is being called for, that is why it is there.
The struct device is now member of struct
typec_partner. This is what a typical port driver would have (I hope it's readable):struct my_port { /* This structure is provided by the class */ struct typec_port *port; /* * Don't forget, there can only be one partner at a time */ struct typec_partner partner; /* NOTE: this is not a pointer */ };int
my_interrupt(...){ ... /* * Connection happened (I'm skipping the typec_connection * wrapper in this example) */ my_port->partner.usb_pd = ... ... ret = typec_connect(my_port->port, &my_port->partner); ... /* * Disconnect */ typec_disconnect(my_port->port); memset(&my_port->partner, 0, sizeof(struct typec_partner)); ... }int
my_probe(...){ struct my_port *my_port; ... my_port = devm_kzalloc(... ... my_port->port = typec_register_port(... ... }To have something to free when the partner device's reference counter goes to zero and release is called (this happens after all the alternate modes, so the children, and the device are unregistered), we will need an extra structure, just for the fun of having something to free in release.
struct
internal_partner_structure{
struct device dev;
structtypec_partner*partner_capabilities; /* port driver provides */
};
Quoted 5 lines
Why is this necessary in this case? It is just something extra we have to do, just so we can allocate that when connection happens and the partner device is generated, and so we can then free that thing when release gets called? It does not give us anything. It does not affect anything.
Blah, ignore that message. I'm talking about the wrong thing here.
Sorry about that.
Signature · 1 line
heikki
Heikki Krogerus
maintainerRe: [PATCHv11 2/3] usb: USB Type-C connector class
In reply to Greg KHQuoted 2 lines · Greg KH
Again, free the device for which this release function is being called for, that is why it is there.
I will.
Thanks,
Signature · 1 line
heikki
Heikki Krogerus
maintainerPATCH v11 3/3 usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY
In reply to Heikki KrogerusThis adds driver for the USB Type-C PHY on Intel WhiskeyCove PMIC which is available on some of the Intel Broxton SoC based platforms.
--- drivers/usb/typec/Kconfig | 14 ++ drivers/usb/typec/Makefile | 1 + drivers/usb/typec/typec_wcove.c | 372 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 387 insertions(+) create mode 100644 drivers/usb/typec/typec_wcove.c
drivers/usb/typec/Kconfig +14 -0
@@ -4,4 +4,18 @@ menu "USB PD and Type-C drivers" config TYPEC tristate +config TYPEC_WCOVE + tristate "Intel WhiskeyCove PMIC USB Type-C PHY driver" + depends on ACPI + depends on INTEL_SOC_PMIC + depends on INTEL_PMC_IPC + select TYPEC + help + This driver adds support for USB Type-C detection on Intel Broxton + platforms that have Intel Whiskey Cove PMIC. The driver can detect the + role and cable orientation. + + To compile this driver as module, choose M here: the module will be + called typec_wcove + endmenu
drivers/usb/typec/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_TYPEC) += typec.o +obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o
drivers/usb/typec/typec_wcove.c new file +372 -0
372 lines not on this page · raw message
Signature · 1 line
2.10.2