Skip to contentSkip to conversation

Add Intel LJCA device driver

PATCH Superseded Ye Xiang 8 participants 19 messages Mar 12, 2023 – Jun 30, 2023

Subsystems (5)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Ye Xiang

author
#0 lore raw

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

---
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 (5):
usb: Add support for Intel 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
Documentation: Add ABI doc for attributes of LJCA device

 .../ABI/testing/sysfs-bus-usb-devices-ljca    |  36 +
 drivers/gpio/Kconfig                          |  12 +
 drivers/gpio/Makefile                         |   1 +
 drivers/gpio/gpio-ljca.c                      | 459 ++++++++
 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                        | 293 +++++
 drivers/usb/misc/Kconfig                      |  13 +
 drivers/usb/misc/Makefile                     |   1 +
 drivers/usb/misc/ljca.c                       | 998 ++++++++++++++++++
 include/linux/usb/ljca.h                      |  95 ++
 14 files changed, 2287 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/ljca.c
 create mode 100644 include/linux/usb/ljca.h
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v5 1/5 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. The sub-module of LJCA can use ljca_transfer() to issue a transfer between host and hardware.

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/ljca.c   | 998 ++++++++++++++++++++++++++++++++++++++
 include/linux/usb/ljca.h  |  95 ++++
 4 files changed, 1107 insertions(+)
 create mode 100644 drivers/usb/misc/ljca.c
 create mode 100644 include/linux/usb/ljca.h
drivers/usb/misc/Kconfig +13 -0
index a5f7652db7da..59ec120c26d4 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 MFD_CORE
+	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 ljca.
+
 config USB_CHAOSKEY
 	tristate "ChaosKey random number generator driver support"
 	depends on HW_RANDOM
drivers/usb/misc/Makefile +1 -0
index 93581baec3a8..6f6adfbe17e0 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)			+= ljca.o
 
 obj-$(CONFIG_USB_SISUSBVGA)		+= sisusbvga/
 obj-$(CONFIG_USB_LINK_LAYER_TEST)	+= lvstest.o
drivers/usb/misc/ljca.c new file +998 -0

998 lines not on this page · raw message

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

95 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

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. The sub-module of LJCA can use ljca_transfer() to issue a transfer between host and hardware.

So you have 2 different things happening in this driver. One is the USB interaction and control and stuff, and one is the creation of an api that is to be used by other parts of the kernel.

Can you split this up into 2 different commits, one for the api, and one for the USB stuff? I think you will find that the API is going to need a bunch of work, as it's not "normal" for what the kernel is expecting to have.

Some other review comments below:

drivers/usb/misc/ljca.c line 155

Quoted 3 lines
drivers/usb/misc/ljca.c new file +3 -0
+struct ljca_event_cb_entry {
+	ljca_event_cb_t notify;
+	void *context;

Why a void *?

drivers/usb/misc/ljca.c line 160

Quoted 5 lines
drivers/usb/misc/ljca.c new file +5 -0
+};
+
+struct ljca_dev {
+	struct usb_device *udev;
+	struct usb_interface *intf;

If you have the interface, you can get the usb device. Why store both?

drivers/usb/misc/ljca.c line 169

Quoted 9 lines
drivers/usb/misc/ljca.c new file +9 -0
+	u8 in_ep; /* the address of the bulk in endpoint */
+	u8 out_ep; /* the address of the bulk out endpoint */
+
+	/* the urb/buffer for read */
+	struct urb *in_urb;
+	unsigned char *ibuf;
+	size_t ibuf_len;
+
+	bool started;

You can't just use a boolean as a "flag" without any locking, that is not going to work, sorry.

drivers/usb/misc/ljca.c line 178

Quoted 9 lines
drivers/usb/misc/ljca.c new file +9 -0
+	struct list_head stubs_list;
+
+	/* to wait for an ongoing write ack */
+	wait_queue_head_t ack_wq;
+
+	struct mfd_cell *cells;
+	int cell_count;
+	/* mutex to protect package transfer with LJCA device */
+	struct mutex mutex;

Why is this not protecting "started" as well as the other fields in this structure?

Quoted 18 lines
drivers/usb/misc/ljca.c new file +18 -0
+};
+
+struct ljca {
+	u8 type;
+	struct ljca_dev *dev;
+};
+
+struct ljca_stub_packet {
+	unsigned int *ibuf_len;
+	u8 *ibuf;
+};
+
+struct ljca_stub {
+	struct list_head list;
+	struct usb_interface *intf;
+	struct ljca_stub_packet ipacket;
+	u8 type;
+

drivers/usb/misc/ljca.c line 206

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
+	/* for identify ack */
+	bool acked;
+	int cur_cmd;
+
+	struct ljca_event_cb_entry event_entry;
+	/* lock to protect event_entry */
+	spinlock_t event_cb_lock;
+
+	struct ljca ljca;
+	unsigned long priv[];

What is "priv" for? Why is it unsigned long and not a real type?

drivers/usb/misc/ljca.c line 211

Quoted 5 lines
drivers/usb/misc/ljca.c new file +5 -0
+};
+
+static inline void *ljca_priv(struct ljca_stub *stub)
+{
+	return stub->priv;

Why is this a void *?

Quoted 8 lines
drivers/usb/misc/ljca.c new file +8 -0
+}
+
+static bool ljca_validate(struct ljca_msg *header, u32 data_len)
+{
+	return header->len + sizeof(*header) == data_len;
+}
+
+static struct ljca_stub *ljca_stub_alloc(struct ljca_dev *dev, u8 type, int priv_size)

