Skip to contentSkip to conversation

Add Intel LJCA device driver

PATCH Superseded Ye Xiang 4 participants 14 messages Mar 23, 2023 – Apr 10, 2023

Subsystems (5)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Ye Xiang

author
#0 lore raw

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

---
v6:
- ljca: split LJCA USB driver into two commits: USB part and API part.
- gpio/i2c/spi: use auxiliary bus for sub-module device enumeration instead of MFD.
- move document patch for LJCA sysfs entry to the 3th patch of this patch series.
- ljca: fix potential race condition when wait response timeout.
- ljca: use devm_kzalloc to malloc ljca device struct.

v5:
- move ljca.h from drivers/include/mfd to drivers/include/usb.
- ljca: fix a potential memory leak issue.
- add a blank line before return to adust to kernel code style.
- ljca: sysfs: split "cmd" to "ljca_dfu" and "ljca_trace_level".

v4:
- move ljca.c from drivers/mfd to drivers/usb/misc folder.
- fix index warning in sysfs-bus-devices-ljca.

v3:
- spi: make ljca_spi_transfer inline and fix an endian issue.

v2:
- ljca: remove reset command.
- gpio/spi/i2c: add default MFD_LJCA in Kconfig.
- gpio: add "select GPIOLIB_IRQCHIP" in Kconfig.

Ye Xiang (6):
usb: Add support for Intel LJCA device
usb: ljca: Add transport interfaces for sub-module drivers
Documentation: Add ABI doc for attributes of LJCA device
gpio: Add support for Intel LJCA USB GPIO driver
i2c: Add support for Intel LJCA USB I2C driver
spi: Add support for Intel LJCA USB SPI driver

 .../ABI/testing/sysfs-bus-usb-devices-ljca    |   36 +
 drivers/gpio/Kconfig                          |   12 +
 drivers/gpio/Makefile                         |    1 +
 drivers/gpio/gpio-ljca.c                      |  458 ++++++++
 drivers/i2c/busses/Kconfig                    |   11 +
 drivers/i2c/busses/Makefile                   |    1 +
 drivers/i2c/busses/i2c-ljca.c                 |  355 ++++++
 drivers/spi/Kconfig                           |   11 +
 drivers/spi/Makefile                          |    1 +
 drivers/spi/spi-ljca.c                        |  289 +++++
 drivers/usb/misc/Kconfig                      |   13 +
 drivers/usb/misc/Makefile                     |    1 +
 drivers/usb/misc/ljca.c                       | 1012 +++++++++++++++++
 include/linux/usb/ljca.h                      |   95 ++
 14 files changed, 2296 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/usb/ljca.h
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v6 1/6 usb: 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. Three modules ( I2C, GPIO, and SPI) are supported currently.

Each sub-module of LJCA device is identified by type field within the LJCA message header.

The minimum code in ASL that covers this board is
Scope (\_SB.PCI0.DWC3.RHUB.HS01)

    {
        Device (GPIO)
        {
            Name (_ADR, Zero)
            Name (_STA, 0x0F)
        }

        Device (I2C)
        {
            Name (_ADR, One)
            Name (_STA, 0x0F)
        }

        Device (SPI)
        {
            Name (_ADR, 0x02)
            Name (_STA, 0x0F)
        }
    }
---
 drivers/usb/misc/Kconfig  |  13 +
 drivers/usb/misc/Makefile |   1 +
 drivers/usb/misc/ljca.c   | 965 ++++++++++++++++++++++++++++++++++++++
 include/linux/usb/ljca.h  |  29 ++
 4 files changed, 1008 insertions(+)
 create mode 100644 drivers/usb/misc/ljca.c
 create mode 100644 include/linux/usb/ljca.h
drivers/usb/misc/Kconfig +13 -0
index a5f7652db7da..74ee39d02e69 100644
@@ -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 AUXILIARY_BUS
+	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
index 93581baec3a8..6f6adfbe17e0 100644
@@ -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 +965 -0

965 lines not on this page · raw message

