media: atomisp: Fix and refactor PMIC I²C discovery
Subsystems (4)
cover media: atomisp: Fix and refactor PMIC I²C discovery
Drop the reference count when detecting PMIC.
Refactor PMIC detection using new API.
Andy Shevchenko (2):
media: atomisp: Put PMIC device after getting its I²C address
media: atomisp: Replace open-coded i2c_find_device_by_fwnode()
.../media/atomisp/pci/atomisp_gmin_platform.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
PATCH 1/2 media: atomisp: Put PMIC device after getting its I²C address
We don't use the PMIC I²C client device after getting its address. Drop the reference to it. We do not expect device to disappear as it should be taken care by the OpRegion drivers.
--- .../media/atomisp/pci/atomisp_gmin_platform.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +8 -5
@@ -497,16 +497,19 @@ static u8 gmin_get_pmic_id_and_addr(struct device *dev)if (pmic_id)return pmic_i2c_addr; -if (gmin_i2c_dev_exists (dev,PMIC_ACPI_TI , &power)) +if (gmin_i2c_dev_exists (dev,PMIC_ACPI_TI , &power)) { pmic_id =PMIC_TI ; -else if (gmin_i2c_dev_exists (dev,PMIC_ACPI_AXP , &power)) + }else if (gmin_i2c_dev_exists (dev,PMIC_ACPI_AXP , &power)) { pmic_id =PMIC_AXP ; -else if (gmin_i2c_dev_exists (dev,PMIC_ACPI_CRYSTALCOVE , &power)) + }else if (gmin_i2c_dev_exists (dev,PMIC_ACPI_CRYSTALCOVE , &power)) { pmic_id =PMIC_CRYSTALCOVE ; -else + }else { pmic_id =PMIC_REGULATOR ; +return 0 ; + } - pmic_i2c_addr = power ? power->addr :0 ; + pmic_i2c_addr = power->addr; +put_device (&power->dev);return pmic_i2c_addr; }
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
Re: [PATCH v1 1/2] media: atomisp: Put PMIC device after getting its I²C address
Hi,
Quoted 5 lines · Andy Shevchenko
We don't use the PMIC I²C client device after getting its address. Drop the reference to it. We do not expect device to disappear as it should be taken care by the OpRegion drivers.
Signed-off-by Andy Shevchenko <[email protected]>
Thank you for your patch.
I have merged this in my media-atomisp branch:
https://git.kernel.org/pub/scm/linux/kernel/git/hansg/linux.git/log/?h=media-atomisp
And this patch will be included in my next pull-request to Mauro (to media subsystem maintainer)
Regards,
Hans
Quoted 33 lines
--- .../media/atomisp/pci/atomisp_gmin_platform.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +8
-5@@ -497,16 +497,19 @@ static u8 gmin_get_pmic_id_and_addr(struct device *dev)if (pmic_id)return pmic_i2c_addr; -if (gmin_i2c_dev_exists (dev,PMIC_ACPI_TI , &power)) +if (gmin_i2c_dev_exists (dev,PMIC_ACPI_TI , &power)) { pmic_id =PMIC_TI ; -else if (gmin_i2c_dev_exists (dev,PMIC_ACPI_AXP , &power)) + }else if (gmin_i2c_dev_exists (dev,PMIC_ACPI_AXP , &power)) { pmic_id =PMIC_AXP ; -else if (gmin_i2c_dev_exists (dev,PMIC_ACPI_CRYSTALCOVE , &power)) + }else if (gmin_i2c_dev_exists (dev,PMIC_ACPI_CRYSTALCOVE , &power)) { pmic_id =PMIC_CRYSTALCOVE ; -else + }else { pmic_id =PMIC_REGULATOR ; +return 0 ; + } - pmic_i2c_addr = power ? power->addr :0 ; + pmic_i2c_addr = power->addr; +put_device (&power->dev);return pmic_i2c_addr; }
PATCH 2/2 media: atomisp: Replace open-coded i2c_find_device_by_fwnode()
In reply to Andy Shevchenkogmin_i2c_dev_exists() is using open-coded variant of i2c_find_device_by_fwnode(). Replace it with a corresponding call.
--- drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +2 -4
@@ -394,12 +394,10 @@ static struct i2c_client *gmin_i2c_dev_exists(struct device *dev, char *name,if (!adev)return NULL ; - d =bus_find_device_by_acpi_dev (&i2c_bus_type, adev); + d =get_device (acpi_get_first_physical_node (adev));acpi_dev_put (adev); -if (!d) -return NULL ; - *client =i2c_verify_client (d); + *client =i2c_find_device_by_fwnode (dev_fwnode (d));put_device (d); dev_dbg(dev, "found '%s' at address 0x%02x, adapter %d\n",
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
Re: [PATCH v1 2/2] media: atomisp: Replace open-coded i2c_find_device_by_fwnode()
Hi Andy,
Thank you for the patch.
Quoted 17 lines · Andy Shevchenko
gmin_i2c_dev_exists()is using open-coded variant ofi2c_find_device_by_fwnode(). Replace it with a corresponding call.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +0
-1@@ -394,12 +394,10 @@ static struct i2c_client *gmin_i2c_dev_exists(struct device *dev, char *name,if (!adev)return NULL ; - d =bus_find_device_by_acpi_dev (&i2c_bus_type, adev);
drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c static struct i2c_client *gmin_i2c_dev_exists(struct device *dev, char *name, · line 403
Quoted 10 lines
drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +2
-3+ d =get_device (acpi_get_first_physical_node (adev));acpi_dev_put (adev); -if (!d) -return NULL ; - *client =i2c_verify_client (d); + *client =i2c_find_device_by_fwnode (dev_fwnode (d));put_device (d); dev_dbg(dev, "found '%s' at address 0x%02x, adapter %d\n",
If we are ging to simplify this I think the change should be:
From ea66d15b9a72fcb8baf22a2ff059f2b842a91b67 Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <[email protected]>
Date: Wed, 10 Apr 2024 12:32:11 +0200
Subject: [PATCH] media: atomisp: Replace open-coded
i2c_find_device_by_fwnode()
gmin_i2c_dev_exists() is using open-coded variant of i2c_find_device_by_fwnode(). Replace it with a corresponding call.
---
Changes in v2:
- Directly use the ACPI fwnode through acpi_fwnode_handle(adev) instead of first calling acpi_get_first_physical_node(adev)
--- drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +2 -5
@@ -394,14 +394,11 @@ static struct i2c_client *gmin_i2c_dev_exists(struct device *dev, char *name,if (!adev)return NULL ; - d =bus_find_device_by_acpi_dev (&i2c_bus_type, adev); + *client =i2c_find_device_by_fwnode (acpi_fwnode_handle (adev));acpi_dev_put (adev); -if (!d) +if (!*client)return NULL ; - *client =i2c_verify_client (d); -put_device (d); -dev_dbg (dev,"found '%s' at address 0x%02x, adapter %d\n" , (*client)->name, (*client)->addr, (*client)->adapter->nr);return *client;
Signature · 16 lines
2.44.0 Note I added a: if (!*client) return NULL; To fix a bug in the original code where the dev_dbg() arguments are dereferencing a potential NULL *client ptr. I'm going to merge this variant into my media-atomisp branch instead of the orignal. Regards, Hans
Re: [PATCH v1 2/2] media: atomisp: Replace open-coded i2c_find_device_by_fwnode()
Quoted 1 line · Hans de Goede
On 3/26/24 9:27 PM, Andy Shevchenko wrote:
...
Quoted 2 lines
I'm going to merge this variant into my media-atomisp branch instead of the orignal.
Thanks!
This explains why changelog made the commit message. Was it done deliberately?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 2/2] media: atomisp: Replace open-coded i2c_find_device_by_fwnode()
Hi Andy,
Quoted 5 lines · Andy Shevchenko
Quoted 1 line · Hans de Goede
On 3/26/24 9:27 PM, Andy Shevchenko wrote:
...
Quoted 7 lines
Quoted 2 lines
I'm going to merge this variant into my media-atomisp branch instead of the orignal.
Thanks!
This explains why changelog made the commit message. Was it done deliberately?
Oops, no that was by accident. I normally git send-email
+ git am my patches and then git am cuts it off...
I just send out a pull-request with this minor wart in it (after testing), so unless there are other reasons to respin I guess we'll have to live with it.
Regards,
Hans
Re: [PATCH v1 2/2] media: atomisp: Replace open-coded i2c_find_device_by_fwnode()
Quoted 3 lines · Hans de Goede
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Hans de Goede
On 3/26/24 9:27 PM, Andy Shevchenko wrote:
...
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
I'm going to merge this variant into my media-atomisp branch instead of the orignal.
Thanks!
This explains why changelog made the commit message. Was it done deliberately?
Quoted 6 lines
Oops, no that was by accident. I normally git send-email
+ git am my patches and then git am cuts it off...I just send out a pull-request with this minor wart in it (after testing), so unless there are other reasons to respin I guess we'll have to live with it.
You might check the linux-next scripts or ask Stephen if this is an issue. In any case we will know sooner or later :-)
Signature · 2 lines
With Best Regards, Andy Shevchenko