Add Intel LJCA device driver
Subsystems (6)
v4 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.
---
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):
mfd: 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 | 22 + drivers/gpio/Kconfig | 12 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-ljca.c | 454 ++++++++ drivers/i2c/busses/Kconfig | 11 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-ljca.c | 357 +++++++ drivers/spi/Kconfig | 11 + drivers/spi/Makefile | 1 + drivers/spi/spi-ljca.c | 291 ++++++ drivers/usb/misc/Kconfig | 13 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/ljca.c | 969 ++++++++++++++++++ include/linux/mfd/ljca.h | 95 ++ 14 files changed, 2239 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/mfd/ljca.h
Signature · 1 line
2.34.1
PATCH v4 1/5 mfd: 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 | 969 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/ljca.h | 95 ++++ 4 files changed, 1078 insertions(+) create mode 100644 drivers/usb/misc/ljca.c create mode 100644 include/linux/mfd/ljca.h
drivers/usb/misc/Kconfig +13 -0
@@ -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
@@ -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 +969 -0
969 lines not on this page · raw message
include/linux/mfd/ljca.h new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.34.1
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 2 lines · Ye Xiang
This patch implements the USB part of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA).
Then why is this called "mfd" in the subject line?
Quoted 1 line
include/linux/mfd/ljca.h | 95 ++++
Why is this .h file in the mfd directory?
thanks,
greg k-h
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Hi Greg,
Thanks for the review.
Quoted 5 lines · Greg Kroah-Hartman
Quoted 2 lines · Ye Xiang
This patch implements the USB part of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA).
Then why is this called "mfd" in the subject line?
Sorry, it's a mistake. I forget to change mfd to usb in the commit message because I just move the ljca.c from driver/mfd to drivers/usb/misc according to previous review comments[1]. And I will address this on v5.
[1] https://www.spinics.net/lists/kernel/msg4708451.html
Quoted 4 lines
Quoted 2 lines
include/linux/mfd/ljca.h | 95 ++++Why is this .h file in the mfd directory?
It's a mistake as well. Will address it by moving include/linux/mfd/ljca.h to include/linux/usb/ljca.h.
Quoted 4 lines
thanks,
greg k-h
--
Thanks
Ye Xiang
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 13 lines · Xiang
Hi Greg,
Thanks for the review.
Quoted 5 lines · Greg Kroah-Hartman
Quoted 2 lines · Ye Xiang
This patch implements the USB part of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA).
Then why is this called "mfd" in the subject line?
Sorry, it's a mistake. I forget to change mfd to usb in the commit message because I just move the
ljca.cfrom driver/mfd todrivers/usb/miscaccording to previous review comments[1]. And I will address this on v5.
Quoted 7 lines
[1] https://www.spinics.net/lists/kernel/msg4708451.html
Quoted 4 lines
Quoted 2 lines
include/linux/mfd/ljca.h | 95 ++++Why is this .h file in the mfd directory?
It's a mistake as well. Will address it by moving
include/linux/mfd/ljca.htoinclude/linux/usb/ljca.h.
Why do you need a .h file at all for such a tiny .c file? If you don't need it, don't have one please.
thanks,
greg k-h
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 16 lines · Greg Kroah-Hartman
Quoted 15 lines · Xiang
Hi Greg,
Thanks for the review.
Quoted 5 lines · Greg Kroah-Hartman
Quoted 2 lines · Ye Xiang
This patch implements the USB part of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA).
Then why is this called "mfd" in the subject line?
Sorry, it's a mistake. I forget to change mfd to usb in the commit message because I just move the
ljca.cfrom driver/mfd todrivers/usb/miscaccording to previous review comments[1]. And I will address this on v5.[1] https://www.spinics.net/lists/kernel/msg4708451.html
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
include/linux/mfd/ljca.h | 95 ++++Why is this .h file in the mfd directory?
It's a mistake as well. Will address it by moving
include/linux/mfd/ljca.htoinclude/linux/usb/ljca.h.Why do you need a .h file at all for such a tiny .c file? If you don't need it, don't have one please.
The ljca.h file is needed because there are three function driver in this series (LJCA-SPI, LJCA-GPIO, and LJCA-I2C) which needs LJCA API to do actual transfers. LJCA-USB can be considered as a transport driver, and the other three function driver use LJCA API to transfer their own packages.
--
Thanks
Ye Xiang
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
In reply to Ye XiangQuoted 9 lines · Ye Xiang
drivers/usb/misc/ljca.c new file +9
-0+static int ljca_mng_get_version (struct ljca_stub *stub,char *buf) +{ +struct fw_version version = {}; +unsigned int len =sizeof (version); +int ret; + + ret =ljca_stub_write (stub,LJCA_MNG_GET_VERSION ,NULL ,0 , &version, &len, true, +LJCA_USB_WRITE_ACK_TIMEOUT_MS ); +if (ret)
drivers/usb/misc/ljca.c line 720
Quoted 10 lines
drivers/usb/misc/ljca.c new file +10
-0+return ret; + +if (len !=sizeof (version)) { +dev_err (&stub->intf->dev,"get version failed, len:%d\n" , len); +return -EINVAL ; + } + +return sysfs_emit (buf,"%d.%d.%d.%d\n" , version.major, version.minor, +le16_to_cpu (version.patch),le16_to_cpu (version.build)); +}
You have sysfs files, yet no Documentation/ABI/ entries? That's not allowed, you know this :(
drivers/usb/misc/ljca.c line 819
Quoted 12 lines
drivers/usb/misc/ljca.c new file +12
-0+static ssize_t cmd_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 ); +struct ljca_stub *diag_stub =ljca_stub_find (ljca_dev,LJCA_DIAG_STUB ); + +if (sysfs_streq (buf,"dfu" )) +ljca_mng_set_dfu_mode (mng_stub); +else if (sysfs_streq (buf,"debug" )) +ljca_diag_set_trace_level (diag_stub,3 );
Sorry, but no, you can't do this in a sysfs file.
drivers/usb/misc/ljca.c line 826
Quoted 7 lines
drivers/usb/misc/ljca.c new file +7
-0+ +return count; +} + +static ssize_t cmd_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%s\n" ,"supported cmd: [dfu, debug]" );
sysfs files do not show "help text".
thanks,
greg k-h
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Ye Xiang
drivers/usb/misc/ljca.c new file +14
-0+static int ljca_mng_get_version (struct ljca_stub *stub,char *buf) +{ +struct fw_version version = {}; +unsigned int len =sizeof (version); +int ret; + + ret =ljca_stub_write (stub,LJCA_MNG_GET_VERSION ,NULL ,0 , &version, &len, true, +LJCA_USB_WRITE_ACK_TIMEOUT_MS ); +if (ret) +return ret; + +if (len !=sizeof (version)) { +dev_err (&stub->intf->dev,"get version failed, len:%d\n" , len); +return -EINVAL ;
Quoted 8 lines
drivers/usb/misc/ljca.c line 720
Quoted 5 lines
drivers/usb/misc/ljca.c new file +5
-0+ } + +return sysfs_emit (buf,"%d.%d.%d.%d\n" , version.major, version.minor, +le16_to_cpu (version.patch),le16_to_cpu (version.build)); +}You have sysfs files, yet no
Documentation/ABI/entries? That's not allowed, you know this :(
The Documentation/ABI/ entries is added for the sysfs on patch 5 of this series.
https://patchwork.kernel.org/project/linux-usb/patch/[email protected]/
Quoted 15 lines
drivers/usb/misc/ljca.c line 819
Quoted 13 lines
drivers/usb/misc/ljca.c new file +12
-0+static ssize_t cmd_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 ); +struct ljca_stub *diag_stub =ljca_stub_find (ljca_dev,LJCA_DIAG_STUB ); + +if (sysfs_streq (buf,"dfu" )) +ljca_mng_set_dfu_mode (mng_stub); +else if (sysfs_streq (buf,"debug" )) +ljca_diag_set_trace_level (diag_stub,3 );Sorry, but no, you can't do this in a sysfs file.
Do you mean that we can't use sysfs to send "debug" command to device? Could you provide some detail or hints?
Quoted 10 lines
drivers/usb/misc/ljca.c line 826
Quoted 8 lines
drivers/usb/misc/ljca.c new file +7
-0+ +return count; +} + +static ssize_t cmd_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%s\n" ,"supported cmd: [dfu, debug]" );sysfs files do not show "help text".
Ok. I can remove this for this has been described in Documentation/ABI/testing/sysfs-bus-usb-devices-ljca (added in patch 5 of this series).
Quoted 4 lines
thanks,
greg k-h
--
Thanks
Ye Xiang
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 24 lines · Xiang
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Ye Xiang
drivers/usb/misc/ljca.c new file +14
-0+static int ljca_mng_get_version (struct ljca_stub *stub,char *buf) +{ +struct fw_version version = {}; +unsigned int len =sizeof (version); +int ret; + + ret =ljca_stub_write (stub,LJCA_MNG_GET_VERSION ,NULL ,0 , &version, &len, true, +LJCA_USB_WRITE_ACK_TIMEOUT_MS ); +if (ret) +return ret; + +if (len !=sizeof (version)) { +dev_err (&stub->intf->dev,"get version failed, len:%d\n" , len); +return -EINVAL ;Quoted 8 lines
drivers/usb/misc/ljca.c line 720
Quoted 5 lines
drivers/usb/misc/ljca.c new file +5
-0+ } + +return sysfs_emit (buf,"%d.%d.%d.%d\n" , version.major, version.minor, +le16_to_cpu (version.patch),le16_to_cpu (version.build)); +}You have sysfs files, yet no
Documentation/ABI/entries? That's not allowed, you know this :(
Quoted 2 lines
The
Documentation/ABI/entries is added for the sysfs on patch 5 of this series.
https://patchwork.kernel.org/project/linux-usb/patch/[email protected]/
Ah, missed that, sorry.
Quoted 15 lines
Quoted 15 lines
drivers/usb/misc/ljca.c line 819
Quoted 13 lines
drivers/usb/misc/ljca.c new file +12
-0+static ssize_t cmd_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 ); +struct ljca_stub *diag_stub =ljca_stub_find (ljca_dev,LJCA_DIAG_STUB ); + +if (sysfs_streq (buf,"dfu" )) +ljca_mng_set_dfu_mode (mng_stub); +else if (sysfs_streq (buf,"debug" )) +ljca_diag_set_trace_level (diag_stub,3 );Sorry, but no, you can't do this in a sysfs file.
Quoted 1 line
Do you mean that we can't use sysfs to send "debug" command to device?
That is correct, use the kernel-wide debugging facilities that we have for this NEVER create your own custom interface just for one tiny driver, that is not allowed.
Quoted 1 line
Could you provide some detail or hints?
dev_dbg().
thanks,
greg k-h
Andi Shyti
maintainerRe: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 47 lines · Greg Kroah-Hartman
Quoted 24 lines · Xiang
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Ye Xiang
drivers/usb/misc/ljca.c new file +14
-0+static int ljca_mng_get_version (struct ljca_stub *stub,char *buf) +{ +struct fw_version version = {}; +unsigned int len =sizeof (version); +int ret; + + ret =ljca_stub_write (stub,LJCA_MNG_GET_VERSION ,NULL ,0 , &version, &len, true, +LJCA_USB_WRITE_ACK_TIMEOUT_MS ); +if (ret) +return ret; + +if (len !=sizeof (version)) { +dev_err (&stub->intf->dev,"get version failed, len:%d\n" , len); +return -EINVAL ;Quoted 8 lines
drivers/usb/misc/ljca.c line 720
Quoted 5 lines
drivers/usb/misc/ljca.c new file +5
-0+ } + +return sysfs_emit (buf,"%d.%d.%d.%d\n" , version.major, version.minor, +le16_to_cpu (version.patch),le16_to_cpu (version.build)); +}You have sysfs files, yet no
Documentation/ABI/entries? That's not allowed, you know this :(Quoted 2 lines
The
Documentation/ABI/entries is added for the sysfs on patch 5 of this series.
https://patchwork.kernel.org/project/linux-usb/patch/[email protected]/Ah, missed that, sorry.
Quoted 15 lines
Quoted 15 lines
drivers/usb/misc/ljca.c line 819
Quoted 13 lines
drivers/usb/misc/ljca.c new file +12
-0+static ssize_t cmd_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 ); +struct ljca_stub *diag_stub =ljca_stub_find (ljca_dev,LJCA_DIAG_STUB ); + +if (sysfs_streq (buf,"dfu" )) +ljca_mng_set_dfu_mode (mng_stub); +else if (sysfs_streq (buf,"debug" )) +ljca_diag_set_trace_level (diag_stub,3 );Sorry, but no, you can't do this in a sysfs file.
Quoted 1 line
Do you mean that we can't use sysfs to send "debug" command to device?
Quoted 7 lines
That is correct, use the kernel-wide debugging facilities that we have for this NEVER create your own custom interface just for one tiny driver, that is not allowed.
Quoted 1 line
Could you provide some detail or hints?
dev_dbg().
I'm not sure this is the same thing, though, as it's not a drvier to user debug message.
Ye, can you please explain better what this command does? You are sending a LJCA_DIAG_SET_TRACE_LEVEL command to the device with a parameter "3" which has a meaining only for you :)
What is ugly here is the parsing of "dfu" and "debug", I would just make different boolean files, something like:
echo 1 > ljca_dfu
echo 0 > ljca_dfu
and
echo N > ljca_trace_level
with a proper documentation of the trace levels.
The show counterparast can provide a feedback on how the interfaces are set rather than providing some help message, which is not what sysfs files are meant for.
Would this work?
Andi
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 48 lines · Andi Shyti
Quoted 47 lines · Greg Kroah-Hartman
Quoted 24 lines · Xiang
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Ye Xiang
drivers/usb/misc/ljca.c new file +14
-0+static int ljca_mng_get_version (struct ljca_stub *stub,char *buf) +{ +struct fw_version version = {}; +unsigned int len =sizeof (version); +int ret; + + ret =ljca_stub_write (stub,LJCA_MNG_GET_VERSION ,NULL ,0 , &version, &len, true, +LJCA_USB_WRITE_ACK_TIMEOUT_MS ); +if (ret) +return ret; + +if (len !=sizeof (version)) { +dev_err (&stub->intf->dev,"get version failed, len:%d\n" , len); +return -EINVAL ;Quoted 8 lines
drivers/usb/misc/ljca.c line 720
Quoted 5 lines
drivers/usb/misc/ljca.c new file +5
-0+ } + +return sysfs_emit (buf,"%d.%d.%d.%d\n" , version.major, version.minor, +le16_to_cpu (version.patch),le16_to_cpu (version.build)); +}You have sysfs files, yet no
Documentation/ABI/entries? That's not allowed, you know this :(Quoted 2 lines
The
Documentation/ABI/entries is added for the sysfs on patch 5 of this series.
https://patchwork.kernel.org/project/linux-usb/patch/[email protected]/Ah, missed that, sorry.
Quoted 16 lines
Quoted 15 lines
drivers/usb/misc/ljca.c line 819
Quoted 13 lines
drivers/usb/misc/ljca.c new file +12
-0+static ssize_t cmd_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 ); +struct ljca_stub *diag_stub =ljca_stub_find (ljca_dev,LJCA_DIAG_STUB ); + +if (sysfs_streq (buf,"dfu" )) +ljca_mng_set_dfu_mode (mng_stub); +else if (sysfs_streq (buf,"debug" )) +ljca_diag_set_trace_level (diag_stub,3 );Sorry, but no, you can't do this in a sysfs file.
Do you mean that we can't use sysfs to send "debug" command to device?
Quoted 7 lines
Quoted 7 lines
That is correct, use the kernel-wide debugging facilities that we have for this NEVER create your own custom interface just for one tiny driver, that is not allowed.
Quoted 1 line
Could you provide some detail or hints?
dev_dbg().
But, this command is sent to SET LJCA Firmware logging level.
Quoted 7 lines
I'm not sure this is the same thing, though, as it's not a drvier to user debug message.
Ye, can you please explain better what this command does? You are sending a
LJCA_DIAG_SET_TRACE_LEVELcommand to the device with a parameter "3" which has a meaining only for you :)
Sure, the LJCA_DIAG_SET_TRACE_LEVEL command is used to set LJCA FW logging level. 3 means debug level for FW. It is used for LJCA FW
debugging: when FW got some issue, we can send debug level to FW to make FW print degging log for analysis.
Quoted 11 lines
What is ugly here is the parsing of "dfu" and "debug", I would just make different boolean files, something like:
echo 1 >
ljca_dfu
echo 0 >ljca_dfuand
echo N >
ljca_trace_level
Quoted 7 lines
with a proper documentation of the trace levels.
The show counterparast can provide a feedback on how the interfaces are set rather than providing some help message, which is not what sysfs files are meant for.
Would this work?
Thanks. It should works, and I will try it.
--
Thanks
Ye Xiang
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 49 lines · Xiang
Quoted 48 lines · Andi Shyti
Quoted 47 lines · Greg Kroah-Hartman
Quoted 24 lines · Xiang
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Ye Xiang
drivers/usb/misc/ljca.c new file +14
-0+static int ljca_mng_get_version (struct ljca_stub *stub,char *buf) +{ +struct fw_version version = {}; +unsigned int len =sizeof (version); +int ret; + + ret =ljca_stub_write (stub,LJCA_MNG_GET_VERSION ,NULL ,0 , &version, &len, true, +LJCA_USB_WRITE_ACK_TIMEOUT_MS ); +if (ret) +return ret; + +if (len !=sizeof (version)) { +dev_err (&stub->intf->dev,"get version failed, len:%d\n" , len); +return -EINVAL ;Quoted 8 lines
drivers/usb/misc/ljca.c line 720
Quoted 5 lines
drivers/usb/misc/ljca.c new file +5
-0+ } + +return sysfs_emit (buf,"%d.%d.%d.%d\n" , version.major, version.minor, +le16_to_cpu (version.patch),le16_to_cpu (version.build)); +}You have sysfs files, yet no
Documentation/ABI/entries? That's not allowed, you know this :(Quoted 2 lines
The
Documentation/ABI/entries is added for the sysfs on patch 5 of this series.
https://patchwork.kernel.org/project/linux-usb/patch/[email protected]/Ah, missed that, sorry.
Quoted 16 lines
Quoted 15 lines
drivers/usb/misc/ljca.c line 819
Quoted 13 lines
drivers/usb/misc/ljca.c new file +12
-0+static ssize_t cmd_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 ); +struct ljca_stub *diag_stub =ljca_stub_find (ljca_dev,LJCA_DIAG_STUB ); + +if (sysfs_streq (buf,"dfu" )) +ljca_mng_set_dfu_mode (mng_stub); +else if (sysfs_streq (buf,"debug" )) +ljca_diag_set_trace_level (diag_stub,3 );Sorry, but no, you can't do this in a sysfs file.
Do you mean that we can't use sysfs to send "debug" command to device?
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
That is correct, use the kernel-wide debugging facilities that we have for this NEVER create your own custom interface just for one tiny driver, that is not allowed.
Quoted 1 line
Could you provide some detail or hints?
dev_dbg().But, this command is sent to SET LJCA Firmware logging level.
What command?
This isn't documented at all, sorry, I don't understand what you are trying to do here.
Quoted 10 lines
Quoted 6 lines
I'm not sure this is the same thing, though, as it's not a drvier to user debug message.
Ye, can you please explain better what this command does? You are sending a
LJCA_DIAG_SET_TRACE_LEVELcommand to the device with a parameter "3" which has a meaining only for you :)Sure, the
LJCA_DIAG_SET_TRACE_LEVELcommand is used to set LJCA FW logging level. 3 means debug level for FW. It is used for LJCA FW
debugging: when FW got some issue, we can send debug level to FW to make FW print degging log for analysis.
And where is that printed? In the kernel log? Somewhere else? What does the firmware have to do with any of this?
thanks,
greg k-h
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 54 lines · Greg Kroah-Hartman
Quoted 53 lines · Xiang
Quoted 52 lines · Andi Shyti
Quoted 51 lines · Greg Kroah-Hartman
Quoted 24 lines · Xiang
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Ye Xiang
(quoted diff) +14
-0+static int ljca_mng_get_version(struct ljca_stub *stub, char *buf) +{ + struct fw_version version = {}; + unsigned int len = sizeof(version); + int ret; + + ret = ljca_stub_write(stub, LJCA_MNG_GET_VERSION, NULL, 0, &version, &len, true, + LJCA_USB_WRITE_ACK_TIMEOUT_MS); + if (ret) + return ret; + + if (len != sizeof(version)) { + dev_err(&stub->intf->dev, "get version failed, len:%d\n", len); + return -EINVAL;Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ } + + return sysfs_emit(buf, "%d.%d.%d.%d\n", version.major, version.minor, + le16_to_cpu(version.patch), le16_to_cpu(version.build)); +}You have sysfs files, yet no
Documentation/ABI/entries? That's not allowed, you know this :(Quoted 2 lines
The
Documentation/ABI/entries is added for the sysfs on patch 5 of this series.
https://patchwork.kernel.org/project/linux-usb/patch/[email protected]/Ah, missed that, sorry.
Quoted 15 lines
Quoted 15 lines
Review
Quoted 13 lines
(quoted diff) +12
-0+static ssize_t cmd_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); + struct ljca_stub *diag_stub = ljca_stub_find(ljca_dev, LJCA_DIAG_STUB); + + if (sysfs_streq(buf, "dfu")) + ljca_mng_set_dfu_mode(mng_stub); + else if (sysfs_streq(buf, "debug")) + ljca_diag_set_trace_level(diag_stub, 3);Sorry, but no, you can't do this in a sysfs file.
Quoted 1 line
Do you mean that we can't use sysfs to send "debug" command to device?
That is correct, use the kernel-wide debugging facilities that we have for this NEVER create your own custom interface just for one tiny driver, that is not allowed.
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Could you provide some detail or hints?
dev_dbg().But, this command is sent to SET LJCA Firmware logging level.
What command?
ljca_diag_set_trace_level send LJCA_DIAG_SET_TRACE_LEVEL command to LJCA FW to set FW log level.
Quoted 3 lines
This isn't documented at all, sorry, I don't understand what you are trying to do here.
Sorry for the doc missing. will try to add more details on comments and Documentation/ABI/ entries.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
I'm not sure this is the same thing, though, as it's not a drvier to user debug message.
Ye, can you please explain better what this command does? You are sending a
LJCA_DIAG_SET_TRACE_LEVELcommand to the device with a parameter "3" which has a meaining only for you :)
Quoted 7 lines
Quoted 4 lines
Sure, the
LJCA_DIAG_SET_TRACE_LEVELcommand is used to set LJCA FW logging level. 3 means debug level for FW. It is used for LJCA FW
debugging: when FW got some issue, we can send debug level to FW to make FW print degging log for analysis.And where is that printed? In the kernel log? Somewhere else? What does the firmware have to do with any of this?
The firmware log was printed through UART port of LJCA device to another computer just for debugging purposes. After sending LJCA_DIAG_SET_TRACE_LEVEL command to LJCA device, it will print logging according to the log level sent before.
--
Thanks
Ye Xiang
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
In reply to Ye XiangQuoted 13 lines · Ye Xiang
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)
Quoted 8 lines
}
Device (SPI)
{
Name (_ADR, 0x02)
Name (_STA, 0x0F)
}
}I'm a bit confused by this bit, does that mean this only works if the device is integrated on the mainboard and the BIOS is aware of it? This won't work if you plug it into a random USB port, or have no ACPI firmware, right?
Quoted 7 lines
Signed-off-by Ye Xiang <[email protected]>Reviewed-by Sakari Ailus <[email protected]>--- drivers/usb/misc/Kconfig | 13 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/ljca.c | 969 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/ljca.h | 95 ++++
Why is this in driver/usb/misc? It looks like a normal mfd driver to me, and it evenhas the header in include/linux/mfd/
Arnd
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Hi Arnd,
Thanks for the review.
Quoted 24 lines · Arnd Bergmann
Quoted 13 lines · Ye Xiang
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)Quoted 8 lines
} Device (SPI) { Name (_ADR, 0x02) Name (_STA, 0x0F) } }
Quoted 4 lines
I'm a bit confused by this bit, does that mean this only works if the device is integrated on the mainboard and the BIOS is aware of it? This won't work if you plug it into a random USB port, or have no ACPI firmware, right?
LJCA can work both when there is an ACPI firmware or not.
When there is a config like "The minimum code in ASL" in DSDT, LJCA device and its sub-devices will bind to right ACPI devices. Our current use case needs the the ACPI binding. Because we have a camera sensor depending on this LJCA device, We use the ACPI binding to control the probe order, making sure the camera sensor probe after LJCA and LJCA-I2C.
When there isn't a config in DSDT, the LJCA device also can works. But it won't have an acpi binding.
So, If you plug into a random USB port or have no ACPI binding, It just does not have an ACPI binding.
Quoted 11 lines
Quoted 8 lines
Signed-off-by Ye Xiang <[email protected]>Reviewed-by Sakari Ailus <[email protected]>--- drivers/usb/misc/Kconfig | 13 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/ljca.c | 969 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/ljca.h | 95 ++++Why is this in driver/usb/misc? It looks like a normal mfd driver to me, and it evenhas the header in
include/linux/mfd/
It's a mistake. I just moved it from driver/mfd and forget to move the header to right place. It will be addressed on next version.
Quoted 2 lines
Arnd
--
Thanks
Ye Xiang
Mark Brown
maintainerRe: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
In reply to Arnd BergmannQuoted 9 lines · Arnd Bergmann
Quoted 4 lines · Ye Xiang
drivers/usb/misc/Kconfig | 13 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/ljca.c | 969 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/ljca.h | 95 ++++Why is this in driver/usb/misc? It looks like a normal mfd driver to me, and it evenhas the header in
include/linux/mfd/
It was a MFD in the original version, Lee asked for it to be moved to
USB: https://lore.kernel.org/r/[email protected]
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 8 lines · Mark Brown
Quoted 6 lines · Arnd Bergmann
Quoted 4 lines · Ye Xiang
drivers/usb/misc/Kconfig | 13 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/ljca.c | 969 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/ljca.h | 95 ++++
Quoted 5 lines
Quoted 2 lines
Why is this in driver/usb/misc? It looks like a normal mfd driver to me, and it evenhas the header in
include/linux/mfd/It was a MFD in the original version, Lee asked for it to be moved to
USB: https://lore.kernel.org/r/[email protected]
Ok, I see. That should probably be mentioned in the patch description then. I'm still not sure I follow the reasoning for the split between "usb functionality" and and mfd part:
This is just a usb driver as it is attached to a usb bus, and drivers usually get put into a directory based on what they provide, not how they are attached to a parent bus.
Arnd
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
In reply to Ye Xiangdrivers/usb/misc/ljca.c line 294
Quoted 2 lines · Ye Xiang
drivers/usb/misc/ljca.c new file +2
-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)
Why do you make ibuf_len a pointer?
Quoted 21 lines
drivers/usb/misc/ljca.c new file +21
-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;
drivers/usb/misc/ljca.c line 325
Quoted 10 lines
drivers/usb/misc/ljca.c new file +10
-0+ 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) {
Memory leak in error case. You must free header.
Quoted 19 lines
drivers/usb/misc/ljca.c new file +19
-0+ 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,
drivers/usb/misc/ljca.c line 354
Quoted 10 lines
drivers/usb/misc/ljca.c new file +10
-0+ 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 ;
If that triggers, you may have a pending URB.
You must kill it.
Quoted 36 lines
drivers/usb/misc/ljca.c new file +34
-0+ 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_i2c_stub_init (struct ljca_dev *dev,struct ljca_i2c_descriptor *desc) +{ +struct ljca_i2c_info *i2c_info; +struct ljca_stub *stub; +int ret; +int i; + + stub =ljca_stub_alloc (dev,LJCA_I2C_STUB ,size_mul (desc->num,sizeof (*i2c_info))); +if (IS_ERR (stub)) +return PTR_ERR (stub); + + i2c_info =ljca_priv (stub); + +for (i =0 ; i < desc->num; i++) { +struct mfd_cell cell = {}; + + i2c_info[i].ljca = &stub->ljca; + i2c_info[i].id = desc->info[i].id; + i2c_info[i].capacity = desc->info[i].capacity; + i2c_info[i].intr_pin = desc->info[i].intr_pin; +
drivers/usb/misc/ljca.c
Quoted 10 lines
drivers/usb/misc/ljca.c new file +10
-0+ cell.name ="ljca-i2c" ; + cell.platform_data = &i2c_info[i]; + cell.pdata_size =sizeof (i2c_info[i]); + +if (i <ARRAY_SIZE (ljca_acpi_match_i2cs)) + cell.acpi_match = &ljca_acpi_match_i2cs[i]; + + ret =ljca_add_mfd_cell (dev, &cell); +if (ret) +return ret;
What happens to stub in the error case?
drivers/usb/misc/ljca.c line 926
Quoted 12 lines
drivers/usb/misc/ljca.c new file +10
-0+ } + +return 0 ; +} + +static void ljca_disconnect (struct usb_interface *intf) +{ +struct ljca_dev *dev =usb_get_intfdata (intf); + +ljca_stop (dev);
What prevents restarting the device here?
Quoted 8 lines
drivers/usb/misc/ljca.c new file +8
-0+mfd_remove_devices (&intf->dev); +ljca_stub_cleanup (dev); +ljca_delete (dev); +} + +static int ljca_suspend (struct usb_interface *intf,pm_message_t message) +{ +struct ljca_dev *dev =usb_get_intfdata (intf);
drivers/usb/misc/ljca.c line 944
Quoted 10 lines
drivers/usb/misc/ljca.c new file +10
-0+ +ljca_stop (dev); +return 0 ; +} + +static int ljca_resume (struct usb_interface *intf) +{ +struct ljca_dev *dev =usb_get_intfdata (intf); + +return ljca_start (dev);
So here you report errors, but at the same time you set "started" even if errors occur.
Regards
Oliver
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Hi Oliver,
Thanks for your review.
Quoted 8 lines · Oliver Neukum
drivers/usb/misc/ljca.c line 294
Quoted 2 lines · Ye Xiang
drivers/usb/misc/ljca.c new file +2
-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)Why do you make
ibuf_lena pointer?
Because ibuf_len is also used as output of this function here. It stores the actual length of ibuf receive from LJCA device.
Quoted 26 lines
Quoted 26 lines
drivers/usb/misc/ljca.c new file +25
-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);
Quoted 8 lines
drivers/usb/misc/ljca.c line 325
Quoted 6 lines
drivers/usb/misc/ljca.c new file +6
-0+ +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) {Memory leak in error case. You must free header.
Good catch. Thanks. Will address it.
Quoted 25 lines
Quoted 25 lines
drivers/usb/misc/ljca.c new file +24
-0+ 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; + } +
Quoted 8 lines
drivers/usb/misc/ljca.c line 354
Quoted 5 lines
drivers/usb/misc/ljca.c new file +5
-0+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 ;If that triggers, you may have a pending URB.
You must kill it.
which URB? I guess what you mean is dev->in_urb?
But the in_urb should always be up to waiting for message from firmware, even through this timeout happen.
Quoted 41 lines
Quoted 41 lines
drivers/usb/misc/ljca.c new file +38
-0+ 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_i2c_stub_init (struct ljca_dev *dev,struct ljca_i2c_descriptor *desc) +{ +struct ljca_i2c_info *i2c_info; +struct ljca_stub *stub; +int ret; +int i; + + stub =ljca_stub_alloc (dev,LJCA_I2C_STUB ,size_mul (desc->num,sizeof (*i2c_info))); +if (IS_ERR (stub)) +return PTR_ERR (stub); + + i2c_info =ljca_priv (stub); + +for (i =0 ; i < desc->num; i++) { +struct mfd_cell cell = {}; + + i2c_info[i].ljca = &stub->ljca; + i2c_info[i].id = desc->info[i].id; + i2c_info[i].capacity = desc->info[i].capacity; + i2c_info[i].intr_pin = desc->info[i].intr_pin; + + cell.name ="ljca-i2c" ; + cell.platform_data = &i2c_info[i]; + cell.pdata_size =sizeof (i2c_info[i]); +
Quoted 8 lines
drivers/usb/misc/ljca.c line 625
Quoted 6 lines
drivers/usb/misc/ljca.c new file +6
-0+if (i <ARRAY_SIZE (ljca_acpi_match_i2cs)) + cell.acpi_match = &ljca_acpi_match_i2cs[i]; + + ret =ljca_add_mfd_cell (dev, &cell); +if (ret) +return ret;What happens to stub in the error case?
ljca_add_mfd_cell only failed when krealloc_array failing. When ljca_add_mfd_cell fails, the related stub just be left alone here.
Maybe I should free the stub here when fails? what is your advice?
Quoted 7 lines
Quoted 5 lines
drivers/usb/misc/ljca.c new file +4
-0+ } + +return 0 ; +}
Quoted 8 lines
drivers/usb/misc/ljca.c line 926
Quoted 6 lines
drivers/usb/misc/ljca.c new file +6
-0+ +static void ljca_disconnect (struct usb_interface *intf) +{ +struct ljca_dev *dev =usb_get_intfdata (intf); + +ljca_stop (dev);What prevents restarting the device here?
Why need to restart the device here?
The ljca_disconnect function should be called when the LJCA device is unplugged.
Quoted 14 lines
Quoted 14 lines
drivers/usb/misc/ljca.c new file +13
-0+mfd_remove_devices (&intf->dev); +ljca_stub_cleanup (dev); +ljca_delete (dev); +} + +static int ljca_suspend (struct usb_interface *intf,pm_message_t message) +{ +struct ljca_dev *dev =usb_get_intfdata (intf); + +ljca_stop (dev); +return 0 ; +} +
Quoted 8 lines
drivers/usb/misc/ljca.c line 944
Quoted 5 lines
drivers/usb/misc/ljca.c new file +5
-0+static int ljca_resume (struct usb_interface *intf) +{ +struct ljca_dev *dev =usb_get_intfdata (intf); + +return ljca_start (dev);So here you report errors, but at the same time you set "started" even if errors occur.
Thanks, Got it. Will address it on next version.
--
Thanks
Ye Xiang
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Quoted 1 line · Xiang
Hi Oliver,
Hi,
sorry for the delayed answer.
Quoted 4 lines
Thanks for your review.
Quoted 2 lines · Oliver Neukum
Quoted 8 lines
Quoted 6 lines · Ye Xiang
drivers/usb/misc/ljca.c line 294
Quoted 3 lines
drivers/usb/misc/ljca.c new file +2
-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)Why do you make
ibuf_lena pointer?Because
ibuf_lenis also used as output of this function here. It stores the actual length of ibuf receive from LJCA device.
Yes, I understand that now, thank you for the explanation, yet that is problematic, if we look at another issue. See further down:
Quoted 8 lines
Quoted 8 lines
drivers/usb/misc/ljca.c line 333
Quoted 8 lines
drivers/usb/misc/ljca.c new file +8
-0+ ret = -ENODEV ; + goto error_put; + } + +mutex_lock (&dev->mutex); + stub->cur_cmd = cmd; + stub->ipacket.ibuf = ibuf; + stub->ipacket.ibuf_len = ibuf_len;
Here you store the pointer into the stub. Hence we must make sure that the location it points to stays valid.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/usb/misc/ljca.c new file +13
-0+ 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 ;
Quoted 8 lines
Quoted 8 lines
drivers/usb/misc/ljca.c line 354
Quoted 8 lines
drivers/usb/misc/ljca.c new file +8
-0+ 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 ;
The function will return an error in the timeout case. This may be a trivial observation but it becomes important.
Quoted 1 line
Quoted 1 line
If that triggers, you may have a pending URB.
I misspoke. Pending IO would have been correct.
Quoted 4 lines
Quoted 1 line
You must kill it.
which URB? I guess what you mean is
dev->in_urb?
But thein_urbshould always be up to waiting for message from firmware, even through this timeout happen.
Now let's look at ljca_mng_reset_handshake(). I am afraid I have to quote its first part in full:
+static int ljca_mng_reset_handshake(struct ljca_stub *stub) +{
+ struct ljca_mng_priv *priv;
+ __le32 reset_id;
+ __le32 reset_id_ret = 0;
+ unsigned int ilen = sizeof(__le32);
This is on the _stack_
Highly important !!!
+ int ret;
+
+ priv = ljca_priv(stub);
+ reset_id = cpu_to_le32(priv->reset_id++);
+ ret = ljca_stub_write(stub, LJCA_MNG_RESET_NOTIFY, &reset_id, sizeof(reset_id),
+ &reset_id_ret, &ilen, true, LJCA_USB_WRITE_ACK_TIMEOUT_MS);
If we run into the timeout error case, ret will be -ETIMEDOUT.
+ if (ret)
+ return ret;
And thus here we return and free the stack _including_ "ilen", which we still have a pointer to. That means if the operation concludes after a timeout, we _will_ follow a rogue pointer.
A couple of functions have this race condition.
Quoted 5 lines
Quoted 1 line
What happens to stub in the error case?
ljca_add_mfd_cellonly failed whenkrealloc_arrayfailing. Whenljca_add_mfd_cellfails, the related stub just be left alone here.Maybe I should free the stub here when fails? what is your advice?
Yes, that is the cleanest solution.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
drivers/usb/misc/ljca.c new file +4
-0+ } + +return 0 ; +}
Quoted 8 lines
Quoted 8 lines
drivers/usb/misc/ljca.c line 926
Quoted 6 lines
drivers/usb/misc/ljca.c new file +6
-0+ +static void ljca_disconnect (struct usb_interface *intf) +{ +struct ljca_dev *dev =usb_get_intfdata (intf); + +ljca_stop (dev);What prevents restarting the device here?
Sorry, you are calling ljca_start() only in probe(9 and resume() Your code is correct.
Regards
Oliver
Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Hi Oliver,
Thanks for the review.
Quoted 6 lines · Oliver Neukum
Quoted 1 line · Xiang
Hi Oliver,
Hi,
sorry for the delayed answer.
No problem.
Quoted 55 lines
Quoted 5 lines
Thanks for your review.
Quoted 2 lines · Oliver Neukum
Quoted 8 lines
Quoted 6 lines · Ye Xiang
drivers/usb/misc/ljca.c line 294
Quoted 3 lines
drivers/usb/misc/ljca.c new file +2
-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)Why do you make
ibuf_lena pointer?Because
ibuf_lenis also used as output of this function here. It stores the actual length of ibuf receive from LJCA device.Yes, I understand that now, thank you for the explanation, yet that is problematic, if we look at another issue. See further down:
Quoted 8 lines
Quoted 8 lines
drivers/usb/misc/ljca.c line 333
Quoted 8 lines
drivers/usb/misc/ljca.c new file +8
-0+ ret = -ENODEV ; + goto error_put; + } + +mutex_lock (&dev->mutex); + stub->cur_cmd = cmd; + stub->ipacket.ibuf = ibuf; + stub->ipacket.ibuf_len = ibuf_len;Here you store the pointer into the stub. Hence we must make sure that the location it points to stays valid.
Now let's look at
ljca_mng_reset_handshake(). I am afraid I have to quote its first part in full:drivers/usb/misc/ljca.c new file +6
-0+static int ljca_mng_reset_handshake (struct ljca_stub *stub) +{ +struct ljca_mng_priv *priv; +__le32 reset_id; +__le32 reset_id_ret =0 ; +unsigned int ilen =sizeof (__le32);This is on the _stack_
Highly important !!!drivers/usb/misc/ljca.c new file +6
-0+int ret; + + priv =ljca_priv (stub); + reset_id =cpu_to_le32 (priv->reset_id++); + ret =ljca_stub_write (stub,LJCA_MNG_RESET_NOTIFY , &reset_id,sizeof (reset_id), + &reset_id_ret, &ilen, true,LJCA_USB_WRITE_ACK_TIMEOUT_MS );If we run into the timeout error case, ret will be
-ETIMEDOUT.(quoted diff) +2
-0+ if (ret) + return ret;
Quoted 4 lines
And thus here we return and free the stack _including_ "ilen", which we still have a pointer to. That means if the operation concludes after a timeout, we _will_ follow a rogue pointer.
A couple of functions have this race condition.
Got it. Will fix that on next version.
Quoted 2 lines
Thanks
Ye Xiang
PATCH v4 2/5 gpio: Add support for Intel LJCA USB GPIO driver
In reply to Ye XiangThis 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 | 454 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 467 insertions(+) create mode 100644 drivers/gpio/gpio-ljca.c
drivers/gpio/Kconfig +12 -0
@@ -1253,6 +1253,18 @@ config GPIO_KEMPLD This driver can also be built as a module. If so, the module will be called gpio-kempld. +config GPIO_LJCA + tristate "INTEL La Jolla Cove Adapter GPIO support" + depends on MFD_LJCA + select GPIOLIB_IRQCHIP + default MFD_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
@@ -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 +454 -0
454 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 7 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +7
-0+#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct platform_device *pdev; +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);
drivers/gpio/gpio-ljca.c line 72
Quoted 10 lines
drivers/gpio/gpio-ljca.c new file +10
-0+DECLARE_BITMAP (reenable_irqs,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 ];
And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
drivers/gpio/gpio-ljca.c line 431
Quoted 8 lines
drivers/gpio/gpio-ljca.c new file +8
-0+static int ljca_gpio_remove (struct platform_device *pdev) +{ +struct ljca_gpio_dev *ljca_gpio =platform_get_drvdata (pdev); + +gpiochip_remove (&ljca_gpio->gc); +ljca_unregister_event_cb (ljca_gpio->gpio_info->ljca); +mutex_destroy (&ljca_gpio->irq_lock); +mutex_destroy (&ljca_gpio->trans_lock);
At this time, what has made sure that no work is scheduled?
Review
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +}
Regards
Oliver
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 15 lines · Oliver Neukum
Quoted 13 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +13
-0+#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct platform_device *pdev; +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); +u8 *connect_mode; +/* mutex to protect irq bus */ +struct mutex irq_lock; +struct work_struct work; +/* lock to protect package transfer to Hardware */
Quoted 8 lines
drivers/gpio/gpio-ljca.c line 72
Quoted 4 lines
drivers/gpio/gpio-ljca.c new file +4
-0+struct mutex trans_lock; + +u8 obuf[LJCA_GPIO_BUF_SIZE ]; +u8 ibuf[LJCA_GPIO_BUF_SIZE ];And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
Huh?!
The problem here is alignment. But other than that I can't see the issue with embedding into structures the instances of which will be allocated on the heap.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Greg Kroah-Hartman
maintainerRe: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 25 lines · Andy Shevchenko
Quoted 15 lines · Oliver Neukum
Quoted 13 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +13
-0+#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct platform_device *pdev; +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); +u8 *connect_mode; +/* mutex to protect irq bus */ +struct mutex irq_lock; +struct work_struct work; +/* lock to protect package transfer to Hardware */ Quoted 8 lines
drivers/gpio/gpio-ljca.c line 72
Quoted 4 lines
drivers/gpio/gpio-ljca.c new file +4
-0+struct mutex trans_lock; + +u8 obuf[LJCA_GPIO_BUF_SIZE ]; +u8 ibuf[LJCA_GPIO_BUF_SIZE ];And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
Quoted 4 lines
Huh?!
The problem here is alignment. But other than that I can't see the issue with embedding into structures the instances of which will be allocated on the heap.
As you said, the problem is alignment.
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
In reply to Andy ShevchenkoQuoted 25 lines · Andy Shevchenko
Quoted 15 lines · Oliver Neukum
Quoted 13 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +13
-0+#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct platform_device *pdev; +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); +u8 *connect_mode; +/* mutex to protect irq bus */ +struct mutex irq_lock; +struct work_struct work; +/* lock to protect package transfer to Hardware */ Quoted 8 lines
drivers/gpio/gpio-ljca.c line 72
Quoted 4 lines
drivers/gpio/gpio-ljca.c new file +4
-0+struct mutex trans_lock; + +u8 obuf[LJCA_GPIO_BUF_SIZE ]; +u8 ibuf[LJCA_GPIO_BUF_SIZE ];And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
Quoted 4 lines
Huh?!
The problem here is alignment. But other than that I can't see the issue with embedding into structures the instances of which will be allocated on the heap.
Yups. And I think the solution looks something like this:
u8 obuf[LJCA_GPIO_BUF_SIZE] __aligned(8);
u8 ibuf[LJCA_GPIO_BUF_SIZE] __aligned(8);
__aligned(4) if it's 32bit DMA I guess? 8 always works that's why we use it all over the IIO subsystem.
Yours,
Linus Walleij
Greg Kroah-Hartman
maintainerRe: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 32 lines · Linus Walleij
Quoted 25 lines · Andy Shevchenko
Quoted 15 lines · Oliver Neukum
Quoted 13 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +13
-0+#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct platform_device *pdev; +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); +u8 *connect_mode; +/* mutex to protect irq bus */ +struct mutex irq_lock; +struct work_struct work; +/* lock to protect package transfer to Hardware */ Quoted 8 lines
drivers/gpio/gpio-ljca.c line 72
Quoted 4 lines
drivers/gpio/gpio-ljca.c new file +4
-0+struct mutex trans_lock; + +u8 obuf[LJCA_GPIO_BUF_SIZE ]; +u8 ibuf[LJCA_GPIO_BUF_SIZE ];And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
Quoted 4 lines
Huh?!
The problem here is alignment. But other than that I can't see the issue with embedding into structures the instances of which will be allocated on the heap.
Quoted 7 lines
Yups. And I think the solution looks something like this:
u8 obuf[LJCA_GPIO_BUF_SIZE]
__aligned(8);
u8 ibuf[LJCA_GPIO_BUF_SIZE]__aligned(8);
__aligned(4)if it's 32bit DMA I guess? 8 always works that's why we use it all over the IIO subsystem.
To make it all simple, just make obuf and ibuf pointers to the data you allocate with a call to kmalloc().
thanks,
greg k-h
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
In reply to Linus WalleijQuoted 10 lines · Linus Walleij
On Thu, Mar 9, 2023 at 2:53 PM Andy Shevchenko
<[email protected]> wrote:Yups. And I think the solution looks something like this:
u8 obuf[LJCA_GPIO_BUF_SIZE]
__aligned(8);
u8 ibuf[LJCA_GPIO_BUF_SIZE]__aligned(8);
__aligned(4)if it's 32bit DMA I guess? 8 always works that's why we use it all over the IIO subsystem.
I think it must be __aligned(ARCH_DMA_MINALIGN), to account for architectures with non-coherent DMA.
Arnd
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 6 lines · Arnd Bergmann
Quoted 5 lines · Linus Walleij
On Thu, Mar 9, 2023 at 2:53 PM Andy Shevchenko
<[email protected]> wrote:Yups. And I think the solution looks something like this:
Quoted 8 lines
Quoted 5 lines
u8 obuf[LJCA_GPIO_BUF_SIZE]
__aligned(8);
u8 ibuf[LJCA_GPIO_BUF_SIZE]__aligned(8);
__aligned(4)if it's 32bit DMA I guess? 8 always works that's why we use it all over the IIO subsystem.I think it must be
__aligned(ARCH_DMA_MINALIGN), to account for architectures with non-coherent DMA.
In theory, yes, you can do that.
Is that a better solution than using what kmalloc() is designed to provide. I don't think so.
Regards
Oliver
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
In reply to Andy ShevchenkoQuoted 10 lines · Andy Shevchenko
Quoted 8 lines · Oliver Neukum
drivers/gpio/gpio-ljca.c line 72
Quoted 2 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +2
-0+u8 obuf[LJCA_GPIO_BUF_SIZE ]; +u8 ibuf[LJCA_GPIO_BUF_SIZE ];And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
Quoted 4 lines
Huh?!
The problem here is alignment. But other than that I can't see the issue with embedding into structures the instances of which will be allocated on the heap.
Hi,
These constraints are documented in dma-api-howto, but perhaps this is inconvenient to read through.
Let me explain for the input case. On certain CPUs DMA does not update CPU caches. Hence when you want to read data generated by DMA you must read from RAM. Hence you invalidate the cache line with dma_map_* operations.
Those cache lines must stay invalidated. If you wish to guarantee that, you cannot access a data structure that shares a cache line with a buffer, until you are sure that DMA is finished.
On the affected architectures kmalloc() makes sure that no allocation straddles cache lines.
Regards
Oliver
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
In reply to Oliver NeukumQuoted 17 lines · Oliver Neukum
Quoted 13 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +13
-0+#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct platform_device *pdev; +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); +u8 *connect_mode; +/* mutex to protect irq bus */ +struct mutex irq_lock; +struct work_struct work; +/* lock to protect package transfer to Hardware */
Quoted 8 lines
drivers/gpio/gpio-ljca.c line 72
Quoted 4 lines
drivers/gpio/gpio-ljca.c new file +4
-0+struct mutex trans_lock; + +u8 obuf[LJCA_GPIO_BUF_SIZE ]; +u8 ibuf[LJCA_GPIO_BUF_SIZE ];And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
But obuf and ibuf does not used to do DMA transfer here. It is actually copied from or to ljca buffer to do URB transfer. Should it still need to follow the DMA coherency rules?
Quoted 4 lines
Quoted 10 lines
drivers/gpio/gpio-ljca.c line 431
Quoted 8 lines
drivers/gpio/gpio-ljca.c new file +8
-0+static int ljca_gpio_remove (struct platform_device *pdev) +{ +struct ljca_gpio_dev *ljca_gpio =platform_get_drvdata (pdev); + +gpiochip_remove (&ljca_gpio->gc); +ljca_unregister_event_cb (ljca_gpio->gpio_info->ljca); +mutex_destroy (&ljca_gpio->irq_lock); +mutex_destroy (&ljca_gpio->trans_lock);At this time, what has made sure that no work is scheduled?
Can't make sure of that. Could Adding cancel_work_sync(&ljca_gpio->work) before mutex_destroy can address it?
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ return 0; +}
--
Thanks
Ye Xiang
Greg Kroah-Hartman
maintainerRe: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 26 lines · Xiang
Quoted 17 lines · Oliver Neukum
Quoted 13 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +13
-0+#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct platform_device *pdev; +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); +u8 *connect_mode; +/* mutex to protect irq bus */ +struct mutex irq_lock; +struct work_struct work; +/* lock to protect package transfer to Hardware */ Quoted 8 lines
drivers/gpio/gpio-ljca.c line 72
Quoted 4 lines
drivers/gpio/gpio-ljca.c new file +4
-0+struct mutex trans_lock; + +u8 obuf[LJCA_GPIO_BUF_SIZE ]; +u8 ibuf[LJCA_GPIO_BUF_SIZE ];And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
Quoted 2 lines
But obuf and ibuf does not used to do DMA transfer here. It is actually copied from or to ljca buffer to do URB transfer.
urb transfers _ARE_ DMA transfers.
Quoted 1 line
Should it still need to follow the DMA coherency rules?
Yes, all buffers for USB urbs are required to follow those rules.
thanks,
greg k-h
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 27 lines · Greg Kroah-Hartman
Quoted 26 lines · Xiang
Quoted 25 lines · Oliver Neukum
Quoted 7 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +7
-0+#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct platform_device *pdev; +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);drivers/gpio/gpio-ljca.c line 72
Quoted 10 lines
drivers/gpio/gpio-ljca.c new file +10
-0+DECLARE_BITMAP (reenable_irqs,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 ];And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
Quoted 8 lines
Quoted 2 lines
But obuf and ibuf does not used to do DMA transfer here. It is actually copied from or to ljca buffer to do URB transfer.
urb transfers _ARE_ DMA transfers.
Quoted 1 line
Should it still need to follow the DMA coherency rules?
Yes, all buffers for USB urbs are required to follow those rules.
But these two buffers are not used to do USB urb transfer directly. For the "u8 obuf[LJCA_GPIO_BUF_SIZE]", it will be copied to ljca buffer ("header->data" as below code [1] showed) first. Then the "header" is used to do the actual urb transfer.
And the "header" is allocated by using kmalloc. It should has met the DMA coherency rules.
[1] """
struct ljca_msg *header;
...
header = kmalloc(msg_len, GFP_KERNEL);
if (!header)
return -ENOMEM;
...
if (obuf)
memcpy(header->data, obuf, obuf_len);
"""
--
Thanks
Ye Xiang
Greg Kroah-Hartman
maintainerRe: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 44 lines · Xiang
Quoted 27 lines · Greg Kroah-Hartman
Quoted 26 lines · Xiang
Quoted 25 lines · Oliver Neukum
Quoted 7 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +7
-0+#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct platform_device *pdev; +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);drivers/gpio/gpio-ljca.c line 72
Quoted 10 lines
drivers/gpio/gpio-ljca.c new file +10
-0+DECLARE_BITMAP (reenable_irqs,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 ];And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
Quoted 8 lines
Quoted 2 lines
But obuf and ibuf does not used to do DMA transfer here. It is actually copied from or to ljca buffer to do URB transfer.
urb transfers _ARE_ DMA transfers.
Quoted 1 line
Should it still need to follow the DMA coherency rules?
Yes, all buffers for USB urbs are required to follow those rules.
But these two buffers are not used to do USB urb transfer directly. For the "u8 obuf[LJCA_GPIO_BUF_SIZE]", it will be copied to ljca buffer ("
header->data" as below code [1] showed) first. Then the "header" is used to do the actual urb transfer.And the "header" is allocated by using kmalloc. It should has met the DMA coherency rules.
Quoted 6 lines
[1] """
structljca_msg*header;
...
header =kmalloc(msg_len, GFP_KERNEL);
if (!header)return -ENOMEM;
Ok, that's good, but why have 2 buffers for this then?
thanks,
greg k-h
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
Quoted 45 lines · Greg Kroah-Hartman
Quoted 44 lines · Xiang
Quoted 27 lines · Greg Kroah-Hartman
Quoted 26 lines · Xiang
Quoted 25 lines · Oliver Neukum
Quoted 7 lines · Ye Xiang
drivers/gpio/gpio-ljca.c new file +7
-0+#define LJCA_GPIO_BUF_SIZE 60 +struct ljca_gpio_dev { +struct platform_device *pdev; +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);drivers/gpio/gpio-ljca.c line 72
Quoted 10 lines
drivers/gpio/gpio-ljca.c new file +10
-0+DECLARE_BITMAP (reenable_irqs,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 ];And here we have a violation of DMA coherency rules. Basically you cannot embed buffers into other data structures if they can be subject to DMA.
Quoted 8 lines
Quoted 2 lines
But obuf and ibuf does not used to do DMA transfer here. It is actually copied from or to ljca buffer to do URB transfer.
urb transfers _ARE_ DMA transfers.
Quoted 1 line
Should it still need to follow the DMA coherency rules?
Yes, all buffers for USB urbs are required to follow those rules.
But these two buffers are not used to do USB urb transfer directly. For the "u8 obuf[LJCA_GPIO_BUF_SIZE]", it will be copied to ljca buffer ("
header->data" as below code [1] showed) first. Then the "header" is used to do the actual urb transfer.And the "header" is allocated by using kmalloc. It should has met the DMA coherency rules.
Quoted 8 lines
Quoted 6 lines
[1] """
structljca_msg*header;
...
header =kmalloc(msg_len, GFP_KERNEL);
if (!header)return -ENOMEM;Ok, that's good, but why have 2 buffers for this then?
"u8 obuf[LJCA_GPIO_BUF_SIZE]" is used as a out buffer of LJCA GPIO package.
"u8 ibuf[LJCA_GPIO_BUF_SIZE]" is used as a in buffer of LJCA GPIO package.
Both obuf and ibuf here are not used to do URB transfer directly.
This obuf and ibuf somtimes are using at the same time when calling ljca_transfer. So we need these two buffers.
--
Thanks
Ye Xiang
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
In reply to Ye XiangQuoted 177 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.
Signed-off-by Ye Xiang <[email protected]>Reviewed-by Sakari Ailus <[email protected]>Reviewed-by Linus Walleij <[email protected]>--- drivers/gpio/Kconfig | 12 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-ljca.c | 454 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 467 insertions(+) create mode 100644 drivers/gpio/gpio-ljca.cdrivers/gpio/Kconfig +12
-0@@ -1253,6 +1253,18 @@ config GPIO_KEMPLD This driver can also be built as a module. If so, the module will be called gpio-kempld. +config GPIO_LJCA + tristate "INTEL La Jolla Cove Adapter GPIO support" + depends on MFD_LJCA + select GPIOLIB_IRQCHIP + default MFD_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_LP3943drivers/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.odrivers/gpio/gpio-ljca.c new file +121
-0@@ -0,0 +1,454 @@ +// 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/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/mfd/ljca.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/types.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) +#define LJCA_GPIO_CONF_LEVEL FIELD_PREP(LJCA_GPIO_INT_TYPE, 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 platform_device *pdev; +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); +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->gpio_info->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->gpio_info->ljca,LJCA_GPIO_READ , packet, +struct_size (packet, item, packet->num), ljca_gpio->ibuf, &ibuf_len); +if (ret) + goto out_unlock; + +if (!ibuf_len || ack_packet->num != packet->num) { +dev_err (&ljca_gpio->pdev->dev,"failed gpio_id:%u %u" , gpio_id, ack_packet->num); + 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;
drivers/gpio/gpio-ljca.c line 131
Quoted 10 lines
drivers/gpio/gpio-ljca.c new file +10
-0+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->gpio_info->ljca,LJCA_GPIO_WRITE , packet, +struct_size (packet, item, packet->num),NULL ,NULL ); +mutex_unlock (&ljca_gpio->trans_lock);
Everywhere you have unusual coding pattern around return. There is almost always line break before return. Adjust to the kernel style.
Quoted 2 lines
drivers/gpio/gpio-ljca.c new file +2
-0+return ret; +}
(...)
drivers/gpio/gpio-ljca.c line 440
Quoted 7 lines
drivers/gpio/gpio-ljca.c new file +7
-0+ +#define LJCA_GPIO_DRV_NAME "ljca-gpio" +static const struct platform_device_id ljca_gpio_id[] = { + {LJCA_GPIO_DRV_NAME ,0 }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (platform, ljca_gpio_id);
ljca_gpio_id is unused (except module autoloading). How do you bind your devices?
drivers/gpio/gpio-ljca.c line 445
Quoted 5 lines
drivers/gpio/gpio-ljca.c new file +5
-0+ +static struct platform_driver ljca_gpio_driver = { + .driver.name =LJCA_GPIO_DRV_NAME , + .probe = ljca_gpio_probe, + .remove = ljca_gpio_remove,
Best regards,
Krzysztof
Re: [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver
Hi Krzysztof,
Thanks for your review.
Quoted 183 lines · Krzysztof Kozlowski
Quoted 182 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.
Signed-off-by Ye Xiang <[email protected]>Reviewed-by Sakari Ailus <[email protected]>Reviewed-by Linus Walleij <[email protected]>--- drivers/gpio/Kconfig | 12 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-ljca.c | 454 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 467 insertions(+) create mode 100644 drivers/gpio/gpio-ljca.cdrivers/gpio/Kconfig +12
-0@@ -1253,6 +1253,18 @@ config GPIO_KEMPLD This driver can also be built as a module. If so, the module will be called gpio-kempld. +config GPIO_LJCA + tristate "INTEL La Jolla Cove Adapter GPIO support" + depends on MFD_LJCA + select GPIOLIB_IRQCHIP + default MFD_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_LP3943drivers/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.odrivers/gpio/gpio-ljca.c new file +126
-0@@ -0,0 +1,454 @@ +// 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/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/mfd/ljca.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/types.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) +#define LJCA_GPIO_CONF_LEVEL FIELD_PREP(LJCA_GPIO_INT_TYPE, 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 platform_device *pdev; +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); +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->gpio_info->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->gpio_info->ljca,LJCA_GPIO_READ , packet, +struct_size (packet, item, packet->num), ljca_gpio->ibuf, &ibuf_len); +if (ret) + goto out_unlock; + +if (!ibuf_len || ack_packet->num != packet->num) { +dev_err (&ljca_gpio->pdev->dev,"failed gpio_id:%u %u" , gpio_id, ack_packet->num); + 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;
Quoted 8 lines
drivers/gpio/gpio-ljca.c line 131
Quoted 5 lines
drivers/gpio/gpio-ljca.c new file +5
-0+ packet->item[0 ].value = value &1 ; + + ret =ljca_transfer (ljca_gpio->gpio_info->ljca,LJCA_GPIO_WRITE , packet, +struct_size (packet, item, packet->num),NULL ,NULL ); +mutex_unlock (&ljca_gpio->trans_lock);Everywhere you have unusual coding pattern around return. There is almost always line break before return. Adjust to the kernel style.
Got it. Will add a blank line before return.
Quoted 6 lines
Quoted 3 lines
drivers/gpio/gpio-ljca.c new file +2
-0+return ret; +}(...)
Quoted 10 lines
drivers/gpio/gpio-ljca.c line 440
Quoted 7 lines
drivers/gpio/gpio-ljca.c new file +7
-0+ +#define LJCA_GPIO_DRV_NAME "ljca-gpio" +static const struct platform_device_id ljca_gpio_id[] = { + {LJCA_GPIO_DRV_NAME ,0 }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (platform, ljca_gpio_id);
ljca_gpio_idis unused (except module autoloading). How do you bind your devices?
driver.name = LJCA_GPIO_DRV_NAME, this driver name is used to bind with devices.
Quoted 7 lines
drivers/gpio/gpio-ljca.c line 445
Quoted 5 lines
drivers/gpio/gpio-ljca.c new file +5
-0+ +static struct platform_driver ljca_gpio_driver = { + .driver.name =LJCA_GPIO_DRV_NAME , + .probe = ljca_gpio_probe, + .remove = ljca_gpio_remove,
--
Thanks
Ye Xiang
PATCH v4 3/5 i2c: Add support for Intel LJCA USB I2C driver
In reply to Ye XiangThis 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 | 357 ++++++++++++++++++++++++++++++++++ 3 files changed, 369 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 MFD_LJCA + default MFD_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 +357 -0
357 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v4 4/5 spi: Add support for Intel LJCA USB SPI driver
In reply to Ye XiangThis 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 | 291 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 303 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 MFD_LJCA + default MFD_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 +291 -0
291 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v4 5/5 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 | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-usb-devices-ljca
Documentation/ABI/testing/sysfs-bus-usb-devices-ljca new file +22 -0
@@ -0,0 +1,22 @@ +What: /sys/bus/usb/.../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/.../cmd +Date: July 2023 +KernelVersion: 6.4 +Contact: Ye Xiang <[email protected]> +Description: + Commands supported by LJCA device. + When read, it will return valid commands. + When write with a command, it will execute the command. + Valid commands are [dfu, debug] + - Writing "dfu" to this file so as to put the device into + DFU mode so the firmware can be updated. + - Writing "debug" to this file to enable debug logging.
Signature · 1 line
2.34.1