Skip to contentSkip to conversation

Add Intel LJCA device driver

PATCH Superseded Wentong Wu 4 participants 11 messages Aug 16, 2023 – Aug 24, 2023

Subsystems (5)

v9 of 20 Superseded Latest is v20 →

lore
Share & tools
lore

Wentong Wu

author
#0 lore raw

v9 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.

---
v9:
- overhaul usb-ljca driver to make it more structured and easy understanding
- 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      | 242 +++++++------
 drivers/i2c/busses/Kconfig    |  11 +
 drivers/i2c/busses/Makefile   |   1 +
 drivers/i2c/busses/i2c-ljca.c | 353 ++++++++++++++++++
 drivers/spi/Kconfig           |  11 +
 drivers/spi/Makefile          |   1 +
 drivers/spi/spi-ljca.c        | 299 ++++++++++++++++
 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, 1764 insertions(+), 103 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 v9 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
author
#2 lore raw

PATCH v9 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 | 353 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 365 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 +353 -0

353 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#5 lore raw

PATCH v9 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 | 299 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 311 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 +299 -0

299 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#6 lore raw

PATCH v9 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 | 242 +++++++++++++++++++++++++++--------------------
 2 files changed, 143 insertions(+), 103 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 +141 -101

469 lines not on this page · raw message

Signature · 1 line
2.7.4
Acked-by on v9 4/4
#7 lore raw

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

Quoted 6 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.

This patch does several things at the same time, consider the "one technical step per patch" approach, for some definition of a "technical step". The upside is that git bisect gets better precision when something goes sidewise.

However it's no big deal for me as I'm not hung up on process and I bet you have tested the result, so:

Yours,
Linus Walleij

#8 lore raw

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

Quoted 9 lines

From: Linus Walleij <[email protected]>

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 6 lines
Quoted 2 lines

This patch does several things at the same time, consider the "one technical step per patch" approach, for some definition of a "technical step". The upside is that git bisect gets better precision when something goes sidewise.

Ack, thanks. I will follow this going forward.

Quoted 3 lines

However it's no big deal for me as I'm not hung up on process and I bet you have tested the result, so:

Definitely, I have tested this patch sets dozens of times.

Quoted 1 line

Thanks a lot

BR,
Wentong

Quoted 3 lines

Yours,
Linus Walleij

maintainer
#3 lore raw

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

In reply to Wentong Wu

Hi Weontong,

patch looks good, just few minor comments.

[...]

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

Quoted 4 lines
drivers/i2c/busses/i2c-ljca.c new file +4 -0
+static u8 ljca_i2c_format_slave_addr(u8 slave_addr, u8 type)
+{
+	return (slave_addr << 1) | type;
+}

this is used only once, you could eventually ger rid of it and use explicitely in the start function.

[...]

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

