diff mbox series

[v2,2/3] platform/x86: x86-android-tablets: Add support for getting i2c_adapter by PCI parent devname()

Message ID 20241104200848.58693-3-hdegoede@redhat.com (mailing list archive)
State Accepted, archived
Headers show
Series platform/x86: x86-android-tablets: Add support for Vexia EDU ATLA 10 tablet | expand

Commit Message

Hans de Goede Nov. 4, 2024, 8:08 p.m. UTC
On the Vexia EDU ATLA 10 tablet, which ships with Android + a custom Linux
(guadalinex) using the custom Android kernel the I2C controllers are not
enumerated as ACPI devices as they typically are.

Instead they are enumerated as PCI devices which do not have ACPI firmware
nodes associated with them, so getting the i2c_adapter by the ACPI path of
its firmware node does not work.

Add support for getting the i2c_adapter by the devname() of its PCI parent
instead.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
- Move "depends on PCI" Kconfig change to this patch
- Put the code to get the adapter in a get_i2c_adap_by_pci_parent() helper
---
 .../platform/x86/x86-android-tablets/Kconfig  |  4 +-
 .../platform/x86/x86-android-tablets/core.c   | 39 ++++++++++++++++++-
 .../x86-android-tablets/x86-android-tablets.h |  1 +
 3 files changed, 41 insertions(+), 3 deletions(-)

Comments

Andy Shevchenko Nov. 5, 2024, 8:22 a.m. UTC | #1
On Mon, Nov 4, 2024 at 10:09 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> On the Vexia EDU ATLA 10 tablet, which ships with Android + a custom Linux
> (guadalinex) using the custom Android kernel the I2C controllers are not
> enumerated as ACPI devices as they typically are.
>
> Instead they are enumerated as PCI devices which do not have ACPI firmware
> nodes associated with them, so getting the i2c_adapter by the ACPI path of
> its firmware node does not work.
>
> Add support for getting the i2c_adapter by the devname() of its PCI parent
> instead.

Reviewed-by: Andy Shevchenko <andy@kernel.org>

...

>         struct i2c_board_info board_info = client_info->board_info;
> -       struct i2c_adapter *adap;
> +       struct i2c_adapter *adap = NULL;

Unneeded change.
Hans de Goede Nov. 5, 2024, 10:47 a.m. UTC | #2
Hi,

On 5-Nov-24 9:22 AM, Andy Shevchenko wrote:
> On Mon, Nov 4, 2024 at 10:09 PM Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> On the Vexia EDU ATLA 10 tablet, which ships with Android + a custom Linux
>> (guadalinex) using the custom Android kernel the I2C controllers are not
>> enumerated as ACPI devices as they typically are.
>>
>> Instead they are enumerated as PCI devices which do not have ACPI firmware
>> nodes associated with them, so getting the i2c_adapter by the ACPI path of
>> its firmware node does not work.
>>
>> Add support for getting the i2c_adapter by the devname() of its PCI parent
>> instead.
> 
> Reviewed-by: Andy Shevchenko <andy@kernel.org>
> 
> ...
> 
>>         struct i2c_board_info board_info = client_info->board_info;
>> -       struct i2c_adapter *adap;
>> +       struct i2c_adapter *adap = NULL;
> 
> Unneeded change.

Ack I noticed this myself and I thought I had dropped this change,
but apparently I did not.

Ilpo can you fix this up while merging or do you want a v3 series?

Regards,

Hans
Ilpo Järvinen Nov. 6, 2024, 1:25 p.m. UTC | #3
On Tue, 5 Nov 2024, Hans de Goede wrote:

> Hi,
> 
> On 5-Nov-24 9:22 AM, Andy Shevchenko wrote:
> > On Mon, Nov 4, 2024 at 10:09 PM Hans de Goede <hdegoede@redhat.com> wrote:
> >>
> >> On the Vexia EDU ATLA 10 tablet, which ships with Android + a custom Linux
> >> (guadalinex) using the custom Android kernel the I2C controllers are not
> >> enumerated as ACPI devices as they typically are.
> >>
> >> Instead they are enumerated as PCI devices which do not have ACPI firmware
> >> nodes associated with them, so getting the i2c_adapter by the ACPI path of
> >> its firmware node does not work.
> >>
> >> Add support for getting the i2c_adapter by the devname() of its PCI parent
> >> instead.
> > 
> > Reviewed-by: Andy Shevchenko <andy@kernel.org>
> > 
> > ...
> > 
> >>         struct i2c_board_info board_info = client_info->board_info;
> >> -       struct i2c_adapter *adap;
> >> +       struct i2c_adapter *adap = NULL;
> > 
> > Unneeded change.
> 
> Ack I noticed this myself and I thought I had dropped this change,
> but apparently I did not.
> 
> Ilpo can you fix this up while merging or do you want a v3 series?

Thanks both.

I removed this change while applying. I also made minor adjustments to the 
braces in the patch 3 for stylish consistency.
Hans de Goede Nov. 6, 2024, 9:18 p.m. UTC | #4
Hi,

