Skip to contentSkip to conversation

Add Intel LJCA device driver

PATCH Superseded Ye Xiang 5 participants 18 messages Mar 25, 2023 – Apr 12, 2023

Subsystems (5)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Ye Xiang

author
#0 lore raw

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

---
v7:
- ljca: remove unused field udev in struct ljca_dev.
- ljca: rename ljca module name to usb-ljca.
- ljca: use CONFIG_ACPI to enclose acpi related code.
- ljca/gpio/i2c/spi: aligh MACRO defination.

v6:
- ljca: split LJCA USB driver into two commits: USB part and API part.
- gpio/i2c/spi: use auxiliary bus for sub-module device enumeration instead of MFD.
- move document patch for LJCA sysfs entry to the 3th patch of this patch series.
- ljca: fix potential race condition when wait response timeout.
- ljca: use devm_kzalloc to malloc ljca device struct.

v5:
- move ljca.h from drivers/include/mfd to drivers/include/usb.
- ljca: fix a potential memory leak issue.
- add a blank line before return to adust to kernel code style.
- ljca: sysfs: split "cmd" to "ljca_dfu" and "ljca_trace_level".

v4:
- move ljca.c from drivers/mfd to drivers/usb/misc folder.
- fix index warning in sysfs-bus-devices-ljca.

v3:
- spi: make ljca_spi_transfer inline and fix an endian issue.

v2:
- ljca: remove reset command.
- gpio/spi/i2c: add default MFD_LJCA in Kconfig.
- gpio: add "select GPIOLIB_IRQCHIP" in Kconfig.

Ye Xiang (6):
usb: Add support for Intel LJCA device
usb: ljca: Add transport interfaces for sub-module drivers
Documentation: Add ABI doc for attributes of LJCA device
gpio: Add support for Intel LJCA USB GPIO driver
i2c: Add support for Intel LJCA USB I2C driver
spi: Add support for Intel LJCA USB SPI driver

 .../ABI/testing/sysfs-bus-usb-devices-ljca    |   36 +
 drivers/gpio/Kconfig                          |   12 +
 drivers/gpio/Makefile                         |    1 +
 drivers/gpio/gpio-ljca.c                      |  458 ++++++++
 drivers/i2c/busses/Kconfig                    |   11 +
 drivers/i2c/busses/Makefile                   |    1 +
 drivers/i2c/busses/i2c-ljca.c                 |  355 ++++++
 drivers/spi/Kconfig                           |   11 +
 drivers/spi/Makefile                          |    1 +
 drivers/spi/spi-ljca.c                        |  289 +++++
 drivers/usb/misc/Kconfig                      |   13 +
 drivers/usb/misc/Makefile                     |    1 +
 drivers/usb/misc/usb-ljca.c                   | 1027 +++++++++++++++++
 include/linux/usb/ljca.h                      |   95 ++
 14 files changed, 2311 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-usb-devices-ljca
 create mode 100644 drivers/gpio/gpio-ljca.c
 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.34.1
author
#1 lore raw

PATCH v7 1/6 usb: Add support for Intel LJCA device

This patch 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 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    |  13 +
 drivers/usb/misc/Makefile   |   1 +
 drivers/usb/misc/usb-ljca.c | 966 ++++++++++++++++++++++++++++++++++++
 include/linux/usb/ljca.h    |  43 ++
 4 files changed, 1023 insertions(+)
 create mode 100644 drivers/usb/misc/usb-ljca.c
 create mode 100644 include/linux/usb/ljca.h
drivers/usb/misc/Kconfig +13 -0
index a5f7652db7da..6566039b3e1c 100644
@@ -273,6 +273,19 @@ config USB_LINK_LAYER_TEST
 	  Layer Test Device. Say Y only when you want to conduct USB Super Speed
 	  Link Layer Test for host controllers.
 
+config USB_LJCA
+	tristate "Intel La Jolla Cove Adapter support"
+	select AUXILIARY_BUS
+	depends on USB
+	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.
+
 config USB_CHAOSKEY
 	tristate "ChaosKey random number generator driver support"
 	depends on HW_RANDOM
drivers/usb/misc/Makefile +1 -0
index 93581baec3a8..a41d02cc4f3e 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_USB_HUB_USB251XB)		+= usb251xb.o
 obj-$(CONFIG_USB_HSIC_USB3503)		+= usb3503.o
 obj-$(CONFIG_USB_HSIC_USB4604)		+= usb4604.o
 obj-$(CONFIG_USB_CHAOSKEY)		+= chaoskey.o