include/linux/usb/ljca.h new file +29 -0
new file mode 100644
index 000000000000..057f18c5b17a
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _LINUX_USB_LJCA_H_
+#define _LINUX_USB_LJCA_H_
+
+#include <linux/types.h>
+
+struct ljca;
+
+#define LJCA_MAX_GPIO_NUM 64
+struct ljca_gpio_info {
+	struct ljca *ljca;
+	unsigned int num;
+	DECLARE_BITMAP(valid_pin_map, LJCA_MAX_GPIO_NUM);
+};
+
+struct ljca_i2c_info {
+	struct ljca *ljca;
+	u8 id;
+	u8 capacity;
+	u8 intr_pin;
+};
+
+struct ljca_spi_info {
+	struct ljca *ljca;
+	u8 id;
+	u8 capacity;
+};
+
+#endif
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v6 1/6] usb: Add support for Intel LJCA device

drivers/usb/misc/Kconfig config USB_LINK_LAYER_TEST · line 287

Quoted 12 lines · Ye Xiang
drivers/usb/misc/Kconfig +12 -0
+config USB_LJCA
+	tristate "Intel La Jolla Cove Adapter support"
+	select AUXILIARY_BUS
+	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.

That's a very generic name for a USB driver, why not "usb_ljca"?

drivers/usb/misc/ljca.c line 138

