* [PATCH v2 1/2] usb: roles: Link the switch to its connector
2024-02-13 13:00 [PATCH v2 0/2] platform/chrome: typec: xHCI DbC Heikki Krogerus
@ 2024-02-13 13:00 ` Heikki Krogerus
2024-02-14 9:25 ` Prashant Malani
2024-02-13 13:00 ` [PATCH v2 2/2] platform/chrome: cros_ec_typec: Make sure the USB role switch has PLD Heikki Krogerus
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Heikki Krogerus @ 2024-02-13 13:00 UTC (permalink / raw)
To: Prashant Malani, Greg Kroah-Hartman
Cc: Benson Leung, Tzung-Bi Shih, Guenter Roeck, Emilie Roberts,
Nyman, Mathias, Regupathy, Rajaram, Radjacoumar, Shyam Sundar,
Samuel Jacob, Uday Bhat, linux-usb, chrome-platform, linux-kernel
This is probable useful information to have in user space in
general, but it's primarily needed for the xHCI DbC (Debug
Capability). When xHCI DbC is being used, the USB port needs
to be muxed to the xHCI even in device role. In xHCI DbC mode,
the xHCI is the USB device controller.
Tested-by: Uday Bhat <uday.m.bhat@intel.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
.../ABI/testing/sysfs-class-usb_role | 6 +++
drivers/usb/roles/class.c | 40 ++++++++++++++++++-
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-class-usb_role b/Documentation/ABI/testing/sysfs-class-usb_role
index 3b810a425a52..9fab3f06679e 100644
--- a/Documentation/ABI/testing/sysfs-class-usb_role
+++ b/Documentation/ABI/testing/sysfs-class-usb_role
@@ -19,3 +19,9 @@ Description:
- none
- host
- device
+
+What: /sys/class/usb_role/<switch>/connector
+Date: Feb 2024
+Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
+Description:
+ Optional symlink to the USB Type-C connector.
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index ae41578bd014..4ad03c93c17f 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -7,6 +7,7 @@
* Hans de Goede <hdegoede@redhat.com>
*/
+#include <linux/component.h>
#include <linux/usb/role.h>
#include <linux/property.h>
#include <linux/device.h>
@@ -34,6 +35,32 @@ struct usb_role_switch {
#define to_role_switch(d) container_of(d, struct usb_role_switch, dev)
+static int connector_bind(struct device *dev, struct device *connector, void *data)
+{
+ int ret;
+
+ ret = sysfs_create_link(&dev->kobj, &connector->kobj, "connector");
+ if (ret)
+ return ret;
+
+ ret = sysfs_create_link(&connector->kobj, &dev->kobj, "usb-role-switch");
+ if (ret)
+ sysfs_remove_link(&dev->kobj, "connector");
+
+ return ret;
+}
+
+static void connector_unbind(struct device *dev, struct device *connector, void *data)
+{
+ sysfs_remove_link(&connector->kobj, "usb-role-switch");
+ sysfs_remove_link(&dev->kobj, "connector");
+}
+
+static const struct component_ops connector_ops = {
+ .bind = connector_bind,
+ .unbind = connector_unbind,
+};
+
/**
* usb_role_switch_set_role - Set USB role for a switch
* @sw: USB role switch
@@ -352,6 +379,12 @@ usb_role_switch_register(struct device *parent,
return ERR_PTR(ret);
}
+ if (dev_fwnode(&sw->dev)) {
+ ret = component_add(&sw->dev, &connector_ops);
+ if (ret)
+ dev_warn(&sw->dev, "failed to add component\n");
+ }
+
/* TODO: Symlinks for the host port and the device controller. */
return sw;
@@ -366,8 +399,11 @@ EXPORT_SYMBOL_GPL(usb_role_switch_register);
*/
void usb_role_switch_unregister(struct usb_role_switch *sw)
{
- if (!IS_ERR_OR_NULL(sw))
- device_unregister(&sw->dev);
+ if (IS_ERR_OR_NULL(sw))
+ return;
+ if (dev_fwnode(&sw->dev))
+ component_del(&sw->dev, &connector_ops);
+ device_unregister(&sw->dev);
}
EXPORT_SYMBOL_GPL(usb_role_switch_unregister);
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 1/2] usb: roles: Link the switch to its connector
2024-02-13 13:00 ` [PATCH v2 1/2] usb: roles: Link the switch to its connector Heikki Krogerus
@ 2024-02-14 9:25 ` Prashant Malani
0 siblings, 0 replies; 10+ messages in thread
From: Prashant Malani @ 2024-02-14 9:25 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Greg Kroah-Hartman, Benson Leung, Tzung-Bi Shih, Guenter Roeck,
Emilie Roberts, Nyman, Mathias, Regupathy, Rajaram,
Radjacoumar, Shyam Sundar, Samuel Jacob, Uday Bhat, linux-usb,
chrome-platform, linux-kernel
On Tue, Feb 13, 2024 at 5:00 AM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> This is probable useful information to have in user space in
> general, but it's primarily needed for the xHCI DbC (Debug
> Capability). When xHCI DbC is being used, the USB port needs
> to be muxed to the xHCI even in device role. In xHCI DbC mode,
> the xHCI is the USB device controller.
>
> Tested-by: Uday Bhat <uday.m.bhat@intel.com>
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
FWIW:
Reviewed-by: Prashant Malani <pmalani@chromium.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 2/2] platform/chrome: cros_ec_typec: Make sure the USB role switch has PLD
2024-02-13 13:00 [PATCH v2 0/2] platform/chrome: typec: xHCI DbC Heikki Krogerus
2024-02-13 13:00 ` [PATCH v2 1/2] usb: roles: Link the switch to its connector Heikki Krogerus
@ 2024-02-13 13:00 ` Heikki Krogerus
2024-02-13 16:55 ` Prashant Malani
2024-03-25 1:54 ` [PATCH v2 0/2] platform/chrome: typec: xHCI DbC patchwork-bot+chrome-platform
2024-03-25 2:13 ` patchwork-bot+chrome-platform
3 siblings, 1 reply; 10+ messages in thread
From: Heikki Krogerus @ 2024-02-13 13:00 UTC (permalink / raw)
To: Prashant Malani, Greg Kroah-Hartman
Cc: Benson Leung, Tzung-Bi Shih, Guenter Roeck, Emilie Roberts,
Nyman, Mathias, Regupathy, Rajaram, Radjacoumar, Shyam Sundar,
Samuel Jacob, Uday Bhat, linux-usb, chrome-platform, linux-kernel
The USB role switch does not always have the _PLD (Physical
Location of Device) in ACPI tables. If it's missing,
assigning the PLD hash of the port to the switch. That
should guarantee that the USB Type-C port mapping code is
always able to find the connection between the two (the port
and the switch).
Tested-by: Uday Bhat <uday.m.bhat@intel.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/platform/chrome/cros_ec_typec.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 2b2f14a1b711..4d305876ec08 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -24,6 +24,23 @@
#define DP_PORT_VDO (DP_CONF_SET_PIN_ASSIGN(BIT(DP_PIN_ASSIGN_C) | BIT(DP_PIN_ASSIGN_D)) | \
DP_CAP_DFP_D | DP_CAP_RECEPTACLE)
+static void cros_typec_role_switch_quirk(struct fwnode_handle *fwnode)
+{
+#ifdef CONFIG_ACPI
+ struct fwnode_handle *switch_fwnode;
+
+ /* Supply the USB role switch with the correct pld_crc if it's missing. */
+ switch_fwnode = fwnode_find_reference(fwnode, "usb-role-switch", 0);
+ if (!IS_ERR_OR_NULL(switch_fwnode)) {
+ struct acpi_device *adev = to_acpi_device_node(switch_fwnode);
+
+ if (adev && !adev->pld_crc)
+ adev->pld_crc = to_acpi_device_node(fwnode)->pld_crc;
+ fwnode_handle_put(switch_fwnode);
+ }
+#endif
+}
+
static int cros_typec_parse_port_props(struct typec_capability *cap,
struct fwnode_handle *fwnode,
struct device *dev)
@@ -66,6 +83,8 @@ static int cros_typec_parse_port_props(struct typec_capability *cap,
cap->prefer_role = ret;
}
+ cros_typec_role_switch_quirk(fwnode);
+
cap->fwnode = fwnode;
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 2/2] platform/chrome: cros_ec_typec: Make sure the USB role switch has PLD
2024-02-13 13:00 ` [PATCH v2 2/2] platform/chrome: cros_ec_typec: Make sure the USB role switch has PLD Heikki Krogerus
@ 2024-02-13 16:55 ` Prashant Malani
2024-02-14 10:22 ` Heikki Krogerus
0 siblings, 1 reply; 10+ messages in thread
From: Prashant Malani @ 2024-02-13 16:55 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Greg Kroah-Hartman, Benson Leung, Tzung-Bi Shih, Guenter Roeck,
Emilie Roberts, Nyman, Mathias, Regupathy, Rajaram,
Radjacoumar, Shyam Sundar, Samuel Jacob, Uday Bhat, linux-usb,
chrome-platform, linux-kernel
Hi Heikki,
On Tue, Feb 13, 2024 at 5:00 AM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> The USB role switch does not always have the _PLD (Physical
> Location of Device) in ACPI tables. If it's missing,
> assigning the PLD hash of the port to the switch. That
> should guarantee that the USB Type-C port mapping code is
> always able to find the connection between the two (the port
> and the switch).
>
> Tested-by: Uday Bhat <uday.m.bhat@intel.com>
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> drivers/platform/chrome/cros_ec_typec.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 2b2f14a1b711..4d305876ec08 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -24,6 +24,23 @@
> #define DP_PORT_VDO (DP_CONF_SET_PIN_ASSIGN(BIT(DP_PIN_ASSIGN_C) | BIT(DP_PIN_ASSIGN_D)) | \
> DP_CAP_DFP_D | DP_CAP_RECEPTACLE)
>
> +static void cros_typec_role_switch_quirk(struct fwnode_handle *fwnode)
> +{
> +#ifdef CONFIG_ACPI
> + struct fwnode_handle *switch_fwnode;
> +
> + /* Supply the USB role switch with the correct pld_crc if it's missing. */
> + switch_fwnode = fwnode_find_reference(fwnode, "usb-role-switch", 0);
> + if (!IS_ERR_OR_NULL(switch_fwnode)) {
> + struct acpi_device *adev = to_acpi_device_node(switch_fwnode);
> +
> + if (adev && !adev->pld_crc)
> + adev->pld_crc = to_acpi_device_node(fwnode)->pld_crc;
> + fwnode_handle_put(switch_fwnode);
> + }
> +#endif
> +}
> +
I'll reiterate my comment[ 1] from v1: can this be in the
common Type-C code, i.e typec_register_port() ?
I don't see anything in this implementation which is Chrome OS specific.
Thanks,
-Prashant
[1] https://lore.kernel.org/chrome-platform/CACeCKaffZBPA0Q_Bqs1hjKJB4HCj=VKrqO21dXj4AF5C5VwtVQ@mail.gmail.com/
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2 2/2] platform/chrome: cros_ec_typec: Make sure the USB role switch has PLD
2024-02-13 16:55 ` Prashant Malani
@ 2024-02-14 10:22 ` Heikki Krogerus
[not found] ` <CAAuZZi9h=d2_CM4tU4-H9wJfhLZbw99X2dGSddiCeDFDdb+kjw@mail.gmail.com>
0 siblings, 1 reply; 10+ messages in thread
From: Heikki Krogerus @ 2024-02-14 10:22 UTC (permalink / raw)
To: Prashant Malani
Cc: Greg Kroah-Hartman, Benson Leung, Tzung-Bi Shih, Guenter Roeck,
Emilie Roberts, Nyman, Mathias, Regupathy, Rajaram,
Radjacoumar, Shyam Sundar, Samuel Jacob, Uday Bhat, linux-usb,
chrome-platform, linux-kernel
On Tue, Feb 13, 2024 at 08:55:20AM -0800, Prashant Malani wrote:
> Hi Heikki,
>
> On Tue, Feb 13, 2024 at 5:00 AM Heikki Krogerus
> <heikki.krogerus@linux.intel.com> wrote:
> >
> > The USB role switch does not always have the _PLD (Physical
> > Location of Device) in ACPI tables. If it's missing,
> > assigning the PLD hash of the port to the switch. That
> > should guarantee that the USB Type-C port mapping code is
> > always able to find the connection between the two (the port
> > and the switch).
> >
> > Tested-by: Uday Bhat <uday.m.bhat@intel.com>
> > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > ---
> > drivers/platform/chrome/cros_ec_typec.c | 19 +++++++++++++++++++
> > 1 file changed, 19 insertions(+)
> >
> > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> > index 2b2f14a1b711..4d305876ec08 100644
> > --- a/drivers/platform/chrome/cros_ec_typec.c
> > +++ b/drivers/platform/chrome/cros_ec_typec.c
> > @@ -24,6 +24,23 @@
> > #define DP_PORT_VDO (DP_CONF_SET_PIN_ASSIGN(BIT(DP_PIN_ASSIGN_C) | BIT(DP_PIN_ASSIGN_D)) | \
> > DP_CAP_DFP_D | DP_CAP_RECEPTACLE)
> >
> > +static void cros_typec_role_switch_quirk(struct fwnode_handle *fwnode)
> > +{
> > +#ifdef CONFIG_ACPI
> > + struct fwnode_handle *switch_fwnode;
> > +
> > + /* Supply the USB role switch with the correct pld_crc if it's missing. */
> > + switch_fwnode = fwnode_find_reference(fwnode, "usb-role-switch", 0);
> > + if (!IS_ERR_OR_NULL(switch_fwnode)) {
> > + struct acpi_device *adev = to_acpi_device_node(switch_fwnode);
> > +
> > + if (adev && !adev->pld_crc)
> > + adev->pld_crc = to_acpi_device_node(fwnode)->pld_crc;
> > + fwnode_handle_put(switch_fwnode);
> > + }
> > +#endif
> > +}
> > +
>
> I'll reiterate my comment[ 1] from v1: can this be in the
> common Type-C code, i.e typec_register_port() ?
>
> I don't see anything in this implementation which is Chrome OS specific.
I'm sorry Prashant, I failed to notice your comment.
This is only needed for Chrome OS. The problem affects only certain
Chromebooks.
I do not want to put quirks to the generic subsystem code unless we
have to. If there are more device drivers that need the same quirk,
then we can move it there, but not before that.
This solution is in any case a hack regardless of where we put it, and
I don't like it because of that. But I don't have any better ideas
unfortunately.
thanks,
--
heikki
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/2] platform/chrome: typec: xHCI DbC
2024-02-13 13:00 [PATCH v2 0/2] platform/chrome: typec: xHCI DbC Heikki Krogerus
2024-02-13 13:00 ` [PATCH v2 1/2] usb: roles: Link the switch to its connector Heikki Krogerus
2024-02-13 13:00 ` [PATCH v2 2/2] platform/chrome: cros_ec_typec: Make sure the USB role switch has PLD Heikki Krogerus
@ 2024-03-25 1:54 ` patchwork-bot+chrome-platform
2024-03-25 2:13 ` patchwork-bot+chrome-platform
3 siblings, 0 replies; 10+ messages in thread
From: patchwork-bot+chrome-platform @ 2024-03-25 1:54 UTC (permalink / raw)
To: Heikki Krogerus
Cc: pmalani, gregkh, bleung, tzungbi, groeck, hadrosaur,
mathias.nyman, rajaram.regupathy, ssradjacoumar, samjaco,
uday.m.bhat, linux-usb, chrome-platform, linux-kernel
Hello:
This series was applied to chrome-platform/linux.git (for-kernelci)
by Greg Kroah-Hartman <gregkh@linuxfoundation.org>:
On Tue, 13 Feb 2024 15:00:16 +0200 you wrote:
> Hi,
>
> Changed in v2:
>
> The quirk is now wrapped inside an ugly ifdef CONFIG_ACPI :(
> I don't have better ideas better ideas for this I'm afraid.
>
> [...]
Here is the summary with links:
- [v2,1/2] usb: roles: Link the switch to its connector
https://git.kernel.org/chrome-platform/c/9a270ec7bfb0
- [v2,2/2] platform/chrome: cros_ec_typec: Make sure the USB role switch has PLD
https://git.kernel.org/chrome-platform/c/56403220577b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2 0/2] platform/chrome: typec: xHCI DbC
2024-02-13 13:00 [PATCH v2 0/2] platform/chrome: typec: xHCI DbC Heikki Krogerus
` (2 preceding siblings ...)
2024-03-25 1:54 ` [PATCH v2 0/2] platform/chrome: typec: xHCI DbC patchwork-bot+chrome-platform
@ 2024-03-25 2:13 ` patchwork-bot+chrome-platform
3 siblings, 0 replies; 10+ messages in thread
From: patchwork-bot+chrome-platform @ 2024-03-25 2:13 UTC (permalink / raw)
To: Heikki Krogerus
Cc: pmalani, gregkh, bleung, tzungbi, groeck, hadrosaur,
mathias.nyman, rajaram.regupathy, ssradjacoumar, samjaco,
uday.m.bhat, linux-usb, chrome-platform, linux-kernel
Hello:
This series was applied to chrome-platform/linux.git (for-next)
by Greg Kroah-Hartman <gregkh@linuxfoundation.org>:
On Tue, 13 Feb 2024 15:00:16 +0200 you wrote:
> Hi,
>
> Changed in v2:
>
> The quirk is now wrapped inside an ugly ifdef CONFIG_ACPI :(
> I don't have better ideas better ideas for this I'm afraid.
>
> [...]
Here is the summary with links:
- [v2,1/2] usb: roles: Link the switch to its connector
https://git.kernel.org/chrome-platform/c/9a270ec7bfb0
- [v2,2/2] platform/chrome: cros_ec_typec: Make sure the USB role switch has PLD
https://git.kernel.org/chrome-platform/c/56403220577b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 10+ messages in thread