diff mbox series

usb: typec: don't disable sink or source on initialization

Message ID 20180906192644.24587-1-angus@akkea.ca (mailing list archive)
State New, archived
Headers show
Series usb: typec: don't disable sink or source on initialization | expand

Commit Message

Angus Ainslie Sept. 6, 2018, 7:26 p.m. UTC
If the board is being powered by USB disabling the source and sink
can remove power from the board. Default to source and sink enabled.

Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
---
 drivers/usb/typec/tcpm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Sergei Shtylyov Sept. 7, 2018, 9:39 a.m. UTC | #1
Hello!

On 9/6/2018 10:26 PM, Angus Ainslie (Purism) wrote:

> If the board is being powered by USB disabling the source and sink
> can remove power from the board. Default to source and sink enabled.
> 
> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
> ---
>   drivers/usb/typec/tcpm.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
> index ca7bedb46f7f..a1b819cf31da 100644
> --- a/drivers/usb/typec/tcpm.c
> +++ b/drivers/usb/typec/tcpm.c
> @@ -2462,9 +2462,11 @@ static int tcpm_init_vbus(struct tcpm_port *port)
>   {
>   	int ret;
>   
> -	ret = port->tcpc->set_vbus(port->tcpc, false, false);
> -	port->vbus_source = false;
> -	port->vbus_charge = false;
> +	/* default to source and sink enabled in case USB is our only power
> +	 * source */

    The multi-line comments should look like this:

/*
  * bla
  * bla
  */

[...]

MBR, Sergei
Heikki Krogerus Sept. 7, 2018, 10:34 a.m. UTC | #2
+Guenter

On Thu, Sep 06, 2018 at 01:26:44PM -0600, Angus Ainslie (Purism) wrote:
> If the board is being powered by USB disabling the source and sink
> can remove power from the board. Default to source and sink enabled.
> 
> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
> ---
>  drivers/usb/typec/tcpm.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
> index ca7bedb46f7f..a1b819cf31da 100644
> --- a/drivers/usb/typec/tcpm.c
> +++ b/drivers/usb/typec/tcpm.c
> @@ -2462,9 +2462,11 @@ static int tcpm_init_vbus(struct tcpm_port *port)
>  {
>  	int ret;
>  
> -	ret = port->tcpc->set_vbus(port->tcpc, false, false);
> -	port->vbus_source = false;
> -	port->vbus_charge = false;
> +	/* default to source and sink enabled in case USB is our only power
> +	 * source */
> +	ret = port->tcpc->set_vbus(port->tcpc, true, true);
> +	port->vbus_source = true;
> +	port->vbus_charge = true;
>  	return ret;
>  }
Guenter Roeck Sept. 7, 2018, 12:55 p.m. UTC | #3
On 09/07/2018 03:34 AM, Heikki Krogerus wrote:
> +Guenter
> 
> On Thu, Sep 06, 2018 at 01:26:44PM -0600, Angus Ainslie (Purism) wrote:
>> If the board is being powered by USB disabling the source and sink
>> can remove power from the board. Default to source and sink enabled.
>>

Seems to me that might violate the specification, and cause trouble for systems
where vbus has to be off initially. It may be better to provide this kind of
information as configuration parameter instead of imposing it on everyone.

Guenter

>> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
>> ---
>>   drivers/usb/typec/tcpm.c | 8 +++++---
>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
>> index ca7bedb46f7f..a1b819cf31da 100644
>> --- a/drivers/usb/typec/tcpm.c
>> +++ b/drivers/usb/typec/tcpm.c
>> @@ -2462,9 +2462,11 @@ static int tcpm_init_vbus(struct tcpm_port *port)
>>   {
>>   	int ret;
>>   
>> -	ret = port->tcpc->set_vbus(port->tcpc, false, false);
>> -	port->vbus_source = false;
>> -	port->vbus_charge = false;
>> +	/* default to source and sink enabled in case USB is our only power
>> +	 * source */

I am personally in favor of standard multi-line comments.

>> +	ret = port->tcpc->set_vbus(port->tcpc, true, true);
>> +	port->vbus_source = true;
>> +	port->vbus_charge = true;
>>   	return ret;
>>   }
>
Angus Ainslie Sept. 9, 2018, 2:08 p.m. UTC | #4
Hi Guenter

On 2018-09-07 06:55, Guenter Roeck wrote:
> On 09/07/2018 03:34 AM, Heikki Krogerus wrote:
>> +Guenter
>> 
>> On Thu, Sep 06, 2018 at 01:26:44PM -0600, Angus Ainslie (Purism) 
>> wrote:
>>> If the board is being powered by USB disabling the source and sink
>>> can remove power from the board. Default to source and sink enabled.
>>> 
> 
> Seems to me that might violate the specification, and cause trouble for 
> systems
> where vbus has to be off initially. It may be better to provide this 
> kind of
> information as configuration parameter instead of imposing it on 
> everyone.
> 

It felt like it would not be the correct thing to do either. I've tried 
re-arranging the code in tcpci.c to enable the sink before disabling the 
source but the only way I found to not disable the power was by setting 
both of those to true.

What about adding some device tree entries for the initial vbus state 
and default to false if they are not present ?

init-vbus-source and init-vbus-charge ?

Angus

> Guenter
> 
>>> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
>>> ---
>>>   drivers/usb/typec/tcpm.c | 8 +++++---
>>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>> 
>>> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
>>> index ca7bedb46f7f..a1b819cf31da 100644
>>> --- a/drivers/usb/typec/tcpm.c
>>> +++ b/drivers/usb/typec/tcpm.c
>>> @@ -2462,9 +2462,11 @@ static int tcpm_init_vbus(struct tcpm_port 
>>> *port)
>>>   {
>>>   	int ret;
>>>   -	ret = port->tcpc->set_vbus(port->tcpc, false, false);
>>> -	port->vbus_source = false;
>>> -	port->vbus_charge = false;
>>> +	/* default to source and sink enabled in case USB is our only power
>>> +	 * source */
> 
> I am personally in favor of standard multi-line comments.
> 
>>> +	ret = port->tcpc->set_vbus(port->tcpc, true, true);
>>> +	port->vbus_source = true;
>>> +	port->vbus_charge = true;
>>>   	return ret;
>>>   }
>>
Guenter Roeck Sept. 9, 2018, 2:20 p.m. UTC | #5
On 09/09/2018 07:08 AM, Angus Ainslie wrote:
> Hi Guenter
> 
> On 2018-09-07 06:55, Guenter Roeck wrote:
>> On 09/07/2018 03:34 AM, Heikki Krogerus wrote:
>>> +Guenter
>>>
>>> On Thu, Sep 06, 2018 at 01:26:44PM -0600, Angus Ainslie (Purism) wrote:
>>>> If the board is being powered by USB disabling the source and sink
>>>> can remove power from the board. Default to source and sink enabled.
>>>>
>>
>> Seems to me that might violate the specification, and cause trouble for systems
>> where vbus has to be off initially. It may be better to provide this kind of
>> information as configuration parameter instead of imposing it on everyone.
>>
> 
> It felt like it would not be the correct thing to do either. I've tried re-arranging the code in tcpci.c to enable the sink before disabling the source but the only way I found to not disable the power was by setting both of those to true.
> 
> What about adding some device tree entries for the initial vbus state and default to false if they are not present ?
> 
> init-vbus-source and init-vbus-charge ?
> 

Yes, I think we should do something along that line. Another question is
if we could or should optionally pull the current state from the low level
driver, but that may be secondary.

Thanks,
Guenter

> Angus
> 
>> Guenter
>>
>>>> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
>>>> ---
>>>>   drivers/usb/typec/tcpm.c | 8 +++++---
>>>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
>>>> index ca7bedb46f7f..a1b819cf31da 100644
>>>> --- a/drivers/usb/typec/tcpm.c
>>>> +++ b/drivers/usb/typec/tcpm.c
>>>> @@ -2462,9 +2462,11 @@ static int tcpm_init_vbus(struct tcpm_port *port)
>>>>   {
>>>>       int ret;
>>>>   -    ret = port->tcpc->set_vbus(port->tcpc, false, false);
>>>> -    port->vbus_source = false;
>>>> -    port->vbus_charge = false;
>>>> +    /* default to source and sink enabled in case USB is our only power
>>>> +     * source */
>>
>> I am personally in favor of standard multi-line comments.
>>
>>>> +    ret = port->tcpc->set_vbus(port->tcpc, true, true);
>>>> +    port->vbus_source = true;
>>>> +    port->vbus_charge = true;
>>>>       return ret;
>>>>   }
>>>
> 
>
Angus Ainslie Sept. 9, 2018, 2:36 p.m. UTC | #6
On 2018-09-09 08:20, Guenter Roeck wrote:
> On 09/09/2018 07:08 AM, Angus Ainslie wrote:
>> Hi Guenter
>> 
>> On 2018-09-07 06:55, Guenter Roeck wrote:
>>> On 09/07/2018 03:34 AM, Heikki Krogerus wrote:
>>>> +Guenter
>>>> 
>>>> On Thu, Sep 06, 2018 at 01:26:44PM -0600, Angus Ainslie (Purism) 
>>>> wrote:
>>>>> If the board is being powered by USB disabling the source and sink
>>>>> can remove power from the board. Default to source and sink 
>>>>> enabled.
>>>>> 
>>> 
>>> Seems to me that might violate the specification, and cause trouble 
>>> for systems
>>> where vbus has to be off initially. It may be better to provide this 
>>> kind of
>>> information as configuration parameter instead of imposing it on 
>>> everyone.
>>> 
>> 
>> It felt like it would not be the correct thing to do either. I've 
>> tried re-arranging the code in tcpci.c to enable the sink before 
>> disabling the source but the only way I found to not disable the power 
>> was by setting both of those to true.
>> 
>> What about adding some device tree entries for the initial vbus state 
>> and default to false if they are not present ?
>> 
>> init-vbus-source and init-vbus-charge ?
>> 
> 
> Yes, I think we should do something along that line. Another question 
> is
> if we could or should optionally pull the current state from the low 
> level
> driver, but that may be secondary.
> 

I thought of trying to do that but from reading the "PTN5110N PD PHY 
application programming guide" there didn't seem to be a direct way to 
read those parameters.

> Thanks,
> Guenter
> 
>> Angus
>> 
>>> Guenter
>>> 
>>>>> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
>>>>> ---
>>>>>   drivers/usb/typec/tcpm.c | 8 +++++---
>>>>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>>>> 
>>>>> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
>>>>> index ca7bedb46f7f..a1b819cf31da 100644
>>>>> --- a/drivers/usb/typec/tcpm.c
>>>>> +++ b/drivers/usb/typec/tcpm.c
>>>>> @@ -2462,9 +2462,11 @@ static int tcpm_init_vbus(struct tcpm_port 
>>>>> *port)
>>>>>   {
>>>>>       int ret;
>>>>>   -    ret = port->tcpc->set_vbus(port->tcpc, false, false);
>>>>> -    port->vbus_source = false;
>>>>> -    port->vbus_charge = false;
>>>>> +    /* default to source and sink enabled in case USB is our only 
>>>>> power
>>>>> +     * source */
>>> 
>>> I am personally in favor of standard multi-line comments.
>>> 
>>>>> +    ret = port->tcpc->set_vbus(port->tcpc, true, true);
>>>>> +    port->vbus_source = true;
>>>>> +    port->vbus_charge = true;
>>>>>       return ret;
>>>>>   }
>>>> 
>> 
>>
Guenter Roeck Sept. 9, 2018, 2:43 p.m. UTC | #7
On 09/09/2018 07:36 AM, Angus Ainslie wrote:
> On 2018-09-09 08:20, Guenter Roeck wrote:
>> On 09/09/2018 07:08 AM, Angus Ainslie wrote:
>>> Hi Guenter
>>>
>>> On 2018-09-07 06:55, Guenter Roeck wrote:
>>>> On 09/07/2018 03:34 AM, Heikki Krogerus wrote:
>>>>> +Guenter
>>>>>
>>>>> On Thu, Sep 06, 2018 at 01:26:44PM -0600, Angus Ainslie (Purism) wrote:
>>>>>> If the board is being powered by USB disabling the source and sink
>>>>>> can remove power from the board. Default to source and sink enabled.
>>>>>>
>>>>
>>>> Seems to me that might violate the specification, and cause trouble for systems
>>>> where vbus has to be off initially. It may be better to provide this kind of
>>>> information as configuration parameter instead of imposing it on everyone.
>>>>
>>>
>>> It felt like it would not be the correct thing to do either. I've tried re-arranging the code in tcpci.c to enable the sink before disabling the source but the only way I found to not disable the power was by setting both of those to true.
>>>
>>> What about adding some device tree entries for the initial vbus state and default to false if they are not present ?
>>>
>>> init-vbus-source and init-vbus-charge ?
>>>
>>
>> Yes, I think we should do something along that line. Another question is
>> if we could or should optionally pull the current state from the low level
>> driver, but that may be secondary.
>>
> 
> I thought of trying to do that but from reading the "PTN5110N PD PHY application programming guide" there didn't seem to be a direct way to read those parameters.
> 

Let's put that on the backburner (maybe it works for some other chips)
and go with the devicetree property for now.

Guenter


>> Thanks,
>> Guenter
>>
>>> Angus
>>>
>>>> Guenter
>>>>
>>>>>> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
>>>>>> ---
>>>>>>   drivers/usb/typec/tcpm.c | 8 +++++---
>>>>>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
>>>>>> index ca7bedb46f7f..a1b819cf31da 100644
>>>>>> --- a/drivers/usb/typec/tcpm.c
>>>>>> +++ b/drivers/usb/typec/tcpm.c
>>>>>> @@ -2462,9 +2462,11 @@ static int tcpm_init_vbus(struct tcpm_port *port)
>>>>>>   {
>>>>>>       int ret;
>>>>>>   -    ret = port->tcpc->set_vbus(port->tcpc, false, false);
>>>>>> -    port->vbus_source = false;
>>>>>> -    port->vbus_charge = false;
>>>>>> +    /* default to source and sink enabled in case USB is our only power
>>>>>> +     * source */
>>>>
>>>> I am personally in favor of standard multi-line comments.
>>>>
>>>>>> +    ret = port->tcpc->set_vbus(port->tcpc, true, true);
>>>>>> +    port->vbus_source = true;
>>>>>> +    port->vbus_charge = true;
>>>>>>       return ret;
>>>>>>   }
>>>>>
>>>
>>>
> 
>
diff mbox series

Patch

diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
index ca7bedb46f7f..a1b819cf31da 100644
--- a/drivers/usb/typec/tcpm.c
+++ b/drivers/usb/typec/tcpm.c
@@ -2462,9 +2462,11 @@  static int tcpm_init_vbus(struct tcpm_port *port)
 {
 	int ret;
 
-	ret = port->tcpc->set_vbus(port->tcpc, false, false);
-	port->vbus_source = false;
-	port->vbus_charge = false;
+	/* default to source and sink enabled in case USB is our only power
+	 * source */
+	ret = port->tcpc->set_vbus(port->tcpc, true, true);
+	port->vbus_source = true;
+	port->vbus_charge = true;
 	return ret;
 }