Skip to contentSkip to conversation

Adding i2c-cp2615: i2c support for Silicon Labs' CP2615 Digital Audio Bridge

PATCH In review Bence Csókás 3 participants 6 messages Mar 17, 2021 – Mar 18, 2021

Subsystems (2)
lore
Share & tools
lore

Bence Csókás

author maintainer
#0 lore raw

PATCH v2 1/1 Adding i2c-cp2615: i2c support for Silicon Labs' CP2615 Digital Audio Bridge

---
 drivers/i2c/busses/Kconfig      |  10 ++
 drivers/i2c/busses/Makefile     |   1 +
 drivers/i2c/busses/i2c-cp2615.c | 282 ++++++++++++++++++++++++++++++++
 3 files changed, 293 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-cp2615.c
drivers/i2c/busses/Kconfig +10 -0
index a49e0ed4a599..7a0dd18140d3 100644
@@ -1227,6 +1227,16 @@ config I2C_DLN2
 	 This driver can also be built as a module.  If so, the module
 	 will be called i2c-dln2.
 
+config I2C_CP2615
+	tristate "Silicon Labs CP2615 USB sound card and I2C adapter"
+	depends on USB
+	help
+	  If you say yes to this option, support will be included for Silicon
+	  Labs CP2615's I2C interface.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-cp2615.
+
 config I2C_PARPORT
 	tristate "Parallel port adapter"
 	depends on PARPORT
drivers/i2c/busses/Makefile +1 -0
index 683c49faca05..adb71d9c9d42 100644
@@ -127,6 +127,7 @@ obj-$(CONFIG_I2C_ZX2967)	+= i2c-zx2967.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_CP2615) += i2c-cp2615.o
 obj-$(CONFIG_I2C_PARPORT)	+= i2c-parport.o
 obj-$(CONFIG_I2C_ROBOTFUZZ_OSIF)	+= i2c-robotfuzz-osif.o
 obj-$(CONFIG_I2C_TAOS_EVM)	+= i2c-taos-evm.o
drivers/i2c/busses/i2c-cp2615.c new file +282 -0

282 lines not on this page · raw message

Signature · 1 line
2.30.1
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi "Bence,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on wsa/i2c/for-next]
[also build test WARNING on v5.12-rc3 next-20210317]
[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]

url:    https://github.com/0day-ci/linux/commits/Bence-Cs-k-s/Adding-i2c-cp2615-i2c-support-for-Silicon-Labs-CP2615-Digital-Audio-Bridge/20210317-181539
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
config: arc-allyesconfig (attached as .config)
compiler: arceb-elf-gcc (GCC) 9.3.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/0day-ci/linux/commit/c8c005a08175789b1874e69abf4c6da690d5b323
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Bence-Cs-k-s/Adding-i2c-cp2615-i2c-support-for-Silicon-Labs-CP2615-Digital-Audio-Bridge/20210317-181539 git checkout c8c005a08175789b1874e69abf4c6da690d5b323
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/i2c/busses/i2c-cp2615.c:82:5: warning: no previous prototype for 'cp2615_init_iop_msg' [-Wmissing-prototypes]
      82 | int cp2615_init_iop_msg(struct cp2615_iop_msg *ret, enum cp2615_iop_msg_type msg, const void *data, size_t data_len)
         |     ^~~~~~~~~~~~~~~~~~~
>> drivers/i2c/busses/i2c-cp2615.c:99:5: warning: no previous prototype for 'cp2615_init_i2c_msg' [-Wmissing-prototypes]
      99 | int cp2615_init_i2c_msg(struct cp2615_iop_msg *ret, const struct cp2615_i2c_transfer *data)
         |     ^~~~~~~~~~~~~~~~~~~
>> drivers/i2c/busses/i2c-cp2615.c:105:5: warning: no previous prototype for 'cp2615_check_status' [-Wmissing-prototypes]
     105 | int cp2615_check_status(enum cp2615_i2c_status status)
         |     ^~~~~~~~~~~~~~~~~~~
>> drivers/i2c/busses/i2c-cp2615.c:269:1: warning: data definition has no type or storage class
     269 | MODULE_DEVICE_TABLE(usb, id_table);
         | ^~~~~~~~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:269:1: error: type defaults to 'int' in declaration of 'MODULE_DEVICE_TABLE' [-Werror=implicit-int]