drivers/usb/misc/ljca.c line 229

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
+{
+	struct ljca_stub *stub;
+
+	stub = kzalloc(struct_size(stub, priv, priv_size), GFP_KERNEL);
+	if (!stub)
+		return ERR_PTR(-ENOMEM);
+
+	stub->type = type;
+	stub->intf = dev->intf;
+	stub->ljca.dev = dev;

You are saving a reference to a reference counted device, yet never grabbing the reference? That is ripe for disaster.

drivers/usb/misc/ljca.c line 232

Quoted 3 lines
drivers/usb/misc/ljca.c new file +3 -0
+	stub->ljca.type = stub->type;
+	spin_lock_init(&stub->event_cb_lock);
+	list_add_tail(&stub->list, &dev->stubs_list);

Where is the reference counting on this new structure that you just created? Who controls the lifespan of it?

Quoted 52 lines
drivers/usb/misc/ljca.c new file +52 -0
+	return stub;
+}
+
+static struct ljca_stub *ljca_stub_find(struct ljca_dev *dev, u8 type)
+{
+	struct ljca_stub *stub;
+
+	list_for_each_entry(stub, &dev->stubs_list, list) {
+		if (stub->type == type)
+			return stub;
+	}
+
+	dev_err(&dev->intf->dev, "USB stub not found, type:%d\n", type);
+
+	return ERR_PTR(-ENODEV);
+}
+
+static void ljca_stub_notify(struct ljca_stub *stub, u8 cmd, const void *evt_data, int len)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&stub->event_cb_lock, flags);
+	if (stub->event_entry.notify && stub->event_entry.context)
+		stub->event_entry.notify(stub->event_entry.context, cmd, evt_data, len);
+	spin_unlock_irqrestore(&stub->event_cb_lock, flags);
+}
+
+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);
+		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) {
+		unsigned int newlen;
+
+		newlen = min_t(unsigned int, header->len, *stub->ipacket.ibuf_len);
+
+		*stub->ipacket.ibuf_len = newlen;

drivers/usb/misc/ljca.c line 294

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
+		memcpy(stub->ipacket.ibuf, header->data, newlen);
+	}
+
+	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,

Why is obuf a void *? It's a real structure (or u8 stream), make it so.

drivers/usb/misc/ljca.c line 295

Quoted 1 line
drivers/usb/misc/ljca.c new file +1 -0
+			   void *ibuf, unsigned int *ibuf_len, bool wait_ack, unsigned long timeout)

Same for ibuf.

Quoted 94 lines
drivers/usb/misc/ljca.c new file +94 -0
+{
+	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(dev->udev, usb_sndbulkpipe(dev->udev, 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) {
+			dev_err(&dev->intf->dev, "acked wait timeout\n");
+			ret = -ETIMEDOUT;
+			goto error_unlock;
+		}
+	}
+
+	stub->ipacket.ibuf = NULL;
+	stub->ipacket.ibuf_len = NULL;
+	ret = 0;
+error_unlock:
+	mutex_unlock(&dev->mutex);
+error_put:
+	usb_autopm_put_interface(dev->intf);
+
+	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);

drivers/usb/misc/ljca.c line 399

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
+}
+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)

What are these magic events you are registering? What do they do and why would anyone need them?

You have global functions here that other drivers are using, yet no documentation about them at all for any way to review that the api really is doing what you are wanting it to do.

So again, please split this up into at least 2 changes, and document this new api you are creating, so that we have a chance to review it properly. Otherwise it's almost impossible to do so.

thanks,

greg k-h

author
#3 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

Hi Greq,

Thanks for the review.

Quoted 9 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. The sub-module of LJCA can use ljca_transfer() to issue a transfer between host and hardware.

Quoted 8 lines

So you have 2 different things happening in this driver. One is the USB interaction and control and stuff, and one is the creation of an api that is to be used by other parts of the kernel.

Can you split this up into 2 different commits, one for the api, and one for the USB stuff? I think you will find that the API is going to need a bunch of work, as it's not "normal" for what the kernel is expecting to have.

Thanks. I will split this into to commits on v6.

Quoted 8 lines

Some other review comments below:

drivers/usb/misc/ljca.c line 155

