platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function
@ 2021-08-03 16:00 Hans de Goede
  2021-08-03 16:00 ` [PATCH 1/4] i2c: acpi: " Hans de Goede
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Hans de Goede @ 2021-08-03 16:00 UTC (permalink / raw)
  To: Mark Gross, Andy Shevchenko, Wolfram Sang, Mika Westerberg
  Cc: Hans de Goede, platform-driver-x86, linux-i2c, linux-acpi

Hi All,

This patch-set adds a new i2c_acpi_client_count() helper function
to remove a bunch of code-duplication.

Since 3 of the 4 patches touch files under drivers/platform/x86 and
also since the drivers/platform/x86/dual_accel_detect.h file is new
in pdx86/for-next I believe that it would be best to just merge the
entire series through my pdx86 tree.

Mika + WSA, may I have your ack for merging the entire series through
the pdx86 tree (or please let me know if you want to proceed in a
different way) ?

Regards,

Hans


Hans de Goede (4):
  i2c: acpi: Add an i2c_acpi_client_count() helper function
  platform/x86: dual_accel_detect: Use the new i2c_acpi_client_count()
    helper
  platform/x86: i2c-multi-instantiate: Use the new
    i2c_acpi_client_count() helper
  platform/x86: intel_cht_int33fe: Use the new i2c_acpi_client_count()
    helper

 drivers/i2c/i2c-core-acpi.c                   | 32 +++++++++++++++++++
 drivers/platform/x86/dual_accel_detect.h      | 26 +--------------
 drivers/platform/x86/i2c-multi-instantiate.c  | 27 +---------------
 .../intel/int33fe/intel_cht_int33fe_common.c  | 29 +----------------
 include/linux/i2c.h                           |  5 +++
 5 files changed, 40 insertions(+), 79 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] i2c: acpi: Add an i2c_acpi_client_count() helper function
  2021-08-03 16:00 [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function Hans de Goede
@ 2021-08-03 16:00 ` Hans de Goede
  2021-08-03 16:50   ` Mika Westerberg
  2021-08-03 16:00 ` [PATCH 2/4] platform/x86: dual_accel_detect: Use the new i2c_acpi_client_count() helper Hans de Goede
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Hans de Goede @ 2021-08-03 16:00 UTC (permalink / raw)
  To: Mark Gross, Andy Shevchenko, Wolfram Sang, Mika Westerberg
  Cc: Hans de Goede, platform-driver-x86, linux-i2c, linux-acpi

We have 3 files now which have the need to count the number of
I2cSerialBus resources in an ACPI-device's resource-list.

Currently all implement their own helper function for this,
add a generic helper function to replace the 3 implementations.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/i2c/i2c-core-acpi.c | 32 ++++++++++++++++++++++++++++++++
 include/linux/i2c.h         |  5 +++++
 2 files changed, 37 insertions(+)

diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index 6f0aa0ed3241..aaeeacc12121 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -69,6 +69,38 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
 }
 EXPORT_SYMBOL_GPL(i2c_acpi_get_i2c_resource);
 
+static int i2c_acpi_resource_count(struct acpi_resource *ares, void *data)
+{
+	struct acpi_resource_i2c_serialbus *sb;
+	int *count = data;
+
+	if (i2c_acpi_get_i2c_resource(ares, &sb))
+		*count = *count + 1;
+
+	return 1;
+}
+
+/**
+ * i2c_acpi_client_count - Count the number of I2cSerialBus resources
+ * @adev:	ACPI device
+ *
+ * Returns the number of I2cSerialBus resources in the ACPI-device's
+ * resource-list; or a negative error code.
+ */
+int i2c_acpi_client_count(struct acpi_device *adev)
+{
+	int ret, count = 0;
+	LIST_HEAD(r);
+
+	ret = acpi_dev_get_resources(adev, &r, i2c_acpi_resource_count, &count);
+	if (ret < 0)
+		return ret;
+
+	acpi_dev_free_resource_list(&r);
+	return count;
+}
+EXPORT_SYMBOL_GPL(i2c_acpi_client_count);
+
 static int i2c_acpi_fill_info(struct acpi_resource *ares, void *data)
 {
 	struct i2c_acpi_lookup *lookup = data;
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 3eb60a2e9e61..2ce3efbe9198 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -1010,6 +1010,7 @@ struct acpi_resource_i2c_serialbus;
 #if IS_ENABLED(CONFIG_ACPI)
 bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
 			       struct acpi_resource_i2c_serialbus **i2c);
