diff mbox series

[V6,3/6] usb: typec: ucsi_ccg: Add OF support

Message ID 20230119121639.226729-4-jonathanh@nvidia.com
State Superseded
Headers show
Series Add device-tree support for Cypress CYPD4226 | expand

Commit Message

Jon Hunter Jan. 19, 2023, 12:16 p.m. UTC
From: Wayne Chang <waynec@nvidia.com>

Add device-tree support for the Cypress CCG UCSI driver. The device-tree
binding for the Cypress CCG device uses the standard device-tree
'firmware-name' string property to indicate the firmware build that is
used. For ACPI a 16-bit property named 'ccgx,firmware-build' is used and
if this is not found fall back to the 'firmware-name' property.

Signed-off-by: Wayne Chang <waynec@nvidia.com>
Co-developed-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
---
V5 -> V6: fixed compilation
V4 -> V5: add support for 'firmware-name'
V1 -> V4: nothing has changed

 drivers/usb/typec/ucsi/ucsi_ccg.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

Comments

Heikki Krogerus Jan. 20, 2023, 9:33 a.m. UTC | #1
On Thu, Jan 19, 2023 at 12:16:36PM +0000, Jon Hunter wrote:
> From: Wayne Chang <waynec@nvidia.com>
> 
> Add device-tree support for the Cypress CCG UCSI driver. The device-tree
> binding for the Cypress CCG device uses the standard device-tree
> 'firmware-name' string property to indicate the firmware build that is
> used. For ACPI a 16-bit property named 'ccgx,firmware-build' is used and
> if this is not found fall back to the 'firmware-name' property.
> 
> Signed-off-by: Wayne Chang <waynec@nvidia.com>
> Co-developed-by: Jon Hunter <jonathanh@nvidia.com>
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> ---
> V5 -> V6: fixed compilation
> V4 -> V5: add support for 'firmware-name'
> V1 -> V4: nothing has changed
> 
>  drivers/usb/typec/ucsi/ucsi_ccg.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c
> index 46441f1477f2..661a3988b39d 100644
> --- a/drivers/usb/typec/ucsi/ucsi_ccg.c
> +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c
> @@ -643,7 +643,7 @@ static int ccg_request_irq(struct ucsi_ccg *uc)
>  {
>  	unsigned long flags = IRQF_ONESHOT;
>  
> -	if (!has_acpi_companion(uc->dev))
> +	if (!dev_fwnode(uc->dev))
>  		flags |= IRQF_TRIGGER_HIGH;
>  
>  	return request_threaded_irq(uc->irq, NULL, ccg_irq_handler, flags, dev_name(uc->dev), uc);
> @@ -1342,6 +1342,7 @@ static int ucsi_ccg_probe(struct i2c_client *client)
>  {
>  	struct device *dev = &client->dev;
>  	struct ucsi_ccg *uc;
> +	const char *fw_name;
>  	int status;
>  
>  	uc = devm_kzalloc(dev, sizeof(*uc), GFP_KERNEL);
> @@ -1359,7 +1360,18 @@ static int ucsi_ccg_probe(struct i2c_client *client)
>  	/* Only fail FW flashing when FW build information is not provided */
>  	status = device_property_read_u16(dev, "ccgx,firmware-build",
>  					  &uc->fw_build);

You don't need this anymore. You already added the new property
"firmware-name" to drivers/i2c/busses/i2c-nvidia-gpu.c.

> -	if (status)
> +	if (status) {
> +		status = device_property_read_string(dev, "firmware-name",
> +						     &fw_name);
> +		if (!status) {
> +			if (!strcmp(fw_name, "nvidia,jetson-agx-xavier"))
> +				uc->fw_build = CCG_FW_BUILD_NVIDIA_TEGRA;
> +			else if (!strcmp(fw_name, "nvidia,gpu"))
> +				uc->fw_build = CCG_FW_BUILD_NVIDIA;
> +		}

So this will already work also with the build-in properties from
i2c-nvidia-gpu.c.

> +	}
> +
> +	if (!uc->fw_build)
>  		dev_err(uc->dev, "failed to get FW build information\n");
>  
>  	/* reset ccg device and initialize ucsi */
> @@ -1426,6 +1438,12 @@ static void ucsi_ccg_remove(struct i2c_client *client)
>  	free_irq(uc->irq, uc);
>  }
>  
> +static const struct of_device_id ucsi_ccg_of_match_table[] = {
> +		{ .compatible = "cypress,cypd4226", },
> +		{ /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, ucsi_ccg_of_match_table);
> +
>  static const struct i2c_device_id ucsi_ccg_device_id[] = {
>  	{"ccgx-ucsi", 0},
>  	{}
> @@ -1480,6 +1498,7 @@ static struct i2c_driver ucsi_ccg_driver = {
>  		.pm = &ucsi_ccg_pm,
>  		.dev_groups = ucsi_ccg_groups,
>  		.acpi_match_table = amd_i2c_ucsi_match,
> +		.of_match_table = ucsi_ccg_of_match_table,
>  	},
>  	.probe_new = ucsi_ccg_probe,
>  	.remove = ucsi_ccg_remove,
> -- 
> 2.25.1
Jon Hunter Jan. 20, 2023, 1:18 p.m. UTC | #2
On 20/01/2023 09:33, Heikki Krogerus wrote:
> On Thu, Jan 19, 2023 at 12:16:36PM +0000, Jon Hunter wrote:
>> From: Wayne Chang <waynec@nvidia.com>
>>
>> Add device-tree support for the Cypress CCG UCSI driver. The device-tree
>> binding for the Cypress CCG device uses the standard device-tree
>> 'firmware-name' string property to indicate the firmware build that is
>> used. For ACPI a 16-bit property named 'ccgx,firmware-build' is used and
>> if this is not found fall back to the 'firmware-name' property.
>>
>> Signed-off-by: Wayne Chang <waynec@nvidia.com>
>> Co-developed-by: Jon Hunter <jonathanh@nvidia.com>
>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>> ---
>> V5 -> V6: fixed compilation
>> V4 -> V5: add support for 'firmware-name'
>> V1 -> V4: nothing has changed
>>
>>   drivers/usb/typec/ucsi/ucsi_ccg.c | 23 +++++++++++++++++++++--
>>   1 file changed, 21 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c
>> index 46441f1477f2..661a3988b39d 100644
>> --- a/drivers/usb/typec/ucsi/ucsi_ccg.c
>> +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c
>> @@ -643,7 +643,7 @@ static int ccg_request_irq(struct ucsi_ccg *uc)
>>   {
>>   	unsigned long flags = IRQF_ONESHOT;
>>   
>> -	if (!has_acpi_companion(uc->dev))
>> +	if (!dev_fwnode(uc->dev))
>>   		flags |= IRQF_TRIGGER_HIGH;
>>   
>>   	return request_threaded_irq(uc->irq, NULL, ccg_irq_handler, flags, dev_name(uc->dev), uc);
>> @@ -1342,6 +1342,7 @@ static int ucsi_ccg_probe(struct i2c_client *client)
>>   {
>>   	struct device *dev = &client->dev;
>>   	struct ucsi_ccg *uc;
>> +	const char *fw_name;
>>   	int status;
>>   
>>   	uc = devm_kzalloc(dev, sizeof(*uc), GFP_KERNEL);
>> @@ -1359,7 +1360,18 @@ static int ucsi_ccg_probe(struct i2c_client *client)
>>   	/* Only fail FW flashing when FW build information is not provided */
>>   	status = device_property_read_u16(dev, "ccgx,firmware-build",
>>   					  &uc->fw_build);
> 
> You don't need this anymore. You already added the new property
> "firmware-name" to drivers/i2c/busses/i2c-nvidia-gpu.c.


I was planning to get rid of this here, but I was not sure if AMD need 
this. I see now that Sanket has confirmed they don't use this and so 
will drop it from here.

Jon
diff mbox series

Patch

diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c
index 46441f1477f2..661a3988b39d 100644
--- a/drivers/usb/typec/ucsi/ucsi_ccg.c
+++ b/drivers/usb/typec/ucsi/ucsi_ccg.c
@@ -643,7 +643,7 @@  static int ccg_request_irq(struct ucsi_ccg *uc)
 {
 	unsigned long flags = IRQF_ONESHOT;
 
-	if (!has_acpi_companion(uc->dev))
+	if (!dev_fwnode(uc->dev))
 		flags |= IRQF_TRIGGER_HIGH;
 
 	return request_threaded_irq(uc->irq, NULL, ccg_irq_handler, flags, dev_name(uc->dev), uc);
@@ -1342,6 +1342,7 @@  static int ucsi_ccg_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
 	struct ucsi_ccg *uc;
+	const char *fw_name;
 	int status;
 
 	uc = devm_kzalloc(dev, sizeof(*uc), GFP_KERNEL);
@@ -1359,7 +1360,18 @@  static int ucsi_ccg_probe(struct i2c_client *client)
 	/* Only fail FW flashing when FW build information is not provided */
 	status = device_property_read_u16(dev, "ccgx,firmware-build",
 					  &uc->fw_build);
-	if (status)
+	if (status) {
+		status = device_property_read_string(dev, "firmware-name",
+						     &fw_name);
+		if (!status) {
+			if (!strcmp(fw_name, "nvidia,jetson-agx-xavier"))
+				uc->fw_build = CCG_FW_BUILD_NVIDIA_TEGRA;
+			else if (!strcmp(fw_name, "nvidia,gpu"))
+				uc->fw_build = CCG_FW_BUILD_NVIDIA;
+		}
+	}
+
+	if (!uc->fw_build)
 		dev_err(uc->dev, "failed to get FW build information\n");
 
 	/* reset ccg device and initialize ucsi */
@@ -1426,6 +1438,12 @@  static void ucsi_ccg_remove(struct i2c_client *client)
 	free_irq(uc->irq, uc);
 }
 
+static const struct of_device_id ucsi_ccg_of_match_table[] = {
+		{ .compatible = "cypress,cypd4226", },
+		{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, ucsi_ccg_of_match_table);
+
 static const struct i2c_device_id ucsi_ccg_device_id[] = {
 	{"ccgx-ucsi", 0},
 	{}
@@ -1480,6 +1498,7 @@  static struct i2c_driver ucsi_ccg_driver = {
 		.pm = &ucsi_ccg_pm,
 		.dev_groups = ucsi_ccg_groups,
 		.acpi_match_table = amd_i2c_ucsi_match,
+		.of_match_table = ucsi_ccg_of_match_table,
 	},
 	.probe_new = ucsi_ccg_probe,
 	.remove = ucsi_ccg_remove,