Quoted 3 lines
drivers/usb/misc/ljca.c new file +3 -0
+struct ljca_event_cb_entry {
+	ljca_event_cb_t notify;
+	void *context;

Why a void *?

We use void * here because we don't know the data type of context on this driver.
The context here is the first parameter of notify callback. And the notify callback is registered by sub-modules. So it represents the execution context of whom registered this callback and the type of it is determined by who registered the callback.

Quoted 8 lines

drivers/usb/misc/ljca.c line 160

Quoted 6 lines
drivers/usb/misc/ljca.c new file +5 -0
+};
+
+struct ljca_dev {
+	struct usb_device *udev;
+	struct usb_interface *intf;

If you have the interface, you can get the usb device. Why store both?

okay, I can just store intf here. When udev are needed when submitting a urb, interface_to_usbdev can be used to get the udev.

Quoted 13 lines

drivers/usb/misc/ljca.c line 169

Quoted 10 lines
drivers/usb/misc/ljca.c new file +9 -0
+	u8 in_ep; /* the address of the bulk in endpoint */
+	u8 out_ep; /* the address of the bulk out endpoint */
+
+	/* the urb/buffer for read */
+	struct urb *in_urb;
+	unsigned char *ibuf;
+	size_t ibuf_len;
+
+	bool started;

You can't just use a boolean as a "flag" without any locking, that is not going to work, sorry.

ok, I will use a mutex to protect it.

Quoted 13 lines

drivers/usb/misc/ljca.c line 178

Quoted 10 lines
drivers/usb/misc/ljca.c new file +9 -0
+	struct list_head stubs_list;
+
+	/* to wait for an ongoing write ack */
+	wait_queue_head_t ack_wq;
+
+	struct mfd_cell *cells;
+	int cell_count;
+	/* mutex to protect package transfer with LJCA device */
+	struct mutex mutex;

Why is this not protecting "started" as well as the other fields in this structure?

Ok, will use it to protect "started", and other fields if needed.

Quoted 23 lines
Quoted 23 lines
drivers/usb/misc/ljca.c new file +22 -0
+};
+
+struct ljca {
+	u8 type;
+	struct ljca_dev *dev;
+};
+
+struct ljca_stub_packet {
+	unsigned int *ibuf_len;
+	u8 *ibuf;
+};
+
+struct ljca_stub {
+	struct list_head list;
+	struct usb_interface *intf;
+	struct ljca_stub_packet ipacket;
+	u8 type;
+
+	/* for identify ack */
+	bool acked;
+	int cur_cmd;
+
Quoted 8 lines

drivers/usb/misc/ljca.c line 206

Quoted 6 lines
drivers/usb/misc/ljca.c new file +6 -0
+	struct ljca_event_cb_entry event_entry;
+	/* lock to protect event_entry */
+	spinlock_t event_cb_lock;
+
+	struct ljca ljca;
+	unsigned long priv[];

What is "priv" for? Why is it unsigned long and not a real type?

The priv type is different for each stub. So it can be several types and we use unsigned long type instead.

Quoted 8 lines

drivers/usb/misc/ljca.c line 211

Quoted 6 lines
drivers/usb/misc/ljca.c new file +5 -0
+};
+
+static inline void *ljca_priv(struct ljca_stub *stub)
+{
+	return stub->priv;

Why is this a void *?

return void here can save one type casting when using priv = ljca_priv(stub);

Quoted 15 lines
Quoted 15 lines
drivers/usb/misc/ljca.c new file +13 -0
+}
+
+static bool ljca_validate(struct ljca_msg *header, u32 data_len)
+{
+	return header->len + sizeof(*header) == data_len;
+}
+
+static struct ljca_stub *ljca_stub_alloc(struct ljca_dev *dev, u8 type, int priv_size)
+{
+	struct ljca_stub *stub;
+
+	stub = kzalloc(struct_size(stub, priv, priv_size), GFP_KERNEL);
+	if (!stub)
Quoted 8 lines

drivers/usb/misc/ljca.c line 229

Quoted 5 lines
drivers/usb/misc/ljca.c new file +5 -0
+		return ERR_PTR(-ENOMEM);
+
+	stub->type = type;
+	stub->intf = dev->intf;
+	stub->ljca.dev = dev;

You are saving a reference to a reference counted device, yet never grabbing the reference? That is ripe for disaster.

ok, will use usb_get_intf to increment reference count.

Quoted 7 lines

drivers/usb/misc/ljca.c line 232

Quoted 4 lines
drivers/usb/misc/ljca.c new file +3 -0
+	stub->ljca.type = stub->type;
+	spin_lock_init(&stub->event_cb_lock);
+	list_add_tail(&stub->list, &dev->stubs_list);

Where is the reference counting on this new structure that you just created? Who controls the lifespan of it?

We didn't use reference counting for this struct ljca_stub structure. The stubs will be destroyed in ljca_stub_cleanup. So The life span of stubs is from create to ljca_disconnect->ljca_stub_cleanup.

Quoted 57 lines
Quoted 57 lines
drivers/usb/misc/ljca.c new file +56 -0
+	return stub;
+}
+
+static struct ljca_stub *ljca_stub_find(struct ljca_dev *dev, u8 type)
+{
+	struct ljca_stub *stub;
+
+	list_for_each_entry(stub, &dev->stubs_list, list) {
+		if (stub->type == type)
+			return stub;
+	}
+
+	dev_err(&dev->intf->dev, "USB stub not found, type:%d\n", type);
+
+	return ERR_PTR(-ENODEV);
+}
+
+static void ljca_stub_notify(struct ljca_stub *stub, u8 cmd, const void *evt_data, int len)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&stub->event_cb_lock, flags);
+	if (stub->event_entry.notify && stub->event_entry.context)
+		stub->event_entry.notify(stub->event_entry.context, cmd, evt_data, len);
+	spin_unlock_irqrestore(&stub->event_cb_lock, flags);
+}
+
+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);
+		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) {
+		unsigned int newlen;
+
+		newlen = min_t(unsigned int, header->len, *stub->ipacket.ibuf_len);
+
+		*stub->ipacket.ibuf_len = newlen;
+		memcpy(stub->ipacket.ibuf, header->data, newlen);
+	}
+
+	stub->acked = true;
Quoted 8 lines

