2023-01-11 02:11:03

by Prashant Malani

[permalink] [raw]
Subject: [PATCH 1/3] usb: typec: altmodes/displayport: Add pin assignment helper

The code to extract a peripheral's currently supported Pin Assignments
is repeated in a couple of locations. Factor it out into a separate
function.

This will also make it easier to add fixes (we only need to update 1
location instead of 2).

Fixes: c1e5c2f0cb8a ("usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles")
Cc: [email protected]
Cc: Heikki Krogerus <[email protected]>
Signed-off-by: Prashant Malani <[email protected]>
---

While this patch doesn't fix anything, it is required by the actual
fix (which is Patch 2/3 in this series). So, I've add the "Fixes" tag
and "Cc stable" tag to ensure that both patches are picked.

If this is the incorrect approach and there is a better way, my
apologies, and please let me know the appropriate process.

drivers/usb/typec/altmodes/displayport.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
index 06fb4732f8cd..f9d4a7648bc9 100644
--- a/drivers/usb/typec/altmodes/displayport.c
+++ b/drivers/usb/typec/altmodes/displayport.c
@@ -420,6 +420,18 @@ static const char * const pin_assignments[] = {
[DP_PIN_ASSIGN_F] = "F",
};

+/*
+ * Helper function to extract a peripheral's currently supported
+ * Pin Assignments from its DisplayPort alternate mode state.
+ */
+static u8 get_current_pin_assignments(struct dp_altmode *dp)
+{
+ if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
+ return DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
+ else
+ return DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
+}
+
static ssize_t
pin_assignment_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t size)
@@ -446,10 +458,7 @@ pin_assignment_store(struct device *dev, struct device_attribute *attr,
goto out_unlock;
}

- if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
- assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
- else
- assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
+ assignments = get_current_pin_assignments(dp);