On 6-Nov-24 2:25 PM, Ilpo Järvinen wrote:
> On Tue, 5 Nov 2024, Hans de Goede wrote:
> 
>> Hi,
>>
>> On 5-Nov-24 9:22 AM, Andy Shevchenko wrote:
>>> On Mon, Nov 4, 2024 at 10:09 PM Hans de Goede <hdegoede@redhat.com> wrote:
>>>>
>>>> On the Vexia EDU ATLA 10 tablet, which ships with Android + a custom Linux
>>>> (guadalinex) using the custom Android kernel the I2C controllers are not
>>>> enumerated as ACPI devices as they typically are.
>>>>
>>>> Instead they are enumerated as PCI devices which do not have ACPI firmware
>>>> nodes associated with them, so getting the i2c_adapter by the ACPI path of
>>>> its firmware node does not work.
>>>>
>>>> Add support for getting the i2c_adapter by the devname() of its PCI parent
>>>> instead.
>>>
>>> Reviewed-by: Andy Shevchenko <andy@kernel.org>
>>>
>>> ...
>>>
>>>>         struct i2c_board_info board_info = client_info->board_info;
>>>> -       struct i2c_adapter *adap;
>>>> +       struct i2c_adapter *adap = NULL;
>>>
>>> Unneeded change.
>>
>> Ack I noticed this myself and I thought I had dropped this change,
>> but apparently I did not.
>>
>> Ilpo can you fix this up while merging or do you want a v3 series?
> 
> Thanks both.
> 
> I removed this change while applying. I also made minor adjustments to the 
> braces in the patch 3 for stylish consistency.

Great, Thank you for merging these.

Regards,

Hans
diff mbox series

Patch

diff --git a/drivers/platform/x86/x86-android-tablets/Kconfig b/drivers/platform/x86/x86-android-tablets/Kconfig
index 88d9e8f2ff24..a67bddc43007 100644
--- a/drivers/platform/x86/x86-android-tablets/Kconfig
+++ b/drivers/platform/x86/x86-android-tablets/Kconfig
@@ -5,7 +5,9 @@ 
 
 config X86_ANDROID_TABLETS
 	tristate "X86 Android tablet support"
-	depends on I2C && SPI && SERIAL_DEV_BUS && ACPI && EFI && GPIOLIB && PMIC_OPREGION
+	depends on I2C && SPI && SERIAL_DEV_BUS
+	depends on GPIOLIB && PMIC_OPREGION
+	depends on ACPI && EFI && PCI
 	select NEW_LEDS
 	select LEDS_CLASS
 	help
diff --git a/drivers/platform/x86/x86-android-tablets/core.c b/drivers/platform/x86/x86-android-tablets/core.c
index 4154395c60bb..5241b260c0e8 100644
--- a/drivers/platform/x86/x86-android-tablets/core.c
+++ b/drivers/platform/x86/x86-android-tablets/core.c
@@ -11,11 +11,13 @@ 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/acpi.h>
+#include <linux/device.h>
 #include <linux/dmi.h>
 #include <linux/gpio/consumer.h>
 #include <linux/gpio/machine.h>
 #include <linux/irq.h>
 #include <linux/module.h>
+#include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/serdev.h>
 #include <linux/string.h>
@@ -170,18 +172,51 @@  get_i2c_adap_by_handle(const struct x86_i2c_client_info *client_info)
 	return i2c_acpi_find_adapter_by_handle(handle);
 }
 
+static __init int match_parent(struct device *dev, const void *data)
+{
+	return dev->parent == data;
+}
+
+static struct i2c_adapter *
+get_i2c_adap_by_pci_parent(const struct x86_i2c_client_info *client_info)
+{
+	struct i2c_adapter *adap = NULL;
+	struct device *pdev, *adap_dev;
+
+	pdev = bus_find_device_by_name(&pci_bus_type, NULL, client_info->adapter_path);
+	if (!pdev) {
+		pr_err("Error could not find %s PCI device\n", client_info->adapter_path);
+		return NULL;
+	}
+
+	adap_dev = bus_find_device(&i2c_bus_type, NULL, pdev, match_parent);
+	if (adap_dev) {
+		adap = i2c_verify_adapter(adap_dev);
+		if (!adap)
+			put_device(adap_dev);
+	}
+
+	put_device(pdev);
+
+	return adap;
+}
+
 static __init int x86_instantiate_i2c_client(const struct x86_dev_info *dev_info,
 					     int idx)
 {
 	const struct x86_i2c_client_info *client_info = &dev_info->i2c_client_info[idx];
 	struct i2c_board_info board_info = client_info->board_info;
-	struct i2c_adapter *adap;
+	struct i2c_adapter *adap = NULL;
 
 	board_info.irq = x86_acpi_irq_helper_get(&client_info->irq_data);
 	if (board_info.irq < 0)
 		return board_info.irq;
 
-	adap = get_i2c_adap_by_handle(client_info);
+	if (dev_info->use_pci_devname)
+		adap = get_i2c_adap_by_pci_parent(client_info);
+	else
+		adap = get_i2c_adap_by_handle(client_info);
+
 	if (!adap) {
 		pr_err("error could not get %s adapter\n", client_info->adapter_path);
 		return -ENODEV;
diff --git a/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h b/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h
index 5517e438c7b6..d26a4792eb0e 100644
--- a/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h
+++ b/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h
@@ -91,6 +91,7 @@  struct x86_dev_info {
 	int gpio_button_count;
 	int (*init)(struct device *dev);
 	void (*exit)(void);
+	bool use_pci_devname;
 };
 
 int x86_android_tablet_get_gpiod(const char *chip, int pin, const char *con_id,