drivers/usb/misc/ljca.c line 294

Quoted 6 lines
drivers/usb/misc/ljca.c new file +6 -0
+	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,

Why is obuf a void *? It's a real structure (or u8 stream), make it so.

obuf and ibuf here is the transfer payload of LJCA. It has several types for different packages (such as gpio package, i2c package andspi package). If change the type to u8, we need to add a type casting from real package type to u8 everywhere when calling ljca_transfer.

Quoted 104 lines

drivers/usb/misc/ljca.c line 295

Quoted 2 lines
drivers/usb/misc/ljca.c new file +1 -0
+			   void *ibuf, unsigned int *ibuf_len, bool wait_ack, unsigned long timeout)

Same for ibuf.

Quoted 99 lines
drivers/usb/misc/ljca.c new file +99 -0
+{
+	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(dev->udev, usb_sndbulkpipe(dev->udev, 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) {
+			dev_err(&dev->intf->dev, "acked wait timeout\n");
+			ret = -ETIMEDOUT;
+			goto error_unlock;
+		}
+	}
+
+	stub->ipacket.ibuf = NULL;
+	stub->ipacket.ibuf_len = NULL;
+	ret = 0;
+error_unlock:
+	mutex_unlock(&dev->mutex);
+error_put:
+	usb_autopm_put_interface(dev->intf);
+
+	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)
+{
Quoted 8 lines

drivers/usb/misc/ljca.c line 399

Quoted 5 lines
drivers/usb/misc/ljca.c new file +5 -0
+	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)

What are these magic events you are registering? What do they do and why would anyone need them?

It provides a path for sub-devices to listening events from LJCA device. For gpio-ljca, it uses this API to implement gpio interrupt.

Quoted 4 lines

You have global functions here that other drivers are using, yet no documentation about them at all for any way to review that the api really is doing what you are wanting it to do.

Kernel-doc format comments are in ljca.h in this patch. It has some introduction about these for exported API.

Quoted 4 lines

So again, please split this up into at least 2 changes, and document this new api you are creating, so that we have a chance to review it properly. Otherwise it's almost impossible to do so.

Got it. Will spit this into 2 commit on next version.

Quoted 1 line

--
Thanks
Ye Xiang

maintainer
#4 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

In reply to Ye Xiang

Hi Ye,

On top of what Greg has already said, few things from my side through the lines.

[...]

drivers/usb/misc/ljca.c line 745