+obj-$(CONFIG_USB_LJCA)			+= usb-ljca.o
 
 obj-$(CONFIG_USB_SISUSBVGA)		+= sisusbvga/
 obj-$(CONFIG_USB_LINK_LAYER_TEST)	+= lvstest.o
drivers/usb/misc/usb-ljca.c new file +966 -0

966 lines not on this page · raw message

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

43 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v7 1/6] usb: Add support for Intel LJCA device

Quoted 11 lines · Ye Xiang

This patch 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 minimum code in ASL that covers this board is

As this requires ACPI, why are you not saying so in your Kconfig entry? What good would this driver be without ACPI enabled?

thanks,

greg k-h

author
#3 lore raw

Re: [PATCH v7 1/6] usb: Add support for Intel LJCA device

Hi Greg,

Thanks for the review.

Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Ye Xiang

This patch 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.

Quoted 6 lines
Quoted 4 lines

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

The minimum code in ASL that covers this board is

As this requires ACPI, why are you not saying so in your Kconfig entry?

I would add a depends on ACPI item on the Kconfig entry so that the CONFI_ACPI macro can be removed from usb-ljca, because our use case with LJCA currently needs the ACPI binding.

Quoted 1 line

What good would this driver be without ACPI enabled?

Before, I just tried to make it compatible with other platforms that don't support ACPI but want to use LJCA device. But, We don't have this use case until now.

Thanks
Ye Xiang

#4 lore raw

Re: [PATCH v7 1/6] usb: Add support for Intel LJCA device

Quoted 15 lines · Xiang

Hi Greg,

Thanks for the review.

Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Ye Xiang

This patch 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.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

The minimum code in ASL that covers this board is

As this requires ACPI, why are you not saying so in your Kconfig entry?

I would add a depends on ACPI item on the Kconfig entry so that the CONFI_ACPI macro can be removed from usb-ljca, because our use case with LJCA currently needs the ACPI binding.

That would make more sense.

thanks,

greg k-h

maintainer
#5 lore raw

Re: [PATCH v7 1/6] usb: Add support for Intel LJCA device

In reply to Ye, Xiang
Quoted 7 lines · Xiang
Quoted 1 line · Greg Kroah-Hartman

As this requires ACPI, why are you not saying so in your Kconfig entry?

I would add a depends on ACPI item on the Kconfig entry so that the CONFI_ACPI macro can be removed from usb-ljca, because our use case with

Quoted 6 lines

LJCA currently needs the ACPI binding.

Quoted 1 line

What good would this driver be without ACPI enabled?

Before, I just tried to make it compatible with other platforms that don't support ACPI but want to use LJCA device. But, We don't have this use case until now.

If it builds without ACPI then making the dependency ACPI || COMPILE_TEST will help improve build coverage for people doing treewide or subsystem work.

#6 lore raw

Re: [PATCH v7 1/6] usb: Add support for Intel LJCA device

In reply to Ye Xiang
Quoted 1 line · Ye Xiang

+static void ljca_aux_release(struct device *dev) {}

Sorry, but creating an empty release function just to shut the kernel up is NOT how to properly do this, you all know better. This is totally broken. The kernel was telling you what you had to do, don't think that you are being smarter than it by doing this, otherwise we would have never had the kernel spit out that error in the first place, right?

Now I will ask you to follow the proper Intel kernel review rules and get proper approval for the patchset before submitting it to us again, as basic things like this are not supposed to be caught by us, but by your internal review process first.

good luck!

greg k-h

author
#7 lore raw

Re: [PATCH v7 1/6] usb: Add support for Intel LJCA device

Quoted 8 lines · Greg Kroah-Hartman
Quoted 1 line · Ye Xiang

+static void ljca_aux_release(struct device *dev) {}

Sorry, but creating an empty release function just to shut the kernel up is NOT how to properly do this, you all know better. This is totally broken. The kernel was telling you what you had to do, don't think that you are being smarter than it by doing this, otherwise we would have never had the kernel spit out that error in the first place, right?

Got it. Will use the release callback to free memory used by the auxiliary device instead.

Quoted 5 lines

Now I will ask you to follow the proper Intel kernel review rules and get proper approval for the patchset before submitting it to us again, as basic things like this are not supposed to be caught by us, but by your internal review process first.

