diff mbox series

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

Message ID 20190413203955.10788-2-hdegoede@redhat.com (mailing list archive)
State New, archived
Headers show
Series [1/3] usb: typec: tcpm: Add start_srp_connection_detect callback | expand

Commit Message

Hans de Goede April 13, 2019, 8:39 p.m. UTC
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(+)

Comments

Sergei Shtylyov April 14, 2019, 7:40 a.m. UTC | #1
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. UTC | #2
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
diff mbox series

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;
 }