[PATCH 2/4] usb: typec: hd3ss3220: use typec_get_fw_cap() to fill typec_cap

Oliver Facklam via B4 Relay posted 4 patches 2 weeks, 2 days ago
There is a newer version of this series
[PATCH 2/4] usb: typec: hd3ss3220: use typec_get_fw_cap() to fill typec_cap
Posted by Oliver Facklam via B4 Relay 2 weeks, 2 days ago
From: Oliver Facklam <oliver.facklam@zuehlke.com>

The type, data, and prefer_role properties were previously hard-coded
when creating the struct typec_capability.

Use typec_get_fw_cap() to populate these fields based on the
respective fwnode properties.

Signed-off-by: Oliver Facklam <oliver.facklam@zuehlke.com>
---
 drivers/usb/typec/hd3ss3220.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
index 56f74bf70895ca701083bde44a5bbe0b691551e1..e6e4b1871b5d805f8c367131509f4e6ec0d2b5f0 100644
--- a/drivers/usb/typec/hd3ss3220.c
+++ b/drivers/usb/typec/hd3ss3220.c
@@ -259,12 +259,12 @@ static int hd3ss3220_probe(struct i2c_client *client)
 		goto err_put_fwnode;
 	}
 
-	typec_cap.prefer_role = TYPEC_NO_PREFERRED_ROLE;
+	ret = typec_get_fw_cap(&typec_cap, connector);
+	if (ret)
+		goto err_put_role;
+
 	typec_cap.driver_data = hd3ss3220;
-	typec_cap.type = TYPEC_PORT_DRP;
-	typec_cap.data = TYPEC_PORT_DRD;
 	typec_cap.ops = &hd3ss3220_ops;
-	typec_cap.fwnode = connector;
 
 	hd3ss3220->port = typec_register_port(&client->dev, &typec_cap);
 	if (IS_ERR(hd3ss3220->port)) {

-- 
2.34.1
Re: [PATCH 2/4] usb: typec: hd3ss3220: use typec_get_fw_cap() to fill typec_cap
Posted by Heikki Krogerus 2 weeks, 2 days ago
Hi Oliver,

On Thu, Nov 07, 2024 at 12:43:28PM +0100, Oliver Facklam via B4 Relay wrote:
> From: Oliver Facklam <oliver.facklam@zuehlke.com>
> 
> The type, data, and prefer_role properties were previously hard-coded
> when creating the struct typec_capability.
> 
> Use typec_get_fw_cap() to populate these fields based on the
> respective fwnode properties.
> 
> Signed-off-by: Oliver Facklam <oliver.facklam@zuehlke.com>
> ---
>  drivers/usb/typec/hd3ss3220.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
> index 56f74bf70895ca701083bde44a5bbe0b691551e1..e6e4b1871b5d805f8c367131509f4e6ec0d2b5f0 100644
> --- a/drivers/usb/typec/hd3ss3220.c
> +++ b/drivers/usb/typec/hd3ss3220.c
> @@ -259,12 +259,12 @@ static int hd3ss3220_probe(struct i2c_client *client)
>  		goto err_put_fwnode;
>  	}
>  
> -	typec_cap.prefer_role = TYPEC_NO_PREFERRED_ROLE;
> +	ret = typec_get_fw_cap(&typec_cap, connector);
> +	if (ret)
> +		goto err_put_role;

You are not leaving any fallback here. Are you sure all the existing
systems supply those properties?

There is another problem. At least "data-role" property is optional,
but that will in practice make it a requirement.

I think it would be safer to use the values from the device properties
only if they are available. Otherwise simply use default values.

>  	typec_cap.driver_data = hd3ss3220;
> -	typec_cap.type = TYPEC_PORT_DRP;
> -	typec_cap.data = TYPEC_PORT_DRD;
>  	typec_cap.ops = &hd3ss3220_ops;
> -	typec_cap.fwnode = connector;
>  
>  	hd3ss3220->port = typec_register_port(&client->dev, &typec_cap);
>  	if (IS_ERR(hd3ss3220->port)) {

thanks,

-- 
heikki