Quoted 12 lines
drivers/usb/misc/ljca.c new file +12 -0
+static int ljca_mng_link(struct ljca_dev *dev, struct ljca_stub *stub)
+{
+	int ret;
+
+	ret = ljca_mng_reset_handshake(stub);
+	if (ret)
+		return ret;
+
+	/* try to enum all the stubs */
+	ljca_mng_enum_gpio(stub);
+	ljca_mng_enum_i2c(stub);
+	ljca_mng_enum_spi(stub);

We are ignoring here the return value. So either make the whole function call chain to be void or please check the return values here.

[...]

Quoted 8 lines
drivers/usb/misc/ljca.c new file +8 -0
+static ssize_t ljca_enable_dfu_store(struct device *dev, struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct usb_interface *intf = to_usb_interface(dev);
+	struct ljca_dev *ljca_dev = usb_get_intfdata(intf);
+	struct ljca_stub *mng_stub = ljca_stub_find(ljca_dev, LJCA_MNG_STUB);
+	bool enable;
+	int ret;

drivers/usb/misc/ljca.c line 831

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
+
+	ret = kstrtobool(buf, &enable);
+	if (ret)
+		return ret;
+
+	if (enable) {
+		ret = ljca_mng_set_dfu_mode(mng_stub);
+		if (ret)
+			return ret;
+	}

What is the DFU mode?
Is it an operational mode?
Do we enter and exit from it?
Does the device leave this mode on its own?
What if I write twice in a raw enable?
Can I check if I am in DFU mode or not?

Would you mind adding some comments here?

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
+
+	return count;
+}
+static DEVICE_ATTR_WO(ljca_enable_dfu);
+
+static ssize_t ljca_trace_level_store(struct device *dev, struct device_attribute *attr,
+				      const char *buf, size_t count)
+{
+	struct usb_interface *intf = to_usb_interface(dev);
+	struct ljca_dev *ljca_dev = usb_get_intfdata(intf);

drivers/usb/misc/ljca.c line 851

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
+	struct ljca_stub *diag_stub = ljca_stub_find(ljca_dev, LJCA_DIAG_STUB);
+	u8 level;
+	int ret;
+
+	if (kstrtou8(buf, 0, &level))
+		return -EINVAL;
+
+	ret = ljca_diag_set_trace_level(diag_stub, level);
+	if (ret)
+		return ret;

do we need any range check for the levels? What happens if I do:

echo "I am too cool" > /sys/.../ljca_trace_level

As there were questions here, would you mind adding some comments so that the next reader won't make the same questions?

Quoted 4 lines
drivers/usb/misc/ljca.c new file +4 -0
+
+	return count;
+}
+static DEVICE_ATTR_WO(ljca_trace_level);

[...]

drivers/usb/misc/ljca.c line 882

Quoted 8 lines
drivers/usb/misc/ljca.c new file +8 -0
+static int ljca_probe(struct usb_interface *intf, const struct usb_device_id *id)
+{
+	struct ljca_dev *dev;
+	struct usb_endpoint_descriptor *bulk_in, *bulk_out;
+	int ret;
+
+	/* allocate memory for our device state and initialize it */
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);

devm_kzalloc()

Thanks,
Andi

Quoted 2 lines
drivers/usb/misc/ljca.c new file +2 -0
+	if (!dev)
+		return -ENOMEM;
author
#5 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

Hi Andi,

Thanks for the review.

Quoted 7 lines · Andi Shyti

Hi Ye,

On top of what Greg has already said, few things from my side through the lines.

[...]

Quoted 16 lines

drivers/usb/misc/ljca.c line 745

Quoted 12 lines
drivers/usb/misc/ljca.c new file +12 -0
+static int ljca_mng_link(struct ljca_dev *dev, struct ljca_stub *stub)
+{
+	int ret;
+
+	ret = ljca_mng_reset_handshake(stub);
+	if (ret)
+		return ret;
+
+	/* try to enum all the stubs */
+	ljca_mng_enum_gpio(stub);
+	ljca_mng_enum_i2c(stub);
+	ljca_mng_enum_spi(stub);

We are ignoring here the return value. So either make the whole function call chain to be void or please check the return values here.

Ok, got it.

Quoted 29 lines

[...]

Quoted 8 lines
drivers/usb/misc/ljca.c new file +8 -0
+static ssize_t ljca_enable_dfu_store(struct device *dev, struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct usb_interface *intf = to_usb_interface(dev);
+	struct ljca_dev *ljca_dev = usb_get_intfdata(intf);
+	struct ljca_stub *mng_stub = ljca_stub_find(ljca_dev, LJCA_MNG_STUB);
+	bool enable;
+	int ret;

drivers/usb/misc/ljca.c line 831

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
+
+	ret = kstrtobool(buf, &enable);
+	if (ret)
+		return ret;
+
+	if (enable) {
+		ret = ljca_mng_set_dfu_mode(mng_stub);
+		if (ret)
+			return ret;
+	}

What is the DFU mode?
Is it an operational mode?
Do we enter and exit from it?
Does the device leave this mode on its own?
What if I write twice in a raw enable?
Can I check if I am in DFU mode or not?

Quoted 1 line

Would you mind adding some comments here?

DFU mode is used for updating LJCA device Firmware.
We have a Documentation/ABI/testing/sysfs-bus-usb-devices-ljca in patch 5 of this patch series. It has information about the entry. Maybe it should be go after this patch (patch 2/5).

Quoted 24 lines
Quoted 11 lines
drivers/usb/misc/ljca.c new file +10 -0
+
+	return count;
+}
+static DEVICE_ATTR_WO(ljca_enable_dfu);
+
+static ssize_t ljca_trace_level_store(struct device *dev, struct device_attribute *attr,
+				      const char *buf, size_t count)
+{
+	struct usb_interface *intf = to_usb_interface(dev);
+	struct ljca_dev *ljca_dev = usb_get_intfdata(intf);

drivers/usb/misc/ljca.c line 851

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
+	struct ljca_stub *diag_stub = ljca_stub_find(ljca_dev, LJCA_DIAG_STUB);
+	u8 level;
+	int ret;
+
+	if (kstrtou8(buf, 0, &level))
+		return -EINVAL;
+
+	ret = ljca_diag_set_trace_level(diag_stub, level);
+	if (ret)
+		return ret;

do we need any range check for the levels? What happens if I do:

Quoted 4 lines

echo "I am too cool" > /sys/.../ljca_trace_level

As there were questions here, would you mind adding some comments so that the next reader won't make the same questions?

We have a patch (patch 5 of this series) adding some Documentation/ABI/ entries to specify the correct value for each entry.

Quoted 8 lines
Quoted 5 lines
drivers/usb/misc/ljca.c new file +4 -0
+
+	return count;
+}
+static DEVICE_ATTR_WO(ljca_trace_level);

[...]

Quoted 10 lines

drivers/usb/misc/ljca.c line 882

Quoted 8 lines
drivers/usb/misc/ljca.c new file +8 -0
+static int ljca_probe(struct usb_interface *intf, const struct usb_device_id *id)
+{
+	struct ljca_dev *dev;
+	struct usb_endpoint_descriptor *bulk_in, *bulk_out;
+	int ret;
+
+	/* allocate memory for our device state and initialize it */
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);

devm_kzalloc()

Got it. Thanks.

--
Thanks
Ye Xiang

#6 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

In reply to Ye Xiang
Quoted 86 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. The sub-module of LJCA can use ljca_transfer() to issue a transfer between host and hardware.

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/ljca.c   | 998 ++++++++++++++++++++++++++++++++++++++
 include/linux/usb/ljca.h  |  95 ++++
 4 files changed, 1107 insertions(+)
 create mode 100644 drivers/usb/misc/ljca.c
 create mode 100644 include/linux/usb/ljca.h
drivers/usb/misc/Kconfig +13 -0
index a5f7652db7da..59ec120c26d4 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 MFD_CORE
+	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 ljca.
+
 config USB_CHAOSKEY
 	tristate "ChaosKey random number generator driver support"
 	depends on HW_RANDOM
drivers/usb/misc/Makefile +1 -0
index 93581baec3a8..6f6adfbe17e0 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)			+= ljca.o
 
 obj-$(CONFIG_USB_SISUSBVGA)		+= sisusbvga/
 obj-$(CONFIG_USB_LINK_LAYER_TEST)	+= lvstest.o
drivers/usb/misc/ljca.c new file +0 -0
new file mode 100644
index 000000000000..ab98deaf0074

drivers/usb/misc/ljca.c line 10

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
@@ -0,0 +1,998 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Intel La Jolla Cove Adapter USB driver
+ *
+ * Copyright (c) 2023, Intel Corporation.
+ */
+
+#include <linux/dev_printk.h>
+#include <linux/kernel.h>
+#include <linux/mfd/core.h>

Please don't use the MFD API outside of drivers/mfd.

If you wish to use the API, please do.

Strip out (only) the MFD parts and move them into drivers/mfd.

drivers/usb/misc/ljca.c line 18

Quoted 8 lines
drivers/usb/misc/ljca.c new file +8 -0
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <linux/usb.h>
+#include <linux/usb/ljca.h>

--
Lee Jones [李琼斯]

author
#7 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

Hi Lee,

Thanks for the review.

Quoted 101 lines · Lee Jones
Quoted 86 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. The sub-module of LJCA can use ljca_transfer() to issue a transfer between host and hardware.

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/ljca.c   | 998 ++++++++++++++++++++++++++++++++++++++
 include/linux/usb/ljca.h  |  95 ++++
 4 files changed, 1107 insertions(+)
 create mode 100644 drivers/usb/misc/ljca.c
 create mode 100644 include/linux/usb/ljca.h
drivers/usb/misc/Kconfig +13 -0
index a5f7652db7da..59ec120c26d4 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 MFD_CORE
+	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 ljca.
+
 config USB_CHAOSKEY
 	tristate "ChaosKey random number generator driver support"
 	depends on HW_RANDOM
drivers/usb/misc/Makefile +1 -0
index 93581baec3a8..6f6adfbe17e0 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)			+= ljca.o
 
 obj-$(CONFIG_USB_SISUSBVGA)		+= sisusbvga/
 obj-$(CONFIG_USB_LINK_LAYER_TEST)	+= lvstest.o
