diff mbox

[v4,2/5] usb: typec: fusb302: remove max_snk_* for sink config

Message ID 1523629125-16332-3-git-send-email-jun.li@nxp.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jun Li April 13, 2018, 2:18 p.m. UTC
Since max_snk_* is to be deprecated, so remove max_snk_* by adding a
variable PDO for sink config.

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
---
 drivers/usb/typec/fusb302/fusb302.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

Comments

Guenter Roeck April 13, 2018, 4:03 p.m. UTC | #1
On Fri, Apr 13, 2018 at 10:18:42PM +0800, Li Jun wrote:
> Since max_snk_* is to be deprecated, so remove max_snk_* by adding a
> variable PDO for sink config.

max_snk or max_sink ?

> 
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
> Signed-off-by: Li Jun <jun.li@nxp.com>
> ---
>  drivers/usb/typec/fusb302/fusb302.c | 34 ++++++++++++++++++++--------------
>  1 file changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/usb/typec/fusb302/fusb302.c b/drivers/usb/typec/fusb302/fusb302.c
> index 7036171..893f9e5 100644
> --- a/drivers/usb/typec/fusb302/fusb302.c
> +++ b/drivers/usb/typec/fusb302/fusb302.c
> @@ -120,6 +120,7 @@ struct fusb302_chip {
>  	enum typec_cc_polarity cc_polarity;
>  	enum typec_cc_status cc1;
>  	enum typec_cc_status cc2;
> +	u32 snk_pdo[PDO_MAX_OBJECTS];
>  
>  #ifdef CONFIG_DEBUG_FS
>  	struct dentry *dentry;
> @@ -1212,11 +1213,6 @@ static const u32 snk_pdo[] = {
>  static const struct tcpc_config fusb302_tcpc_config = {
>  	.src_pdo = src_pdo,
>  	.nr_src_pdo = ARRAY_SIZE(src_pdo),
> -	.snk_pdo = snk_pdo,
> -	.nr_snk_pdo = ARRAY_SIZE(snk_pdo),
> -	.max_snk_mv = 5000,
> -	.max_snk_ma = 3000,
> -	.max_snk_mw = 15000,
>  	.operating_snk_mw = 2500,
>  	.type = TYPEC_PORT_DRP,
>  	.data = TYPEC_PORT_DRD,
> @@ -1756,6 +1752,21 @@ static int init_gpio(struct fusb302_chip *chip)
>  	return 0;
>  }
>  
> +static int fusb302_composite_snk_pdo_array(struct fusb302_chip *chip)
> +{
> +	struct device *dev = chip->dev;
> +	u32 max_uv, max_ua;
> +
> +	chip->snk_pdo[0] = PDO_FIXED(5000, 400, PDO_FIXED_FLAGS);
> +
> +	if (device_property_read_u32(dev, "fcs,max-sink-microvolt", &max_uv) ||
> +		device_property_read_u32(dev, "fcs,max-sink-microamp", &max_ua))
> +		return 1;

Aren't those properties removed in the next patch ? If this is on purpose,
it should be documented.

> +
> +	chip->snk_pdo[1] = PDO_VAR(5000, max_uv / 1000, max_ua / 1000);
> +	return 2;
> +}
> +
>  static int fusb302_probe(struct i2c_client *client,
>  			 const struct i2c_device_id *id)
>  {
> @@ -1784,18 +1795,13 @@ static int fusb302_probe(struct i2c_client *client,
>  	chip->tcpc_dev.config = &chip->tcpc_config;
>  	mutex_init(&chip->lock);
>  
> -	if (!device_property_read_u32(dev, "fcs,max-sink-microvolt", &v))
> -		chip->tcpc_config.max_snk_mv = v / 1000;
> -
> -	if (!device_property_read_u32(dev, "fcs,max-sink-microamp", &v))
> -		chip->tcpc_config.max_snk_ma = v / 1000;
> -
> -	if (!device_property_read_u32(dev, "fcs,max-sink-microwatt", &v))
> -		chip->tcpc_config.max_snk_mw = v / 1000;
> -
>  	if (!device_property_read_u32(dev, "fcs,operating-sink-microwatt", &v))
>  		chip->tcpc_config.operating_snk_mw = v / 1000;
>  
> +	/* Composite sink PDO */
> +	chip->tcpc_config.nr_snk_pdo = fusb302_composite_snk_pdo_array(chip);
> +	chip->tcpc_config.snk_pdo = chip->snk_pdo;
> +
>  	/*
>  	 * Devicetree platforms should get extcon via phandle (not yet
>  	 * supported). On ACPI platforms, we get the name from a device prop.
> -- 
> 2.7.4
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jun Li April 13, 2018, 11:25 p.m. UTC | #2
SGkNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogR3VlbnRlciBSb2VjayBb
bWFpbHRvOmxpbnV4QHJvZWNrLXVzLm5ldF0NCj4gU2VudDogMjAxOMTqNNTCMTTI1SAwOjAzDQo+
IFRvOiBKdW4gTGkgPGp1bi5saUBueHAuY29tPg0KPiBDYzogZ3JlZ2toQGxpbnV4Zm91bmRhdGlv
bi5vcmc7IHJvYmgrZHRAa2VybmVsLm9yZzsNCj4gaGVpa2tpLmtyb2dlcnVzQGxpbnV4LmludGVs
LmNvbTsgaGRlZ29lZGVAcmVkaGF0LmNvbTsgcm1mcmZzQGdtYWlsLmNvbTsNCj4geXVleWFvLnpo
dUBnbWFpbC5jb207IGxpbnV4LXVzYkB2Z2VyLmtlcm5lbC5vcmc7IGRsLWxpbnV4LWlteA0KPiA8
bGludXgtaW14QG54cC5jb20+DQo+IFN1YmplY3Q6IFJlOiBbUEFUQ0ggdjQgMi81XSB1c2I6IHR5
cGVjOiBmdXNiMzAyOiByZW1vdmUgbWF4X3Nua18qIGZvciBzaW5rDQo+IGNvbmZpZw0KPiANCj4g
T24gRnJpLCBBcHIgMTMsIDIwMTggYXQgMTA6MTg6NDJQTSArMDgwMCwgTGkgSnVuIHdyb3RlOg0K
PiA+IFNpbmNlIG1heF9zbmtfKiBpcyB0byBiZSBkZXByZWNhdGVkLCBzbyByZW1vdmUgbWF4X3Nu
a18qIGJ5IGFkZGluZyBhDQo+ID4gdmFyaWFibGUgUERPIGZvciBzaW5rIGNvbmZpZy4NCj4gDQo+
IG1heF9zbmsgb3IgbWF4X3NpbmsgPw0KDQoubWF4X3Nua19tYS9tdi9tdw0KDQo+IA0KPiA+DQo+
ID4gUmV2aWV3ZWQtYnk6IEhhbnMgZGUgR29lZGUg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nZXQgdGhlIG5hbWUgZnJvbSBhIGRldmljZSBwcm9w
Lg0KPiA+IC0tDQo+ID4gMi43LjQNCj4gPg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/usb/typec/fusb302/fusb302.c b/drivers/usb/typec/fusb302/fusb302.c
index 7036171..893f9e5 100644
--- a/drivers/usb/typec/fusb302/fusb302.c
+++ b/drivers/usb/typec/fusb302/fusb302.c
@@ -120,6 +120,7 @@  struct fusb302_chip {
 	enum typec_cc_polarity cc_polarity;
 	enum typec_cc_status cc1;
 	enum typec_cc_status cc2;
+	u32 snk_pdo[PDO_MAX_OBJECTS];
 
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *dentry;
@@ -1212,11 +1213,6 @@  static const u32 snk_pdo[] = {
 static const struct tcpc_config fusb302_tcpc_config = {
 	.src_pdo = src_pdo,
 	.nr_src_pdo = ARRAY_SIZE(src_pdo),
-	.snk_pdo = snk_pdo,
-	.nr_snk_pdo = ARRAY_SIZE(snk_pdo),
-	.max_snk_mv = 5000,
-	.max_snk_ma = 3000,
-	.max_snk_mw = 15000,
 	.operating_snk_mw = 2500,
 	.type = TYPEC_PORT_DRP,
 	.data = TYPEC_PORT_DRD,
@@ -1756,6 +1752,21 @@  static int init_gpio(struct fusb302_chip *chip)
 	return 0;
 }
 
+static int fusb302_composite_snk_pdo_array(struct fusb302_chip *chip)
+{
+	struct device *dev = chip->dev;
+	u32 max_uv, max_ua;
+
+	chip->snk_pdo[0] = PDO_FIXED(5000, 400, PDO_FIXED_FLAGS);
+
+	if (device_property_read_u32(dev, "fcs,max-sink-microvolt", &max_uv) ||
+		device_property_read_u32(dev, "fcs,max-sink-microamp", &max_ua))
+		return 1;
+
+	chip->snk_pdo[1] = PDO_VAR(5000, max_uv / 1000, max_ua / 1000);
+	return 2;
+}
+
 static int fusb302_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -1784,18 +1795,13 @@  static int fusb302_probe(struct i2c_client *client,
 	chip->tcpc_dev.config = &chip->tcpc_config;
 	mutex_init(&chip->lock);
 
-	if (!device_property_read_u32(dev, "fcs,max-sink-microvolt", &v))
-		chip->tcpc_config.max_snk_mv = v / 1000;
-
-	if (!device_property_read_u32(dev, "fcs,max-sink-microamp", &v))
-		chip->tcpc_config.max_snk_ma = v / 1000;
-
-	if (!device_property_read_u32(dev, "fcs,max-sink-microwatt", &v))
-		chip->tcpc_config.max_snk_mw = v / 1000;
-
 	if (!device_property_read_u32(dev, "fcs,operating-sink-microwatt", &v))
 		chip->tcpc_config.operating_snk_mw = v / 1000;
 
+	/* Composite sink PDO */
+	chip->tcpc_config.nr_snk_pdo = fusb302_composite_snk_pdo_array(chip);
+	chip->tcpc_config.snk_pdo = chip->snk_pdo;
+
 	/*
 	 * Devicetree platforms should get extcon via phandle (not yet
 	 * supported). On ACPI platforms, we get the name from a device prop.