Thanks. I will get approval on Intel's internal review first before sending the next version out for review.

--
Thanks
Ye Xiang

#8 lore raw

Re: [PATCH v7 1/6] usb: Add support for Intel LJCA device

In reply to Ye Xiang

On 25.03.23 16:47, Ye Xiang wrote:

Hi,

Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10 -0
+static int ljca_parse(struct ljca_dev *dev, struct ljca_msg *header)
+{
+	struct ljca_stub *stub;
+
+	stub = ljca_stub_find(dev, header->type);
+	if (IS_ERR(stub))
+		return PTR_ERR(stub);
+
+	if (!(header->flags & LJCA_ACK_FLAG)) {
+		ljca_stub_notify(stub, header->cmd, header->data, header->len);

drivers/usb/misc/usb-ljca.c line 274

Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10 -0
+		return 0;
+	}
+
+	if (stub->cur_cmd != header->cmd) {
+		dev_err(&dev->intf->dev, "header and stub current command mismatch (%x vs %x)\n",
+			header->cmd, stub->cur_cmd);
+		return -EINVAL;
+	}
+
+	if (stub->ipacket.ibuf && stub->ipacket.ibuf_len) {

Here you read those values from ipacket.

drivers/usb/misc/usb-ljca.c line 277

Quoted 3 lines
drivers/usb/misc/usb-ljca.c new file +3 -0
+		unsigned int newlen;
+
+		newlen = min_t(unsigned int, header->len, *stub->ipacket.ibuf_len);

Here you read them again.

drivers/usb/misc/usb-ljca.c line 280

Quoted 3 lines
drivers/usb/misc/usb-ljca.c new file +3 -0
+
+		*stub->ipacket.ibuf_len = newlen;
+		memcpy(stub->ipacket.ibuf, header->data, newlen);

And here you read them again. The compiler is free to generate a memory access for ipacket.ibuf, which may read a new value from RAM. That means here you have a window in which you can no longer guarantee stub->ipacket.ibuf != NULL,
if you set it to NULL elsewhere.

Quoted 70 lines
drivers/usb/misc/usb-ljca.c new file +70 -0
+	}
+
+	stub->acked = true;
+	wake_up(&dev->ack_wq);
+
+	return 0;
+}
+
+static int ljca_stub_write(struct ljca_stub *stub, u8 cmd, const void *obuf, unsigned int obuf_len,
+			   void *ibuf, unsigned int *ibuf_len, bool wait_ack, unsigned long timeout)
+{
+	struct ljca_dev *dev = usb_get_intfdata(stub->intf);
+	u8 flags = LJCA_CMPL_FLAG;
+	struct ljca_msg *header;
+	unsigned int msg_len = sizeof(*header) + obuf_len;
+	int actual;
+	int ret;
+
+	if (msg_len > LJCA_MAX_PACKET_SIZE)
+		return -EINVAL;
+
+	if (wait_ack)
+		flags |= LJCA_ACK_FLAG;
+
+	header = kmalloc(msg_len, GFP_KERNEL);
+	if (!header)
+		return -ENOMEM;
+
+	header->type = stub->type;
+	header->cmd = cmd;
+	header->flags = flags;
+	header->len = obuf_len;
+
+	if (obuf)
+		memcpy(header->data, obuf, obuf_len);
+
+	dev_dbg(&dev->intf->dev, "send: type:%d cmd:%d flags:%d len:%d\n", header->type,
+		header->cmd, header->flags, header->len);
+
+	usb_autopm_get_interface(dev->intf);
+	if (!dev->started) {
+		kfree(header);
+		ret = -ENODEV;
+		goto error_put;
+	}
+
+	mutex_lock(&dev->mutex);
+	stub->cur_cmd = cmd;
+	stub->ipacket.ibuf = ibuf;
+	stub->ipacket.ibuf_len = ibuf_len;
+	stub->acked = false;
+	ret = usb_bulk_msg(interface_to_usbdev(dev->intf),
+			   usb_sndbulkpipe(interface_to_usbdev(dev->intf), dev->out_ep), header,
+			   msg_len, &actual, LJCA_USB_WRITE_TIMEOUT_MS);
+	kfree(header);
+	if (ret) {
+		dev_err(&dev->intf->dev, "bridge write failed ret:%d\n", ret);
+		goto error_unlock;
+	}
+
+	if (actual != msg_len) {
+		dev_err(&dev->intf->dev, "bridge write length mismatch (%d vs %d)\n", msg_len,
+			actual);
+		ret = -EINVAL;
+		goto error_unlock;
+	}
+
+	if (wait_ack) {
+		ret = wait_event_timeout(dev->ack_wq, stub->acked, msecs_to_jiffies(timeout));
+		if (!ret) {

drivers/usb/misc/usb-ljca.c line 360

Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10 -0
+			dev_err(&dev->intf->dev, "acked wait timeout\n");
+			ret = -ETIMEDOUT;
+			goto error_unlock;
+		}
+	}
+
+	ret = 0;
+error_unlock:
+	stub->ipacket.ibuf = NULL;
+	stub->ipacket.ibuf_len = NULL;

And here you set stub->ipacket.ibuf to NULL.
If you do that and want consistency, you'll need to use READ_ONCE and a local variable if you read this in interrupt.

drivers/usb/misc/usb-ljca.c line 367

Quoted 7 lines
drivers/usb/misc/usb-ljca.c new file +7 -0
+	mutex_unlock(&dev->mutex);
+error_put:
+	usb_autopm_put_interface(dev->intf);
+
+	return ret;
+}
+

