diff mbox series

usb: typec: wcove: Provide fwnode for the port

Message ID 20190319125324.7284-1-heikki.krogerus@linux.intel.com (mailing list archive)
State Mainlined
Commit 4c912bff46cc1b37490fda2eac33471ddd0fadf2
Headers show
Series usb: typec: wcove: Provide fwnode for the port | expand

Commit Message

Heikki Krogerus March 19, 2019, 12:53 p.m. UTC
By registering a software fwnode for the port, we can supply
the connector capabilities to the tcpm using the common USB
connector device properties instead of relying on platform
data (struct tcpc_config).

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/usb/typec/tcpm/wcove.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

Comments

Guenter Roeck March 19, 2019, 2:51 p.m. UTC | #1
On Tue, Mar 19, 2019 at 03:53:24PM +0300, Heikki Krogerus wrote:
> By registering a software fwnode for the port, we can supply
> the connector capabilities to the tcpm using the common USB
> connector device properties instead of relying on platform
> data (struct tcpc_config).
> 
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

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

> ---
>  drivers/usb/typec/tcpm/wcove.c | 29 ++++++++++++++++-------------
>  1 file changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/wcove.c b/drivers/usb/typec/tcpm/wcove.c
> index 423208e19383..53f00ad9aa92 100644
> --- a/drivers/usb/typec/tcpm/wcove.c
> +++ b/drivers/usb/typec/tcpm/wcove.c
> @@ -587,17 +587,14 @@ static const u32 snk_pdo[] = {
>  	PDO_VAR(5000, 12000, 3000),
>  };
>  
> -static struct tcpc_config wcove_typec_config = {
> -	.src_pdo = src_pdo,
> -	.nr_src_pdo = ARRAY_SIZE(src_pdo),
> -	.snk_pdo = snk_pdo,
> -	.nr_snk_pdo = ARRAY_SIZE(snk_pdo),
> -
> -	.operating_snk_mw = 15000,
> -
> -	.type = TYPEC_PORT_DRP,
> -	.data = TYPEC_PORT_DRD,
> -	.default_role = TYPEC_SINK,
> +static const struct property_entry wcove_props[] = {
> +	PROPERTY_ENTRY_STRING("data-role", "dual"),
> +	PROPERTY_ENTRY_STRING("power-role", "dual"),
> +	PROPERTY_ENTRY_STRING("try-power-role", "sink"),
> +	PROPERTY_ENTRY_U32_ARRAY("source-pdos", src_pdo),
> +	PROPERTY_ENTRY_U32_ARRAY("sink-pdos", snk_pdo),
> +	PROPERTY_ENTRY_U32("op-sink-microwatt", 15000),
> +	{ }
>  };
>  
>  static int wcove_typec_probe(struct platform_device *pdev)
> @@ -643,17 +640,22 @@ static int wcove_typec_probe(struct platform_device *pdev)
>  	wcove->tcpc.set_roles = wcove_set_roles;
>  	wcove->tcpc.pd_transmit = wcove_pd_transmit;
>  
> -	wcove->tcpc.config = &wcove_typec_config;
> +	wcove->tcpc.fwnode = fwnode_create_software_node(wcove_props, NULL);
> +	if (IS_ERR(wcove->tcpc.fwnode))
> +		return PTR_ERR(wcove->tcpc.fwnode);
>  
>  	wcove->tcpm = tcpm_register_port(wcove->dev, &wcove->tcpc);
> -	if (IS_ERR(wcove->tcpm))
> +	if (IS_ERR(wcove->tcpm)) {
> +		fwnode_remove_software_node(wcove->tcpc.fwnode);
>  		return PTR_ERR(wcove->tcpm);
> +	}
>  
>  	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
>  					wcove_typec_irq, IRQF_ONESHOT,
>  					"wcove_typec", wcove);
>  	if (ret) {
>  		tcpm_unregister_port(wcove->tcpm);
> +		fwnode_remove_software_node(wcove->tcpc.fwnode);
>  		return ret;
>  	}
>  
> @@ -673,6 +675,7 @@ static int wcove_typec_remove(struct platform_device *pdev)
>  	regmap_write(wcove->regmap, USBC_IRQMASK2, val | USBC_IRQMASK2_ALL);
>  
>  	tcpm_unregister_port(wcove->tcpm);
> +	fwnode_remove_software_node(wcove->tcpc.fwnode);
>  
>  	return 0;
>  }
> -- 
> 2.20.1
>
diff mbox series

Patch

diff --git a/drivers/usb/typec/tcpm/wcove.c b/drivers/usb/typec/tcpm/wcove.c
index 423208e19383..53f00ad9aa92 100644
--- a/drivers/usb/typec/tcpm/wcove.c
+++ b/drivers/usb/typec/tcpm/wcove.c
@@ -587,17 +587,14 @@  static const u32 snk_pdo[] = {
 	PDO_VAR(5000, 12000, 3000),
 };
 
-static struct tcpc_config wcove_typec_config = {
-	.src_pdo = src_pdo,
-	.nr_src_pdo = ARRAY_SIZE(src_pdo),
-	.snk_pdo = snk_pdo,
-	.nr_snk_pdo = ARRAY_SIZE(snk_pdo),
-
-	.operating_snk_mw = 15000,
-
-	.type = TYPEC_PORT_DRP,
-	.data = TYPEC_PORT_DRD,
-	.default_role = TYPEC_SINK,
+static const struct property_entry wcove_props[] = {
+	PROPERTY_ENTRY_STRING("data-role", "dual"),
+	PROPERTY_ENTRY_STRING("power-role", "dual"),
+	PROPERTY_ENTRY_STRING("try-power-role", "sink"),
+	PROPERTY_ENTRY_U32_ARRAY("source-pdos", src_pdo),
+	PROPERTY_ENTRY_U32_ARRAY("sink-pdos", snk_pdo),
+	PROPERTY_ENTRY_U32("op-sink-microwatt", 15000),
+	{ }
 };
 
 static int wcove_typec_probe(struct platform_device *pdev)
@@ -643,17 +640,22 @@  static int wcove_typec_probe(struct platform_device *pdev)
 	wcove->tcpc.set_roles = wcove_set_roles;
 	wcove->tcpc.pd_transmit = wcove_pd_transmit;
 
-	wcove->tcpc.config = &wcove_typec_config;
+	wcove->tcpc.fwnode = fwnode_create_software_node(wcove_props, NULL);
+	if (IS_ERR(wcove->tcpc.fwnode))
+		return PTR_ERR(wcove->tcpc.fwnode);
 
 	wcove->tcpm = tcpm_register_port(wcove->dev, &wcove->tcpc);
-	if (IS_ERR(wcove->tcpm))
+	if (IS_ERR(wcove->tcpm)) {
+		fwnode_remove_software_node(wcove->tcpc.fwnode);
 		return PTR_ERR(wcove->tcpm);
+	}
 
 	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
 					wcove_typec_irq, IRQF_ONESHOT,
 					"wcove_typec", wcove);
 	if (ret) {
 		tcpm_unregister_port(wcove->tcpm);
+		fwnode_remove_software_node(wcove->tcpc.fwnode);
 		return ret;
 	}
 
@@ -673,6 +675,7 @@  static int wcove_typec_remove(struct platform_device *pdev)
 	regmap_write(wcove->regmap, USBC_IRQMASK2, val | USBC_IRQMASK2_ALL);
 
 	tcpm_unregister_port(wcove->tcpm);
+	fwnode_remove_software_node(wcove->tcpc.fwnode);
 
 	return 0;
 }