Skip to contentSkip to conversation

Add Intel LJCA device driver

PATCH Superseded Wentong Wu 5 participants 18 messages Sep 1, 2023 – Sep 13, 2023

Subsystems (5)

v12 of 20 Superseded Latest is v20 →

lore
Share & tools
lore

Wentong Wu

author
#0 lore raw

v12 cover Add Intel LJCA device driver

Add driver for Intel La Jolla Cove Adapter (LJCA) device. This is a USB-GPIO, USB-I2C and USB-SPI device. We add 4 drivers to support this device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.

---
v12:
- switch dev_err to dev_dbg for i2c-ljca driver
- avoid err printing because of calling usb_kill_urb when
attempts to resubmit the rx urb

v11:
- switch dev_err to dev_dbg for i2c-ljca driver
- remove message length check because of defined quirk structure
- remove I2C_FUNC_SMBUS_EMUL support

v10:
- remove ljca_i2c_format_slave_addr
- remove memset before write write w_packet
- make ljca_i2c_stop void and print err message in case failure
- use dev_err_probe in ljca_i2c_probe function

v9:
- overhaul usb-ljca driver to make it more structured and easy understand
- fix memory leak issue for usb-ljca driver
- add spinlock to protect tx_buf and ex_buf
- change exported APIs for usb-ljca driver
- unify prefix for structures and functions for i2c-ljca driver
- unify prefix for structures and functions for spi-ljca driver
- unify prefix for structures and functions for gpio-ljca driver
- update gpio-ljca, i2c-ljca and spi-ljca drivers according to usb-ljca's changes

Wentong Wu (4):
usb: Add support for Intel LJCA device
i2c: Add support for Intel LJCA USB I2C driver
spi: Add support for Intel LJCA USB SPI driver
gpio: update Intel LJCA USB GPIO driver

 drivers/gpio/Kconfig          |   4 +-
 drivers/gpio/gpio-ljca.c      | 246 +++++++------
 drivers/i2c/busses/Kconfig    |  11 +
 drivers/i2c/busses/Makefile   |   1 +
 drivers/i2c/busses/i2c-ljca.c | 326 +++++++++++++++++
 drivers/spi/Kconfig           |  11 +
 drivers/spi/Makefile          |   1 +
 drivers/spi/spi-ljca.c        | 297 +++++++++++++++
 drivers/usb/misc/Kconfig      |  14 +
 drivers/usb/misc/Makefile     |   1 +
 drivers/usb/misc/usb-ljca.c   | 817 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/usb/ljca.h      | 113 ++++++
 12 files changed, 1737 insertions(+), 105 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-ljca.c
 create mode 100644 drivers/spi/spi-ljca.c
 create mode 100644 drivers/usb/misc/usb-ljca.c
 create mode 100644 include/linux/usb/ljca.h
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v12 1/4 usb: Add support for Intel LJCA device

Implements the USB part of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA).

The communication between the various LJCA module drivers and the hardware will be muxed/demuxed by this driver. Three modules ( I2C, GPIO, and SPI) are supported currently.

Each sub-module of LJCA device is identified by type field within the LJCA message header.

The sub-modules of LJCA can use ljca_transfer() to issue a transfer between host and hardware. And ljca_register_event_cb is exported to LJCA sub-module drivers for hardware event subscription.

The minimum code in ASL that covers this board is
Scope (\_SB.PCI0.DWC3.RHUB.HS01)

    {
        Device (GPIO)
        {
            Name (_ADR, Zero)
            Name (_STA, 0x0F)
        }

        Device (I2C)
        {
            Name (_ADR, One)
            Name (_STA, 0x0F)
        }

        Device (SPI)
        {
            Name (_ADR, 0x02)
            Name (_STA, 0x0F)
        }
    }
---
 drivers/usb/misc/Kconfig    |  14 +
 drivers/usb/misc/Makefile   |   1 +
 drivers/usb/misc/usb-ljca.c | 817 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/usb/ljca.h    | 113 ++++++
 4 files changed, 945 insertions(+)
 create mode 100644 drivers/usb/misc/usb-ljca.c
 create mode 100644 include/linux/usb/ljca.h
drivers/usb/misc/Kconfig +14 -0
index 99b15b7..999193e 100644
@@ -165,6 +165,20 @@ config APPLE_MFI_FASTCHARGE
 
 	  It is safe to say M here.
 
+config USB_LJCA
+	tristate "Intel La Jolla Cove Adapter support"
+	select AUXILIARY_BUS
+	depends on USB
+	depends on ACPI || COMPILE_TEST
+	help
+	  This adds support for Intel La Jolla Cove USB-I2C/SPI/GPIO
+	  Master Adapter (LJCA). Additional drivers such as I2C_LJCA,
+	  GPIO_LJCA and SPI_LJCA must be enabled in order to use the
+	  functionality of the device.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called usb-ljca.
+
 source "drivers/usb/misc/sisusbvga/Kconfig"
 
 config USB_LD
