linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v2,3/8] usb: typec: fusb302: Fold fusb302_set_cc_pull into tcpm_set_cc
@ 2019-03-07 16:36 Hans de Goede
  0 siblings, 0 replies; 2+ messages in thread
From: Hans de Goede @ 2019-03-07 16:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Guenter Roeck, Heikki Krogerus
  Cc: Hans de Goede, linux-usb

After the recent cleanups, tcpm_set_cc is the only caller of
fusb302_set_cc_pull, fold fusb302_set_cc_pull directly into
tcpm_set_cc for a nice cleanup.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/usb/typec/tcpm/fusb302.c | 51 ++++++++------------------------
 1 file changed, 13 insertions(+), 38 deletions(-)

diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
index bcb38e397712..cb6637e82f32 100644
--- a/drivers/usb/typec/tcpm/fusb302.c
+++ b/drivers/usb/typec/tcpm/fusb302.c
@@ -518,31 +518,6 @@ static int tcpm_get_current_limit(struct tcpc_dev *dev)
 	return current_limit;
 }
 
-static int fusb302_set_cc_pull(struct fusb302_chip *chip,
-			       bool pull_up, bool pull_down)
-{
-	int ret = 0;
-	u8 data = 0x00;
-	u8 mask = FUSB_REG_SWITCHES0_CC1_PU_EN |
-		  FUSB_REG_SWITCHES0_CC2_PU_EN |
-		  FUSB_REG_SWITCHES0_CC1_PD_EN |
-		  FUSB_REG_SWITCHES0_CC2_PD_EN;
-
-	if (pull_up)
-		data |= (chip->cc_polarity == TYPEC_POLARITY_CC1) ?
-			FUSB_REG_SWITCHES0_CC1_PU_EN :
-			FUSB_REG_SWITCHES0_CC2_PU_EN;
-	if (pull_down)
-		data |= FUSB_REG_SWITCHES0_CC1_PD_EN |
-			FUSB_REG_SWITCHES0_CC2_PD_EN;
-	ret = fusb302_i2c_mask_write(chip, FUSB_REG_SWITCHES0,
-				     mask, data);
-	if (ret < 0)
-		return ret;
-
-	return ret;
-}
-
 static int fusb302_set_src_current(struct fusb302_chip *chip,
 				   enum src_current_status status)
 {
@@ -674,27 +649,30 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc)
 {
 	struct fusb302_chip *chip = container_of(dev, struct fusb302_chip,
 						 tcpc_dev);
+	u8 switches0_mask = FUSB_REG_SWITCHES0_CC1_PU_EN |
+			    FUSB_REG_SWITCHES0_CC2_PU_EN |
+			    FUSB_REG_SWITCHES0_CC1_PD_EN |
+			    FUSB_REG_SWITCHES0_CC2_PD_EN;
+	u8 switches0_data = 0x00;
 	int ret = 0;
-	bool pull_up, pull_down;
 	enum toggling_mode mode;
 
 	mutex_lock(&chip->lock);
 	switch (cc) {
 	case TYPEC_CC_OPEN:
-		pull_up = false;
-		pull_down = false;
 		mode = TOGGLING_MODE_OFF;
 		break;
 	case TYPEC_CC_RD:
-		pull_up = false;
-		pull_down = true;
+		switches0_data |= FUSB_REG_SWITCHES0_CC1_PD_EN |
+				  FUSB_REG_SWITCHES0_CC2_PD_EN;
 		mode = TOGGLING_MODE_SNK;
 		break;
 	case TYPEC_CC_RP_DEF:
 	case TYPEC_CC_RP_1_5:
 	case TYPEC_CC_RP_3_0:
-		pull_up = true;
-		pull_down = false;
+		switches0_data |= (chip->cc_polarity == TYPEC_POLARITY_CC1) ?
+				  FUSB_REG_SWITCHES0_CC1_PU_EN :
+				  FUSB_REG_SWITCHES0_CC2_PU_EN;
 		mode = TOGGLING_MODE_SRC;
 		break;
 	default:
@@ -706,13 +684,10 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc)
 
 	fusb302_log(chip, "cc := %s", typec_cc_status_name[cc]);
 
-	ret = fusb302_set_cc_pull(chip, pull_up, pull_down);
+	ret = fusb302_i2c_mask_write(chip, FUSB_REG_SWITCHES0,
+				     switches0_mask, switches0_data);
 	if (ret < 0) {
-		fusb302_log(chip,
-			    "cannot set cc pulling up %s, down %s, ret = %d",
-			    pull_up ? "True" : "False",
-			    pull_down ? "True" : "False",
-			    ret);
+		fusb302_log(chip, "cannot set pull-up/-down, ret = %d", ret);
 		goto done;
 	}
 	/* reset the cc status */

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

* [v2,3/8] usb: typec: fusb302: Fold fusb302_set_cc_pull into tcpm_set_cc
@ 2019-03-07 18:14 Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2019-03-07 18:14 UTC (permalink / raw)
  To: Hans de Goede; +Cc: Greg Kroah-Hartman, Heikki Krogerus, linux-usb

On Thu, Mar 07, 2019 at 05:36:02PM +0100, Hans de Goede wrote:
> After the recent cleanups, tcpm_set_cc is the only caller of
> fusb302_set_cc_pull, fold fusb302_set_cc_pull directly into
> tcpm_set_cc for a nice cleanup.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/usb/typec/tcpm/fusb302.c | 51 ++++++++------------------------
>  1 file changed, 13 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
> index bcb38e397712..cb6637e82f32 100644
> --- a/drivers/usb/typec/tcpm/fusb302.c
> +++ b/drivers/usb/typec/tcpm/fusb302.c
> @@ -518,31 +518,6 @@ static int tcpm_get_current_limit(struct tcpc_dev *dev)
>  	return current_limit;
>  }
>  
> -static int fusb302_set_cc_pull(struct fusb302_chip *chip,
> -			       bool pull_up, bool pull_down)
> -{
> -	int ret = 0;
> -	u8 data = 0x00;
> -	u8 mask = FUSB_REG_SWITCHES0_CC1_PU_EN |
> -		  FUSB_REG_SWITCHES0_CC2_PU_EN |
> -		  FUSB_REG_SWITCHES0_CC1_PD_EN |
> -		  FUSB_REG_SWITCHES0_CC2_PD_EN;
> -
> -	if (pull_up)
> -		data |= (chip->cc_polarity == TYPEC_POLARITY_CC1) ?
> -			FUSB_REG_SWITCHES0_CC1_PU_EN :
> -			FUSB_REG_SWITCHES0_CC2_PU_EN;
> -	if (pull_down)
> -		data |= FUSB_REG_SWITCHES0_CC1_PD_EN |
> -			FUSB_REG_SWITCHES0_CC2_PD_EN;
> -	ret = fusb302_i2c_mask_write(chip, FUSB_REG_SWITCHES0,
> -				     mask, data);
> -	if (ret < 0)
> -		return ret;
> -
> -	return ret;
> -}
> -
>  static int fusb302_set_src_current(struct fusb302_chip *chip,
>  				   enum src_current_status status)
>  {
> @@ -674,27 +649,30 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc)
>  {
>  	struct fusb302_chip *chip = container_of(dev, struct fusb302_chip,
>  						 tcpc_dev);
> +	u8 switches0_mask = FUSB_REG_SWITCHES0_CC1_PU_EN |
> +			    FUSB_REG_SWITCHES0_CC2_PU_EN |
> +			    FUSB_REG_SWITCHES0_CC1_PD_EN |
> +			    FUSB_REG_SWITCHES0_CC2_PD_EN;
> +	u8 switches0_data = 0x00;
>  	int ret = 0;
> -	bool pull_up, pull_down;
>  	enum toggling_mode mode;
>  
>  	mutex_lock(&chip->lock);
>  	switch (cc) {
>  	case TYPEC_CC_OPEN:
> -		pull_up = false;
> -		pull_down = false;
>  		mode = TOGGLING_MODE_OFF;
>  		break;
>  	case TYPEC_CC_RD:
> -		pull_up = false;
> -		pull_down = true;
> +		switches0_data |= FUSB_REG_SWITCHES0_CC1_PD_EN |
> +				  FUSB_REG_SWITCHES0_CC2_PD_EN;
>  		mode = TOGGLING_MODE_SNK;
>  		break;
>  	case TYPEC_CC_RP_DEF:
>  	case TYPEC_CC_RP_1_5:
>  	case TYPEC_CC_RP_3_0:
> -		pull_up = true;
> -		pull_down = false;
> +		switches0_data |= (chip->cc_polarity == TYPEC_POLARITY_CC1) ?
> +				  FUSB_REG_SWITCHES0_CC1_PU_EN :
> +				  FUSB_REG_SWITCHES0_CC2_PU_EN;
>  		mode = TOGGLING_MODE_SRC;
>  		break;
>  	default:
> @@ -706,13 +684,10 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc)
>  
>  	fusb302_log(chip, "cc := %s", typec_cc_status_name[cc]);
>  
> -	ret = fusb302_set_cc_pull(chip, pull_up, pull_down);
> +	ret = fusb302_i2c_mask_write(chip, FUSB_REG_SWITCHES0,
> +				     switches0_mask, switches0_data);
>  	if (ret < 0) {
> -		fusb302_log(chip,
> -			    "cannot set cc pulling up %s, down %s, ret = %d",
> -			    pull_up ? "True" : "False",
> -			    pull_down ? "True" : "False",
> -			    ret);
> +		fusb302_log(chip, "cannot set pull-up/-down, ret = %d", ret);
>  		goto done;
>  	}
>  	/* reset the cc status */
> -- 
> 2.20.1
>

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

end of thread, other threads:[~2019-03-07 18:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-07 18:14 [v2,3/8] usb: typec: fusb302: Fold fusb302_set_cc_pull into tcpm_set_cc Guenter Roeck
  -- strict thread matches above, loose matches on Subject: below --
2019-03-07 16:36 Hans de Goede

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).