>> drivers/i2c/busses/i2c-cp2615.c:269:1: warning: parameter names (without types) in function declaration
   In file included from include/linux/device.h:32,
                    from include/linux/acpi.h:15,
                    from include/linux/i2c.h:13,
                    from drivers/i2c/busses/i2c-cp2615.c:11:
>> include/linux/device/driver.h:263:1: warning: data definition has no type or storage class
     263 | module_init(__driver##_init); \
         | ^~~~~~~~~~~
   include/linux/usb.h:1303:2: note: in expansion of macro 'module_driver'
    1303 |  module_driver(__usb_driver, usb_register, \
         |  ^~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:278:1: note: in expansion of macro 'module_usb_driver'
     278 | module_usb_driver(cp2615_i2c_driver);
         | ^~~~~~~~~~~~~~~~~
   include/linux/device/driver.h:263:1: error: type defaults to 'int' in declaration of 'module_init' [-Werror=implicit-int]
     263 | module_init(__driver##_init); \
         | ^~~~~~~~~~~
   include/linux/usb.h:1303:2: note: in expansion of macro 'module_driver'
    1303 |  module_driver(__usb_driver, usb_register, \
         |  ^~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:278:1: note: in expansion of macro 'module_usb_driver'
     278 | module_usb_driver(cp2615_i2c_driver);
         | ^~~~~~~~~~~~~~~~~
   In file included from include/linux/linkage.h:7,
                    from include/linux/kernel.h:7,
                    from drivers/i2c/busses/i2c-cp2615.c:9:
>> include/linux/export.h:19:30: warning: parameter names (without types) in function declaration
      19 | #define THIS_MODULE ((struct module *)0)
         |                              ^~~~~~
   include/linux/usb.h:1290:30: note: in expansion of macro 'THIS_MODULE'
    1290 |  usb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
         |                              ^~~~~~~~~~~
   include/linux/device/driver.h:261:9: note: in expansion of macro 'usb_register'
     261 |  return __register(&(__driver) , ##__VA_ARGS__); \
         |         ^~~~~~~~~~
   include/linux/usb.h:1303:2: note: in expansion of macro 'module_driver'
    1303 |  module_driver(__usb_driver, usb_register, \
         |  ^~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:278:1: note: in expansion of macro 'module_usb_driver'
     278 | module_usb_driver(cp2615_i2c_driver);
         | ^~~~~~~~~~~~~~~~~
   In file included from include/linux/device.h:32,
                    from include/linux/acpi.h:15,
                    from include/linux/i2c.h:13,
                    from drivers/i2c/busses/i2c-cp2615.c:11:
   include/linux/device/driver.h:268:1: warning: data definition has no type or storage class
     268 | module_exit(__driver##_exit);
         | ^~~~~~~~~~~
   include/linux/usb.h:1303:2: note: in expansion of macro 'module_driver'
    1303 |  module_driver(__usb_driver, usb_register, \
         |  ^~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:278:1: note: in expansion of macro 'module_usb_driver'
     278 | module_usb_driver(cp2615_i2c_driver);
         | ^~~~~~~~~~~~~~~~~
   include/linux/device/driver.h:268:1: error: type defaults to 'int' in declaration of 'module_exit' [-Werror=implicit-int]
     268 | module_exit(__driver##_exit);
         | ^~~~~~~~~~~
   include/linux/usb.h:1303:2: note: in expansion of macro 'module_driver'
    1303 |  module_driver(__usb_driver, usb_register, \
         |  ^~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:278:1: note: in expansion of macro 'module_usb_driver'
     278 | module_usb_driver(cp2615_i2c_driver);
         | ^~~~~~~~~~~~~~~~~
   In file included from include/linux/linkage.h:7,
                    from include/linux/kernel.h:7,
                    from drivers/i2c/busses/i2c-cp2615.c:9:
>> include/linux/export.h:19:30: warning: parameter names (without types) in function declaration
      19 | #define THIS_MODULE ((struct module *)0)
         |                              ^~~~~~
   include/linux/usb.h:1290:30: note: in expansion of macro 'THIS_MODULE'
    1290 |  usb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
         |                              ^~~~~~~~~~~
   include/linux/device/driver.h:261:9: note: in expansion of macro 'usb_register'
     261 |  return __register(&(__driver) , ##__VA_ARGS__); \
         |         ^~~~~~~~~~
   include/linux/usb.h:1303:2: note: in expansion of macro 'module_driver'
    1303 |  module_driver(__usb_driver, usb_register, \
         |  ^~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:278:1: note: in expansion of macro 'module_usb_driver'
     278 | module_usb_driver(cp2615_i2c_driver);
         | ^~~~~~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:280:15: error: expected declaration specifiers or '...' before string constant
     280 | MODULE_AUTHOR("Bence Csókás <[email protected]>");
         |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:281:20: error: expected declaration specifiers or '...' before string constant
     281 | MODULE_DESCRIPTION("CP2615 I2C bus driver");
         |                    ^~~~~~~~~~~~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:282:16: error: expected declaration specifiers or '...' before string constant
     282 | MODULE_LICENSE("GPL");
         |                ^~~~~
   In file included from include/linux/device.h:32,
                    from include/linux/acpi.h:15,
                    from include/linux/i2c.h:13,
                    from drivers/i2c/busses/i2c-cp2615.c:11:
   drivers/i2c/busses/i2c-cp2615.c:278:19: warning: 'cp2615_i2c_driver_init' defined but not used [-Wunused-function]
     278 | module_usb_driver(cp2615_i2c_driver);
         |                   ^~~~~~~~~~~~~~~~~
   include/linux/device/driver.h:259:19: note: in definition of macro 'module_driver'
     259 | static int __init __driver##_init(void) \
         |                   ^~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:278:1: note: in expansion of macro 'module_usb_driver'
     278 | module_usb_driver(cp2615_i2c_driver);
         | ^~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +/cp2615_init_iop_msg +82 drivers/i2c/busses/i2c-cp2615.c

    81	
  > 82	int cp2615_init_iop_msg(struct cp2615_iop_msg *ret, enum cp2615_iop_msg_type msg, const void *data, size_t data_len)
    83	{
    84		if (data_len > MAX_IOP_PAYLOAD_SIZE)
    85			return -EFBIG;
    86	
    87		if (ret) {
    88			ret->preamble = 0x2A2A;
    89			ret->length = htons(data_len+6);
    90			ret->msg = htons(msg);
    91			if(data && data_len)
    92				memcpy(&ret->data, data, data_len);
    93	        return 0;
    94		} else {
    95	        return -EINVAL;
    96		}
    97	}
    98	
  > 99	int cp2615_init_i2c_msg(struct cp2615_iop_msg *ret, const struct cp2615_i2c_transfer *data)
   100	{
   101	    return cp2615_init_iop_msg(ret, iop_DoI2cTransfer, data, 4 + data->write_len);
   102	}
   103	
   104	/* Translates status codes to Linux errno's */
 > 105	int cp2615_check_status(enum cp2615_i2c_status status)
   106	{
   107		switch (status) {
   108		case CP2615_SUCCESS:
   109				return 0;
   110		case CP2615_BUS_ERROR:
   111			return -ECOMM;
   112		case CP2615_BUS_BUSY:
   113			return -EAGAIN;
   114		case CP2615_TIMEOUT:
   115			return -ETIMEDOUT;
   116		case CP2615_INVALID_PARAM:
   117			return -EINVAL;
   118		case CP2615_CFG_LOCKED:
   119			return -EPERM;
   120		}
   121		/* Unknown error code */
   122		return -EPROTO;
   123	}
   124	
   125	
   126	static int
   127	cp2615_i2c_send(struct usb_interface *usbif, struct cp2615_i2c_transfer *i2c_w)
   128	{
   129		struct cp2615_iop_msg *msg = kzalloc(sizeof(struct cp2615_iop_msg), GFP_KERNEL);
   130		struct usb_device *usbdev = interface_to_usbdev(usbif);
   131		int res = cp2615_init_i2c_msg(msg, i2c_w);
   132		if (!res)
   133			res = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, IOP_EP_OUT), msg, ntohs(msg->length), NULL, 0);
   134		kfree(msg);
   135		return res;
   136	}
   137	
   138	static int
   139	cp2615_i2c_recv(struct usb_interface *usbif, unsigned char tag, void *buf)
   140	{
   141		struct cp2615_iop_msg *msg = kzalloc(sizeof(struct cp2615_iop_msg), GFP_KERNEL);
   142		struct cp2615_i2c_transfer_result *i2c_r = (struct cp2615_i2c_transfer_result*) &msg->data;
   143		struct usb_device *usbdev = interface_to_usbdev(usbif);
   144		int res = usb_bulk_msg(usbdev, usb_rcvbulkpipe(usbdev, IOP_EP_IN), msg, sizeof(struct cp2615_iop_msg), NULL, 0);
   145		if (res < 0)
   146			return res;
   147	
   148		if (msg->msg != htons(iop_I2cTransferResult) || i2c_r->tag != tag)
   149			return -EIO;
   150	
   151		res = cp2615_check_status(i2c_r->status);
   152		if (res < 0)
   153			return res;
   154	
   155		memcpy(buf, &i2c_r->data, i2c_r->read_len);
   156		kfree(msg);
   157		return 0;
   158	}
   159	
   160	static int
   161	cp2615_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
   162	{
   163		struct usb_interface *usbif = adap->algo_data;
   164		int i = 0, ret = 0;
   165		struct i2c_msg *msg;
   166		struct cp2615_i2c_transfer i2c_w = {0};
   167		dev_dbg(&usbif->dev, "Doing %d I2C transactions\n", num);
   168	
   169		for(; !ret && i < num; i++) {
   170			msg = &msgs[i];
   171	
   172			i2c_w.tag = 0xdd;
   173			i2c_w.i2caddr = i2c_8bit_addr_from_msg(msg);
   174			if (msg->flags & I2C_M_RD) {
   175				i2c_w.read_len = msg->len;
   176				i2c_w.write_len = 0;
   177			} else {
   178				i2c_w.read_len = 0;
   179				i2c_w.write_len = msg->len;
   180				memcpy(&i2c_w.data, msg->buf, i2c_w.write_len);
   181			}
   182			ret = cp2615_i2c_send(usbif, &i2c_w);
   183			if (ret)
   184				break;
   185			ret = cp2615_i2c_recv(usbif, i2c_w.tag, msg->buf);
   186		}
   187		if (ret < 0)
   188			return ret;
   189		return i;
   190	}
   191	
   192	static u32
   193	cp2615_i2c_func(struct i2c_adapter *adap)
   194	{
   195		return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
   196	}
   197	
   198	static const struct i2c_algorithm cp2615_i2c_algo = {
   199		.master_xfer	= cp2615_i2c_master_xfer,
   200		.functionality	= cp2615_i2c_func,
   201	};
   202	
   203	/*
   204	 * This chip has some limitations: one is that the USB endpoint
   205	 * can only receive 64 bytes/transfer, that leaves 54 bytes for
   206	 * the I2C transfer. On top of that, EITHER read_len OR write_len
   207	 * may be zero, but not both. If both are non-zero, the adapter
   208	 * issues a write followed by a read. And the chip does not
   209	 * support repeated START between the write and read phases.
   210	 *
   211	 * FIXME: There in no quirk flag for specifying that the adapter
   212	 * does not support empty transfers, or that it cannot emit a
   213	 * START condition between the combined phases.
   214	 */
   215	struct i2c_adapter_quirks cp2615_i2c_quirks = {
   216		.max_write_len = MAX_I2C_SIZE,
   217		.max_read_len = MAX_I2C_SIZE,
   218		.flags = I2C_AQ_COMB_WRITE_THEN_READ,
   219		.max_comb_1st_msg_len = MAX_I2C_SIZE,
   220		.max_comb_2nd_msg_len = MAX_I2C_SIZE
   221	};
   222	
   223	static void
   224	cp2615_i2c_remove(struct usb_interface *usbif)
   225	{
   226		struct i2c_adapter *adap = usb_get_intfdata(usbif);
   227	
   228		usb_set_intfdata(usbif, NULL);
   229		i2c_del_adapter(adap);
   230	}
   231	
   232	static int
   233	cp2615_i2c_probe(struct usb_interface *usbif, const struct usb_device_id *id)
   234	{
   235		int ret = 0;
   236		struct i2c_adapter *adap;
   237		struct usb_device *usbdev = interface_to_usbdev(usbif);
   238	
   239		ret = usb_set_interface(usbdev, IOP_IFN, IOP_ALTSETTING);
   240		if (ret)
   241			return ret;
   242	
   243		adap = devm_kzalloc(&usbif->dev, sizeof(struct i2c_adapter), GFP_KERNEL);
   244		if (!adap)
   245			return -ENOMEM;
   246	
   247		strncpy(adap->name, usbdev->serial, sizeof(adap->name));
   248		adap->owner = THIS_MODULE;
   249		adap->dev.parent = &usbif->dev;
   250		adap->dev.of_node = usbif->dev.of_node;
   251		adap->timeout = HZ;
   252		adap->algo = &cp2615_i2c_algo;
   253		adap->quirks = &cp2615_i2c_quirks;
   254		adap->algo_data = usbif;
   255	
   256		ret = i2c_add_adapter(adap);
   257		if (ret)
   258			return ret;
   259	
   260		usb_set_intfdata(usbif, adap);
   261		return ret;
   262	}
   263	
   264	static const struct usb_device_id id_table[] = {
   265		{ USB_DEVICE(CP2615_VID, CP2615_PID) },
   266		{ }
   267	};
   268	
 > 269	MODULE_DEVICE_TABLE(usb, id_table);

270

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Bence Csókás
Quoted 1 line · Bence Csókás

Thanks, this looks good now and I think we are very close.

Quoted 1 line

---

Next, time please provide a small summary of changes since last version. I get enough patches that it becomes confusing otherwise.

drivers/i2c/busses/i2c-cp2615.c line 1

Quoted 4 lines
drivers/i2c/busses/i2c-cp2615.c new file +1 -0
@@ -0,0 +1,282 @@
+/* SPDX-License-Identifier: GPL-2.0 */

If you want GPL v2 only, then you need to say in MODULE_LICENSE also "GPL v2".

drivers/i2c/busses/i2c-cp2615.c line 12

Quoted 5 lines
drivers/i2c/busses/i2c-cp2615.c new file +5 -0
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/i2c.h>
+#include <linux/usb.h>

Please sort this to avoid double entries get added in the future.

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

Quoted 6 lines
drivers/i2c/busses/i2c-cp2615.c new file +6 -0
+enum cp2615_iop_msg_type {
+	iop_GetAccessoryInfo = 0xD100,
+	iop_AccessoryInfo = 0xA100,
+	iop_GetPortConfiguration = 0xD203,
+	iop_PortConfiguration = 0xA203,
+	// ...

This comment can go?

drivers/i2c/busses/i2c-cp2615.c line 60

Quoted 4 lines
drivers/i2c/busses/i2c-cp2615.c new file +4 -0
+/** Possible values for struct cp2615_i2c_transfer_result.status
+ *
+ *  Values extracted from the USBXpress(r) SDK
+ */

I'd think this can go, too.

drivers/i2c/busses/i2c-cp2615.c line 82

Quoted 1 line
drivers/i2c/busses/i2c-cp2615.c new file +1 -0
+int cp2615_init_iop_msg(struct cp2615_iop_msg *ret, enum cp2615_iop_msg_type msg, const void *data, size_t data_len)

Please break it into two lines. And please run 'checkpatch --strict' on your patch to find things like too long lines and spaces around operators etc... I will skip pointing them out here.

drivers/i2c/busses/i2c-cp2615.c line 87

Quoted 5 lines
drivers/i2c/busses/i2c-cp2615.c new file +5 -0
+{
+	if (data_len > MAX_IOP_PAYLOAD_SIZE)
+		return -EFBIG;
+
+	if (ret) {

Minor nit:

	if (!ret)
		return -EINVAL;

and then save the indentation for the main code path.

Quoted 5 lines
drivers/i2c/busses/i2c-cp2615.c new file +5 -0
+		ret->preamble = 0x2A2A;
+		ret->length = htons(data_len+6);
+		ret->msg = htons(msg);
+		if(data && data_len)
+			memcpy(&ret->data, data, data_len);

drivers/i2c/busses/i2c-cp2615.c line 102

Quoted 10 lines
drivers/i2c/busses/i2c-cp2615.c new file +10 -0
+        return 0;
+	} else {
+        return -EINVAL;
+	}
+}
+
+int cp2615_init_i2c_msg(struct cp2615_iop_msg *ret, const struct cp2615_i2c_transfer *data)
+{
+    return cp2615_init_iop_msg(ret, iop_DoI2cTransfer, data, 4 + data->write_len);
+}

I'll leave it to you but maybe this function can go and cp2615_init_iop_msg can be used directly? Both are only called once.

drivers/i2c/busses/i2c-cp2615.c line 111

Quoted 9 lines
drivers/i2c/busses/i2c-cp2615.c new file +9 -0
+
+/* Translates status codes to Linux errno's */
+int cp2615_check_status(enum cp2615_i2c_status status)
+{
+	switch (status) {
+	case CP2615_SUCCESS:
+			return 0;
+	case CP2615_BUS_ERROR:
+		return -ECOMM;

-EIO probably.

We have 'Documentation/i2c/fault-codes.rst' as a guide.

Quoted 13 lines
drivers/i2c/busses/i2c-cp2615.c new file +13 -0
+	case CP2615_BUS_BUSY:
+		return -EAGAIN;
+	case CP2615_TIMEOUT:
+		return -ETIMEDOUT;
+	case CP2615_INVALID_PARAM:
+		return -EINVAL;
+	case CP2615_CFG_LOCKED:
+		return -EPERM;
+	}
+	/* Unknown error code */
+	return -EPROTO;
+}
+

...

Quoted 7 lines

+/*
+ * This chip has some limitations: one is that the USB endpoint
+ * can only receive 64 bytes/transfer, that leaves 54 bytes for
+ * the I2C transfer. On top of that, EITHER read_len OR write_len
+ * may be zero, but not both. If both are non-zero, the adapter
+ * issues a write followed by a read. And the chip does not
+ * support repeated START between the write and read phases.

Good and useful paragraph!

Quoted 2 lines

+ * FIXME: There in no quirk flag for specifying that the adapter
+ * does not support empty transfers, or that it cannot emit a

Can't we use I2C_AQ_NO_ZERO_LEN here?

Quoted 1 line

+ * START condition between the combined phases.

True! But it makes sense, so we can fix that. We just need to add I2C_AQ_NO_REP_START and a short explanation to i2c.h. If you want, you can do it in a seperate patch. I can do it, too, if you prefer.

drivers/i2c/busses/i2c-cp2615.c line 221

Quoted 8 lines

+ */

drivers/i2c/busses/i2c-cp2615.c new file +7 -0
+struct i2c_adapter_quirks cp2615_i2c_quirks = {
+	.max_write_len = MAX_I2C_SIZE,
+	.max_read_len = MAX_I2C_SIZE,
+	.flags = I2C_AQ_COMB_WRITE_THEN_READ,
+	.max_comb_1st_msg_len = MAX_I2C_SIZE,
+	.max_comb_2nd_msg_len = MAX_I2C_SIZE
+};

quirks struct looks good otherwise!

drivers/i2c/busses/i2c-cp2615.c line 265

Quoted 2 lines
drivers/i2c/busses/i2c-cp2615.c new file +2 -0
+static const struct usb_device_id id_table[] = {
+	{ USB_DEVICE(CP2615_VID, CP2615_PID) },

Maybe skip the defines for VID and PID and use the values directly? I am not a USB expert, not really sure what the consistent way is.

So, this and the checkpatch issues and I think we are done.

Thanks,

Wolfram

author maintainer
#3 lore raw

Thanks for the lightning quick response!

Wolfram Sang <[email protected]> ezt írta (időpont: 2021. márc. 17., Sze, 13:34):

Quoted 11 lines · Bence Csókás
Quoted 1 line

Thanks, this looks good now and I think we are very close.

Quoted 1 line

---

Next, time please provide a small summary of changes since last version. I get enough patches that it becomes confusing otherwise.

You are right, sorry, I am still familiarizing myself with git send-email

Quoted 8 lines

drivers/i2c/busses/i2c-cp2615.c line 1

Quoted 4 lines
drivers/i2c/busses/i2c-cp2615.c new file +1 -0
@@ -0,0 +1,282 @@
+/* SPDX-License-Identifier: GPL-2.0 */

If you want GPL v2 only, then you need to say in MODULE_LICENSE also "GPL v2".

GPLv2 or later is fine by me. If I change this to "//
SPDX-License-Identifier: GPL-2.0-or-later", is that OK?

Quoted 8 lines

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

Quoted 6 lines
drivers/i2c/busses/i2c-cp2615.c new file +6 -0
+enum cp2615_iop_msg_type {
+     iop_GetAccessoryInfo = 0xD100,
+     iop_AccessoryInfo = 0xA100,
+     iop_GetPortConfiguration = 0xD203,
+     iop_PortConfiguration = 0xA203,
+     // ...

This comment can go?

Sorry, this slipped in from before... I shall remove it.

Quoted 9 lines

drivers/i2c/busses/i2c-cp2615.c line 209

Quoted 7 lines
drivers/i2c/busses/i2c-cp2615.c new file +7 -0
+/*
+ * This chip has some limitations: one is that the USB endpoint
+ * can only receive 64 bytes/transfer, that leaves 54 bytes for
+ * the I2C transfer. On top of that, EITHER read_len OR write_len
+ * may be zero, but not both. If both are non-zero, the adapter
+ * issues a write followed by a read. And the chip does not
+ * support repeated START between the write and read phases.

Good and useful paragraph!

Thank you!

Quoted 5 lines

drivers/i2c/busses/i2c-cp2615.c line 212

Quoted 3 lines
drivers/i2c/busses/i2c-cp2615.c new file +2 -0
+ * FIXME: There in no quirk flag for specifying that the adapter
+ * does not support empty transfers, or that it cannot emit a

Can't we use I2C_AQ_NO_ZERO_LEN here?

I thought that meant the adapter cannot handle NEITHER zero-length reads NOR writes, but the CP2615 can do a zero read combined with a non-zero write or the other way around, just both cannot be zero. If both are zero, the chip just ignores the request, as I've learned from a very confusing situation with i2cdetect.

Quoted 6 lines

drivers/i2c/busses/i2c-cp2615.c line 213

Quoted 2 lines
drivers/i2c/busses/i2c-cp2615.c new file +1 -0
+ * START condition between the combined phases.

True! But it makes sense, so we can fix that. We just need to add I2C_AQ_NO_REP_START and a short explanation to i2c.h. If you want, you can do it in a seperate patch. I can do it, too, if you prefer.

Sure! I should just define it as BIT(7) or something, right? Should I do it in a completely different patchset, or is it OK if I submit it as the 2/2 of PATCH v3? Are there maybe other adapters that would be affected?

Quoted 2 lines

Maybe skip the defines for VID and PID and use the values directly? I am not a USB expert, not really sure what the consistent way is.

I think this is how they usually do it, or at least from what I've seen.

Quoted 7 lines

So, this and the checkpatch issues and I think we are done.

Thanks,

Wolfram

Thanks,
Bence

#4 lore raw

Hi Bence,

Quoted 1 line

You are right, sorry, I am still familiarizing myself with git send-email

No worries, the progress from your first to your second version was really great! You can add such information e.g. using the "--annotate" parameter og git-send-email.

Quoted 2 lines

GPLv2 or later is fine by me. If I change this to "//
SPDX-License-Identifier: GPL-2.0-or-later", is that OK?

Yes, also perfect.

Quoted 10 lines
Quoted 4 lines
Quoted 2 lines

+ * FIXME: There in no quirk flag for specifying that the adapter
+ * does not support empty transfers, or that it cannot emit a

Can't we use I2C_AQ_NO_ZERO_LEN here?

I thought that meant the adapter cannot handle NEITHER zero-length reads NOR writes, but the CP2615 can do a zero read combined with a non-zero write or the other way around, just both cannot be zero. If both are zero, the chip just ignores the request, as I've learned from a very confusing situation with i2cdetect.

I think we still should use I2C_AQ_NO_ZERO_LEN. The almost only use case is a standalone zero-len read or write. This is not supported by your adapter as you found out.

Quoted 7 lines
Quoted 3 lines

True! But it makes sense, so we can fix that. We just need to add I2C_AQ_NO_REP_START and a short explanation to i2c.h. If you want, you can do it in a seperate patch. I can do it, too, if you prefer.

Sure! I should just define it as BIT(7) or something, right? Should I do it in a completely different patchset, or is it OK if I submit it as the 2/2 of PATCH v3? Are there maybe other adapters that would be

Yes, BIT(7) and same patchset please. But you need to make it 1/2 because you will use it in you driver which is then 2/2.

Quoted 1 line

affected?

Maybe, but we can fix them later incrementally. Currently, there is also no client testing the flag, so we have a bit of time here.

Quoted 4 lines
Quoted 2 lines

Maybe skip the defines for VID and PID and use the values directly? I am not a USB expert, not really sure what the consistent way is.

I think this is how they usually do it, or at least from what I've seen.

Then keep it.

All the best and happy hacking,

Wolfram

#5 lore raw
In reply to Bence Csókás
Thank you for the patch! Perhaps something to improve:

Hi "Bence,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on wsa/i2c/for-next]
[also build test WARNING on v5.12-rc3 next-20210317]
[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]

url:    https://github.com/0day-ci/linux/commits/Bence-Cs-k-s/Adding-i2c-cp2615-i2c-support-for-Silicon-Labs-CP2615-Digital-Audio-Bridge/20210317-181539
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.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/0day-ci/linux/commit/c8c005a08175789b1874e69abf4c6da690d5b323
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Bence-Cs-k-s/Adding-i2c-cp2615-i2c-support-for-Silicon-Labs-CP2615-Digital-Audio-Bridge/20210317-181539 git checkout c8c005a08175789b1874e69abf4c6da690d5b323
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=ia64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/i2c/busses/i2c-cp2615.c:82:5: warning: no previous prototype for 'cp2615_init_iop_msg' [-Wmissing-prototypes]

      82 | int cp2615_init_iop_msg(struct cp2615_iop_msg *ret, enum cp2615_iop_msg_type msg, const void *data, size_t data_len)
         |     ^~~~~~~~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:99:5: warning: no previous prototype for 'cp2615_init_i2c_msg' [-Wmissing-prototypes]
      99 | int cp2615_init_i2c_msg(struct cp2615_iop_msg *ret, const struct cp2615_i2c_transfer *data)
         |     ^~~~~~~~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c:105:5: warning: no previous prototype for 'cp2615_check_status' [-Wmissing-prototypes]
     105 | int cp2615_check_status(enum cp2615_i2c_status status)
         |     ^~~~~~~~~~~~~~~~~~~
   drivers/i2c/busses/i2c-cp2615.c: In function 'cp2615_i2c_probe':
>> drivers/i2c/busses/i2c-cp2615.c:247:2: warning: 'strncpy' specified bound 48 equals destination size [-Wstringop-truncation]
     247 |  strncpy(adap->name, usbdev->serial, sizeof(adap->name));
         |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for FRAME_POINTER
Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS
Selected by
- FAULT_INJECTION_STACKTRACE_FILTER && FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT && !X86_64 && !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM && !ARC && !X86

vim +/strncpy +247 drivers/i2c/busses/i2c-cp2615.c

231
232 static int
233 cp2615_i2c_probe(struct usb_interface *usbif, const struct usb_device_id *id)
234 {
235 int ret = 0;
236 struct i2c_adapter *adap;
237 struct usb_device *usbdev = interface_to_usbdev(usbif);
238
239 ret = usb_set_interface(usbdev, IOP_IFN, IOP_ALTSETTING);
240 if (ret)
241 return ret;
242
243 adap = devm_kzalloc(&usbif->dev, sizeof(struct i2c_adapter), GFP_KERNEL);
244 if (!adap)
245 return -ENOMEM;
246

 > 247		strncpy(adap->name, usbdev->serial, sizeof(adap->name));

248 adap->owner = THIS_MODULE;
249 adap->dev.parent = &usbif->dev;
250 adap->dev.of_node = usbif->dev.of_node;
251 adap->timeout = HZ;
252 adap->algo = &cp2615_i2c_algo;
253 adap->quirks = &cp2615_i2c_quirks;
254 adap->algo_data = usbif;
255
256 ret = i2c_add_adapter(adap);
257 if (ret)
258 return ret;
259
260 usb_set_intfdata(usbif, adap);
261 return ret;
262 }
263

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org