drivers/usb/misc/Makefile +1 -0
index 1992cc2..0bc732bc 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_USB_EMI26)			+= emi26.o
 obj-$(CONFIG_USB_EMI62)			+= emi62.o
 obj-$(CONFIG_USB_EZUSB_FX2)		+= ezusb.o
 obj-$(CONFIG_APPLE_MFI_FASTCHARGE)	+= apple-mfi-fastcharge.o
+obj-$(CONFIG_USB_LJCA)			+= usb-ljca.o
 obj-$(CONFIG_USB_IDMOUSE)		+= idmouse.o
 obj-$(CONFIG_USB_IOWARRIOR)		+= iowarrior.o
 obj-$(CONFIG_USB_ISIGHTFW)		+= isight_firmware.o
drivers/usb/misc/usb-ljca.c new file +817 -0

817 lines not on this page · raw message

include/linux/usb/ljca.h new file +113 -0

113 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v12 1/4
#2 lore raw

Re: [PATCH v12 1/4] usb: Add support for Intel LJCA device

Hi Wentong,

Quoted 36 lines · Wentong Wu

Implements the USB part of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA).

The communication between the various LJCA module drivers and the hardware will be muxed/demuxed by this driver. Three modules ( I2C, GPIO, and SPI) are supported currently.

Each sub-module of LJCA device is identified by type field within the LJCA message header.

The sub-modules of LJCA can use ljca_transfer() to issue a transfer between host and hardware. And ljca_register_event_cb is exported to LJCA sub-module drivers for hardware event subscription.

The minimum code in ASL that covers this board is
Scope (\_SB.PCI0.DWC3.RHUB.HS01)

    {
        Device (GPIO)
        {
            Name (_ADR, Zero)
            Name (_STA, 0x0F)
        }

        Device (I2C)
        {
            Name (_ADR, One)
            Name (_STA, 0x0F)
        }

        Device (SPI)
        {
            Name (_ADR, 0x02)
            Name (_STA, 0x0F)
        }
    }
Quoted 2 lines

looks good:

Andi

#3 lore raw

RE: [PATCH v12 1/4] usb: Add support for Intel LJCA device

Hi Andi,

Thanks for your review

Quoted 41 lines

From: Andi Shyti <[email protected]>

Hi Wentong,

Quoted 36 lines · Wentong Wu

Implements the USB part of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA).

The communication between the various LJCA module drivers and the hardware will be muxed/demuxed by this driver. Three modules ( I2C, GPIO, and SPI) are supported currently.

Each sub-module of LJCA device is identified by type field within the LJCA message header.

The sub-modules of LJCA can use ljca_transfer() to issue a transfer between host and hardware. And ljca_register_event_cb is exported to LJCA sub-module drivers for hardware event subscription.

The minimum code in ASL that covers this board is Scope (\_SB.PCI0.DWC3.RHUB.HS01)

    {
        Device (GPIO)
        {
            Name (_ADR, Zero)
            Name (_STA, 0x0F)
        }

        Device (I2C)
        {
            Name (_ADR, One)
            Name (_STA, 0x0F)
        }

        Device (SPI)
        {
            Name (_ADR, 0x02)
            Name (_STA, 0x0F)
        }
    }
Quoted 6 lines
Quoted 2 lines

looks good:

Thanks

BR,
Wentong

Quoted 2 lines

Andi

author
#4 lore raw

PATCH v12 2/4 i2c: Add support for Intel LJCA USB I2C driver

In reply to Wentong Wu

Implements the I2C function of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA I2C module with specific protocol through interfaces exported by LJCA USB driver.

---
 drivers/i2c/busses/Kconfig    |  11 ++
 drivers/i2c/busses/Makefile   |   1 +
 drivers/i2c/busses/i2c-ljca.c | 326 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 338 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ljca.c
drivers/i2c/busses/Kconfig +11 -0
index 9cfe8fc..7e2c52d 100644
@@ -1264,6 +1264,17 @@ config I2C_DLN2
 	 This driver can also be built as a module.  If so, the module
 	 will be called i2c-dln2.
 
+config I2C_LJCA
+	tristate "I2C functionality of Intel La Jolla Cove Adapter"
+	depends on USB_LJCA
+	default USB_LJCA
+	help
+	  If you say yes to this option, I2C functionality support of Intel
+	  La Jolla Cove Adapter (LJCA) will be included.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-ljca.
+
 config I2C_CP2615
 	tristate "Silicon Labs CP2615 USB sound card and I2C adapter"
 	depends on USB
drivers/i2c/busses/Makefile +1 -0
index af56fe2..3757b93 100644
@@ -133,6 +133,7 @@ obj-$(CONFIG_I2C_GXP)		+= i2c-gxp.o
 # External I2C/SMBus adapter drivers
 obj-$(CONFIG_I2C_DIOLAN_U2C)	+= i2c-diolan-u2c.o
 obj-$(CONFIG_I2C_DLN2)		+= i2c-dln2.o