drivers/usb/misc/ljca.c new file +0 -0
new file mode 100644
index 000000000000..ab98deaf0074

drivers/usb/misc/ljca.c line 10

Quoted 10 lines
drivers/usb/misc/ljca.c new file +10 -0
@@ -0,0 +1,998 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Intel La Jolla Cove Adapter USB driver
+ *
+ * Copyright (c) 2023, Intel Corporation.
+ */
+
+#include <linux/dev_printk.h>
+#include <linux/kernel.h>
+#include <linux/mfd/core.h>

Please don't use the MFD API outside of drivers/mfd.

Quoted 3 lines

If you wish to use the API, please do.

Strip out (only) the MFD parts and move them into drivers/mfd.

I have no idea about how to split MFD parts out from this driver currently. The MFD part just have mfd cells filling and the call mfd_add_hotplug_devices to register mfd devices. How to module them as an independent driver?
Would you give some hints or recommendations?

And I am a little comfused about where this USB device driver should be put to (drivers/mfd or drivers/usb).

As far as I know, where a driver should be put is based on what it provides. This driver just do some urb package transfer to provides multi-functions, such as GPIO function, I2C function, SPI function. so it should be under drivers/mfd folder. Please correct me, if something is wrong. Thanks

Quoted 10 lines

drivers/usb/misc/ljca.c line 18