+int i2c_acpi_client_count(struct acpi_device *adev);
 u32 i2c_acpi_find_bus_speed(struct device *dev);
 struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
 				       struct i2c_board_info *info);
@@ -1020,6 +1021,10 @@ static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
 {
 	return false;
 }
+static inline int i2c_acpi_client_count(struct acpi_device *adev)
+{
+	return 0;
+}
 static inline u32 i2c_acpi_find_bus_speed(struct device *dev)
 {
 	return 0;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/4] platform/x86: dual_accel_detect: Use the new i2c_acpi_client_count() helper
  2021-08-03 16:00 [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function Hans de Goede
  2021-08-03 16:00 ` [PATCH 1/4] i2c: acpi: " Hans de Goede
@ 2021-08-03 16:00 ` Hans de Goede
  2021-08-03 16:00 ` [PATCH 3/4] platform/x86: i2c-multi-instantiate: " Hans de Goede
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2021-08-03 16:00 UTC (permalink / raw)
  To: Mark Gross, Andy Shevchenko, Wolfram Sang, Mika Westerberg
  Cc: Hans de Goede, platform-driver-x86, linux-i2c, linux-acpi

Use the new i2c_acpi_client_count() helper, this
results in a nice cleanup.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/dual_accel_detect.h | 26 +-----------------------
 1 file changed, 1 insertion(+), 25 deletions(-)

diff --git a/drivers/platform/x86/dual_accel_detect.h b/drivers/platform/x86/dual_accel_detect.h
index a9eae17cc43d..72e9624331c8 100644
--- a/drivers/platform/x86/dual_accel_detect.h
+++ b/drivers/platform/x86/dual_accel_detect.h
@@ -17,30 +17,6 @@
 #include <linux/acpi.h>
 #include <linux/i2c.h>
 
-static int dual_accel_i2c_resource_count(struct acpi_resource *ares, void *data)
-{
-	struct acpi_resource_i2c_serialbus *sb;
-	int *count = data;
-
-	if (i2c_acpi_get_i2c_resource(ares, &sb))
-		*count = *count + 1;
-
-	return 1;
-}
-
-static int dual_accel_i2c_client_count(struct acpi_device *adev)
-{
-	int ret, count = 0;
-	LIST_HEAD(r);
-
-	ret = acpi_dev_get_resources(adev, &r, dual_accel_i2c_resource_count, &count);
-	if (ret < 0)
-		return ret;
-
-	acpi_dev_free_resource_list(&r);
-	return count;
-}
-
 static bool dual_accel_detect_bosc0200(void)
 {
 	struct acpi_device *adev;
@@ -50,7 +26,7 @@ static bool dual_accel_detect_bosc0200(void)
 	if (!adev)
 		return false;
 
-	count = dual_accel_i2c_client_count(adev);
+	count = i2c_acpi_client_count(adev);
 
 	acpi_dev_put(adev);
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/4] platform/x86: i2c-multi-instantiate: Use the new i2c_acpi_client_count() helper
  2021-08-03 16:00 [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function Hans de Goede
  2021-08-03 16:00 ` [PATCH 1/4] i2c: acpi: " Hans de Goede
  2021-08-03 16:00 ` [PATCH 2/4] platform/x86: dual_accel_detect: Use the new i2c_acpi_client_count() helper Hans de Goede
@ 2021-08-03 16:00 ` Hans de Goede
  2021-08-03 16:00 ` [PATCH 4/4] platform/x86: intel_cht_int33fe: " Hans de Goede
  2021-08-03 16:14 ` [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function Andy Shevchenko
  4 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2021-08-03 16:00 UTC (permalink / raw)
  To: Mark Gross, Andy Shevchenko, Wolfram Sang, Mika Westerberg
  Cc: Hans de Goede, platform-driver-x86, linux-i2c, linux-acpi

Use the new i2c_acpi_client_count() helper, this
results in a nice cleanup.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/i2c-multi-instantiate.c | 27 +-------------------
 1 file changed, 1 insertion(+), 26 deletions(-)

diff --git a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/platform/x86/i2c-multi-instantiate.c
index 2cce82579d09..a50153ecd560 100644
--- a/drivers/platform/x86/i2c-multi-instantiate.c
+++ b/drivers/platform/x86/i2c-multi-instantiate.c
@@ -32,31 +32,6 @@ struct i2c_multi_inst_data {
 	struct i2c_client *clients[];
 };
 
-static int i2c_multi_inst_count(struct acpi_resource *ares, void *data)
-{
-	struct acpi_resource_i2c_serialbus *sb;
-	int *count = data;
-
-	if (i2c_acpi_get_i2c_resource(ares, &sb))
-		*count = *count + 1;
-
-	return 1;
-}
-
-static int i2c_multi_inst_count_resources(struct acpi_device *adev)
-{
-	LIST_HEAD(r);
-	int count = 0;
-	int ret;
-
-	ret = acpi_dev_get_resources(adev, &r, i2c_multi_inst_count, &count);
-	if (ret < 0)
-		return ret;
-
-	acpi_dev_free_resource_list(&r);
-	return count;
-}
-
 static int i2c_multi_inst_probe(struct platform_device *pdev)
 {
 	struct i2c_multi_inst_data *multi;
@@ -76,7 +51,7 @@ static int i2c_multi_inst_probe(struct platform_device *pdev)
 	adev = ACPI_COMPANION(dev);
 
 	/* Count number of clients to instantiate */
-	ret = i2c_multi_inst_count_resources(adev);
+	ret = i2c_acpi_client_count(adev);
 	if (ret < 0)
 		return ret;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/4] platform/x86: intel_cht_int33fe: Use the new i2c_acpi_client_count() helper
  2021-08-03 16:00 [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function Hans de Goede
                   ` (2 preceding siblings ...)
  2021-08-03 16:00 ` [PATCH 3/4] platform/x86: i2c-multi-instantiate: " Hans de Goede
@ 2021-08-03 16:00 ` Hans de Goede
  2021-08-03 16:14 ` [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function Andy Shevchenko
  4 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2021-08-03 16:00 UTC (permalink / raw)
  To: Mark Gross, Andy Shevchenko, Wolfram Sang, Mika Westerberg
  Cc: Hans de Goede, platform-driver-x86, linux-i2c, linux-acpi

Use the new i2c_acpi_client_count() helper, this
results in a nice cleanup.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 .../intel/int33fe/intel_cht_int33fe_common.c  | 29 +------------------
 1 file changed, 1 insertion(+), 28 deletions(-)

diff --git a/drivers/platform/x86/intel/int33fe/intel_cht_int33fe_common.c b/drivers/platform/x86/intel/int33fe/intel_cht_int33fe_common.c
index 251ed9bac789..463222521e61 100644
--- a/drivers/platform/x86/intel/int33fe/intel_cht_int33fe_common.c
+++ b/drivers/platform/x86/intel/int33fe/intel_cht_int33fe_common.c
@@ -16,33 +16,6 @@
 
 #define EXPECTED_PTYPE		4
 
-static int cht_int33fe_i2c_res_filter(struct acpi_resource *ares, void *data)
-{
-	struct acpi_resource_i2c_serialbus *sb;
-	int *count = data;
-
-	if (i2c_acpi_get_i2c_resource(ares, &sb))
-		(*count)++;
-
-	return 1;
-}
-
-static int cht_int33fe_count_i2c_clients(struct device *dev)
-{
-	struct acpi_device *adev = ACPI_COMPANION(dev);
-	LIST_HEAD(resource_list);
-	int count = 0;
-	int ret;
-
-	ret = acpi_dev_get_resources(adev, &resource_list,
-				     cht_int33fe_i2c_res_filter, &count);
-	acpi_dev_free_resource_list(&resource_list);
-	if (ret < 0)
-		return ret;
-
-	return count;
-}
-
 static int cht_int33fe_check_hw_type(struct device *dev)
 {
 	unsigned long long ptyp;
@@ -69,7 +42,7 @@ static int cht_int33fe_check_hw_type(struct device *dev)
 		return -ENODEV;
 	}
 
-	ret = cht_int33fe_count_i2c_clients(dev);
+	ret = i2c_acpi_client_count(ACPI_COMPANION(dev));
 	if (ret < 0)
 		return ret;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function
  2021-08-03 16:00 [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function Hans de Goede
                   ` (3 preceding siblings ...)
  2021-08-03 16:00 ` [PATCH 4/4] platform/x86: intel_cht_int33fe: " Hans de Goede
@ 2021-08-03 16:14 ` Andy Shevchenko
  4 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2021-08-03 16:14 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Mark Gross, Andy Shevchenko, Wolfram Sang, Mika Westerberg,
	Platform Driver, linux-i2c, ACPI Devel Maling List

On Tue, Aug 3, 2021 at 7:01 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> Hi All,
>
> This patch-set adds a new i2c_acpi_client_count() helper function
> to remove a bunch of code-duplication.
>
> Since 3 of the 4 patches touch files under drivers/platform/x86 and
> also since the drivers/platform/x86/dual_accel_detect.h file is new
> in pdx86/for-next I believe that it would be best to just merge the
> entire series through my pdx86 tree.

Utterly in favour of this series
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Thanks for doing this!

> Mika + WSA, may I have your ack for merging the entire series through
> the pdx86 tree (or please let me know if you want to proceed in a
> different way) ?
>
> Regards,
>
> Hans
>
>
> Hans de Goede (4):
>   i2c: acpi: Add an i2c_acpi_client_count() helper function
>   platform/x86: dual_accel_detect: Use the new i2c_acpi_client_count()
>     helper
>   platform/x86: i2c-multi-instantiate: Use the new
>     i2c_acpi_client_count() helper
>   platform/x86: intel_cht_int33fe: Use the new i2c_acpi_client_count()
>     helper
>
>  drivers/i2c/i2c-core-acpi.c                   | 32 +++++++++++++++++++
>  drivers/platform/x86/dual_accel_detect.h      | 26 +--------------
>  drivers/platform/x86/i2c-multi-instantiate.c  | 27 +---------------
>  .../intel/int33fe/intel_cht_int33fe_common.c  | 29 +----------------
>  include/linux/i2c.h                           |  5 +++
>  5 files changed, 40 insertions(+), 79 deletions(-)
>
> --
> 2.31.1
>


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] i2c: acpi: Add an i2c_acpi_client_count() helper function
  2021-08-03 16:00 ` [PATCH 1/4] i2c: acpi: " Hans de Goede
@ 2021-08-03 16:50   ` Mika Westerberg
  2021-08-06 13:44     ` Hans de Goede
  0 siblings, 1 reply; 10+ messages in thread
From: Mika Westerberg @ 2021-08-03 16:50 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Mark Gross, Andy Shevchenko, Wolfram Sang, platform-driver-x86,
	linux-i2c, linux-acpi

On Tue, Aug 03, 2021 at 06:00:41PM +0200, Hans de Goede wrote:
> We have 3 files now which have the need to count the number of
> I2cSerialBus resources in an ACPI-device's resource-list.
> 
> Currently all implement their own helper function for this,
> add a generic helper function to replace the 3 implementations.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] i2c: acpi: Add an i2c_acpi_client_count() helper function
  2021-08-03 16:50   ` Mika Westerberg
@ 2021-08-06 13:44     ` Hans de Goede
  2021-08-10 20:44       ` Wolfram Sang
  0 siblings, 1 reply; 10+ messages in thread
From: Hans de Goede @ 2021-08-06 13:44 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: Mark Gross, Andy Shevchenko, Wolfram Sang, platform-driver-x86,
	linux-i2c, linux-acpi

Hi,

On 8/3/21 6:50 PM, Mika Westerberg wrote:
> On Tue, Aug 03, 2021 at 06:00:41PM +0200, Hans de Goede wrote:
>> We have 3 files now which have the need to count the number of
>> I2cSerialBus resources in an ACPI-device's resource-list.
>>
>> Currently all implement their own helper function for this,
>> add a generic helper function to replace the 3 implementations.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> 
> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Thank you, Wolfram are you also ok with me merging this
patch through the pdx86 tree?

Regards,

Hans


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] i2c: acpi: Add an i2c_acpi_client_count() helper function
  2021-08-06 13:44     ` Hans de Goede
@ 2021-08-10 20:44       ` Wolfram Sang
  2021-08-12 15:27         ` Hans de Goede
  0 siblings, 1 reply; 10+ messages in thread
From: Wolfram Sang @ 2021-08-10 20:44 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Mika Westerberg, Mark Gross, Andy Shevchenko,
	platform-driver-x86, linux-i2c, linux-acpi

[-- Attachment #1: Type: text/plain, Size: 561 bytes --]


> >> We have 3 files now which have the need to count the number of
> >> I2cSerialBus resources in an ACPI-device's resource-list.
> >>
> >> Currently all implement their own helper function for this,
> >> add a generic helper function to replace the 3 implementations.
> >>
> >> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> > 
> > Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> 
> Thank you, Wolfram are you also ok with me merging this
> patch through the pdx86 tree?

Sure!

Acked-by: Wolfram Sang <wsa@kernel.org>


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] i2c: acpi: Add an i2c_acpi_client_count() helper function
  2021-08-10 20:44       ` Wolfram Sang
@ 2021-08-12 15:27         ` Hans de Goede
  0 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2021-08-12 15:27 UTC (permalink / raw)
  To: Wolfram Sang, Mika Westerberg, Mark Gross, Andy Shevchenko,
	platform-driver-x86, linux-i2c, linux-acpi

Hi,

On 8/10/21 10:44 PM, Wolfram Sang wrote:
> 
>>>> We have 3 files now which have the need to count the number of
>>>> I2cSerialBus resources in an ACPI-device's resource-list.
>>>>
>>>> Currently all implement their own helper function for this,
>>>> add a generic helper function to replace the 3 implementations.
>>>>
>>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>>>
>>> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
>>
>> Thank you, Wolfram are you also ok with me merging this
>> patch through the pdx86 tree?
> 
> Sure!
> 
> Acked-by: Wolfram Sang <wsa@kernel.org>

Thank you. I've added this series to my review-hans branch now.

I'll push it out to pdx86/for-next after some (build) testing.

Regards,

Hans


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-08-12 15:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 16:00 [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function Hans de Goede
2021-08-03 16:00 ` [PATCH 1/4] i2c: acpi: " Hans de Goede
2021-08-03 16:50   ` Mika Westerberg
2021-08-06 13:44     ` Hans de Goede
2021-08-10 20:44       ` Wolfram Sang
2021-08-12 15:27         ` Hans de Goede
2021-08-03 16:00 ` [PATCH 2/4] platform/x86: dual_accel_detect: Use the new i2c_acpi_client_count() helper Hans de Goede
2021-08-03 16:00 ` [PATCH 3/4] platform/x86: i2c-multi-instantiate: " Hans de Goede
2021-08-03 16:00 ` [PATCH 4/4] platform/x86: intel_cht_int33fe: " Hans de Goede
2021-08-03 16:14 ` [PATCH 0/4] i2c/pdx86: Add an i2c_acpi_client_count() helper function Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).