+obj-$(CONFIG_I2C_LJCA)		+= i2c-ljca.o
 obj-$(CONFIG_I2C_CP2615) += i2c-cp2615.o
 obj-$(CONFIG_I2C_PARPORT)	+= i2c-parport.o
 obj-$(CONFIG_I2C_PCI1XXXX)	+= i2c-mchp-pci1xxxx.o
drivers/i2c/busses/i2c-ljca.c new file +326 -0

326 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#5 lore raw

Re: [PATCH v12 2/4] i2c: Add support for Intel LJCA USB I2C driver

Hi Wolfram,

[...]

drivers/i2c/busses/i2c-ljca.c line 130

Quoted 6 lines
drivers/i2c/busses/i2c-ljca.c new file +6 -0
+	if (ret < 0 || ret < sizeof(*r_packet)) {
+		dev_dbg(&ljca_i2c->adap.dev,
+			"i2c stop failed ret: %d id: %d\n",
+			ret, w_packet->id);
+		return;
+	}

your comment here has been addressed. This commit depends on the first patch how do we get this in?

Thanks,
Andi

#6 lore raw

Re: [PATCH v12 2/4] i2c: Add support for Intel LJCA USB I2C driver

Hi Andi,

Quoted 2 lines

your comment here has been addressed. This commit depends on the first patch how do we get this in?

Wentong Wu confirmed my assumption that the auxiliary bus hides away the dependencies. So, we can simply merge it into for-mergewindow AFAIU.

author
#7 lore raw

PATCH v12 3/4 spi: Add support for Intel LJCA USB SPI driver

In reply to Wentong Wu

Implements the SPI function of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA SPI module with specific protocol through interfaces exported by LJCA USB driver.

---
 drivers/spi/Kconfig    |  11 ++
 drivers/spi/Makefile   |   1 +
 drivers/spi/spi-ljca.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 309 insertions(+)
 create mode 100644 drivers/spi/spi-ljca.c
drivers/spi/Kconfig +11 -0
index 8962b25..ad18864 100644
@@ -583,6 +583,17 @@ config SPI_FSL_ESPI
 	  From MPC8536, 85xx platform uses the controller, and all P10xx,
 	  P20xx, P30xx,P40xx, P50xx uses this controller.
 
+config SPI_LJCA
+	tristate "Intel La Jolla Cove Adapter SPI support"
+	depends on USB_LJCA
+	default USB_LJCA
+	help
+	  Select this option to enable SPI driver for the Intel
+	  La Jolla Cove Adapter (LJCA) board.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called spi-ljca.
+
 config SPI_MESON_SPICC
 	tristate "Amlogic Meson SPICC controller"
 	depends on COMMON_CLK
drivers/spi/Makefile +1 -0
index 080c2c1..0847962 100644
@@ -70,6 +70,7 @@ obj-$(CONFIG_SPI_INTEL_PCI)		+= spi-intel-pci.o
 obj-$(CONFIG_SPI_INTEL_PLATFORM)	+= spi-intel-platform.o
 obj-$(CONFIG_SPI_LANTIQ_SSC)		+= spi-lantiq-ssc.o
 obj-$(CONFIG_SPI_JCORE)			+= spi-jcore.o
+obj-$(CONFIG_SPI_LJCA)			+= spi-ljca.o
 obj-$(CONFIG_SPI_LM70_LLP)		+= spi-lm70llp.o
 obj-$(CONFIG_SPI_LP8841_RTC)		+= spi-lp8841-rtc.o
 obj-$(CONFIG_SPI_MESON_SPICC)		+= spi-meson-spicc.o
drivers/spi/spi-ljca.c new file +297 -0

297 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v12 3/4
#8 lore raw

Re: [PATCH v12 3/4] spi: Add support for Intel LJCA USB SPI driver

Hi Wentong,

Quoted 7 lines · Wentong Wu

Implements the SPI function of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA SPI module with specific protocol through interfaces exported by LJCA USB driver.

Thanks,
Andi

#9 lore raw

RE: [PATCH v12 3/4] spi: Add support for Intel LJCA USB SPI driver

Hi Andi,

Thanks for your review

Quoted 10 lines

From: Andi Shyti <[email protected]>

Hi Wentong,

Quoted 5 lines · Wentong Wu

Implements the SPI function of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA SPI module with specific protocol through interfaces exported by LJCA USB driver.

Quoted 4 lines
Quoted 2 lines

Thanks

BR,
Wentong

Quoted 3 lines

Thanks,
Andi

author
#10 lore raw

PATCH v12 4/4 gpio: update Intel LJCA USB GPIO driver

In reply to Wentong Wu

This driver communicate with LJCA GPIO module with specific protocol through interfaces exported by LJCA USB driver. Update the driver according to LJCA USB driver's changes.

---
 drivers/gpio/Kconfig     |   4 +-
 drivers/gpio/gpio-ljca.c | 246 +++++++++++++++++++++++++++--------------------
 2 files changed, 145 insertions(+), 105 deletions(-)
