diff mbox series

[1/4] i2c: acpi: Add an i2c_acpi_client_count() helper function

Message ID 20210803160044.158802-2-hdegoede@redhat.com (mailing list archive)
State Accepted, archived
Headers show
Series i2c/pdx86: Add an i2c_acpi_client_count() helper function | expand

Commit Message

Hans de Goede Aug. 3, 2021, 4 p.m. UTC
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(+)

Comments

Mika Westerberg Aug. 3, 2021, 4:50 p.m. UTC | #1
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>
Hans de Goede Aug. 6, 2021, 1:44 p.m. UTC | #2
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
Wolfram Sang Aug. 10, 2021, 8:44 p.m. UTC | #3
> >> 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>
Hans de Goede Aug. 12, 2021, 3:27 p.m. UTC | #4
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
diff mbox series

Patch

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;