Add Intel LJCA device driver
Subsystems (5)
v10 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.
---
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 | 242 +++++++------ drivers/i2c/busses/Kconfig | 11 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-ljca.c | 332 +++++++++++++++++ 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 | 817 ++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/ljca.h | 113 ++++++ 12 files changed, 1741 insertions(+), 103 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 v10 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 | 817 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/ljca.h | 113 ++++++ 4 files changed, 945 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 +817 -0
817 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
PATCH v10 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 | 332 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 344 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 +332 -0
332 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v10 2/4] i2c: Add support for Intel LJCA USB I2C driver
Hi,
thank you for your patches!
...
Quoted 15 lines
drivers/i2c/busses/i2c-ljca.c new file +15
-0+static int ljca_i2c_start (struct ljca_i2c_dev *ljca_i2c,u8 slave_addr, +enum ljca_xfer_type type) +{ +struct ljca_i2c_rw_packet *w_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->obuf; +struct ljca_i2c_rw_packet *r_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->ibuf; +s16 rp_len; +int ret; + + w_packet->id = ljca_i2c->i2c_info->id; + w_packet->len =cpu_to_le16 (sizeof (*w_packet->data)); + w_packet->data[0 ] = (slave_addr <<1 ) | type; + + ret = ljca_transfer(ljca_i2c->ljca, LJCA_I2C_START, w_packet,
drivers/i2c/busses/i2c-ljca.c line 102
Quoted 10 lines
drivers/i2c/busses/i2c-ljca.c new file +10
-0+struct_size (w_packet, data,1 ), r_packet, + LJCA_I2C_BUF_SIZE); +if (ret <0 || ret <sizeof (*r_packet)) +return ret <0 ? ret : -EIO ; + + rp_len =le16_to_cpu (r_packet->len); +if (rp_len <0 || r_packet->id != w_packet->id) { +dev_err (&ljca_i2c->adap.dev, +"i2c start failed len: %d id: %d %d\n" , + rp_len, r_packet->id, w_packet->id);
All dev_err look more like dev_dbg to me. They are not helpful for the regular user, I'd think.
Quoted 6 lines
drivers/i2c/busses/i2c-ljca.c new file +6
-0+return -EIO ; + } + +return 0 ; +} +
...
drivers/i2c/busses/i2c-ljca.c line 149
Quoted 11 lines
drivers/i2c/busses/i2c-ljca.c new file +11
-0+static int ljca_i2c_pure_read (struct ljca_i2c_dev *ljca_i2c,u8 *data,u8 len) +{ +struct ljca_i2c_rw_packet *w_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->obuf; +struct ljca_i2c_rw_packet *r_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->ibuf; +s16 rp_len; +int ret; + +if (len >LJCA_I2C_MAX_XFER_SIZE ) +return -EINVAL ;
You can remove this check. You already have a quirk structure, so the core will do it for you.
...
drivers/i2c/busses/i2c-ljca.c line 198
Quoted 11 lines
drivers/i2c/busses/i2c-ljca.c new file +11
-0+static int ljca_i2c_pure_write (struct ljca_i2c_dev *ljca_i2c,u8 *data,u8 len) +{ +struct ljca_i2c_rw_packet *w_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->obuf; +struct ljca_i2c_rw_packet *r_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->ibuf; +s16 rplen; +int ret; + +if (len >LJCA_I2C_MAX_XFER_SIZE ) +return -EINVAL ;
You can remove this check. You already have a quirk structure, so the core will do it for you.
...
drivers/i2c/busses/i2c-ljca.c line 265
Quoted 4 lines
drivers/i2c/busses/i2c-ljca.c new file +4
-0+static u32 ljca_i2c_func (struct i2c_adapter *adap) +{ +return I2C_FUNC_I2C |I2C_FUNC_SMBUS_EMUL ; +}
Have you successfully tried SMBUS_QUICK (e.g. with scanning a bus with 'i2cdetect')?
...
Quoted 6 lines
drivers/i2c/busses/i2c-ljca.c new file +6
-0+static int ljca_i2c_probe (struct auxiliary_device *auxdev, +const struct auxiliary_device_id *aux_dev_id) +{ +struct ljca_client *ljca =auxiliary_dev_to_ljca_client (auxdev); +struct ljca_i2c_dev *ljca_i2c; +int ret;
drivers/i2c/busses/i2c-ljca.c line 292
Quoted 10 lines
drivers/i2c/busses/i2c-ljca.c new file +10
-0+ + ljca_i2c =devm_kzalloc (&auxdev->dev,sizeof (*ljca_i2c),GFP_KERNEL ); +if (!ljca_i2c) +return -ENOMEM ; + + ljca_i2c->ljca = ljca; + ljca_i2c->i2c_info =dev_get_platdata (&auxdev->dev); + + ljca_i2c->adap.owner =THIS_MODULE ; + ljca_i2c->adap.class =I2C_CLASS_HWMON ;
Just to make sure: you want class based instantiation here because you have no other way of describing clients? I guess it makes sense for USB, just wanted to ask.
Other than that, it looks good!
All the best,
Wolfram
RE: [PATCH v10 2/4] i2c: Add support for Intel LJCA USB I2C driver
Hi Wolfram,
Thanks for your review.
Quoted 28 lines
From: Wolfram Sang <[email protected]>
Hi,
thank you for your patches!
...
Quoted 20 lines
drivers/i2c/busses/i2c-ljca.c new file +20
-0+static int ljca_i2c_start (struct ljca_i2c_dev *ljca_i2c,u8 slave_addr, +enum ljca_xfer_type type) +{ +struct ljca_i2c_rw_packet *w_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->obuf; +struct ljca_i2c_rw_packet *r_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->ibuf; +s16 rp_len; +int ret; + + w_packet->id = ljca_i2c->i2c_info->id; + w_packet->len =cpu_to_le16 (sizeof (*w_packet->data)); + w_packet->data[0 ] = (slave_addr <<1 ) | type; + + ret =ljca_transfer (ljca_i2c->ljca,LJCA_I2C_START , w_packet, +struct_size (w_packet, data,1 ), r_packet, +LJCA_I2C_BUF_SIZE ); +if (ret <0 || ret <sizeof (*r_packet)) +return ret <0 ? ret : -EIO ; +
Quoted 8 lines
drivers/i2c/busses/i2c-ljca.c line 102
Quoted 5 lines
drivers/i2c/busses/i2c-ljca.c new file +5
-0+ rp_len =le16_to_cpu (r_packet->len); +if (rp_len <0 || r_packet->id != w_packet->id) { +dev_err (&ljca_i2c->adap.dev, +"i2c start failed len: %d id: %d %d\n" , + rp_len, r_packet->id, w_packet->id);All
dev_errlook more likedev_dbgto me. They are not helpful for the regular user, I'd think.
Ack, thanks
Quoted 10 lines
Quoted 7 lines
drivers/i2c/busses/i2c-ljca.c new file +6
-0+return -EIO ; + } + +return 0 ; +} +...
Quoted 14 lines
drivers/i2c/busses/i2c-ljca.c line 149
Quoted 11 lines
drivers/i2c/busses/i2c-ljca.c new file +11
-0+static int ljca_i2c_pure_read (struct ljca_i2c_dev *ljca_i2c,u8 +*data,u8 len) { +struct ljca_i2c_rw_packet *w_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->obuf; +struct ljca_i2c_rw_packet *r_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->ibuf; +s16 rp_len; +int ret; + +if (len >LJCA_I2C_MAX_XFER_SIZE ) +return -EINVAL ;You can remove this check. You already have a quirk structure, so the core will do it for you.
Ack, thanks
Quoted 17 lines
...
drivers/i2c/busses/i2c-ljca.c line 198
Quoted 11 lines
drivers/i2c/busses/i2c-ljca.c new file +11
-0+static int ljca_i2c_pure_write (struct ljca_i2c_dev *ljca_i2c,u8 +*data,u8 len) { +struct ljca_i2c_rw_packet *w_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->obuf; +struct ljca_i2c_rw_packet *r_packet = + (struct ljca_i2c_rw_packet *)ljca_i2c->ibuf; +s16 rplen; +int ret; + +if (len >LJCA_I2C_MAX_XFER_SIZE ) +return -EINVAL ;You can remove this check. You already have a quirk structure, so the core will do it for you.
Ack, thanks
Quoted 8 lines
...
Review
Quoted 2 lines
(quoted diff) +2
-0+static u32 ljca_i2c_func(struct i2c_adapter *adap) { + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; }Have you successfully tried
SMBUS_QUICK(e.g. with scanning a bus with 'i2cdetect')?
Thanks, we just suppose it support SMBUS function after reviewed the core code, but never try the SMBUS functionality, so I decide to remove the I2C_FUNC_SMBUS_EMUL support currently and after we verify it working correctly, we will add it in another patch.
Thanks
Quoted 13 lines
...
Quoted 10 lines
drivers/i2c/busses/i2c-ljca.c new file +10
-0+static int ljca_i2c_probe (struct auxiliary_device *auxdev, +const struct auxiliary_device_id *aux_dev_id) { +struct ljca_client *ljca =auxiliary_dev_to_ljca_client (auxdev); +struct ljca_i2c_dev *ljca_i2c; +int ret; + + ljca_i2c =devm_kzalloc (&auxdev->dev,sizeof (*ljca_i2c),GFP_KERNEL ); +if (!ljca_i2c) +return -ENOMEM ; +
Quoted 8 lines
drivers/i2c/busses/i2c-ljca.c line 292
Quoted 5 lines
drivers/i2c/busses/i2c-ljca.c new file +5
-0+ ljca_i2c->ljca = ljca; + ljca_i2c->i2c_info =dev_get_platdata (&auxdev->dev); + + ljca_i2c->adap.owner =THIS_MODULE ; + ljca_i2c->adap.class =I2C_CLASS_HWMON ;Just to make sure: you want class based instantiation here because you have no other way of describing clients?
Actually it's about the method 3 of instantiate I2C devices described in
https://www.kernel.org/doc/Documentation/i2c/instantiating-devices
and it's not preferred wherever possible. And below are the definitions about i2c adapter class, we only have I2C_CLASS_HWMON class tested, so just put it here.
/* i2c adapter classes (bitmask) */
#define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */ #define I2C_CLASS_DDC (1<<3) /* DDC bus on graphics adapters */ #define I2C_CLASS_SPD (1<<7) /* Memory modules */
/* Warn users that the adapter doesn't support classes anymore */
#define I2C_CLASS_DEPRECATED (1<<8)
BR,
Wentong
Quoted 8 lines
I guess it makes sense for USB, just wanted to
ask.Other than that, it looks good!
All the best,
Wolfram
Re: [PATCH v10 2/4] i2c: Add support for Intel LJCA USB I2C driver
Quoted 6 lines
Actually it's about the method 3 of instantiate I2C devices described in
https://www.kernel.org/doc/Documentation/i2c/instantiating-devices
and it's not preferred wherever possible. And below are the definitions about i2c adapter class, we only haveI2C_CLASS_HWMONclass tested, so just put it here.
Yeah, as I mentioned before, it may make sense for a USB based device. I just wanted to make sure you did it intentionally. Keep it.
RE: [PATCH v10 2/4] i2c: Add support for Intel LJCA USB I2C driver
Quoted 5 lines
From: Wolfram Sang <[email protected]>
Quoted 8 lines
Quoted 5 lines
Actually it's about the method 3 of instantiate I2C devices described in https://www.kernel.org/doc/Documentation/i2c/instantiating-devices
and it's not preferred wherever possible. And below are the definitions about i2c adapter class, we only haveI2C_CLASS_HWMONclass tested, so just put it here.Yeah, as I mentioned before, it may make sense for a USB based device. I just wanted to make sure you did it intentionally. Keep it.
Thanks, please help review v11 patch set as well which is to address your comments.
BR,
Wentong
PATCH v10 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 v10 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 | 242 +++++++++++++++++++++++++++-------------------- 2 files changed, 143 insertions(+), 103 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 +141 -101
469 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v10 4/4] gpio: update Intel LJCA USB GPIO driver
Quoted 9 lines · Wentong Wu
This 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.
Signed-off-by Wentong Wu <[email protected]>Reviewed-by Sakari Ailus <[email protected]>Acked-by Linus Walleij <[email protected]>---