drivers/gpio/Kconfig +2 -2
index e382dfe..c85843b 100644
@@ -1294,9 +1294,9 @@ config GPIO_KEMPLD
 
 config GPIO_LJCA
 	tristate "INTEL La Jolla Cove Adapter GPIO support"
-	depends on MFD_LJCA
+	depends on USB_LJCA
 	select GPIOLIB_IRQCHIP
-	default MFD_LJCA
+	default USB_LJCA
 	help
 	  Select this option to enable GPIO driver for the INTEL
 	  La Jolla Cove Adapter (LJCA) board.
drivers/gpio/gpio-ljca.c +143 -103

473 lines not on this page · raw message

Signature · 1 line
2.7.4
#11 lore raw

Re: [PATCH v12 4/4] gpio: update Intel LJCA USB GPIO driver

Hi Wentong,

Quoted 8 lines · Wentong Wu

This driver communicate with LJCA GPIO module with specific protocol through interfaces exported by LJCA USB driver. Update the driver according to LJCA USB driver's changes.

I am not understanding this patch... Looks like a collection of random to relevant changes you did in gpio-ljca.c.

I'm not able to review this, can you please split it in minor changes?

Meanwhile the previous patches should be able to work without this one, right?

Andi

#12 lore raw

RE: [PATCH v12 4/4] gpio: update Intel LJCA USB GPIO driver

Hi Andi,

Thanks for your review

Quoted 9 lines

From: Andi Shyti <[email protected]>

Hi Wentong,

Quoted 4 lines · Wentong Wu

This driver communicate with LJCA GPIO module with specific protocol through interfaces exported by LJCA USB driver.
Update the driver according to LJCA USB driver's changes.

Quoted 7 lines
Quoted 4 lines

I am not understanding this patch... Looks like a collection of random to relevant changes you did in gpio-ljca.c.

This patch is following the changes of usb-ljca, from platform_device to auxiliary_device, and ljca_transfer API's change. And others are mainly coding style's change.

Quoted 4 lines

I'm not able to review this, can you please split it in minor changes?

Meanwhile the previous patches should be able to work without this one, right?

I don't think it can work without usb-ljca

BR,
Wentong

Quoted 2 lines

Andi

maintainer
#13 lore raw

Re: [PATCH v12 4/4] gpio: update Intel LJCA USB GPIO driver

Hi Wentong,

Quoted 10 lines
Quoted 10 lines · Wentong Wu
Quoted 8 lines

This driver communicate with LJCA GPIO module with specific protocol through interfaces exported by LJCA USB driver.
Update the driver according to LJCA USB driver's changes.

Quoted 6 lines
Quoted 2 lines

I am not understanding this patch... Looks like a collection of random to relevant changes you did in gpio-ljca.c.

This patch is following the changes of usb-ljca, from platform_device to auxiliary_device, and ljca_transfer API's change. And others are mainly coding style's change.

then please divide this into smaller commits. Cosmetic changes should be in separate patches, and functional changes in different commits. They should not be mixed together.

Quoted 5 lines
Quoted 3 lines

I'm not able to review this, can you please split it in minor changes?

Meanwhile the previous patches should be able to work without this one, right?

I don't think it can work without usb-ljca

I am actually asking about the reverse. Are we confident that patches 1, 2, and 3 function correctly without this one? I didn't notice any dependencies.

If that's the case, I would suggest removing this patch from the series, merging patches 1, 2, and 3, and then addressing this patch separately. It can be properly divided and expanded into a more comprehensive series.

Andi

Tested-by on the v12 series
#14 lore raw
In reply to Wentong Wu

Hi,

Quoted 4 lines · Wentong Wu

Add driver for Intel La Jolla Cove Adapter (LJCA) device. This is a USB-GPIO, USB-I2C and USB-SPI device. We add 4 drivers to support this device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.

Thanks. I've been testing this on a Lenovo X1 ThinkPad Yoga gen 8 with an ov2740 sensor connected to the LJCA device.

I needed 2 small(ish) fixes to make everything work there. I have attached the 2 fixes here.

With these 2 fixes this series is:

Regards,

Hans

Quoted 42 lines

---
v12:
- switch dev_err to dev_dbg for i2c-ljca driver
- avoid err printing because of calling usb_kill_urb when
attempts to resubmit the rx urb

v11:
- switch dev_err to dev_dbg for i2c-ljca driver
- remove message length check because of defined quirk structure
- remove I2C_FUNC_SMBUS_EMUL support

v10:
- remove ljca_i2c_format_slave_addr
- remove memset before write write w_packet
- make ljca_i2c_stop void and print err message in case failure
- use dev_err_probe in ljca_i2c_probe function

