Add Intel LJCA device driver
Subsystems (5)
v15 cover Add Intel LJCA device driver
Add driver for Intel La Jolla Cove Adapter (LJCA) device. This IO-expander adds additional functions to the host system such as GPIO, I2C and SPI with USB host interface. We add 4 drivers to support this device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.
---
v15:
- enhance disconnect() of usb-ljca driver
- change memchr to strchr in ljca_match_device_ids() of usb-ljca driver
v14:
- fix build error: implicit declaration of function 'acpi_dev_clear_dependencies'
v13:
- make ljca-usb more robust with the help of Hans de Goede
- call acpi_dev_clear_dependencies() to mark _DEP ACPI dependencies on the I2C controller as satisfied, and patch is from Hans de Goede
v12:
- switch dev_err to dev_dbg for i2c-ljca driver
- avoid err printing because of calling usb_kill_urb when attempts to resubmit the rx urb
v11:
- switch dev_err to dev_dbg for i2c-ljca driver
- remove message length check because of defined quirk structure
- remove I2C_FUNC_SMBUS_EMUL support
v10:
- remove ljca_i2c_format_slave_addr
- remove memset before write write w_packet
- make ljca_i2c_stop void and print err message in case failure
- use dev_err_probe in ljca_i2c_probe function
v9:
- overhaul usb-ljca driver to make it more structured and easy understand
- fix memory leak issue for usb-ljca driver
- add spinlock to protect tx_buf and ex_buf
- change exported APIs for usb-ljca driver
- unify prefix for structures and functions for i2c-ljca driver
- unify prefix for structures and functions for spi-ljca driver
- unify prefix for structures and functions for gpio-ljca driver
- update gpio-ljca, i2c-ljca and spi-ljca drivers according to usb-ljca's changes
Wentong Wu (4):
usb: Add support for Intel LJCA device
i2c: Add support for Intel LJCA USB I2C driver
spi: Add support for Intel LJCA USB SPI driver
gpio: update Intel LJCA USB GPIO driver
drivers/gpio/Kconfig | 4 +- drivers/gpio/gpio-ljca.c | 246 +++++++----- drivers/i2c/busses/Kconfig | 11 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-ljca.c | 342 +++++++++++++++++ drivers/spi/Kconfig | 11 + drivers/spi/Makefile | 1 + drivers/spi/spi-ljca.c | 297 +++++++++++++++ drivers/usb/misc/Kconfig | 14 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/usb-ljca.c | 852 ++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/ljca.h | 113 ++++++ 12 files changed, 1788 insertions(+), 105 deletions(-) create mode 100644 drivers/i2c/busses/i2c-ljca.c create mode 100644 drivers/spi/spi-ljca.c create mode 100644 drivers/usb/misc/usb-ljca.c create mode 100644 include/linux/usb/ljca.h
Signature · 1 line
2.7.4
PATCH v15 1/4 usb: Add support for Intel LJCA device
Implements the USB part of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA).
The communication between the various LJCA module drivers and the hardware will be muxed/demuxed by this driver. Three modules ( I2C, GPIO, and SPI) are supported currently.
Each sub-module of LJCA device is identified by type field within the LJCA message header.
The sub-modules of LJCA can use ljca_transfer() to issue a transfer between host and hardware. And ljca_register_event_cb is exported to LJCA sub-module drivers for hardware event subscription.
The minimum code in ASL that covers this board is
Scope (\_SB.PCI0.DWC3.RHUB.HS01)
{
Device (GPIO)
{
Name (_ADR, Zero)
Name (_STA, 0x0F)
}
Device (I2C)
{
Name (_ADR, One)
Name (_STA, 0x0F)
}
Device (SPI)
{
Name (_ADR, 0x02)
Name (_STA, 0x0F)
}
}--- drivers/usb/misc/Kconfig | 14 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/usb-ljca.c | 852 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/ljca.h | 113 ++++++ 4 files changed, 980 insertions(+) create mode 100644 drivers/usb/misc/usb-ljca.c create mode 100644 include/linux/usb/ljca.h
drivers/usb/misc/Kconfig +14 -0
@@ -165,6 +165,20 @@ config APPLE_MFI_FASTCHARGE It is safe to say M here. +config USB_LJCA + tristate "Intel La Jolla Cove Adapter support" + select AUXILIARY_BUS + depends on USB + depends on ACPI || COMPILE_TEST + help + This adds support for Intel La Jolla Cove USB-I2C/SPI/GPIO + Master Adapter (LJCA). Additional drivers such as I2C_LJCA, + GPIO_LJCA and SPI_LJCA must be enabled in order to use the + functionality of the device. + + This driver can also be built as a module. If so, the module + will be called usb-ljca. + source "drivers/usb/misc/sisusbvga/Kconfig" config USB_LD
drivers/usb/misc/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_USB_EMI26) += emi26.o obj-$(CONFIG_USB_EMI62) += emi62.o obj-$(CONFIG_USB_EZUSB_FX2) += ezusb.o obj-$(CONFIG_APPLE_MFI_FASTCHARGE) += apple-mfi-fastcharge.o +obj-$(CONFIG_USB_LJCA) += usb-ljca.o obj-$(CONFIG_USB_IDMOUSE) += idmouse.o obj-$(CONFIG_USB_IOWARRIOR) += iowarrior.o obj-$(CONFIG_USB_ISIGHTFW) += isight_firmware.o
drivers/usb/misc/usb-ljca.c new file +852 -0
852 lines not on this page · raw message
include/linux/usb/ljca.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.7.4
Greg KH
maintainerRe: [PATCH v15 1/4] usb: Add support for Intel LJCA device
drivers/usb/misc/usb-ljca.c line 95
Quoted 7 lines · Wentong Wu
drivers/usb/misc/usb-ljca.c new file +7
-0+struct ljca_bank_descriptor { +u8 bank_id; +u8 pin_num; + +/* 1 bit for each gpio, 1 means valid */ +u32 valid_pins; +} __packed;
This is an unaligned access, do you mean to have that?
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+struct ljca_adapter { +struct usb_interface *intf; +struct usb_device *usb_dev; +struct device *dev; + +unsigned int rx_pipe;
drivers/usb/misc/usb-ljca.c line 118
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+unsigned int tx_pipe; + +/* urb for recv */ +struct urb *rx_urb; +/* buffer for recv */ +void *rx_buf; +unsigned int rx_len; + +/* external buffer for recv */ +void *ex_buf;
Shouldn't buffers be u8*?
drivers/usb/misc/usb-ljca.c line 152
Quoted 8 lines
drivers/usb/misc/usb-ljca.c new file +8
-0+static void ljca_handle_event (struct ljca_adapter *adap, +struct ljca_msg *header) +{ +struct ljca_client *client; + +list_for_each_entry (client, &adap->client_list, link) { +/* +* FIXME: currently only GPIO register event callback.
When is this fixme going to be addressed?
Quoted 17 lines
drivers/usb/misc/usb-ljca.c new file +17
-0+* firmware message structure should include id when +* multiple same type clients register event callback. +*/ +if (client->type == header->type) { +unsigned long flags; + +spin_lock_irqsave (&client->event_cb_lock, flags); + client->event_cb (client->context, header->cmd, + header->data, header->len); +spin_unlock_irqrestore (&client->event_cb_lock, flags); + +break ; + } + } +} + +/* process command ack */
drivers/usb/misc/usb-ljca.c line 179
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+static void ljca_handle_cmd_ack (struct ljca_adapter *adap, +struct ljca_msg *header) +{ +struct ljca_msg *tx_header = adap->tx_buf; +unsigned int actual_len =0 ; +unsigned int ibuf_len; +unsigned long flags; +void *ibuf; + +spin_lock_irqsave (&adap->lock, flags);
Why not use the functionality in cleanup.h for this lock? Makes this function much simpler.
drivers/usb/misc/usb-ljca.c line 183
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +4
-0+ +if (tx_header->type != header->type || tx_header->cmd != header->cmd) { +spin_unlock_irqrestore (&adap->lock, flags); +
No need for a blank line.
And how can these things happen? No need to return an error if this is the case?
drivers/usb/misc/usb-ljca.c line 245
Quoted 3 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+static int ljca_send (struct ljca_adapter *adap,u8 type,u8 cmd, +const void *obuf,unsigned int obuf_len,void *ibuf, +unsigned int ibuf_len,bool ack,unsigned long timeout)
That's a lot of function parameters, whyh so many?
And why void *? That should never be used in an internal function where you know the real type.
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+{ +unsigned int msg_len =sizeof (struct ljca_msg ) + obuf_len; +struct ljca_msg *header = adap->tx_buf; +unsigned long flags; +unsigned int actual; +int ret =0 ;
drivers/usb/misc/usb-ljca.c line 261
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ +if (adap->disconnect) +return -ENODEV ; + +if (msg_len > adap->tx_buf_len) +return -EINVAL ; + +mutex_lock (&adap->mutex); + +spin_lock_irqsave (&adap->lock, flags);
2 locks? Why 2 locks for the same structure?
Quoted 11 lines
drivers/usb/misc/usb-ljca.c new file +11
-0+ + header->type = type; + header->cmd = cmd; + header->len = obuf_len; +if (obuf) +memcpy (header->data, obuf, obuf_len); + + header->flags =LJCA_CMPL_FLAG | (ack ?LJCA_ACK_FLAG :0 ); + + adap->ex_buf = ibuf; + adap->ex_buf_len = ibuf_len;
drivers/usb/misc/usb-ljca.c line 282
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ adap->actual_length =0 ; + +spin_unlock_irqrestore (&adap->lock, flags); + +reinit_completion (&adap->cmd_completion); + +usb_autopm_get_interface (adap->intf); + + ret =usb_bulk_msg (adap->usb_dev, adap->tx_pipe, header, + msg_len, &actual,LJCA_WRITE_TIMEOUT_MS );
This function is slow. Really slow. You drop the spinlock which is good, but the mutex is still held. Does this call have to be synchronous?
Quoted 11 lines
drivers/usb/misc/usb-ljca.c new file +11
-0+ +usb_autopm_put_interface (adap->intf); + +if (!ret && ack) { + ret =wait_for_completion_timeout (&adap->cmd_completion, + timeout); +if (ret <0 ) { + goto out; + }if (!ret) { + ret = -ETIMEDOUT ; + goto out;
drivers/usb/misc/usb-ljca.c line 303
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ } + } + ret = adap->actual_length; + +out: +spin_lock_irqsave (&adap->lock, flags); + adap->ex_buf =NULL ; + adap->ex_buf_len =0 ; + +memset (header,0 ,sizeof (*header));
Why?
drivers/usb/misc/usb-ljca.c line 311
Quoted 8 lines
drivers/usb/misc/usb-ljca.c new file +8
-0+spin_unlock_irqrestore (&adap->lock, flags); + +mutex_unlock (&adap->mutex); + +return ret; +} + +int ljca_transfer(struct ljca_client *client, u8 cmd, const void *obuf,
Again, drop all void * please, use real types in your apis.
drivers/usb/misc/usb-ljca.c line 488
Quoted 7 lines
drivers/usb/misc/usb-ljca.c new file +7
-0+#else +static void ljca_auxdev_acpi_bind (struct ljca_adapter *adap, +struct auxiliary_device *auxdev, +u64 adr,u8 id) +{ +} +#endif
Can't this go in a .h file? #ifdef in .c files are frowned apon.
Quoted 9 lines
drivers/usb/misc/usb-ljca.c new file +9
-0+static int ljca_enumerate_clients (struct ljca_adapter *adap) +{ +int ret; + + ret =ljca_reset_handshake (adap); +if (ret) +return ret; + + ret =ljca_enumerate_gpio (adap);
drivers/usb/misc/usb-ljca.c line 698
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+if (ret) +dev_warn (adap->dev,"enumerate GPIO error\n" ); + + ret =ljca_enumerate_i2c (adap); +if (ret) +dev_warn (adap->dev,"enumerate I2C error\n" ); + + ret =ljca_enumerate_spi (adap); +if (ret) +dev_warn (adap->dev,"enumerate SPI error\n" );
You warn about these things, but keep on saying the code is working properly with a return of:
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;
That's not good. Why not unwind properly and handle the error?
Quoted 54 lines
include/linux/usb/ljca.h new file +51
-0@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2023, Intel Corporation. All rights reserved. +*/ +#ifndef _LINUX_USB_LJCA_H_ +#define _LINUX_USB_LJCA_H_ + +#include <linux/auxiliary_bus.h> +#include <linux/list.h> +#include <linux/spinlock.h> +#include <linux/types.h> + +#define LJCA_MAX_GPIO_NUM 64 + +#define auxiliary_dev_to_ljca_client (auxiliary_dev) \ + container_of(auxiliary_dev, struct ljca_client, auxdev) + +struct ljca_adapter ; + +/** +* typedef ljca_event_cb_t - event callback function signature +* +* @context: the execution context of who registered this callback +* @cmd: the command from device for this event +* @evt_data: the event data payload +* @len: the event data payload length +* +* The callback function is called in interrupt context and the data payload is +* only valid during the call. If the user needs later access of the data, it +* must copy it. +*/ +typedef void (*ljca_event_cb_t )(void *context,u8 cmd,const void *evt_data,int len); + +struct ljca_client { +u8 type; +u8 id; +struct list_head link; +struct auxiliary_device auxdev; +struct ljca_adapter *adapter; + +void *context; +ljca_event_cb_t event_cb; +/* lock to protect event_cb */ +spinlock_t event_cb_lock; +}; + +struct ljca_gpio_info { +unsigned int num; + DECLARE_BITMAP(valid_pin_map, LJCA_MAX_GPIO_NUM); +}; +
include/linux/usb/ljca.h line 61
Quoted 10 lines
include/linux/usb/ljca.h new file +10
-0+struct ljca_i2c_info { +u8 id; +u8 capacity; +u8 intr_pin; +}; + +struct ljca_spi_info { +u8 id; +u8 capacity; +};
No documentation for these other public structures?
thanks,
greg k-h
RE: [PATCH v15 1/4] usb: Add support for Intel LJCA device
Hi Greg,
Thanks for your review
Quoted 11 lines
From: Greg KH Friday, September 8, 2023 9:39 PM
drivers/usb/misc/usb-ljca.c line 95
Quoted 7 lines
drivers/usb/misc/usb-ljca.c new file +7
-0+struct ljca_bank_descriptor { +u8 bank_id; +u8 pin_num; + +/* 1 bit for each gpio, 1 means valid */ +u32 valid_pins; +} __packed;This is an unaligned access, do you mean to have that?
Yes, this is defined by the firmware, we have to keep the same structure with firmware.
Quoted 11 lines
Quoted 11 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+struct ljca_adapter { +struct usb_interface *intf; +struct usb_device *usb_dev; +struct device *dev; + +unsigned int rx_pipe; +unsigned int tx_pipe; + +/* urb for recv */ +struct urb *rx_urb;
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 118
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+/* buffer for recv */ +void *rx_buf; +unsigned int rx_len; + +/* external buffer for recv */ +void *ex_buf;Shouldn't buffers be u8*?
It can be u8 *, but it can avoid many cast if with void *.
Quoted 11 lines
drivers/usb/misc/usb-ljca.c line 152
Quoted 9 lines
drivers/usb/misc/usb-ljca.c new file +8
-0+static void ljca_handle_event (struct ljca_adapter *adap, +struct ljca_msg *header) +{ +struct ljca_client *client; + +list_for_each_entry (client, &adap->client_list, link) { +/* +* FIXME: currently only GPIO register event callback. When is this fixme going to be addressed?
Actually this is following firmware, and it takes some time to fix firmware issue, but currently it doesn't impact the functionality.
Quoted 23 lines
Quoted 23 lines
drivers/usb/misc/usb-ljca.c new file +22
-0+* firmware message structure should include id when +* multiple same type clients register event callback. +*/ +if (client->type == header->type) { +unsigned long flags; + +spin_lock_irqsave (&client->event_cb_lock, flags); + client->event_cb (client->context, header->cmd, + header->data, header->len); +spin_unlock_irqrestore (&client->event_cb_lock, flags); + +break ; + } + } +} + +/* process command ack */ +static void ljca_handle_cmd_ack (struct ljca_adapter *adap, +struct ljca_msg *header) +{ +struct ljca_msg *tx_header = adap->tx_buf; +unsigned int actual_len =0 ;
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 179
Quoted 5 lines
drivers/usb/misc/usb-ljca.c new file +5
-0+unsigned int ibuf_len; +unsigned long flags; +void *ibuf; + +spin_lock_irqsave (&adap->lock, flags);Why not use the functionality in
cleanup.hfor this lock? Makes this function much simpler.
Sorry, I'm not familiar with this cleanup.h, and also I don't get how to simplify this function after review the cleanup.h, could you please help? Thanks
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ + if (tx_header->type != header->type || tx_header->cmd != header->cmd){
Review
Quoted 2 lines
(quoted diff) +2
-0+ spin_unlock_irqrestore(&adap->lock, flags); +No need for a blank line.
Ack, thanks
Quoted 2 lines
And how can these things happen? No need to return an error if this is the case?
In case something wrong happens in firmware, and yes, I will add an error message here, thanks.
Quoted 6 lines
drivers/usb/misc/usb-ljca.c line 245
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+static int ljca_send (struct ljca_adapter *adap,u8 type,u8 cmd, +const void *obuf,unsigned int obuf_len,void *ibuf, +unsigned int ibuf_len,bool ack,unsigned long timeout)That's a lot of function parameters, whyh so many?
This function sends command to firmware. The command is composed of the command header And data buffer which comes from the function parameters.
Also some commands have response, and we need external buffer and length to copy to
Quoted 3 lines
And why void *? That should never be used in an internal function where you know the real type.
Ack, I will change them to real type for the internal function, thanks
Quoted 11 lines
Quoted 11 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+{ +unsigned int msg_len =sizeof (struct ljca_msg ) + obuf_len; +struct ljca_msg *header = adap->tx_buf; +unsigned long flags; +unsigned int actual; +int ret =0 ; + +if (adap->disconnect) +return -ENODEV ; +
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 261
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+if (msg_len > adap->tx_buf_len) +return -EINVAL ; + +mutex_lock (&adap->mutex); + +spin_lock_irqsave (&adap->lock, flags);2 locks? Why 2 locks for the same structure?
The mutex is to avoid command download concurrently.
The spinlock is to protect tx_buf and ex_buf, which may be accessed by tx thread and rx thread at the same time.
Quoted 17 lines
Quoted 17 lines
drivers/usb/misc/usb-ljca.c new file +16
-0+ + header->type = type; + header->cmd = cmd; + header->len = obuf_len; +if (obuf) +memcpy (header->data, obuf, obuf_len); + + header->flags =LJCA_CMPL_FLAG | (ack ?LJCA_ACK_FLAG :0 ); + + adap->ex_buf = ibuf; + adap->ex_buf_len = ibuf_len; + adap->actual_length =0 ; + +spin_unlock_irqrestore (&adap->lock, flags); + +reinit_completion (&adap->cmd_completion);
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 282
Quoted 5 lines
drivers/usb/misc/usb-ljca.c new file +5
-0+ +usb_autopm_get_interface (adap->intf); + + ret =usb_bulk_msg (adap->usb_dev, adap->tx_pipe, header, + msg_len, &actual,LJCA_WRITE_TIMEOUT_MS );This function is slow. Really slow. You drop the spinlock which is good, but the mutex is still held. Does this call have to be synchronous?
As I said above, the mutex is to avoid more commands downloading to firmware before the current one is completed.
Quoted 16 lines
Quoted 16 lines
drivers/usb/misc/usb-ljca.c new file +15
-0+ +usb_autopm_put_interface (adap->intf); + +if (!ret && ack) { + ret =wait_for_completion_timeout (&adap->cmd_completion, + timeout); +if (ret <0 ) { + goto out; + }if (!ret) { + ret = -ETIMEDOUT ; + goto out; + } + } + ret = adap->actual_length; +
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 303
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+out: +spin_lock_irqsave (&adap->lock, flags); + adap->ex_buf =NULL ; + adap->ex_buf_len =0 ; + +memset (header,0 ,sizeof (*header));Why?
In ljca_handle_cmd_ack(), we use the tx header to compare the received header. If we receive command ack after timeout(though most likely it won't happen), I want it just return, so I clear the tx header here.
Quoted 12 lines
drivers/usb/misc/usb-ljca.c
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +9
-0+spin_unlock_irqrestore (&adap->lock, flags); + +mutex_unlock (&adap->mutex); + +return ret; +} + +int ljca_transfer(struct ljca_client *client, u8 cmd, const void +*obuf,Again, drop all void * please, use real types in your apis.
This is the exposed API, usually it's void *. I can change it to real type, but is there any rule when to use void * and when to use real type?
Quoted 10 lines
drivers/usb/misc/usb-ljca.c line 488
Quoted 8 lines
drivers/usb/misc/usb-ljca.c new file +7
-0+#else +static void ljca_auxdev_acpi_bind (struct ljca_adapter *adap, +struct auxiliary_device *auxdev, +u64 adr,u8 id) +{ +} +#endif Can't this go in a .h file? #ifdef in .c files are frowned apon.
Ack, but I will remove the #ifdef because it ready has 'depends on ACPI' in Kconfig, Thanks.
Quoted 23 lines
Quoted 9 lines
drivers/usb/misc/usb-ljca.c new file +8
-0+static int ljca_enumerate_clients (struct ljca_adapter *adap) { +int ret; + + ret =ljca_reset_handshake (adap); +if (ret) +return ret; + + ret =ljca_enumerate_gpio (adap);drivers/usb/misc/usb-ljca.c line 698
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+if (ret) +dev_warn (adap->dev,"enumerate GPIO error\n" ); + + ret =ljca_enumerate_i2c (adap); +if (ret) +dev_warn (adap->dev,"enumerate I2C error\n" ); + + ret =ljca_enumerate_spi (adap); +if (ret) +dev_warn (adap->dev,"enumerate SPI error\n" );You warn about these things, but keep on saying the code is working properly with a return of:
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;That's not good. Why not unwind properly and handle the error?
This is to be compatible with old version FW which does not support full USB2xxx functions, so just warn here and keep the code going. Thanks
Quoted 61 lines
Quoted 61 lines
include/linux/usb/ljca.h new file +57
-0@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2023, Intel Corporation. All rights reserved. +*/ +#ifndef _LINUX_USB_LJCA_H_ +#define _LINUX_USB_LJCA_H_ + +#include <linux/auxiliary_bus.h> +#include <linux/list.h> +#include <linux/spinlock.h> +#include <linux/types.h> + +#define LJCA_MAX_GPIO_NUM 64 + +#define auxiliary_dev_to_ljca_client(auxiliary_dev) \ + container_of(auxiliary_dev, struct ljca_client, auxdev) + +struct ljca_adapter; + +/** + * typedef ljca_event_cb_t - event callback function signature + * + * @context: the execution context of who registered this callback + * @cmd: the command from device for this event + * @evt_data: the event data payload + * @len: the event data payload length + * + * The callback function is called in interrupt context and the data +payload is + * only valid during the call. If the user needs later access of the +data, it + * must copy it. + */ +typedef void (*ljca_event_cb_t)(void *context, u8 cmd, const void +*evt_data, int len); + +struct ljca_client { + u8 type; + u8 id; + struct list_head link; + struct auxiliary_device auxdev; + struct ljca_adapter *adapter; + + void *context; + ljca_event_cb_t event_cb; + /* lock to protect event_cb */ + spinlock_t event_cb_lock; +}; + +struct ljca_gpio_info { + unsigned int num; + DECLARE_BITMAP(valid_pin_map, LJCA_MAX_GPIO_NUM); }; + +struct ljca_i2c_info { + u8 id; + u8 capacity; + u8 intr_pin;
Quoted 8 lines
include/linux/usb/ljca.h line 61
Quoted 6 lines
include/linux/usb/ljca.h new file +6
-0+}; + +struct ljca_spi_info { +u8 id; +u8 capacity; +};No documentation for these other public structures?
Ack, I will add doc for these public structures in next version. Thanks
Thanks
Wentong
Quoted 4 lines
thanks,
greg k-h
RE: [PATCH v15 1/4] usb: Add support for Intel LJCA device
In reply to Greg KHHi Greg,
Thanks for your review
Quoted 12 lines
From: Greg KH <[email protected]>
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+struct ljca_adapter { +struct usb_interface *intf; +struct usb_device *usb_dev; +struct device *dev; + +unsigned int rx_pipe; +unsigned int tx_pipe; + +/* urb for recv */ +struct urb *rx_urb;
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 118
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+/* buffer for recv */ +void *rx_buf; +unsigned int rx_len; + +/* external buffer for recv */ +void *ex_buf;Shouldn't buffers be u8*?
Ack, this has been fixed in my local version.
Quoted 16 lines
drivers/usb/misc/usb-ljca.c line 179
Quoted 13 lines
drivers/usb/misc/usb-ljca.c new file +12
-0+ +/* process command ack */ +static void ljca_handle_cmd_ack (struct ljca_adapter *adap, +struct ljca_msg *header) +{ +struct ljca_msg *tx_header = adap->tx_buf; +unsigned int actual_len =0 ; +unsigned int ibuf_len; +unsigned long flags; +void *ibuf; + +spin_lock_irqsave (&adap->lock, flags);Why not use the functionality in
cleanup.hfor this lock? Makes this function much simpler.
Ack, I understand the cleanup.h now, and use the functionality as much as I can.
Quoted 10 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ + if (tx_header->type != header->type || tx_header->cmd != header->cmd){
Review
Quoted 2 lines
(quoted diff) +2
-0+ spin_unlock_irqrestore(&adap->lock, flags); +No need for a blank line.
And how can these things happen? No need to return an error if this is the case?
Ack, removed the blank line and added error print here.
Quoted 9 lines
drivers/usb/misc/usb-ljca.c line 245
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+static int ljca_send (struct ljca_adapter *adap,u8 type,u8 cmd, +const void *obuf,unsigned int obuf_len,void *ibuf, +unsigned int ibuf_len,bool ack,unsigned long timeout)That's a lot of function parameters, whyh so many?
And why void *? That should never be used in an internal function where you know the real type.
Ack, have switched void * to real type
Quoted 12 lines
drivers/usb/misc/usb-ljca.c line 488
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +8
-0+{ +#else +static void ljca_auxdev_acpi_bind (struct ljca_adapter *adap, +struct auxiliary_device *auxdev, +u64 adr,u8 id) +{ +} +#endif Can't this go in a .h file? #ifdef in .c files are frowned apon.
Ack, this has been removed
Quoted 25 lines
Quoted 25 lines
include/linux/usb/ljca.h new file +22
-0+ +struct ljca_client { +u8 type; +u8 id; +struct list_head link; +struct auxiliary_device auxdev; +struct ljca_adapter *adapter; + +void *context; +ljca_event_cb_t event_cb; +/* lock to protect event_cb */ +spinlock_t event_cb_lock; +}; + +struct ljca_gpio_info { +unsigned int num; + DECLARE_BITMAP(valid_pin_map, LJCA_MAX_GPIO_NUM); }; + +struct ljca_i2c_info { +u8 id; +u8 capacity; +u8 intr_pin;
Quoted 8 lines
include/linux/usb/ljca.h line 61
Quoted 6 lines
include/linux/usb/ljca.h new file +6
-0+}; + +struct ljca_spi_info { +u8 id; +u8 capacity; +};No documentation for these other public structures?
Ack, This has been addressed. If no more comments, I will send out v16 for review.
Thanks
Wentong
Quoted 4 lines
thanks,
greg k-h
PATCH v15 2/4 i2c: Add support for Intel LJCA USB I2C driver
In reply to Wentong WuImplements 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 | 342 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 354 insertions(+) create mode 100644 drivers/i2c/busses/i2c-ljca.c
drivers/i2c/busses/Kconfig +11 -0
@@ -1264,6 +1264,17 @@ config I2C_DLN2 This driver can also be built as a module. If so, the module will be called i2c-dln2. +config I2C_LJCA + tristate "I2C functionality of Intel La Jolla Cove Adapter" + depends on USB_LJCA + default USB_LJCA + help + If you say yes to this option, I2C functionality support of Intel + La Jolla Cove Adapter (LJCA) will be included. + + This driver can also be built as a module. If so, the module + will be called i2c-ljca. + config I2C_CP2615 tristate "Silicon Labs CP2615 USB sound card and I2C adapter" depends on USB
drivers/i2c/busses/Makefile +1 -0
@@ -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 +342 -0
342 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v15 3/4 spi: Add support for Intel LJCA USB SPI driver
In reply to Wentong WuImplements 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 | 297 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 309 insertions(+) create mode 100644 drivers/spi/spi-ljca.c
drivers/spi/Kconfig +11 -0
@@ -583,6 +583,17 @@ config SPI_FSL_ESPI From MPC8536, 85xx platform uses the controller, and all P10xx, P20xx, P30xx,P40xx, P50xx uses this controller. +config SPI_LJCA + tristate "Intel La Jolla Cove Adapter SPI support" + depends on USB_LJCA + default USB_LJCA + help + Select this option to enable SPI driver for the Intel + La Jolla Cove Adapter (LJCA) board. + + This driver can also be built as a module. If so, the module + will be called spi-ljca. + config SPI_MESON_SPICC tristate "Amlogic Meson SPICC controller" depends on COMMON_CLK
drivers/spi/Makefile +1 -0
@@ -70,6 +70,7 @@ obj-$(CONFIG_SPI_INTEL_PCI) += spi-intel-pci.o obj-$(CONFIG_SPI_INTEL_PLATFORM) += spi-intel-platform.o obj-$(CONFIG_SPI_LANTIQ_SSC) += spi-lantiq-ssc.o obj-$(CONFIG_SPI_JCORE) += spi-jcore.o +obj-$(CONFIG_SPI_LJCA) += spi-ljca.o obj-$(CONFIG_SPI_LM70_LLP) += spi-lm70llp.o obj-$(CONFIG_SPI_LP8841_RTC) += spi-lp8841-rtc.o obj-$(CONFIG_SPI_MESON_SPICC) += spi-meson-spicc.o
drivers/spi/spi-ljca.c new file +297 -0
297 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v15 4/4 gpio: update Intel LJCA USB GPIO driver
In reply to Wentong WuThis driver communicate with LJCA GPIO module with specific protocol through interfaces exported by LJCA USB driver. Update the driver according to LJCA USB driver's changes.
--- drivers/gpio/Kconfig | 4 +- drivers/gpio/gpio-ljca.c | 246 +++++++++++++++++++++++++++-------------------- 2 files changed, 145 insertions(+), 105 deletions(-)
drivers/gpio/Kconfig +2 -2
@@ -1294,9 +1294,9 @@ config GPIO_KEMPLD config GPIO_LJCA tristate "INTEL La Jolla Cove Adapter GPIO support" - depends on MFD_LJCA + depends on USB_LJCA select GPIOLIB_IRQCHIP - default MFD_LJCA + default USB_LJCA help Select this option to enable GPIO driver for the INTEL La Jolla Cove Adapter (LJCA) board.
drivers/gpio/gpio-ljca.c +143 -103
473 lines not on this page · raw message
Signature · 1 line
2.7.4