Quoted 9 lines
drivers/usb/misc/ljca.c new file +8 -0
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <linux/usb.h>
+#include <linux/usb/ljca.h>

--
Thanks
Ye Xiang

#8 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

Hi Xiang,

Quoted 11 lines · Xiang
Quoted 5 lines

Please don't use the MFD API outside of drivers/mfd.

If you wish to use the API, please do.

Strip out (only) the MFD parts and move them into drivers/mfd.

I have no idea about how to split MFD parts out from this driver currently. The MFD part just have mfd cells filling and the call mfd_add_hotplug_devices to register mfd devices. How to module them as an independent driver?
Would you give some hints or recommendations?

Quoted 8 lines

And I am a little comfused about where this USB device driver should be put to (drivers/mfd or drivers/usb).

As far as I know, where a driver should be put is based on what it provides. This driver just do some urb package transfer to provides multi-functions, such as GPIO function, I2C function, SPI function. so it should be under drivers/mfd folder. Please correct me, if something is wrong. Thanks

You don't really seem to get any benefit from MFD. Perhaps it would be more appropriate and clear if you just registered auxiliary devices in this driver. Check drivers/base/auxiliary.c.

thanks,

Signature · 1 line
heikki
author
#9 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

Hi Heikki,

Thanks for the review.

Quoted 23 lines · Heikki Krogerus

Hi Xiang,

Quoted 11 lines · Xiang
Quoted 5 lines

Please don't use the MFD API outside of drivers/mfd.

If you wish to use the API, please do.

Strip out (only) the MFD parts and move them into drivers/mfd.

I have no idea about how to split MFD parts out from this driver currently. The MFD part just have mfd cells filling and the call mfd_add_hotplug_devices to register mfd devices. How to module them as an independent driver?
Would you give some hints or recommendations?

Quoted 8 lines

And I am a little comfused about where this USB device driver should be put to (drivers/mfd or drivers/usb).

As far as I know, where a driver should be put is based on what it provides. This driver just do some urb package transfer to provides multi-functions, such as GPIO function, I2C function, SPI function. so it should be under drivers/mfd folder. Please correct me, if something is wrong. Thanks

Quoted 3 lines

You don't really seem to get any benefit from MFD. Perhaps it would be more appropriate and clear if you just registered auxiliary devices in this driver. Check drivers/base/auxiliary.c.

Yes, it should be a work. I have a question.
MFD provides the ACPI binding for sub-devices through
struct mfd_cell_acpi_match. But I didn't see this in drivers/base/auxiliary.c. If using auxiliary bus to implement the LJCA sub-devices, we need to do the sub-devices acpi binding manually in ljca.c.

Something Like:
adr = LJCA_ACPI_MATCH_GPIO
adev = acpi_find_child_device(parent, adr, false); ACPI_COMPANION_SET(&pdev->dev, adev ?: parent);

Is that acceptable?

--
Thanks
Ye Xiang

#10 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

Quoted 2 lines · Xiang
Quoted 1 line · Heikki Krogerus

On Tue, Mar 14, 2023 at 04:03:26PM +0800, Ye, Xiang wrote:

...

Quoted 9 lines
Quoted 3 lines

You don't really seem to get any benefit from MFD. Perhaps it would be more appropriate and clear if you just registered auxiliary devices in this driver. Check drivers/base/auxiliary.c.

Yes, it should be a work. I have a question.
MFD provides the ACPI binding for sub-devices through
struct mfd_cell_acpi_match. But I didn't see this in drivers/base/auxiliary.c. If using auxiliary bus to implement the LJCA sub-devices, we need to do the sub-devices acpi binding manually in ljca.c.

Quoted 6 lines

Something Like:
adr = LJCA_ACPI_MATCH_GPIO
adev = acpi_find_child_device(parent, adr, false); ACPI_COMPANION_SET(&pdev->dev, adev ?: parent);

Is that acceptable?

Maybe you can implement this on the level of auxiliary bus.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

Quoted 15 lines · Andy Shevchenko
Quoted 2 lines · Xiang
Quoted 1 line · Heikki Krogerus

On Tue, Mar 14, 2023 at 04:03:26PM +0800, Ye, Xiang wrote:

...

Quoted 9 lines
Quoted 3 lines

You don't really seem to get any benefit from MFD. Perhaps it would be more appropriate and clear if you just registered auxiliary devices in this driver. Check drivers/base/auxiliary.c.