Quoted 2 lines
drivers/usb/misc/ljca.c new file +2 -0
+struct ljca_dev {
+	struct usb_device *udev;

You didn't remove this like you said you would :(

author
#3 lore raw

Re: [PATCH v6 1/6] usb: Add support for Intel LJCA device

Hi Greg,

Thanks for your review.

Quoted 15 lines · Greg Kroah-Hartman

drivers/usb/misc/Kconfig config USB_LINK_LAYER_TEST · line 287

Quoted 12 lines · Ye Xiang
drivers/usb/misc/Kconfig +12 -0
+config USB_LJCA
+	tristate "Intel La Jolla Cove Adapter support"
+	select AUXILIARY_BUS
+	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.

That's a very generic name for a USB driver, why not "usb_ljca"?

Thanks for the suggestion. Will adopt it on next version.

Quoted 5 lines

drivers/usb/misc/ljca.c line 138

Quoted 3 lines
drivers/usb/misc/ljca.c new file +2 -0
+struct ljca_dev {
+	struct usb_device *udev;

You didn't remove this like you said you would :(

Sorry. I just stopped using it, but I forgot to delete it in struct ljca_dev. The udev field is unused in this driver now. I will definitely delete it on next version.

--
Thanks
Ye Xiang

#4 lore raw

Re: [PATCH v6 1/6] usb: Add support for Intel LJCA device

In reply to Ye Xiang
Thank you for the patch! Yet something to improve:

Hi Ye,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on usb/usb-next usb/usb-linus brgl/gpio/for-next wsa/i2c/for-next broonie-spi/for-next linus/master v6.3-rc3 next-20230323] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Ye-Xiang/usb-Add-support-for-Intel-LJCA-device/20230324-012303
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
patch link:    https://lore.kernel.org/r/20230323172113.1231050-2-xiang.ye%40intel.com
patch subject: [PATCH v6 1/6] usb: Add support for Intel LJCA device
config: riscv-allmodconfig (https://download.01.org/0day-ci/archive/20230324/[email protected]/config)
compiler: riscv64-linux-gcc (GCC) 12.1.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/606c371c73fa37d233b47bd34d4789a1a157a9e4
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ye-Xiang/usb-Add-support-for-Intel-LJCA-device/20230324-012303
git checkout 606c371c73fa37d233b47bd34d4789a1a157a9e4
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=riscv olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/usb/misc/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

drivers/usb/misc/ljca.c:133:9: error: unknown type name 'ljca_event_cb_t'

     133 |         ljca_event_cb_t notify;
         |         ^~~~~~~~~~~~~~~
   drivers/usb/misc/ljca.c: In function 'ljca_stub_notify':
   drivers/usb/misc/ljca.c:252:17: error: called object is not a function or function pointer
     252 |                 stub->event_entry.notify(stub->event_entry.context, cmd, evt_data, len);
         |                 ^~~~
   drivers/usb/misc/ljca.c: In function 'ljca_add_aux_dev':
>> drivers/usb/misc/ljca.c:498:16: error: implicit declaration of function 'acpi_find_child_device'; did you mean 'acpi_match_device'? [-Werror=implicit-function-declaration]
     498 |         adev = acpi_find_child_device(parent, adr, false);
         |                ^~~~~~~~~~~~~~~~~~~~~~
         |                acpi_match_device
>> drivers/usb/misc/ljca.c:498:14: warning: assignment to 'struct acpi_device *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     498 |         adev = acpi_find_child_device(parent, adr, false);
         |              ^
>> drivers/usb/misc/ljca.c:479:29: warning: variable 'adev' set but not used [-Wunused-but-set-variable]
     479 |         struct acpi_device *adev = NULL;
         |                             ^~~~

drivers/usb/misc/ljca.c: At top level:
drivers/usb/misc/ljca.c:369:12: warning: 'ljca_transfer_internal' defined but not used [-Wunused-function]
369 | static int ljca_transfer_internal(struct ljca *ljca, u8 cmd, const void *obuf,
| ^~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

vim +498 drivers/usb/misc/ljca.c

473
474 static int ljca_add_aux_dev(struct ljca_dev *dev, char *name, unsigned int id, unsigned int adr,
475 void *data)
476 {
477 struct auxiliary_device *auxdev;
478 struct acpi_device *parent;

 > 479		struct acpi_device *adev = NULL;
   480		int ret;
   481	
   482		if (dev->auxdev_count >= ARRAY_SIZE(dev->auxdevs))
   483			return -EINVAL;
   484	
   485		auxdev = &dev->auxdevs[dev->auxdev_count];
   486		auxdev->name = name;
   487		auxdev->id = id;
   488		auxdev->dev.platform_data = data;
   489		auxdev->dev.parent = &dev->intf->dev;
   490		auxdev->dev.release = ljca_aux_release;
   491	
   492		ret = auxiliary_device_init(auxdev);
   493		if (ret)
   494			return ret;
   495	
   496		/* new auxiliary device bind to acpi device */
   497		parent = ACPI_COMPANION(&dev->intf->dev);
 > 498		adev = acpi_find_child_device(parent, adr, false);

499 ACPI_COMPANION_SET(&auxdev->dev, adev ?: parent);
500
501 ret = auxiliary_device_add(auxdev);
502 if (ret) {
503 dev_err(&dev->intf->dev, "failed to add auxiliary dev %s.%d\n", name, id);
504 auxiliary_device_uninit(auxdev);
505 return ret;
506 }
507
508 dev->auxdev_count++;
509
510 return 0;
511 }
512

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
maintainer
#5 lore raw

Re: [PATCH v6 1/6] usb: Add support for Intel LJCA device

In reply to Ye Xiang

Hi Ye,

drivers/usb/misc/ljca.c line 391

Quoted 9 lines
drivers/usb/misc/ljca.c new file +9 -0
+static void ljca_read_complete(struct urb *urb)
+{
+	struct ljca_msg *header = urb->transfer_buffer;
+	struct ljca_dev *dev = urb->context;
+	int len = urb->actual_length;
+	int ret;
+
+	WARN_ON_ONCE(!dev);
+	WARN_ON_ONCE(!header);

WARN_* macros should be used when we can recover from that condition, while we are running straight to a NULL pointer dereference.

If !dev or !header is not a warning but a "bug", so either you make sure we don't go ahead or remove the check.

The rest looks fairly good,
Andi

author
#6 lore raw

PATCH v6 2/6 usb: ljca: Add transport interfaces for sub-module drivers

In reply to Ye Xiang

This patch adds the transport interfaces for various LJCA sub-module drivers to communicate with LJCA hardware. The sub-module of LJCA can use ljca_transfer() to issue a transfer between host and hardware. And ljca_register_event_cb is exported to LJCA sub-module drivers for hardware event subscription.

---
 drivers/usb/misc/ljca.c  | 47 ++++++++++++++++++++++++++++
 include/linux/usb/ljca.h | 66 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
drivers/usb/misc/ljca.c +47 -0
index 3e4f85f453dd..7b874b82f1da 100644
@@ -380,6 +380,53 @@ static int ljca_transfer_internal(struct ljca *ljca, u8 cmd, const void *obuf,
 			       LJCA_USB_WRITE_ACK_TIMEOUT_MS);
 }
 
+int ljca_transfer(struct ljca *ljca, u8 cmd, const void *obuf, unsigned int obuf_len, void *ibuf,
+		  unsigned int *ibuf_len)
+{
+	return ljca_transfer_internal(ljca, cmd, obuf, obuf_len, ibuf, ibuf_len, true);
+}
+EXPORT_SYMBOL_NS_GPL(ljca_transfer, LJCA);
+
+int ljca_transfer_noack(struct ljca *ljca, u8 cmd, const void *obuf, unsigned int obuf_len)
+{
+	return ljca_transfer_internal(ljca, cmd, obuf, obuf_len, NULL, NULL, false);
+}
+EXPORT_SYMBOL_NS_GPL(ljca_transfer_noack, LJCA);
+
+int ljca_register_event_cb(struct ljca *ljca, ljca_event_cb_t event_cb, void *context)
+{
+	struct ljca_stub *stub;
+	unsigned long flags;
+
+	stub = ljca_stub_find(ljca->dev, ljca->type);
+	if (IS_ERR(stub))
+		return PTR_ERR(stub);
+
+	spin_lock_irqsave(&stub->event_cb_lock, flags);
+	stub->event_entry.notify = event_cb;
+	stub->event_entry.context = context;
+	spin_unlock_irqrestore(&stub->event_cb_lock, flags);
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(ljca_register_event_cb, LJCA);
+
+void ljca_unregister_event_cb(struct ljca *ljca)
+{
+	struct ljca_stub *stub;
+	unsigned long flags;
+
+	stub = ljca_stub_find(ljca->dev, ljca->type);
+	if (IS_ERR(stub))
+		return;
+
+	spin_lock_irqsave(&stub->event_cb_lock, flags);
+	stub->event_entry.notify = NULL;
+	stub->event_entry.context = NULL;
+	spin_unlock_irqrestore(&stub->event_cb_lock, flags);
+}
+EXPORT_SYMBOL_NS_GPL(ljca_unregister_event_cb, LJCA);
+
 static void ljca_read_complete(struct urb *urb)
 {
 	struct ljca_msg *header = urb->transfer_buffer;
include/linux/usb/ljca.h +66 -0

70 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#7 lore raw

Re: [PATCH v6 2/6] usb: ljca: Add transport interfaces for sub-module drivers

Hi Ye,

Quoted 1 line · Ye Xiang

This patch adds the transport interfaces for various LJCA

please, here and in the other patches, keep using the imperative form, as in the subject.

Quoted 9 lines

sub-module drivers to communicate with LJCA hardware. The sub-module of LJCA can use ljca_transfer() to issue a transfer between host and hardware. And ljca_register_event_cb is exported to LJCA sub-module drivers for hardware event subscription.

---
 drivers/usb/misc/ljca.c  | 47 ++++++++++++++++++++++++++++
 include/linux/usb/ljca.h | 66 ++++++++++++++++++++++++++++++++++++++++

Why havne't you added this in the previous patch?

Quoted 1 line
 2 files changed, 113 insertions(+)

[...]

include/linux/usb/ljca.h struct ljca_spi_info { · line 41

Quoted 13 lines
include/linux/usb/ljca.h +13 -0
+/**
+ * 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);

I'm not very enthusiastic about this typedef here. Is it providing a real improvement? As far as I can see it's used only in one occasion.

I don't have a strong opinion on this, though.

Andi

author
#8 lore raw

PATCH v6 3/6 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    | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-usb-devices-ljca
Documentation/ABI/testing/sysfs-bus-usb-devices-ljca new file +36 -0
new file mode 100644
index 000000000000..16eecaf870e2
@@ -0,0 +1,36 @@
+What:		/sys/bus/usb/.../ljca_version
+Date:		July 2023
+KernelVersion:	6.4
+Contact:	Ye Xiang <[email protected]>
+Description:
+		Provides the current firmware version of LJCA device.
+		The format is Major.Minor.Patch.Build, where
+		Major, Minor, Patch, and Build are decimal numbers.
+		For example: 1.0.0.256
+
+What:		/sys/bus/usb/.../ljca_enable_dfu
+Date:		July 2023
+KernelVersion:	6.4
+Contact:	Ye Xiang <[email protected]>
+Description:
+		Writing 1 to this file to force the LJCA device into DFU
+		mode so the firmware can be updated. After firmware
+		updating has been done, the device will back to normal
+		working mode.
+
+What:		/sys/bus/usb/.../ljca_trace_level
+Date:		July 2023
+KernelVersion:	6.4
+Contact:	Ye Xiang <[email protected]>
+Description:
+		Writing N to this file to set firmware log level of LJCA
+		device. The log can be printed to another computer through
+		UART ports in LJCA device. Valid values:
+
+		  ==	==========
+		   0	LEVEL_ERROR
+		   1	LEVEL_WARNING
+		   2	LEVEL_INFO
+		   3	LEVEL_DEBUG
+		   4	LEVEL_OFF
+		  ==	==========
Signature · 1 line
2.34.1
author
#9 lore raw

PATCH v6 4/6 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 | 458 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 471 insertions(+)
 create mode 100644 drivers/gpio/gpio-ljca.c
drivers/gpio/Kconfig +12 -0
index 13be729710f2..70c57b3ccb22 100644
@@ -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 USB_LJCA
+	select GPIOLIB_IRQCHIP
+	default USB_LJCA
+	help
+	  Select this option to enable GPIO driver for the INTEL
+	  La Jolla Cove Adapter (LJCA) board.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called gpio-ljca.
+
 config GPIO_LP3943
 	tristate "TI/National Semiconductor LP3943 GPIO expander"
 	depends on MFD_LP3943
drivers/gpio/Makefile +1 -0
index c048ba003367..eb59524d18c0 100644
@@ -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 +458 -0

458 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#10 lore raw

PATCH v6 5/6 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 | 355 ++++++++++++++++++++++++++++++++++
 3 files changed, 367 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ljca.c
drivers/i2c/busses/Kconfig +11 -0
index 25eb4e8fd22f..37fed62797a9 100644
@@ -1261,6 +1261,17 @@ config I2C_DLN2
 	 This driver can also be built as a module.  If so, the module
 	 will be called i2c-dln2.
 
+config I2C_LJCA
+	tristate "I2C functionality of Intel La Jolla Cove Adapter"
+	depends on USB_LJCA
+	default USB_LJCA
+	help
+	  If you say yes to this option, I2C functionality support of Intel
+	  La Jolla Cove Adapter (LJCA) will be included.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-ljca.
+
 config I2C_CP2615
 	tristate "Silicon Labs CP2615 USB sound card and I2C adapter"
 	depends on USB
drivers/i2c/busses/Makefile +1 -0
index af56fe2c75c0..4af5b06ef288 100644
@@ -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 +355 -0

355 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#11 lore raw

Re: [PATCH v6 5/6] i2c: Add support for Intel LJCA USB I2C driver

Hi Ye,

looks good, just a few questions:

Quoted 1 line · Ye Xiang

This patch implements the I2C function of Intel USB-I2C/GPIO/SPI adapter

also here, please keep using the imperative form.

Quoted 5 lines

device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA I2c module with specific protocol through interfaces exported by LJCA USB driver.

[...]

drivers/i2c/busses/i2c-ljca.c line 33

Quoted 8 lines
drivers/i2c/busses/i2c-ljca.c new file +8 -0
+enum ljca_xfer_type {
+	LJCA_I2C_READ_XFER_TYPE,
+	LJCA_I2C_WRITE_XFER_TYPE,
+};
+
+/* I2C r/w Flags */
+#define LJCA_I2C_SLAVE_TRANSFER_WRITE	(0)
+#define LJCA_I2C_SLAVE_TRANSFER_READ	(1)

the enum above and the bits here look a bit redundant to me as they are the same thing.

What's the point for writing something like:

if (type == LJCA_I2C_READ_XFER_TYPE)

	addr |= LJCA_I2C_SLAVE_TRANSFER_WRITE

when the two are the same. You are just adding confusion.

As this is a bit field, you can just keep the defines.

[...]

drivers/i2c/busses/i2c-ljca.c line 81

Quoted 6 lines
drivers/i2c/busses/i2c-ljca.c new file +6 -0
+static u8 ljca_i2c_format_slave_addr(u8 slave_addr, u8 type)
+{
+	return (slave_addr << 1) | (type == LJCA_I2C_READ_XFER_TYPE) ?
+		       LJCA_I2C_SLAVE_TRANSFER_READ :
+		       LJCA_I2C_SLAVE_TRANSFER_WRITE;
+}

How about:

	return (slave_addr << 1) | !!type;

BTW, am I reading correctly that the address here is composed as:

7 6 5 5 3 2 1 0
ADDR7 ADDR6 ADDR5 ADDR4 ADDR3 ADDR2 ADDR1 R/W

[...]

drivers/i2c/busses/i2c-ljca.c line 290

Quoted 3 lines
drivers/i2c/busses/i2c-ljca.c new file +3 -0
+static u32 ljca_i2c_func(struct i2c_adapter *adap)
+{
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;

how is the smbus supported here?

Andi

author
#12 lore raw

Re: [PATCH v6 5/6] i2c: Add support for Intel LJCA USB I2C driver

Hi Andi,

Thanks for the review.

Quoted 8 lines · Andi Shyti

Hi Ye,

looks good, just a few questions:

Quoted 1 line · Ye Xiang

This patch implements the I2C function of Intel USB-I2C/GPIO/SPI adapter

also here, please keep using the imperative form.

Got it.

Quoted 4 lines
Quoted 4 lines

device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA I2c module with specific protocol through interfaces exported by LJCA USB driver.

...

Quoted 9 lines

drivers/i2c/busses/i2c-ljca.c line 81

Quoted 6 lines
drivers/i2c/busses/i2c-ljca.c new file +6 -0
+static u8 ljca_i2c_format_slave_addr(u8 slave_addr, u8 type)
+{
+	return (slave_addr << 1) | (type == LJCA_I2C_READ_XFER_TYPE) ?
+		       LJCA_I2C_SLAVE_TRANSFER_READ :
+		       LJCA_I2C_SLAVE_TRANSFER_WRITE;
+}

How about:

Quoted 9 lines
	return (slave_addr << 1) | !!type;

BTW, am I reading correctly that the address here is composed as:

7 6 5 5 3 2 1 0
ADDR7 ADDR6 ADDR5 ADDR4 ADDR3 ADDR2 ADDR1 R/W

[...]

You are correct. Will adopt this solution on next version.

Quoted 5 lines

drivers/i2c/busses/i2c-ljca.c line 290

Quoted 3 lines
drivers/i2c/busses/i2c-ljca.c new file +3 -0
+static u32 ljca_i2c_func(struct i2c_adapter *adap)
+{
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;

how is the smbus supported here?

The i2c-sub module of LJCA device is SMBUS compatible. It's supported by LJCA device hardware itself.

Thanks
Ye Xiang

author
#13 lore raw

PATCH v6 6/6 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 | 289 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 301 insertions(+)
 create mode 100644 drivers/spi/spi-ljca.c
drivers/spi/Kconfig +11 -0
index 47bbba04fe3a..c3de4e20531f 100644
@@ -404,6 +404,17 @@ config SPI_HISI_SFC_V3XX
 	  This enables support for HiSilicon v3xx SPI NOR flash controller
 	  found in hi16xx chipsets.
 
+config SPI_LJCA
+	tristate "Intel La Jolla Cove Adapter SPI support"
+	depends on USB_LJCA
+	default USB_LJCA
+	help
+	  Select this option to enable SPI driver for the Intel
+	  La Jolla Cove Adapter (LJCA) board.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called spi-ljca.
+
 config SPI_NXP_FLEXSPI
 	tristate "NXP Flex SPI controller"
 	depends on ARCH_LAYERSCAPE || HAS_IOMEM
drivers/spi/Makefile +1 -0
index d87cf75bee6a..0d0cc1b0fb9b 100644
@@ -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 +289 -0

289 lines not on this page · raw message

Signature · 1 line
2.34.1