Add Intel LJCA device driver
Subsystems (5)
v8 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.
---
v8:
- ljca: use READ_ONCE to make the value of ibuf consistent.
- gpio: inplement get_direction callback.
- gpio: move kconfig item into USB GPIO expanders menu.
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: align 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 | 479 ++++++++ drivers/i2c/busses/Kconfig | 11 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-ljca.c | 350 ++++++ drivers/spi/Kconfig | 11 + drivers/spi/Makefile | 1 + drivers/spi/spi-ljca.c | 290 +++++ drivers/usb/misc/Kconfig | 14 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/usb-ljca.c | 1068 +++++++++++++++++ include/linux/usb/ljca.h | 102 ++ 14 files changed, 2377 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
PATCH v8 1/6 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 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 | 977 ++++++++++++++++++++++++++++++++++++ include/linux/usb/ljca.h | 50 ++ 4 files changed, 1042 insertions(+) create mode 100644 drivers/usb/misc/usb-ljca.c create mode 100644 include/linux/usb/ljca.h
drivers/usb/misc/Kconfig +14 -0
@@ -273,6 +273,20 @@ 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 + 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. + config USB_CHAOSKEY tristate "ChaosKey random number generator driver support" depends on HW_RANDOM
drivers/usb/misc/Makefile +1 -0
@@ -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 +977 -0
977 lines not on this page · raw message
include/linux/usb/ljca.h new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v8 1/6] usb: Add support for Intel LJCA device
Quoted 10 lines · Ye Xiang
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.
Hi,
I am terribly sorry to come up with issues after so many iterations, but I am really afraid there are issues left.
Quoted 41 lines
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) } }Signed-off-by Ye Xiang <[email protected]>---
drivers/usb/misc/usb-ljca.c new file +16
-0+ +/* MNG stub commands */ +enum ljca_mng_cmd { +LJCA_MNG_GET_VERSION =1 , +LJCA_MNG_RESET_NOTIFY , +LJCA_MNG_RESET , +LJCA_MNG_ENUM_GPIO , +LJCA_MNG_ENUM_I2C , +LJCA_MNG_POWER_STATE_CHANGE , +LJCA_MNG_SET_DFU_MODE , +LJCA_MNG_ENUM_SPI , +}; + +/* DIAG commands */ +enum ljca_diag_cmd { +LJCA_DIAG_GET_STATE =1 ,
drivers/usb/misc/usb-ljca.c line 89
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+LJCA_DIAG_GET_STATISTIC , +LJCA_DIAG_SET_TRACE_LEVEL , +LJCA_DIAG_SET_ECHO_MODE , +LJCA_DIAG_GET_FW_LOG , +LJCA_DIAG_GET_FW_COREDUMP , +LJCA_DIAG_TRIGGER_WDT , +LJCA_DIAG_TRIGGER_FAULT , +LJCA_DIAG_FEED_WDT , + LJCA_DIAG_GET_SECURE_STATE, +};
Should those really be enum? They just happen
to be nummerically dense.
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +4
-0+static int ljca_parse (struct ljca_dev *dev,struct ljca_msg *header) +{ +struct ljca_stub *stub; +unsigned int *ibuf_len;
drivers/usb/misc/usb-ljca.c line 266
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+u8 *ibuf; + + 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 ; + }
First you ack ...
drivers/usb/misc/usb-ljca.c line 272
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-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 ; + }
... then you check whether this is for the correct command?
drivers/usb/misc/usb-ljca.c line 275
Quoted 3 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+ + ibuf_len =READ_ONCE (stub->ipacket.ibuf_len); + ibuf =READ_ONCE (stub->ipacket.ibuf);
This races against stub_write(). Yes, every value now is consistent within this function. But that does not solve the issue. The pair needs to be consistent. You need to rule out that you are reading a different length and buffer location. I am afraid this needs a spinlock.
Quoted 25 lines
drivers/usb/misc/usb-ljca.c new file +25
-0+ +if (ibuf && ibuf_len) { +unsigned int newlen; + + newlen = min_t(unsigned int, header->len, *ibuf_len); + + *ibuf_len = newlen; +memcpy (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, +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;
drivers/usb/misc/usb-ljca.c line 310
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ +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 ;
Do you really want to first set a flag, then error out?
Quoted 5 lines
drivers/usb/misc/usb-ljca.c new file +5
-0+ header->type = stub->type; + header->cmd = cmd; + header->flags = flags; + header->len = obuf_len; +
drivers/usb/misc/usb-ljca.c line 326
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+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 ;
Again, the flag remains set.
Quoted 44 lines
drivers/usb/misc/usb-ljca.c new file +44
-0+ 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) { +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 ; +mutex_unlock (&dev->mutex); +error_put: +usb_autopm_put_interface (dev->intf); + +return ret; +} +
[..]
Quoted 7 lines
drivers/usb/misc/usb-ljca.c new file +7
-0+static int ljca_start (struct ljca_dev *dev) +{ +int ret; + +usb_fill_bulk_urb (dev->in_urb,interface_to_usbdev (dev->intf), +usb_rcvbulkpipe (interface_to_usbdev (dev->intf), dev->in_ep), dev->ibuf, + dev->ibuf_len, ljca_read_complete, dev);
drivers/usb/misc/usb-ljca.c line 424
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ + ret =usb_submit_urb (dev->in_urb,GFP_KERNEL ); +if (ret) { +dev_err (&dev->intf->dev,"failed submitting read urb, error %d\n" , ret); +return ret; + } + +mutex_lock (&dev->mutex); + dev->started = true; +mutex_unlock (&dev->mutex);
Why do you take a mutex here? Either this function cannot race with anything else, or you set the flag too late.
Quoted 41 lines
drivers/usb/misc/usb-ljca.c new file +40
-0+ +return 0 ; +} + +#ifdef CONFIG_ACPI +static void ljca_aux_dev_acpi_bind (struct ljca_dev *dev,struct auxiliary_device *auxdev, +unsigned int adr) +{ +struct acpi_device *parent; +struct acpi_device *adev =NULL ; + +/* new auxiliary device bind to acpi device */ + parent =ACPI_COMPANION (&dev->intf->dev); +if (!parent) +return ; + + adev =acpi_find_child_device (parent, adr, false); +ACPI_COMPANION_SET (&auxdev->dev, adev ?: parent); +} +#else +static void ljca_aux_dev_acpi_bind (struct ljca_dev *dev,struct auxiliary_device *auxdev, +unsigned int adr) +{ +} +#endif + +static int ljca_add_aux_dev (struct ljca_dev *dev,char *name,u8 type,u8 id,u8 adr,void *data, +unsigned int len) +{ +struct auxiliary_device *auxdev; +struct ljca *ljca; +int ret; + +if (dev->ljca_count >=ARRAY_SIZE (dev->ljcas)) +return -EINVAL ; + + ljca =kzalloc (sizeof (*ljca),GFP_KERNEL ); +if (!ljca) +return -ENOMEM ; +
drivers/usb/misc/usb-ljca.c line 506
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ ljca->type = type; + ljca->id = id; + ljca->dev = dev; + + auxdev = &ljca->auxdev; + auxdev->name = name; + auxdev->id = id; + auxdev->dev.platform_data =kmemdup (data, len,GFP_KERNEL ); +if (!auxdev->dev.platform_data) +return -ENOMEM ;
memory leak of struct ljca *ljca
drivers/usb/misc/usb-ljca.c line 509
Quoted 3 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+ + auxdev->dev.parent = &dev->intf->dev; + auxdev->dev.release = ljca_aux_release;
Regards
Oliver
RE: [PATCH v8 1/6] usb: Add support for Intel LJCA device
Hi Oliver,
Thanks for your review
Quoted 85 lines
-----Original Message-----
From: Oliver Neukum <[email protected]>
Sent: Monday, May 22, 2023 5:22 PMQuoted 10 lines · Ye Xiang
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.
Hi,
I am terribly sorry to come up with issues after so many iterations, but I am really afraid there are issues left.
Quoted 41 lines
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) } }Signed-off-by Ye Xiang <[email protected]>---
drivers/usb/misc/usb-ljca.c new file +16
-0+ +/* MNG stub commands */ +enum ljca_mng_cmd { +LJCA_MNG_GET_VERSION =1 , +LJCA_MNG_RESET_NOTIFY , +LJCA_MNG_RESET , +LJCA_MNG_ENUM_GPIO , +LJCA_MNG_ENUM_I2C , +LJCA_MNG_POWER_STATE_CHANGE , +LJCA_MNG_SET_DFU_MODE , +LJCA_MNG_ENUM_SPI , +}; + +/* DIAG commands */ +enum ljca_diag_cmd { +LJCA_DIAG_GET_STATE =1 ,drivers/usb/misc/usb-ljca.c line 89
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+LJCA_DIAG_GET_STATISTIC , +LJCA_DIAG_SET_TRACE_LEVEL , +LJCA_DIAG_SET_ECHO_MODE , +LJCA_DIAG_GET_FW_LOG , +LJCA_DIAG_GET_FW_COREDUMP , +LJCA_DIAG_TRIGGER_WDT , +LJCA_DIAG_TRIGGER_FAULT , +LJCA_DIAG_FEED_WDT , + LJCA_DIAG_GET_SECURE_STATE, +};Should those really be enum? They just happen to be nummerically dense.
Quoted 9 lines
drivers/usb/misc/usb-ljca.c new file +9
-0+static int ljca_parse (struct ljca_dev *dev,struct ljca_msg *header) +{ +struct ljca_stub *stub; +unsigned int *ibuf_len; +u8 *ibuf; + + stub =ljca_stub_find (dev, header->type); +if (IS_ERR (stub)) +return PTR_ERR (stub);
Quoted 8 lines
Review
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+ +if (!(header->flags &LJCA_ACK_FLAG )) { + ljca_stub_notify(stub, header->cmd, header->data, header-len);
(quoted diff) +2
-0+ return 0; + }First you ack ...
This is checking whether the message is cmd ack or event, if not cmd ack, it will be event.
Quoted 10 lines
drivers/usb/misc/usb-ljca.c
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+ +if (stub->cur_cmd != header->cmd) { + dev_err(&dev->intf->dev, "header and stub current commandmismatch (%x vs %x)\n",
drivers/usb/misc/usb-ljca.c line 272
Quoted 3 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+ header->cmd, stub->cur_cmd); +return -EINVAL ; + }... then you check whether this is for the correct command?
If it's cmd ack, we check if it's correct command.
Quoted 9 lines
drivers/usb/misc/usb-ljca.c line 275
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+ + ibuf_len =READ_ONCE (stub->ipacket.ibuf_len); + ibuf =READ_ONCE (stub->ipacket.ibuf);This races against
stub_write(). Yes, every value now is consistent within this function. But that does not solve the issue. The pair needs to be consistent. You need to rule out that you are reading a different length and buffer location. I am afraid this needs a spinlock.
Sorry, based on my understanding, the stub's ibuf_len and ibuf won't be changed by stub_write until firmware ack the current command.
This memory barrier here is for potential cache consistency issue in some arches though most likely this driver will only be run on X86 platform.
Quoted 21 lines
Quoted 8 lines
drivers/usb/misc/usb-ljca.c new file +7
-0+ +if (ibuf && ibuf_len) { +unsigned int newlen; + + newlen = min_t(unsigned int, header->len, *ibuf_len); + + *ibuf_len = newlen;drivers/usb/misc/usb-ljca.c
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+memcpy (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,Review
Quoted 1 line
(quoted diff) +1
-0+ void *ibuf, unsigned int *ibuf_len, bool wait_ack,unsigned
Quoted 13 lines
drivers/usb/misc/usb-ljca.c line 306
Quoted 13 lines
drivers/usb/misc/usb-ljca.c new file +13
-0+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 ;
Will be removed in next version
Quoted 6 lines
drivers/usb/misc/usb-ljca.c line 310
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +4
-0+ + header =kmalloc (msg_len,GFP_KERNEL ); +if (!header) +return -ENOMEM ;Do you really want to first set a flag, then error out?
Thanks, in next version, it will be like blow:header->flags = wait_ack ? flags | LJCA_ACK_FLAG : flags;
Quoted 11 lines
drivers/usb/misc/usb-ljca.c
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +9
-0+ 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,
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 326
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ header->cmd, header->flags, header->len); + +usb_autopm_get_interface (dev->intf); +if (!dev->started) { +kfree (header); + ret = -ENODEV ;Again, the flag remains set.
The flag is local variable, and the header has been freed as well, I don't think we have to take care the flag here.
Quoted 62 lines
Quoted 12 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ 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,drivers/usb/misc/usb-ljca.c
Quoted 9 lines
drivers/usb/misc/usb-ljca.c new file +9
-0+ 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 (%dvs %d)\n",
msg_len,drivers/usb/misc/usb-ljca.c
Quoted 7 lines
drivers/usb/misc/usb-ljca.c new file +7
-0+ actual); + ret = -EINVAL ; + goto error_unlock; + } + +if (wait_ack) { + ret = wait_event_timeout(dev->ack_wq, stub->acked,
msecs_to_jiffies(timeout));Quoted 18 lines
drivers/usb/misc/usb-ljca.c new file +18
-0+if (!ret) { +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 ; +mutex_unlock (&dev->mutex); +error_put: +usb_autopm_put_interface (dev->intf); + +return ret; +} +[..]
drivers/usb/misc/usb-ljca.c
Quoted 11 lines
drivers/usb/misc/usb-ljca.c new file +5
-0+static int ljca_start (struct ljca_dev *dev) { +int ret; + + usb_fill_bulk_urb(dev->in_urb, interface_to_usbdev(dev->intf), + usb_rcvbulkpipe(interface_to_usbdev(dev->intf), dev-
in_ep),dev->ibuf,drivers/usb/misc/usb-ljca.c new file +5
-0+ dev->ibuf_len, ljca_read_complete, dev); + + ret =usb_submit_urb (dev->in_urb,GFP_KERNEL ); +if (ret) { + dev_err(&dev->intf->dev, "failed submitting read urb,error %d\n", ret);
Quoted 9 lines
drivers/usb/misc/usb-ljca.c line 424
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+return ret; + } + +mutex_lock (&dev->mutex); + dev->started = true; +mutex_unlock (&dev->mutex);Why do you take a mutex here? Either this function cannot race with anything else, or you set the flag too late.
Thanks, I will consider the 'started' again.
Quoted 47 lines
drivers/usb/misc/usb-ljca.c
Quoted 8 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ +return 0 ; +} + +#ifdef CONFIG_ACPI +static void ljca_aux_dev_acpi_bind(struct ljca_dev *dev, struct
auxiliary_device*auxdev,drivers/usb/misc/usb-ljca.c
Quoted 13 lines
drivers/usb/misc/usb-ljca.c new file +13
-0+ unsigned int adr) +{ +struct acpi_device *parent; +struct acpi_device *adev =NULL ; + +/* new auxiliary device bind to acpi device */ + parent =ACPI_COMPANION (&dev->intf->dev); +if (!parent) +return ; + + adev =acpi_find_child_device (parent, adr, false); +ACPI_COMPANION_SET (&auxdev->dev, adev ?: parent); }#else static +void ljca_aux_dev_acpi_bind(struct ljca_dev *dev, struct auxiliary_device*auxdev,
drivers/usb/misc/usb-ljca.c
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ unsigned int adr) +{ +} +#endif + +static int ljca_add_aux_dev(struct ljca_dev *dev, char *name, u8 type, u8 id,u8 adr, void *data,
Quoted 17 lines
drivers/usb/misc/usb-ljca.c new file +17
-0+ unsigned int len) +{ +struct auxiliary_device *auxdev; +struct ljca *ljca; +int ret; + +if (dev->ljca_count >=ARRAY_SIZE (dev->ljcas)) +return -EINVAL ; + + ljca =kzalloc (sizeof (*ljca),GFP_KERNEL ); +if (!ljca) +return -ENOMEM ; + + ljca->type = type; + ljca->id = id; + ljca->dev = dev; +
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 506
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ auxdev = &ljca->auxdev; + auxdev->name = name; + auxdev->id = id; + auxdev->dev.platform_data =kmemdup (data, len,GFP_KERNEL ); +if (!auxdev->dev.platform_data) +return -ENOMEM ;memory leak of struct ljca *ljca
ack, this will be fixed in next version, thanks
Quoted 7 lines
drivers/usb/misc/usb-ljca.c line 509
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+ + auxdev->dev.parent = &dev->intf->dev; + auxdev->dev.release = ljca_aux_release;Regards
Oliver
Re: [PATCH v8 1/6] usb: Add support for Intel LJCA device
On 20.06.23 09:39, Wu, Wentong wrote:
Hi,
Quoted 11 lines
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 275
Quoted 3 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+ + ibuf_len =READ_ONCE (stub->ipacket.ibuf_len); + ibuf =READ_ONCE (stub->ipacket.ibuf);This races against
stub_write(). Yes, every value now is consistent within this function. But that does not solve the issue. The pair needs to be consistent. You need to rule out that you are reading a different length and buffer location. I am afraid this needs a spinlock.Sorry, based on my understanding, the stub's
ibuf_lenand ibuf won't be changed bystub_writeuntil firmware ack the current command.
Or a timeout.
There are two places in the driver ibuf_len and ibuf are touched. Both are in ljca_stub_write(), but in case of a timeout they are set to NULL. And you are checking for that case. That is good, but not sufficient, as READ_ONCE does not guarantee ordering, nor do you use WRITE_ONCE to set them.
Quoted 2 lines
This memory barrier here is for potential cache consistency issue in some arches though most likely this driver will only be run on X86 platform.
Well, you can move them to architecture dependent directories. But if not, they will have to work generically.
A correct version would be something like:
+static int ljca_parse(struct ljca_dev *dev, struct ljca_msg *header) +{
+ struct ljca_stub *stub;
+ unsigned int *ibuf_len;
+ u8 *ibuf;
+
+ 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;
+ }
+
smp_rmb();
+ ibuf_len = READ_ONCE(stub->ipacket.ibuf_len);
+ ibuf = READ_ONCE(stub->ipacket.ibuf);
+
+ if (ibuf && ibuf_len) {
+ unsigned int newlen;
+
+ newlen = min_t(unsigned int, header->len, *ibuf_len);
+
+ *ibuf_len = newlen;
+ memcpy(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,
+ 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;
WRITE_ONCE(stub->ipacket.ibuf, ibuf);WRITE_ONCE(stub->ipacket.ibuf_len, ibuf_len);
+ stub->acked = false;
smp_wmb();
[..]
+error_unlock:
WRITE_ONCE(stub->ipacket.ibuf, NULL);WRITE_ONCE(stub->ipacket.ibuf_len, NULL);smp_wmb();
+ mutex_unlock(&dev->mutex);
Regards
Oliver
PATCH v8 2/6 usb: ljca: Add transport interfaces for sub-module drivers
In reply to Ye XiangAdds the transport interfaces for various LJCA sub-module drivers to communicate with LJCA hardware. 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.
--- drivers/usb/misc/usb-ljca.c | 91 +++++++++++++++++++++++++++++++++++++ include/linux/usb/ljca.h | 52 +++++++++++++++++++++ 2 files changed, 143 insertions(+)
drivers/usb/misc/usb-ljca.c +91 -0
@@ -368,6 +368,97 @@ static int ljca_stub_write(struct ljca_stub *stub, u8 cmd, const void *obuf, unsreturn 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_event_cb_entry *entry, *iter; +struct ljca_stub *stub; +unsigned long flags; +int ret; + + stub =ljca_stub_find (ljca->dev, ljca->type); +if (IS_ERR (stub)) +return PTR_ERR (stub); + + entry =kzalloc (sizeof (*entry),GFP_KERNEL ); +if (!entry) +return -ENOMEM ; + + entry->notify = event_cb; + entry->context = context; + entry->id = ljca->id; + +spin_lock_irqsave (&stub->event_cb_lock, flags); + +list_for_each_entry (iter, &stub->event_entrys, list) { +if (iter->id == ljca->id) { + ret = -EBUSY ; +break ; + } + } + +if (!ret) +list_add_tail (&entry->list, &stub->event_entrys); + +spin_unlock_irqrestore (&stub->event_cb_lock, flags); + +if (ret) +kfree (entry); + +return ret; +} +EXPORT_SYMBOL_NS_GPL (ljca_register_event_cb,LJCA ); + +void ljca_unregister_event_cb (struct ljca *ljca) +{ +struct ljca_stub *stub; +struct ljca_event_cb_entry *iter; +unsigned long flags; + + stub =ljca_stub_find (ljca->dev, ljca->type); +if (IS_ERR (stub)) +return ; + +spin_lock_irqsave (&stub->event_cb_lock, flags); + +list_for_each_entry (iter, &stub->event_entrys, list) { +if (iter->id == ljca->id) { +list_del_init (&iter->list); +kfree (iter); +break ; + } + } + +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
Re: [PATCH v8 2/6] usb: ljca: Add transport interfaces for sub-module drivers
Quoted 9 lines · Ye Xiang
Adds the transport interfaces for various LJCA sub-module drivers to communicate with LJCA hardware. The sub-modules of LJCA can use
ljca_transfer()to issue a transfer between host and hardware. Andljca_register_event_cbis exported to LJCA sub-module drivers for hardware event subscription.Signed-off-by Ye Xiang <[email protected]>---
drivers/usb/misc/usb-ljca.c static int ljca_stub_write(struct ljca_stub *stub, u8 cmd, const void *obuf, uns · line 403
Quoted 7 lines
drivers/usb/misc/usb-ljca.c +7
-0+ +int ljca_register_event_cb (struct ljca *ljca,ljca_event_cb_t event_cb,void *context) +{ +struct ljca_event_cb_entry *entry, *iter; +struct ljca_stub *stub; +unsigned long flags; +int ret;
Uninitialized variable
Quoted 4 lines
drivers/usb/misc/usb-ljca.c +4
-0+ + stub =ljca_stub_find (ljca->dev, ljca->type); +if (IS_ERR (stub)) +return PTR_ERR (stub);
drivers/usb/misc/usb-ljca.c static int ljca_stub_write(struct ljca_stub *stub, u8 cmd, const void *obuf, uns · line 417
Quoted 10 lines
drivers/usb/misc/usb-ljca.c +10
-0+ + entry =kzalloc (sizeof (*entry),GFP_KERNEL ); +if (!entry) +return -ENOMEM ; + + entry->notify = event_cb; + entry->context = context; + entry->id = ljca->id; + +spin_lock_irqsave (&stub->event_cb_lock, flags);
You are using GFP_KERNEL a few lines earlier. No need for irqsave
Quoted 9 lines
drivers/usb/misc/usb-ljca.c +9
-0+ +list_for_each_entry (iter, &stub->event_entrys, list) { +if (iter->id == ljca->id) { + ret = -EBUSY ; +break ; + } + } + +if (!ret)
drivers/usb/misc/usb-ljca.c static int ljca_stub_write(struct ljca_stub *stub, u8 cmd, const void *obuf, uns · line 436
Quoted 10 lines
drivers/usb/misc/usb-ljca.c +10
-0+list_add_tail (&entry->list, &stub->event_entrys); + +spin_unlock_irqrestore (&stub->event_cb_lock, flags); + +if (ret) +kfree (entry); + +return ret; +} +EXPORT_SYMBOL_NS_GPL (ljca_register_event_cb,LJCA );
Regards
Oliver
PATCH v8 3/6 Documentation: Add ABI doc for attributes of LJCA device
In reply to Ye XiangAdd 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
@@ -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
PATCH v8 4/6 gpio: Add support for Intel LJCA USB GPIO driver
In reply to Ye XiangImplements 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 | 479 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 492 insertions(+) create mode 100644 drivers/gpio/gpio-ljca.c
drivers/gpio/Kconfig +12 -0
@@ -1658,6 +1658,18 @@ config GPIO_VIPERBOARD River Tech's viperboard.h for detailed meaning of the module parameters. +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. + endmenu menu "Virtual GPIO drivers"
drivers/gpio/Makefile +1 -0
@@ -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 +479 -0
479 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v8 4/6] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 6 lines · Ye Xiang
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.
Signed-off-by Ye Xiang <[email protected]>
Overall this looks very nice.
Quoted 1 line
+static int
gpio_config(struct ljca_gpio_dev *ljca_gpio, u8 gpio_id, u8 config)
All other functions are prefixed ljca_* except this one, so I think you should do that on this one too.
With that fixes:
Yours,
Linus Walleij
RE: [PATCH v8 4/6] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 11 lines
-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Friday, May 12, 2023 5:08 AMReview
Quoted 2 lines
(quoted diff) +2
-0+static int gpio_config(struct ljca_gpio_dev *ljca_gpio, u8 gpio_id, +u8 config)All other functions are prefixed ljca_* except this one, so I think you should do that on this one too.
Thank you, Linus, this will be fixed in next version, Thanks
Quoted 6 lines
With that fixes:
Reviewed-by Linus Walleij <[email protected]>Yours,
Linus Walleij
Re: [PATCH v8 4/6] gpio: Add support for Intel LJCA USB GPIO driver
In reply to Ye XiangQuoted 8 lines · Ye Xiang
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.
Signed-off-by Ye Xiang <[email protected]>---
With Linus' comment addressed, you can add:
RE: [PATCH v8 4/6] gpio: Add support for Intel LJCA USB GPIO driver
In reply to Ye XiangQuoted 521 lines
-----Original Message-----
From: Ye, Xiang <[email protected]>
Sent: Friday, May 12, 2023 1:59 AMImplements 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.
Signed-off-by Ye Xiang <[email protected]>--- drivers/gpio/Kconfig | 12 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-ljca.c | 479 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 492 insertions(+) create mode 100644 drivers/gpio/gpio-ljca.cdrivers/gpio/Kconfig index renamed from drivers/gpio/Kconfig +0
-0
13be729710f2..bbf00e157dcd100644drivers/gpio/Kconfig +12
-0@@ -1658,6 +1658,18 @@ config GPIO_VIPERBOARD River Tech's viperboard.h for detailed meaning of the module parameters. +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. + endmenu menu "Virtual GPIO drivers"drivers/gpio/Makefile index renamed from drivers/gpio/Makefile +0
-0
c048ba003367..eb59524d18c0100644drivers/gpio/Makefile +0
-0@@ -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.odrivers/gpio/Makefile +1
-0+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.odrivers/gpio/gpio-ljca.c new file mode renamed from drivers/gpio/gpio-ljca.c +0
-0100644 index 000000000000..81835a21e8c0
drivers/gpio/gpio-ljca.c new file +39
-0@@ -0,0 +1,479 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Intel La Jolla Cove Adapter USB-GPIO driver +* +* Copyright (c) 2023, Intel Corporation. +*/ + +#include <linux/acpi.h> +#include <linux/auxiliary_bus.h> +#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/dev_printk.h> +#include <linux/gpio/driver.h> +#include <linux/irq.h> +#include <linux/kernel.h> +#include <linux/kref.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/usb/ljca.h> + +/* GPIO commands */ +#define LJCA_GPIO_CONFIG 1 +#define LJCA_GPIO_READ 2 +#define LJCA_GPIO_WRITE 3 +#define LJCA_GPIO_INT_EVENT 4 +#define LJCA_GPIO_INT_MASK 5 +#define LJCA_GPIO_INT_UNMASK 6 + +#define LJCA_GPIO_CONF_DISABLE BIT(0) +#define LJCA_GPIO_CONF_INPUT BIT(1) +#define LJCA_GPIO_CONF_OUTPUT BIT(2) +#define LJCA_GPIO_CONF_PULLUP BIT(3) +#define LJCA_GPIO_CONF_PULLDOWN BIT(4) +#define LJCA_GPIO_CONF_DEFAULT BIT(5) +#define LJCA_GPIO_CONF_INTERRUPT BIT(6) +#define LJCA_GPIO_INT_TYPE BIT(7) + +#define LJCA_GPIO_CONF_EDGE
FIELD_PREP(LJCA_GPIO_INT_TYPE, 1)
+#defineLJCA_GPIO_CONF_LEVEL
FIELD_PREP(LJCA_GPIO_INT_TYPE, 0)drivers/gpio/gpio-ljca.c new file +64
-0+ +/* Intentional overlap with PULLUP / PULLDOWN */ +#define LJCA_GPIO_CONF_SET BIT(3) +#define LJCA_GPIO_CONF_CLR BIT(4) + +struct gpio_op { +u8 index; +u8 value; +} __packed; + +struct gpio_packet { +u8 num; +struct gpio_op item[]; +} __packed; + +#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct ljca *ljca; +struct gpio_chip gc; +struct ljca_gpio_info *gpio_info; + DECLARE_BITMAP(unmasked_irqs, LJCA_MAX_GPIO_NUM); + DECLARE_BITMAP(enabled_irqs, LJCA_MAX_GPIO_NUM); + DECLARE_BITMAP(reenable_irqs, LJCA_MAX_GPIO_NUM); + DECLARE_BITMAP(output_enabled, LJCA_MAX_GPIO_NUM); +u8 *connect_mode; +/* mutex to protect irq bus */ +struct mutex irq_lock; +struct work_struct work; +/* lock to protect package transfer to Hardware */ +struct mutex trans_lock; + +u8 obuf[LJCA_GPIO_BUF_SIZE ]; +u8 ibuf[LJCA_GPIO_BUF_SIZE ]; +}; + +static int gpio_config (struct ljca_gpio_dev *ljca_gpio,u8 gpio_id,u8 +config) { +struct gpio_packet *packet = (struct gpio_packet *)ljca_gpio->obuf; +int ret; + +mutex_lock (&ljca_gpio->trans_lock); + packet->item[0 ].index = gpio_id; + packet->item[0 ].value = config | ljca_gpio->connect_mode[gpio_id]; + packet->num =1 ; + + ret =ljca_transfer (ljca_gpio->ljca,LJCA_GPIO_CONFIG , packet, +struct_size (packet, item, packet->num),NULL ,NULL ); +mutex_unlock (&ljca_gpio->trans_lock); + +return ret; +} + +static int ljca_gpio_read (struct ljca_gpio_dev *ljca_gpio,u8 gpio_id) +{ +struct gpio_packet *packet = (struct gpio_packet *)ljca_gpio->obuf; +struct gpio_packet *ack_packet = (struct gpio_packet *)ljca_gpio->ibuf; +unsigned int ibuf_len =LJCA_GPIO_BUF_SIZE ; +int ret; + +mutex_lock (&ljca_gpio->trans_lock); + packet->num =1 ; + packet->item[0 ].index = gpio_id; + ret = ljca_transfer(ljca_gpio->ljca, LJCA_GPIO_READ, packet, + struct_size(packet, item, packet->num), ljca_gpio-Quoted 1 line
ibuf,
&ibuf_len);drivers/gpio/gpio-ljca.c new file +6
-0+if (ret) + goto out_unlock; + +if (!ibuf_len || ack_packet->num != packet->num) { + dev_err(&ljca_gpio->ljca->auxdev.dev, + "read package error, gpio_id:%u num:%uibuf_len:%d\n",
gpio_id,drivers/gpio/gpio-ljca.c new file +43
-0+ ack_packet->num, ibuf_len); + ret = -EIO ; + } + +out_unlock: +mutex_unlock (&ljca_gpio->trans_lock); +if (ret) +return ret; + +return ack_packet->item[0 ].value >0 ; +} + +static int ljca_gpio_write (struct ljca_gpio_dev *ljca_gpio,u8 gpio_id, +int value) { +struct gpio_packet *packet = (struct gpio_packet *)ljca_gpio->obuf; +int ret; + +mutex_lock (&ljca_gpio->trans_lock); + packet->num =1 ; + packet->item[0 ].index = gpio_id; + packet->item[0 ].value = value &1 ; + + ret =ljca_transfer (ljca_gpio->ljca,LJCA_GPIO_WRITE , packet, +struct_size (packet, item, packet->num),NULL ,NULL ); +mutex_unlock (&ljca_gpio->trans_lock); + +return ret; +} + +static int ljca_gpio_get_value (struct gpio_chip *chip,unsigned int +offset) { +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (chip); + +return ljca_gpio_read (ljca_gpio, offset); } + +static void ljca_gpio_set_value (struct gpio_chip *chip,unsigned int +offset,int val) { +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (chip); +int ret; + + ret =ljca_gpio_write (ljca_gpio, offset, val); +if (ret) + dev_err(chip->parent, "set value failed offset:%u val:%dret:%d\n", offset, val,
drivers/gpio/gpio-ljca.c new file +53
-0+ ret); +} + +static int ljca_gpio_direction_input (struct gpio_chip *chip,unsigned +int offset) { +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (chip); +u8 config =LJCA_GPIO_CONF_INPUT |LJCA_GPIO_CONF_CLR ; +int ret; + + ret =gpio_config (ljca_gpio, offset, config); +if (ret) +return ret; + +clear_bit (offset, ljca_gpio->output_enabled); + +return 0 ; +} + +static int ljca_gpio_direction_output (struct gpio_chip *chip,unsigned +int offset,int val) { +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (chip); +u8 config =LJCA_GPIO_CONF_OUTPUT |LJCA_GPIO_CONF_CLR ; +int ret; + + ret =gpio_config (ljca_gpio, offset, config); +if (ret) +return ret; + +ljca_gpio_set_value (chip, offset, val); +set_bit (offset, ljca_gpio->output_enabled); + +return 0 ; +} + +static int ljca_gpio_get_direction (struct gpio_chip *chip,unsigned int +offset) { +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (chip); + +if (test_bit (offset, ljca_gpio->output_enabled)) +return GPIO_LINE_DIRECTION_OUT ; + +return GPIO_LINE_DIRECTION_IN ; +} + +static int ljca_gpio_set_config (struct gpio_chip *chip,unsigned int offset, +unsigned long config) +{ +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (chip); + + ljca_gpio->connect_mode[offset] =0 ; +switch (pinconf_to_config_param (config)) { +case PIN_CONFIG_BIAS_PULL_UP : + ljca_gpio->connect_mode[offset] |=
LJCA_GPIO_CONF_PULLUP;drivers/gpio/gpio-ljca.c new file +3
-0+break ; +case PIN_CONFIG_BIAS_PULL_DOWN : + ljca_gpio->connect_mode[offset] |=
LJCA_GPIO_CONF_PULLDOWN;drivers/gpio/gpio-ljca.c new file +12
-0+break ; +case PIN_CONFIG_DRIVE_PUSH_PULL : +case PIN_CONFIG_PERSIST_STATE : +break ; +default : +return -ENOTSUPP ; + } + +return 0 ; +} + +static int ljca_gpio_init_valid_mask(struct gpio_chip *chip, unsigned long
*valid_mask,drivers/gpio/gpio-ljca.c new file +11
-0+ unsigned int ngpios) +{ +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (chip); + +WARN_ON_ONCE (ngpios != ljca_gpio->gpio_info->num); +bitmap_copy (valid_mask, ljca_gpio->gpio_info->valid_pin_map, ngpios); + +return 0 ; +} + +static void ljca_gpio_irq_init_valid_mask(struct gpio_chip *chip, unsigned long
*valid_mask,drivers/gpio/gpio-ljca.c new file +15
-0+ unsigned int ngpios) +{ +ljca_gpio_init_valid_mask (chip, valid_mask, ngpios); } + +static int ljca_enable_irq (struct ljca_gpio_dev *ljca_gpio,int +gpio_id,bool enable) { +struct gpio_packet *packet = (struct gpio_packet *)ljca_gpio->obuf; +int ret; + +mutex_lock (&ljca_gpio->trans_lock); + packet->num =1 ; + packet->item[0 ].index = gpio_id; + packet->item[0 ].value =0 ; + + ret = ljca_transfer(ljca_gpio->ljca, enable ? LJCA_GPIO_INT_UNMASK :
LJCA_GPIO_INT_MASK,drivers/gpio/gpio-ljca.c new file +1
-0+ packet, struct_size(packet, item, packet->num), NULL,NULL);
drivers/gpio/gpio-ljca.c new file +7
-0+mutex_unlock (&ljca_gpio->trans_lock); + +return ret; +} + +static void ljca_gpio_async (struct work_struct *work) { + struct ljca_gpio_dev *ljca_gpio = container_of(work, struct
ljca_gpio_dev, work);drivers/gpio/gpio-ljca.c new file +4
-0+int gpio_id; +int unmasked; + +for_each_set_bit (gpio_id, ljca_gpio->reenable_irqs, ljca_gpio->gc.ngpio){
drivers/gpio/gpio-ljca.c new file +19
-0+clear_bit (gpio_id, ljca_gpio->reenable_irqs); + unmasked =test_bit (gpio_id, ljca_gpio->unmasked_irqs); +if (unmasked) +ljca_enable_irq (ljca_gpio, gpio_id, true); + } +} + +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-Quoted 1 line
item[i].index);
drivers/gpio/gpio-ljca.c new file +2
-0+if (!irq) { + dev_err(ljca_gpio->gc.parent, "gpio_id %u does notmapped to IRQ yet\n",
drivers/gpio/gpio-ljca.c new file +38
-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); +} + +static void ljca_irq_unmask (struct irq_data *irqd) { +struct gpio_chip *gc =irq_data_get_irq_chip_data (irqd); +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (gc); +int gpio_id =irqd_to_hwirq (irqd); + +gpiochip_enable_irq (gc, gpio_id); +set_bit (gpio_id, ljca_gpio->unmasked_irqs); } + +static void ljca_irq_mask (struct irq_data *irqd) { +struct gpio_chip *gc =irq_data_get_irq_chip_data (irqd); +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (gc); +int gpio_id =irqd_to_hwirq (irqd); + +clear_bit (gpio_id, ljca_gpio->unmasked_irqs); +gpiochip_disable_irq (gc, gpio_id); +} + +static int ljca_irq_set_type (struct irq_data *irqd,unsigned int type) +{ +struct gpio_chip *gc =irq_data_get_irq_chip_data (irqd); +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (gc); +int gpio_id =irqd_to_hwirq (irqd); + + ljca_gpio->connect_mode[gpio_id] =LJCA_GPIO_CONF_INTERRUPT ; +switch (type) { +case IRQ_TYPE_LEVEL_HIGH : + ljca_gpio->connect_mode[gpio_id] |=(
LJCA_GPIO_CONF_LEVEL|LJCA_GPIO_CONF_PULLUP);drivers/gpio/gpio-ljca.c new file +3
-0+break ; +case IRQ_TYPE_LEVEL_LOW : + ljca_gpio->connect_mode[gpio_id] |=(
LJCA_GPIO_CONF_LEVEL|LJCA_GPIO_CONF_PULLDOWN);drivers/gpio/gpio-ljca.c new file +5
-0+break ; +case IRQ_TYPE_EDGE_BOTH : +break ; +case IRQ_TYPE_EDGE_RISING : + ljca_gpio->connect_mode[gpio_id] |= (LJCA_GPIO_CONF_EDGE|
LJCA_GPIO_CONF_PULLUP);drivers/gpio/gpio-ljca.c new file +3
-0+break ; +case IRQ_TYPE_EDGE_FALLING : + ljca_gpio->connect_mode[gpio_id] |= (LJCA_GPIO_CONF_EDGE|
LJCA_GPIO_CONF_PULLDOWN);drivers/gpio/gpio-ljca.c new file +58
-0+break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static void ljca_irq_bus_lock (struct irq_data *irqd) { +struct gpio_chip *gc =irq_data_get_irq_chip_data (irqd); +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (gc); + +mutex_lock (&ljca_gpio->irq_lock); +} + +static void ljca_irq_bus_unlock (struct irq_data *irqd) { +struct gpio_chip *gc =irq_data_get_irq_chip_data (irqd); +struct ljca_gpio_dev *ljca_gpio =gpiochip_get_data (gc); +int gpio_id =irqd_to_hwirq (irqd); +int enabled; +int unmasked; + + enabled =test_bit (gpio_id, ljca_gpio->enabled_irqs); + unmasked =test_bit (gpio_id, ljca_gpio->unmasked_irqs); + +if (enabled != unmasked) { +if (unmasked) { +gpio_config (ljca_gpio, gpio_id,0 ); +ljca_enable_irq (ljca_gpio, gpio_id, true); +set_bit (gpio_id, ljca_gpio->enabled_irqs); + }else { +ljca_enable_irq (ljca_gpio, gpio_id, false); +clear_bit (gpio_id, ljca_gpio->enabled_irqs); + } + } + +mutex_unlock (&ljca_gpio->irq_lock); +} + +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 , +}; + +static int ljca_gpio_probe (struct auxiliary_device *auxdev, +const struct auxiliary_device_id *aux_dev_id) { +struct ljca *ljca =auxiliary_dev_to_ljca (auxdev); +struct ljca_gpio_dev *ljca_gpio; +struct gpio_irq_chip *girq; +int ret; + + ljca_gpio = devm_kzalloc(&auxdev->dev, sizeof(*ljca_gpio),
GFP_KERNEL);drivers/gpio/gpio-ljca.c new file +6
-0+if (!ljca_gpio) +return -ENOMEM ; + + ljca_gpio->ljca = ljca; + ljca_gpio->gpio_info =dev_get_platdata (&auxdev->dev); + ljca_gpio->connect_mode = devm_kcalloc(&auxdev->dev, ljca_gpio-Quoted 1 line
gpio_info->num,drivers/gpio/gpio-ljca.c new file +1
-0+ sizeof(*ljca_gpio->connect_mode),
GFP_KERNEL);drivers/gpio/gpio-ljca.c new file +46
-0+if (!ljca_gpio->connect_mode) +return -ENOMEM ; + +mutex_init (&ljca_gpio->irq_lock); +mutex_init (&ljca_gpio->trans_lock); + ljca_gpio->gc.direction_input = ljca_gpio_direction_input; + ljca_gpio->gc.direction_output = ljca_gpio_direction_output; + ljca_gpio->gc.get_direction = ljca_gpio_get_direction; + ljca_gpio->gc.get = ljca_gpio_get_value; + ljca_gpio->gc.set = ljca_gpio_set_value; + ljca_gpio->gc.set_config = ljca_gpio_set_config; + ljca_gpio->gc.init_valid_mask = ljca_gpio_init_valid_mask; + ljca_gpio->gc.can_sleep = true; + ljca_gpio->gc.parent = &auxdev->dev; + + ljca_gpio->gc.base =-1 ; + ljca_gpio->gc.ngpio = ljca_gpio->gpio_info->num; + ljca_gpio->gc.label =ACPI_COMPANION (&auxdev->dev) ? +acpi_dev_name (ACPI_COMPANION (&auxdev->dev)) : +dev_name (&auxdev->dev); + ljca_gpio->gc.owner =THIS_MODULE ; + +auxiliary_set_drvdata (auxdev, ljca_gpio); +ljca_register_event_cb (ljca, ljca_gpio_event_cb, ljca_gpio); + + girq = &ljca_gpio->gc.irq; +gpio_irq_chip_set_chip (girq, &ljca_gpio_irqchip); + girq->parent_handler =NULL ; + girq->num_parents =0 ; + girq->parents =NULL ; + girq->default_type =IRQ_TYPE_NONE ; + girq->handler = handle_simple_irq; + girq->init_valid_mask = ljca_gpio_irq_init_valid_mask; + +INIT_WORK (&ljca_gpio->work, ljca_gpio_async); + ret =gpiochip_add_data (&ljca_gpio->gc, ljca_gpio); +if (ret) { +ljca_unregister_event_cb (ljca); +mutex_destroy (&ljca_gpio->irq_lock); +mutex_destroy (&ljca_gpio->trans_lock); + } + +return ret; +} + +static void ljca_gpio_remove (struct auxiliary_device *auxdev) {
drivers/gpio/gpio-ljca.c line 460
Quoted 10 lines
drivers/gpio/gpio-ljca.c new file +10
-0+struct ljca_gpio_dev *ljca_gpio =auxiliary_get_drvdata (auxdev); + +gpiochip_remove (&ljca_gpio->gc); +ljca_unregister_event_cb (ljca_gpio->ljca); +cancel_work_sync (&ljca_gpio->work); +mutex_destroy (&ljca_gpio->irq_lock); +mutex_destroy (&ljca_gpio->trans_lock); +} + +#define LJCA_GPIO_DRV_NAME "ljca.ljca-gpio"
The wrong name causes the probe match failed. The name should be "usb_ljca.ljca-gpio", the same as spi and i2c.
BR,
Wentong
Quoted 21 lines
drivers/gpio/gpio-ljca.c new file +14
-0+static const struct auxiliary_device_id ljca_gpio_id_table[] = { + {LJCA_GPIO_DRV_NAME ,0 }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (auxiliary, ljca_gpio_id_table); + +static struct auxiliary_driver ljca_gpio_driver = { + .probe = ljca_gpio_probe, + .remove = ljca_gpio_remove, + .id_table = ljca_gpio_id_table, +}; +module_auxiliary_driver (ljca_gpio_driver); + +MODULE_AUTHOR ("Ye Xiang <[email protected]>" );MODULE_AUTHOR("Wang
drivers/gpio/gpio-ljca.c new file +4
-1+Zhifeng <[email protected]>"); MODULE_AUTHOR("Zhang Lixu +<[email protected]>"); MODULE_DESCRIPTION("Intel La Jolla Cove +Adapter USB-GPIO driver"); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS (LJCA ); --2.34.1
PATCH v8 5/6 i2c: Add support for Intel LJCA USB I2C driver
In reply to Ye XiangImplements 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 | 350 ++++++++++++++++++++++++++++++++++ 3 files changed, 362 insertions(+) create mode 100644 drivers/i2c/busses/i2c-ljca.c
drivers/i2c/busses/Kconfig +11 -0
@@ -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
@@ -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 +350 -0
350 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v8 5/6] i2c: Add support for Intel LJCA USB I2C driver
Quoted 5 lines · Ye Xiang
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/i2c-ljca.c line 51
Quoted 9 lines
drivers/i2c/busses/i2c-ljca.c new file +9
-0+/* I2C Transfer */ +struct i2c_xfer { +u8 id; +u8 slave; +u16 flag;/* speed, 8/16bit addr, addr increase, etc */ +u16 addr; +u16 len; +u8 data[]; +} __packed;
Where is this needed?
Why is it defined __packed, yet the internal endianness is not declared?
Regards
Oliver
RE: [PATCH v8 5/6] i2c: Add support for Intel LJCA USB I2C driver
Hi Oliver,
Thanks for your review.
Quoted 10 lines
-----Original Message-----
From: Oliver Neukum <[email protected]>
Sent: Monday, May 22, 2023 5:50 PMQuoted 4 lines · Ye Xiang
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.
Quoted 11 lines
drivers/i2c/busses/i2c-ljca.c line 51
Quoted 9 lines
drivers/i2c/busses/i2c-ljca.c new file +9
-0+/* I2C Transfer */ +struct i2c_xfer { +u8 id; +u8 slave; +u16 flag;/* speed, 8/16bit addr, addr increase, etc */ +u16 addr; +u16 len; +u8 data[]; +} __packed;Where is this needed?
Yes, you're right, we don’t need this structure. Thanks
Quoted 4 lines
Why is it defined
__packed, yet the internal endianness is not declared?Regards
Oliver
PATCH v8 6/6 spi: Add support for Intel LJCA USB SPI driver
In reply to Ye XiangImplements 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 | 290 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 302 insertions(+) create mode 100644 drivers/spi/spi-ljca.c
drivers/spi/Kconfig +11 -0
@@ -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
@@ -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 +290 -0
290 lines not on this page · raw message
Signature · 1 line
2.34.1
Mark Brown
maintainerRe: [PATCH v8 6/6] spi: Add support for Intel LJCA USB SPI driver
drivers/spi/spi-ljca.c line 3
Quoted 5 lines · Ye Xiang
+++
b/drivers/spi/spi-ljca.cdrivers/spi/spi-ljca.c new file +3
-0@@ -0,0 +1,290 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Intel La Jolla Cove Adapter USB-SPI driver
Please make the entire comment a C++ one so things look more intentional.
drivers/spi/spi-ljca.c line 61
Quoted 7 lines
drivers/spi/spi-ljca.c new file +7
-0+struct spi_init_packet { +u8 index; +u8 speed; +u8 mode; +} __packed; + +struct spi_xfer_packet {
These should be namespaced, especially since they look likely to collide with other things. Otherwise this looks fine.
RE: [PATCH v8 6/6] spi: Add support for Intel LJCA USB SPI driver
Hi Brown,
Thanks for your review
Quoted 6 lines
-----Original Message-----
From: Mark Brown <[email protected]>
Sent: Friday, May 12, 2023 12:18 PMOn Fri, May 12, 2023 at 01:58:44AM +0800, Ye Xiang wrote:
Quoted 8 lines
drivers/spi/spi-ljca.c line 3
Quoted 5 lines
+++
b/drivers/spi/spi-ljca.cdrivers/spi/spi-ljca.c new file +3
-0@@ -0,0 +1,290 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Intel La Jolla Cove Adapter USB-SPI driver Please make the entire comment a C++ one so things look more intentional.
I see lots of drivers are commenting like current one.
But sorry, you mean the entire comment start with /* and end with */ ? Thanks
BR,
Wentong
Quoted 10 lines
drivers/spi/spi-ljca.c line 61
Quoted 7 lines
drivers/spi/spi-ljca.c new file +7
-0+struct spi_init_packet { +u8 index; +u8 speed; +u8 mode; +} __packed; + +struct spi_xfer_packet {These should be namespaced, especially since they look likely to collide with other things. Otherwise this looks fine.
Ack, these two structs will be like below in next version, thanks
struct ljca_spi_init_packet {
u8 index;
u8 index;
u8 mode;
} __packed;struct ljca_spi_xfer_packet {
u8 indicator;
s8 len;
u8 data[];
} __packed;Mark Brown
maintainerRe: [PATCH v8 6/6] spi: Add support for Intel LJCA USB SPI driver
Quoted 8 lines · Wentong
Quoted 5 lines
drivers/spi/spi-ljca.c line 3
Quoted 3 lines
drivers/spi/spi-ljca.c new file +3
-0+// SPDX-License-Identifier: GPL-2.0-only +/* +* Intel La Jolla Cove Adapter USB-SPI driver Please make the entire comment a C++ one so things look more intentional.
I see lots of drivers are commenting like current one.
But sorry, you mean the entire comment start with /* and end with */ ? Thanks
Other way around, use // for all the lines in this comment block please.
Greg Kroah-Hartman
maintainerQuoted 4 lines · Ye Xiang
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.
I am sorry, but you have not followed the required Intel-specific requirements for submitting code like this. Please work with the Linux Intel developer group to resolve this issue and do it properly for your next patch submission as I can not take this one for this obvious reason.
thanks,
greg k-h
Hi Greg,
Thanks for your review.
BTW, somehow I will take care this patch set.
Thanks
Wentong
Quoted 18 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Saturday, May 13, 2023 4:50 PMQuoted 4 lines · Ye Xiang
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.
I am sorry, but you have not followed the required Intel-specific requirements for submitting code like this. Please work with the Linux Intel developer group to resolve this issue and do it properly for your next patch submission as I can not take this one for this obvious reason.
thanks,
greg k-h