v9:
- overhaul usb-ljca driver to make it more structured and easy understand
- fix memory leak issue for usb-ljca driver
- add spinlock to protect tx_buf and ex_buf
- change exported APIs for usb-ljca driver
- unify prefix for structures and functions for i2c-ljca driver
- unify prefix for structures and functions for spi-ljca driver
- unify prefix for structures and functions for gpio-ljca driver
- update gpio-ljca, i2c-ljca and spi-ljca drivers according to usb-ljca's changes

Wentong Wu (4):
usb: Add support for Intel LJCA device
i2c: Add support for Intel LJCA USB I2C driver
spi: Add support for Intel LJCA USB SPI driver
gpio: update Intel LJCA USB GPIO driver

 drivers/gpio/Kconfig          |   4 +-
 drivers/gpio/gpio-ljca.c      | 246 +++++++------
 drivers/i2c/busses/Kconfig    |  11 +
 drivers/i2c/busses/Makefile   |   1 +
 drivers/i2c/busses/i2c-ljca.c | 326 +++++++++++++++++
 drivers/spi/Kconfig           |  11 +
 drivers/spi/Makefile          |   1 +
 drivers/spi/spi-ljca.c        | 297 +++++++++++++++
 drivers/usb/misc/Kconfig      |  14 +
Quoted 9 lines
 drivers/usb/misc/Makefile     |   1 +
 drivers/usb/misc/usb-ljca.c   | 817 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/usb/ljca.h      | 113 ++++++
 12 files changed, 1737 insertions(+), 105 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-ljca.c
 create mode 100644 drivers/spi/spi-ljca.c
 create mode 100644 drivers/usb/misc/usb-ljca.c
 create mode 100644 include/linux/usb/ljca.h

From c43f73014c652a6616b360edc2be582098960382 Mon Sep 17 00:00:00 2001
From: Hans de Goede <[email protected]>
Date: Sat, 2 Sep 2023 12:08:16 +0200
Subject: [PATCH 1/4] usb: ljca: Fix picking the ACPI companion for the I2C
controllers

The ljca IO-expander has 2 I2C controllers, which both have the same API HID, e.g. "INTC1097" on a Lenovo X1 ThinkPad Yoga gen 8.

Taking the first ACPI companion which matches the HID results in both I2C controllers getting assigned the same ACPI companion.

Add an ACPI UID check to assign the right companion to both I2C controllers. This fixes no i2c-client getting instantiated for the ov2740 sensor on a Lenovo X1 ThinkPad Yoga gen 8.

Note some DSDTs have only 1 ACPI companion for the 2 I2C controllers and these don't set a UID at all. On these models only the first I2C controller is used. So if a HID match has no UID use "0" for the HID. assigning the ACPI companion to the first I2C controller. An example device with this setup is the Dell Latitude 9420.

---
 drivers/usb/misc/usb-ljca.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)
drivers/usb/misc/usb-ljca.c +22 -8
index 4b0a77725bdd..82b8e1ea6bbb 100644
@@ -349,6 +349,7 @@ EXPORT_SYMBOL_NS_GPL(ljca_unregister_event_cb, LJCA);
 #ifdef CONFIG_ACPI
 struct ljca_match_ids_walk_data {
 	const struct acpi_device_id *ids;
+	const char *uid;
 	struct acpi_device *adev;
 };
 
