diff mbox series

[1/3] usb: typec: ucsi: call typec_set_mode on non-altmode partner change

Message ID 20230614-topic-sm8550-upstream-type-c-audio-v1-1-15a92565146b@linaro.org
State New
Headers show
Series typec: support Audio Accessory mode on FSA4480 | expand

Commit Message

Neil Armstrong June 14, 2023, 1:10 p.m. UTC
Add support for calling typec_set_mode() for the DEBUG, AUDIO
accessory modes.

Let's also call typec_set_mode() for USB as default and SAFE
when partner is disconnected.

The USB state is only called when ALT mode is specifically
not specified by the partner status flags in order
to leave the altmode handlers setup the proper mode to
switches, muxes and retimers.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/usb/typec/ucsi/ucsi.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Heikki Krogerus June 26, 2023, 8:12 a.m. UTC | #1
Hi Neil,

Sorry to keep you waiting.

On Wed, Jun 14, 2023 at 03:10:39PM +0200, Neil Armstrong wrote:
> Add support for calling typec_set_mode() for the DEBUG, AUDIO
> accessory modes.
> 
> Let's also call typec_set_mode() for USB as default and SAFE
> when partner is disconnected.
> 
> The USB state is only called when ALT mode is specifically
> not specified by the partner status flags in order
> to leave the altmode handlers setup the proper mode to
> switches, muxes and retimers.
> 
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
> ---
>  drivers/usb/typec/ucsi/ucsi.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 2b472ec01dc4..44f43cdea5c1 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -809,6 +809,23 @@ static void ucsi_partner_change(struct ucsi_connector *con)
>  		break;
>  	}
>  
> +	if (con->status.flags & UCSI_CONSTAT_CONNECTED) {
> +		switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) {
> +		case UCSI_CONSTAT_PARTNER_TYPE_DEBUG:
> +			typec_set_mode(con->port, TYPEC_MODE_DEBUG);
> +			break;
> +		case UCSI_CONSTAT_PARTNER_TYPE_AUDIO:
> +			typec_set_mode(con->port, TYPEC_MODE_AUDIO);
> +			break;
> +		default:
> +			if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) ==
> +					UCSI_CONSTAT_PARTNER_FLAG_USB)
> +				typec_set_mode(con->port, TYPEC_STATE_USB);
> +		}
> +	} else {
> +		typec_set_mode(con->port, TYPEC_STATE_SAFE);
> +	}

Can you do that (set safe mode) in ucsi_unregister_partner() instead?

thanks,
Neil Armstrong June 26, 2023, 1:23 p.m. UTC | #2
Hi,

On 26/06/2023 10:12, Heikki Krogerus wrote:
> Hi Neil,
> 
> Sorry to keep you waiting.

No problem, thanks for reviewing my patches!

> 
> On Wed, Jun 14, 2023 at 03:10:39PM +0200, Neil Armstrong wrote:
>> Add support for calling typec_set_mode() for the DEBUG, AUDIO
>> accessory modes.
>>
>> Let's also call typec_set_mode() for USB as default and SAFE
>> when partner is disconnected.
>>
>> The USB state is only called when ALT mode is specifically
>> not specified by the partner status flags in order
>> to leave the altmode handlers setup the proper mode to
>> switches, muxes and retimers.
>>
>> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
>> ---
>>   drivers/usb/typec/ucsi/ucsi.c | 17 +++++++++++++++++
>>   1 file changed, 17 insertions(+)
>>
>> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
>> index 2b472ec01dc4..44f43cdea5c1 100644
>> --- a/drivers/usb/typec/ucsi/ucsi.c
>> +++ b/drivers/usb/typec/ucsi/ucsi.c
>> @@ -809,6 +809,23 @@ static void ucsi_partner_change(struct ucsi_connector *con)
>>   		break;
>>   	}
>>   
>> +	if (con->status.flags & UCSI_CONSTAT_CONNECTED) {
>> +		switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) {
>> +		case UCSI_CONSTAT_PARTNER_TYPE_DEBUG:
>> +			typec_set_mode(con->port, TYPEC_MODE_DEBUG);
>> +			break;
>> +		case UCSI_CONSTAT_PARTNER_TYPE_AUDIO:
>> +			typec_set_mode(con->port, TYPEC_MODE_AUDIO);
>> +			break;
>> +		default:
>> +			if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) ==
>> +					UCSI_CONSTAT_PARTNER_FLAG_USB)
>> +				typec_set_mode(con->port, TYPEC_STATE_USB);
>> +		}
>> +	} else {
>> +		typec_set_mode(con->port, TYPEC_STATE_SAFE);
>> +	}
> 
> Can you do that (set safe mode) in ucsi_unregister_partner() instead?