Quoted 11 lines
drivers/i2c/busses/i2c-ljca.c new file +11 -0
+static int ljca_i2c_start(struct ljca_i2c_dev *ljca_i2c, u8 slave_addr,
+			  enum ljca_xfer_type type)
+{
+	struct ljca_i2c_rw_packet *w_packet =
+			(struct ljca_i2c_rw_packet *)ljca_i2c->obuf;
+	struct ljca_i2c_rw_packet *r_packet =
+			(struct ljca_i2c_rw_packet *)ljca_i2c->ibuf;
+	s16 rp_len;
+	int ret;
+
+	memset(w_packet, 0, sizeof(*w_packet));

do you really need to set this to '0' as you are initializing the header

Quoted 14 lines
drivers/i2c/busses/i2c-ljca.c new file +14 -0
+	w_packet->id = ljca_i2c->i2c_info->id;
+	w_packet->len = cpu_to_le16(sizeof(*w_packet->data));
+	w_packet->data[0] = ljca_i2c_format_slave_addr(slave_addr, type);
+
+	ret = ljca_transfer(ljca_i2c->ljca, LJCA_I2C_START, w_packet,
+			    struct_size(w_packet, data, 1), r_packet,
+			    LJCA_I2C_BUF_SIZE);
+	if (ret < 0)
+		return ret;
+	else if (ret < sizeof(*r_packet))
+		return -EIO;
+
+	rp_len = le16_to_cpu(r_packet->len);
+	if (rp_len < 0 || r_packet->id != w_packet->id) {

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

Quoted 10 lines
drivers/i2c/busses/i2c-ljca.c new file +10 -0
+		dev_err(&ljca_i2c->adap.dev,
+			"i2c start failed len: %d id: %d %d\n",
+			rp_len, r_packet->id, w_packet->id);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static int ljca_i2c_stop(struct ljca_i2c_dev *ljca_i2c, u8 slave_addr)

the return value here is not used anywhere, what about making this function void and printing a warning in case of failure?

[...]

Quoted 3 lines
drivers/i2c/busses/i2c-ljca.c new file +3 -0
+static int ljca_i2c_probe(struct auxiliary_device *auxdev,
+			  const struct auxiliary_device_id *aux_dev_id)
+{

[...]

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

Quoted 5 lines
drivers/i2c/busses/i2c-ljca.c new file +5 -0
+	ret = ljca_i2c_init(ljca_i2c, ljca_i2c->i2c_info->id);
+	if (ret) {
+		dev_err(&auxdev->dev, "i2c init failed id: %d\n",
+			ljca_i2c->i2c_info->id);
+		return -EIO;

please use dev_err_probe();

Andi

#4 lore raw

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

Hi Andi,

Thanks for your review.

Quoted 5 lines

From: Andi Shyti <[email protected]>

Hi Weontong,

patch looks good, just few minor comments.

Thanks, and below comments will be fixed in next version patch set.

BR,
Wentong

Quoted 9 lines

[...]

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

Quoted 3 lines
drivers/i2c/busses/i2c-ljca.c new file +3 -0
+static u8 ljca_i2c_format_slave_addr(u8 slave_addr, u8 type) {
+	return (slave_addr << 1) | type;
+}

this is used only once, you could eventually ger rid of it and use explicitely in the start function.

Ack, thanks.

Quoted 16 lines

[...]

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

Quoted 11 lines
drivers/i2c/busses/i2c-ljca.c new file +11 -0
+static int ljca_i2c_start(struct ljca_i2c_dev *ljca_i2c, u8 slave_addr,
+			  enum ljca_xfer_type type)
+{
+	struct ljca_i2c_rw_packet *w_packet =
+			(struct ljca_i2c_rw_packet *)ljca_i2c->obuf;
+	struct ljca_i2c_rw_packet *r_packet =
+			(struct ljca_i2c_rw_packet *)ljca_i2c->ibuf;
+	s16 rp_len;
+	int ret;
+
+	memset(w_packet, 0, sizeof(*w_packet));

do you really need to set this to '0' as you are initializing the header

Ack, thanks

Quoted 21 lines
Quoted 21 lines
drivers/i2c/busses/i2c-ljca.c new file +20 -0
+	w_packet->id = ljca_i2c->i2c_info->id;
+	w_packet->len = cpu_to_le16(sizeof(*w_packet->data));
+	w_packet->data[0] = ljca_i2c_format_slave_addr(slave_addr, type);
+
+	ret = ljca_transfer(ljca_i2c->ljca, LJCA_I2C_START, w_packet,
+			    struct_size(w_packet, data, 1), r_packet,
+			    LJCA_I2C_BUF_SIZE);
+	if (ret < 0)
+		return ret;
+	else if (ret < sizeof(*r_packet))
+		return -EIO;
+
+	rp_len = le16_to_cpu(r_packet->len);
+	if (rp_len < 0 || r_packet->id != w_packet->id) {
+		dev_err(&ljca_i2c->adap.dev,
+			"i2c start failed len: %d id: %d %d\n",
+			rp_len, r_packet->id, w_packet->id);
+		return -EIO;
+	}
+
Quoted 8 lines

drivers/i2c/busses/i2c-ljca.c

Quoted 5 lines
drivers/i2c/busses/i2c-ljca.c new file +5 -0
+	return 0;
+}
+
+static int ljca_i2c_stop(struct ljca_i2c_dev *ljca_i2c, u8
+slave_addr)

the return value here is not used anywhere, what about making this function void and printing a warning in case of failure?

Ack, thanks

Quoted 8 lines

[...]

Quoted 2 lines
(quoted diff) +2 -0
+static int ljca_i2c_probe(struct auxiliary_device *auxdev,
+			  const struct auxiliary_device_id *aux_dev_id) {

[...]

Quoted 7 lines

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

Quoted 5 lines
drivers/i2c/busses/i2c-ljca.c new file +5 -0
+	ret = ljca_i2c_init(ljca_i2c, ljca_i2c->i2c_info->id);
+	if (ret) {
+		dev_err(&auxdev->dev, "i2c init failed id: %d\n",
+			ljca_i2c->i2c_info->id);
+		return -EIO;

please use dev_err_probe();

Ack, thanks

Quoted 2 lines

Andi

#9 lore raw

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

In reply to Wu, Wentong

Hi Wentong, Linus,

Quoted 9 lines · Wentong
Quoted 9 lines

From: Linus Walleij <[email protected]>

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 8 lines
Quoted 6 lines
Quoted 2 lines

This patch does several things at the same time, consider the "one technical step per patch" approach, for some definition of a "technical step". The upside is that git bisect gets better precision when something goes sidewise.

Ack, thanks. I will follow this going forward.

The old LJCA GPIO driver got added without the rest of the LJCA, including the main driver (now 1st patch of this set). I might have just reverted the patch that added the old one and put the new one on top.

The old driver was never usable AFAIU and there are many changes as Linus noted. It would be easier to review as new driver.

I wonder what others think.

Signature · 3 lines
Regards,

Sakari Ailus
#10 lore raw

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

Quoted 25 lines

From: [email protected] <[email protected]>

Hi Wentong, Linus,

Quoted 9 lines · Wentong
Quoted 9 lines

From: Linus Walleij <[email protected]>

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 6 lines
Quoted 6 lines
Quoted 2 lines

This patch does several things at the same time, consider the "one technical step per patch" approach, for some definition of a "technical step". The upside is that git bisect gets better precision when

something goes sidewise.

Quoted 2 lines

Ack, thanks. I will follow this going forward.

Quoted 8 lines

The old LJCA GPIO driver got added without the rest of the LJCA, including the main driver (now 1st patch of this set). I might have just reverted the patch that added the old one and put the new one on top.

The old driver was never usable AFAIU and there are many changes as Linus noted. It would be easier to review as new driver.

I wonder what others think.

Agree, Thanks

BR,
Wentong

Quoted 5 lines

--
Regards,

Sakari Ailus