if (!(DP_CONF_GET_PIN_ASSIGN(conf) & assignments)) {
ret = -EINVAL;
@@ -486,10 +495,7 @@ static ssize_t pin_assignment_show(struct device *dev,

cur = get_count_order(DP_CONF_GET_PIN_ASSIGN(dp->data.conf));

- if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
- assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
- else
- assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
+ assignments = get_current_pin_assignments(dp);

for (i = 0; assignments; assignments >>= 1, i++) {
if (assignments & 1) {
--
2.39.0.314.g84b9a713c41-goog


2023-01-11 02:30:09

by Prashant Malani

[permalink] [raw]
Subject: [PATCH 2/3] usb: typec: altmodes/displayport: Fix pin assignment calculation

Commit c1e5c2f0cb8a ("usb: typec: altmodes/displayport: correct pin
assignment for UFP receptacles") fixed the pin assignment calculation
to take into account whether the peripheral was a plug or a receptacle.

But the "pin_assignments" sysfs logic was not updated. Address this by
using the macros introduced in the aforementioned commit in the sysfs
logic too.

Fixes: c1e5c2f0cb8a ("usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles")
Cc: [email protected]
Cc: Heikki Krogerus <[email protected]>
Signed-off-by: Prashant Malani <[email protected]>
---
drivers/usb/typec/altmodes/displayport.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
index f9d4a7648bc9..c0d65c93cefe 100644
--- a/drivers/usb/typec/altmodes/displayport.c
+++ b/drivers/usb/typec/altmodes/displayport.c
@@ -427,9 +427,9 @@ static const char * const pin_assignments[] = {
static u8 get_current_pin_assignments(struct dp_altmode *dp)
{
if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
- return DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
+ return DP_CAP_PIN_ASSIGN_DFP_D(dp->alt->vdo);
else
- return DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
+ return DP_CAP_PIN_ASSIGN_UFP_D(dp->alt->vdo);
}

static ssize_t
--
2.39.0.314.g84b9a713c41-goog

2023-01-11 02:44:17

by Prashant Malani

[permalink] [raw]
Subject: [PATCH 3/3] usb: typec: altmodes/displayport: Use proper macro for pin assignment check

While looking at the DP configuration VDO to determine the peripheral
configuration, the spec (Table 8-5: DisplayPort Configurations, VESA
DisplayPort Alt Mode Standard v2.0) lists the options as "UFP_U as a DP
Source/Sink Device".

So, use the correct macro while performing this check. Effectively it's
the same as the existing code, but the proposed macro describes the
state a little better.

No functional changes introduced.

Cc: Heikki Krogerus <[email protected]>
Signed-off-by: Prashant Malani <[email protected]>
---
drivers/usb/typec/altmodes/displayport.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
index c0d65c93cefe..746bfbf3d557 100644
--- a/drivers/usb/typec/altmodes/displayport.c
+++ b/drivers/usb/typec/altmodes/displayport.c
@@ -426,7 +426,7 @@ static const char * const pin_assignments[] = {
*/
static u8 get_current_pin_assignments(struct dp_altmode *dp)
{
- if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
+ if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_UFP_U_AS_DFP_D)
return DP_CAP_PIN_ASSIGN_DFP_D(dp->alt->vdo);
else
return DP_CAP_PIN_ASSIGN_UFP_D(dp->alt->vdo);
--
2.39.0.314.g84b9a713c41-goog

2023-01-11 02:48:55

by Benson Leung

[permalink] [raw]
Subject: Re: [PATCH 1/3] usb: typec: altmodes/displayport: Add pin assignment helper

On Wed, Jan 11, 2023 at 02:05:41AM +0000, Prashant Malani wrote:
> The code to extract a peripheral's currently supported Pin Assignments
> is repeated in a couple of locations. Factor it out into a separate
> function.
>
> This will also make it easier to add fixes (we only need to update 1
> location instead of 2).
>
> Fixes: c1e5c2f0cb8a ("usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles")
> Cc: [email protected]
> Cc: Heikki Krogerus <[email protected]>
> Signed-off-by: Prashant Malani <[email protected]>

Reviewed-by: Benson Leung <[email protected]>


> ---
>
> While this patch doesn't fix anything, it is required by the actual
> fix (which is Patch 2/3 in this series). So, I've add the "Fixes" tag
> and "Cc stable" tag to ensure that both patches are picked.
>
> If this is the incorrect approach and there is a better way, my
> apologies, and please let me know the appropriate process.
>
> drivers/usb/typec/altmodes/displayport.c | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index 06fb4732f8cd..f9d4a7648bc9 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -420,6 +420,18 @@ static const char * const pin_assignments[] = {
> [DP_PIN_ASSIGN_F] = "F",
> };
>
> +/*
> + * Helper function to extract a peripheral's currently supported
> + * Pin Assignments from its DisplayPort alternate mode state.
> + */
> +static u8 get_current_pin_assignments(struct dp_altmode *dp)
> +{
> + if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
> + return DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
> + else
> + return DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
> +}
> +
> static ssize_t
> pin_assignment_store(struct device *dev, struct device_attribute *attr,
> const char *buf, size_t size)
> @@ -446,10 +458,7 @@ pin_assignment_store(struct device *dev, struct device_attribute *attr,
> goto out_unlock;
> }
>
> - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
> - assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
> - else
> - assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
> + assignments = get_current_pin_assignments(dp);
>
> if (!(DP_CONF_GET_PIN_ASSIGN(conf) & assignments)) {
> ret = -EINVAL;
> @@ -486,10 +495,7 @@ static ssize_t pin_assignment_show(struct device *dev,
>
> cur = get_count_order(DP_CONF_GET_PIN_ASSIGN(dp->data.conf));
>
> - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
> - assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
> - else
> - assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
> + assignments = get_current_pin_assignments(dp);
>
> for (i = 0; assignments; assignments >>= 1, i++) {
> if (assignments & 1) {
> --
> 2.39.0.314.g84b9a713c41-goog
>

--
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]


Attachments:
(No filename) (3.07 kB)
signature.asc (235.00 B)
Download all attachments

2023-01-11 02:52:24

by Benson Leung

[permalink] [raw]
Subject: Re: [PATCH 3/3] usb: typec: altmodes/displayport: Use proper macro for pin assignment check

On Wed, Jan 11, 2023 at 02:05:43AM +0000, Prashant Malani wrote:
> While looking at the DP configuration VDO to determine the peripheral
> configuration, the spec (Table 8-5: DisplayPort Configurations, VESA
> DisplayPort Alt Mode Standard v2.0) lists the options as "UFP_U as a DP
> Source/Sink Device".
>
> So, use the correct macro while performing this check. Effectively it's
> the same as the existing code, but the proposed macro describes the
> state a little better.
>
> No functional changes introduced.
>
> Cc: Heikki Krogerus <[email protected]>
> Signed-off-by: Prashant Malani <[email protected]>

Reviewed-by: Benson Leung <[email protected]>


> ---
> drivers/usb/typec/altmodes/displayport.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index c0d65c93cefe..746bfbf3d557 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -426,7 +426,7 @@ static const char * const pin_assignments[] = {
> */
> static u8 get_current_pin_assignments(struct dp_altmode *dp)
> {
> - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
> + if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_UFP_U_AS_DFP_D)
> return DP_CAP_PIN_ASSIGN_DFP_D(dp->alt->vdo);
> else
> return DP_CAP_PIN_ASSIGN_UFP_D(dp->alt->vdo);
> --
> 2.39.0.314.g84b9a713c41-goog
>

--
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]


Attachments:
(No filename) (1.59 kB)
signature.asc (235.00 B)
Download all attachments

2023-01-12 14:03:23

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH 1/3] usb: typec: altmodes/displayport: Add pin assignment helper

On Wed, Jan 11, 2023 at 02:05:41AM +0000, Prashant Malani wrote:
> The code to extract a peripheral's currently supported Pin Assignments
> is repeated in a couple of locations. Factor it out into a separate
> function.
>
> This will also make it easier to add fixes (we only need to update 1
> location instead of 2).
>
> Fixes: c1e5c2f0cb8a ("usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles")
> Cc: [email protected]
> Cc: Heikki Krogerus <[email protected]>
> Signed-off-by: Prashant Malani <[email protected]>

Reviewed-by: Heikki Krogerus <[email protected]>

> ---
>
> While this patch doesn't fix anything, it is required by the actual
> fix (which is Patch 2/3 in this series). So, I've add the "Fixes" tag
> and "Cc stable" tag to ensure that both patches are picked.
>
> If this is the incorrect approach and there is a better way, my
> apologies, and please let me know the appropriate process.
>
> drivers/usb/typec/altmodes/displayport.c | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index 06fb4732f8cd..f9d4a7648bc9 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -420,6 +420,18 @@ static const char * const pin_assignments[] = {
> [DP_PIN_ASSIGN_F] = "F",
> };
>
> +/*
> + * Helper function to extract a peripheral's currently supported
> + * Pin Assignments from its DisplayPort alternate mode state.
> + */
> +static u8 get_current_pin_assignments(struct dp_altmode *dp)
> +{
> + if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
> + return DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
> + else
> + return DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
> +}
> +
> static ssize_t
> pin_assignment_store(struct device *dev, struct device_attribute *attr,
> const char *buf, size_t size)
> @@ -446,10 +458,7 @@ pin_assignment_store(struct device *dev, struct device_attribute *attr,
> goto out_unlock;
> }
>
> - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
> - assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
> - else
> - assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
> + assignments = get_current_pin_assignments(dp);
>
> if (!(DP_CONF_GET_PIN_ASSIGN(conf) & assignments)) {
> ret = -EINVAL;
> @@ -486,10 +495,7 @@ static ssize_t pin_assignment_show(struct device *dev,
>
> cur = get_count_order(DP_CONF_GET_PIN_ASSIGN(dp->data.conf));
>
> - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
> - assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
> - else
> - assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
> + assignments = get_current_pin_assignments(dp);
>
> for (i = 0; assignments; assignments >>= 1, i++) {
> if (assignments & 1) {
> --
> 2.39.0.314.g84b9a713c41-goog

--
heikki

2023-01-12 15:22:51

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH 3/3] usb: typec: altmodes/displayport: Use proper macro for pin assignment check

On Wed, Jan 11, 2023 at 02:05:43AM +0000, Prashant Malani wrote:
> While looking at the DP configuration VDO to determine the peripheral
> configuration, the spec (Table 8-5: DisplayPort Configurations, VESA
> DisplayPort Alt Mode Standard v2.0) lists the options as "UFP_U as a DP
> Source/Sink Device".
>
> So, use the correct macro while performing this check. Effectively it's
> the same as the existing code, but the proposed macro describes the
> state a little better.
>
> No functional changes introduced.
>
> Cc: Heikki Krogerus <[email protected]>
> Signed-off-by: Prashant Malani <[email protected]>

Reviewed-by: Heikki Krogerus <[email protected]>

> ---
> drivers/usb/typec/altmodes/displayport.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index c0d65c93cefe..746bfbf3d557 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -426,7 +426,7 @@ static const char * const pin_assignments[] = {
> */
> static u8 get_current_pin_assignments(struct dp_altmode *dp)
> {
> - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
> + if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_UFP_U_AS_DFP_D)
> return DP_CAP_PIN_ASSIGN_DFP_D(dp->alt->vdo);
> else
> return DP_CAP_PIN_ASSIGN_UFP_D(dp->alt->vdo);
> --
> 2.39.0.314.g84b9a713c41-goog

--
heikki

2023-01-12 15:57:33

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH 2/3] usb: typec: altmodes/displayport: Fix pin assignment calculation

On Wed, Jan 11, 2023 at 02:05:42AM +0000, Prashant Malani wrote:
> Commit c1e5c2f0cb8a ("usb: typec: altmodes/displayport: correct pin
> assignment for UFP receptacles") fixed the pin assignment calculation
> to take into account whether the peripheral was a plug or a receptacle.
>
> But the "pin_assignments" sysfs logic was not updated. Address this by
> using the macros introduced in the aforementioned commit in the sysfs
> logic too.
>
> Fixes: c1e5c2f0cb8a ("usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles")
> Cc: [email protected]
> Cc: Heikki Krogerus <[email protected]>
> Signed-off-by: Prashant Malani <[email protected]>

Reviewed-by: Heikki Krogerus <[email protected]>

> ---
> drivers/usb/typec/altmodes/displayport.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index f9d4a7648bc9..c0d65c93cefe 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -427,9 +427,9 @@ static const char * const pin_assignments[] = {
> static u8 get_current_pin_assignments(struct dp_altmode *dp)
> {
> if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
> - return DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
> + return DP_CAP_PIN_ASSIGN_DFP_D(dp->alt->vdo);
> else
> - return DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
> + return DP_CAP_PIN_ASSIGN_UFP_D(dp->alt->vdo);
> }
>
> static ssize_t
> --
> 2.39.0.314.g84b9a713c41-goog

--
heikki