It seems greg already landed the patch into usb-next, but I can send a fix to
move it to unregister

Neil

> 
> thanks,
>
Greg KH June 26, 2023, 2:43 p.m. UTC | #3
On Mon, Jun 26, 2023 at 03:23:11PM +0200, Neil Armstrong wrote:
> Hi,
> 
> On 26/06/2023 10:12, Heikki Krogerus wrote:
> > Hi Neil,
> > 
> > Sorry to keep you waiting.
> 
> No problem, thanks for reviewing my patches!
> 
> > 
> > On Wed, Jun 14, 2023 at 03:10:39PM +0200, Neil Armstrong wrote:
> > > Add support for calling typec_set_mode() for the DEBUG, AUDIO
> > > accessory modes.
> > > 
> > > Let's also call typec_set_mode() for USB as default and SAFE
> > > when partner is disconnected.
> > > 
> > > The USB state is only called when ALT mode is specifically
> > > not specified by the partner status flags in order
> > > to leave the altmode handlers setup the proper mode to
> > > switches, muxes and retimers.
> > > 
> > > Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
> > > ---
> > >   drivers/usb/typec/ucsi/ucsi.c | 17 +++++++++++++++++
> > >   1 file changed, 17 insertions(+)
> > > 
> > > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> > > index 2b472ec01dc4..44f43cdea5c1 100644
> > > --- a/drivers/usb/typec/ucsi/ucsi.c
> > > +++ b/drivers/usb/typec/ucsi/ucsi.c
> > > @@ -809,6 +809,23 @@ static void ucsi_partner_change(struct ucsi_connector *con)
> > >   		break;
> > >   	}
> > > +	if (con->status.flags & UCSI_CONSTAT_CONNECTED) {
> > > +		switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) {
> > > +		case UCSI_CONSTAT_PARTNER_TYPE_DEBUG:
> > > +			typec_set_mode(con->port, TYPEC_MODE_DEBUG);
> > > +			break;
> > > +		case UCSI_CONSTAT_PARTNER_TYPE_AUDIO:
> > > +			typec_set_mode(con->port, TYPEC_MODE_AUDIO);
> > > +			break;
> > > +		default:
> > > +			if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) ==
> > > +					UCSI_CONSTAT_PARTNER_FLAG_USB)
> > > +				typec_set_mode(con->port, TYPEC_STATE_USB);
> > > +		}
> > > +	} else {
> > > +		typec_set_mode(con->port, TYPEC_STATE_SAFE);
> > > +	}
> > 
> > Can you do that (set safe mode) in ucsi_unregister_partner() instead?
> 
> It seems greg already landed the patch into usb-next, but I can send a fix to
> move it to unregister

Yes please.
diff mbox series

Patch

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 2b472ec01dc4..44f43cdea5c1 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -809,6 +809,23 @@  static void ucsi_partner_change(struct ucsi_connector *con)
 		break;
 	}
 
+	if (con->status.flags & UCSI_CONSTAT_CONNECTED) {
+		switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) {
+		case UCSI_CONSTAT_PARTNER_TYPE_DEBUG:
+			typec_set_mode(con->port, TYPEC_MODE_DEBUG);
+			break;
+		case UCSI_CONSTAT_PARTNER_TYPE_AUDIO:
+			typec_set_mode(con->port, TYPEC_MODE_AUDIO);
+			break;
+		default:
+			if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) ==
+					UCSI_CONSTAT_PARTNER_FLAG_USB)
+				typec_set_mode(con->port, TYPEC_STATE_USB);
+		}
+	} else {
+		typec_set_mode(con->port, TYPEC_STATE_SAFE);
+	}
+
 	/* Only notify USB controller if partner supports USB data */
 	if (!(UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) & UCSI_CONSTAT_PARTNER_FLAG_USB))
 		u_role = USB_ROLE_NONE;