HTH,
Oliver

author
#9 lore raw

PATCH v7 2/6 usb: ljca: Add transport interfaces for sub-module drivers

In reply to Ye Xiang

This patch adds the transport interfaces for various LJCA sub-module drivers to communicate with LJCA hardware. The sub-module 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.

---
 drivers/usb/misc/usb-ljca.c | 61 +++++++++++++++++++++++++++++++++++++
 include/linux/usb/ljca.h    | 52 +++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
drivers/usb/misc/usb-ljca.c +61 -0
index 96e2b8c43c58..a5312869693a 100644
@@ -365,6 +365,67 @@ static int ljca_stub_write(struct ljca_stub *stub, u8 cmd, const void *obuf, uns
 	return ret;
 }
 
+static int ljca_transfer_internal(struct ljca *ljca, u8 cmd, const void *obuf,
+				  unsigned int obuf_len, void *ibuf, unsigned int *ibuf_len,
+				  bool wait_ack)
+{
+	struct ljca_stub *stub;
+
+	stub = ljca_stub_find(ljca->dev, ljca->type);
+	if (IS_ERR(stub))
+		return PTR_ERR(stub);
+
+	return ljca_stub_write(stub, cmd, obuf, obuf_len, ibuf, ibuf_len, wait_ack,
+			       LJCA_USB_WRITE_ACK_TIMEOUT_MS);
+}
+
+int ljca_transfer(struct ljca *ljca, u8 cmd, const void *obuf, unsigned int obuf_len, void *ibuf,
+		  unsigned int *ibuf_len)
+{
+	return ljca_transfer_internal(ljca, cmd, obuf, obuf_len, ibuf, ibuf_len, true);
+}
+EXPORT_SYMBOL_NS_GPL(ljca_transfer, LJCA);
+
+int ljca_transfer_noack(struct ljca *ljca, u8 cmd, const void *obuf, unsigned int obuf_len)
+{
+	return ljca_transfer_internal(ljca, cmd, obuf, obuf_len, NULL, NULL, false);
+}
+EXPORT_SYMBOL_NS_GPL(ljca_transfer_noack, LJCA);
+
+int ljca_register_event_cb(struct ljca *ljca, ljca_event_cb_t event_cb, void *context)
+{
+	struct ljca_stub *stub;
+	unsigned long flags;
+
+	stub = ljca_stub_find(ljca->dev, ljca->type);
+	if (IS_ERR(stub))
+		return PTR_ERR(stub);
+
+	spin_lock_irqsave(&stub->event_cb_lock, flags);
+	stub->event_entry.notify = event_cb;
+	stub->event_entry.context = context;
+	spin_unlock_irqrestore(&stub->event_cb_lock, flags);
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(ljca_register_event_cb, LJCA);
+
+void ljca_unregister_event_cb(struct ljca *ljca)
+{
+	struct ljca_stub *stub;
+	unsigned long flags;
+
+	stub = ljca_stub_find(ljca->dev, ljca->type);
+	if (IS_ERR(stub))
+		return;
+
+	spin_lock_irqsave(&stub->event_cb_lock, flags);
+	stub->event_entry.notify = NULL;
+	stub->event_entry.context = NULL;
+	spin_unlock_irqrestore(&stub->event_cb_lock, flags);
+}
+EXPORT_SYMBOL_NS_GPL(ljca_unregister_event_cb, LJCA);
+
 static void ljca_read_complete(struct urb *urb)
 {
 	struct ljca_msg *header = urb->transfer_buffer;
include/linux/usb/ljca.h +52 -0

56 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#10 lore raw

PATCH v7 3/6 Documentation: Add ABI doc for attributes of LJCA device

In reply to Ye Xiang

Add sysfs attributes Documentation entries for LJCA device

---
 .../ABI/testing/sysfs-bus-usb-devices-ljca    | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-usb-devices-ljca
Documentation/ABI/testing/sysfs-bus-usb-devices-ljca new file +36 -0
new file mode 100644
index 000000000000..16eecaf870e2
@@ -0,0 +1,36 @@
+What:		/sys/bus/usb/.../ljca_version
+Date:		July 2023
+KernelVersion:	6.4
+Contact:	Ye Xiang <[email protected]>
+Description:
+		Provides the current firmware version of LJCA device.
+		The format is Major.Minor.Patch.Build, where
+		Major, Minor, Patch, and Build are decimal numbers.
+		For example: 1.0.0.256
+
+What:		/sys/bus/usb/.../ljca_enable_dfu
+Date:		July 2023
+KernelVersion:	6.4
+Contact:	Ye Xiang <[email protected]>
+Description:
+		Writing 1 to this file to force the LJCA device into DFU
+		mode so the firmware can be updated. After firmware
+		updating has been done, the device will back to normal
+		working mode.
+
+What:		/sys/bus/usb/.../ljca_trace_level
+Date:		July 2023
+KernelVersion:	6.4
+Contact:	Ye Xiang <[email protected]>
+Description:
+		Writing N to this file to set firmware log level of LJCA
+		device. The log can be printed to another computer through
+		UART ports in LJCA device. Valid values:
+
+		  ==	==========
+		   0	LEVEL_ERROR
+		   1	LEVEL_WARNING
+		   2	LEVEL_INFO
+		   3	LEVEL_DEBUG
+		   4	LEVEL_OFF
+		  ==	==========
Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH v7 3/6] Documentation: Add ABI doc for attributes of LJCA device

Quoted 1 line · Ye Xiang

Add sysfs attributes Documentation entries for LJCA device

Hi,

do we really want each driver to have its own attribute for that? It seems to me that that should be unified.

Regards
Oliver

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-usb-devices-ljca new file +10 -0
+
+What:		/sys/bus/usb/.../ljca_enable_dfu
+Date:		July 2023
+KernelVersion:	6.4
+Contact:	Ye Xiang<[email protected]>
+Description:
+		Writing 1 to this file to force the LJCA device into DFU
+		mode so the firmware can be updated. After firmware
+		updating has been done, the device will back to normal
+		working mode.
author
#12 lore raw

Re: [PATCH v7 3/6] Documentation: Add ABI doc for attributes of LJCA device

Hi Oliver

Thanks for the review.

Quoted 9 lines · Oliver Neukum
Quoted 1 line · Ye Xiang

Add sysfs attributes Documentation entries for LJCA device

Hi,

do we really want each driver to have its own attribute for that? It seems to me that that should be unified.

Three ABI entries are added in this patch: ljca_version, ljca_trace_level, and ljca_enable_dfu. The first two items are specified for LJCA device and I think they can be kept in sysfs-bus-usb-devices-ljca.

But for ljca_enable_dfu, I didn't see a unified DFU entry in sys-bus-usb. I am not sure whether other USB devices have similar DFU mode or not.

Any suggestions?

Thanks
Ye Xiang

Quoted 11 lines
Quoted 11 lines
Documentation/ABI/testing/sysfs-bus-usb-devices-ljca new file +10 -0
+
+What:		/sys/bus/usb/.../ljca_enable_dfu
+Date:		July 2023
+KernelVersion:	6.4
+Contact:	Ye Xiang<[email protected]>
+Description:
+		Writing 1 to this file to force the LJCA device into DFU
+		mode so the firmware can be updated. After firmware
+		updating has been done, the device will back to normal
+		working mode.
#13 lore raw

Re: [PATCH v7 3/6] Documentation: Add ABI doc for attributes of LJCA device

On 10.04.23 12:44, Ye, Xiang wrote:

Hi,

Quoted 10 lines
Quoted 2 lines

do we really want each driver to have its own attribute for that? It seems to me that that should be unified.

Three ABI entries are added in this patch: ljca_version, ljca_trace_level, and ljca_enable_dfu. The first two items are specified for LJCA device and I think they can be kept in sysfs-bus-usb-devices-ljca.

But for ljca_enable_dfu, I didn't see a unified DFU entry in sys-bus-usb. I am not sure whether other USB devices have similar DFU mode or not.

Any suggestions?

What exactly does this attribute do?
Is it in addition to the normal DFU_DETACH + reset sequence, is it needed for DFU_DETACH to work, does it enable the
DFU class interface descriptor?

A point of DFU is rather that the capability should be announced via descriptors. The answer would depend on what exactly this attribute does.

Regards
Oliver

author
#14 lore raw

PATCH v7 4/6 gpio: Add support for Intel LJCA USB GPIO driver

In reply to Ye Xiang

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

---
 drivers/gpio/Kconfig     |  12 +
 drivers/gpio/Makefile    |   1 +
 drivers/gpio/gpio-ljca.c | 458 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 471 insertions(+)
 create mode 100644 drivers/gpio/gpio-ljca.c
drivers/gpio/Kconfig +12 -0
index 13be729710f2..70c57b3ccb22 100644
@@ -1253,6 +1253,18 @@ config GPIO_KEMPLD
 	  This driver can also be built as a module. If so, the module will be
 	  called gpio-kempld.
 
+config GPIO_LJCA
+	tristate "INTEL La Jolla Cove Adapter GPIO support"
+	depends on USB_LJCA
+	select GPIOLIB_IRQCHIP
+	default USB_LJCA
+	help
+	  Select this option to enable GPIO 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 gpio-ljca.
+
 config GPIO_LP3943
 	tristate "TI/National Semiconductor LP3943 GPIO expander"
 	depends on MFD_LP3943
drivers/gpio/Makefile +1 -0
index c048ba003367..eb59524d18c0 100644
@@ -77,6 +77,7 @@ obj-$(CONFIG_GPIO_IXP4XX)		+= gpio-ixp4xx.o
 obj-$(CONFIG_GPIO_JANZ_TTL)		+= gpio-janz-ttl.o
 obj-$(CONFIG_GPIO_KEMPLD)		+= gpio-kempld.o
 obj-$(CONFIG_GPIO_LATCH)		+= gpio-latch.o
+obj-$(CONFIG_GPIO_LJCA) 		+= gpio-ljca.o
 obj-$(CONFIG_GPIO_LOGICVC)		+= gpio-logicvc.o
 obj-$(CONFIG_GPIO_LOONGSON1)		+= gpio-loongson1.o
 obj-$(CONFIG_GPIO_LOONGSON)		+= gpio-loongson.o
drivers/gpio/gpio-ljca.c new file +458 -0

458 lines not on this page · raw message

Signature · 1 line
2.34.1
#15 lore raw

Re: [PATCH v7 4/6] gpio: Add support for Intel LJCA USB GPIO driver

Hi Ye,

thanks for your patch!

Quoted 6 lines · Ye Xiang

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

Lots of improvements! here are some comments:

Quoted 5 lines
drivers/gpio/Kconfig +1 -0
@@ -1253,6 +1253,18 @@ config GPIO_KEMPLD
          This driver can also be built as a module. If so, the module will be
          called gpio-kempld.
 
+config GPIO_LJCA

drivers/gpio/Kconfig config GPIO_KEMPLD · line 1266

Quoted 10 lines
drivers/gpio/Kconfig +10 -0
+       tristate "INTEL La Jolla Cove Adapter GPIO support"
+       depends on USB_LJCA
+       select GPIOLIB_IRQCHIP
+       default USB_LJCA
+       help
+         Select this option to enable GPIO 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 gpio-ljca.

The GPIO Kconfig has a separate submenu for USB expanders, so put this Kconfig in that submenu. This makes the choice come in a more logical spot and not appear on configs that don't even have USB.

(...)

drivers/gpio/gpio-ljca.c line 66

Quoted 6 lines
drivers/gpio/gpio-ljca.c new file +6 -0
+       DECLARE_BITMAP(unmasked_irqs, LJCA_MAX_GPIO_NUM);
+       DECLARE_BITMAP(enabled_irqs, LJCA_MAX_GPIO_NUM);
+       DECLARE_BITMAP(reenable_irqs, LJCA_MAX_GPIO_NUM);
+       u8 *connect_mode;
+       /* mutex to protect irq bus */
+       struct mutex irq_lock;

(...)

With IRQ code like this from a USB callback:

Quoted 14 lines
drivers/gpio/gpio-ljca.c new file +14 -0
+static void ljca_gpio_event_cb(void *context, u8 cmd, const void *evt_data, int len)
+{
+       const struct gpio_packet *packet = evt_data;
+       struct ljca_gpio_dev *ljca_gpio = context;
+       int i;
+       int irq;
+
+       if (cmd != LJCA_GPIO_INT_EVENT)
+               return;
+
+       for (i = 0; i < packet->num; i++) {
+               irq = irq_find_mapping(ljca_gpio->gc.irq.domain, packet->item[i].index);
+               if (!irq) {
+                       dev_err(ljca_gpio->gc.parent, "gpio_id %u does not mapped to IRQ yet\n",

drivers/gpio/gpio-ljca.c line 274

Quoted 10 lines
drivers/gpio/gpio-ljca.c new file +10 -0
+                               packet->item[i].index);
+                       return;
+               }
+
+               generic_handle_domain_irq(ljca_gpio->gc.irq.domain, irq);
+               set_bit(packet->item[i].index, ljca_gpio->reenable_irqs);
+       }
+
+       schedule_work(&ljca_gpio->work);
+}

I don't feel comfortable merging this unless Marc Zyngier has looked at the code first, so please CC him on this patch next time.

drivers/gpio/gpio-ljca.c line 367

Quoted 10 lines
drivers/gpio/gpio-ljca.c new file +10 -0
+static const struct irq_chip ljca_gpio_irqchip = {
+       .name = "ljca-irq",
+       .irq_mask = ljca_irq_mask,
+       .irq_unmask = ljca_irq_unmask,
+       .irq_set_type = ljca_irq_set_type,
+       .irq_bus_lock = ljca_irq_bus_lock,
+       .irq_bus_sync_unlock = ljca_irq_bus_unlock,
+       .flags = IRQCHIP_IMMUTABLE,
+       GPIOCHIP_IRQ_RESOURCE_HELPERS,
+};

Thanks for fixing the immutable irq chip!

drivers/gpio/gpio-ljca.c line 390

Quoted 3 lines
drivers/gpio/gpio-ljca.c new file +3 -0
+       ljca_gpio->auxdev = auxdev;
+       ljca_gpio->gc.direction_input = ljca_gpio_direction_input;
+       ljca_gpio->gc.direction_output = ljca_gpio_direction_output;

Can you implement .get_direction()?

It's scanned on probe to determine the initial state of each line so it is very nice to have.

Yours,
Linus Walleij

author
#16 lore raw

PATCH v7 5/6 i2c: Add support for Intel LJCA USB I2C driver

In reply to Ye Xiang

This patch 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 | 355 ++++++++++++++++++++++++++++++++++
 3 files changed, 367 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ljca.c
drivers/i2c/busses/Kconfig +11 -0
index 25eb4e8fd22f..37fed62797a9 100644
@@ -1261,6 +1261,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 af56fe2c75c0..4af5b06ef288 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 +355 -0

355 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#17 lore raw

PATCH v7 6/6 spi: Add support for Intel LJCA USB SPI driver

In reply to Ye Xiang

This patch 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 | 289 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 301 insertions(+)
 create mode 100644 drivers/spi/spi-ljca.c
drivers/spi/Kconfig +11 -0
index 47bbba04fe3a..c3de4e20531f 100644
@@ -404,6 +404,17 @@ config SPI_HISI_SFC_V3XX
 	  This enables support for HiSilicon v3xx SPI NOR flash controller
 	  found in hi16xx chipsets.
 
+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_NXP_FLEXSPI
 	tristate "NXP Flex SPI controller"
 	depends on ARCH_LAYERSCAPE || HAS_IOMEM
drivers/spi/Makefile +1 -0
index d87cf75bee6a..0d0cc1b0fb9b 100644
@@ -69,6 +69,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 +289 -0

289 lines not on this page · raw message

Signature · 1 line
2.34.1