Yes, it should be a work. I have a question.
MFD provides the ACPI binding for sub-devices through
struct mfd_cell_acpi_match. But I didn't see this in drivers/base/auxiliary.c. If using auxiliary bus to implement the LJCA sub-devices, we need to do the sub-devices acpi binding manually in ljca.c.

Quoted 6 lines
Quoted 6 lines

Something Like:
adr = LJCA_ACPI_MATCH_GPIO
adev = acpi_find_child_device(parent, adr, false); ACPI_COMPANION_SET(&pdev->dev, adev ?: parent);

Is that acceptable?

Looks ok to me.

Quoted 1 line

Maybe you can implement this on the level of auxiliary bus.

I would actually prefer that the auxiliary bus itself does not make any assumptions regarding the whereabouts of the fwnodes at this stage. Maybe later, when(if) there are more users.

thanks,

Signature · 1 line
heikki
#12 lore raw

RE: [PATCH v5 1/5] usb: Add support for Intel LJCA device

Quoted 27 lines

-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Wednesday, March 15, 2023 5:10 PM

Quoted 21 lines · Andy Shevchenko
Quoted 2 lines · Xiang
Quoted 1 line · Heikki Krogerus

On Tue, Mar 14, 2023 at 04:03:26PM +0800, Ye, Xiang wrote:

...

Quoted 15 lines
Quoted 3 lines

You don't really seem to get any benefit from MFD. Perhaps it would be more appropriate and clear if you just registered auxiliary devices in this driver. Check drivers/base/auxiliary.c.

Yes, it should be a work. I have a question.
MFD provides the ACPI binding for sub-devices through struct mfd_cell_acpi_match. But I didn't see this in drivers/base/auxiliary.c. If using auxiliary bus to implement the LJCA sub-devices, we need to do the sub-devices acpi binding manually in ljca.c.

Something Like:
adr = LJCA_ACPI_MATCH_GPIO
adev = acpi_find_child_device(parent, adr, false); ACPI_COMPANION_SET(&pdev->dev, adev ?: parent);

Is that acceptable?

This actually doesn't work, look at the acpi_find_child_device(), it compares the bus address specified by _ADR object, but there is no _ADR object in DSDT for these three devices because the relationship between the parent and children isn't bus type listed in ACPI spec, so it always return NULL.

BR,
Wentong

Quoted 13 lines

Looks ok to me.

Quoted 1 line

Maybe you can implement this on the level of auxiliary bus.

I would actually prefer that the auxiliary bus itself does not make any assumptions regarding the whereabouts of the fwnodes at this stage. Maybe later, when(if) there are more users.

thanks,

--
heikki

#13 lore raw

Re: [PATCH v5 1/5] usb: Add support for Intel LJCA device

Quoted 6 lines · Wentong
Quoted 6 lines

From: Heikki Krogerus <[email protected]>
Sent: Wednesday, March 15, 2023 5:10 PM

Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Xiang
Quoted 1 line · Heikki Krogerus

On Tue, Mar 14, 2023 at 04:03:26PM +0800, Ye, Xiang wrote:

...

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 3 lines

You don't really seem to get any benefit from MFD. Perhaps it would be more appropriate and clear if you just registered auxiliary devices in this driver. Check drivers/base/auxiliary.c.

Yes, it should be a work. I have a question.
MFD provides the ACPI binding for sub-devices through struct mfd_cell_acpi_match. But I didn't see this in drivers/base/auxiliary.c. If using auxiliary bus to implement the LJCA sub-devices, we need to do the sub-devices acpi binding manually in ljca.c.

Something Like:
adr = LJCA_ACPI_MATCH_GPIO
adev = acpi_find_child_device(parent, adr, false); ACPI_COMPANION_SET(&pdev->dev, adev ?: parent);

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Is that acceptable?

This actually doesn't work, look at the acpi_find_child_device(), it compares the bus address specified by _ADR object, but there is no _ADR object in DSDT for these three devices because the relationship between the parent and children isn't bus type listed in ACPI spec, so it always return NULL.

If you want to have this on ACPI enabled platform, ACPI table has to have the necessary bits. What you are describing is a BIOS bug _or_ somebody has to provide the SSDT overlay depending on the real connection of the device..

Quoted 7 lines
Quoted 7 lines

Looks ok to me.

Quoted 1 line

Maybe you can implement this on the level of auxiliary bus.

I would actually prefer that the auxiliary bus itself does not make any assumptions regarding the whereabouts of the fwnodes at this stage. Maybe later, when(if) there are more users.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#14 lore raw

PATCH v5 2/5 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 | 459 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 472 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 +459 -0

459 lines not on this page · raw message

Signature · 1 line
2.34.1
Acked-by on v5 2/5
#15 lore raw

Re: [PATCH v5 2/5] gpio: Add support for Intel LJCA USB GPIO driver

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

---

author
#16 lore raw

PATCH v5 3/5 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 v5 4/5 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 | 293 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 305 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 +293 -0

293 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#18 lore raw

PATCH v5 5/5 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