Skip to contentSkip to conversation

Add Intel LJCA device driver

PATCH Superseded Ye Xiang 3 participants 9 messages Feb 25, 2023 – Mar 6, 2023

Subsystems (5)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Ye Xiang

author
#0 lore raw

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

---
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/mfd/Kconfig                           |  13 +
 drivers/mfd/Makefile                          |   1 +
 drivers/mfd/ljca.c                            | 969 ++++++++++++++++++
 drivers/spi/Kconfig                           |  11 +
 drivers/spi/Makefile                          |   1 +
 drivers/spi/spi-ljca.c                        | 291 ++++++
 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/mfd/ljca.c
 create mode 100644 drivers/spi/spi-ljca.c
 create mode 100644 include/linux/mfd/ljca.h
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 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/mfd/Kconfig      |  13 +
 drivers/mfd/Makefile     |   1 +
 drivers/mfd/ljca.c       | 969 +++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/ljca.h |  95 ++++
 4 files changed, 1078 insertions(+)
 create mode 100644 drivers/mfd/ljca.c
 create mode 100644 include/linux/mfd/ljca.h
drivers/mfd/Kconfig +13 -0
index 30db49f31866..f74df74d7f30 100644
@@ -411,6 +411,19 @@ config MFD_DLN2
 	  etc. must be enabled in order to use the functionality of
 	  the device.
 
+config MFD_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 MFD_ENE_KB3930
 	tristate "ENE KB3930 Embedded Controller support"
 	depends on I2C
drivers/mfd/Makefile +1 -0
index 457471478a93..b1831cf4d6ed 100644
@@ -237,6 +237,7 @@ obj-$(CONFIG_MFD_HI6421_PMIC)	+= hi6421-pmic-core.o
 obj-$(CONFIG_MFD_HI6421_SPMI)	+= hi6421-spmi-pmic.o
 obj-$(CONFIG_MFD_HI655X_PMIC)   += hi655x-pmic.o
 obj-$(CONFIG_MFD_DLN2)		+= dln2.o
+obj-$(CONFIG_MFD_LJCA) 		+= ljca.o
 obj-$(CONFIG_MFD_RT4831)	+= rt4831.o
 obj-$(CONFIG_MFD_RT5033)	+= rt5033.o
 obj-$(CONFIG_MFD_RT5120)	+= rt5120.o
drivers/mfd/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
author
#2 lore raw

PATCH v2 2/5 gpio: Add support for Intel LJCA USB GPIO driver

In reply to Ye Xiang

This patch implements the GPIO function of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA GPIO module with specific protocol through interfaces exported by LJCA USB driver.

---
 drivers/gpio/Kconfig     |  12 ++
 drivers/gpio/Makefile    |   1 +
 drivers/gpio/gpio-ljca.c | 454 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 467 insertions(+)
 create mode 100644 drivers/gpio/gpio-ljca.c
drivers/gpio/Kconfig +12 -0
index e9917a45b005..8332af1f5025 100644
@@ -1257,6 +1257,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
index 010587025fc8..4e2e2d44b820 100644
@@ -78,6 +78,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
Reviewed-by on v2 2/5
#3 lore raw

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

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

Looks good to me, also looks like a really helpful adapter.

I would appreciate if Andy could ACK it too, as Intel engineer.

Yours,
Linus Walleij

author
#4 lore raw

PATCH v2 3/5 i2c: Add support for Intel LJCA USB I2C driver

In reply to Ye Xiang

This patch implements the I2C function of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA I2c module with specific protocol through interfaces exported by LJCA USB driver.

---
 drivers/i2c/busses/Kconfig    |  11 ++
 drivers/i2c/busses/Makefile   |   1 +
 drivers/i2c/busses/i2c-ljca.c | 357 ++++++++++++++++++++++++++++++++++
 3 files changed, 369 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ljca.c
drivers/i2c/busses/Kconfig +11 -0
index a7bfddf08fa7..f94e2ed32563 100644
@@ -1243,6 +1243,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
index e73cdb1d2b5a..66a1fe79d0f6 100644
@@ -131,6 +131,7 @@ obj-$(CONFIG_I2C_RCAR)		+= i2c-rcar.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
author
#5 lore raw

PATCH v2 4/5 spi: Add support for Intel LJCA USB SPI driver

In reply to Ye Xiang

This patch implements the SPI function of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA SPI module with specific protocol through interfaces exported by LJCA USB driver.

---
 drivers/spi/Kconfig    |  11 ++
 drivers/spi/Makefile   |   1 +
 drivers/spi/spi-ljca.c | 291 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 303 insertions(+)
 create mode 100644 drivers/spi/spi-ljca.c