@@ -379,23 +380,34 @@ static const struct acpi_device_id ljca_spi_hids[] = {
 static int ljca_match_device_ids(struct acpi_device *adev, void *data)
 {
 	struct ljca_match_ids_walk_data *wd = data;
+	const char *uid = acpi_device_uid(adev);
 
-	if (!acpi_match_device_ids(adev, wd->ids)) {
-		wd->adev = adev;
-		return 1;
-	}
+	if (acpi_match_device_ids(adev, wd->ids))
+		return 0;
 
-	return 0;
+	if (!wd->uid)
+		goto match;
+
+	if (!uid)
+		uid = "0";
+
+	if (strcmp(uid, wd->uid))
+		return 0;
+
+match:
+	wd->adev = adev;
+	return 1;
 }
 
 /* bind auxiliary device to acpi device */
 static void ljca_auxdev_acpi_bind(struct ljca_adapter *adap,
 				  struct auxiliary_device *auxdev,
-				  u64 adr)
+				  u64 adr, u8 id)
 {
 	struct ljca_match_ids_walk_data wd = { 0 };
 	struct acpi_device *parent, *adev;
 	struct device *dev = adap->dev;
+	char uid[4];
 
 	parent = ACPI_COMPANION(dev);
 	if (!parent)
@@ -421,6 +433,8 @@ static void ljca_auxdev_acpi_bind(struct ljca_adapter *adap,
 		break;
 	case LJCA_I2C1_ACPI_ADR:
 	case LJCA_I2C2_ACPI_ADR:
+		snprintf(uid, sizeof(uid), "%d", id);
+		wd.uid = uid;
 		wd.ids = ljca_i2c_hids;
 		break;
 	case LJCA_SPI1_ACPI_ADR:
@@ -449,7 +463,7 @@ static void ljca_auxdev_acpi_bind(struct ljca_adapter *adap,
 #else
 static void ljca_auxdev_acpi_bind(struct ljca_adapter *adap,
 				  struct auxiliary_device *auxdev,
-				  u64 adr)
+				  u64 adr, u8 id)
 {
 }
 #endif
@@ -489,7 +503,7 @@ static int ljca_new_client_device(struct ljca_adapter *adap, u8 type, u8 id,
 	if (ret)
 		goto err_free;
 
-	ljca_auxdev_acpi_bind(adap, auxdev, adr);
+	ljca_auxdev_acpi_bind(adap, auxdev, adr, id);
 
 	ret = auxiliary_device_add(auxdev);
 	if (ret)
Signature · 1 line
2.41.0

From dfa3bb3d5f403b36b779509b9dcfbf1114eebee2 Mon Sep 17 00:00:00 2001
From: Hans de Goede <[email protected]>
Date: Fri, 1 Sep 2023 19:47:48 +0200
Subject: [PATCH 2/4] i2c: ljca: Call acpi_dev_clear_dependencies()

Call acpi_dev_clear_dependencies() to mark _DEP ACPI dependencies on the I2C controller as satisfied so that acpi_dev_ready_for_enumeration() for the I2C device nodes in APCI will return true once the I2C controller is registered.

---
 drivers/i2c/busses/i2c-ljca.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-ljca.c +8 -1
index 357234894dea..3aff4de52920 100644
@@ -303,7 +303,14 @@ static int ljca_i2c_probe(struct auxiliary_device *auxdev,
 				     "i2c init failed id: %d\n",
 				     ljca_i2c->i2c_info->id);
 
-	return devm_i2c_add_adapter(&auxdev->dev, &ljca_i2c->adap);
+	ret = devm_i2c_add_adapter(&auxdev->dev, &ljca_i2c->adap);
+	if (ret)
+		return ret;
+
+	if (has_acpi_companion(&ljca_i2c->adap.dev))
+		acpi_dev_clear_dependencies(ACPI_COMPANION(&ljca_i2c->adap.dev));
+
+	return 0;
 }
 
 static const struct auxiliary_device_id ljca_i2c_id_table[] = {
Signature · 1 line
2.41.0
#15 lore raw

Hi Hans,

Thanks

Quoted 4 lines

From: Hans de Goede <[email protected]>

Hi,

Quoted 8 lines
Quoted 4 lines · Wentong Wu

Add driver for Intel La Jolla Cove Adapter (LJCA) device. This is a USB-GPIO, USB-I2C and USB-SPI device. We add 4 drivers to support this
device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.

Thanks. I've been testing this on a Lenovo X1 ThinkPad Yoga gen 8 with an ov2740 sensor connected to the LJCA device.

Thanks, and I don’t have this laptop, could you please share your DSDT so that I can understand it more?

And I will update this patch set after understand your DSDT and have the patches tested on my setup.

Quoted 7 lines

I needed 2 small(ish) fixes to make everything work there. I have attached the 2 fixes here.

With these 2 fixes this series is:

Thanks a lot

BR,
Wentong

Quoted 62 lines

Regards,

Hans

Quoted 35 lines

---
v12:
- switch dev_err to dev_dbg for i2c-ljca driver
- avoid err printing because of calling usb_kill_urb when attempts to
resubmit the rx urb

v11:
- switch dev_err to dev_dbg for i2c-ljca driver
- remove message length check because of defined quirk structure
- remove I2C_FUNC_SMBUS_EMUL support

v10:
- remove ljca_i2c_format_slave_addr
- remove memset before write write w_packet
- make ljca_i2c_stop void and print err message in case failure
- use dev_err_probe in ljca_i2c_probe function

v9:
- overhaul usb-ljca driver to make it more structured and easy
understand
- fix memory leak issue for usb-ljca driver
- add spinlock to protect tx_buf and ex_buf
- change exported APIs for usb-ljca driver
- unify prefix for structures and functions for i2c-ljca driver
- unify prefix for structures and functions for spi-ljca driver
- unify prefix for structures and functions for gpio-ljca driver
- update gpio-ljca, i2c-ljca and spi-ljca drivers according to
usb-ljca's changes

Wentong Wu (4):
usb: Add support for Intel LJCA device
i2c: Add support for Intel LJCA USB I2C driver
spi: Add support for Intel LJCA USB SPI driver
gpio: update Intel LJCA USB GPIO driver

Quoted 11 lines
 drivers/gpio/Kconfig          |   4 +-
 drivers/gpio/gpio-ljca.c      | 246 +++++++------
 drivers/i2c/busses/Kconfig    |  11 +
 drivers/i2c/busses/Makefile   |   1 +
 drivers/i2c/busses/i2c-ljca.c | 326 +++++++++++++++++
 drivers/spi/Kconfig           |  11 +
 drivers/spi/Makefile          |   1 +
 drivers/spi/spi-ljca.c        | 297 +++++++++++++++
 drivers/usb/misc/Kconfig      |  14 +
 drivers/usb/misc/Makefile     |   1 +
 drivers/usb/misc/usb-ljca.c   | 817

++++++++++++++++++++++++++++++++++++++++++

Quoted 6 lines
 include/linux/usb/ljca.h      | 113 ++++++
 12 files changed, 1737 insertions(+), 105 deletions(-)  create mode

100644 drivers/i2c/busses/i2c-ljca.c create mode 100644 drivers/spi/spi-ljca.c create mode 100644 drivers/usb/misc/usb-ljca.c create mode 100644 include/linux/usb/ljca.h

#16 lore raw

Hi,

Quoted 14 lines · Wentong

Hi Hans,

Thanks

Quoted 10 lines

From: Hans de Goede <[email protected]>

Hi,

Quoted 4 lines · Wentong Wu

Add driver for Intel La Jolla Cove Adapter (LJCA) device. This is a USB-GPIO, USB-I2C and USB-SPI device. We add 4 drivers to support this
device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.

Quoted 5 lines
Quoted 2 lines

Thanks. I've been testing this on a Lenovo X1 ThinkPad Yoga gen 8 with an ov2740 sensor connected to the LJCA device.

Thanks, and I don’t have this laptop, could you please share your DSDT so that I can understand it more?

I have send you an acpidump by private email.

Quoted 2 lines

And I will update this patch set after understand your DSDT and have the patches tested on my setup.

Ok. Note that the out of tree ivsc driver already does uid matching in the i2c-driver to fixup the wrong ACPI companion being assigned by the MFD driver, see:

https://github.com/intel/ivsc-driver/blob/main/drivers/i2c/busses/i2c-ljca.c#L346

For upstream it seemed cleaner to me to directly pick the correct ACPI companion at aux-device instantiation, something which was not possible with the MFD approach but is possible with the auxilary bus approach.

And the other change which I'm proposing has already been merged into the out of tree version of the LJCA i2c driver:

https://github.com/intel/ivsc-driver/commit/70d95269169cf9e452580b0c15471829df4a6d59

Regards,

Hans

Quoted 73 lines
Quoted 6 lines

I needed 2 small(ish) fixes to make everything work there. I have attached the 2 fixes here.

With these 2 fixes this series is:

Thanks a lot

BR,
Wentong

Quoted 62 lines

Regards,

Hans

Quoted 35 lines

---
v12:
- switch dev_err to dev_dbg for i2c-ljca driver
- avoid err printing because of calling usb_kill_urb when attempts to
resubmit the rx urb

v11:
- switch dev_err to dev_dbg for i2c-ljca driver
- remove message length check because of defined quirk structure
- remove I2C_FUNC_SMBUS_EMUL support

v10:
- remove ljca_i2c_format_slave_addr
- remove memset before write write w_packet
- make ljca_i2c_stop void and print err message in case failure
- use dev_err_probe in ljca_i2c_probe function

v9:
- overhaul usb-ljca driver to make it more structured and easy
understand
- fix memory leak issue for usb-ljca driver
- add spinlock to protect tx_buf and ex_buf
- change exported APIs for usb-ljca driver
- unify prefix for structures and functions for i2c-ljca driver
- unify prefix for structures and functions for spi-ljca driver
- unify prefix for structures and functions for gpio-ljca driver
- update gpio-ljca, i2c-ljca and spi-ljca drivers according to
usb-ljca's changes

Wentong Wu (4):
usb: Add support for Intel LJCA device
i2c: Add support for Intel LJCA USB I2C driver
spi: Add support for Intel LJCA USB SPI driver
gpio: update Intel LJCA USB GPIO driver

Quoted 11 lines
 drivers/gpio/Kconfig          |   4 +-
 drivers/gpio/gpio-ljca.c      | 246 +++++++------
 drivers/i2c/busses/Kconfig    |  11 +
 drivers/i2c/busses/Makefile   |   1 +
 drivers/i2c/busses/i2c-ljca.c | 326 +++++++++++++++++
 drivers/spi/Kconfig           |  11 +
 drivers/spi/Makefile          |   1 +
 drivers/spi/spi-ljca.c        | 297 +++++++++++++++
 drivers/usb/misc/Kconfig      |  14 +
 drivers/usb/misc/Makefile     |   1 +
 drivers/usb/misc/usb-ljca.c   | 817

++++++++++++++++++++++++++++++++++++++++++

Quoted 6 lines
 include/linux/usb/ljca.h      | 113 ++++++
 12 files changed, 1737 insertions(+), 105 deletions(-)  create mode

100644 drivers/i2c/busses/i2c-ljca.c create mode 100644 drivers/spi/spi-ljca.c create mode 100644 drivers/usb/misc/usb-ljca.c create mode 100644 include/linux/usb/ljca.h

#17 lore raw

Hi Hans,

Thanks

Quoted 29 lines

From: Hans de Goede <[email protected]>

Hi,

Quoted 15 lines · Wentong

Hi Hans,

Thanks

Quoted 11 lines

From: Hans de Goede <[email protected]>

Hi,

Quoted 5 lines · Wentong Wu

Add driver for Intel La Jolla Cove Adapter (LJCA) device. This is a USB-GPIO, USB-I2C and USB-SPI device. We add 4 drivers to support this
device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.

Quoted 6 lines
Quoted 3 lines

Thanks. I've been testing this on a Lenovo X1 ThinkPad Yoga gen 8 with an
ov2740 sensor connected to the LJCA device.

Thanks, and I don’t have this laptop, could you please share your DSDT so that I can understand it more?

I have send you an acpidump by private email.

Quoted 8 lines
Quoted 2 lines

And I will update this patch set after understand your DSDT and have the patches tested on my setup.

Ok. Note that the out of tree ivsc driver already does uid matching in the i2c- driver to fixup the wrong ACPI companion being assigned by the MFD driver, see:

https://github.com/intel/ivsc-driver/blob/main/drivers/i2c/busses/i2c-
ljca.c#L346

Thanks, there is a little bit change based on your patch, because since RPL the UID becomes "Name (_UID, "VIC0")" style. Could you please revisit below code?

static int ljca_match_device_ids(struct acpi_device *adev, void *data)

{
        struct ljca_match_ids_walk_data *wd = data;
        const char *uid = acpi_device_uid(adev);

        if (acpi_match_device_ids(adev, wd->ids))
                return 0;

        if (!wd->uid)
                goto match;

        if (!uid)
                uid = "0";
        else
                uid = memchr(uid, wd->uid[0], strlen(uid));

        if (!uid || strcmp(uid, wd->uid))
                return 0;

match:

        wd->adev = adev;

        return 1;
}

Thanks
Wentong

Quoted 2 lines

For upstream it seemed cleaner to me to directly pick the correct ACPI

Thanks

Quoted 92 lines

companion at aux-device instantiation, something which was not possible with the MFD approach but is possible with the auxilary bus approach.

And the other change which I'm proposing has already been merged into the out of tree version of the LJCA i2c driver:

https://github.com/intel/ivsc-
driver/commit/70d95269169cf9e452580b0c15471829df4a6d59

Regards,

Hans

Quoted 74 lines
Quoted 6 lines

I needed 2 small(ish) fixes to make everything work there. I have attached the 2 fixes here.

With these 2 fixes this series is:

Thanks a lot

BR,
Wentong

Quoted 63 lines

Regards,

Hans

Quoted 35 lines

---
v12:
- switch dev_err to dev_dbg for i2c-ljca driver
- avoid err printing because of calling usb_kill_urb when attempts
to resubmit the rx urb

v11:
- switch dev_err to dev_dbg for i2c-ljca driver
- remove message length check because of defined quirk structure
- remove I2C_FUNC_SMBUS_EMUL support

v10:
- remove ljca_i2c_format_slave_addr
- remove memset before write write w_packet
- make ljca_i2c_stop void and print err message in case failure
- use dev_err_probe in ljca_i2c_probe function

v9:
- overhaul usb-ljca driver to make it more structured and easy
understand
- fix memory leak issue for usb-ljca driver
- add spinlock to protect tx_buf and ex_buf
- change exported APIs for usb-ljca driver
- unify prefix for structures and functions for i2c-ljca driver
- unify prefix for structures and functions for spi-ljca driver
- unify prefix for structures and functions for gpio-ljca driver
- update gpio-ljca, i2c-ljca and spi-ljca drivers according to
usb-ljca's changes

Wentong Wu (4):
usb: Add support for Intel LJCA device
i2c: Add support for Intel LJCA USB I2C driver
spi: Add support for Intel LJCA USB SPI driver
gpio: update Intel LJCA USB GPIO driver

Quoted 11 lines
 drivers/gpio/Kconfig          |   4 +-
 drivers/gpio/gpio-ljca.c      | 246 +++++++------
 drivers/i2c/busses/Kconfig    |  11 +
 drivers/i2c/busses/Makefile   |   1 +
 drivers/i2c/busses/i2c-ljca.c | 326 +++++++++++++++++
 drivers/spi/Kconfig           |  11 +
 drivers/spi/Makefile          |   1 +
 drivers/spi/spi-ljca.c        | 297 +++++++++++++++
 drivers/usb/misc/Kconfig      |  14 +
 drivers/usb/misc/Makefile     |   1 +
 drivers/usb/misc/usb-ljca.c   | 817

++++++++++++++++++++++++++++++++++++++++++

Quoted 7 lines
 include/linux/usb/ljca.h      | 113 ++++++
 12 files changed, 1737 insertions(+), 105 deletions(-)  create mode

100644 drivers/i2c/busses/i2c-ljca.c create mode 100644 drivers/spi/spi-ljca.c create mode 100644 drivers/usb/misc/usb-ljca.c create mode 100644 include/linux/usb/ljca.h