linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] usb: typec: ucsi: Add support for orientation
@ 2025-10-15 13:50 Abel Vesa
  2025-10-15 14:00 ` Greg Kroah-Hartman
  2025-10-21 10:14 ` Heikki Krogerus
  0 siblings, 2 replies; 6+ messages in thread
From: Abel Vesa @ 2025-10-15 13:50 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Abel Vesa

According to UCSI 2.0 specification, the orientation is
part of the connector status payload. So tie up the port
orientation.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/usb/typec/ucsi/ucsi.c | 24 ++++++++++++++++++++++++
 drivers/usb/typec/ucsi/ucsi.h |  3 +++
 2 files changed, 27 insertions(+)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 3995483a0aa097b822046e819f994164d6183b0d..17439ec434d41d24e8e4c7a97d7e6117fd07d950 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1008,6 +1008,28 @@ static int ucsi_check_connector_capability(struct ucsi_connector *con)
 	return ret;
 }
 
+static void ucsi_orientation(struct ucsi_connector *con)
+{
+	if (con->ucsi->version < UCSI_VERSION_2_0)
+		return;
+
+	if (!UCSI_CONSTAT(con, CONNECTED)) {
+		typec_set_orientation(con->port, TYPEC_ORIENTATION_NONE);
+		return;
+	}
+
+	switch (UCSI_CONSTAT(con, ORIENTATION)) {
+	case UCSI_CONSTAT_ORIENTATION_NORMAL:
+		typec_set_orientation(con->port, TYPEC_ORIENTATION_NORMAL);
+		break;
+	case UCSI_CONSTAT_ORIENTATION_REVERSE:
+		typec_set_orientation(con->port, TYPEC_ORIENTATION_REVERSE);
+		break;
+	default:
+		break;
+	}
+}
+
 static void ucsi_pwr_opmode_change(struct ucsi_connector *con)
 {
 	switch (UCSI_CONSTAT(con, PWR_OPMODE)) {
@@ -1258,6 +1280,7 @@ static void ucsi_handle_connector_change(struct work_struct *work)
 		typec_set_pwr_role(con->port, role);
 		ucsi_port_psy_changed(con);
 		ucsi_partner_change(con);
+		ucsi_orientation(con);
 
 		if (UCSI_CONSTAT(con, CONNECTED)) {
 			ucsi_register_partner(con);
@@ -1690,6 +1713,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
 		typec_set_pwr_role(con->port, UCSI_CONSTAT(con, PWR_DIR));
 		ucsi_register_partner(con);
 		ucsi_pwr_opmode_change(con);
+		ucsi_orientation(con);
 		ucsi_port_psy_changed(con);
 		if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
 			ucsi_get_partner_identity(con);
diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
index e301d9012936fb85eaff7f260a862ff099eb77c5..c85175cd001487fa9d66076e608e098d236f5275 100644
--- a/drivers/usb/typec/ucsi/ucsi.h
+++ b/drivers/usb/typec/ucsi/ucsi.h
@@ -360,6 +360,9 @@ struct ucsi_cable_property {
 #define   UCSI_CONSTAT_BC_SLOW_CHARGING		2
 #define   UCSI_CONSTAT_BC_TRICKLE_CHARGING	3
 #define UCSI_CONSTAT_PD_VERSION_V1_2		UCSI_DECLARE_BITFIELD_V1_2(70, 16)
+#define UCSI_CONSTAT_ORIENTATION		UCSI_DECLARE_BITFIELD_V2_0(86, 1)
+#define   UCSI_CONSTAT_ORIENTATION_NORMAL	0
+#define   UCSI_CONSTAT_ORIENTATION_REVERSE	1
 #define UCSI_CONSTAT_PWR_READING_READY_V2_1	UCSI_DECLARE_BITFIELD_V2_1(89, 1)
 #define UCSI_CONSTAT_CURRENT_SCALE_V2_1		UCSI_DECLARE_BITFIELD_V2_1(90, 3)
 #define UCSI_CONSTAT_PEAK_CURRENT_V2_1		UCSI_DECLARE_BITFIELD_V2_1(93, 16)

---
base-commit: 13863a59e410cab46d26751941980dc8f088b9b3
change-id: 20251015-usb-typec-ucsi-orientation-75ed0a2c9ff3

Best regards,
-- 
Abel Vesa <abel.vesa@linaro.org>


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH RFC] usb: typec: ucsi: Add support for orientation
  2025-10-15 13:50 [PATCH RFC] usb: typec: ucsi: Add support for orientation Abel Vesa
@ 2025-10-15 14:00 ` Greg Kroah-Hartman
  2025-10-24 20:19   ` Abel Vesa
  2025-10-21 10:14 ` Heikki Krogerus
  1 sibling, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2025-10-15 14:00 UTC (permalink / raw)
  To: Abel Vesa; +Cc: Heikki Krogerus, linux-usb, linux-kernel

On Wed, Oct 15, 2025 at 04:50:36PM +0300, Abel Vesa wrote:
> According to UCSI 2.0 specification, the orientation is
> part of the connector status payload. So tie up the port
> orientation.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>  drivers/usb/typec/ucsi/ucsi.c | 24 ++++++++++++++++++++++++
>  drivers/usb/typec/ucsi/ucsi.h |  3 +++
>  2 files changed, 27 insertions(+)

Why is this a "RFC"?  What is the request?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RFC] usb: typec: ucsi: Add support for orientation
  2025-10-15 13:50 [PATCH RFC] usb: typec: ucsi: Add support for orientation Abel Vesa
  2025-10-15 14:00 ` Greg Kroah-Hartman
@ 2025-10-21 10:14 ` Heikki Krogerus
  2025-10-21 11:32   ` Greg Kroah-Hartman
  1 sibling, 1 reply; 6+ messages in thread
From: Heikki Krogerus @ 2025-10-21 10:14 UTC (permalink / raw)
  To: Abel Vesa; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On Wed, Oct 15, 2025 at 04:50:36PM +0300, Abel Vesa wrote:
> According to UCSI 2.0 specification, the orientation is
> part of the connector status payload. So tie up the port
> orientation.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>

RFC or not, this looks ok to me.

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/ucsi/ucsi.c | 24 ++++++++++++++++++++++++
>  drivers/usb/typec/ucsi/ucsi.h |  3 +++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 3995483a0aa097b822046e819f994164d6183b0d..17439ec434d41d24e8e4c7a97d7e6117fd07d950 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1008,6 +1008,28 @@ static int ucsi_check_connector_capability(struct ucsi_connector *con)
>  	return ret;
>  }
>  
> +static void ucsi_orientation(struct ucsi_connector *con)
> +{
> +	if (con->ucsi->version < UCSI_VERSION_2_0)
> +		return;
> +
> +	if (!UCSI_CONSTAT(con, CONNECTED)) {
> +		typec_set_orientation(con->port, TYPEC_ORIENTATION_NONE);
> +		return;
> +	}
> +
> +	switch (UCSI_CONSTAT(con, ORIENTATION)) {
> +	case UCSI_CONSTAT_ORIENTATION_NORMAL:
> +		typec_set_orientation(con->port, TYPEC_ORIENTATION_NORMAL);
> +		break;
> +	case UCSI_CONSTAT_ORIENTATION_REVERSE:
> +		typec_set_orientation(con->port, TYPEC_ORIENTATION_REVERSE);
> +		break;
> +	default:
> +		break;
> +	}
> +}
> +
>  static void ucsi_pwr_opmode_change(struct ucsi_connector *con)
>  {
>  	switch (UCSI_CONSTAT(con, PWR_OPMODE)) {
> @@ -1258,6 +1280,7 @@ static void ucsi_handle_connector_change(struct work_struct *work)
>  		typec_set_pwr_role(con->port, role);
>  		ucsi_port_psy_changed(con);
>  		ucsi_partner_change(con);
> +		ucsi_orientation(con);
>  
>  		if (UCSI_CONSTAT(con, CONNECTED)) {
>  			ucsi_register_partner(con);
> @@ -1690,6 +1713,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
>  		typec_set_pwr_role(con->port, UCSI_CONSTAT(con, PWR_DIR));
>  		ucsi_register_partner(con);
>  		ucsi_pwr_opmode_change(con);
> +		ucsi_orientation(con);
>  		ucsi_port_psy_changed(con);
>  		if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
>  			ucsi_get_partner_identity(con);
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index e301d9012936fb85eaff7f260a862ff099eb77c5..c85175cd001487fa9d66076e608e098d236f5275 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -360,6 +360,9 @@ struct ucsi_cable_property {
>  #define   UCSI_CONSTAT_BC_SLOW_CHARGING		2
>  #define   UCSI_CONSTAT_BC_TRICKLE_CHARGING	3
>  #define UCSI_CONSTAT_PD_VERSION_V1_2		UCSI_DECLARE_BITFIELD_V1_2(70, 16)
> +#define UCSI_CONSTAT_ORIENTATION		UCSI_DECLARE_BITFIELD_V2_0(86, 1)
> +#define   UCSI_CONSTAT_ORIENTATION_NORMAL	0
> +#define   UCSI_CONSTAT_ORIENTATION_REVERSE	1
>  #define UCSI_CONSTAT_PWR_READING_READY_V2_1	UCSI_DECLARE_BITFIELD_V2_1(89, 1)
>  #define UCSI_CONSTAT_CURRENT_SCALE_V2_1		UCSI_DECLARE_BITFIELD_V2_1(90, 3)
>  #define UCSI_CONSTAT_PEAK_CURRENT_V2_1		UCSI_DECLARE_BITFIELD_V2_1(93, 16)
> 
> ---
> base-commit: 13863a59e410cab46d26751941980dc8f088b9b3
> change-id: 20251015-usb-typec-ucsi-orientation-75ed0a2c9ff3
> 
> Best regards,
> -- 
> Abel Vesa <abel.vesa@linaro.org>

-- 
heikki

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RFC] usb: typec: ucsi: Add support for orientation
  2025-10-21 10:14 ` Heikki Krogerus
@ 2025-10-21 11:32   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2025-10-21 11:32 UTC (permalink / raw)
  To: Heikki Krogerus; +Cc: Abel Vesa, linux-usb, linux-kernel

On Tue, Oct 21, 2025 at 01:14:11PM +0300, Heikki Krogerus wrote:
> On Wed, Oct 15, 2025 at 04:50:36PM +0300, Abel Vesa wrote:
> > According to UCSI 2.0 specification, the orientation is
> > part of the connector status payload. So tie up the port
> > orientation.
> > 
> > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> 
> RFC or not, this looks ok to me.
> 
> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

For obvious reasons, I don't apply RFCs as they imply that the submitter
still has some questions that need to be answered :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RFC] usb: typec: ucsi: Add support for orientation
  2025-10-15 14:00 ` Greg Kroah-Hartman
@ 2025-10-24 20:19   ` Abel Vesa
  2025-10-25  7:59     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 6+ messages in thread
From: Abel Vesa @ 2025-10-24 20:19 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Heikki Krogerus, linux-usb, linux-kernel

On 25-10-15 16:00:43, Greg Kroah-Hartman wrote:
> On Wed, Oct 15, 2025 at 04:50:36PM +0300, Abel Vesa wrote:
> > According to UCSI 2.0 specification, the orientation is
> > part of the connector status payload. So tie up the port
> > orientation.
> > 
> > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > ---
> >  drivers/usb/typec/ucsi/ucsi.c | 24 ++++++++++++++++++++++++
> >  drivers/usb/typec/ucsi/ucsi.h |  3 +++
> >  2 files changed, 27 insertions(+)
> 
> Why is this a "RFC"?  What is the request?
> 

My bad. Posted as an RFC since I wasn't sure if I tied the ucsi_orientation
correctly, meaning in all the right places.

Let me know if you want me to respin this as a proper patch.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RFC] usb: typec: ucsi: Add support for orientation
  2025-10-24 20:19   ` Abel Vesa
@ 2025-10-25  7:59     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2025-10-25  7:59 UTC (permalink / raw)
  To: Abel Vesa; +Cc: Heikki Krogerus, linux-usb, linux-kernel

On Fri, Oct 24, 2025 at 11:19:46PM +0300, Abel Vesa wrote:
> On 25-10-15 16:00:43, Greg Kroah-Hartman wrote:
> > On Wed, Oct 15, 2025 at 04:50:36PM +0300, Abel Vesa wrote:
> > > According to UCSI 2.0 specification, the orientation is
> > > part of the connector status payload. So tie up the port
> > > orientation.
> > > 
> > > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > > ---
> > >  drivers/usb/typec/ucsi/ucsi.c | 24 ++++++++++++++++++++++++
> > >  drivers/usb/typec/ucsi/ucsi.h |  3 +++
> > >  2 files changed, 27 insertions(+)
> > 
> > Why is this a "RFC"?  What is the request?
> > 
> 
> My bad. Posted as an RFC since I wasn't sure if I tied the ucsi_orientation
> correctly, meaning in all the right places.

That's great, in the future try asking that question so we know what to
look for :)

> Let me know if you want me to respin this as a proper patch.

Please do, it's long gone from my queue.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-10-25  7:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-15 13:50 [PATCH RFC] usb: typec: ucsi: Add support for orientation Abel Vesa
2025-10-15 14:00 ` Greg Kroah-Hartman
2025-10-24 20:19   ` Abel Vesa
2025-10-25  7:59     ` Greg Kroah-Hartman
2025-10-21 10:14 ` Heikki Krogerus
2025-10-21 11:32   ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).