drivers/spi/Kconfig +11 -0
index 3b1c0878bb85..b7ce4cbeb024 100644
@@ -396,6 +396,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
index be9ba40ef8d0..871a088294cb 100644
@@ -68,6 +68,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
maintainer
#6 lore raw

Re: [PATCH v2 4/5] spi: Add support for Intel LJCA USB SPI driver

Quoted 12 lines · Ye Xiang
drivers/spi/spi-ljca.c new file +11 -0
+struct spi_xfer_packet {
+	u8 indicator;
+	s8 len;
+	u8 data[];
+} __packed;
 
+static int ljca_spi_read_write(struct ljca_spi_dev *ljca_spi, const u8 *w_data, u8 *r_data, int len,
+			       int id, int complete, int cmd)
+{
+	struct spi_xfer_packet *w_packet = (struct spi_xfer_packet *)ljca_spi->obuf;
+	struct spi_xfer_packet *r_packet = (struct spi_xfer_packet *)ljca_spi->ibuf;
+	unsigned int ibuf_len = LJCA_SPI_BUF_SIZE;

drivers/spi/spi-ljca.c line 93

Quoted 10 lines
drivers/spi/spi-ljca.c new file +10 -0
+	int ret;
+
+	w_packet->indicator = FIELD_PREP(LJCA_SPI_XFER_INDICATOR_ID, id) |
+			      FIELD_PREP(LJCA_SPI_XFER_INDICATOR_CMPL, complete) |
+			      FIELD_PREP(LJCA_SPI_XFER_INDICATOR_INDEX,
+					 ljca_spi->spi_info->id);
+
+	if (cmd == LJCA_SPI_READ) {
+		w_packet->len = sizeof(u16);
+		*(u16 *)&w_packet->data[0] = len;

Are there no endianness considerations here?

drivers/spi/spi-ljca.c line 151

Quoted 3 lines
drivers/spi/spi-ljca.c new file +3 -0
+static int ljca_spi_transfer(struct ljca_spi_dev *ljca_spi, const u8 *tx_data,
+			     u8 *rx_data, u16 len)
+{

This function has one caller with barely anything in it - perhaps just inline it?

author
#7 lore raw

Re: [PATCH v2 4/5] spi: Add support for Intel LJCA USB SPI driver

Hi Mark,

Thanks for the review.

Quoted 18 lines · Mark Brown
Quoted 16 lines · Ye Xiang
drivers/spi/spi-ljca.c new file +15 -0
+struct spi_xfer_packet {
+	u8 indicator;
+	s8 len;
+	u8 data[];
+} __packed;
 
+static int ljca_spi_read_write(struct ljca_spi_dev *ljca_spi, const u8 *w_data, u8 *r_data, int len,
+			       int id, int complete, int cmd)
+{
+	struct spi_xfer_packet *w_packet = (struct spi_xfer_packet *)ljca_spi->obuf;
+	struct spi_xfer_packet *r_packet = (struct spi_xfer_packet *)ljca_spi->ibuf;
+	unsigned int ibuf_len = LJCA_SPI_BUF_SIZE;
+	int ret;
+
+	w_packet->indicator = FIELD_PREP(LJCA_SPI_XFER_INDICATOR_ID, id) |
+			      FIELD_PREP(LJCA_SPI_XFER_INDICATOR_CMPL, complete) |
Quoted 8 lines

drivers/spi/spi-ljca.c line 93

Quoted 6 lines
drivers/spi/spi-ljca.c new file +6 -0
+			      FIELD_PREP(LJCA_SPI_XFER_INDICATOR_INDEX,
+					 ljca_spi->spi_info->id);
+
+	if (cmd == LJCA_SPI_READ) {
+		w_packet->len = sizeof(u16);
+		*(u16 *)&w_packet->data[0] = len;

Are there no endianness considerations here?

Yes, it should be little endian. Will address this.

Quoted 7 lines

drivers/spi/spi-ljca.c line 151

Quoted 4 lines
drivers/spi/spi-ljca.c new file +3 -0
+static int ljca_spi_transfer(struct ljca_spi_dev *ljca_spi, const u8 *tx_data,
+			     u8 *rx_data, u16 len)
+{

This function has one caller with barely anything in it - perhaps just inline it?

Agree. Will make this function inline.

--
Thanks
Ye Xiang

author
#8 lore raw

PATCH v2 5/5 Documentation: Add ABI doc for attributes of LJCA device

In reply to Ye Xiang

Add sysfs attributes Documentation entries for LJCA device

---
 .../ABI/testing/sysfs-bus-usb-devices-ljca    | 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
new file mode 100644
index 000000000000..43b95effdefc
@@ -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]
+		dfu:	Echo dfu to this file so as to put the device into
+			DFU mode so the firmware can be updated.
+		debug:	Enable debug logging.
Signature · 1 line
2.34.1