usb: USB Type-C Connector Class
Subsystems (2)
Heikki Krogerus
maintainerRFC PATCH v2 1/1 usb: USB Type-C Connector Class
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 230 +++++++++++ 6 files changed, 1199 insertions(+) create mode 100644 drivers/usb/type-c/Kconfig create mode 100644 drivers/usb/type-c/Makefile create mode 100644 drivers/usb/type-c/typec.c create mode 100644 include/linux/usb/typec.h
Hi,
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
An other change is that the data role is now handled in two ways. The current_data_role file will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to be fixed to one specific role with DRP ports. So this approach will replace the suggestions for "preferred" data role we had. The current_usb_data_role will use values "host" and "device" and it will be used for data role swapping when already connected.
The tree of devices that will be populated when the cable is active and when the cable has controller on both plug, will look as following:
usbc0
|- usbc0-cable | |- usbc0-plug0 | | |- usbc0-plug.svid:xxx | | | |-mode0 | | | | |- vdo | | | | |- desc | | | | |- active ... | |- usbc0-plug1 | | |-usbc0-partner | | | |- usbc0-partner.svid:xxxx | | | | |-mode0 | | | | | |- vdo | | | | | |- desc | | | | | |- active | | | | |-mode1 ... | | |- usbc0-plug1.svid:xxx | | | |-mode0 | | | | |- vdo
...
If there is no active cable, the partner will be directly attached to the port, but symlink to the partner is now always added to the port folder in any case. I'm not sure about this approach. There is a question about it in the code. Please check it.
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
There were quite a few suggestions for the file names. I'm using the most popular ones from the first thread now.
In case somebody is wondering, I'm not adding ABI documentation until we know how the final version will look like.
I Hope I remembered to CC everybody interested.
Thanks,
drivers/usb/Kconfig +2 -0
@@ -150,6 +150,8 @@ source "drivers/usb/phy/Kconfig" source "drivers/usb/gadget/Kconfig" +source "drivers/usb/type-c/Kconfig" + config USB_LED_TRIG bool "USB LED Triggers" depends on LEDS_CLASS && USB_COMMON && LEDS_TRIGGERS
drivers/usb/Makefile +2 -0
@@ -61,3 +61,5 @@ obj-$(CONFIG_USB_GADGET) += gadget/ obj-$(CONFIG_USB_COMMON) += common/ obj-$(CONFIG_USBIP_CORE) += usbip/ + +obj-$(CONFIG_TYPEC) += type-c/
drivers/usb/type-c/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ + +menu "USB PD and Type-C drivers" + +config TYPEC + tristate + +endmenu
drivers/usb/type-c/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_TYPEC) += typec.o
drivers/usb/type-c/typec.c new file +957 -0
957 lines not on this page · raw message
include/linux/usb/typec.h new file +230 -0
230 lines not on this page · raw message
Signature · 1 line
2.8.1
Quoted 26 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 230 +++++++++++ 6 files changed, 1199 insertions(+) create mode 100644 drivers/usb/type-c/Kconfig create mode 100644 drivers/usb/type-c/Makefile create mode 100644 drivers/usb/type-c/typec.c create mode 100644 include/linux/usb/typec.hHi,
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
Quoted 6 lines
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
That raises a question. If I read the standard correctly, alternate modes could be combinable. So how do you represent that.
Quoted 8 lines
An other change is that the data role is now handled in two ways. The
current_data_rolefile will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to be fixed to one specific role with DRP ports. So this approach will replace the suggestions for "preferred" data role we had. Thecurrent_usb_data_rolewill use values "host" and "device" and it will be used for data role swapping when already connected.
Please explain. How does that express DRP but prefered master?
Quoted 1 line
I Hope I remembered to CC everybody interested.
Alternate modes can be left involuntarily. So we need a method of notification.
Regards
Oliver
Heikki Krogerus
maintainerQuoted 46 lines · Oliver Neukum
Quoted 26 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 230 +++++++++++ 6 files changed, 1199 insertions(+) create mode 100644 drivers/usb/type-c/Kconfig create mode 100644 drivers/usb/type-c/Makefile create mode 100644 drivers/usb/type-c/typec.c create mode 100644 include/linux/usb/typec.hHi,
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
Quoted 6 lines
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
That raises a question. If I read the standard correctly, alternate modes could be combinable. So how do you represent that.
Quoted 8 lines
An other change is that the data role is now handled in two ways. The
current_data_rolefile will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to be fixed to one specific role with DRP ports. So this approach will replace the suggestions for "preferred" data role we had. Thecurrent_usb_data_rolewill use values "host" and "device" and it will be used for data role swapping when already connected.
Quoted 1 line
Please explain. How does that express DRP but prefered master?
Sorry but I'm not sure what you mean here. If the port is capable of being used as dual role port (DRP in the supported_data_roles file), that is the only case where you can select the role with this file. So I would imagine that in your case you want to make the port act as DFP only, right? But if the port is capable of acting only as UFP, you are stuck with that role.
Quoted 4 lines
Quoted 1 line
I Hope I remembered to CC everybody interested.
Alternate modes can be left involuntarily. So we need a method of notification.
Yes, that is missing indeed.
Thanks,
Signature · 1 line
heikki
Quoted 10 lines · Heikki Krogerus
Quoted 2 lines · Oliver Neukum
Please explain. How does that express DRP but prefered master?
Sorry but I'm not sure what you mean here. If the port is capable of being used as dual role port (DRP in the
supported_data_rolesfile), that is the only case where you can select the role with this file. So I would imagine that in your case you want to make the port act as DFP only, right? But if the port is capable of acting only as UFP, you are stuck with that role.
How do I trigger that Try.SRC is to be used on a port?
Regards
Oliver
Quoted 5 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus
Quoted 2 lines · Oliver Neukum
Please explain. How does that express DRP but prefered master?
Quoted 9 lines
Quoted 6 lines
Sorry but I'm not sure what you mean here. If the port is capable of being used as dual role port (DRP in the
supported_data_rolesfile), that is the only case where you can select the role with this file. So I would imagine that in your case you want to make the port act as DFP only, right? But if the port is capable of acting only as UFP, you are stuck with that role.How do I trigger that Try.SRC is to be used on a port?
This would be part of the USB PD protocol, ie probably outside the scope of the class code. In my implementation, I enable Try.SRC or Try.SNK based on the platform's preferred role.
Guenter
Quoted 13 lines · Guenter Roeck
Quoted 12 lines · Oliver Neukum
Quoted 10 lines · Heikki Krogerus
Quoted 2 lines · Oliver Neukum
Please explain. How does that express DRP but prefered master?
Sorry but I'm not sure what you mean here. If the port is capable of being used as dual role port (DRP in the
supported_data_rolesfile), that is the only case where you can select the role with this file. So I would imagine that in your case you want to make the port act as DFP only, right? But if the port is capable of acting only as UFP, you are stuck with that role.
Quoted 6 lines
Quoted 2 lines
How do I trigger that Try.SRC is to be used on a port?
This would be part of the USB PD protocol, ie probably outside the scope of the class code. In my implementation, I enable Try.SRC or Try.SNK based on the platform's preferred role.
Hi,
from a purely formal point of view that makes sense.
Quoted 1 line
From a usability viewpoint I'd ideally want all controls
for role at one place. And possibly the controls for modes at the same place.
I think part of the problem here is that we lack a statement of mission. What are these controls for?
Merely for controlling modes and providing information about modes? And to use neutral terms only for the "master" side or both sides?
Regards
Oliver
Hi Oliver,
Quoted 26 lines · Oliver Neukum
Quoted 13 lines · Guenter Roeck
Quoted 12 lines · Oliver Neukum
Quoted 10 lines · Heikki Krogerus
Quoted 2 lines · Oliver Neukum
Please explain. How does that express DRP but prefered master?
Sorry but I'm not sure what you mean here. If the port is capable of being used as dual role port (DRP in the
supported_data_rolesfile), that is the only case where you can select the role with this file. So I would imagine that in your case you want to make the port act as DFP only, right? But if the port is capable of acting only as UFP, you are stuck with that role.Quoted 6 lines
Quoted 2 lines
How do I trigger that Try.SRC is to be used on a port?
This would be part of the USB PD protocol, ie probably outside the scope of the class code. In my implementation, I enable Try.SRC or Try.SNK based on the platform's preferred role.
Hi,
from a purely formal point of view that makes sense.
Quoted 1 line
From a usability viewpoint I'd ideally want all controls
Quoted 9 lines
for role at one place. And possibly the controls for modes at the same place.
I think part of the problem here is that we lack a statement of mission. What are these controls for?
Merely for controlling modes and providing information about modes? And to use neutral terms only for the "master" side or both sides?
Good question. I originally added a sysfs attribute 'preferred-mode' to my code, but then concluded that this is supposed to be provided by the platform and added it as platform data instead, with (currently) no means to report it to user space.
Heikki's current code doesn't really match the semantics of a 'preferred' mode, at least not as I read it. In my understanding, 'preferred mode' means "this is a DRP port which prefers to be a source/sink". In Heikki's code, one can fix the mode to source or sink, but that doesn't support situations such as "this port prefers to be a source, but is currently a sink because the link partner happens to be a charger or refuses to act as sink for some other reason".
Given that, my working assumption is that preferred mode handling is supposed to be outside the scope of the infrastructure. I am happy to be corrected, though.
On a side note, are you working on a USB-PD implementation as well ?
Thanks,
Guenter
Quoted 39 lines · Guenter Roeck
Hi Oliver,
Quoted 26 lines · Oliver Neukum
Quoted 13 lines · Guenter Roeck
Quoted 12 lines · Oliver Neukum
Quoted 10 lines · Heikki Krogerus
Quoted 2 lines · Oliver Neukum
Please explain. How does that express DRP but prefered master?
Sorry but I'm not sure what you mean here. If the port is capable of being used as dual role port (DRP in the
supported_data_rolesfile), that is the only case where you can select the role with this file. So I would imagine that in your case you want to make the port act as DFP only, right? But if the port is capable of acting only as UFP, you are stuck with that role.Quoted 6 lines
Quoted 2 lines
How do I trigger that Try.SRC is to be used on a port?
This would be part of the USB PD protocol, ie probably outside the scope of the class code. In my implementation, I enable Try.SRC or Try.SNK based on the platform's preferred role.
Hi,
from a purely formal point of view that makes sense.
Quoted 1 line
From a usability viewpoint I'd ideally want all controls
Quoted 9 lines
for role at one place. And possibly the controls for modes at the same place.
I think part of the problem here is that we lack a statement of mission. What are these controls for?
Merely for controlling modes and providing information about modes? And to use neutral terms only for the "master" side or both sides?
Quoted 4 lines
Good question. I originally added a sysfs attribute 'preferred-mode' to my code, but then concluded that this is supposed to be provided by the platform and added it as platform data instead, with (currently) no means to report it to user space.
Mode or role? I would say that the choice of alternate modes belongs to user space. THere's no point in giving a preference to the kernel. Role is different. Try.SRC is part of the standard (and Try.SNK has been added). It needs to be in kernel space.
Now, if you say that this API is for selecting modes only, then I say it lacks support for cable resets and notifications thereof. Yes, that is a PD feature, but that doesn't help us. It changes the mode.
Quoted 7 lines
Heikki's current code doesn't really match the semantics of a 'preferred' mode, at least not as I read it. In my understanding, 'preferred mode' means "this is a DRP port which prefers to be a source/sink". In Heikki's code, one can fix the mode to source or sink, but that doesn't support situations such as "this port prefers to be a source, but is currently a sink because the link partner happens to be a charger or refuses to act as sink for some other reason".
Yes. That is why we need a mission statement. We may be talking a rice cooker not preparing tea here.
Quoted 5 lines
Given that, my working assumption is that preferred mode handling is supposed to be outside the scope of the infrastructure. I am happy to be corrected, though.
On a side note, are you working on a USB-PD implementation as well ?
No, one of my task is to to make use of USB PD (and alternate modes) in a distribution.
Regards
Oliver
Quoted 40 lines · Oliver Neukum
Quoted 39 lines · Guenter Roeck
Hi Oliver,
Quoted 35 lines · Oliver Neukum
Quoted 13 lines · Guenter Roeck
Quoted 12 lines · Oliver Neukum
Quoted 10 lines · Heikki Krogerus
Quoted 2 lines · Oliver Neukum
Please explain. How does that express DRP but prefered master?
Sorry but I'm not sure what you mean here. If the port is capable of being used as dual role port (DRP in the
supported_data_rolesfile), that is the only case where you can select the role with this file. So I would imagine that in your case you want to make the port act as DFP only, right? But if the port is capable of acting only as UFP, you are stuck with that role.Quoted 6 lines
Quoted 2 lines
How do I trigger that Try.SRC is to be used on a port?
This would be part of the USB PD protocol, ie probably outside the scope of the class code. In my implementation, I enable Try.SRC or Try.SNK based on the platform's preferred role.
Hi,
from a purely formal point of view that makes sense.
Quoted 1 line
From a usability viewpoint I'd ideally want all controls
for role at one place. And possibly the controls for modes at the same place.
I think part of the problem here is that we lack a statement of mission. What are these controls for?
Merely for controlling modes and providing information about modes? And to use neutral terms only for the "master" side or both sides?
Quoted 6 lines
Quoted 4 lines
Good question. I originally added a sysfs attribute 'preferred-mode' to my code, but then concluded that this is supposed to be provided by the platform and added it as platform data instead, with (currently) no means to report it to user space.
Mode or role? I would say that the choice of alternate modes belongs to
s/preferred mode/preferred role/g
Quoted 33 lines
user space. THere's no point in giving a preference to the kernel. Role is different. Try.SRC is part of the standard (and Try.SNK has been added). It needs to be in kernel space.
Now, if you say that this API is for selecting modes only, then I say it lacks support for cable resets and notifications thereof. Yes, that is a PD feature, but that doesn't help us. It changes the mode.
Quoted 7 lines
Heikki's current code doesn't really match the semantics of a 'preferred' mode, at least not as I read it. In my understanding, 'preferred mode' means "this is a DRP port which prefers to be a source/sink". In Heikki's code, one can fix the mode to source or sink, but that doesn't support situations such as "this port prefers to be a source, but is currently a sink because the link partner happens to be a charger or refuses to act as sink for some other reason".
Yes. That is why we need a mission statement. We may be talking a rice cooker not preparing tea here.
Quoted 5 lines
Given that, my working assumption is that preferred mode handling is supposed to be outside the scope of the infrastructure. I am happy to be corrected, though.
On a side note, are you working on a USB-PD implementation as well ?
No, one of my task is to to make use of USB PD (and alternate modes) in a distribution.
Regards
Oliver
Quoted 11 lines · Guenter Roeck
Quoted 1 line
Quoted 1 line
Good question. I originally added a sysfs attribute
'preferred-mode' to
Quoted 2 lines
Quoted 2 lines
my code, but then concluded that this is supposed to be provided by the platform and added it as platform data instead, with
(currently)
Quoted 3 lines
Quoted 1 line
no means to report it to user space.
Mode or role? I would say that the choice of alternate modes belongs
to
s/preferred mode/preferred role/g
Now I am confused. Are you saying that the choice of Alternate Mode does not belong into user space?
Regards
Oliver
Quoted 8 lines · Oliver Neukum
Quoted 7 lines · Guenter Roeck
Quoted 1 line
Quoted 1 line
Good question. I originally added a sysfs attribute
'preferred-mode' to
Quoted 2 lines
Quoted 2 lines
my code, but then concluded that this is supposed to be provided by the platform and added it as platform data instead, with
(currently)
Quoted 2 lines
Quoted 1 line
no means to report it to user space.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Mode or role? I would say that the choice of alternate modes belongs
to
s/preferred mode/preferred role/g
Now I am confused. Are you saying that the choice of Alternate Mode does not belong into user space?
No; sorry for the confusion. The above was meant to apply to my use of "preferred mode", not yours. I was trying to say that the choice of preferred roles (which determines if Try.SRC or Try.SNK is enabled) should belong primarily into the kernel, to be determined by the platform (presumably via ACPI, devicetree data, or platform data). If it should be possible to override it by user space is a different question. That might be useful, at least for testing. If so, does such an override belong into the class or into the PD driver ? Good question. I am fine either way.
I don't really have a strong opinion about alternate mode selection. I would think that there should be a kernel (platform) default, possibly determined by the alternate mode itself, but I also think that it should be selectable by user space. Question is if that should be done through the alternate mode driver or through the class (example: alternate modes used for firmware upgrades and other device specific functionality). I don't really have an answer for that at this point. I'll probably have a better idea after I implemented the alternate mode driver for Google devices.
Again, sorry for creating confusion between preferred role and preferred (alternate) mode selection.
Thanks,
Guenter
Quoted 11 lines · Guenter Roeck
Quoted 3 lines · Oliver Neukum
Now I am confused. Are you saying that the choice of Alternate Mode does not belong into user space?
No; sorry for the confusion. The above was meant to apply to my use of "preferred mode", not yours. I was trying to say that the choice of preferred roles (which determines if Try.SRC or Try.SNK is enabled) should belong primarily into the kernel, to be determined by the platform (presumably via ACPI, devicetree data, or platform data). If it should
Why on earth? That is most clearly a policy decision.
Quoted 4 lines
be possible to override it by user space is a different question. That might be useful, at least for testing. If so, does such an override belong into the class or into the PD driver ? Good question. I am fine either way.
Well, if platform data has a default, I suppose we ought to use it.
Quoted 5 lines
I don't really have a strong opinion about alternate mode selection. I would think that there should be a kernel (platform) default, possibly determined by the alternate mode itself, but I also think that it should be selectable by user space. Question is if that should be done through the alternate mode driver or through the class (example: alternate modes used for firmware
I would say that the ought to be a driver for type C which controls alternate modes and roles.
Regards
Oliver
Quoted 7 lines · Oliver Neukum
Quoted 6 lines · Guenter Roeck
Quoted 3 lines · Oliver Neukum
Now I am confused. Are you saying that the choice of Alternate Mode does not belong into user space?
Quoted 8 lines
Quoted 5 lines
No; sorry for the confusion. The above was meant to apply to my use of "preferred mode", not yours. I was trying to say that the choice of preferred roles (which determines if Try.SRC or Try.SNK is enabled) should belong primarily into the kernel, to be determined by the platform (presumably via ACPI, devicetree data, or platform data). If it should
Why on earth? That is most clearly a policy decision.
The question is not that much if it is policy (it is), but if the policy should be driven by the platform or by user space. I think there needs to be at least a default driven by the platform. As already mentioned, I am ok with a means to override this platform default from user space. But if user space doesn't say, there still needs to be a default.
Thanks,
Guenter
Quoted 20 lines
Quoted 4 lines
be possible to override it by user space is a different question. That might be useful, at least for testing. If so, does such an override belong into the class or into the PD driver ? Good question. I am fine either way.
Well, if platform data has a default, I suppose we ought to use it.
Quoted 5 lines
I don't really have a strong opinion about alternate mode selection. I would think that there should be a kernel (platform) default, possibly determined by the alternate mode itself, but I also think that it should be selectable by user space. Question is if that should be done through the alternate mode driver or through the class (example: alternate modes used for firmware
I would say that the ought to be a driver for type C which controls alternate modes and roles.
Regards
Oliver
Heikki Krogerus
maintainerHi Guenter,
Quoted 14 lines · Guenter Roeck
Quoted 13 lines · Oliver Neukum
Quoted 11 lines · Guenter Roeck
Quoted 3 lines · Oliver Neukum
Now I am confused. Are you saying that the choice of Alternate Mode does not belong into user space?
No; sorry for the confusion. The above was meant to apply to my use of "preferred mode", not yours. I was trying to say that the choice of preferred roles (which determines if Try.SRC or Try.SNK is enabled) should belong primarily into the kernel, to be determined by the platform (presumably via ACPI, devicetree data, or platform data). If it should
Quoted 8 lines
Quoted 2 lines
Why on earth? That is most clearly a policy decision.
The question is not that much if it is policy (it is), but if the policy should be driven by the platform or by user space. I think there needs to be at least a default driven by the platform. As already mentioned, I am ok with a means to override this platform default from user space. But if user space doesn't say, there still needs to be a default.
I don't completely agree with that. The platform should not, and actually in most cases with ACPI AFAIK, will not provide any "preferences" to the OS about anything. The platform should only provide the OS the physical capabilities and nothing else. So if for example the platform is capable of acting as only source with a Type-C port, that is what it needs to tell to the OS so possibly the PHY can be programmed accordingly, etc.
So IMO, just like with any decision related to what the system will ultimately be used for, decision about the preferred role really belongs to the userspace.
Thanks,
Signature · 1 line
heikki
Quoted 26 lines · Heikki Krogerus
Hi Guenter,
Quoted 14 lines · Guenter Roeck
Quoted 13 lines · Oliver Neukum
Quoted 11 lines · Guenter Roeck
Quoted 3 lines · Oliver Neukum
Now I am confused. Are you saying that the choice of Alternate Mode does not belong into user space?
No; sorry for the confusion. The above was meant to apply to my use of "preferred mode", not yours. I was trying to say that the choice of preferred roles (which determines if Try.SRC or Try.SNK is enabled) should belong primarily into the kernel, to be determined by the platform (presumably via ACPI, devicetree data, or platform data). If it should
Quoted 8 lines
Quoted 2 lines
Why on earth? That is most clearly a policy decision.
The question is not that much if it is policy (it is), but if the policy should be driven by the platform or by user space. I think there needs to be at least a default driven by the platform. As already mentioned, I am ok with a means to override this platform default from user space. But if user space doesn't say, there still needs to be a default.
Quoted 7 lines
I don't completely agree with that. The platform should not, and actually in most cases with ACPI AFAIK, will not provide any "preferences" to the OS about anything. The platform should only provide the OS the physical capabilities and nothing else. So if for example the platform is capable of acting as only source with a Type-C port, that is what it needs to tell to the OS so possibly the PHY can be programmed accordingly, etc.
May I suggest that the point is moot as long as we agree that user space needs to be able to set a policy? The OS cannot ignore the port before user space tells it what to do. So a default will be needed.
The OS must act conservatively, which means it cannot deactivate hardware. So if a port can do DRP, that must be the default. I would go so far that I would suggest that we add a module parameter for Try.SRC and Try.SNK to avoid trouble during boot.
Quoted 3 lines
So IMO, just like with any decision related to what the system will ultimately be used for, decision about the preferred role really belongs to the userspace.
Yes, but ought the APIs for role, mode and PD be separate or not. Sorry to sound like a broken record, but you need to provide some higher level planning here.
Regards
Oliver
Heikki Krogerus
maintainerQuoted 35 lines · Oliver Neukum
Quoted 26 lines · Heikki Krogerus
Hi Guenter,
Quoted 14 lines · Guenter Roeck
Quoted 13 lines · Oliver Neukum
Quoted 11 lines · Guenter Roeck
Quoted 3 lines · Oliver Neukum
Now I am confused. Are you saying that the choice of Alternate Mode does not belong into user space?
No; sorry for the confusion. The above was meant to apply to my use of "preferred mode", not yours. I was trying to say that the choice of preferred roles (which determines if Try.SRC or Try.SNK is enabled) should belong primarily into the kernel, to be determined by the platform (presumably via ACPI, devicetree data, or platform data). If it should
Quoted 8 lines
Quoted 2 lines
Why on earth? That is most clearly a policy decision.
The question is not that much if it is policy (it is), but if the policy should be driven by the platform or by user space. I think there needs to be at least a default driven by the platform. As already mentioned, I am ok with a means to override this platform default from user space. But if user space doesn't say, there still needs to be a default.
Quoted 7 lines
I don't completely agree with that. The platform should not, and actually in most cases with ACPI AFAIK, will not provide any "preferences" to the OS about anything. The platform should only provide the OS the physical capabilities and nothing else. So if for example the platform is capable of acting as only source with a Type-C port, that is what it needs to tell to the OS so possibly the PHY can be programmed accordingly, etc.
Quoted 6 lines
May I suggest that the point is moot as long as we agree that user space needs to be able to set a policy? The OS cannot ignore the port before user space tells it what to do. So a default will be needed.
The OS must act conservatively, which means it cannot deactivate hardware. So if a port can do DRP, that must be the default.
So exactly my point.
Quoted 2 lines
I would go so far that I would suggest that we add a module parameter for Try.SRC and Try.SNK to avoid trouble during boot.
I would be fine with that, but apparently module parameters are so 90s :(
Quoted 7 lines
Quoted 3 lines
So IMO, just like with any decision related to what the system will ultimately be used for, decision about the preferred role really belongs to the userspace.
Yes, but ought the APIs for role, mode and PD be separate or not. Sorry to sound like a broken record, but you need to provide some higher level planning here.
I was kinda hoping that we could formulate the plan together in this thread.
Thanks,
Signature · 1 line
heikki
drivers/usb/type-c/typec.c line 132
Quoted 10 lines · Heikki Krogerus
drivers/usb/type-c/typec.c new file +10
-0+ dev->class = &typec_class; + dev->parent = parent; + dev->type = &typec_partner_dev_type; +dev_set_name (dev,"%s-partner" ,dev_name (&port->dev)); + + ret =device_register (dev); +if (ret) { +put_device (dev); +return ret; + }
This looks like a race condition.
drivers/usb/type-c/typec.c line 144
Quoted 11 lines
drivers/usb/type-c/typec.c new file +11
-0+ ret =typec_register_altmodes (dev, partner->alt_modes); +if (ret) { +device_unregister (dev); +return ret; + } + +/* REVISIT: Creating symlink for the port device for now. */ + ret =sysfs_create_link (&port->dev.kobj, &dev->kobj,"partner" ); +if (ret) +dev_WARN (&port->dev,"failed to create link to %s (%d)\n" , +dev_name (dev), ret);
The attributes should be present as soon as the device is announced.
Regards
Oliver
Greg KH
maintainerQuoted 14 lines · Oliver Neukum
drivers/usb/type-c/typec.c line 132
Quoted 10 lines · Heikki Krogerus
drivers/usb/type-c/typec.c new file +10
-0+ dev->class = &typec_class; + dev->parent = parent; + dev->type = &typec_partner_dev_type; +dev_set_name (dev,"%s-partner" ,dev_name (&port->dev)); + + ret =device_register (dev); +if (ret) { +put_device (dev); +return ret; + }This looks like a race condition.
Really? How?
Quoted 5 lines
Quoted 5 lines
drivers/usb/type-c/typec.c new file +5
-0+ ret =typec_register_altmodes (dev, partner->alt_modes); +if (ret) { +device_unregister (dev); +return ret; + }
Quoted 8 lines
drivers/usb/type-c/typec.c line 144
Quoted 6 lines
drivers/usb/type-c/typec.c new file +6
-0+ +/* REVISIT: Creating symlink for the port device for now. */ + ret =sysfs_create_link (&port->dev.kobj, &dev->kobj,"partner" ); +if (ret) +dev_WARN (&port->dev,"failed to create link to %s (%d)\n" , +dev_name (dev), ret);The attributes should be present as soon as the device is announced.
Yes, this is wrong and racy (hint, if you have to drop down to a sysfs call within a driver, almost always something is wrong...)
thanks,
greg k-h
Heikki Krogerus
maintainerQuoted 16 lines · Greg KH
Quoted 14 lines · Oliver Neukum
drivers/usb/type-c/typec.c line 144
Quoted 11 lines · Heikki Krogerus
drivers/usb/type-c/typec.c new file +11
-0+ ret =typec_register_altmodes (dev, partner->alt_modes); +if (ret) { +device_unregister (dev); +return ret; + } + +/* REVISIT: Creating symlink for the port device for now. */ + ret =sysfs_create_link (&port->dev.kobj, &dev->kobj,"partner" ); +if (ret) +dev_WARN (&port->dev,"failed to create link to %s (%d)\n" , +dev_name (dev), ret);The attributes should be present as soon as the device is announced.
Quoted 2 lines
Yes, this is wrong and racy (hint, if you have to drop down to a sysfs call within a driver, almost always something is wrong...)
I'll remove those links.
I'm hoping to get comments about the attributes in general. Do we have everything needed to describe the state and capabilities of USB Type-C ports with them, and are they in reasonable places. I'm playing with these links in couple of places in the code, and I've put questions in the comments on some of them. I'm really not planning on leaving them as they are.
So if you guys could provide your opinions on those questions, I would much appreciate.
Thanks a lot,
Signature · 1 line
heikki
Hello Heikki,
Quoted 33 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 230 +++++++++++ 6 files changed, 1199 insertions(+) create mode 100644 drivers/usb/type-c/Kconfig create mode 100644 drivers/usb/type-c/Makefile create mode 100644 drivers/usb/type-c/typec.c create mode 100644 include/linux/usb/typec.hHi,
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
Quoted 9 lines
An other change is that the data role is now handled in two ways. The
current_data_rolefile will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to be fixed to one specific role with DRP ports. So this approach will replace the suggestions for "preferred" data role we had. Thecurrent_usb_data_rolewill use values "host" and "device" and it will be used for data role swapping when already connected.
What I am missing completely is a means to handle role and alternate mode changes triggered by the partner. The need for those should be obvious, unless I am really missing something (just consider two devices supporting this code connected to each other).
Also, I am not sure where the policy engine is supposed to reside. I understand that some policy changes (eg unsolicited requests to switch roles) can be triggered from user space. However, role change requests triggered from the partner need to be evaluated quickly (typically within 15 ms), so user space can not get involved. Maybe it would help to have some text describing where the policy engine is expected to reside and how it is involved in the decision making process. This includes the initial decision making process, when it needs to be decided if role changes should be requested or if one or multiple alternate modes should be entered after the initial connection has been established.
On top of that, I am concerned about synchronization problems with role changes triggered from user space. The driver is not told about the desired role, only that it shall perform a role change. If a role change triggered by the partner is ongoing at the time a role change request is made from user space, it may well happen that the dual role change results in a revert to the original role. Some synchronization primitives as well as an API change might resolve that, but essentially it would mean that drivers have to implement at least part of the policy engine. It might make more sense to have that code in the infrastructure.
On disconnect, a port reverts to the default role. However, on port registration, the port roles are left at 0, meaning they always default to device/sink independent of the port's capabilities. Is this on purpose ?
current_data_role_store() lets user space set a fixed port role. However, the port role variables are not updated. How is this supposed to be handled ? The same is true for other role change attributes - I don't see any code to update the role variables. Presumably this would have to be done in the class code, since the port data structure is private.
Overall, I am quite concerned by the lack of synchronization primitives between the class code and port drivers, but also in the class code itself. For example, nothing prevents multiple user space processes from writing into the same (or different) attribute(s) repeatedly.
Thanks,
Guenter
Heikki Krogerus
maintainerQuoted 46 lines · Guenter Roeck
Hello Heikki,
Quoted 33 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 230 +++++++++++ 6 files changed, 1199 insertions(+) create mode 100644 drivers/usb/type-c/Kconfig create mode 100644 drivers/usb/type-c/Makefile create mode 100644 drivers/usb/type-c/typec.c create mode 100644 include/linux/usb/typec.hHi,
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
Quoted 9 lines
An other change is that the data role is now handled in two ways. The
current_data_rolefile will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to be fixed to one specific role with DRP ports. So this approach will replace the suggestions for "preferred" data role we had. Thecurrent_usb_data_rolewill use values "host" and "device" and it will be used for data role swapping when already connected.
Quoted 4 lines
What I am missing completely is a means to handle role and alternate mode changes triggered by the partner. The need for those should be obvious, unless I am really missing something (just consider two devices supporting this code connected to each other).
We are missing the notifications that are needed in these cases. But I don't see much more we can do about those cases. We can not put any policies in place at this level, because we have to be able to support also things like USB PD and Type-C controllers that take care of all that, leaving us to not be able to do anything else but to pass the information forward. So the framework at this level has to be "stupid", and if more infrastructure is needed, it has to be introduced in an other layer.
Quoted 10 lines
Also, I am not sure where the policy engine is supposed to reside. I understand that some policy changes (eg unsolicited requests to switch roles) can be triggered from user space. However, role change requests triggered from the partner need to be evaluated quickly (typically within 15 ms), so user space can not get involved. Maybe it would help to have some text describing where the policy engine is expected to reside and how it is involved in the decision making process. This includes the initial decision making process, when it needs to be decided if role changes should be requested or if one or multiple alternate modes should be entered after the initial connection has been established.
Well, yes we need to document these things, but you are now coupling this framework with USB PD and we really should not do that.
The policy engine, and the whole USB PD stack, belongs inside the kernel, and it will be completely separated from this framework. This framework can not have any dependencies on the future USB PD stack. This is not only because of the USB PD/Type-C controllers which handle the policy engine on their own and only allow "unsolicited" requests like "swap role" and "enter/exit mode", but also because this framework must work smoothly on systems that don't want to use USB PD and of course also with USB Type-C PHYs that simply don't include USB PD transceiver.
The layer that joins these two parts together will be the port drivers themselves, so the USB Type-C/PD PHYs and controllers, at least in the beginning.
Any initial decisions about which role or which alternate mode to select belongs to the stack. The userspace will need to be notified, and the userspace can then attempt to request changes after that, but if there is something that blocks the requests, the attempt has to just fail. So we can't provide any knowledge for the userspace about the requirements regarding the high level operations we allow the userspace to request (so in practice swap role/power and enter/exit mode). This information the userspace needs to get from somewhere else just live without it. Nor do we expect the userspace to be aware of the state of the system. So for example if the userspace attempts to activate a mode, the framework will just pass it forward to the port driver, which will then process it with the PD stack, and if for example the state is not PE_SRC_Ready or PE_SNK_Ready or whatever, the operation will just fail probable with -EBUSY in that case.
And the knowledge about dependencies related to the alternate modes belong primarily to the alternate mode specific drivers in the end (once we have the bus) like I said. We can't expect the USB PD stack to be aware of those as they are alternate mode specific, and of course we can not trust that the userspace will always do things the right way. But the initial states after connection must be handle by the policy engine of course.
Quoted 9 lines
On top of that, I am concerned about synchronization problems with role changes triggered from user space. The driver is not told about the desired role, only that it shall perform a role change. If a role change triggered by the partner is ongoing at the time a role change request is made from user space, it may well happen that the dual role change results in a revert to the original role. Some synchronization primitives as well as an API change might resolve that, but essentially it would mean that drivers have to implement at least part of the policy engine. It might make more sense to have that code in the infrastructure.
Well, like I said above, this framework can not provide this infrastructure. The framework at this level really has to be "stupid". We simply can not do any decisions or have any expectations at this level. If more infra is needed, it has to be provided in an other layer on top of this bottom layer. So basically the driver have to implement those things for now.
Quoted 4 lines
On disconnect, a port reverts to the default role. However, on port registration, the port roles are left at 0, meaning they always default to device/sink independent of the port's capabilities. Is this on purpose ?
On disconnect, the port role is set according to the "fixed_role"? If the port is DFP only, then the port will still be host/source after disconnect. I don't see the problem here?
Quoted 5 lines
current_data_role_store()lets user space set a fixed port role. However, the port role variables are not updated. How is this supposed to be handled ? The same is true for other role change attributes - I don't see any code to update the role variables. Presumably this would have to be done in the class code, since the port data structure is private.
This is a bug in the code indeed.
Quoted 4 lines
Overall, I am quite concerned by the lack of synchronization primitives between the class code and port drivers, but also in the class code itself. For example, nothing prevents multiple user space processes from writing into the same (or different) attribute(s) repeatedly.
We clearly need consensus on what this class will be responsible of. I've tried to explain how I see it above, hopefully with reasonable explanations. So basically, USB PD for this class is just a external feature that the alternate modes and power and vconn swapping depends on, that the class can not take any responsibility of IMHO.
The UCSI spec defines an other layer on top of the USB PD stack that basically describes what the userspace interface that I'm trying to achieve with this class is. The "OS Policy".
Thanks,
Signature · 1 line
heikki
Quoted 52 lines · Heikki Krogerus
Quoted 46 lines · Guenter Roeck
Hello Heikki,
Quoted 33 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 230 +++++++++++ 6 files changed, 1199 insertions(+) create mode 100644 drivers/usb/type-c/Kconfig create mode 100644 drivers/usb/type-c/Makefile create mode 100644 drivers/usb/type-c/typec.c create mode 100644 include/linux/usb/typec.hHi,
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
Quoted 9 lines
An other change is that the data role is now handled in two ways. The
current_data_rolefile will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to be fixed to one specific role with DRP ports. So this approach will replace the suggestions for "preferred" data role we had. Thecurrent_usb_data_rolewill use values "host" and "device" and it will be used for data role swapping when already connected.Quoted 4 lines
What I am missing completely is a means to handle role and alternate mode changes triggered by the partner. The need for those should be obvious, unless I am really missing something (just consider two devices supporting this code connected to each other).
Quoted 9 lines
We are missing the notifications that are needed in these cases. But I don't see much more we can do about those cases. We can not put any policies in place at this level, because we have to be able to support also things like USB PD and Type-C controllers that take care of all that, leaving us to not be able to do anything else but to pass the information forward. So the framework at this level has to be "stupid", and if more infrastructure is needed, it has to be introduced in an other layer.
Ok.
Quoted 11 lines
Quoted 10 lines
Also, I am not sure where the policy engine is supposed to reside. I understand that some policy changes (eg unsolicited requests to switch roles) can be triggered from user space. However, role change requests triggered from the partner need to be evaluated quickly (typically within 15 ms), so user space can not get involved. Maybe it would help to have some text describing where the policy engine is expected to reside and how it is involved in the decision making process. This includes the initial decision making process, when it needs to be decided if role changes should be requested or if one or multiple alternate modes should be entered after the initial connection has been established.
Quoted 3 lines
Well, yes we need to document these things, but you are now coupling this framework with USB PD and we really should not do that.
Not really. I was trying to understand where you would expect the policy engine to reside, which you answered above.
Quoted 14 lines
The policy engine, and the whole USB PD stack, belongs inside the kernel, and it will be completely separated from this framework. This framework can not have any dependencies on the future USB PD stack. This is not only because of the USB PD/Type-C controllers which handle the policy engine on their own and only allow "unsolicited" requests like "swap role" and "enter/exit mode", but also because this framework must work smoothly on systems that don't want to use USB PD and of course also with USB Type-C PHYs that simply don't include USB PD transceiver.
The layer that joins these two parts together will be the port drivers themselves, so the USB Type-C/PD PHYs and controllers, at least in the beginning.
Quoted 15 lines
Any initial decisions about which role or which alternate mode to select belongs to the stack. The userspace will need to be notified, and the userspace can then attempt to request changes after that, but if there is something that blocks the requests, the attempt has to just fail. So we can't provide any knowledge for the userspace about the requirements regarding the high level operations we allow the userspace to request (so in practice swap role/power and enter/exit mode). This information the userspace needs to get from somewhere else just live without it. Nor do we expect the userspace to be aware of the state of the system. So for example if the userspace attempts to activate a mode, the framework will just pass it forward to the port driver, which will then process it with the PD stack, and if for example the state is not
PE_SRC_ReadyorPE_SNK_Readyor whatever, the operation will just fail probable with-EBUSYin that case.
Makes sense.
Quoted 18 lines
And the knowledge about dependencies related to the alternate modes belong primarily to the alternate mode specific drivers in the end (once we have the bus) like I said. We can't expect the USB PD stack to be aware of those as they are alternate mode specific, and of course we can not trust that the userspace will always do things the right way. But the initial states after connection must be handle by the policy engine of course.
Quoted 9 lines
On top of that, I am concerned about synchronization problems with role changes triggered from user space. The driver is not told about the desired role, only that it shall perform a role change. If a role change triggered by the partner is ongoing at the time a role change request is made from user space, it may well happen that the dual role change results in a revert to the original role. Some synchronization primitives as well as an API change might resolve that, but essentially it would mean that drivers have to implement at least part of the policy engine. It might make more sense to have that code in the infrastructure.
Quoted 2 lines
Well, like I said above, this framework can not provide this infrastructure. The framework at this level really has to be "stupid".
Ok.
Quoted 5 lines
We simply can not do any decisions or have any expectations at this level. If more infra is needed, it has to be provided in an other layer on top of this bottom layer. So basically the driver have to implement those things for now.
I still think that the lack of synchronization is inherently racy. For example, on a power role swap request, port->pwr_role can change (via the currently missing notification) after it was evaluated in current_power_role_store(), but before port->cap->pr_swap() is called. The lower level code has at this point no means to know which power role change was requested, which may result in the power role being swapped again even though it already is in the requested state.
Quoted 9 lines
Quoted 4 lines
On disconnect, a port reverts to the default role. However, on port registration, the port roles are left at 0, meaning they always default to device/sink independent of the port's capabilities. Is this on purpose ?
On disconnect, the port role is set according to the "
fixed_role"? If the port is DFP only, then the port will still be host/source after disconnect. I don't see the problem here?
Roles are set differently on port registration vs. disconnect. This means that roles (can) differ between "initial disconnect state" and "disconnect state after connect". On port registration, usb_role, pwr_role, and vconn_role are all set based on the current pwr_opmode. During port registration, they are all initialized with 0.
Quoted 13 lines
Quoted 5 lines
current_data_role_store()lets user space set a fixed port role. However, the port role variables are not updated. How is this supposed to be handled ? The same is true for other role change attributes - I don't see any code to update the role variables. Presumably this would have to be done in the class code, since the port data structure is private.This is a bug in the code indeed.
Quoted 4 lines
Overall, I am quite concerned by the lack of synchronization primitives between the class code and port drivers, but also in the class code itself. For example, nothing prevents multiple user space processes from writing into the same (or different) attribute(s) repeatedly.
Quoted 6 lines
We clearly need consensus on what this class will be responsible of. I've tried to explain how I see it above, hopefully with reasonable explanations. So basically, USB PD for this class is just a external feature that the alternate modes and power and vconn swapping depends on, that the class can not take any responsibility of IMHO.
Sounds good to me, as long as the lower level code can inform the class about state/role changes.
Quoted 4 lines
The UCSI spec defines an other layer on top of the USB PD stack that basically describes what the userspace interface that I'm trying to achieve with this class is. The "OS Policy".
Since you mention UCSI - in UCSI, the two API functions available to set the power role (Set Power Direction Mode, Set Power Direction Mode) both provide the desired role to the connector driver. How does this map to the API in the class code, where a power swap is requested without telling the low level code about the desired role ?
Personally I prefer the approach used in UCSI, or let's say what I perceive the approach to be: Maybe the class code should just send a request to the connector driver to change the role to X, independent of the current role. This way, most if not all synchronization problems could be handled by the lower level driver.
On a side note, I don't see how to request a vconn swap with UCSI. Is that supported ?
Thanks,
Guenter
Heikki Krogerus
maintainerQuoted 75 lines · Guenter Roeck
Quoted 52 lines · Heikki Krogerus
Quoted 46 lines · Guenter Roeck
Hello Heikki,
Quoted 33 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 230 +++++++++++ 6 files changed, 1199 insertions(+) create mode 100644 drivers/usb/type-c/Kconfig create mode 100644 drivers/usb/type-c/Makefile create mode 100644 drivers/usb/type-c/typec.c create mode 100644 include/linux/usb/typec.hHi,
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
Quoted 9 lines
An other change is that the data role is now handled in two ways. The
current_data_rolefile will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to be fixed to one specific role with DRP ports. So this approach will replace the suggestions for "preferred" data role we had. Thecurrent_usb_data_rolewill use values "host" and "device" and it will be used for data role swapping when already connected.Quoted 4 lines
What I am missing completely is a means to handle role and alternate mode changes triggered by the partner. The need for those should be obvious, unless I am really missing something (just consider two devices supporting this code connected to each other).
Quoted 9 lines
We are missing the notifications that are needed in these cases. But I don't see much more we can do about those cases. We can not put any policies in place at this level, because we have to be able to support also things like USB PD and Type-C controllers that take care of all that, leaving us to not be able to do anything else but to pass the information forward. So the framework at this level has to be "stupid", and if more infrastructure is needed, it has to be introduced in an other layer.
Ok.
Quoted 11 lines
Quoted 10 lines
Also, I am not sure where the policy engine is supposed to reside. I understand that some policy changes (eg unsolicited requests to switch roles) can be triggered from user space. However, role change requests triggered from the partner need to be evaluated quickly (typically within 15 ms), so user space can not get involved. Maybe it would help to have some text describing where the policy engine is expected to reside and how it is involved in the decision making process. This includes the initial decision making process, when it needs to be decided if role changes should be requested or if one or multiple alternate modes should be entered after the initial connection has been established.
Quoted 5 lines
Quoted 3 lines
Well, yes we need to document these things, but you are now coupling this framework with USB PD and we really should not do that.
Not really. I was trying to understand where you would expect the policy engine to reside, which you answered above.
Ah OK, got it. Sorry.
Quoted 59 lines
Quoted 14 lines
The policy engine, and the whole USB PD stack, belongs inside the kernel, and it will be completely separated from this framework. This framework can not have any dependencies on the future USB PD stack. This is not only because of the USB PD/Type-C controllers which handle the policy engine on their own and only allow "unsolicited" requests like "swap role" and "enter/exit mode", but also because this framework must work smoothly on systems that don't want to use USB PD and of course also with USB Type-C PHYs that simply don't include USB PD transceiver.
The layer that joins these two parts together will be the port drivers themselves, so the USB Type-C/PD PHYs and controllers, at least in the beginning.
Quoted 15 lines
Any initial decisions about which role or which alternate mode to select belongs to the stack. The userspace will need to be notified, and the userspace can then attempt to request changes after that, but if there is something that blocks the requests, the attempt has to just fail. So we can't provide any knowledge for the userspace about the requirements regarding the high level operations we allow the userspace to request (so in practice swap role/power and enter/exit mode). This information the userspace needs to get from somewhere else just live without it. Nor do we expect the userspace to be aware of the state of the system. So for example if the userspace attempts to activate a mode, the framework will just pass it forward to the port driver, which will then process it with the PD stack, and if for example the state is not
PE_SRC_ReadyorPE_SNK_Readyor whatever, the operation will just fail probable with-EBUSYin that case.Makes sense.
Quoted 18 lines
And the knowledge about dependencies related to the alternate modes belong primarily to the alternate mode specific drivers in the end (once we have the bus) like I said. We can't expect the USB PD stack to be aware of those as they are alternate mode specific, and of course we can not trust that the userspace will always do things the right way. But the initial states after connection must be handle by the policy engine of course.
Quoted 9 lines
On top of that, I am concerned about synchronization problems with role changes triggered from user space. The driver is not told about the desired role, only that it shall perform a role change. If a role change triggered by the partner is ongoing at the time a role change request is made from user space, it may well happen that the dual role change results in a revert to the original role. Some synchronization primitives as well as an API change might resolve that, but essentially it would mean that drivers have to implement at least part of the policy engine. It might make more sense to have that code in the infrastructure.
Quoted 2 lines
Well, like I said above, this framework can not provide this infrastructure. The framework at this level really has to be "stupid".
Ok.
Quoted 5 lines
We simply can not do any decisions or have any expectations at this level. If more infra is needed, it has to be provided in an other layer on top of this bottom layer. So basically the driver have to implement those things for now.
Quoted 7 lines
I still think that the lack of synchronization is inherently racy. For example, on a power role swap request,
port->pwr_rolecan change (via the currently missing notification) after it was evaluated incurrent_power_role_store(), but beforeport->cap->pr_swap()is called. The lower level code has at this point no means to know which power role change was requested, which may result in the power role being swapped again even though it already is in the requested state.
You are correct. We need to pass the requested role to the drivers.
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
On disconnect, a port reverts to the default role. However, on port registration, the port roles are left at 0, meaning they always default to device/sink independent of the port's capabilities. Is this on purpose ?
On disconnect, the port role is set according to the "
fixed_role"? If the port is DFP only, then the port will still be host/source after disconnect. I don't see the problem here?
Quoted 5 lines
Roles are set differently on port registration vs. disconnect. This means that roles (can) differ between "initial disconnect state" and "disconnect state after connect". On port registration,
usb_role,pwr_role, andvconn_roleare all set based on the currentpwr_opmode. During port registration, they are all initialized with 0.
Got it. I'll fix that.
Quoted 32 lines
Quoted 13 lines
Quoted 5 lines
current_data_role_store()lets user space set a fixed port role. However, the port role variables are not updated. How is this supposed to be handled ? The same is true for other role change attributes - I don't see any code to update the role variables. Presumably this would have to be done in the class code, since the port data structure is private.This is a bug in the code indeed.
Quoted 4 lines
Overall, I am quite concerned by the lack of synchronization primitives between the class code and port drivers, but also in the class code itself. For example, nothing prevents multiple user space processes from writing into the same (or different) attribute(s) repeatedly.
Quoted 6 lines
We clearly need consensus on what this class will be responsible of. I've tried to explain how I see it above, hopefully with reasonable explanations. So basically, USB PD for this class is just a external feature that the alternate modes and power and vconn swapping depends on, that the class can not take any responsibility of IMHO.
Sounds good to me, as long as the lower level code can inform the class about state/role changes.
Quoted 4 lines
The UCSI spec defines an other layer on top of the USB PD stack that basically describes what the userspace interface that I'm trying to achieve with this class is. The "OS Policy".
Since you mention UCSI - in UCSI, the two API functions available to set the power role (Set Power Direction Mode, Set Power Direction Mode) both provide the desired role to the connector driver. How does this map to the API in the class code, where a power swap is requested without telling the low level code about the desired role ?
Quoted 5 lines
Personally I prefer the approach used in UCSI, or let's say what I perceive the approach to be: Maybe the class code should just send a request to the connector driver to change the role to X, independent of the current role. This way, most if not all synchronization problems could be handled by the lower level driver.
That sounds good to me. And it fits to the plan that the class does not make any decisions.
Quoted 2 lines
On a side note, I don't see how to request a vconn swap with UCSI. Is that supported ?
No, with UCSI we can not support vconn swap. Originally I was not even proposing an attribute for vconn swap in v1, but there was demand for it.
Thanks,
Signature · 1 line
heikki
Quoted 4 lines · Heikki Krogerus
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
Is this strictly divorced from USB PD?
How do you trigger a cable reset or a USB PD reset?
Regards
Oliver
Heikki Krogerus
maintainerHi Oliver,
Quoted 7 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
Is this strictly divorced from USB PD?
The bus can not be tied to the USB PD stack we will have in the kernel completely, or there is no change of using it with things like UCSI. It's going to be difficult to achieve that in any case as we simply won't be able to send and rescieve the VDMs with things like UCSI, but let's see.
Quoted 1 line
How do you trigger a cable reset or a USB PD reset?
There needs to be an API, but I'm sure that's not going to be a problem. The bus and the altmode specific drivers will reside inside kernel.
But I'm getting the sense that you are thinking about having some responsibility of USB PD in userspace. Please correct me if I'm wrong. I don't think it will be possible. I think the role of userspace can only be the source for high level requests via this interface, like enter/exit mode and swap role, and receiving the status and details of the ports, but any knowledge about the requirements regarding those steps belongs to the kernel. This includes also the knowledge about stuff like mode dependencies, for example if cable plug has to be in a certain mode in order for the partner to be able to enter some specific mode, etc.
Thanks.
Signature · 1 line
heikki
Quoted 17 lines · Heikki Krogerus
Hi Oliver,
Quoted 7 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
Is this strictly divorced from USB PD?
The bus can not be tied to the USB PD stack we will have in the kernel completely, or there is no change of using it with things like UCSI. It's going to be difficult to achieve that in any case as we simply won't be able to send and rescieve the VDMs with things like UCSI, but let's see.
Quoted 5 lines
Quoted 1 line
How do you trigger a cable reset or a USB PD reset?
There needs to be an API, but I'm sure that's not going to be a problem. The bus and the altmode specific drivers will reside inside kernel.
Absolutely. But at some point we need to settle on an API. If I am to tell you whether your proposed API leaves out something that needs to be covered, I need to know what is to go into the other APIs.
A reset is a generic function, so it does not belong to specific drivers.
Quoted 2 lines
But I'm getting the sense that you are thinking about having some responsibility of USB PD in userspace. Please correct me if I'm wrong.
Gods help us all if we are ready to do that.
It would fail.
Yet I think the idea that PD and Alternate Modes can be cleanly divorced is wrong. The selection of Alternate Modes is done by USB PD messages. We can encapsulate that, but we cannot leave it out, especially in the area of resets.
Quoted 5 lines
I don't think it will be possible. I think the role of userspace can only be the source for high level requests via this interface, like enter/exit mode and swap role, and receiving the status and details of the ports, but any knowledge about the requirements regarding those steps belongs to the kernel. This includes also the knowledge about
Yes.
Quoted 3 lines
stuff like mode dependencies, for example if cable plug has to be in a certain mode in order for the partner to be able to enter some specific mode, etc.
Yes.
So for Alternate Modes we need on a high level the following features
1. discovery of available Alternate Modes
2. selection of an Alternate Mode
3. notification about entering an Alternate Mode
4. triggering a reset
5. notification about resets
6. discovery about the current role
7. switching roles
8. setting preferred roles (Try.SRC and Try.SNK)
You covered 1. and 2.
3. can be covered by specific drivers
4. and 5. are not covered (and it makes no sense to tie it to specific drivers)
6. and 7. is covered
8. is not
And 8. needs to be covered. It affects who selects the Alternate Mode. You cannot tie it to USB and it doesn't fit with pure PD stuff.
I like your API as it is now. But it is incomplete.
Regards
Oliver
Quoted 24 lines · Oliver Neukum
Quoted 17 lines · Heikki Krogerus
Hi Oliver,
Quoted 7 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
Is this strictly divorced from USB PD?
The bus can not be tied to the USB PD stack we will have in the kernel completely, or there is no change of using it with things like UCSI. It's going to be difficult to achieve that in any case as we simply won't be able to send and rescieve the VDMs with things like UCSI, but let's see.
Quoted 5 lines
Quoted 1 line
How do you trigger a cable reset or a USB PD reset?
There needs to be an API, but I'm sure that's not going to be a problem. The bus and the altmode specific drivers will reside inside kernel.
Quoted 8 lines
Absolutely. But at some point we need to settle on an API. If I am to tell you whether your proposed API leaves out something that needs to be covered, I need to know what is to go into the other APIs.
A reset is a generic function, so it does not belong to specific drivers.
A would expect the driver to execute the reset.
Maybe the question should be phrased differently: Even USCI (which doesn't provide for everything) has commands to reset the policy manager and to reset the connector. The class should provide a means to execute those commands.
Quoted 32 lines
Quoted 2 lines
But I'm getting the sense that you are thinking about having some responsibility of USB PD in userspace. Please correct me if I'm wrong.
Gods help us all if we are ready to do that.
It would fail.
Yet I think the idea that PD and Alternate Modes can be cleanly divorced is wrong. The selection of Alternate Modes is done by USB PD messages. We can encapsulate that, but we cannot leave it out, especially in the area of resets.Quoted 5 lines
I don't think it will be possible. I think the role of userspace can only be the source for high level requests via this interface, like enter/exit mode and swap role, and receiving the status and details of the ports, but any knowledge about the requirements regarding those steps belongs to the kernel. This includes also the knowledge about
Yes.
Quoted 3 lines
stuff like mode dependencies, for example if cable plug has to be in a certain mode in order for the partner to be able to enter some specific mode, etc.
Yes.
So for Alternate Modes we need on a high level the following features
1. discovery of available Alternate Modes
2. selection of an Alternate Mode
3. notification about entering an Alternate Mode
4. triggering a reset
5. notification about resets
Quoted 4 lines
6. discovery about the current role
7. switching roles
8. setting preferred roles (Try.SRC and Try.SNK)
Isn't reset and role handling orthogonal to alternate mode functionality ? Both will still be needed even if alternate mode support is not implemented at all.
Quoted 9 lines
You covered 1. and 2.
3. can be covered by specific drivers
4. and 5. are not covered (and it makes no sense to tie it to specific drivers)6. and 7. is covered
8. is notAnd 8. needs to be covered. It affects who selects the Alternate Mode.
Doesn't the actual role determine that ? A device which prefers to be a DFP might still end up as UFP.
Quoted 4 lines
You cannot tie it to USB and it doesn't fit with pure PD stuff.
I like your API as it is now. But it is incomplete.
Same here.
Thanks,
Guenter
Quoted 6 lines · Guenter Roeck
Quoted 5 lines · Oliver Neukum
On Mon, 2016-05-23 at 12:57 +0300, Heikki Krogerus wrote:
A reset is a generic function, so it does not belong to specific drivers.
Quoted 6 lines
A would expect the driver to execute the reset.
Maybe the question should be phrased differently: Even USCI (which doesn't provide for everything) has commands to reset the policy manager and to reset the connector. The class should provide a means to execute those commands.
Yes.
Quoted 8 lines
Quoted 8 lines
So for Alternate Modes we need on a high level the following features
1. discovery of available Alternate Modes
2. selection of an Alternate Mode
3. notification about entering an Alternate Mode
4. triggering a reset
5. notification about resets
Quoted 8 lines
Quoted 4 lines
6. discovery about the current role
7. switching roles
8. setting preferred roles (Try.SRC and Try.SNK)Isn't reset and role handling orthogonal to alternate mode functionality ? Both will still be needed even if alternate mode support is not implemented at all.
In part. A reset can cause the Alternate Mode to be left unexpectedly and unintentionally.
So how many APIs do we want?
Three:
- Alternate Modes
- USB PD
- type C for roles and reset
Or another number?
Quoted 4 lines
Quoted 2 lines
I like your API as it is now. But it is incomplete.
Same here.
So what is to be done?
Regards
Oliver
Heikki Krogerus
maintainerQuoted 17 lines · Oliver Neukum
So for Alternate Modes we need on a high level the following features
1. discovery of available Alternate Modes
2. selection of an Alternate Mode
3. notification about entering an Alternate Mode
4. triggering a reset
5. notification about resets6. discovery about the current role
7. switching roles
8. setting preferred roles (Try.SRC and Try.SNK)You covered 1. and 2.
3. can be covered by specific drivers
4. and 5. are not covered (and it makes no sense to tie it to specific drivers)
Quoted 7 lines
6. and 7. is covered
8. is notAnd 8. needs to be covered. It affects who selects the Alternate Mode. You cannot tie it to USB and it doesn't fit with pure PD stuff.
I like your API as it is now. But it is incomplete.
OK, Got it.
Thanks Oliver,
Signature · 1 line
heikki
On Thu, 2016-05-19 at 15:44 +0300, Heikki Krogerus wrote:
Hi,
as this discussion seems to go in circles, I am starting anew at the top.
Quoted 11 lines
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
The API works for a DFP. I fail to see how the UFP learns about entering an alternate mode.
Secondly, support to trigger a reset is missing
Quoted 4 lines
An other change is that the data role is now handled in two ways. The
current_data_rolefile will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to be
Good, but support for Try.SRC and Try.SNK is missing. An additional problem with that is that it needs to work without user space during boot. So I think module parameters to set the default are necessary.
Quoted 30 lines
fixed to one specific role with DRP ports. So this approach will replace the suggestions for "preferred" data role we had. The
current_usb_data_rolewill use values "host" and "device" and it will be used for data role swapping when already connected.The tree of devices that will be populated when the cable is active and when the cable has controller on both plug, will look as following:
usbc0
|- usbc0-cable | |- usbc0-plug0 | | |- usbc0-plug.svid:xxx | | | |-mode0 | | | | |- vdo | | | | |- desc | | | | |- active ... | |- usbc0-plug1 | | |-usbc0-partner | | | |- usbc0-partner.svid:xxxx | | | | |-mode0 | | | | | |- vdo | | | | | |- desc | | | | | |- active | | | | |-mode1 ... | | |- usbc0-plug1.svid:xxx | | | |-mode0 | | | | |- vdo
Quoted 6 lines
...
If there is no active cable, the partner will be directly attached to the port, but symlink to the partner is now always added to the port folder in any case. I'm not sure about this approach. There is a question about it in the code. Please check it.
This approach looks workable.
An the whole the approach looks good, but needs to be extended.
Regards
Oliver
Heikki Krogerus
maintainerHi,
Quoted 19 lines · Oliver Neukum
On Thu, 2016-05-19 at 15:44 +0300, Heikki Krogerus wrote:
Hi,
as this discussion seems to go in circles, I am starting anew at the top.
Quoted 11 lines
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
Quoted 3 lines
The API works for a DFP. I fail to see how the UFP learns about entering an alternate mode.
Secondly, support to trigger a reset is missing
I'm fine with adding an attribute for port and cable resets if it's something that is needed. So do you want to be able to execute hard reset on a port?
But could you please explain the case(s) where you need to tricker a reset.
Quoted 6 lines
Quoted 4 lines
An other change is that the data role is now handled in two ways. The
current_data_rolefile will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to beGood, but support for Try.SRC and Try.SNK is missing.
OK, but what is Try.SNK? It's not in the specs?
Quoted 3 lines
An additional problem with that is that it needs to work without user space during boot. So I think module parameters to set the default are necessary.
I don't have a problem with that, but what does Greg say?
Quoted 32 lines
Quoted 32 lines
fixed to one specific role with DRP ports. So this approach will replace the suggestions for "preferred" data role we had. The
current_usb_data_rolewill use values "host" and "device" and it will be used for data role swapping when already connected.The tree of devices that will be populated when the cable is active and when the cable has controller on both plug, will look as following:
usbc0
|- usbc0-cable | |- usbc0-plug0 | | |- usbc0-plug.svid:xxx | | | |-mode0 | | | | |- vdo | | | | |- desc | | | | |- active ... | |- usbc0-plug1 | | |-usbc0-partner | | | |- usbc0-partner.svid:xxxx | | | | |-mode0 | | | | | |- vdo | | | | | |- desc | | | | | |- active | | | | |-mode1 ... | | |- usbc0-plug1.svid:xxx | | | |-mode0 | | | | |- vdo...
Quoted 7 lines
Quoted 4 lines
If there is no active cable, the partner will be directly attached to the port, but symlink to the partner is now always added to the port folder in any case. I'm not sure about this approach. There is a question about it in the code. Please check it.
This approach looks workable.
An the whole the approach looks good, but needs to be extended.
Thanks,
Signature · 1 line
heikki
Quoted 33 lines · Heikki Krogerus
Hi,
Quoted 19 lines · Oliver Neukum
On Thu, 2016-05-19 at 15:44 +0300, Heikki Krogerus wrote:
Hi,
as this discussion seems to go in circles, I am starting anew at the top.
Quoted 11 lines
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
Quoted 3 lines
The API works for a DFP. I fail to see how the UFP learns about entering an alternate mode.
Secondly, support to trigger a reset is missingI'm fine with adding an attribute for port and cable resets if it's something that is needed. So do you want to be able to execute hard reset on a port?
But could you please explain the case(s) where you need to tricker a reset.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
An other change is that the data role is now handled in two ways. The
current_data_rolefile will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to beGood, but support for Try.SRC and Try.SNK is missing.
OK, but what is Try.SNK? It's not in the specs?
It is not in the USB PD specification, but in "USB Type-C Specification Release 1.2 - Cable and Connector Specification".
Section 4.5.2.2.11, "Try.SNK State", says
"Note: if both Try.SRC and Try.SNK mechanisms are implemented, only one
shall be enabled by the port at any given time. Deciding which of these two mechanisms is enabled is product design-specific."
... which is why I suggested earlier that there should be a platform parameter to enable one or the other.
Guenter
Heikki Krogerus
maintainerQuoted 47 lines · Guenter Roeck
Quoted 33 lines · Heikki Krogerus
Hi,
Quoted 19 lines · Oliver Neukum
On Thu, 2016-05-19 at 15:44 +0300, Heikki Krogerus wrote:
Hi,
as this discussion seems to go in circles, I am starting anew at the top.
Quoted 11 lines
Like I've told some of you guys, I'm trying to implement a bus for the Alternate Modes, but I'm still nowhere near finished with that one, so let's just get the class ready now. The altmode bus should in any case not affect the userspace interface proposed in this patch.
As you can see, the Alternate Modes are handled completely differently compared to the original proposal. Every Alternate Mode will have their own device instance (which will be then later bound to an Alternate Mode specific driver once we have the bus), but also every partner, cable and cable plug will have their own device instances representing them.
Quoted 3 lines
The API works for a DFP. I fail to see how the UFP learns about entering an alternate mode.
Secondly, support to trigger a reset is missingI'm fine with adding an attribute for port and cable resets if it's something that is needed. So do you want to be able to execute hard reset on a port?
But could you please explain the case(s) where you need to tricker a reset.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
An other change is that the data role is now handled in two ways. The
current_data_rolefile will represent static mode of the port, and it will use the names for the roles as they are defined in the spec:
DFP, UFP and DRP. This file should be used if the port needs to beGood, but support for Try.SRC and Try.SNK is missing.
OK, but what is Try.SNK? It's not in the specs?
It is not in the USB PD specification, but in "USB Type-C Specification Release 1.2 - Cable and Connector Specification".
Quoted 8 lines
Section 4.5.2.2.11, "Try.SNK State", says
"Note: if both Try.SRC and Try.SNK mechanisms are implemented, only one
shall be enabled by the port at any given time. Deciding which of these two mechanisms is enabled is product design-specific."... which is why I suggested earlier that there should be a platform parameter to enable one or the other.
Heh, I'm still living the year 2015 :). I've missed the Type-C 1.2 spec.
Thanks guys,
Signature · 1 line
heikki
Quoted 14 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 230 +++++++++++ 6 files changed, 1199 insertions(+)
Quoted 5 lines
create mode 100644
drivers/usb/type-c/Kconfig
create mode 100644drivers/usb/type-c/Makefile
create mode 100644drivers/usb/type-c/typec.c
create mode 100644include/linux/usb/typec.h
Hi,
Quoted 19 lines
include/linux/usb/typec.h new file +19
-0+/* +* struct typec_capability - USB Type-C Port Capabilities +* @role: DFP (Host-only), UFP (Device-only) or DRP (Dual Role) +* @usb_pd: USB Power Delivery support +* @alt_modes: Alternate Modes the connector supports (null terminated) +* @audio_accessory: Audio Accessory Adapter Mode support +* @debug_accessory: Debug Accessory Mode support +* @fix_role: Set a fixed data role for DRP port +* @dr_swap: Data Role Swap support +* @pr_swap: Power Role Swap support +* @vconn_swap: VCONN Swap support +* @activate_mode: Enter/exit given Alternate Mode +* +* Static capabilities of a single USB Type-C port. +*/ +struct typec_capability { +enum typec_data_role role; +unsigned int usb_pd:1 ; +struct typec_altmode *alt_modes;
include/linux/usb/typec.h line 191
Quoted 10 lines
include/linux/usb/typec.h new file +10
-0+ unsigned int audio_accessory:1; + unsigned int debug_accessory:1; + +int (*fix_role)(struct typec_port *, +enum typec_data_role ); + +int (*dr_swap)(struct typec_port *); +int (*pr_swap)(struct typec_port *); +int (*vconn_swap)(struct typec_port *); +
The function parameter in those calls is all but useless to the caller. It needs to store the typec_port returned from typec_register(), create a list of ports, and then search through this list each time one of the functions is called. This is quite expensive for no good reason.
Previously, with typec_port exported, the called code could use the stored caps pointer to map to its internal data structures. This is no longer possible.
I think it would be useful to provide a better means for the called function to identify its context. Maybe provide a pointer to the private data in the registration function and use it as parameter in the callback functions ?
Thanks,
Guenter
Heikki Krogerus
maintainerHi,
Quoted 20 lines · Guenter Roeck
Quoted 4 lines
include/linux/usb/typec.h new file +4
-0+struct typec_capability { +enum typec_data_role role; +unsigned int usb_pd:1 ; +struct typec_altmode *alt_modes;include/linux/usb/typec.h line 191
Quoted 10 lines
include/linux/usb/typec.h new file +10
-0+ unsigned int audio_accessory:1; + unsigned int debug_accessory:1; + +int (*fix_role)(struct typec_port *, +enum typec_data_role ); + +int (*dr_swap)(struct typec_port *); +int (*pr_swap)(struct typec_port *); +int (*vconn_swap)(struct typec_port *); +The function parameter in those calls is all but useless to the caller. It needs to store the
typec_portreturned fromtypec_register(), create a list of ports, and then search through this list each time one of the functions is called. This is quite expensive for no good reason.
Quoted 3 lines
Previously, with
typec_portexported, the called code could use the stored caps pointer to map to its internal data structures. This is no longer possible.
True, the API now is in practice broken.
Quoted 3 lines
I think it would be useful to provide a better means for the called function to identify its context. Maybe provide a pointer to the private data in the registration function and use it as parameter in the callback functions ?
Sounds reasonable.
Thanks,
Signature · 1 line
heikki
Quoted 27 lines · Heikki Krogerus
Hi,
Quoted 20 lines · Guenter Roeck
Quoted 4 lines
include/linux/usb/typec.h new file +4
-0+struct typec_capability { +enum typec_data_role role; +unsigned int usb_pd:1 ; +struct typec_altmode *alt_modes;include/linux/usb/typec.h line 191
Quoted 10 lines
include/linux/usb/typec.h new file +10
-0+ unsigned int audio_accessory:1; + unsigned int debug_accessory:1; + +int (*fix_role)(struct typec_port *, +enum typec_data_role ); + +int (*dr_swap)(struct typec_port *); +int (*pr_swap)(struct typec_port *); +int (*vconn_swap)(struct typec_port *); +The function parameter in those calls is all but useless to the caller. It needs to store the
typec_portreturned fromtypec_register(), create a list of ports, and then search through this list each time one of the functions is called. This is quite expensive for no good reason.Quoted 3 lines
Previously, with
typec_portexported, the called code could use the stored caps pointer to map to its internal data structures. This is no longer possible.
Quoted 8 lines
True, the API now is in practice broken.
Quoted 3 lines
I think it would be useful to provide a better means for the called function to identify its context. Maybe provide a pointer to the private data in the registration function and use it as parameter in the callback functions ?
Sounds reasonable.
I'll send a follow-up patch hopefully later today which fixes all the problems I have found so far.
Guenter
Quoted 6 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>
[ ... ]
drivers/usb/type-c/typec.c line 153
Quoted 5 lines
drivers/usb/type-c/typec.c new file +5
-0+ +static void typec_remove_partner (struct typec_port *port) +{ +sysfs_remove_link (&port->dev.kobj,"partner" ); +typec_unregister_altmodes (port->partner->alt_modes);
This only unregisters alternate modes registered through typec_add_partner(), but not alternate modes registered separately. Or is the calling code expected to set port->partner->alt_modes when calling typec_register_altmodes() directly ?
[ ... ]
drivers/usb/type-c/typec.c line 563
Quoted 5 lines
drivers/usb/type-c/typec.c new file +5
-0+ +void typec_unregister_altmodes (struct typec_altmode *alt_modes) +{ +struct typec_altmode *alt; +
This will crash if alt_modes is NULL, which will happen if partner->alt_modes is NULL at connection time. Semantically this is different to typec_register_altmodes(), which does have a NULL check.
Guenter
Heikki Krogerus
maintainerQuoted 10 lines · Guenter Roeck
Quoted 6 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>[ ... ]
Quoted 10 lines
drivers/usb/type-c/typec.c line 153
Quoted 5 lines
drivers/usb/type-c/typec.c new file +5
-0+ +static void typec_remove_partner (struct typec_port *port) +{ +sysfs_remove_link (&port->dev.kobj,"partner" ); +typec_unregister_altmodes (port->partner->alt_modes);This only unregisters alternate modes registered through
typec_add_partner(), but not alternate modes registered separately. Or is the calling code expected to setport->partner->alt_modeswhen callingtypec_register_altmodes()directly ?
The altmodes for the partner are not meant to be registered separately. With the partners and also cable plugs the class is in control of registering and unregistering of the altmode devices after typec_connect() is called.
The idea was that only the ports will register the alternate modes they support separately, but I think we have to change that too. So I don't think we'll export the typec_un/register_altmodes() at all.
We will have to prevent any drivers from being bound to the port alternate mode devices when we add the alternate mode bus, and I had some idea where by making the port drivers themselves in charge of registering the port alternate modes, we could prevent it easily. But it's probable easier to just handle those in the class driver as well.
Quoted 9 lines
drivers/usb/type-c/typec.c line 563
Quoted 5 lines
drivers/usb/type-c/typec.c new file +5
-0+ +void typec_unregister_altmodes (struct typec_altmode *alt_modes) +{ +struct typec_altmode *alt; +This will crash if
alt_modesis NULL, which will happen ifpartner->alt_modesis NULL at connection time. Semantically this is different totypec_register_altmodes(), which does have a NULL check.
Yes, need to fix that.
Thanks Guenter,
Signature · 1 line
heikki
Quoted 31 lines · Heikki Krogerus
Quoted 10 lines · Guenter Roeck
Quoted 6 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>[ ... ]
Quoted 10 lines
drivers/usb/type-c/typec.c line 153
Quoted 5 lines
drivers/usb/type-c/typec.c new file +5
-0+ +static void typec_remove_partner (struct typec_port *port) +{ +sysfs_remove_link (&port->dev.kobj,"partner" ); +typec_unregister_altmodes (port->partner->alt_modes);This only unregisters alternate modes registered through
typec_add_partner(), but not alternate modes registered separately. Or is the calling code expected to setport->partner->alt_modeswhen callingtypec_register_altmodes()directly ?The altmodes for the partner are not meant to be registered separately. With the partners and also cable plugs the class is in control of registering and unregistering of the altmode devices after
typec_connect()is called.The idea was that only the ports will register the alternate modes they support separately, but I think we have to change that too. So I don't think we'll export the typec_un/register_altmodes() at all.
Quoted 6 lines
We will have to prevent any drivers from being bound to the port alternate mode devices when we add the alternate mode bus, and I had some idea where by making the port drivers themselves in charge of registering the port alternate modes, we could prevent it easily. But it's probable easier to just handle those in the class driver as well.
Alternate mode discovery is an orthogonal process to the connection state machine, and may take a while to complete. Are you saying that the call to typec_connect() should be delayed until after alternate mode discovery completes or times out ?
So far I call typec_connect() in SRC.Ready and SNK.Ready, and typec_register_altmodes() after mode discovery is complete. It is also orthogonal, meaning it is only called if and when alternate mode discovery completes, and the alternate mode discovery state machine is separate to the port state machine.
No problem for me to change that, just making sure that the registration delay is understood and accepted.
Thanks,
Guenter
Quoted 15 lines
Quoted 9 lines
drivers/usb/type-c/typec.c line 563
Quoted 5 lines
drivers/usb/type-c/typec.c new file +5
-0+ +void typec_unregister_altmodes (struct typec_altmode *alt_modes) +{ +struct typec_altmode *alt; +This will crash if
alt_modesis NULL, which will happen ifpartner->alt_modesis NULL at connection time. Semantically this is different totypec_register_altmodes(), which does have a NULL check.Yes, need to fix that.
Thanks Guenter,
Heikki Krogerus
maintainerQuoted 44 lines · Guenter Roeck
Quoted 31 lines · Heikki Krogerus
Quoted 10 lines · Guenter Roeck
Quoted 6 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Signed-off-by Heikki Krogerus <[email protected]>[ ... ]
Quoted 10 lines
drivers/usb/type-c/typec.c line 153
Quoted 5 lines
drivers/usb/type-c/typec.c new file +5
-0+ +static void typec_remove_partner (struct typec_port *port) +{ +sysfs_remove_link (&port->dev.kobj,"partner" ); +typec_unregister_altmodes (port->partner->alt_modes);This only unregisters alternate modes registered through
typec_add_partner(), but not alternate modes registered separately. Or is the calling code expected to setport->partner->alt_modeswhen callingtypec_register_altmodes()directly ?The altmodes for the partner are not meant to be registered separately. With the partners and also cable plugs the class is in control of registering and unregistering of the altmode devices after
typec_connect()is called.The idea was that only the ports will register the alternate modes they support separately, but I think we have to change that too. So I don't think we'll export the typec_un/register_altmodes() at all.
Quoted 6 lines
We will have to prevent any drivers from being bound to the port alternate mode devices when we add the alternate mode bus, and I had some idea where by making the port drivers themselves in charge of registering the port alternate modes, we could prevent it easily. But it's probable easier to just handle those in the class driver as well.
Alternate mode discovery is an orthogonal process to the connection state machine, and may take a while to complete. Are you saying that the call to
typec_connect()should be delayed until after alternate mode discovery completes or times out ?
Quoted 8 lines
So far I call
typec_connect()in SRC.Ready and SNK.Ready, andtypec_register_altmodes()after mode discovery is complete. It is also orthogonal, meaning it is only called if and when alternate mode discovery completes, and the alternate mode discovery state machine is separate to the port state machine.No problem for me to change that, just making sure that the registration delay is understood and accepted.
I'm not against leaving the responsibility of registering the alternate modes to the drivers. I'm a little bit worried about relying then on the drivers to also handle the unregistering accordingly, but I can live with that. But we just shouldn't share the responsibility of un/registering them between the class and the drivers, so the driver should then handle the registration always.
Oliver, what do you think?
Thanks,
Signature · 1 line
heikki
Quoted 8 lines · Heikki Krogerus
I'm not against leaving the responsibility of registering the alternate modes to the drivers. I'm a little bit worried about relying then on the drivers to also handle the unregistering accordingly, but I can live with that. But we just shouldn't share the responsibility of un/registering them between the class and the drivers, so the driver should then handle the registration always.
Oliver, what do you think?
Either will do for me. Registration by the drivers is a bit better. But it has to be the one or the other. Mixing is indeed bad.
Regards
Oliver
Quoted 9 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
I'm not against leaving the responsibility of registering the alternate modes to the drivers. I'm a little bit worried about relying then on the drivers to also handle the unregistering accordingly, but I can live with that. But we just shouldn't share the responsibility of un/registering them between the class and the drivers, so the driver should then handle the registration always.
Quoted 5 lines
Quoted 1 line
Oliver, what do you think?
Either will do for me. Registration by the drivers is a bit better. But it has to be the one or the other. Mixing is indeed bad.
Same here. I don't have any problems handling unregistering from the driver. I just have to keep track of the state and call typec_unregister_altmodes() before calling typec_disconnect().
Having to wait for mode discovery to complete before calling typec_connect() is much more complicated, at least with my current code.
Guenter
Heikki Krogerus
maintainerQuoted 15 lines · Guenter Roeck
Quoted 9 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
I'm not against leaving the responsibility of registering the alternate modes to the drivers. I'm a little bit worried about relying then on the drivers to also handle the unregistering accordingly, but I can live with that. But we just shouldn't share the responsibility of un/registering them between the class and the drivers, so the driver should then handle the registration always.
Quoted 5 lines
Quoted 1 line
Oliver, what do you think?
Either will do for me. Registration by the drivers is a bit better. But it has to be the one or the other. Mixing is indeed bad.
Quoted 7 lines
Same here. I don't have any problems handling unregistering from the driver. I just have to keep track of the state and call
typec_unregister_altmodes()before callingtypec_disconnect().Having to wait for mode discovery to complete before calling
typec_connect()is much more complicated, at least with my current code.
OK, so we'll change this and make the driver take care of the registration.
Signature · 1 line
heikki
RFC PATCH 1/1 usb: typec: Various API updates and fixes
In reply to Heikki KrogerusFrom: Guenter Roeck <[email protected]>
New API functions (calls into class code)
typec_set_usb_role()
typec_set_pwr_role()
typec_set_vconn_role()
typec_set_pwr_opmode()
Modified API functions (calls into class code):
typec_register_port(dev, cap) -> typec_register_port(dev, cap, driver_data)
Modified callback functions:
dr_swap(port) -> dr_set(port, driver_data, role); pr_swap(port) -> pr_set(port, driver_data, role); vconn_swap(port) -> vconn_set(port, driver_data, role); fix_role(port) -> fix_role(port, driver_data, role); activate_mode(...) -> activate_mode(..., driver_data, ...);
New sysfs attribute:
current_vconn_role
Other:
- Extract role initialization to new function typec_init_roles()
- Call driver code unconditionally on role changes
- Add NULL check in typec_unregister_altmodes()
- If an alternate mode description pointer is NULL, display an empty string.
---
This patch applies on top of '[RFC PATCHv2] usb: USB Type-C Connector Class' from Heikki Krogerus. It provided the changes I made to get the code operational.
drivers/usb/type-c/typec.c | 134 ++++++++++++++++++++++++++++++++++++--------- include/linux/usb/typec.h | 26 ++++++--- 2 files changed, 125 insertions(+), 35 deletions(-)
drivers/usb/type-c/typec.c +108 -26
@@ -27,6 +27,8 @@ struct typec_port {struct typec_partner *partner;struct typec_cable *cable; +void *driver_data; + unsigned int connected:1;int n_altmode;
@@ -324,6 +326,20 @@ static void typec_remove_cable(struct typec_port *port)device_unregister (&port->cable->dev); } +static void typec_init_roles (struct typec_port *port) +{ +if (port->fixed_role ==TYPEC_PORT_DFP ) { + port->usb_role =TYPEC_HOST ; + port->pwr_role =TYPEC_PWR_SOURCE ; + port->vconn_role =TYPEC_PWR_SOURCE ; + }else { +/* Device mode as default also with DRP ports */ + port->usb_role =TYPEC_DEVICE ; + port->pwr_role =TYPEC_PWR_SINK ; + port->vconn_role =TYPEC_PWR_SINK ; + } +} +/* -------------------------------- */ int typec_connect (struct typec_port *port,struct typec_connection *con)
@@ -378,16 +394,7 @@ void typec_disconnect(struct typec_port *port) port->pwr_opmode =TYPEC_PWR_MODE_USB ; -if (port->fixed_role ==TYPEC_PORT_DFP ) { - port->usb_role =TYPEC_HOST ; - port->pwr_role =TYPEC_PWR_SOURCE ; - port->vconn_role =TYPEC_PWR_SOURCE ; - }else { -/* Device mode as default also with DRP ports */ - port->usb_role =TYPEC_DEVICE ; - port->pwr_role =TYPEC_PWR_SINK ; - port->vconn_role =TYPEC_PWR_SINK ; - } +typec_init_roles (port);kobject_uevent (&port->dev.kobj,KOBJ_CHANGE ); }
@@ -405,6 +412,34 @@ struct typec_port *typec_dev2port(struct device *dev) }EXPORT_SYMBOL_GPL (typec_dev2port); +/* --------------------------------------- */ +/* Driver callbacks to report role updates */ + +void typec_set_usb_role (struct typec_port *port,enum typec_usb_role role) +{ + port->usb_role = role; +} +EXPORT_SYMBOL (typec_set_usb_role); + +void typec_set_pwr_role (struct typec_port *port,enum typec_pwr_role role) +{ + port->pwr_role = role; +} +EXPORT_SYMBOL (typec_set_pwr_role); + +void typec_set_vconn_role (struct typec_port *port,enum typec_pwr_role role) +{ + port->vconn_role = role; +} +EXPORT_SYMBOL (typec_set_vconn_role); + +void typec_set_pwr_opmode (struct typec_port *port, +enum typec_pwr_opmode opmode) +{ + port->pwr_opmode = opmode; +} +EXPORT_SYMBOL (typec_set_pwr_opmode); +/* -------------------------------- */ /* Alternate Modes */
@@ -451,7 +486,7 @@ typec_altmode_desc_show(struct device *dev, struct device_attribute *attr, struct typec_mode *mode = container_of(attr, struct typec_mode, desc_attr); -return sprintf (buf,"%s\n" , mode->desc); +return sprintf (buf,"%s\n" , mode->desc ? mode->desc :"" ); } static ssize_t
@@ -561,6 +596,9 @@ void typec_unregister_altmodes(struct typec_altmode *alt_modes) {struct typec_altmode *alt; +if (!alt_modes) +return ; +for (alt = alt_modes; alt->svid; alt++)device_unregister (&alt->dev); }
@@ -581,7 +619,7 @@ current_usb_data_role_store(struct device *dev, struct device_attribute *attr,return -EOPNOTSUPP ; } -if (!port->cap->dr_swap) { +if (!port->cap->dr_set) {dev_warn (dev,"data role swapping not supported\n" );return -EOPNOTSUPP ; }
@@ -593,10 +631,7 @@ current_usb_data_role_store(struct device *dev, struct device_attribute *attr,else return -EINVAL ; -if (port->usb_role == role || !port->partner) -return size; - - ret = port->cap->dr_swap (port); + ret = port->cap->dr_set (port, port->driver_data, role);if (ret)return ret;
@@ -655,10 +690,7 @@ current_data_role_store(struct device *dev, struct device_attribute *attr,else return -EINVAL ; -if (port->fixed_role == role) -return size; - - ret = port->cap->fix_role (port, role); + ret = port->cap->fix_role (port, port->driver_data, role);if (ret)return ret;
@@ -688,7 +720,7 @@ static ssize_t current_power_role_store(struct device *dev,return -EOPNOTSUPP ; } -if (!port->cap->pr_swap) { +if (!port->cap->pr_set) {dev_warn (dev,"power role swapping not supported\n" );return -EOPNOTSUPP ; }
@@ -705,10 +737,7 @@ static ssize_t current_power_role_store(struct device *dev,else return -EINVAL ; -if (port->pwr_role == role || !port->partner) -return size; - - ret = port->cap->pr_swap (port); + ret = port->cap->pr_set (port, port->driver_data, role);if (ret)return ret;
@@ -762,6 +791,54 @@ static ssize_t power_operation_mode_show(struct device *dev, }static DEVICE_ATTR_RO (power_operation_mode); +static ssize_t current_vconn_role_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t size) +{ +struct typec_port *port =to_typec_port (dev); +enum typec_pwr_role role; +int ret; + +if (!port->cap->usb_pd) { +dev_dbg (dev,"vconn swap only supported with USB PD\n" ); +return -EOPNOTSUPP ; + } + +if (!port->cap->vconn_set) { +dev_warn (dev,"vconn swapping not supported\n" ); +return -EOPNOTSUPP ; + } + +if (!strncmp (buf,"source" ,6 )) + role =TYPEC_PWR_SOURCE ; +else if (!strncmp (buf,"sink" ,4 )) + role =TYPEC_PWR_SINK ; +else +return -EINVAL ; + + ret = port->cap->vconn_set (port, port->driver_data, role); +if (ret) +return ret; + +return size; +} + +static ssize_t current_vconn_role_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct typec_port *port =to_typec_port (dev); + +switch (port->vconn_role) { +case TYPEC_PWR_SOURCE : +return sprintf (buf,"source\n" ); +case TYPEC_PWR_SINK : +return sprintf (buf,"sink\n" ); +default : +return sprintf (buf,"unknown\n" ); + }; +} +static DEVICE_ATTR_RW (current_vconn_role); +static ssize_t supports_audio_accessory_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -795,6 +872,7 @@ static DEVICE_ATTR_RO(supports_usb_power_delivery);static struct attribute *typec_attrs[] = { &dev_attr_current_data_role.attr, &dev_attr_current_power_role.attr, + &dev_attr_current_vconn_role.attr, &dev_attr_current_usb_data_role.attr, &dev_attr_power_operation_mode.attr, &dev_attr_supported_data_roles.attr,
@@ -862,7 +940,8 @@ static struct device_type typec_port_dev_type = { };struct typec_port *typec_register_port (struct device *dev, -struct typec_capability *cap) +struct typec_capability *cap, +void *driver_data) {struct typec_port *port;int ret;
@@ -880,6 +959,7 @@ struct typec_port *typec_register_port(struct device *dev, port->id = id; port->cap = cap; + port->driver_data = driver_data; port->dev.type = &typec_port_dev_type; port->dev.class = &typec_class; port->dev.parent = dev;
@@ -888,6 +968,8 @@ struct typec_port *typec_register_port(struct device *dev, port->fixed_role = port->cap->role; +typec_init_roles (port); + ret =device_register (&port->dev);if (ret) {ida_simple_remove (&typec_index_ida, id);
include/linux/usb/typec.h +17 -9
@@ -168,9 +168,9 @@ struct typec_partner {* @audio_accessory: Audio Accessory Adapter Mode support * @debug_accessory: Debug Accessory Mode support * @fix_role: Set a fixed data role for DRP port -* @dr_swap: Data Role Swap support -* @pr_swap: Power Role Swap support -* @vconn_swap: VCONN Swap support +* @dr_set: Set Data Role +* @pr_set: Set Power Role +* @vconn_set: Set VCONN Role * @activate_mode: Enter/exit given Alternate Mode * * Static capabilities of a single USB Type-C port.
@@ -182,14 +182,14 @@ struct typec_capability { unsigned int audio_accessory:1; unsigned int debug_accessory:1; -int (*fix_role)(struct typec_port *, +int (*fix_role)(struct typec_port *,void *,enum typec_data_role ); -int (*dr_swap)(struct typec_port *); -int (*pr_swap)(struct typec_port *); -int (*vconn_swap)(struct typec_port *); +int (*dr_set)(struct typec_port *,void *,enum typec_usb_role ); +int (*pr_set)(struct typec_port *,void *,enum typec_pwr_role ); +int (*vconn_set)(struct typec_port *,void *,enum typec_pwr_role ); -int (*activate_mode)(struct typec_altmode *, +int (*activate_mode)(struct typec_altmode *,void *,int mode,int activate); };
@@ -217,7 +217,8 @@ struct typec_connection { };struct typec_port *typec_register_port (struct device *dev, -struct typec_capability *cap); +struct typec_capability *cap, +void *driver_data);void typec_unregister_port (struct typec_port *port);int typec_connect (struct typec_port *port,struct typec_connection *con);
@@ -227,4 +228,11 @@ void typec_disconnect(struct typec_port *port);struct device *typec_port2dev (struct typec_port *port);struct typec_port *typec_dev2port (struct device *dev); +/* Callbacks from driver */ + +void typec_set_usb_role (struct typec_port *,enum typec_usb_role ); +void typec_set_pwr_role (struct typec_port *,enum typec_pwr_role ); +void typec_set_vconn_role (struct typec_port *,enum typec_pwr_role ); +void typec_set_pwr_opmode (struct typec_port *,enum typec_pwr_opmode ); +#endif /* __LINUX_USB_TYPEC_H */
Signature · 1 line
2.5.0
Heikki Krogerus
maintainerRe: [RFC PATCH] usb: typec: Various API updates and fixes
Hi,
Quoted 31 lines · Guenter Roeck
From: Guenter Roeck <[email protected]>
New API functions (calls into class code)
typec_set_usb_role()
typec_set_pwr_role()
typec_set_vconn_role()
typec_set_pwr_opmode()Modified API functions (calls into class code):
typec_register_port(dev, cap) -> typec_register_port(dev, cap, driver_data)Modified callback functions:
dr_swap(port) -> dr_set(port, driver_data, role); pr_swap(port) -> pr_set(port, driver_data, role); vconn_swap(port) -> vconn_set(port, driver_data, role); fix_role(port) -> fix_role(port, driver_data, role); activate_mode(...) -> activate_mode(..., driver_data, ...);New sysfs attribute:
current_vconn_roleOther:
- Extract role initialization to new functiontypec_init_roles()
- Call driver code unconditionally on role changes
- Add NULL check intypec_unregister_altmodes()
- If an alternate mode description pointer is NULL, display an empty string.Signed-off-by Guenter Roeck <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
Quoted 8 lines
---
This patch applies on top of '[RFC PATCHv2] usb: USB Type-C Connector Class' from Heikki Krogerus. It provided the changes I made to get the code operational.drivers/usb/type-c/typec.c | 134 ++++++++++++++++++++++++++++++++++++--------- include/linux/usb/typec.h | 26 ++++++--- 2 files changed, 125 insertions(+), 35 deletions(-)
Thanks Guenter. After a quick glance looks good to me.
I think I'll create a development branch to my github tree for this class and add this on top of the original v2 patch as is. Just to have some history for as long we develop this thing. Though I'm not sure how useful it is in this case. I think we need to put this together fast. I'm thinking we need to target v4.8 with this.
I'll merge this into any case to v3, and I'll send on Monday.
Quoted 311 lines
drivers/usb/type-c/typec.c +108
-26@@ -27,6 +27,8 @@ struct typec_port {struct typec_partner *partner;struct typec_cable *cable; +void *driver_data; + unsigned int connected:1;int n_altmode;@@ -324,6 +326,20 @@ static void typec_remove_cable(struct typec_port *port)device_unregister (&port->cable->dev); } +static void typec_init_roles (struct typec_port *port) +{ +if (port->fixed_role ==TYPEC_PORT_DFP ) { + port->usb_role =TYPEC_HOST ; + port->pwr_role =TYPEC_PWR_SOURCE ; + port->vconn_role =TYPEC_PWR_SOURCE ; + }else { +/* Device mode as default also with DRP ports */ + port->usb_role =TYPEC_DEVICE ; + port->pwr_role =TYPEC_PWR_SINK ; + port->vconn_role =TYPEC_PWR_SINK ; + } +} +/* -------------------------------- */ int typec_connect (struct typec_port *port,struct typec_connection *con)@@ -378,16 +394,7 @@ void typec_disconnect(struct typec_port *port) port->pwr_opmode =TYPEC_PWR_MODE_USB ; -if (port->fixed_role ==TYPEC_PORT_DFP ) { - port->usb_role =TYPEC_HOST ; - port->pwr_role =TYPEC_PWR_SOURCE ; - port->vconn_role =TYPEC_PWR_SOURCE ; - }else { -/* Device mode as default also with DRP ports */ - port->usb_role =TYPEC_DEVICE ; - port->pwr_role =TYPEC_PWR_SINK ; - port->vconn_role =TYPEC_PWR_SINK ; - } +typec_init_roles (port);kobject_uevent (&port->dev.kobj,KOBJ_CHANGE ); }@@ -405,6 +412,34 @@ struct typec_port *typec_dev2port(struct device *dev) }EXPORT_SYMBOL_GPL (typec_dev2port); +/* --------------------------------------- */ +/* Driver callbacks to report role updates */ + +void typec_set_usb_role (struct typec_port *port,enum typec_usb_role role) +{ + port->usb_role = role; +} +EXPORT_SYMBOL (typec_set_usb_role); + +void typec_set_pwr_role (struct typec_port *port,enum typec_pwr_role role) +{ + port->pwr_role = role; +} +EXPORT_SYMBOL (typec_set_pwr_role); + +void typec_set_vconn_role (struct typec_port *port,enum typec_pwr_role role) +{ + port->vconn_role = role; +} +EXPORT_SYMBOL (typec_set_vconn_role); + +void typec_set_pwr_opmode (struct typec_port *port, +enum typec_pwr_opmode opmode) +{ + port->pwr_opmode = opmode; +} +EXPORT_SYMBOL (typec_set_pwr_opmode); +/* -------------------------------- */ /* Alternate Modes */ @@ -451,7 +486,7 @@ typec_altmode_desc_show(struct device *dev, struct device_attribute *attr, struct typec_mode *mode = container_of(attr, struct typec_mode, desc_attr); -return sprintf (buf,"%s\n" , mode->desc); +return sprintf (buf,"%s\n" , mode->desc ? mode->desc :"" ); } static ssize_t@@ -561,6 +596,9 @@ void typec_unregister_altmodes(struct typec_altmode *alt_modes) {struct typec_altmode *alt; +if (!alt_modes) +return ; +for (alt = alt_modes; alt->svid; alt++)device_unregister (&alt->dev); }@@ -581,7 +619,7 @@ current_usb_data_role_store(struct device *dev, struct device_attribute *attr,return -EOPNOTSUPP ; } -if (!port->cap->dr_swap) { +if (!port->cap->dr_set) {dev_warn (dev,"data role swapping not supported\n" );return -EOPNOTSUPP ; }@@ -593,10 +631,7 @@ current_usb_data_role_store(struct device *dev, struct device_attribute *attr,else return -EINVAL ; -if (port->usb_role == role || !port->partner) -return size; - - ret = port->cap->dr_swap (port); + ret = port->cap->dr_set (port, port->driver_data, role);if (ret)return ret;@@ -655,10 +690,7 @@ current_data_role_store(struct device *dev, struct device_attribute *attr,else return -EINVAL ; -if (port->fixed_role == role) -return size; - - ret = port->cap->fix_role (port, role); + ret = port->cap->fix_role (port, port->driver_data, role);if (ret)return ret;@@ -688,7 +720,7 @@ static ssize_t current_power_role_store(struct device *dev,return -EOPNOTSUPP ; } -if (!port->cap->pr_swap) { +if (!port->cap->pr_set) {dev_warn (dev,"power role swapping not supported\n" );return -EOPNOTSUPP ; }@@ -705,10 +737,7 @@ static ssize_t current_power_role_store(struct device *dev,else return -EINVAL ; -if (port->pwr_role == role || !port->partner) -return size; - - ret = port->cap->pr_swap (port); + ret = port->cap->pr_set (port, port->driver_data, role);if (ret)return ret;@@ -762,6 +791,54 @@ static ssize_t power_operation_mode_show(struct device *dev, }static DEVICE_ATTR_RO (power_operation_mode); +static ssize_t current_vconn_role_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t size) +{ +struct typec_port *port =to_typec_port (dev); +enum typec_pwr_role role; +int ret; + +if (!port->cap->usb_pd) { +dev_dbg (dev,"vconn swap only supported with USB PD\n" ); +return -EOPNOTSUPP ; + } + +if (!port->cap->vconn_set) { +dev_warn (dev,"vconn swapping not supported\n" ); +return -EOPNOTSUPP ; + } + +if (!strncmp (buf,"source" ,6 )) + role =TYPEC_PWR_SOURCE ; +else if (!strncmp (buf,"sink" ,4 )) + role =TYPEC_PWR_SINK ; +else +return -EINVAL ; + + ret = port->cap->vconn_set (port, port->driver_data, role); +if (ret) +return ret; + +return size; +} + +static ssize_t current_vconn_role_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct typec_port *port =to_typec_port (dev); + +switch (port->vconn_role) { +case TYPEC_PWR_SOURCE : +return sprintf (buf,"source\n" ); +case TYPEC_PWR_SINK : +return sprintf (buf,"sink\n" ); +default : +return sprintf (buf,"unknown\n" ); + }; +} +static DEVICE_ATTR_RW (current_vconn_role); +static ssize_t supports_audio_accessory_show (struct device *dev,struct device_attribute *attr,char *buf)@@ -795,6 +872,7 @@ static DEVICE_ATTR_RO(supports_usb_power_delivery);static struct attribute *typec_attrs[] = { &dev_attr_current_data_role.attr, &dev_attr_current_power_role.attr, + &dev_attr_current_vconn_role.attr, &dev_attr_current_usb_data_role.attr, &dev_attr_power_operation_mode.attr, &dev_attr_supported_data_roles.attr,@@ -862,7 +940,8 @@ static struct device_type typec_port_dev_type = { };struct typec_port *typec_register_port (struct device *dev, -struct typec_capability *cap) +struct typec_capability *cap, +void *driver_data) {struct typec_port *port;int ret;@@ -880,6 +959,7 @@ struct typec_port *typec_register_port(struct device *dev, port->id = id; port->cap = cap; + port->driver_data = driver_data; port->dev.type = &typec_port_dev_type; port->dev.class = &typec_class; port->dev.parent = dev;@@ -888,6 +968,8 @@ struct typec_port *typec_register_port(struct device *dev, port->fixed_role = port->cap->role; +typec_init_roles (port); + ret =device_register (&port->dev);if (ret) {ida_simple_remove (&typec_index_ida, id);include/linux/usb/typec.h +17
-9@@ -168,9 +168,9 @@ struct typec_partner {* @audio_accessory: Audio Accessory Adapter Mode support * @debug_accessory: Debug Accessory Mode support * @fix_role: Set a fixed data role for DRP port -* @dr_swap: Data Role Swap support -* @pr_swap: Power Role Swap support -* @vconn_swap: VCONN Swap support +* @dr_set: Set Data Role +* @pr_set: Set Power Role +* @vconn_set: Set VCONN Role * @activate_mode: Enter/exit given Alternate Mode * * Static capabilities of a single USB Type-C port. @@ -182,14 +182,14 @@ struct typec_capability { unsigned int audio_accessory:1; unsigned int debug_accessory:1; -int (*fix_role)(struct typec_port *, +int (*fix_role)(struct typec_port *,void *,enum typec_data_role ); -int (*dr_swap)(struct typec_port *); -int (*pr_swap)(struct typec_port *); -int (*vconn_swap)(struct typec_port *); +int (*dr_set)(struct typec_port *,void *,enum typec_usb_role ); +int (*pr_set)(struct typec_port *,void *,enum typec_pwr_role ); +int (*vconn_set)(struct typec_port *,void *,enum typec_pwr_role ); -int (*activate_mode)(struct typec_altmode *, +int (*activate_mode)(struct typec_altmode *,void *,int mode,int activate); };@@ -217,7 +217,8 @@ struct typec_connection { };struct typec_port *typec_register_port (struct device *dev, -struct typec_capability *cap); +struct typec_capability *cap, +void *driver_data);void typec_unregister_port (struct typec_port *port);int typec_connect (struct typec_port *port,struct typec_connection *con);@@ -227,4 +228,11 @@ void typec_disconnect(struct typec_port *port);struct device *typec_port2dev (struct typec_port *port);struct typec_port *typec_dev2port (struct device *dev); +/* Callbacks from driver */ + +void typec_set_usb_role (struct typec_port *,enum typec_usb_role ); +void typec_set_pwr_role (struct typec_port *,enum typec_pwr_role ); +void typec_set_vconn_role (struct typec_port *,enum typec_pwr_role ); +void typec_set_pwr_opmode (struct typec_port *,enum typec_pwr_opmode ); +#endif /* __LINUX_USB_TYPEC_H */ Signature · 1 line
2.5.0
Signature · 1 line
heikki
Re: [RFC PATCH] usb: typec: Various API updates and fixes
Quoted 2 lines · Heikki Krogerus
Hi,
[ ... ]
Quoted 11 lines
Quoted 8 lines
---
This patch applies on top of '[RFC PATCHv2] usb: USB Type-C Connector Class' from Heikki Krogerus. It provided the changes I made to get the code operational.drivers/usb/type-c/typec.c | 134 ++++++++++++++++++++++++++++++++++++--------- include/linux/usb/typec.h | 26 ++++++--- 2 files changed, 125 insertions(+), 35 deletions(-)Thanks Guenter. After a quick glance looks good to me.
My pleasure.
Quoted 6 lines
I think I'll create a development branch to my github tree for this class and add this on top of the original v2 patch as is. Just to have some history for as long we develop this thing. Though I'm not sure how useful it is in this case. I think we need to put this together fast. I'm thinking we need to target v4.8 with this.
Yes, agreed.
Quoted 2 lines
I'll merge this into any case to v3, and I'll send on Monday.
Sounds good.
Couple of additional comments.
I don't really know what to do with the 'desc' field in struct typec_mode for modes received from the partner. I wonder if it makes sense to display it for partner modes.
Also, there is currently no attribute to show the partner identity (data received from the Discover Identity command). Would it make sense to add an 'identity' attribute to the partner device (plus an associated API function to set it) ?
Thanks,
Guenter
Heikki Krogerus
maintainerRe: [RFC PATCH] usb: typec: Various API updates and fixes
Hi guys,
Quoted 10 lines · Guenter Roeck
Quoted 2 lines · Heikki Krogerus
I'll merge this into any case to v3, and I'll send on Monday.
Sounds good.
Couple of additional comments.
I don't really know what to do with the 'desc' field in struct
typec_modefor modes received from the partner. I wonder if it makes sense to display it for partner modes.
The idea comes straight from Billboard class where every mode has an index to an _optional_ string. Those desc should ultimately come from the altmode bus driver, and I think never from the port drivers.
Quoted 4 lines
Also, there is currently no attribute to show the partner identity (data received from the Discover Identity command). Would it make sense to add an 'identity' attribute to the partner device (plus an associated API function to set it) ?
The problem is that we can only use it when the partner and our port are both PD capable. Details about PDUSB devices that are attached are out side the scope of this interface IMO, and need to be in any case handled in USB core by using the PD Class specific descriptors etc., and possible with the help of the future PD stack that you are working on. It's an other task. So this interface IMO should expose only the Type-C specific details about the ports and partners. How about if we just add an attribute "usb_communication_capable" for the partners? That is something that we should be able to always determine, even without USB PD.
Thanks,
Signature · 1 line
heikki
Heikki Krogerus
maintainerHi guys,
I'm attaching a diff instead of full v3. I'm not yet adding attributes for the reset and cable_reset. I still don't understand what is the case where the userspace would need to be able to tricker reset? Why isn't it enough for the userspace to be able to enter/exit modes? Oliver! Can you please comment?
Guenter, I removed the driver_data you proposed and changed the API so that the struct typec_capability is passed to the function pointers instead of struct typec_port. The driver_data pointer felt a bit clumsy to me, as it was something extra that always had to be passed to every function. Let me know if it's not OK for you.
I also made a change to the partner devices so that they always have the port as their parent. That will have an effect on the location where the partner device is exposed in sysfs (so now always under the port). And because of that, I would like to get an OK from you guys.
I'm a bit concerned about the current API for adding the alternate modes. Since we are passing the parent for an alternate mode as struct device, it makes it possible for the caller to place it into some wrong place. But I guess we can change the API even later.
We also need to decide how the alternate modes a port support are exposed to the userspace. Do we just assume the port drivers will create them as devices under the port device itself, just like alternate modes of partners and cable plugs are exposed under the partners and cable plugs? That works for me, but again, the class does not have any effect on that, and it will be just a guideline. Maybe we can add some kind of helpers and force the port drivers to use them.
And finally, mostly as a reminder for myself. I didn't yet add attributes for Try.SRC/SNK. So can we make it something like "preferred_role" like I think you proposed Guenter? The "current_data_role" I'm dropping.
So to summarize. There are still open questions regarding the required attributes and attribute names and locations. Let's agree on those quickly and then we can polish the patch.
Thanks,
Signature · 1 line
heikki
drivers/usb/type-c/typec.c +9 -119
@@ -27,8 +27,6 @@ struct typec_port {struct typec_partner *partner;struct typec_cable *cable; -void *driver_data; - unsigned int connected:1;int n_altmode;
@@ -101,29 +99,10 @@ static int typec_add_partner(struct typec_port *port, struct typec_partner *partner) { struct device *dev = &partner->dev; -struct device *parent;int ret; -/* -* REVISIT: Maybe it would be better to make the port always as the -* parent of the partner? Or not even that. Would it be enough to just -* create the symlink to the partner like we do below in any case? -*/ -if (port->cable) { -if (port->cable->active) { -if (port->cable->sop_pp_controller) - parent = &port->cable->plug[1 ].dev; -else - parent = &port->cable->plug[0 ].dev; - }else { - parent = &port->cable->dev; - } - }else { - parent = &port->dev; - } - dev->class = &typec_class; - dev->parent = parent; + dev->parent = &port->dev; dev->type = &typec_partner_dev_type;dev_set_name (dev,"%s-partner" ,dev_name (&port->dev));
@@ -133,18 +112,6 @@ typec_add_partner(struct typec_port *port, struct typec_partner *partner)return ret; } - ret =typec_register_altmodes (dev, partner->alt_modes); -if (ret) { -device_unregister (dev); -return ret; - } - -/* REVISIT: Creating symlink for the port device for now. */ - ret =sysfs_create_link (&port->dev.kobj, &dev->kobj,"partner" ); -if (ret) -dev_WARN (&port->dev,"failed to create link to %s (%d)\n" , -dev_name (dev), ret); - port->partner = partner;return 0 ; }
@@ -184,12 +151,6 @@ typec_add_plug(struct typec_port *port, struct typec_plug *plug)return ret; } - ret =typec_register_altmodes (dev, plug->alt_modes); -if (ret) { -device_unregister (dev); -return ret; - } -/* REVISIT: Is this useful? */ ret =sysfs_create_link (&port->dev.kobj, &dev->kobj, name);if (ret)
@@ -278,7 +239,6 @@ static int typec_add_cable(struct typec_port *port, struct typec_cable *cable)int ret; dev->class = &typec_class; -/* REVISIT: We could have just the symlink also for the cable. */ dev->parent = &port->dev; dev->type = &typec_cable_dev_type;dev_set_name (dev,"%s-cable" ,dev_name (&port->dev));
@@ -631,7 +591,7 @@ current_usb_data_role_store(struct device *dev, struct device_attribute *attr,else return -EINVAL ; - ret = port->cap->dr_set (port, port->driver_data, role); + ret = port->cap->dr_set (port->cap, role);if (ret)return ret;
@@ -667,46 +627,6 @@ static ssize_t supported_data_roles_show(struct device *dev, }static DEVICE_ATTR_RO (supported_data_roles); -static ssize_t -current_data_role_store (struct device *dev,struct device_attribute *attr, -const char *buf,size_t size) -{ -struct typec_port *port =to_typec_port (dev); -enum typec_data_role role; -int ret; - -if (port->cap->role !=TYPEC_PORT_DRP ) -return -EOPNOTSUPP ; - -if (!port->cap->fix_role) -return -EOPNOTSUPP ; - -if (!strcmp (buf,"DFP" )) - role =TYPEC_PORT_DFP ; -else if (!strcmp (buf,"UFP" )) - role =TYPEC_PORT_UFP ; -else if (!strcmp (buf,"DRP" )) - role =TYPEC_PORT_DRP ; -else -return -EINVAL ; - - ret = port->cap->fix_role (port, port->driver_data, role); -if (ret) -return ret; - -return size; -} - -static ssize_t -current_data_role_show (struct device *dev,struct device_attribute *attr, -char *buf) -{ -struct typec_port *port =to_typec_port (dev); - -return sprintf (buf,"%s\n" , typec_data_roles[port->fixed_role]); -} -static DEVICE_ATTR_RW (current_data_role); -static ssize_t current_power_role_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t size)
@@ -737,7 +657,7 @@ static ssize_t current_power_role_store(struct device *dev,else return -EINVAL ; - ret = port->cap->pr_set (port, port->driver_data, role); + ret = port->cap->pr_set (port->cap, role);if (ret)return ret;
@@ -816,7 +736,7 @@ static ssize_t current_vconn_role_store(struct device *dev,else return -EINVAL ; - ret = port->cap->vconn_set (port, port->driver_data, role); + ret = port->cap->vconn_set (port->cap, role);if (ret)return ret;
@@ -870,7 +790,6 @@ static ssize_t supports_usb_power_delivery_show(struct device *dev,static DEVICE_ATTR_RO (supports_usb_power_delivery);static struct attribute *typec_attrs[] = { - &dev_attr_current_data_role.attr, &dev_attr_current_power_role.attr, &dev_attr_current_vconn_role.attr, &dev_attr_current_usb_data_role.attr,
@@ -902,6 +821,10 @@ static struct attribute *altmode_attrs[] = { NULL, }; +/* +* FIXME: Now this group is useless, but is there any use for the +* number_of_alternate_modes attribute? +*/ static const struct attribute_group altmode_group = { .name ="supported_alternate_modes" , .attrs = altmode_attrs,
@@ -940,8 +863,7 @@ static struct device_type typec_port_dev_type = { };struct typec_port *typec_register_port (struct device *dev, -struct typec_capability *cap, -void *driver_data) +const struct typec_capability *cap) {struct typec_port *port;int ret;
@@ -959,7 +881,6 @@ struct typec_port *typec_register_port(struct device *dev, port->id = id; port->cap = cap; - port->driver_data = driver_data; port->dev.type = &typec_port_dev_type; port->dev.class = &typec_class; port->dev.parent = dev;
@@ -978,28 +899,6 @@ struct typec_port *typec_register_port(struct device *dev,return ERR_PTR (ret); } -/* -* The alternate modes that the port supports must be created before -* registering the port. They are just linked to the port here. -*/ -if (cap->alt_modes) { -struct typec_altmode *alt; - -for (alt = cap->alt_modes; alt->svid; alt++) { - ret =sysfs_add_link_to_group (&port->dev.kobj, -"supported_alternate_modes" , - &alt->dev.kobj, - alt->name ? alt->name : -dev_name (&alt->dev)); -if (ret) { -dev_WARN (&port->dev, -"failed to create sysfs symlink\n" ); - }else { - port->n_altmode++; - } - } - } -return port; }EXPORT_SYMBOL_GPL (typec_register_port);
@@ -1009,15 +908,6 @@ void typec_unregister_port(struct typec_port *port)if (port->connected)typec_disconnect (port); -if (port->cap->alt_modes) { -struct typec_altmode *alt; - -for (alt = port->cap->alt_modes; alt->svid; alt++) -sysfs_remove_link_from_group (&port->dev.kobj, -"alternate_modes" , - alt->name ? alt->name : -dev_name (&alt->dev)); - }device_unregister (&port->dev); }EXPORT_SYMBOL_GPL (typec_unregister_port);
include/linux/usb/typec.h +10 -7
@@ -182,14 +182,18 @@ struct typec_capability { unsigned int audio_accessory:1; unsigned int debug_accessory:1; -int (*fix_role)(struct typec_port *,void *, +/* FIXME: change to prefer_role? */ +int (*fix_role)(const struct typec_capability *,enum typec_data_role ); -int (*dr_set)(struct typec_port *,void *,enum typec_usb_role ); -int (*pr_set)(struct typec_port *,void *,enum typec_pwr_role ); -int (*vconn_set)(struct typec_port *,void *,enum typec_pwr_role ); +int (*dr_set)(const struct typec_capability *, +enum typec_usb_role ); +int (*pr_set)(const struct typec_capability *, +enum typec_pwr_role ); +int (*vconn_set)(const struct typec_capability *, +enum typec_pwr_role ); -int (*activate_mode)(struct typec_altmode *,void *, +int (*activate_mode)(struct typec_altmode *,int mode,int activate); };
@@ -217,8 +221,7 @@ struct typec_connection { };struct typec_port *typec_register_port (struct device *dev, -struct typec_capability *cap, -void *driver_data); +const struct typec_capability *cap);void typec_unregister_port (struct typec_port *port);int typec_connect (struct typec_port *port,struct typec_connection *con);
Quoted 7 lines · Heikki Krogerus
Hi guys,
I'm attaching a diff instead of full v3. I'm not yet adding attributes for the reset and
cable_reset. I still don't understand what is the case where the userspace would need to be able to tricker reset? Why isn't it enough for the userspace to be able to enter/exit modes? Oliver! Can you please comment?
1. Because we need error handling.
Devices crash. Cables will crash. We will get out of sync. You never put yourself in a place where you cannot handle an IO error.
2. Because it is in the spec. We do not second guess the spec. We implement it.
Quoted 4 lines
I also made a change to the partner devices so that they always have the port as their parent. That will have an effect on the location where the partner device is exposed in sysfs (so now always under the port). And because of that, I would like to get an OK from you guys.
It is not very important. i am fine with it.
Quoted 5 lines
I'm a bit concerned about the current API for adding the alternate modes. Since we are passing the parent for an alternate mode as struct device, it makes it possible for the caller to place it into some wrong place. But I guess we can change the API even later.
Quoted 8 lines
We also need to decide how the alternate modes a port support are exposed to the userspace. Do we just assume the port drivers will create them as devices under the port device itself, just like alternate modes of partners and cable plugs are exposed under the partners and cable plugs? That works for me, but again, the class does not have any effect on that, and it will be just a guideline. Maybe we can add some kind of helpers and force the port drivers to use them.
What are the alternatives?
Quoted 4 lines
And finally, mostly as a reminder for myself. I didn't yet add attributes for Try.SRC/SNK. So can we make it something like "
preferred_role" like I think you proposed Guenter? The "current_data_role" I'm dropping.
That sounds good.
Regards
Oliver
Heikki Krogerus
maintainerHi Oliver,
Quoted 9 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Hi guys,
I'm attaching a diff instead of full v3. I'm not yet adding attributes for the reset and
cable_reset. I still don't understand what is the case where the userspace would need to be able to tricker reset? Why isn't it enough for the userspace to be able to enter/exit modes? Oliver! Can you please comment?
Quoted 6 lines
1. Because we need error handling.
Devices crash. Cables will crash. We will get out of sync. You never put yourself in a place where you cannot handle an IO error.
2. Because it is in the spec. We do not second guess the spec. We implement it.
Error conditions and crashes are the responsibility of the USB PD stack, not userspace. In those cases the stack can not wait for a command from the userspace. So for example if a timer like NoResponseTimer times out, the stack an its state machines will have to take care of the reset quite independently.
If you get out of sync with an alternate mode, you reset that specific alternate mode by exiting and re-entering it, and you do not reset the entire PD connection, port, partner or cable.
The resets from userspace would be purely unsolicited. What would the cases where we would need to tricker a reset like that?
I want to be careful with exposing reset to userspace. Reset in USB PD is not just an IO related thing. When you tricker a reset with USB PD, even if it's a soft reset, it may lead into hard reset, which may potentially lead into sudden voltage and current drop, which may lead into the entire system crashing. We really need to understand the cases where it would be necessary to tricker a reset from userspace. Right now I don't see any.
Quoted 21 lines
Quoted 4 lines
I also made a change to the partner devices so that they always have the port as their parent. That will have an effect on the location where the partner device is exposed in sysfs (so now always under the port). And because of that, I would like to get an OK from you guys.
It is not very important. i am fine with it.
Quoted 5 lines
I'm a bit concerned about the current API for adding the alternate modes. Since we are passing the parent for an alternate mode as struct device, it makes it possible for the caller to place it into some wrong place. But I guess we can change the API even later.
Quoted 8 lines
We also need to decide how the alternate modes a port support are exposed to the userspace. Do we just assume the port drivers will create them as devices under the port device itself, just like alternate modes of partners and cable plugs are exposed under the partners and cable plugs? That works for me, but again, the class does not have any effect on that, and it will be just a guideline. Maybe we can add some kind of helpers and force the port drivers to use them.
Quoted 1 line
What are the alternatives?
Can we make a group for them under the port device somehow? Like the supported_alternate_modes I proposed. I guess it's not possible to add devices to a specific group in sysfs. And would it even be useful.
Thanks,
Signature · 1 line
heikki
Quoted 19 lines · Heikki Krogerus
Hi Oliver,
Quoted 9 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Hi guys,
I'm attaching a diff instead of full v3. I'm not yet adding attributes for the reset and
cable_reset. I still don't understand what is the case where the userspace would need to be able to tricker reset? Why isn't it enough for the userspace to be able to enter/exit modes? Oliver! Can you please comment?Quoted 6 lines
1. Because we need error handling.
Devices crash. Cables will crash. We will get out of sync. You never put yourself in a place where you cannot handle an IO error.
2. Because it is in the spec. We do not second guess the spec. We implement it.
Quoted 2 lines
Error conditions and crashes are the responsibility of the USB PD stack, not userspace. In those cases the stack can not wait for a
Those are not exclusive conditions.
Quoted 3 lines
command from the userspace. So for example if a timer like NoResponseTimer times out, the stack an its state machines will have to take care of the reset quite independently.
Yes. But somebody needs to handle high level errors.
Quoted 3 lines
If you get out of sync with an alternate mode, you reset that specific alternate mode by exiting and re-entering it, and you do not reset the entire PD connection, port, partner or cable.
That would be the first step. If that doesn't work you will at that point either give up or use the next largest hammer.
In principle you could do that in kernel space, but that implies that the kernel can detect all failures. That is unlikely.
Quoted 10 lines
The resets from userspace would be purely unsolicited. What would the cases where we would need to tricker a reset like that?
I want to be careful with exposing reset to userspace. Reset in USB PD is not just an IO related thing. When you tricker a reset with USB PD, even if it's a soft reset, it may lead into hard reset, which may potentially lead into sudden voltage and current drop, which may lead into the entire system crashing. We really need to understand the cases where it would be necessary to tricker a reset from userspace. Right now I don't see any.
User space can call reboot. Actually that does not help. Reset is an operation that is intended for error handling. If all else fails, we will need to use it.
Its bad consequences apply whether you trigger this from kernel or user space. In fact, an operation that may potentially crash the system should involve user space.
[..]
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
We also need to decide how the alternate modes a port support are exposed to the userspace. Do we just assume the port drivers will create them as devices under the port device itself, just like alternate modes of partners and cable plugs are exposed under the partners and cable plugs? That works for me, but again, the class does not have any effect on that, and it will be just a guideline. Maybe we can add some kind of helpers and force the port drivers to use them.
Quoted 5 lines
Quoted 1 line
What are the alternatives?
Can we make a group for them under the port device somehow? Like the
supported_alternate_modesI proposed. I guess it's not possible to add devices to a specific group in sysfs. And would it even be useful.
Please explain. It is not clear to me what you are proposing here.
Regards
Oliver
Heikki Krogerus
maintainerQuoted 31 lines · Oliver Neukum
Quoted 19 lines · Heikki Krogerus
Hi Oliver,
Quoted 9 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Hi guys,
I'm attaching a diff instead of full v3. I'm not yet adding attributes for the reset and
cable_reset. I still don't understand what is the case where the userspace would need to be able to tricker reset? Why isn't it enough for the userspace to be able to enter/exit modes? Oliver! Can you please comment?Quoted 6 lines
1. Because we need error handling.
Devices crash. Cables will crash. We will get out of sync. You never put yourself in a place where you cannot handle an IO error.
2. Because it is in the spec. We do not second guess the spec. We implement it.Quoted 2 lines
Error conditions and crashes are the responsibility of the USB PD stack, not userspace. In those cases the stack can not wait for a
Those are not exclusive conditions.
Quoted 3 lines
command from the userspace. So for example if a timer like NoResponseTimer times out, the stack an its state machines will have to take care of the reset quite independently.
Yes. But somebody needs to handle high level errors.
Quoted 8 lines
Quoted 3 lines
If you get out of sync with an alternate mode, you reset that specific alternate mode by exiting and re-entering it, and you do not reset the entire PD connection, port, partner or cable.
That would be the first step. If that doesn't work you will at that point either give up or use the next largest hammer.
In principle you could do that in kernel space, but that implies that the kernel can detect all failures. That is unlikely.
Any PD communication failures the kernel has to be able to detect, so I guess you mean failures with the alternate modes themselves, right?
In that case, surely exiting the mode is enough to "reset" it? When it is re-entered, it has to be completely re-configured in any case. I don't see how resetting the whole port or cable would guarantee that a mode would become any more functional in case of failures? It will however make also the other active modes to de-activate even if they are functioning fine.
Quoted 27 lines
Quoted 10 lines
The resets from userspace would be purely unsolicited. What would the cases where we would need to tricker a reset like that?
I want to be careful with exposing reset to userspace. Reset in USB PD is not just an IO related thing. When you tricker a reset with USB PD, even if it's a soft reset, it may lead into hard reset, which may potentially lead into sudden voltage and current drop, which may lead into the entire system crashing. We really need to understand the cases where it would be necessary to tricker a reset from userspace. Right now I don't see any.
User space can call reboot. Actually that does not help. Reset is an operation that is intended for error handling. If all else fails, we will need to use it.
Its bad consequences apply whether you trigger this from kernel or user space. In fact, an operation that may potentially crash the system should involve user space.Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
We also need to decide how the alternate modes a port support are exposed to the userspace. Do we just assume the port drivers will create them as devices under the port device itself, just like alternate modes of partners and cable plugs are exposed under the partners and cable plugs? That works for me, but again, the class does not have any effect on that, and it will be just a guideline. Maybe we can add some kind of helpers and force the port drivers to use them.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
What are the alternatives?
Can we make a group for them under the port device somehow? Like the
supported_alternate_modesI proposed. I guess it's not possible to add devices to a specific group in sysfs. And would it even be useful.Please explain. It is not clear to me what you are proposing here.
So is it possible to have a folder in sysfs for the alternate modes a port supports?
So instead of:
/sysfs/class/type-c/usbc0/svid:xxx1/
/sysfs/class/type-c/usbc0/svid:xxx2/
/sysfs/class/type-c/usbc0/svid:xxx3/
...We would have something like:
/sysfs/class/type-c/usbc0/supported_alternate_modes/svid:xxx1/
/sysfs/class/type-c/usbc0/supported_alternate_modes/svid:xxx2/
/sysfs/class/type-c/usbc0/supported_alternate_modes/svid:xxx3/
...Thanks,
Signature · 1 line
heikki
Heikki Krogerus
maintainerQuoted 44 lines · Heikki Krogerus
Quoted 31 lines · Oliver Neukum
Quoted 19 lines · Heikki Krogerus
Hi Oliver,
Quoted 9 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Hi guys,
I'm attaching a diff instead of full v3. I'm not yet adding attributes for the reset and
cable_reset. I still don't understand what is the case where the userspace would need to be able to tricker reset? Why isn't it enough for the userspace to be able to enter/exit modes? Oliver! Can you please comment?Quoted 6 lines
1. Because we need error handling.
Devices crash. Cables will crash. We will get out of sync. You never put yourself in a place where you cannot handle an IO error.
2. Because it is in the spec. We do not second guess the spec. We implement it.Quoted 2 lines
Error conditions and crashes are the responsibility of the USB PD stack, not userspace. In those cases the stack can not wait for a
Those are not exclusive conditions.
Quoted 3 lines
command from the userspace. So for example if a timer like NoResponseTimer times out, the stack an its state machines will have to take care of the reset quite independently.
Yes. But somebody needs to handle high level errors.
Quoted 8 lines
Quoted 3 lines
If you get out of sync with an alternate mode, you reset that specific alternate mode by exiting and re-entering it, and you do not reset the entire PD connection, port, partner or cable.
That would be the first step. If that doesn't work you will at that point either give up or use the next largest hammer.
In principle you could do that in kernel space, but that implies that the kernel can detect all failures. That is unlikely.Any PD communication failures the kernel has to be able to detect, so I guess you mean failures with the alternate modes themselves, right?
Quoted 6 lines
In that case, surely exiting the mode is enough to "reset" it? When it is re-entered, it has to be completely re-configured in any case. I don't see how resetting the whole port or cable would guarantee that a mode would become any more functional in case of failures? It will however make also the other active modes to de-activate even if they are functioning fine.
Forget about it, I'll just add the reset attributes. I'm still not clear about their usefulness, but instead they will just create a small risk, but I can live with that.
Cheers,
Signature · 1 line
heikki
Quoted 52 lines · Heikki Krogerus
Quoted 44 lines · Heikki Krogerus
Quoted 31 lines · Oliver Neukum
Quoted 19 lines · Heikki Krogerus
Hi Oliver,
Quoted 9 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Hi guys,
I'm attaching a diff instead of full v3. I'm not yet adding attributes for the reset and
cable_reset. I still don't understand what is the case where the userspace would need to be able to tricker reset? Why isn't it enough for the userspace to be able to enter/exit modes? Oliver! Can you please comment?Quoted 6 lines
1. Because we need error handling.
Devices crash. Cables will crash. We will get out of sync. You never put yourself in a place where you cannot handle an IO error.
2. Because it is in the spec. We do not second guess the spec. We implement it.Quoted 2 lines
Error conditions and crashes are the responsibility of the USB PD stack, not userspace. In those cases the stack can not wait for a
Those are not exclusive conditions.
Quoted 3 lines
command from the userspace. So for example if a timer like NoResponseTimer times out, the stack an its state machines will have to take care of the reset quite independently.
Yes. But somebody needs to handle high level errors.
Quoted 8 lines
Quoted 3 lines
If you get out of sync with an alternate mode, you reset that specific alternate mode by exiting and re-entering it, and you do not reset the entire PD connection, port, partner or cable.
That would be the first step. If that doesn't work you will at that point either give up or use the next largest hammer.
In principle you could do that in kernel space, but that implies that the kernel can detect all failures. That is unlikely.Any PD communication failures the kernel has to be able to detect, so I guess you mean failures with the alternate modes themselves, right?
Quoted 6 lines
In that case, surely exiting the mode is enough to "reset" it? When it is re-entered, it has to be completely re-configured in any case. I don't see how resetting the whole port or cable would guarantee that a mode would become any more functional in case of failures? It will however make also the other active modes to de-activate even if they are functioning fine.
Quoted 4 lines
Forget about it, I'll just add the reset attributes. I'm still not clear about their usefulness, but instead they will just create a small risk, but I can live with that.
Given my experience over the last few weeks, I think the added risk may not just be small, and I think the added benefit is questionable. Reset handling is not well implemented in all devices, and manually triggered resets in an unexpected state may make the situation worse.
Can you make it optional ? I may choose not to support it to avoid the risk.
Thanks,
Guenter
Heikki Krogerus
maintainerQuoted 58 lines · Guenter Roeck
Quoted 52 lines · Heikki Krogerus
Quoted 44 lines · Heikki Krogerus
Quoted 31 lines · Oliver Neukum
Quoted 19 lines · Heikki Krogerus
Hi Oliver,
Quoted 9 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Hi guys,
I'm attaching a diff instead of full v3. I'm not yet adding attributes for the reset and
cable_reset. I still don't understand what is the case where the userspace would need to be able to tricker reset? Why isn't it enough for the userspace to be able to enter/exit modes? Oliver! Can you please comment?Quoted 6 lines
1. Because we need error handling.
Devices crash. Cables will crash. We will get out of sync. You never put yourself in a place where you cannot handle an IO error.
2. Because it is in the spec. We do not second guess the spec. We implement it.Quoted 2 lines
Error conditions and crashes are the responsibility of the USB PD stack, not userspace. In those cases the stack can not wait for a
Those are not exclusive conditions.
Quoted 3 lines
command from the userspace. So for example if a timer like NoResponseTimer times out, the stack an its state machines will have to take care of the reset quite independently.
Yes. But somebody needs to handle high level errors.
Quoted 8 lines
Quoted 3 lines
If you get out of sync with an alternate mode, you reset that specific alternate mode by exiting and re-entering it, and you do not reset the entire PD connection, port, partner or cable.
That would be the first step. If that doesn't work you will at that point either give up or use the next largest hammer.
In principle you could do that in kernel space, but that implies that the kernel can detect all failures. That is unlikely.Any PD communication failures the kernel has to be able to detect, so I guess you mean failures with the alternate modes themselves, right?
Quoted 6 lines
In that case, surely exiting the mode is enough to "reset" it? When it is re-entered, it has to be completely re-configured in any case. I don't see how resetting the whole port or cable would guarantee that a mode would become any more functional in case of failures? It will however make also the other active modes to de-activate even if they are functioning fine.
Quoted 4 lines
Forget about it, I'll just add the reset attributes. I'm still not clear about their usefulness, but instead they will just create a small risk, but I can live with that.
Quoted 7 lines
Given my experience over the last few weeks, I think the added risk may not just be small, and I think the added benefit is questionable. Reset handling is not well implemented in all devices, and manually triggered resets in an unexpected state may make the situation worse.
Can you make it optional ? I may choose not to support it to avoid the risk.
Maybe I gave up on this too hastily... I changing my mind about this, I'm not going to add them. Having them optional is not enough. It changes nothing when they are implemented. I think there is a change that we would actually end up having to remove the attributes, which would be really bad.
I think we can still add them later if they are still seen as necessity later on, tough I seriously doubt it. It would not be ideal, but adding an attribute should not really break anything, right? Removing would.
Thanks,
Signature · 1 line
heikki
Quoted 73 lines · Heikki Krogerus
Quoted 58 lines · Guenter Roeck
Quoted 52 lines · Heikki Krogerus
Quoted 44 lines · Heikki Krogerus
Quoted 31 lines · Oliver Neukum
Quoted 19 lines · Heikki Krogerus
Hi Oliver,
Quoted 9 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Hi guys,
I'm attaching a diff instead of full v3. I'm not yet adding attributes for the reset and
cable_reset. I still don't understand what is the case where the userspace would need to be able to tricker reset? Why isn't it enough for the userspace to be able to enter/exit modes? Oliver! Can you please comment?Quoted 6 lines
1. Because we need error handling.
Devices crash. Cables will crash. We will get out of sync. You never put yourself in a place where you cannot handle an IO error.
2. Because it is in the spec. We do not second guess the spec. We implement it.Quoted 2 lines
Error conditions and crashes are the responsibility of the USB PD stack, not userspace. In those cases the stack can not wait for a
Those are not exclusive conditions.
Quoted 3 lines
command from the userspace. So for example if a timer like NoResponseTimer times out, the stack an its state machines will have to take care of the reset quite independently.
Yes. But somebody needs to handle high level errors.
Quoted 8 lines
Quoted 3 lines
If you get out of sync with an alternate mode, you reset that specific alternate mode by exiting and re-entering it, and you do not reset the entire PD connection, port, partner or cable.
That would be the first step. If that doesn't work you will at that point either give up or use the next largest hammer.
In principle you could do that in kernel space, but that implies that the kernel can detect all failures. That is unlikely.Any PD communication failures the kernel has to be able to detect, so I guess you mean failures with the alternate modes themselves, right?
Quoted 6 lines
In that case, surely exiting the mode is enough to "reset" it? When it is re-entered, it has to be completely re-configured in any case. I don't see how resetting the whole port or cable would guarantee that a mode would become any more functional in case of failures? It will however make also the other active modes to de-activate even if they are functioning fine.
Quoted 4 lines
Forget about it, I'll just add the reset attributes. I'm still not clear about their usefulness, but instead they will just create a small risk, but I can live with that.
Quoted 7 lines
Given my experience over the last few weeks, I think the added risk may not just be small, and I think the added benefit is questionable. Reset handling is not well implemented in all devices, and manually triggered resets in an unexpected state may make the situation worse.
Can you make it optional ? I may choose not to support it to avoid the risk.
Maybe I gave up on this too hastily... I changing my mind about this, I'm not going to add them. Having them optional is not enough. It changes nothing when they are implemented. I think there is a change that we would actually end up having to remove the attributes, which would be really bad.
Quoted 4 lines
I think we can still add them later if they are still seen as necessity later on, tough I seriously doubt it. It would not be ideal, but adding an attribute should not really break anything, right? Removing would.
That is true. So let's leave it out for now. I still think sane error handling will require it eventually, but that will be in the future.
Regards
Oliver
Quoted 4 lines · Heikki Krogerus
I think we can still add them later if they are still seen as necessity later on, tough I seriously doubt it. It would not be ideal, but adding an attribute should not really break anything, right? Removing would.
However, how do we learn that the other side has triggered a reset?
Regards
Oliver
Quoted 8 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus
I think we can still add them later if they are still seen as necessity later on, tough I seriously doubt it. It would not be ideal, but adding an attribute should not really break anything, right? Removing would.
However, how do we learn that the other side has triggered a reset?
USB PD specification, section 6.8.2.2 (Modal Operation and Hard Reset):
A Hard Reset shall cause all Active Modes to be exited by both Port Partners and any Cable Plugs (see Section 6.4.4.3.4).
Section 6.4.4.3.4 (Enter Mode Command):
The following events shall also cause the Port Partners and Cable Plug(s) to exit all Active Modes:
- A PD Hard Reset
- The Port Partners or Cable Plug(s) are Detached
- A Cable Reset (only exits the Cable Plug’s Active Modes)
The class code would not explicitly learn about the reset, but it would be informed about the exited modes.
Guenter
Quoted 2 lines · Guenter Roeck
The class code would not explicitly learn about the reset, but it would be informed about the exited modes.
That has drawbacks
- it doesn't tell you what caused the mode to be left (if you UFP, it may be the regular command)
- it is a race against your own command
- it does not work if you are in basic USB mode
Regards
Oliver
Quoted 6 lines · Oliver Neukum
Quoted 2 lines · Guenter Roeck
The class code would not explicitly learn about the reset, but it would be informed about the exited modes.
That has drawbacks
Playing devils advocate a bit here
Quoted 2 lines
- it doesn't tell you what caused the mode to be left (if you UFP, it may be the regular command)
Does it matter ?
Quoted 1 line
- it is a race against your own command
It is my understanding that races have to be resolved by the drivers, since the typec code does not do any locking. This is quite similar to handling, say, a request to change the vconn source or to change the power role. Am I missing something ?
Quoted 2 lines
- it does not work if you are in basic USB mode
Would alternate modes be active in that case ?
Thanks,
Guenter
Quoted 8 lines · Guenter Roeck
Quoted 6 lines · Oliver Neukum
Quoted 2 lines · Guenter Roeck
The class code would not explicitly learn about the reset, but it would be informed about the exited modes.
That has drawbacks
Quoted 6 lines
Playing devils advocate a bit here
Quoted 2 lines
- it doesn't tell you what caused the mode to be left (if you UFP, it may be the regular command)
Does it matter ?
Potentially yes. Should you restore the last state when the mode is reentered? If it caused the other side to reset, probably not.
Quoted 6 lines
Quoted 1 line
- it is a race against your own command
It is my understanding that races have to be resolved by the drivers, since the typec code does not do any locking. This is quite similar to handling, say, a request to change the vconn source or to change the power role. Am I missing something ?
Yes. There is a fundamental race between Exit Mode and reset if you only report leaving a mode. Drivers can do nothing to prevent it unless reporting resets by themselves.
Quoted 3 lines
Quoted 2 lines
- it does not work if you are in basic USB mode
Would alternate modes be active in that case ?
No and that is the point. A reset happens, presumably because the other side saw an error condition and we just blindly continue because no Alternate Mode was left and our user space remains uninformed.
Regards
Oliver
Quoted 19 lines · Heikki Krogerus
Hi Oliver,
Quoted 9 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Hi guys,
I'm attaching a diff instead of full v3. I'm not yet adding attributes for the reset and
cable_reset. I still don't understand what is the case where the userspace would need to be able to tricker reset? Why isn't it enough for the userspace to be able to enter/exit modes? Oliver! Can you please comment?Quoted 6 lines
1. Because we need error handling.
Devices crash. Cables will crash. We will get out of sync. You never put yourself in a place where you cannot handle an IO error.
2. Because it is in the spec. We do not second guess the spec. We implement it.
Quoted 6 lines
Error conditions and crashes are the responsibility of the USB PD stack, not userspace. In those cases the stack can not wait for a command from the userspace. So for example if a timer like NoResponseTimer times out, the stack an its state machines will have to take care of the reset quite independently.
Agreed.
Quoted 10 lines
If you get out of sync with an alternate mode, you reset that specific alternate mode by exiting and re-entering it, and you do not reset the entire PD connection, port, partner or cable.
The resets from userspace would be purely unsolicited. What would the cases where we would need to tricker a reset like that?
I want to be careful with exposing reset to userspace. Reset in USB PD is not just an IO related thing. When you tricker a reset with USB PD, even if it's a soft reset, it may lead into hard reset, which may
It may also lead to and trigger error recovery, which is pretty much similar to physical disconnect and reconnect.
Quoted 5 lines
potentially lead into sudden voltage and current drop, which may lead into the entire system crashing. We really need to understand the cases where it would be necessary to tricker a reset from userspace. Right now I don't see any.
Me not either, really. Error conditions are notoriously difficult to handle. I can get devices with external power into a state where even error recovery doesn't bring the USB-PD connection back to operational mode - it is sometimes necessary to disconnect power. With that in mind, not only is a reset from user space risky, it may actually make the situation worse. That will hopefully change over time, as the protocol implementations stabilize, but right now I am very hesitant to add another variable into the picture - especially if the benefits are not clear.
Thanks,
Guenter
Quoted 8 lines · Heikki Krogerus
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
There's one thing we haven't touched upon yet. And I cannot really find an answer in the spec.
What do we do if we return from S4 or S3? I think we need to restore the ALternate Mode because our display may be running over that Alternate Mode.
If we want to support USB persist we also need to restore data role after S4.
Regards
Oliver
Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Heikki Krogerus
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
Quoted 9 lines
There's one thing we haven't touched upon yet. And I cannot really find an answer in the spec.
What do we do if we return from S4 or S3? I think we need to restore the ALternate Mode because our display may be running over that Alternate Mode.
If we want to support USB persist we also need to restore data role after S4.
I don't have an answer ... but another interesting question.
How do we distinguish between alternate modes supported by a host vs. alternate modes supported by a sink ? typec_capability includes a pointer to alternate modes supportedf by the connector, but it is not clear if those are alternate modes supported as host, or alternate modes supported as device, or alternate modes supported by both.
This doesn't matter much if only a fixed role is supported, but it does matter for dual role ports. A laptop will typically only support DisplayPort as host, for example.
Any idea ?
Thanks,
Guenter
Quoted 20 lines · Guenter Roeck
Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Heikki Krogerus
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
Quoted 9 lines
There's one thing we haven't touched upon yet. And I cannot really find an answer in the spec.
What do we do if we return from S4 or S3? I think we need to restore the ALternate Mode because our display may be running over that Alternate Mode.
If we want to support USB persist we also need to restore data role after S4.
Quoted 7 lines
I don't have an answer ... but another interesting question.
How do we distinguish between alternate modes supported by a host vs. alternate modes supported by a sink ?
typec_capabilityincludes a pointer to alternate modes supportedf by the connector, but it is not clear if those are alternate modes supported as host, or alternate modes supported as device, or alternate modes supported by both.
I was under the impression that this applies to the current role.
Quoted 5 lines
This doesn't matter much if only a fixed role is supported, but it does matter for dual role ports. A laptop will typically only support DisplayPort as host, for example.
Any idea ?
I would state the obvious that we need separate directories for that. And how do we express captive cables?
Regards
Oliver
Heikki Krogerus
maintainerQuoted 31 lines · Oliver Neukum
Quoted 20 lines · Guenter Roeck
Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Heikki Krogerus
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
Quoted 9 lines
There's one thing we haven't touched upon yet. And I cannot really find an answer in the spec.
What do we do if we return from S4 or S3? I think we need to restore the ALternate Mode because our display may be running over that Alternate Mode.
If we want to support USB persist we also need to restore data role after S4.Quoted 7 lines
I don't have an answer ... but another interesting question.
How do we distinguish between alternate modes supported by a host vs. alternate modes supported by a sink ?
typec_capabilityincludes a pointer to alternate modes supportedf by the connector, but it is not clear if those are alternate modes supported as host, or alternate modes supported as device, or alternate modes supported by both.I was under the impression that this applies to the current role.
Quoted 8 lines
Quoted 5 lines
This doesn't matter much if only a fixed role is supported, but it does matter for dual role ports. A laptop will typically only support DisplayPort as host, for example.
Any idea ?
I would state the obvious that we need separate directories for that. And how do we express captive cables?
That means we can not present the alternate modes the ports support as devices, as then we would have potentially two devices presenting the same mode. Wish we could make those symlinks.. But perhaps we don't need to present the port alternate modes as devices in any case.
But there is an other problem. The alternate modes a port can support as host or device may be defined by the platform, but it can also be dictated by the alternate mode spec itself. Knowing about the platform is a problem for the port driver, but knowing about the individual alternate modes is not. Those will be problems for the alternate mode drivers in the end.
So the moment a port driver is expected to create the attributes (or populate the devices) that will present the alternate modes it supports, this thing will not always be clear to it.
I'm now wondering should we make it responsibility for the port drivers to generate those attributes that present the alternate modes they support after all?
Thanks,
Signature · 1 line
heikki
Heikki Krogerus
maintainerQuoted 28 lines · Guenter Roeck
Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Heikki Krogerus
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
Quoted 9 lines
There's one thing we haven't touched upon yet. And I cannot really find an answer in the spec.
What do we do if we return from S4 or S3? I think we need to restore the ALternate Mode because our display may be running over that Alternate Mode.
If we want to support USB persist we also need to restore data role after S4.I don't have an answer ... but another interesting question.
How do we distinguish between alternate modes supported by a host vs. alternate modes supported by a sink ?
typec_capabilityincludes a pointer to alternate modes supportedf by the connector, but it is not clear if those are alternate modes supported as host, or alternate modes supported as device, or alternate modes supported by both.
Quoted 3 lines
This doesn't matter much if only a fixed role is supported, but it does matter for dual role ports. A laptop will typically only support DisplayPort as host, for example.
The DP alternate mode spec actually separates the display role from Type-C role. A laptop most likely would only support the modes for display host roles, but if the port was DRP port then it would still do so in both Type-C roles.
So basically, even if the display was Type-C host, it would still work as a display when attached to the laptop.
Quoted 1 line
Any idea ?
I'm actually not sure this is a problem.
Thanks,
Signature · 1 line
heikki
Quoted 38 lines · Heikki Krogerus
Quoted 28 lines · Guenter Roeck
Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Heikki Krogerus
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
Quoted 9 lines
There's one thing we haven't touched upon yet. And I cannot really find an answer in the spec.
What do we do if we return from S4 or S3? I think we need to restore the ALternate Mode because our display may be running over that Alternate Mode.
If we want to support USB persist we also need to restore data role after S4.I don't have an answer ... but another interesting question.
How do we distinguish between alternate modes supported by a host vs. alternate modes supported by a sink ?
typec_capabilityincludes a pointer to alternate modes supportedf by the connector, but it is not clear if those are alternate modes supported as host, or alternate modes supported as device, or alternate modes supported by both.Quoted 3 lines
This doesn't matter much if only a fixed role is supported, but it does matter for dual role ports. A laptop will typically only support DisplayPort as host, for example.
The DP alternate mode spec actually separates the display role from Type-C role. A laptop most likely would only support the modes for display host roles, but if the port was DRP port then it would still do so in both Type-C roles.
Quoted 7 lines
So basically, even if the display was Type-C host, it would still work as a display when attached to the laptop.
Quoted 1 line
Any idea ?
I'm actually not sure this is a problem.
Yes, this was a bad example, since the DisplayPort mode vdo includes a flag indicating if the port supports source, sink, or both.
Let's use a different example:
Google devices (such as power adapters) have mode '1' for firmware upgrades. Obviously hosts will support that, but what should the host advertise if it is configured as sink ?
Maybe this is just my personal confusion, and there is no real problem. It might as well be that the Google mode VDO _should_ include a flag indicating if the port supports updating the partner, and/or if it supports being updated. For now I'll just assume that this is the case.
Something else, which goes back into the symlink question. If I create the alternate mode devices before calling typec_register_port(), the devices won't have a parent and don't show up in the class directory. You previously solved that with the symlink. I am trying to solve it in my current code by calling typec_register_altmodes() from typec_register_port() - primarily because I don't really want to duplicate all the device creation code in my driver.
In my test case, this gives me
/sys/class/type-c/usbc0/ usbc0.svid:18d1 usbc0.svid:18d1/mode0 usbc0.svid:18d1/mode0/vdo usbc0.svid:18d1/mode0/description usbc0.svid:18d1/mode0/active ... usbc0.svid:ff01 usbc0.svid:ff01/mode0/vdo usbc0.svid:ff01/mode0/description usbc0.svid:ff01/mode0/active
in addition to
/sys/class/type-c/usbc0/ usbc0-partner/usbc0-partner.svid:05ac usbc0-partner/usbc0-partner.svid:05ac/mode0 usbc0-partner/usbc0-partner.svid:05ac/mode0/vdo usbc0-partner/usbc0-partner.svid:05ac/mode0/description usbc0-partner/usbc0-partner.svid:05ac/mode0/active usbc0-partner/usbc0-partner.svid:05ac/mode1 usbc0-partner/usbc0-partner.svid:05ac/mode1/vdo usbc0-partner/usbc0-partner.svid:05ac/mode1/description usbc0-partner/usbc0-partner.svid:05ac/mode1/active ... usbc0-partner/usbc0-partner.svid:ff01 usbc0-partner/usbc0-partner.svid:ff01/mode0 usbc0-partner/usbc0-partner.svid:ff01/mode0/vdo usbc0-partner/usbc0-partner.svid:ff01/mode0/description usbc0-partner/usbc0-partner.svid:ff01/mode0/active
(when connecting the Apple adapter), which is exactly what I would expect to see.
Is this sensible ? Do we have a reason for expecting the alternate mode _devices_ to be created (without parent) when calling typec_register_port() ?
Thanks,
Guenter
Heikki Krogerus
maintainerHi,
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Heikki Krogerus
Quoted 28 lines · Guenter Roeck
Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Heikki Krogerus
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
Quoted 9 lines
There's one thing we haven't touched upon yet. And I cannot really find an answer in the spec.
What do we do if we return from S4 or S3? I think we need to restore the ALternate Mode because our display may be running over that Alternate Mode.
If we want to support USB persist we also need to restore data role after S4.I don't have an answer ... but another interesting question.
How do we distinguish between alternate modes supported by a host vs. alternate modes supported by a sink ?
typec_capabilityincludes a pointer to alternate modes supportedf by the connector, but it is not clear if those are alternate modes supported as host, or alternate modes supported as device, or alternate modes supported by both.Quoted 3 lines
This doesn't matter much if only a fixed role is supported, but it does matter for dual role ports. A laptop will typically only support DisplayPort as host, for example.
The DP alternate mode spec actually separates the display role from Type-C role. A laptop most likely would only support the modes for display host roles, but if the port was DRP port then it would still do so in both Type-C roles.
So basically, even if the display was Type-C host, it would still work as a display when attached to the laptop.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Any idea ?
I'm actually not sure this is a problem.
Yes, this was a bad example, since the DisplayPort mode vdo includes a flag indicating if the port supports source, sink, or both.
I meant that in case of DP alternate mode, there should not be a problem.
Quoted 9 lines
Let's use a different example:
Google devices (such as power adapters) have mode '1' for firmware upgrades. Obviously hosts will support that, but what should the host advertise if it is configured as sink ?Maybe this is just my personal confusion, and there is no real problem. It might as well be that the Google mode VDO _should_ include a flag indicating if the port supports updating the partner, and/or if it supports being updated. For now I'll just assume that this is the case.
Well, do you think we can rely on always being able to get this detail from VDO?
Quoted 38 lines
Something else, which goes back into the symlink question. If I create the alternate mode devices before calling
typec_register_port(), the devices won't have a parent and don't show up in the class directory. You previously solved that with the symlink. I am trying to solve it in my current code by callingtypec_register_altmodes()fromtypec_register_port()- primarily because I don't really want to duplicate all the device creation code in my driver.In my test case, this gives me
/sys/class/type-c/usbc0/ usbc0.svid:18d1 usbc0.svid:18d1/mode0 usbc0.svid:18d1/mode0/vdo usbc0.svid:18d1/mode0/description usbc0.svid:18d1/mode0/active ... usbc0.svid:ff01 usbc0.svid:ff01/mode0/vdo usbc0.svid:ff01/mode0/description usbc0.svid:ff01/mode0/activein addition to
/sys/class/type-c/usbc0/ usbc0-partner/usbc0-partner.svid:05ac usbc0-partner/usbc0-partner.svid:05ac/mode0 usbc0-partner/usbc0-partner.svid:05ac/mode0/vdo usbc0-partner/usbc0-partner.svid:05ac/mode0/description usbc0-partner/usbc0-partner.svid:05ac/mode0/active usbc0-partner/usbc0-partner.svid:05ac/mode1 usbc0-partner/usbc0-partner.svid:05ac/mode1/vdo usbc0-partner/usbc0-partner.svid:05ac/mode1/description usbc0-partner/usbc0-partner.svid:05ac/mode1/active ... usbc0-partner/usbc0-partner.svid:ff01 usbc0-partner/usbc0-partner.svid:ff01/mode0 usbc0-partner/usbc0-partner.svid:ff01/mode0/vdo usbc0-partner/usbc0-partner.svid:ff01/mode0/description usbc0-partner/usbc0-partner.svid:ff01/mode0/active
Quoted 4 lines
(when connecting the Apple adapter), which is exactly what I would expect to see.
Is this sensible ? Do we have a reason for expecting the alternate mode _devices_ to be created (without parent) when calling
typec_register_port()?
So if you would prefer that the class code takes care of creating the alternate modes when typec_register_port() is called, I'm fine with that too. Let's make it so.
Thanks,
Signature · 1 line
heikki
Quoted 60 lines · Heikki Krogerus
Hi,
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Heikki Krogerus
Quoted 28 lines · Guenter Roeck
Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Heikki Krogerus
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
Quoted 9 lines
There's one thing we haven't touched upon yet. And I cannot really find an answer in the spec.
What do we do if we return from S4 or S3? I think we need to restore the ALternate Mode because our display may be running over that Alternate Mode.
If we want to support USB persist we also need to restore data role after S4.I don't have an answer ... but another interesting question.
How do we distinguish between alternate modes supported by a host vs. alternate modes supported by a sink ?
typec_capabilityincludes a pointer to alternate modes supportedf by the connector, but it is not clear if those are alternate modes supported as host, or alternate modes supported as device, or alternate modes supported by both.Quoted 3 lines
This doesn't matter much if only a fixed role is supported, but it does matter for dual role ports. A laptop will typically only support DisplayPort as host, for example.
The DP alternate mode spec actually separates the display role from Type-C role. A laptop most likely would only support the modes for display host roles, but if the port was DRP port then it would still do so in both Type-C roles.
So basically, even if the display was Type-C host, it would still work as a display when attached to the laptop.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Any idea ?
I'm actually not sure this is a problem.
Yes, this was a bad example, since the DisplayPort mode vdo includes a flag indicating if the port supports source, sink, or both.
I meant that in case of DP alternate mode, there should not be a problem.
Quoted 5 lines
Let's use a different example:
Google devices (such as power adapters) have mode '1' for firmware upgrades. Obviously hosts will support that, but what should the host advertise if it is configured as sink ?
Quoted 8 lines
Quoted 4 lines
Maybe this is just my personal confusion, and there is no real problem. It might as well be that the Google mode VDO _should_ include a flag indicating if the port supports updating the partner, and/or if it supports being updated. For now I'll just assume that this is the case.
Well, do you think we can rely on always being able to get this detail from VDO?
Not really. Like in the Google case, one end will implement sending the firmware, the other end will implement receiving it and writing it to flash (or whatever). Which is which isn't currently made visible to user space. I suspect that other "intelligent" devices like Apple's multi-function adapter do the same, though obviously I don't really know what the two VDO modes do on the apple adapter.
I'll have to have some ABI to user space for the alternate mode, for example to send the firmware file to the kernel. I am not there yet, though, so I don't really know exactly how that will look like. Most likely it is going to be added sysfs attributes in the mode device (eg usbc0.svid:18d1/mode0/firmware).
Quoted 7 lines
Quoted 7 lines
Something else, which goes back into the symlink question. If I create the alternate mode devices before calling
typec_register_port(), the devices won't have a parent and don't show up in the class directory. You previously solved that with the symlink. I am trying to solve it in my current code by callingtypec_register_altmodes()fromtypec_register_port()- primarily because I don't really want to duplicate all the device creation code in my driver.
Quoted 12 lines
Quoted 12 lines
In my test case, this gives me
/sys/class/type-c/usbc0/ usbc0.svid:18d1 usbc0.svid:18d1/mode0 usbc0.svid:18d1/mode0/vdo usbc0.svid:18d1/mode0/description usbc0.svid:18d1/mode0/active ... usbc0.svid:ff01 usbc0.svid:ff01/mode0/vdo usbc0.svid:ff01/mode0/description usbc0.svid:ff01/mode0/active
Side note: I didn't provide a description/name for the modes, because that would result in something like usbc0.DisplayPort/ instead of usbc0.svid:ff01/, and I prefer a consistent ABI. Since this _is_ part of the ABI, would it make sense to standardize on names for modes in sysfs ? For example, how should a "Display Port" mode directory be named ? It doesn't sound good if I use "usbc0.svid:ff01", someone else uses "usbc0.DisplayPort", and yet someone else uses "usbc0.displayport".
Also, do we at some point need to standardize the ABI for the standard alternate modes such as DisplayPort (if there are any - again I am not there yet) ?
Quoted 19 lines
Quoted 19 lines
in addition to
/sys/class/type-c/usbc0/ usbc0-partner/usbc0-partner.svid:05ac usbc0-partner/usbc0-partner.svid:05ac/mode0 usbc0-partner/usbc0-partner.svid:05ac/mode0/vdo usbc0-partner/usbc0-partner.svid:05ac/mode0/description usbc0-partner/usbc0-partner.svid:05ac/mode0/active usbc0-partner/usbc0-partner.svid:05ac/mode1 usbc0-partner/usbc0-partner.svid:05ac/mode1/vdo usbc0-partner/usbc0-partner.svid:05ac/mode1/description usbc0-partner/usbc0-partner.svid:05ac/mode1/active ... usbc0-partner/usbc0-partner.svid:ff01 usbc0-partner/usbc0-partner.svid:ff01/mode0 usbc0-partner/usbc0-partner.svid:ff01/mode0/vdo usbc0-partner/usbc0-partner.svid:ff01/mode0/description usbc0-partner/usbc0-partner.svid:ff01/mode0/active
Quoted 9 lines
Quoted 4 lines
(when connecting the Apple adapter), which is exactly what I would expect to see.
Is this sensible ? Do we have a reason for expecting the alternate mode _devices_ to be created (without parent) when calling
typec_register_port()?So if you would prefer that the class code takes care of creating the alternate modes when
typec_register_port()is called, I'm fine with that too. Let's make it so.
Sounds good to me. Many other subsystems do the same, ie create the subsystem device(s) during registration with the subsystem, so this is in line with other kernel code.
Should I send you a follow-up patch on top of yours ?
Thanks,
Guenter
Heikki Krogerus
maintainerQuoted 102 lines · Guenter Roeck
Quoted 60 lines · Heikki Krogerus
Hi,
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Heikki Krogerus
Quoted 28 lines · Guenter Roeck
Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Heikki Krogerus
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
Quoted 9 lines
There's one thing we haven't touched upon yet. And I cannot really find an answer in the spec.
What do we do if we return from S4 or S3? I think we need to restore the ALternate Mode because our display may be running over that Alternate Mode.
If we want to support USB persist we also need to restore data role after S4.I don't have an answer ... but another interesting question.
How do we distinguish between alternate modes supported by a host vs. alternate modes supported by a sink ?
typec_capabilityincludes a pointer to alternate modes supportedf by the connector, but it is not clear if those are alternate modes supported as host, or alternate modes supported as device, or alternate modes supported by both.Quoted 3 lines
This doesn't matter much if only a fixed role is supported, but it does matter for dual role ports. A laptop will typically only support DisplayPort as host, for example.
The DP alternate mode spec actually separates the display role from Type-C role. A laptop most likely would only support the modes for display host roles, but if the port was DRP port then it would still do so in both Type-C roles.
So basically, even if the display was Type-C host, it would still work as a display when attached to the laptop.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Any idea ?
I'm actually not sure this is a problem.
Yes, this was a bad example, since the DisplayPort mode vdo includes a flag indicating if the port supports source, sink, or both.
I meant that in case of DP alternate mode, there should not be a problem.
Quoted 5 lines
Let's use a different example:
Google devices (such as power adapters) have mode '1' for firmware upgrades. Obviously hosts will support that, but what should the host advertise if it is configured as sink ?Quoted 8 lines
Quoted 4 lines
Maybe this is just my personal confusion, and there is no real problem. It might as well be that the Google mode VDO _should_ include a flag indicating if the port supports updating the partner, and/or if it supports being updated. For now I'll just assume that this is the case.
Well, do you think we can rely on always being able to get this detail from VDO?
Not really. Like in the Google case, one end will implement sending the firmware, the other end will implement receiving it and writing it to flash (or whatever). Which is which isn't currently made visible to user space. I suspect that other "intelligent" devices like Apple's multi-function adapter do the same, though obviously I don't really know what the two VDO modes do on the apple adapter.
I'll have to have some ABI to user space for the alternate mode, for example to send the firmware file to the kernel. I am not there yet, though, so I don't really know exactly how that will look like. Most likely it is going to be added sysfs attributes in the mode device (eg usbc0.svid:18d1/mode0/firmware).
Quoted 7 lines
Quoted 7 lines
Something else, which goes back into the symlink question. If I create the alternate mode devices before calling
typec_register_port(), the devices won't have a parent and don't show up in the class directory. You previously solved that with the symlink. I am trying to solve it in my current code by callingtypec_register_altmodes()fromtypec_register_port()- primarily because I don't really want to duplicate all the device creation code in my driver.Quoted 12 lines
Quoted 12 lines
In my test case, this gives me
/sys/class/type-c/usbc0/ usbc0.svid:18d1 usbc0.svid:18d1/mode0 usbc0.svid:18d1/mode0/vdo usbc0.svid:18d1/mode0/description usbc0.svid:18d1/mode0/active ... usbc0.svid:ff01 usbc0.svid:ff01/mode0/vdo usbc0.svid:ff01/mode0/description usbc0.svid:ff01/mode0/active
Quoted 7 lines
Side note: I didn't provide a description/name for the modes, because that would result in something like usbc0.DisplayPort/ instead of usbc0.svid:ff01/, and I prefer a consistent ABI. Since this _is_ part of the ABI, would it make sense to standardize on names for modes in sysfs ? For example, how should a "Display Port" mode directory be named ? It doesn't sound good if I use "usbc0.svid:ff01", someone else uses "usbc0.DisplayPort", and yet someone else uses "usbc0.displayport".
Yeah, let's make them standard.
Quoted 4 lines
Also, do we at some point need to standardize the ABI for the standard alternate modes such as DisplayPort (if there are any - again I am not there yet) ?
I don't have an answer to that.
Quoted 29 lines
Quoted 19 lines
Quoted 19 lines
in addition to
/sys/class/type-c/usbc0/ usbc0-partner/usbc0-partner.svid:05ac usbc0-partner/usbc0-partner.svid:05ac/mode0 usbc0-partner/usbc0-partner.svid:05ac/mode0/vdo usbc0-partner/usbc0-partner.svid:05ac/mode0/description usbc0-partner/usbc0-partner.svid:05ac/mode0/active usbc0-partner/usbc0-partner.svid:05ac/mode1 usbc0-partner/usbc0-partner.svid:05ac/mode1/vdo usbc0-partner/usbc0-partner.svid:05ac/mode1/description usbc0-partner/usbc0-partner.svid:05ac/mode1/active ... usbc0-partner/usbc0-partner.svid:ff01 usbc0-partner/usbc0-partner.svid:ff01/mode0 usbc0-partner/usbc0-partner.svid:ff01/mode0/vdo usbc0-partner/usbc0-partner.svid:ff01/mode0/description usbc0-partner/usbc0-partner.svid:ff01/mode0/activeQuoted 9 lines
Quoted 4 lines
(when connecting the Apple adapter), which is exactly what I would expect to see.
Is this sensible ? Do we have a reason for expecting the alternate mode _devices_ to be created (without parent) when calling
typec_register_port()?So if you would prefer that the class code takes care of creating the alternate modes when
typec_register_port()is called, I'm fine with that too. Let's make it so.
Quoted 5 lines
Sounds good to me. Many other subsystems do the same, ie create the subsystem device(s) during registration with the subsystem, so this is in line with other kernel code.
Should I send you a follow-up patch on top of yours ?
Sure. I'm a little bit stuck with an other tasks, so let's keep this thing rolling.
Thanks,
Signature · 1 line
heikki
On Fri, Jun 03, 2016 at 06:17:46PM +0300, Heikki Krogerus wrote:
[ ... ]
Quoted 22 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
In my test case, this gives me
/sys/class/type-c/usbc0/ usbc0.svid:18d1 usbc0.svid:18d1/mode0 usbc0.svid:18d1/mode0/vdo usbc0.svid:18d1/mode0/description usbc0.svid:18d1/mode0/active ... usbc0.svid:ff01 usbc0.svid:ff01/mode0/vdo usbc0.svid:ff01/mode0/description usbc0.svid:ff01/mode0/activeQuoted 7 lines
Side note: I didn't provide a description/name for the modes, because that would result in something like usbc0.DisplayPort/ instead of usbc0.svid:ff01/, and I prefer a consistent ABI. Since this _is_ part of the ABI, would it make sense to standardize on names for modes in sysfs ? For example, how should a "Display Port" mode directory be named ? It doesn't sound good if I use "usbc0.svid:ff01", someone else uses "usbc0.DisplayPort", and yet someone else uses "usbc0.displayport".
Quoted 2 lines
Yeah, let's make them standard.
Any name preferences ?
Quoted 7 lines
Quoted 4 lines
Also, do we at some point need to standardize the ABI for the standard alternate modes such as DisplayPort (if there are any - again I am not there yet) ?
I don't have an answer to that.
Ok, I'll look into it as I proceed with my implementation.
Quoted 10 lines
Quoted 6 lines
Sounds good to me. Many other subsystems do the same, ie create the subsystem device(s) during registration with the subsystem, so this is in line with other kernel code.
Should I send you a follow-up patch on top of yours ?
Sure. I'm a little bit stuck with an other tasks, so let's keep this thing rolling.
See below.
Thanks,
Guenter
---
Quoted 1 line
From
ab1f2d0671e3cda74b80c6d17d99cb3e386c0d08Mon Sep 17 00:00:00 2001
From: Guenter Roeck <[email protected]>
Date: Thu, 2 Jun 2016 10:09:50 -0700
Subject: [PATCH] usb: typec: Register supported alternate modes in
typec_register_port()
By registering supported alternate modes when registering the port, we automatically get the correct directory hierarchie in the class device.
--- drivers/usb/type-c/typec.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/usb/type-c/typec.c +15 -6
@@ -892,14 +892,22 @@ struct typec_port *typec_register_port(struct device *dev,typec_init_roles (port); ret =device_register (&port->dev); -if (ret) { -ida_simple_remove (&typec_index_ida, id); -put_device (&port->dev); -kfree (port); -return ERR_PTR (ret); - } +if (ret) + goto reg_err; + + ret =typec_register_altmodes (&port->dev, cap->alt_modes); +if (ret) + goto alt_err;return port; + +alt_err: +device_unregister (&port->dev); +reg_err: +ida_simple_remove (&typec_index_ida, id); +put_device (&port->dev); +kfree (port); +return ERR_PTR (ret); }EXPORT_SYMBOL_GPL (typec_register_port);
@@ -908,6 +916,7 @@ void typec_unregister_port(struct typec_port *port)if (port->connected)typec_disconnect (port); +typec_unregister_altmodes (port->cap->alt_modes);device_unregister (&port->dev); }EXPORT_SYMBOL_GPL (typec_unregister_port);
Signature · 1 line
2.1.2
Heikki Krogerus
maintainerQuoted 24 lines · Guenter Roeck
On Fri, Jun 03, 2016 at 06:17:46PM +0300, Heikki Krogerus wrote:
[ ... ]Quoted 22 lines
Quoted 21 lines
Quoted 13 lines
Quoted 13 lines
In my test case, this gives me
/sys/class/type-c/usbc0/ usbc0.svid:18d1 usbc0.svid:18d1/mode0 usbc0.svid:18d1/mode0/vdo usbc0.svid:18d1/mode0/description usbc0.svid:18d1/mode0/active ... usbc0.svid:ff01 usbc0.svid:ff01/mode0/vdo usbc0.svid:ff01/mode0/description usbc0.svid:ff01/mode0/activeSide note: I didn't provide a description/name for the modes, because that would result in something like usbc0.DisplayPort/ instead of usbc0.svid:ff01/, and I prefer a consistent ABI. Since this _is_ part of the ABI, would it make sense to standardize on names for modes in sysfs ? For example, how should a "Display Port" mode directory be named ? It doesn't sound good if I use "usbc0.svid:ff01", someone else uses "usbc0.DisplayPort", and yet someone else uses "usbc0.displayport".
Quoted 3 lines
Quoted 2 lines
Yeah, let's make them standard.
Any name preferences ?
I would prefer lower case letters. I don't know the SIDs there are at them moment, other then Display Port. Do you know them?
I don't think we can ever guarantee that in every case we will be able to provide a human readable name for the alternate modes if they are vendor defined. We will then potentially still have the names in two different forms: "usbc0.displayport" and "usbc0.svid:xxxx". Is that something acceptable to everybody?
I guess if it's not, then to only way to go forward would be to always just use the svid in the name.
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
Also, do we at some point need to standardize the ABI for the standard alternate modes such as DisplayPort (if there are any - again I am not there yet) ?
I don't have an answer to that.
Ok, I'll look into it as I proceed with my implementation.
Quoted 5 lines
Quoted 5 lines
Sounds good to me. Many other subsystems do the same, ie create the subsystem device(s) during registration with the subsystem, so this is in line with other kernel code.
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Should I send you a follow-up patch on top of yours ?
Sure. I'm a little bit stuck with an other tasks, so let's keep this thing rolling.
See below.
Thanks. I pushed it to my work branch for this class:
https://github.com/krohei/linux/commits/typec_class
There are still a few open questions, but I'm in any case going to start polishing the driver. I think the other attributes are more or less decided, excluding the alternate modes.
Cheers,
Signature · 1 line
heikki
Quoted 11 lines · Heikki Krogerus
I would prefer lower case letters. I don't know the SIDs there are at them moment, other then Display Port. Do you know them?
I don't think we can ever guarantee that in every case we will be able to provide a human readable name for the alternate modes if they are vendor defined. We will then potentially still have the names in two different forms: "usbc0.displayport" and "usbc0.svid:xxxx". Is that something acceptable to everybody?
I guess if it's not, then to only way to go forward would be to always just use the svid in the name.
Yes, that is better. It makes more sense to use the number. We'd get into versioning problems if we use names.
Regards
Oliver
Heikki Krogerus
maintainerQuoted 11 lines · Oliver Neukum
Quoted 9 lines · Heikki Krogerus
I would prefer lower case letters. I don't know the SIDs there are at them moment, other then Display Port. Do you know them?
I don't think we can ever guarantee that in every case we will be able to provide a human readable name for the alternate modes if they are vendor defined. We will then potentially still have the names in two different forms: "usbc0.displayport" and "usbc0.svid:xxxx". Is that something acceptable to everybody?
Quoted 5 lines
Quoted 2 lines
I guess if it's not, then to only way to go forward would be to always just use the svid in the name.
Yes, that is better. It makes more sense to use the number. We'd get into versioning problems if we use names.
OK, so we'll always use the svid in the name.
Thanks,
Signature · 1 line
heikki
On Mon, Jun 06, 2016 at 04:28:08PM +0300, Heikki Krogerus wrote:
[ ... ]
Quoted 4 lines
I would prefer lower case letters. I don't know the SIDs there are at them moment, other then Display Port. Do you know them?
SIDs:
0xff00 - power delivery 0xff01 - displayport 0xff02 - MHL 0xff03 - Thunderbolt 3 (if I recall correctly)
VIDs: Can obviously be anything. I have seen
0x05ac - Apple 0x18d1 - Google
Quoted 9 lines
I don't think we can ever guarantee that in every case we will be able to provide a human readable name for the alternate modes if they are vendor defined. We will then potentially still have the names in two different forms: "usbc0.displayport" and "usbc0.svid:xxxx". Is that something acceptable to everybody?
I guess if it's not, then to only way to go forward would be to always just use the svid in the name.
I think we should just use the svid.
Quoted 20 lines
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
Also, do we at some point need to standardize the ABI for the standard alternate modes such as DisplayPort (if there are any - again I am not there yet) ?
I don't have an answer to that.
Ok, I'll look into it as I proceed with my implementation.
Quoted 5 lines
Quoted 5 lines
Sounds good to me. Many other subsystems do the same, ie create the subsystem device(s) during registration with the subsystem, so this is in line with other kernel code.
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Should I send you a follow-up patch on top of yours ?
Sure. I'm a little bit stuck with an other tasks, so let's keep this thing rolling.
See below.
Quoted 8 lines
Thanks. I pushed it to my work branch for this class:
https://github.com/krohei/linux/commits/typec_class
There are still a few open questions, but I'm in any case going to start polishing the driver. I think the other attributes are more or less decided, excluding the alternate modes.
Sounds good.
Thanks,
Guenter
Heikki Krogerus
maintainerQuoted 10 lines · Oliver Neukum
Quoted 8 lines · Heikki Krogerus
Just noticed that the "active" file is for now read only, but it needs to be changed to writable. That file will of course provide means for the userspace to Exit and Enter modes. But please note that the responsibility of the dependencies between the modes, say, if a plug needs to be in one mode or the other in order for the partner to enter some specific mode, will fall on the Alternate Mode specific drivers once we have the altmode bus. I remember there were concerns about this in the original thread.
Quoted 8 lines
There's one thing we haven't touched upon yet. And I cannot really find an answer in the spec.
What do we do if we return from S4 or S3? I think we need to restore the ALternate Mode because our display may be running over that Alternate Mode.
If we want to support USB persist we also need to restore data role after S4.
It would make sense.. What are all the things we need to consider with that? An example, how do we know if the attached device has changed, etc.
I'll try to put somekind of suspend and resume hooks to the API, but this needs some thinking.
Does this have an effect on the interface, meaning would this be something we could potentially add later? We need to document the expected behaviour from the beginning, i.e. the roles and the modes should be restored when resuming, in any case I think.
Thanks,
Signature · 1 line
heikki
Quoted 5 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Quoted 7 lines
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++
For consistency, should this be either type-c/type-c.c or typec/typec.c?
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Heikki Krogerus
maintainerHi,
Quoted 14 lines · Pavel Machek
Quoted 5 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Quoted 7 lines
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++
Quoted 2 lines
For consistency, should this be either
type-c/type-c.cortypec/typec.c?
For some reason I like to have the dash in the folder name, but I don't like the idea that the port driver would be in form type-c_something. I would prefer them to be named typec_something. Or maybe just "something" and also name the typec.c maybe class.c or core.c.
Is this a big problem? I guess we could just name the folder "typec". Guenter, whats your opinion?
Thanks,
Signature · 1 line
heikki
Greg KH
maintainerQuoted 20 lines · Heikki Krogerus
Hi,
Quoted 14 lines · Pavel Machek
Quoted 5 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Quoted 7 lines
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++Quoted 2 lines
For consistency, should this be either
type-c/type-c.cortypec/typec.c?
Quoted 8 lines
For some reason I like to have the dash in the folder name, but I don't like the idea that the port driver would be in form type-c_something. I would prefer them to be named
typec_something. Or maybe just "something" and also name thetypec.cmaybeclass.corcore.c.Is this a big problem? I guess we could just name the folder "typec". Guenter, whats your opinion?
"typec" please.
Heikki Krogerus
maintainerQuoted 10 lines · Greg KH
Quoted 9 lines · Heikki Krogerus
Quoted 2 lines
For consistency, should this be either
type-c/type-c.cortypec/typec.c?For some reason I like to have the dash in the folder name, but I don't like the idea that the port driver would be in form type-c_something. I would prefer them to be named
typec_something. Or maybe just "something" and also name thetypec.cmaybeclass.corcore.c.
Quoted 4 lines
Quoted 2 lines
Is this a big problem? I guess we could just name the folder "typec". Guenter, whats your opinion?
"typec" please.
OK, typec it is.
Thanks,
Signature · 1 line
heikki
Quoted 20 lines · Heikki Krogerus
Hi,
Quoted 14 lines · Pavel Machek
Quoted 5 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
Quoted 7 lines
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/type-c/Kconfig | 7 + drivers/usb/type-c/Makefile | 1 + drivers/usb/type-c/typec.c | 957 ++++++++++++++++++++++++++++++++++++++++++++Quoted 2 lines
For consistency, should this be either
type-c/type-c.cortypec/typec.c?
Quoted 9 lines
For some reason I like to have the dash in the folder name, but I don't like the idea that the port driver would be in form type-c_something. I would prefer them to be named
typec_something. Or maybe just "something" and also name thetypec.cmaybeclass.corcore.c.Is this a big problem? I guess we could just name the folder "typec". Guenter, whats your opinion?
I am fine either way.
Thanks,
Guenter
Heikki Krogerus
maintainerRFC PATCH v3 1/1 usb: USB Type-C Connector Class
In reply to Heikki KrogerusThe purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/typec/Kconfig | 7 + drivers/usb/typec/Makefile | 1 + drivers/usb/typec/typec.c | 1077 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 252 +++++++++++ 6 files changed, 1341 insertions(+) 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
Hi,
I'm sorry to send this on Friday evening, but next week I want to get the alternate modes sorted out. Most of the remaining open questions are related to those. But first I want confirmation from you guys that the other attributes are OK.
The attributes for each type-c port under /sys/class/typec/usbc<x> are:
current_data_role
current_power_role
current_vconn_role
power_operation_mode
preferred_role
supported_accessory_modes
supported_data_roles
supported_power_roles
supports_usb_power_delivery
I choose to not have separate attribute for every accessory mode, as it seems we are getting more of them in the future type-c specifications. Instead I added a single attribute, supported_accessory_modes, to list all of them.
For the alternate modes I added an attribute, supported_roles, for the modes. It is not available for the partners and plugs. It will list the roles that particular mode supports on the port.
I have the following opens in my list:
- How do we restore the role and altmodes on resume?
- We are missing notification on alt_mode changes, resets from initiated by partner, etc.
- The supported_accessory_modes is not implemented yet.
What else?
Thanks,
drivers/usb/Kconfig +2 -0
@@ -150,6 +150,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 && USB_COMMON && LEDS_TRIGGERS
drivers/usb/Makefile +2 -0
@@ -61,3 +61,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 +1077 -0
1,077 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.8.1
Quoted 14 lines · Heikki Krogerus
(quoted diff) +2
-0+static ssize_t +preferred_role_store(struct device *dev, struct device_attribute*attr,
drivers/usb/typec/typec.c new file +10
-0+ const char *buf, size_t size) +{ +struct typec_port *port =to_typec_port (dev); +enum typec_role role; +int ret; + +mutex_lock (&port->lock); + +if (port->cap->type !=TYPEC_PORT_DRP ) { + dev_dbg(dev, "Try.SRC/SNK only supported with DRPports\n");
drivers/usb/typec/typec.c line 672
Quoted 3 lines
drivers/usb/typec/typec.c new file +3
-0+ ret = -EOPNOTSUPP ; + goto out; + }
I think Try.SNK with an UFP should fail differently from Try.SRC and vice versa.
And, even more importantly, this offeres no way to cancel a preference.
Regards
Oliver
Quoted 13 lines · Oliver Neukum
Quoted 12 lines · Heikki Krogerus
(quoted diff) +2
-0+static ssize_t +preferred_role_store(struct device *dev, struct device_attribute*attr,
drivers/usb/typec/typec.c new file +9
-0+ const char *buf, size_t size) +{ +struct typec_port *port =to_typec_port (dev); +enum typec_role role; +int ret; + +mutex_lock (&port->lock); + +if (port->cap->type !=TYPEC_PORT_DRP ) {
Quoted 9 lines
drivers/usb/typec/typec.c line 672
Quoted 5 lines
+ dev_dbg(dev, "Try.SRC/SNK only supported with DRP
ports\n");drivers/usb/typec/typec.c new file +3
-0+ ret = -EOPNOTSUPP ; + goto out; + }I think Try.SNK with an UFP should fail differently from Try.SRC and vice versa.
I think the message should not even mention Try.src or Try.snk in the first place, since both are optional and really orthogonal to how the role is set (it can also be changed with pd messages). On top of that, the specification states that Try.{src/snk} are optional if there is no PD support, and NA if PD is supported (see table 4.10). Kind of interesting, and I wonder how this is supposed to be implemented in practice, since Try.{src/snk} runs before it is established that/if the partner supports PD.
A better message would be something like "Setting preferred role only supported with DRP ports", and leave implementation details to the port driver.
Guenter
Heikki Krogerus
maintainerQuoted 33 lines · Guenter Roeck
Quoted 13 lines · Oliver Neukum
Quoted 12 lines · Heikki Krogerus
(quoted diff) +2
-0+static ssize_t +preferred_role_store(struct device *dev, struct device_attribute*attr,
drivers/usb/typec/typec.c new file +9
-0+ const char *buf, size_t size) +{ +struct typec_port *port =to_typec_port (dev); +enum typec_role role; +int ret; + +mutex_lock (&port->lock); + +if (port->cap->type !=TYPEC_PORT_DRP ) {Quoted 9 lines
drivers/usb/typec/typec.c line 672
Quoted 5 lines
+ dev_dbg(dev, "Try.SRC/SNK only supported with DRP
ports\n");drivers/usb/typec/typec.c new file +3
-0+ ret = -EOPNOTSUPP ; + goto out; + }I think Try.SNK with an UFP should fail differently from Try.SRC and vice versa.
I think the message should not even mention Try.src or Try.snk in the first place, since both are optional and really orthogonal to how the role is set (it can also be changed with pd messages). On top of that, the specification states that Try.{src/snk} are optional if there is no PD support, and NA if PD is supported (see table 4.10). Kind of interesting, and I wonder how this is supposed to be implemented in practice, since Try.{src/snk} runs before it is established that/if the partner supports PD.
Quoted 3 lines
A better message would be something like "Setting preferred role only supported with DRP ports", and leave implementation details to the port driver.
Works for me.
Thanks,
Signature · 1 line
heikki
Heikki Krogerus
maintainerQuoted 22 lines · Oliver Neukum
Quoted 14 lines · Heikki Krogerus
(quoted diff) +2
-0+static ssize_t +preferred_role_store(struct device *dev, struct device_attribute*attr,
drivers/usb/typec/typec.c new file +10
-0+ const char *buf, size_t size) +{ +struct typec_port *port =to_typec_port (dev); +enum typec_role role; +int ret; + +mutex_lock (&port->lock); + +if (port->cap->type !=TYPEC_PORT_DRP ) { + dev_dbg(dev, "Try.SRC/SNK only supported with DRPports\n");
drivers/usb/typec/typec.c line 672
Quoted 3 lines
drivers/usb/typec/typec.c new file +3
-0+ ret = -EOPNOTSUPP ; + goto out; + }I think Try.SNK with an UFP should fail differently from Try.SRC and vice versa.
Quoted 2 lines
And, even more importantly, this offeres no way to cancel a preference.
Well, no way that would actually work. I'll fix that.
Thanks,
Signature · 1 line
heikki
Quoted 4 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
This raises two more questions.
1. Booting
It is possible that our only display and, worse, our source of power is a display that can be used only in an alternate mode and is connected via a type C connector.
We need some kind of boot time support for alternate modes.
The firmware will surely want to display something. So it is possible that we start the OS will a valid power contract. How do we deal with that? Renegotiate?
2. Multiple GPUs
How do we know which GPU is connected to which port?
Regards
Oliver
Quoted 14 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
This raises two more questions.
1. Booting
It is possible that our only display and, worse, our source of power is a display that can be used only in an alternate mode and is connected via a type C connector.
Quoted 6 lines
We need some kind of boot time support for alternate modes.
The firmware will surely want to display something. So it is possible that we start the OS will a valid power contract. How do we deal with that? Renegotiate?
In one of my drivers, the PD protocol is running on an EC and the Linux driver is just interfacing it to the typec class. I don't do any renegotiating but just report the port state to the class. What is wrong with that, and why would it not work ?
If the PD protocol runs in Linux (which I implement as well), I tried renegotiating, ie assuming that a contract was already established, with several multi-function adapters. Quite often those 'die' when trying tricks like that, and have to be manually disconnected from power (on both ends) to get back to life. Granted, part of that is that the firmware on those adapters is early and not as stable as I would like it to be, but still that is a significant risk. I ended up always starting with error recovery to avoid that kind of problem, at least for now. Even that doesn't always help.
Quoted 4 lines
2. Multiple GPUs
How do we know which GPU is connected to which port?
Still working on it, but the basic idea (in my case) is to use devicetree data or platform data if that is not available.
Guenter
Quoted 15 lines · Guenter Roeck
Quoted 14 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
This raises two more questions.
1. Booting
It is possible that our only display and, worse, our source of power is a display that can be used only in an alternate mode and is connected via a type C connector.
Quoted 8 lines
Quoted 6 lines
We need some kind of boot time support for alternate modes.
The firmware will surely want to display something. So it is possible that we start the OS will a valid power contract. How do we deal with that? Renegotiate?
In one of my drivers, the PD protocol is running on an EC and the Linux
Is that code public?
Quoted 3 lines
driver is just interfacing it to the typec class. I don't do any renegotiating but just report the port state to the class. What is wrong with that, and why would it not work ?
It is not wrong. But it is unclear how it would work if we pass control between boot loader and OS. If I read the spec for TCPM and TCPC correctly, we can read back the voltage, but not the agreed currents, maximum currents and suspend rules. Yet we need those for power budgeting.
We could reset, but then we leave the alternate mode.
Regards
Oliver
Quoted 18 lines · Oliver Neukum
Quoted 17 lines · Guenter Roeck
Quoted 16 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
This raises two more questions.
1. Booting
It is possible that our only display and, worse, our source of power is a display that can be used only in an alternate mode and is connected via a type C connector.
We need some kind of boot time support for alternate modes.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
The firmware will surely want to display something. So it is possible that we start the OS will a valid power contract. How do we deal with that? Renegotiate?
In one of my drivers, the PD protocol is running on an EC and the Linux
Is that code public?
Pretty much, though it is not always up to date. It isn't pushed into an official chromiumos kernel branch yet, but it is available in the repository if one knows what to look for.
Unfortunately, it looks like I lost permission to create a sandbox in the repository. I'll see what I can do to get that fixed.
Quoted 10 lines
Quoted 3 lines
driver is just interfacing it to the typec class. I don't do any renegotiating but just report the port state to the class. What is wrong with that, and why would it not work ?
It is not wrong. But it is unclear how it would work if we pass control between boot loader and OS. If I read the spec for TCPM and TCPC correctly, we can read back the voltage, but not the agreed currents, maximum currents and suspend rules. Yet we need those for power budgeting.
The TCPC would not (necessarily) know that information, unfortunately. I am not even sure about the negotiated voltage - are you sure the TCPC would know it ?
Quoted 2 lines
We could reset, but then we leave the alternate mode.
Correct. I wasn't able to find a solution for that problem (yet). Going forward, I can see that being an issue, for example if the BIOS/ROMMON negotiates a contract but the TCPM running in the kernel doesn't know about it and thus has to disconnect and reconnect the port.
Guenter
Heikki Krogerus
maintainerQuoted 14 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus
The purpose of this class is to provide unified interface for user space to get the status and basic information about USB Type-C Connectors in the system, control data role swapping, and when USB PD is available, also power role swapping and Alternate Modes.
This raises two more questions.
1. Booting
It is possible that our only display and, worse, our source of power is a display that can be used only in an alternate mode and is connected via a type C connector.
Quoted 5 lines
We need some kind of boot time support for alternate modes.
The firmware will surely want to display something. So it is possible that we start the OS will a valid power contract. How do we deal with that? Renegotiate?
Systems where the firmware has to negotiate PD will likely provide firmware interface like UCSI, and where the OS has no direct interaction with the USB PD transceiver. In these case there is no need to renegotiate as we are just reporting in OS the initial state after bootup.
We do have a system where the typec port is used to power the board. On these systems the firmware does not communicate PD (so we will never have the firmware displaying anything over Type-C on those systems), but the USB PD chargers for example are detected as 3.0A Type-C power supplies before any USB PD negotiation takes place, just like the spec says, and that is more then enough to power these boards.
Quoted 3 lines
2. Multiple GPUs
How do we know which GPU is connected to which port?
With ACPI we will have to be able to bind the correct companion to the device presenting the DP alternate mode under the port. Just like we will have to bind the ACPI companion of the actual USB port to the typec port device itself.
Cheers,
Signature · 1 line
heikki
Quoted 11 lines · Heikki Krogerus
Quoted 3 lines · Oliver Neukum
The firmware will surely want to display something. So it is possible that we start the OS will a valid power contract. How do we deal with that? Renegotiate?
Systems where the firmware has to negotiate PD will likely provide firmware interface like UCSI, and where the OS has no direct interaction with the USB PD transceiver. In these case there is no need to renegotiate as we are just reporting in OS the initial state after bootup.
How certain is that? I was under the impression that on many systems the OS would speak to the TCPM directly.
Quoted 6 lines
We do have a system where the typec port is used to power the board. On these systems the firmware does not communicate PD (so we will never have the firmware displaying anything over Type-C on those systems), but the USB PD chargers for example are detected as 3.0A Type-C power supplies before any USB PD negotiation takes place, just like the spec says, and that is more then enough to power these boards.
Now correct me, if I am misreading the spec. I am sure the system will boot unless it needs ridiculous amounts of power, but will we see anything on the screen? As far as I can tell the spec actually says that you cannot enter an alternate mode without having established a power contract.
If we really leave entering modes up to user space, we have lost printk before getting into the initrd at the earliest.
Regards
Oliver
Heikki Krogerus
maintainerHi Oliver,
Quoted 7 lines · Oliver Neukum
Quoted 6 lines · Heikki Krogerus
Quoted 3 lines · Oliver Neukum
The firmware will surely want to display something. So it is possible that we start the OS will a valid power contract. How do we deal with that? Renegotiate?
Quoted 8 lines
Quoted 5 lines
Systems where the firmware has to negotiate PD will likely provide firmware interface like UCSI, and where the OS has no direct interaction with the USB PD transceiver. In these case there is no need to renegotiate as we are just reporting in OS the initial state after bootup.
How certain is that? I was under the impression that on many systems the OS would speak to the TCPM directly.
I think we gonna see systems where the OS has access to TCPC and where the TCPM is expected to be implemented in the OS, but we will have quite a few systems where the TCPC/PD controller/non TCPC compliant Type-C PHY is attached to a microcontroller like EC, and where that microcontroller will implement TCPM and the OS is exposed just a separate interface, most likely UCSI.
Quoted 7 lines
Quoted 6 lines
We do have a system where the typec port is used to power the board. On these systems the firmware does not communicate PD (so we will never have the firmware displaying anything over Type-C on those systems), but the USB PD chargers for example are detected as 3.0A Type-C power supplies before any USB PD negotiation takes place, just like the spec says, and that is more then enough to power these boards.
Quoted 7 lines
Now correct me, if I am misreading the spec. I am sure the system will boot unless it needs ridiculous amounts of power, but will we see anything on the screen? As far as I can tell the spec actually says that you cannot enter an alternate mode without having established a power contract.
If we really leave entering modes up to user space, we have lost printk before getting into the initrd at the earliest.
With these boards, you will not see anything on the screen that is attached to a Type-C connector until the OS has booted to the point where it has negotiated the power contract and entered a mode.
If the system has BIOS/FW/EC capable of negotiating the power contract and enter a mode, but where we still are expected to take over the whole TCPM in OS, I think the connection will be reset.
Thanks,
Signature · 1 line
heikki
On Wed, 2016-06-22 at 12:31 +0300, Heikki Krogerus wrote:
Hi,
Quoted 8 lines
Quoted 7 lines
Now correct me, if I am misreading the spec. I am sure the system will boot unless it needs ridiculous amounts of power, but will we see anything on the screen? As far as I can tell the spec actually says that you cannot enter an alternate mode without having established a power contract.
If we really leave entering modes up to user space, we have lost printk before getting into the initrd at the earliest.
Quoted 7 lines
With these boards, you will not see anything on the screen that is attached to a Type-C connector until the OS has booted to the point where it has negotiated the power contract and entered a mode.
If the system has BIOS/FW/EC capable of negotiating the power contract and enter a mode, but where we still are expected to take over the whole TCPM in OS, I think the connection will be reset.
Think about a DP over type C display with a USB PD power brick on a daisy chain.
If the host needs more than 15W or more than 5V, a reset is suicide.
And losing earlyprintk hurts a lot.
This means we need USB PD statically in the kernel. And a kernel based policy that brings up all displays.
Regards
Oliver
Heikki Krogerus
maintainerQuoted 16 lines · Oliver Neukum
On Wed, 2016-06-22 at 12:31 +0300, Heikki Krogerus wrote:
Hi,
Quoted 12 lines
Quoted 7 lines
Now correct me, if I am misreading the spec. I am sure the system will boot unless it needs ridiculous amounts of power, but will we see anything on the screen? As far as I can tell the spec actually says that you cannot enter an alternate mode without having established a power contract.
If we really leave entering modes up to user space, we have lost printk before getting into the initrd at the earliest.With these boards, you will not see anything on the screen that is attached to a Type-C connector until the OS has booted to the point where it has negotiated the power contract and entered a mode.
Quoted 7 lines
Quoted 3 lines
If the system has BIOS/FW/EC capable of negotiating the power contract and enter a mode, but where we still are expected to take over the whole TCPM in OS, I think the connection will be reset.
Think about a DP over type C display with a USB PD power brick on a daisy chain.
If the host needs more than 15W or more than 5V, a reset is suicide.
If the host needs more then 15W from Type-C to bootup, which does not have enough capacitance the manage the renegotiation, I think will always have only the FW interface (most likely UCSI) to deal with the Type-C ports, if even that. The Thunderbolt3 controllers for example don't give any details about or control over the Type-C ports to OS. Though I think their firmwares may be made to support UCSI in the future with some of them.
Quoted 3 lines
And losing earlyprintk hurts a lot.
This means we need USB PD statically in the kernel. And a kernel based policy that brings up all displays.
Yep.
I'm guessing these points are probable one of the major reason why the control of the Type-C ports was made a responsibility of a discrete microcontroller or the FW in general.
Thanks,
Signature · 1 line
heikki
Hi!
Quoted 8 lines
Quoted 7 lines
With these boards, you will not see anything on the screen that is attached to a Type-C connector until the OS has booted to the point where it has negotiated the power contract and entered a mode.
If the system has BIOS/FW/EC capable of negotiating the power contract and enter a mode, but where we still are expected to take over the whole TCPM in OS, I think the connection will be reset.
Quoted 7 lines
Think about a DP over type C display with a USB PD power brick on a daisy chain.
If the host needs more than 15W or more than 5V, a reset is suicide.And losing earlyprintk hurts a lot.
This means we need USB PD statically in the kernel. And a kernel based policy that brings up all displays.
Yes please.
Of course, even that will hurt, because I guess that means printk() after USB, and that means late in the boot process, but better late in kernel than in initrd.
(And yes, N900 has display pretty late in the bootprocess, and yes, it is very annoying.)
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 18 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
With these boards, you will not see anything on the screen that is attached to a Type-C connector until the OS has booted to the point where it has negotiated the power contract and entered a mode.
If the system has BIOS/FW/EC capable of negotiating the power contract and enter a mode, but where we still are expected to take over the whole TCPM in OS, I think the connection will be reset.
Quoted 7 lines
Think about a DP over type C display with a USB PD power brick on a daisy chain.
If the host needs more than 15W or more than 5V, a reset is suicide.And losing earlyprintk hurts a lot.
This means we need USB PD statically in the kernel. And a kernel based policy that brings up all displays.
Quoted 5 lines
Yes please.
Of course, even that will hurt, because I guess that means
printk()after USB, and that means late in the boot process, but better late in kernel than in initrd.
i can confirm that in a laptop with a decent firmware a docking station is switched into the mode that will make the display work. In principle all is well if we can manage a handover.
Regards
Oliver