Patchwork [2/3] usb: typec: fusb302: Implement start_srp_connection_detect

login
register
mail settings
Submitter Hans de Goede
Date April 13, 2019, 8:39 p.m.
Message ID <20190413203955.10788-2-hdegoede@redhat.com>
Download mbox | patch
Permalink /patch/772547/
State New
Headers show

Comments

Hans de Goede - April 13, 2019, 8:39 p.m.
When in single role port mode, we most start single-role toggling to
get an interrupt when a device / cable gets plugged into the port.

This commit implements the tcpc_dev start_srp_connection_detect callback
for this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/usb/typec/tcpm/fusb302.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
Sergei Shtylyov - April 14, 2019, 7:40 a.m.
Hello!

On 13.04.2019 23:39, Hans de Goede wrote:

> When in single role port mode, we most start single-role toggling to

    Must, perhaps?

> get an interrupt when a device / cable gets plugged into the port.
> 
> This commit implements the tcpc_dev start_srp_connection_detect callback
> for this.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>   drivers/usb/typec/tcpm/fusb302.c | 30 ++++++++++++++++++++++++++++++
>   1 file changed, 30 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
> index 6ea6199caafa..30413a45104f 100644
> --- a/drivers/usb/typec/tcpm/fusb302.c
> +++ b/drivers/usb/typec/tcpm/fusb302.c
> @@ -876,6 +876,34 @@ static int tcpm_set_roles(struct tcpc_dev *dev, bool attached,
>   	return ret;
>   }
>   
> +static int tcpm_start_srp_connection_detect(struct tcpc_dev *dev,
> +					    enum typec_cc_status cc)
> +{
> +	struct fusb302_chip *chip = container_of(dev, struct fusb302_chip,
> +						 tcpc_dev);
> +	int ret = 0;

    This initializer is useless.

> +
> +	mutex_lock(&chip->lock);
> +	ret = fusb302_set_src_current(chip, cc_src_current[cc]);
> +	if (ret < 0) {
> +		fusb302_log(chip, "unable to set src current %s, ret=%d",
> +			    typec_cc_status_name[cc], ret);
> +		goto done;
> +	}
> +	ret = fusb302_set_toggling(chip, (cc == TYPEC_CC_RD) ?
> +					 TOGGLING_MODE_SNK : TOGGLING_MODE_SRC);
> +	if (ret < 0) {
> +		fusb302_log(chip,
> +			    "unable to start srp toggling, ret=%d", ret);
> +		goto done;
> +	}
> +	fusb302_log(chip, "start srp toggling");
> +done:
> +	mutex_unlock(&chip->lock);
> +
> +	return ret;
> +}
> +
>   static int tcpm_start_drp_toggling(struct tcpc_dev *dev,
>   				   enum typec_cc_status cc)
>   {
[...]

MBR, Sergei
Hans de Goede - April 16, 2019, 8:06 p.m.
Hi,

Thank you for the review.

On 14-04-19 09:40, Sergei Shtylyov wrote:
> Hello!
> 
> On 13.04.2019 23:39, Hans de Goede wrote:
> 
>> When in single role port mode, we most start single-role toggling to
> 
>     Must, perhaps?

Right, fixed for the upcoming v2 of the patch-set.

>> get an interrupt when a device / cable gets plugged into the port.
>>
>> This commit implements the tcpc_dev start_srp_connection_detect callback
>> for this.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>   drivers/usb/typec/tcpm/fusb302.c | 30 ++++++++++++++++++++++++++++++
>>   1 file changed, 30 insertions(+)
>>
>> diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
>> index 6ea6199caafa..30413a45104f 100644
>> --- a/drivers/usb/typec/tcpm/fusb302.c
>> +++ b/drivers/usb/typec/tcpm/fusb302.c
>> @@ -876,6 +876,34 @@ static int tcpm_set_roles(struct tcpc_dev *dev, bool attached,
>>       return ret;
>>   }
>> +static int tcpm_start_srp_connection_detect(struct tcpc_dev *dev,
>> +                        enum typec_cc_status cc)
>> +{
>> +    struct fusb302_chip *chip = container_of(dev, struct fusb302_chip,
>> +                         tcpc_dev);
>> +    int ret = 0;
> 
>     This initializer is useless.

Ack, this part is gone for v2 of the patch though.

Regards,

Hans



> 
>> +
>> +    mutex_lock(&chip->lock);
>> +    ret = fusb302_set_src_current(chip, cc_src_current[cc]);
>> +    if (ret < 0) {
>> +        fusb302_log(chip, "unable to set src current %s, ret=%d",
>> +                typec_cc_status_name[cc], ret);
>> +        goto done;
>> +    }
>> +    ret = fusb302_set_toggling(chip, (cc == TYPEC_CC_RD) ?
>> +                     TOGGLING_MODE_SNK : TOGGLING_MODE_SRC);
>> +    if (ret < 0) {
>> +        fusb302_log(chip,
>> +                "unable to start srp toggling, ret=%d", ret);
>> +        goto done;
>> +    }
>> +    fusb302_log(chip, "start srp toggling");
>> +done:
>> +    mutex_unlock(&chip->lock);
>> +
>> +    return ret;
>> +}
>> +
>>   static int tcpm_start_drp_toggling(struct tcpc_dev *dev,
>>                      enum typec_cc_status cc)
>>   {
> [...]
> 
> MBR, Sergei

Patch

diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
index 6ea6199caafa..30413a45104f 100644
--- a/drivers/usb/typec/tcpm/fusb302.c
+++ b/drivers/usb/typec/tcpm/fusb302.c
@@ -876,6 +876,34 @@  static int tcpm_set_roles(struct tcpc_dev *dev, bool attached,
 	return ret;
 }
 
+static int tcpm_start_srp_connection_detect(struct tcpc_dev *dev,
+					    enum typec_cc_status cc)
+{
+	struct fusb302_chip *chip = container_of(dev, struct fusb302_chip,
+						 tcpc_dev);
+	int ret = 0;
+
+	mutex_lock(&chip->lock);
+	ret = fusb302_set_src_current(chip, cc_src_current[cc]);
+	if (ret < 0) {
+		fusb302_log(chip, "unable to set src current %s, ret=%d",
+			    typec_cc_status_name[cc], ret);
+		goto done;
+	}
+	ret = fusb302_set_toggling(chip, (cc == TYPEC_CC_RD) ?
+					 TOGGLING_MODE_SNK : TOGGLING_MODE_SRC);
+	if (ret < 0) {
+		fusb302_log(chip,
+			    "unable to start srp toggling, ret=%d", ret);
+		goto done;
+	}
+	fusb302_log(chip, "start srp toggling");
+done:
+	mutex_unlock(&chip->lock);
+
+	return ret;
+}
+
 static int tcpm_start_drp_toggling(struct tcpc_dev *dev,
 				   enum typec_cc_status cc)
 {
@@ -1095,6 +1123,8 @@  static void init_tcpc_dev(struct tcpc_dev *fusb302_tcpc_dev)
 	fusb302_tcpc_dev->set_pd_rx = tcpm_set_pd_rx;
 	fusb302_tcpc_dev->set_roles = tcpm_set_roles;
 	fusb302_tcpc_dev->start_drp_toggling = tcpm_start_drp_toggling;
+	fusb302_tcpc_dev->start_srp_connection_detect =
+					tcpm_start_srp_connection_detect;
 	fusb302_tcpc_dev->pd_transmit = tcpm_pd_transmit;
 }