All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI
@ 2022-04-03 23:08 Yusuf Khan
  2022-04-03 23:08 ` [PATCH v10 1/3] " Yusuf Khan
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Yusuf Khan @ 2022-04-03 23:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: jasowang, mikelley, mst, gregkh, javier, arnd, will, axboe,
	Yusuf Khan, Christoph Grenz, kernel test robot

This patch adds the DDCCI driver by Christoph Grenz into the kernel.
The original gitlab page is loacted at https://gitlab.com/ddcci-driv
er-linux/ddcci-driver-linux/-/tree/master.

DDC/CI is a control protocol for monitor settings supported by most
monitors since about 2005. A chardev and sysfs interface is provided.
A backlight driver using DDCCI is also provided in the seccond patch.

Signed-off-by: Yusuf Khan <yusisamerican@gmail.com>
Signed-off-by: Christoph Grenz <christophg+lkml@grenz-bonn.de>
---
v2: Fix typos.

v3: Add documentation, move files around, replace semaphores with
mutexes, and replaced <asm-generic/fcntl.h> with <linux/fcntl.h>.
"imirkin"(which due to his involvement in the dri-devel irc channel
I cant help but assume to be a DRM developer) said that the DDC/CI
bus does not intefere with the buses that DRM is involved with.

v4: Move some documentation, fix grammer mistakes, remove usages of
likely(), and clarify some documentation.

v5: Fix grammer mistakes, remove usages of likely(), and clarify
some documentation.

v6: Change contact information to reference Christoph Grenz.

v7: Remove all instances of the unlikely() macro.

v8: Modify documentation to provide updated date and kernel
documentation, fix SPDX lines, use isalpha instead of redefining
logic, change maximum amount of bytes that can be written to be
conformant with DDC/CI specification, prevent userspace from holding
locks with the open file descriptor, remove ddcci_cdev_seek, dont
refine sysfs_emit() logic, use EXPORT_SYMBOL_GPL instead of
EXPORT_SYMBOL, remove ddcci_device_remove_void, remove module
paramaters and version, and split into 2 patches.

v9: Fix IS_ANY_ID matching for compilers and archs where char is
unsigned char and use the cannonical patch format.
Reported-by: kernel test robot <lkp@intel.com>

v10: Change patch title to "drivers: ddcci: add drivers for DDCCI
and change" and change patch descriptions to add more detailed
explanations of function.

Patch 1: Add the main DDCCI component.

Patch 2: Add the backlight driver that utilizes the DDCCI driver.

Patch 3: Add documentation for the DDCCI drivers.

Yusuf Khan (3):
  drivers: ddcci: add drivers for DDCCI
  drivers: ddcci: add drivers for DDCCI
  drivers: ddcci: add drivers for DDCCI

 Documentation/ABI/testing/sysfs-driver-ddcci |   57 +
 Documentation/driver-api/ddcci.rst           |  122 ++
 drivers/char/Kconfig                         |   11 +
 drivers/char/Makefile                        |    1 +
 drivers/char/ddcci.c                         | 1805 ++++++++++++++++++
 drivers/video/backlight/Kconfig              |   11 +
 drivers/video/backlight/Makefile             |    1 +
 drivers/video/backlight/ddcci-backlight.c    |  411 ++++
 include/linux/ddcci.h                        |  163 ++
 9 files changed, 2582 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-ddcci
 create mode 100644 Documentation/driver-api/ddcci.rst
 create mode 100644 drivers/char/ddcci.c
 create mode 100644 drivers/video/backlight/ddcci-backlight.c
 create mode 100644 include/linux/ddcci.h

-- 
2.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v10 1/3] drivers: ddcci: add drivers for DDCCI
  2022-04-03 23:08 [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI Yusuf Khan
@ 2022-04-03 23:08 ` Yusuf Khan
  2022-04-04  4:58   ` Greg KH
                     ` (2 more replies)
  2022-04-03 23:08 ` [PATCH v10 2/3] " Yusuf Khan
                   ` (4 subsequent siblings)
  5 siblings, 3 replies; 13+ messages in thread
From: Yusuf Khan @ 2022-04-03 23:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: jasowang, mikelley, mst, gregkh, javier, arnd, will, axboe,
	Yusuf Khan, Christoph Grenz

This patch adds the main DDCCI driver. This interfaces with I2C to allow the
kernel to communicate with DDCCI supporting monitors, it exports a chardev
and sysfs interface for userspace.

Signed-off-by: Yusuf Khan <yusisamerican@gmail.com>
Signed-off-by: Christoph Grenz <christophg+lkml@grenz-bonn.de>
---
 drivers/char/Kconfig  |   11 +
 drivers/char/Makefile |    1 +
 drivers/char/ddcci.c  | 1805 +++++++++++++++++++++++++++++++++++++++++
 include/linux/ddcci.h |  163 ++++
 4 files changed, 1980 insertions(+)
 create mode 100644 drivers/char/ddcci.c
 create mode 100644 include/linux/ddcci.h

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 740811893c57..2449c17e1080 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -451,4 +451,15 @@ config RANDOM_TRUST_BOOTLOADER
 	pool. Otherwise, say N here so it will be regarded as device input that
 	only mixes the entropy pool.
 
+config DDCCI
+	tristate "DDCCI display protocol support"
+	depends on I2C
+	help
+	  Display Data Channel Command Interface is an
+	  interface that allows the kernel to "talk"
+	  to most displays made after 2005. Check your
+	  display's specification to see if it has
+	  support for this. This depends on I2C to
+	  compile.
+
 endmenu
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 264eb398fdd4..eaa2d58d50df 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -3,6 +3,7 @@
 # Makefile for the kernel character device drivers.
 #
 
+obj-$(CONFIG_DDCCI)				+= ddcci.o
 obj-y				+= mem.o random.o
 obj-$(CONFIG_TTY_PRINTK)	+= ttyprintk.o
 obj-y				+= misc.o
diff --git a/drivers/char/ddcci.c b/drivers/char/ddcci.c
new file mode 100644
index 000000000000..2861c537468f
--- /dev/null
+++ b/drivers/char/ddcci.c
@@ -0,0 +1,1805 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *  DDC/CI sub-bus driver
+ *
+ *  Copyright (c) 2015 Christoph Grenz
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include <linux/fcntl.h>
+#include <linux/cdev.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/fs.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+#include <linux/version.h>
+
+#include <linux/ddcci.h>
+
+#define DDCCI_RECV_BUFFER_SIZE 130
+#define DEVICE_NAME "ddcci"
+#define DDCCI_MAX_CAP_CHUNKS 200
+
+static unsigned int delay = 60;
+static unsigned short autoprobe_addrs[127] = {0xF0, 0xF2, 0xF4, 0xF6, 0xF8};
+static int autoprobe_addr_count = 5;
+
+static dev_t ddcci_cdev_first;
+static dev_t ddcci_cdev_next;
+static dev_t ddcci_cdev_end;
+static DEFINE_MUTEX(core_lock);
+
+struct bus_type ddcci_bus_type;
+EXPORT_SYMBOL_GPL(ddcci_bus_type);
+
+/* Assert neccessary string array sizes  */
+#ifndef sizeof_field
+# define sizeof_field(t, m) FIELD_SIZEOF(t, m)
+#endif
+static_assert(sizeof_field(struct ddcci_device, prot) > 8);
+static_assert(sizeof_field(struct ddcci_device, type) > 8);
+static_assert(sizeof_field(struct ddcci_device, model) > 8);
+static_assert(sizeof_field(struct ddcci_device, vendor) > 8);
+static_assert(sizeof_field(struct ddcci_device, module) > 8);
+
+/* Internal per-i2c-client driver data */
+struct ddcci_bus_drv_data {
+	unsigned long quirks;
+	struct i2c_client *i2c_dev;
+	struct mutex mut;
+	unsigned char recv_buffer[DDCCI_RECV_BUFFER_SIZE];
+};
+
+/* Replace non-alphanumeric characters in a string (used for modalias) */
+static void ddcci_modalias_clean(char *string, size_t n, char replacement)
+{
+	int i;
+
+	for (i = 0; i < n; ++i) {
+		char c = string[i];
+
+		if (c == 0)
+			return;
+		else if (isalpha(c))
+			string[i] = replacement;
+	}
+}
+
+/* Write a message to the DDC/CI bus using i2c_smbus_write_byte() */
+static int __ddcci_write_bytewise(struct i2c_client *client, unsigned char addr,
+				  bool p_flag, const unsigned char *__restrict buf,
+				  unsigned char len)
+{
+	int ret = 0;
+	unsigned char outer_addr = (unsigned char) (client->addr << 1);
+	unsigned int xor = outer_addr; /* initial xor value */
+
+	/* Consistency checks, maximum allowed by DDCCI spec */
+	if (len > 32)
+		return -EINVAL;
+
+	/* Special case: reply to 0x6E is always 0x51 */
+	if (addr == DDCCI_DEFAULT_DEVICE_ADDR) {
+		addr = DDCCI_HOST_ADDR_ODD;
+	} else {
+		/* When sending the odd address is used */
+		addr = addr | 1;
+	}
+
+	/* first byte: sender address */
+	xor ^= addr;
+	ret = i2c_smbus_write_byte(client, addr);
+	if (ret < 0)
+		return ret;
+
+	/* second byte: protocol flag and message size */
+	xor ^= ((p_flag << 7) | len);
+	ret = i2c_smbus_write_byte(client, (p_flag << 7) | len);
+	if (ret < 0)
+		return ret;
+
+	/* send payload */
+	while (len--) {
+		xor ^= (*buf);
+		ret = i2c_smbus_write_byte(client, (*buf));
+		if (ret < 0)
+			return ret;
+		buf++;
+	}
+
+	/* send checksum */
+	ret = i2c_smbus_write_byte(client, xor);
+	return ret;
+}
+
+/* Write a message to the DDC/CI bus using i2c_master_send() */
+static int __ddcci_write_block(struct i2c_client *client, unsigned char addr,
+			       unsigned char *sendbuf, bool p_flag,
+			       const unsigned char *data, unsigned char len)
+{
+	unsigned char outer_addr = (unsigned char) (client->addr << 1);
+	unsigned int xor = outer_addr;	/* initial xor value */
+	unsigned char *ptr = sendbuf;
+
+	/* Consistency checks, maximum allowed by DDCCI spec */
+	if (len > 32)
+		return -EINVAL;
+
+	/* Special case: sender to 0x6E is always 0x51 */
+	if (addr == DDCCI_DEFAULT_DEVICE_ADDR) {
+		addr = DDCCI_HOST_ADDR_ODD;
+	} else {
+		/* When sending the odd address is used */
+		addr = addr | 1;
+	}
+
+	/* first byte: sender address */
+	xor ^= addr;
+	*(ptr++) = addr;
+	/* second byte: protocol flag and message size */
+	xor ^= ((p_flag << 7) | len);
+	*(ptr++) = (p_flag << 7) | len;
+	/* payload */
+	while (len--) {
+		xor ^= (*data);
+		*(ptr++) = (*data);
+		data++;
+	}
+	/* checksum */
+	(*ptr) = xor;
+
+	/* Send it */
+	return i2c_master_send(client, sendbuf, ptr - sendbuf + 1);
+}
+
+/*
+ * Write a message to the DDC/CI bus.
+ *
+ * You must hold the bus mutex when calling this function.
+ */
+static int ddcci_write(struct i2c_client *client, unsigned char addr,
+		       bool p_flag, const unsigned char *data,
+		       unsigned char len)
+{
+	struct ddcci_bus_drv_data *drv_data;
+	unsigned char *sendbuf;
+	int ret;
+
+	drv_data = i2c_get_clientdata(client);
+
+
+	pr_debug("sending to %d:%02x:%02x: %*ph\n", client->adapter->nr,
+		 client->addr << 1, addr, len, data);
+	if (drv_data->quirks & DDCCI_QUIRK_WRITE_BYTEWISE) {
+		ret = __ddcci_write_bytewise(client, addr, p_flag, data, len);
+	} else {
+		sendbuf = drv_data->recv_buffer;
+		ret = __ddcci_write_block(client, addr, sendbuf, p_flag, data, len);
+	}
+
+	return ret;
+}
+
+/*
+ * Read a response from the DDC/CI bus with headers directly into a buffer.
+ * Always check for DDCCI_QUIRK_SKIP_FIRST_BYTE when using this function.
+ * The returned length contains the whole unmodified response.
+ * If -EMSGSIZE is returned, the buffer contains the response up to `len`.
+ * If any other negative error code is returned, the buffer content is
+ * unspecified.
+ */
+static int __ddcci_read(struct i2c_client *client, unsigned char addr,
+			bool p_flag, unsigned long quirks, unsigned char *buf,
+			unsigned char len)
+{
+	int i, payload_len, packet_length, ret;
+	unsigned char xor = DDCCI_HOST_ADDR_EVEN;
+
+	/* Consistency checks */
+	if (len < 3)
+		return -EINVAL;
+
+	/* Read frame */
+	ret = i2c_master_recv(client, buf, len);
+	if (ret < 0)
+		goto out_err;
+	packet_length = ret;
+
+	/* Skip first byte if quirk active */
+	if ((quirks & DDCCI_QUIRK_SKIP_FIRST_BYTE) && ret > 0 && len > 0) {
+		ret--;
+		len--;
+		buf++;
+	}
+
+	/* If answer too short (= incomplete) break out */
+	if (ret < 3) {
+		ret = -EIO;
+		goto out_err;
+	}
+
+	/* validate first byte */
+	if (buf[0] != addr) {
+		ret = (buf[0] == '\0') ? -EAGAIN : -EIO;
+		goto out_err;
+	}
+
+	/* validate second byte (protocol flag) */
+	if ((buf[1] & 0x80) != (p_flag << 7)) {
+		if (!p_flag || !(quirks & DDCCI_QUIRK_NO_PFLAG)) {
+			ret = -EIO;
+			goto out_err;
+		}
+	}
+
+	/* get and check payload length */
+	payload_len = buf[1] & 0x7F;
+	if (3 + payload_len > packet_length)
+		return -EBADMSG;
+	if (3 + payload_len > len)
+		return -EMSGSIZE;
+
+	/* calculate checksum */
+	for (i = 0; i < 3 + payload_len; i++)
+		xor ^= buf[i];
+
+	/* verify checksum */
+	if (xor != 0) {
+		dev_err(&client->dev, "invalid DDC/CI response, corrupted data - xor is 0x%02x, length 0x%02x\n",
+			xor, payload_len);
+		ret = -EBADMSG;
+		goto out_err;
+	}
+
+	/* return result */
+	ret = payload_len + 3 + ((quirks & DDCCI_QUIRK_SKIP_FIRST_BYTE) ? 1:0);
+
+out_err:
+	return ret;
+}
+
+/*
+ * Read a response from the DDC/CI bus
+ *
+ * You must hold the bus mutex when calling this function.
+ */
+static int ddcci_read(struct i2c_client *client, unsigned char addr,
+		      bool p_flag, unsigned char *buf, unsigned char len)
+{
+	struct ddcci_bus_drv_data *drv_data;
+	unsigned char *recvbuf;
+	int ret;
+
+	drv_data = i2c_get_clientdata(client);
+	recvbuf = drv_data->recv_buffer;
+
+	/* Read frame */
+	ret = __ddcci_read(client, addr, p_flag,
+		drv_data->quirks, recvbuf, DDCCI_RECV_BUFFER_SIZE);
+	if (ret < 0)
+		return ret;
+
+	if (drv_data->quirks & DDCCI_QUIRK_SKIP_FIRST_BYTE)
+		recvbuf++;
+
+	/* return result */
+	if (buf) {
+		if (ret > 3) {
+			ret = ret-3;
+			/* copy to caller buffer */
+			memcpy(buf, &recvbuf[2], (ret < len) ? ret : len);
+
+			if (ret > len) {
+				/* if message was truncated, return -EMSGSIZE */
+				pr_debug("received from %d:%02x:%02x: [%u/%u] %*ph ...\n",
+					 client->adapter->nr, client->addr << 1,
+					 addr, ret, len, len, buf);
+				ret = -EMSGSIZE;
+			} else {
+				pr_debug("received from %d:%02x:%02x: [%u/%u] %*ph\n",
+					 client->adapter->nr, client->addr << 1,
+					 addr, ret, len, ret, buf);
+			}
+		}
+	}
+	if (!(drv_data->quirks & DDCCI_QUIRK_WRITE_BYTEWISE)) {
+		/* second read to clear buffers, needed on some devices */
+		__ddcci_read(client, addr, true, drv_data->quirks, recvbuf, 1);
+	}
+	return ret;
+}
+
+/* Request the capability string for a device and put it into buf */
+static int ddcci_get_caps(struct i2c_client *client, unsigned char addr,
+			  unsigned char *buf, unsigned int len)
+{
+	int result = 0, counter = 0, offset = 0;
+	unsigned char cmd[3] = { DDCCI_COMMAND_CAPS, 0x00, 0x00 };
+	unsigned char *chunkbuf = kzalloc(35, GFP_KERNEL);
+
+	if (!chunkbuf)
+		return -ENOMEM;
+
+	do {
+		/* Send command */
+		result = ddcci_write(client, addr, true, cmd, sizeof(cmd));
+		if (result < 0)
+			goto err_free;
+		msleep(delay);
+		/* read result chunk */
+		result = ddcci_read(client, addr, true, chunkbuf,
+				    (len > 32) ? 35 : len + 3);
+		if (result < 0)
+			goto err_free;
+
+		if (result > 0) {
+			/* check chunk header */
+			if (chunkbuf[0] != DDCCI_REPLY_CAPS) {
+				result = -EIO;
+				goto err_free;
+			}
+			if (chunkbuf[1] != cmd[1] || chunkbuf[2] != cmd[2]) {
+				result = -EIO;
+				goto err_free;
+			}
+			if (result < 3) {
+				result = -EIO;
+				goto err_free;
+			}
+			memcpy(buf, chunkbuf + 3, min((unsigned int)result - 3, len));
+
+			counter++;
+			/* adjust offset, etc. */
+			offset += result-3;
+			len -= result-3;
+			buf += result-3;
+			cmd[1] = offset >> 8;
+			cmd[2] = offset & 0xFF;
+			/* Another superfluous read to make some devices happy... */
+			ddcci_read(client, addr, true, NULL, 2);
+		}
+	} while (result > 3 && counter < DDCCI_MAX_CAP_CHUNKS);
+
+	kfree(chunkbuf);
+	return offset + result-3;
+err_free:
+	kfree(chunkbuf);
+	return result;
+}
+
+/*
+ * Request the device identification and put it into buf.
+ *
+ * Also detects all communication quirks and sets the corresponding flags
+ * in the ddcci_bus_drv_data structure associated with client.
+ *
+ * The identification command will fail on most DDC devices, as it is optional
+ * to support, but even the "failed" response suffices to detect quirks.
+ */
+static int ddcci_identify_device(struct i2c_client *client, unsigned char addr,
+				 unsigned char *buf, unsigned char len)
+{
+	int i, payload_len, ret = -ENODEV;
+	unsigned long quirks;
+	unsigned char cmd[1] = { DDCCI_COMMAND_ID };
+	unsigned char *buffer;
+	unsigned char xor = DDCCI_HOST_ADDR_EVEN;
+	struct ddcci_bus_drv_data *bus_drv_data;
+
+	bus_drv_data = i2c_get_clientdata(client);
+	quirks = bus_drv_data->quirks;
+	buffer = bus_drv_data->recv_buffer;
+
+	/* Send Identification command */
+	if (!(quirks & DDCCI_QUIRK_WRITE_BYTEWISE)) {
+		ret = __ddcci_write_block(client, addr, buffer, true, cmd, sizeof(cmd));
+		dev_dbg(&client->dev,
+			"[%02x:%02x] writing identification command in block mode: %d\n",
+			client->addr << 1, addr, ret);
+		if ((ret == -ENXIO)
+		    && i2c_check_functionality(client->adapter,
+					       I2C_FUNC_SMBUS_WRITE_BYTE)) {
+			quirks |= DDCCI_QUIRK_WRITE_BYTEWISE;
+			dev_info(&client->dev,
+				"DDC/CI bus quirk detected: writes must be done bytewise\n");
+			/* Some devices need writing twice after a failed blockwise write */
+			__ddcci_write_bytewise(client, addr, true, cmd, sizeof(cmd));
+			msleep(delay);
+		}
+	}
+	if (ret < 0 && (quirks & DDCCI_QUIRK_WRITE_BYTEWISE)) {
+		ret = __ddcci_write_bytewise(client, addr, true, cmd, sizeof(cmd));
+		dev_dbg(&client->dev,
+			"[%02x:%02x] writing identification command in bytewise mode: %d\n",
+			client->addr << 1, addr, ret);
+	}
+	if (ret < 0)
+		return -ENODEV;
+
+	/* Wait */
+	msleep(delay);
+
+	/* Receive response */
+	ret = i2c_master_recv(client, buffer, DDCCI_RECV_BUFFER_SIZE);
+	if (ret < 0) {
+		dev_dbg(&client->dev,
+			"[%02x:%02x] receiving identification response resulted in errno %d\n",
+			client->addr << 1, addr, ret);
+		return ret;
+	}
+
+	if (ret == 0) {
+		dev_dbg(&client->dev,
+			"[%02x:%02x] no identification response received\n",
+			client->addr << 1, addr);
+		return ret;
+	}
+
+	/* Skip first byte if quirk already active */
+	if (quirks & DDCCI_QUIRK_SKIP_FIRST_BYTE && ret > 1) {
+		dev_dbg(&client->dev,
+			"[%02x:%02x] doubled first byte quirk in effect\n",
+			client->addr << 1, addr);
+		ret--;
+		buffer++;
+	}
+
+	/* If answer too short (= incomplete) break out */
+	if (ret < 3) {
+		dev_dbg(&client->dev,
+			"[%02x:%02x] identification response is too short (%d bytes)\n",
+			client->addr << 1, addr, ret);
+		return -EIO;
+	}
+
+	/* validate first byte */
+	if (buffer[0] != addr) {
+		dev_dbg(&client->dev,
+			"[%02x:%02x] identification response: %*ph\n",
+			client->addr << 1, addr, (ret > 32 ? 32 : ret), buffer);
+
+		dev_dbg(&client->dev,
+			"[%02x:%02x] identification response invalid (expected first byte %02x, got %02x)\n",
+			client->addr << 1, addr, addr, buffer[0]);
+		return -ENODEV;
+	}
+
+	/* Check if first byte is doubled (QUIRK_SKIP_FIRST_BYTE) */
+	if (!(quirks & DDCCI_QUIRK_SKIP_FIRST_BYTE)) {
+		if (buffer[0] == buffer[1]) {
+			quirks |= DDCCI_QUIRK_SKIP_FIRST_BYTE;
+			dev_info(&client->dev,
+				"DDC/CI bus quirk detected: doubled first byte on read\n");
+			ret--;
+			buffer++;
+			if (ret < 3)
+				return -EIO;
+		}
+	}
+
+	/* validate second byte (protocol flag) */
+	if ((buffer[1] & 0x80) != 0x80 && !(quirks & DDCCI_QUIRK_NO_PFLAG)) {
+		dev_info(&client->dev,
+			"DDC/CI bus quirk detected: device omits protocol flag on responses\n");
+		quirks |= DDCCI_QUIRK_NO_PFLAG;
+	}
+
+	/* get and check payload length */
+	payload_len = buffer[1] & 0x7F;
+	if (3 + payload_len > ret) {
+		dev_dbg(&client->dev,
+			"[%02x:%02x] identification response: %*ph ...\n",
+			client->addr << 1, addr, ret, buffer);
+		dev_dbg(&client->dev,
+			"[%02x:%02x] identification response was truncated (expected %d bytes, got %d)\n",
+			client->addr << 1, addr, 3+payload_len, ret);
+		return -EBADMSG;
+	}
+
+	dev_dbg(&client->dev,
+		"[%02x:%02x] identification response: %*ph\n",
+		client->addr << 1, addr, 3+payload_len, buffer);
+
+	/* calculate checksum */
+	for (i = 0; i < 3 + payload_len; i++)
+		xor ^= buffer[i];
+
+	/* verify checksum */
+	if (xor != 0) {
+		dev_err(&client->dev,
+			"[%02x:%02x] invalid DDC/CI response, corrupted data - xor is 0x%02x, length 0x%02x\n",
+			client->addr << 1, addr, xor, payload_len);
+		return -EBADMSG;
+	}
+
+	/* save quirks */
+	bus_drv_data->quirks = quirks;
+
+	/* return result */
+	if (payload_len <= len) {
+		ret = payload_len;
+		memcpy(buf, &buffer[2], payload_len);
+	} else {
+		ret = -EMSGSIZE;
+		memcpy(buf, &buffer[2], len);
+	}
+	return ret;
+}
+
+/* Character device */
+
+/* Data structure for an open file handle */
+struct ddcci_fp_data {
+	struct ddcci_device *dev;
+	unsigned char buffer[129];
+};
+
+/* Called when the character device is opened */
+static int ddcci_cdev_open(struct inode *inode, struct file *filp)
+{
+	struct ddcci_device *dev = container_of(inode->i_cdev,
+						struct ddcci_device, cdev);
+	struct ddcci_fp_data *fp_data = NULL;
+
+	fp_data = kzalloc(sizeof(struct ddcci_fp_data), GFP_KERNEL);
+
+	if (!fp_data)
+		return -ENOMEM;
+
+	fp_data->dev = dev;
+	filp->private_data = fp_data;
+
+	return 0;
+}
+
+/* Called when reading from the character device */
+static ssize_t ddcci_cdev_read(struct file *filp, char __user *buffer,
+			       size_t length, loff_t *offset)
+{
+	struct ddcci_fp_data *fp_data = filp->private_data;
+	struct ddcci_device *dev = fp_data->dev;
+	unsigned char *buf = fp_data->buffer;
+	const bool nonblocking = (filp->f_flags & O_NONBLOCK) != 0;
+	int ret = 0;
+
+	if ((filp->f_mode & FMODE_READ) == 0)
+		return -EBADF;
+
+	/* Lock mutex */
+	if (nonblocking) {
+		if (mutex_trylock(&dev->bus_drv_data->mut))
+			return -EAGAIN;
+	} else {
+		if (mutex_lock_interruptible(&dev->bus_drv_data->mut))
+			return -ERESTARTSYS;
+	}
+
+	/* Execute read */
+	ret = ddcci_read(dev->bus_drv_data->i2c_dev, dev->inner_addr, true, buf,
+			 length);
+
+	if (ret > 0) {
+		/* Copy data from user space */
+		if (copy_to_user(buffer, buf, ret)) {
+			ret = -EFAULT;
+			goto out;
+		}
+	}
+
+out:
+	mutex_unlock(&dev->bus_drv_data->mut);
+	return ret;
+}
+
+/* Called when writing to the character device */
+static ssize_t ddcci_cdev_write(struct file *filp, const char __user *buffer,
+				size_t count, loff_t *offset)
+{
+	struct ddcci_fp_data *fp_data = filp->private_data;
+	struct ddcci_device *dev = fp_data->dev;
+	unsigned char *buf = fp_data->buffer;
+	const bool nonblocking = (filp->f_flags & O_NONBLOCK) != 0;
+	int ret = 0;
+
+	if ((filp->f_mode & FMODE_WRITE) == 0)
+		return -EBADF;
+
+	if (count > 127)
+		return -EINVAL;
+
+	/* Lock mutex */
+	if (nonblocking) {
+		if (mutex_trylock(&dev->bus_drv_data->mut))
+			return -EAGAIN;
+	} else {
+		if (mutex_lock_interruptible(&dev->bus_drv_data->mut))
+			return -ERESTARTSYS;
+	}
+
+	if (count > 0) {
+		/* Copy data from user space */
+		if (copy_from_user(buf, buffer, count)) {
+			ret = -EFAULT;
+			goto err_out;
+		}
+
+		/* Execute write */
+		ret = ddcci_write(dev->bus_drv_data->i2c_dev, dev->inner_addr,
+				  true, buf, count);
+	}
+
+	if (ret >= 0) {
+		msleep(delay);
+		mutex_unlock(&dev->bus_drv_data->mut);
+		return count;
+	}
+
+err_out:
+	mutex_unlock(&dev->bus_drv_data->mut);
+	return ret;
+}
+
+static const struct file_operations ddcci_fops = {
+	.owner = THIS_MODULE,
+	.read = ddcci_cdev_read,
+	.write = ddcci_cdev_write,
+	.open = ddcci_cdev_open,
+	.llseek = no_llseek
+};
+
+/* Set up the character device for a DDC/CI device */
+static int ddcci_setup_char_device(struct ddcci_device *device)
+{
+	int ret = -EINVAL;
+
+	/* Check if free minor exists */
+	if (ddcci_cdev_next == ddcci_cdev_end) {
+		dev_err(&device->dev, "no free major/minor\n");
+		ret = -ENFILE;
+		goto out;
+	}
+
+	/* Initialize character device node */
+	cdev_init(&device->cdev, &ddcci_fops);
+	device->cdev.owner = THIS_MODULE;
+
+	/* Publish char device */
+	device->dev.devt = ddcci_cdev_next;
+	ret = cdev_add(&device->cdev, ddcci_cdev_next, 1);
+	if (ret) {
+		device->dev.devt = 0;
+		goto out;
+	}
+
+	ddcci_cdev_next++;
+out:
+	return ret;
+}
+
+/* sysfs attributes */
+
+static ssize_t ddcci_attr_capabilities_show(struct device *dev,
+					    struct device_attribute *attr,
+					    char *buf)
+{
+	struct ddcci_device *device = ddcci_verify_device(dev);
+	ssize_t ret = -ENOENT;
+	size_t len;
+
+	if (device != NULL) {
+		len = device->capabilities_len;
+		if (len > PAGE_SIZE)
+			len = PAGE_SIZE;
+		if (len == 0) {
+			ret = len;
+		} else {
+			memcpy(buf, device->capabilities, len);
+			if (len < PAGE_SIZE) {
+				buf[len] = '\n';
+				ret = len + 1;
+			}
+		}
+	}
+
+	return ret;
+}
+
+static ssize_t ddcci_attr_prot_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	struct ddcci_device *device = ddcci_verify_device(dev);
+	ssize_t ret = -ENOENT;
+	size_t len;
+
+	if (device != NULL) {
+		len = strnlen(device->prot, sizeof(device->prot));
+		strncpy(buf, device->prot, PAGE_SIZE);
+		if (len == 0) {
+			ret = len;
+		} else if (len < PAGE_SIZE) {
+			buf[len] = '\n';
+			ret = len + 1;
+		} else {
+			ret = PAGE_SIZE;
+		}
+	}
+	return ret;
+}
+
+static ssize_t ddcci_attr_type_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	struct ddcci_device *device = ddcci_verify_device(dev);
+	ssize_t ret = -ENOENT;
+	size_t len;
+
+	if (device != NULL) {
+		len = strnlen(device->type, sizeof(device->type));
+		strncpy(buf, device->type, PAGE_SIZE);
+		if (len == 0) {
+			ret = len;
+		} else if (len < PAGE_SIZE) {
+			buf[len] = '\n';
+			ret = len + 1;
+		} else {
+			ret = PAGE_SIZE;
+		}
+	}
+	return ret;
+}
+
+static ssize_t ddcci_attr_model_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	struct ddcci_device *device = ddcci_verify_device(dev);
+	ssize_t ret = -ENOENT;
+	size_t len;
+
+	if (device != NULL) {
+		len = strnlen(device->model, sizeof(device->model));
+		strncpy(buf, device->model, PAGE_SIZE);
+		if (len == 0) {
+			ret = len;
+		} else if (len < PAGE_SIZE) {
+			buf[len] = '\n';
+			ret = len + 1;
+		} else {
+			ret = PAGE_SIZE;
+		}
+	}
+	return ret;
+}
+
+static ssize_t ddcci_attr_vendor_show(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	struct ddcci_device *device = ddcci_verify_device(dev);
+	ssize_t ret = -ENOENT;
+
+	if (device != NULL)
+		ret = sysfs_emit(buf, "%s\n", device->vendor);
+
+	return ret;
+}
+
+static ssize_t ddcci_attr_module_show(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	struct ddcci_device *device = ddcci_verify_device(dev);
+	ssize_t ret = -ENOENT;
+
+	if (device != NULL)
+		ret = sysfs_emit(buf, "%s\n", device->module);
+
+	return ret;
+}
+
+static ssize_t ddcci_attr_serial_show(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	struct ddcci_device *device = ddcci_verify_device(dev);
+	ssize_t ret = -ENOENT;
+
+	if (device != NULL)
+		ret = scnprintf(buf, PAGE_SIZE, "%d\n", device->device_number);
+
+	return ret;
+}
+
+static ssize_t ddcci_attr_modalias_show(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	struct ddcci_device *device = ddcci_verify_device(dev);
+	ssize_t ret = -ENOENT;
+	char model[ARRAY_SIZE(device->model)];
+	char vendor[ARRAY_SIZE(device->model)];
+	char module[ARRAY_SIZE(device->model)];
+
+	if (device != NULL) {
+		memcpy(model, device->model, sizeof(model));
+		memcpy(vendor, device->vendor, sizeof(vendor));
+		memcpy(module, device->module, sizeof(module));
+		ddcci_modalias_clean(model, sizeof(model), '_');
+		ddcci_modalias_clean(vendor, sizeof(vendor), '_');
+		ddcci_modalias_clean(module, sizeof(module), '_');
+
+		ret = scnprintf(buf, PAGE_SIZE, "%s%s-%s-%s-%s-%s\n",
+			DDCCI_MODULE_PREFIX,
+			device->prot,
+			device->type,
+			model,
+			vendor,
+			module
+		);
+	}
+	return ret;
+}
+
+static DEVICE_ATTR(capabilities, 0444, ddcci_attr_capabilities_show, NULL);
+static DEVICE_ATTR(idProt, 0444, ddcci_attr_prot_show, NULL);
+static DEVICE_ATTR(idType, 0444, ddcci_attr_type_show, NULL);
+static DEVICE_ATTR(idModel, 0444, ddcci_attr_model_show, NULL);
+static DEVICE_ATTR(idVendor, 0444, ddcci_attr_vendor_show, NULL);
+static DEVICE_ATTR(idModule, 0444, ddcci_attr_module_show, NULL);
+static DEVICE_ATTR(idSerial, 0444, ddcci_attr_serial_show, NULL);
+static DEVICE_ATTR(modalias, 0444, ddcci_attr_modalias_show, NULL);
+
+static struct attribute *ddcci_char_device_attrs[] = {
+	&dev_attr_capabilities.attr,
+	&dev_attr_idProt.attr,
+	&dev_attr_idType.attr,
+	&dev_attr_idModel.attr,
+	&dev_attr_idVendor.attr,
+	&dev_attr_idModule.attr,
+	&dev_attr_idSerial.attr,
+	&dev_attr_modalias.attr,
+	NULL,
+};
+ATTRIBUTE_GROUPS(ddcci_char_device);
+
+/* DDC/CI bus */
+
+static int ddcci_device_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct ddcci_device	*device = to_ddcci_device(dev);
+	char model[ARRAY_SIZE(device->model)];
+	char vendor[ARRAY_SIZE(device->vendor)];
+	char module[ARRAY_SIZE(device->module)];
+
+	memcpy(model, device->model, sizeof(model));
+	memcpy(vendor, device->vendor, sizeof(vendor));
+	memcpy(module, device->module, sizeof(module));
+	ddcci_modalias_clean(model, sizeof(model), '_');
+	ddcci_modalias_clean(vendor, sizeof(vendor), '_');
+	ddcci_modalias_clean(module, sizeof(module), '_');
+
+	if (add_uevent_var(env, "MODALIAS=%s%s-%s-%s-%s-%s",
+			   DDCCI_MODULE_PREFIX,
+			   device->prot,
+			   device->type,
+			   model,
+			   vendor,
+			   module
+		))
+		return -ENOMEM;
+
+	if (device->prot[0])
+		if (add_uevent_var(env, "DDCCI_PROT=%s", device->prot))
+			return -ENOMEM;
+
+	if (device->type[0])
+		if (add_uevent_var(env, "DDCCI_TYPE=%s", device->type))
+			return -ENOMEM;
+
+	if (device->model[0])
+		if (add_uevent_var(env, "DDCCI_MODEL=%s", device->model))
+			return -ENOMEM;
+
+	if (device->vendor[0]) {
+		if (add_uevent_var(env, "DDCCI_VENDOR=%s", device->vendor))
+			return -ENOMEM;
+
+		if (add_uevent_var(env, "DDCCI_MODULE=%s", device->module))
+			return -ENOMEM;
+
+		if (add_uevent_var(env, "DDCCI_UNIQ=%d", device->device_number))
+			return -ENOMEM;
+	}
+
+	return 0;
+}
+
+static void ddcci_device_release(struct device *dev)
+{
+	struct ddcci_device *device = to_ddcci_device(dev);
+	struct ddcci_driver *driver;
+
+	/* Notify driver */
+	if (dev->driver) {
+		driver = to_ddcci_driver(dev->driver);
+		if (driver->remove)
+			driver->remove(device);
+	}
+
+	/* Teardown chardev */
+	if (dev->devt) {
+		mutex_lock(&core_lock);
+		if (device->cdev.dev == ddcci_cdev_next-1)
+			ddcci_cdev_next--;
+		cdev_del(&device->cdev);
+		mutex_unlock(&core_lock);
+	}
+
+	/* Free capability string */
+	if (device->capabilities) {
+		device->capabilities_len = 0;
+		kfree(device->capabilities);
+	}
+	/* Free device */
+	kfree(device);
+}
+
+static char *ddcci_devnode(struct device *dev,
+			 umode_t *mode, kuid_t *uid, kgid_t *gid)
+{
+	struct ddcci_device *device;
+
+	device = to_ddcci_device(dev);
+	return kasprintf(GFP_KERNEL, "bus/ddcci/%d/display",
+			 device->i2c_client->adapter->nr);
+}
+
+static char *ddcci_dependent_devnode(struct device *dev,
+			 umode_t *mode, kuid_t *uid, kgid_t *gid)
+{
+	struct ddcci_device *device;
+
+	device = to_ddcci_device(dev);
+	if (device->flags & DDCCI_FLAG_EXTERNAL) {
+		if (device->outer_addr == device->inner_addr)
+			return kasprintf(GFP_KERNEL, "bus/ddcci/%d/e%02x",
+					 device->i2c_client->adapter->nr,
+					 device->outer_addr);
+		else
+			return kasprintf(GFP_KERNEL, "bus/ddcci/%d/e%02x%02x",
+					 device->i2c_client->adapter->nr,
+					 device->outer_addr, device->inner_addr);
+	} else {
+		return kasprintf(GFP_KERNEL, "bus/ddcci/%d/i%02x",
+				 device->i2c_client->adapter->nr,
+				 device->inner_addr);
+	}
+}
+
+/* Device type for main DDC/CI devices*/
+static struct device_type ddcci_device_type = {
+	.name	= "ddcci-device",
+	.uevent		= ddcci_device_uevent,
+	.groups		= ddcci_char_device_groups,
+	.release	= ddcci_device_release,
+	.devnode	= ddcci_devnode
+};
+
+/* Device type for dependent DDC/CI devices*/
+static struct device_type ddcci_dependent_type = {
+	.name	= "ddcci-dependent-device",
+	.uevent		= ddcci_device_uevent,
+	.groups		= ddcci_char_device_groups,
+	.release	= ddcci_device_release,
+	.devnode	= ddcci_dependent_devnode
+};
+
+/**
+ * ddcci_verify_device - return parameter as ddcci_device, or NULL
+ * @dev: device, probably from some driver model iterator
+ */
+struct ddcci_device *ddcci_verify_device(struct device *dev)
+{
+	if (!dev)
+		return NULL;
+	return (dev->type == &ddcci_device_type
+		|| dev->type == &ddcci_dependent_type)
+			? to_ddcci_device(dev)
+			: NULL;
+}
+EXPORT_SYMBOL_GPL(ddcci_verify_device);
+
+/**
+ * ddcci_quirks - Get quirks for DDC/CI device
+ * @dev: Target DDC/CI device
+ */
+unsigned long ddcci_quirks(struct ddcci_device *dev)
+{
+	if (WARN_ON(!dev))
+		return ~0L;
+	if (WARN_ON(!dev->bus_drv_data))
+		return ~0L;
+	return dev->bus_drv_data->quirks;
+}
+EXPORT_SYMBOL_GPL(ddcci_quirks);
+
+/**
+ * ddcci_register_driver - register DDC/CI driver
+ * @owner: the owning module
+ * @driver: the driver to register
+ */
+int ddcci_register_driver(struct module *owner, struct ddcci_driver *driver)
+{
+	int ret;
+
+	pr_debug("registering driver [%s]\n", driver->driver.name);
+
+	/* add the driver to the list of ddcci drivers in the driver core */
+	driver->driver.owner = owner;
+	driver->driver.bus = &ddcci_bus_type;
+
+	/* When registration returns, the driver core
+	 * will have called probe() for all matching-but-unbound devices.
+	 */
+	ret = driver_register(&driver->driver);
+	if (ret)
+		return ret;
+
+	pr_debug("driver [%s] registered\n", driver->driver.name);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(ddcci_register_driver);
+
+/**
+ * ddcci_del_driver - unregister DDC/CI driver
+ * @driver: the driver being unregistered
+ */
+void ddcci_del_driver(struct ddcci_driver *driver)
+{
+	driver_unregister(&driver->driver);
+	pr_debug("driver [%s] unregistered\n", driver->driver.name);
+}
+EXPORT_SYMBOL_GPL(ddcci_del_driver);
+
+/**
+ * ddcci_device_write - Write a message to a DDC/CI device
+ * @dev: Target DDC/CI device
+ * @p_flag: Protocol flag, true for standard control messages
+ * @data: Data that will be written to the device
+ * @length: How many bytes to write
+ *
+ * Writes the message to the device and sleeps for 'delay' milliseconds
+ */
+int ddcci_device_write(struct ddcci_device *dev, bool p_flag,
+		       unsigned char *data, unsigned char length)
+{
+	int ret;
+
+	if (mutex_lock_interruptible(&dev->bus_drv_data->mut))
+		return -EAGAIN;
+
+	ret = ddcci_write(dev->bus_drv_data->i2c_dev, dev->inner_addr, p_flag, data, length);
+	msleep(delay);
+	mutex_unlock(&dev->bus_drv_data->mut);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ddcci_device_write);
+
+/**
+ * ddcci_device_read - Read a response from a DDC/CI device
+ * @dev: Target DDC/CI device
+ * @p_flag: Protocol flag, must match the corresponding write
+ * @buffer: Where to store data read from the device
+ * @length: Buffer size
+ */
+int ddcci_device_read(struct ddcci_device *dev, bool p_flag,
+		      unsigned char *buffer, unsigned char length)
+{
+	int ret;
+
+	if (mutex_lock_interruptible(&dev->bus_drv_data->mut))
+		return -EAGAIN;
+
+	ret = ddcci_read(dev->bus_drv_data->i2c_dev, dev->inner_addr, p_flag, buffer, length);
+	mutex_unlock(&dev->bus_drv_data->mut);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ddcci_device_read);
+
+/**
+ * ddcci_device_writeread - Write a message to a device and read the response
+ * @dev: Target DDC/CI device
+ * @p_flag: Protocol flag, true for standard control messages
+ * @buffer: Buffer used for write and read
+ * @length: How many bytes to write
+ * @maxlength: Buffer size on read
+ *
+ * Writing, sleeping and reading are done without releasing the DDC/CI bus.
+ * This provides atomicity in respect to other DDC/CI accesses on the same bus.
+ */
+int ddcci_device_writeread(struct ddcci_device *dev, bool p_flag,
+			   unsigned char *buffer, unsigned char length,
+			   unsigned char maxlength)
+{
+	int ret;
+
+	if (mutex_lock_interruptible(&dev->bus_drv_data->mut))
+		return -EAGAIN;
+
+	ret = ddcci_write(dev->bus_drv_data->i2c_dev, dev->inner_addr, p_flag, buffer, length);
+	if (ret < 0)
+		goto err;
+	msleep(delay);
+	ret = ddcci_read(dev->bus_drv_data->i2c_dev, dev->inner_addr, p_flag, buffer, maxlength);
+err:
+	mutex_unlock(&dev->bus_drv_data->mut);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ddcci_device_writeread);
+
+#define IS_ANY_ID(x) (((x)[0] == '\xFF') && ((x)[7] == '\xFF'))
+
+/* Check if any device id in the array matches the device and return the matching id */
+static const struct ddcci_device_id *ddcci_match_id(const struct ddcci_device_id *id,
+						    const struct ddcci_device *device)
+{
+	while (id->prot[0] || id->type[0] || id->model[0] || id->vendor[0] || id->module[0]) {
+		if ((IS_ANY_ID(id->prot) || (strcmp(device->prot, id->prot) == 0))
+		 && (IS_ANY_ID(id->type) || (strcmp(device->type, id->type) == 0))
+		 && (IS_ANY_ID(id->model) || (strcmp(device->model, id->model) == 0))
+		 && (IS_ANY_ID(id->vendor) || (strcmp(device->vendor, id->vendor) == 0))
+		 && (IS_ANY_ID(id->module) || (strcmp(device->module, id->module) == 0))) {
+			return id;
+		}
+		id++;
+	}
+	return NULL;
+}
+
+static int ddcci_device_match(struct device *dev, struct device_driver *drv)
+{
+	struct ddcci_device	*device = ddcci_verify_device(dev);
+	struct ddcci_driver	*driver;
+
+	if (!device)
+		return 0;
+
+	driver = to_ddcci_driver(drv);
+	/* match on an id table if there is one */
+	if (driver->id_table)
+		return ddcci_match_id(driver->id_table, device) != NULL;
+
+	return 0;
+}
+
+static int ddcci_device_probe(struct device *dev)
+{
+	struct ddcci_device	*device = ddcci_verify_device(dev);
+	struct ddcci_driver	*driver;
+	const struct ddcci_device_id *id;
+	int ret = 0;
+
+	if (!device)
+		return -EINVAL;
+	driver = to_ddcci_driver(dev->driver);
+
+	id = ddcci_match_id(driver->id_table, device);
+	if (!id)
+		return -ENODEV;
+
+	if (driver->probe)
+		ret = driver->probe(device, id);
+
+	return ret;
+}
+
+static void ddcci_device_remove(struct device *dev)
+{
+	struct ddcci_device	*device = ddcci_verify_device(dev);
+	struct ddcci_driver	*driver;
+	int ret = 0;
+
+	if (!device)
+		return;
+	driver = to_ddcci_driver(dev->driver);
+
+	if (driver->remove)
+		ret = driver->remove(device);
+}
+
+/**
+ * DDCCI bus type structure
+ */
+struct bus_type ddcci_bus_type = {
+	.name		= "ddcci",
+	.match		= ddcci_device_match,
+	.probe		= ddcci_device_probe,
+	.remove		= ddcci_device_remove
+};
+
+/* Main I2C driver */
+
+/* Get a pointer to the closing parenthesis */
+static char *ddcci_capstr_tok(const char *s, int depth)
+{
+	const char *ptr = s;
+	char *end;
+
+	if (s == NULL || s[0] == '\0')
+		return NULL;
+
+	while ((end = strpbrk(ptr, "()"))) {
+		if (!end || depth == INT_MAX)
+			return NULL;
+		if (*end == '(')
+			depth++;
+		else if (depth > 0)
+			depth--;
+		else
+			break;
+		ptr = end + 1;
+	}
+	return end;
+}
+
+/**
+ * ddcci_find_capstr_item - Search capability string for a tag
+ * @capabilities: Capability string to search
+ * @tag: Tag to find
+ * @length: Buffer for the length of the found tag value (optional)
+ *
+ * Return a pointer to the start of the tag value (directly after the '(') on
+ * success and write the length of the value (excluding the ')') into `length`.
+ *
+ * If the tag is not found or another error occurs, an ERR_PTR is returned
+ * and `length` stays untouched.
+ */
+const char *ddcci_find_capstr_item(const char *capabilities,
+				   const char *__restrict tag,
+				   size_t *length)
+{
+	const char *src = capabilities, *ptr;
+	ptrdiff_t len;
+	int taglen = strnlen(tag, 1024);
+
+	/* Check length of requested tag */
+	if (taglen <= 0 || taglen > 1023)
+		return ERR_PTR(-EINVAL);
+
+	/* Find tag */
+	while (src && (strncmp(src + 1, tag, taglen) != 0 || src[1 + taglen] != '('))
+		src = ddcci_capstr_tok(src + 1, -1);
+	if (!src || src[0] == '\0')
+		return ERR_PTR(-ENOENT);
+
+	/* Locate end of value */
+	src += taglen + 2;
+	ptr = ddcci_capstr_tok(src, 0);
+	if (!ptr)
+		return ERR_PTR(-EOVERFLOW);
+
+	/* Check length of tag data */
+	len = ptr-src;
+	if (len < 0 || len > 65535)
+		return ERR_PTR(-EMSGSIZE);
+
+	/* Return pointer and length */
+	if (length != NULL)
+		*length = (size_t)len;
+	return src;
+}
+EXPORT_SYMBOL_GPL(ddcci_find_capstr_item);
+
+/* Search the capability string for a tag and copy the value to dest */
+static int ddcci_cpy_capstr_item(char *dest, const char *src,
+				  const char *__restrict tag, size_t maxlen)
+{
+	const char *ptr;
+	size_t len;
+
+	/* Find tag */
+	ptr = ddcci_find_capstr_item(src, tag, &len);
+	if (IS_ERR(ptr))
+		return PTR_ERR(ptr);
+
+	/* Copy value */
+	memcpy(dest, ptr, min(len, maxlen));
+	return 0;
+}
+
+/* Fill fields in device by parsing the capability string */
+static int ddcci_parse_capstring(struct ddcci_device *device)
+{
+	const char *capstr = device->capabilities;
+	int ret = 0;
+
+	if (!capstr)
+		return -EINVAL;
+
+	/* capability string start with a paren */
+	if (capstr[0] != '(')
+		return -EINVAL;
+
+	/* get prot(...) */
+	ret = ddcci_cpy_capstr_item(device->prot, capstr, "prot", sizeof(device->prot)-1);
+	if (ret) {
+		if (ret == -ENOENT) {
+			dev_warn(&device->dev, "malformed capability string: no protocol tag");
+			memset(device->prot, 0, sizeof(device->prot)-1);
+		} else {
+			return ret;
+		}
+	}
+
+	/* get type(...) */
+	ret = ddcci_cpy_capstr_item(device->type, capstr, "type", sizeof(device->type)-1);
+	if (ret) {
+		if (ret == -ENOENT) {
+			dev_warn(&device->dev, "malformed capability string: no type tag");
+			memset(device->type, 0, sizeof(device->type)-1);
+		} else {
+			return ret;
+		}
+	}
+
+	/* and then model(...) */
+	ret = ddcci_cpy_capstr_item(device->model, capstr, "model", sizeof(device->model)-1);
+	if (ret) {
+		if (ret == -ENOENT) {
+			dev_warn(&device->dev, "malformed capability string: no model tag");
+			memset(device->model, 0, sizeof(device->model)-1);
+		} else {
+			return ret;
+		}
+	}
+
+	/* if there is no protocol tag */
+	if (!device->prot[0]) {
+		/* and no type tag: give up. */
+		if (!device->type[0])
+			return -ENOENT;
+
+		/* Assume protocol "monitor" if type is "LCD" or "CRT" */
+		if (strncasecmp(device->type, "LCD", sizeof(device->type)-1) == 0
+		 || strncasecmp(device->type, "CRT", sizeof(device->type)-1) == 0) {
+			memcpy(device->prot, "monitor", 7);
+		}
+	}
+
+	/* skip the rest for now */
+
+	return 0;
+}
+
+/* Probe for a device on an inner address and create a ddcci_device for it */
+static int ddcci_detect_device(struct i2c_client *client, unsigned char addr,
+			       int dependent)
+{
+	int ret;
+	unsigned char outer_addr = client->addr << 1;
+	unsigned char *buffer = NULL;
+	struct ddcci_bus_drv_data *drv_data = i2c_get_clientdata(client);
+	struct ddcci_device *device = NULL;
+
+	mutex_lock(&drv_data->mut);
+
+	/* Allocate buffer big enough for any capability string */
+	buffer = kmalloc(16384, GFP_KERNEL);
+	if (!buffer) {
+		ret = -ENOMEM;
+		goto err_end;
+	}
+
+	/* Allocate device struct */
+	device = kzalloc(sizeof(struct ddcci_device), GFP_KERNEL);
+	if (!device) {
+		ret = -ENOMEM;
+		goto err_end;
+	}
+
+	/* Initialize device */
+	device_initialize(&device->dev);
+	device->dev.parent = &client->dev;
+	device->dev.bus = &ddcci_bus_type;
+	device->outer_addr = outer_addr;
+	device->inner_addr = addr;
+	device->bus_drv_data = drv_data;
+	device->i2c_client = client;
+
+	if (!dependent) {
+		device->dev.type = &ddcci_device_type;
+		ret = dev_set_name(&device->dev, "ddcci%d", client->adapter->nr);
+	} else if (outer_addr == dependent) {
+		/* Internal dependent device */
+		device->dev.type = &ddcci_dependent_type;
+		device->flags = DDCCI_FLAG_DEPENDENT;
+		ret = dev_set_name(&device->dev, "ddcci%di%02x", client->adapter->nr, addr);
+	} else if (outer_addr == addr) {
+		/* External dependent device */
+		device->dev.type = &ddcci_dependent_type;
+		device->flags = DDCCI_FLAG_DEPENDENT | DDCCI_FLAG_EXTERNAL;
+		ret = dev_set_name(&device->dev, "ddcci%de%02x", client->adapter->nr, addr);
+	} else {
+		/* Dependent device of external dependent device Just in case something like this exists */
+		device->dev.type = &ddcci_dependent_type;
+		device->flags = DDCCI_FLAG_DEPENDENT | DDCCI_FLAG_EXTERNAL;
+		ret = dev_set_name(&device->dev, "ddcci%de%02x%02x", client->adapter->nr, outer_addr, addr);
+	}
+
+	if (ret)
+		goto err_free;
+
+	/* Read identification and check for quirks */
+	ret = ddcci_identify_device(client, addr, buffer, 29);
+	if (ret < 0) {
+		if (!dependent && (ret == -EBADMSG || ret == -EMSGSIZE))
+			dev_warn(&device->dev, "DDC/CI main device sent broken response on identification. Trying to detect solely based on capability information.\n");
+		else
+			goto err_free;
+	}
+
+	if (ret == 29 && buffer[0] == DDCCI_REPLY_ID) {
+		memcpy(device->vendor, &buffer[7], 8);
+		memcpy(device->module, &buffer[17], 8);
+		device->device_number = be32_to_cpu(*(__force __be32 *)&buffer[18]);
+	}
+
+	/* Read capabilities */
+	ret = ddcci_get_caps(client, addr, buffer, 16384);
+	if (ret > 0) {
+		/*
+		 *	Fixup unparenthesized capability strings, but only if the first
+		 *	character is an ascii lower case letter.
+		 *	This should still allow an early exit for completely garbled
+		 *	data but helps detecting devices where only the parentheses are
+		 *	missing, as the second char must be the first character of a
+		 *	keyword.
+		 */
+		if (ret > 2 && buffer[0] >= 'a' && buffer[0] <= 'z') {
+			dev_err(&device->dev, "DDC/CI device quirk detected: unparenthesized capability string\n");
+			device->capabilities = kzalloc(ret + 3, GFP_KERNEL);
+			if (!device->capabilities) {
+				ret = -ENOMEM;
+				goto err_free;
+			}
+			device->capabilities_len = ret + 2;
+			memcpy(&(device->capabilities[1]), buffer, ret);
+			device->capabilities[0] = '(';
+			device->capabilities[ret + 1] = ')';
+		} else {
+			/* Standard case: simply copy the received string */
+			device->capabilities = kzalloc(ret + 1, GFP_KERNEL);
+			if (!device->capabilities) {
+				ret = -ENOMEM;
+				goto err_free;
+			}
+			device->capabilities_len = ret;
+			memcpy(device->capabilities, buffer, ret);
+		}
+
+		ret = ddcci_parse_capstring(device);
+		if (ret) {
+			dev_err(&device->dev, "malformed capability string: \"%s\" errno %d\n", device->capabilities, ret);
+			ret = -EINVAL;
+			goto err_free;
+		}
+	}
+
+	/* Found a device if either identification or capabilities succeeded */
+	if (!device->capabilities && device->vendor[0] == '\0') {
+		dev_dbg(&client->dev,
+			"[%02x:%02x] got neither valid identification nor capability data\n",
+			client->addr << 1, addr);
+		ret = -ENODEV;
+		goto err_free;
+	}
+
+	/* Setup chardev */
+	mutex_lock(&core_lock);
+	ret = ddcci_setup_char_device(device);
+	mutex_unlock(&core_lock);
+	if (ret)
+		goto err_free;
+
+	/* Release mutex and add device to the tree */
+	mutex_unlock(&drv_data->mut);
+	pr_debug("found device at %d:%02x:%02x\n", client->adapter->nr, outer_addr, addr);
+	ret = device_add(&device->dev);
+	if (ret)
+		goto err_free;
+
+	goto end;
+err_free:
+	put_device(&device->dev);
+err_end:
+	mutex_unlock(&drv_data->mut);
+end:
+	kfree(buffer);
+	return ret;
+}
+
+/* I2C detect function: check if a main or external dependent device exists */
+static int ddcci_detect(struct i2c_client *client, struct i2c_board_info *info)
+{
+	int ret;
+	unsigned char outer_addr;
+	unsigned char inner_addr;
+	unsigned char buf[32];
+	unsigned char cmd_id[1] = { DDCCI_COMMAND_ID };
+	unsigned char cmd_caps[3] = { DDCCI_COMMAND_CAPS, 0x00, 0x00};
+	unsigned char *cmd;
+	unsigned int cmd_len;
+
+	/* Check for i2c_master_* functionality */
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
+		pr_debug("i2c adapter %d unsuitable: no i2c_master functionality\n", client->adapter->nr);
+		return -ENODEV;
+	}
+
+	/* send Capabilities Request (for main) or Identification Request command (for dependent devices) */
+	outer_addr = client->addr << 1;
+	inner_addr = (outer_addr == DDCCI_DEFAULT_DEVICE_ADDR) ? DDCCI_HOST_ADDR_ODD : outer_addr | 1;
+	cmd = (outer_addr == DDCCI_DEFAULT_DEVICE_ADDR) ? cmd_caps : cmd_id;
+	cmd_len = (outer_addr == DDCCI_DEFAULT_DEVICE_ADDR) ? sizeof(cmd_caps) : sizeof(cmd_id);
+	pr_debug("detecting %d:%02x\n", client->adapter->nr, outer_addr);
+
+	ret = __ddcci_write_block(client, inner_addr, buf, true, cmd, cmd_len);
+
+	if (ret == -ENXIO || ret == -EIO) {
+		if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE)) {
+			pr_debug("i2c write failed with ENXIO or EIO but bytewise writing is not supported\n");
+			return -ENODEV;
+		}
+		pr_debug("i2c write failed with ENXIO or EIO, trying bytewise writing\n");
+		ret = __ddcci_write_bytewise(client, inner_addr, true, cmd, cmd_len);
+		if (ret == 0) {
+			msleep(delay);
+			ret = __ddcci_write_bytewise(client, inner_addr, true, cmd, cmd_len);
+		}
+	}
+
+	if (ret < 0)
+		return -ENODEV;
+
+	/* wait for device */
+	msleep(delay);
+	/* receive answer */
+	ret = i2c_master_recv(client, buf, 32);
+	if (ret < 3) {
+		pr_debug("detection failed: no answer\n");
+		return -ENODEV;
+	}
+
+	/* check response starts with outer addr */
+	if (buf[0] != outer_addr) {
+		pr_debug("detection failed: invalid %s response (%02x != %02x)\n", (cmd == cmd_id) ? "identification" : "capabilities", buf[0], outer_addr);
+		pr_debug("received message was %*ph \n", ret, buf);
+		return -ENODEV;
+	}
+
+	pr_debug("detected %d:%02x\n", client->adapter->nr, outer_addr);
+
+	/* set device type */
+	strlcpy(info->type, (outer_addr == DDCCI_DEFAULT_DEVICE_ADDR) ? "ddcci" : "ddcci-dependent", I2C_NAME_SIZE);
+
+	return 0;
+}
+
+/* I2C probe function */
+static int ddcci_probe(struct i2c_client *client, const struct i2c_device_id *id)
+{
+	int i, ret = -ENODEV, tmp;
+	unsigned char main_addr, addr;
+	struct ddcci_bus_drv_data *drv_data;
+
+	/* Initialize driver data structure */
+	drv_data = devm_kzalloc(&client->dev, sizeof(struct ddcci_bus_drv_data), GFP_KERNEL);
+	if (!drv_data)
+		return -ENOMEM;
+	drv_data->i2c_dev = client;
+	mutex_init(&drv_data->mut);
+
+	/* Set i2c client data */
+	i2c_set_clientdata(client, drv_data);
+
+	if (id->driver_data == 0) {
+		/* Core device, probe at 0x6E */
+		main_addr = DDCCI_DEFAULT_DEVICE_ADDR;
+		dev_dbg(&client->dev, "probing core device [%02x]\n",
+			client->addr << 1);
+		ret = ddcci_detect_device(client, main_addr, 0);
+		if (ret) {
+			dev_info(&client->dev, "core device [%02x] probe failed: %d\n",
+				 client->addr << 1, ret);
+			if (ret == -EIO)
+				ret = -ENODEV;
+			goto err_free;
+		}
+
+		/* Detect internal dependent devices */
+		dev_dbg(&client->dev, "probing internal dependent devices\n");
+		for (i = 0; i < autoprobe_addr_count; ++i) {
+			addr = (unsigned short)autoprobe_addrs[i];
+			if ((addr & 1) == 0 && addr != main_addr) {
+				tmp = ddcci_detect_device(client, addr, main_addr);
+				if (tmp < 0 && tmp != -ENODEV) {
+					dev_info(&client->dev, "internal dependent device [%02x:%02x] probe failed: %d\n",
+						 client->addr << 1, addr, ret);
+				}
+			}
+		}
+	} else if (id->driver_data == 1) {
+		/* External dependent device */
+		main_addr = client->addr << 1;
+		dev_dbg(&client->dev, "probing external dependent device [%02x]\n", main_addr);
+		ret = ddcci_detect_device(client, main_addr, -1);
+		if (ret) {
+			dev_info(&client->dev, "external dependent device [%02x] probe failed: %d\n",
+				 main_addr, ret);
+			if (ret == -EIO)
+				ret = -ENODEV;
+			goto err_free;
+		}
+	} else {
+		dev_warn(&client->dev,
+			 "probe() called with invalid i2c device id\n");
+		ret = -EINVAL;
+	}
+
+	goto end;
+err_free:
+	devm_kfree(&client->dev, drv_data);
+end:
+	return ret;
+}
+
+/*
+ * Callback for bus_find_device() used in ddcci_remove()
+ *
+ * Find next device on i2c_client not flagged with
+ * DDCCI_FLAG_REMOVED and flag it.
+ */
+static int ddcci_remove_helper(struct device *dev, const void *p)
+{
+	struct ddcci_device *device;
+
+	device = ddcci_verify_device(dev);
+	if (!device || device->flags & DDCCI_FLAG_REMOVED)
+		return 0;
+
+	if (!p || (dev->parent == p)) {
+		device->flags |= DDCCI_FLAG_REMOVED;
+		/* Memory Barrier */
+		wmb();
+		return 1;
+	}
+
+	return 0;
+}
+
+/* I2C driver remove callback: unregister all subdevices */
+static int ddcci_remove(struct i2c_client *client)
+{
+	struct ddcci_bus_drv_data *drv_data = i2c_get_clientdata(client);
+	struct device *dev;
+
+	mutex_lock(&drv_data->mut);
+	while (1) {
+		dev = bus_find_device(&ddcci_bus_type, NULL, client,
+				      ddcci_remove_helper);
+		if (!dev)
+			break;
+		device_unregister(dev);
+		put_device(dev);
+	}
+	mutex_unlock(&drv_data->mut);
+	return 0;
+}
+
+/*
+ * I2C driver device identification table.
+ */
+static const struct i2c_device_id ddcci_idtable[] = {
+	{ "ddcci", 0 },
+	{ "ddcci-dependent", 1 },
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, ddcci_idtable);
+
+/*
+ * I2C driver description structure
+ */
+static struct i2c_driver ddcci_driver = {
+	.driver = {
+		.name	= "ddcci",
+		.owner	= THIS_MODULE,
+	},
+
+	.id_table	= ddcci_idtable,
+	.probe		= ddcci_probe,
+	.remove		= ddcci_remove,
+	.class		= I2C_CLASS_DDC,
+	.detect		= ddcci_detect,
+	.address_list	= I2C_ADDRS(
+		DDCCI_DEFAULT_DEVICE_ADDR>>1
+	),
+};
+
+/*
+ * Module initialization function. Called when the module is inserted or
+ * (if builtin) at boot time.
+ */
+static int __init ddcci_module_init(void)
+{
+	int ret;
+
+	pr_debug("initializing ddcci driver\n");
+	/* Allocate a device number region for the character devices */
+	ret = alloc_chrdev_region(&ddcci_cdev_first, 0, 128, DEVICE_NAME);
+	if (ret < 0) {
+		pr_err("failed to register device region: error %d\n", ret);
+		goto err_chrdevreg;
+	}
+	ddcci_cdev_next = ddcci_cdev_first;
+	ddcci_cdev_end = MKDEV(MAJOR(ddcci_cdev_first), MINOR(ddcci_cdev_first) + 128);
+
+	/* Register bus */
+	ret = bus_register(&ddcci_bus_type);
+	if (ret) {
+		pr_err("failed to register bus 'ddcci'\n");
+		goto err_busreg;
+	}
+
+	/* Register I2C driver */
+	ret = i2c_add_driver(&ddcci_driver);
+	if (ret) {
+		pr_err("failed to register i2c driver\n");
+		goto err_drvreg;
+	}
+
+	pr_debug("ddcci driver initialized\n");
+
+	return 0;
+
+err_drvreg:
+	bus_unregister(&ddcci_bus_type);
+err_busreg:
+	unregister_chrdev_region(ddcci_cdev_first, 128);
+err_chrdevreg:
+	return ret;
+}
+
+/*
+ * Module clean-up function. Called when the module is removed.
+ */
+static void __exit ddcci_module_exit(void)
+{
+	struct device *dev;
+
+	while (1) {
+		dev = bus_find_device(&ddcci_bus_type, NULL, NULL, ddcci_remove_helper);
+		if (!dev)
+			break;
+		device_unregister(dev);
+		put_device(dev);
+	}
+
+	i2c_del_driver(&ddcci_driver);
+	bus_unregister(&ddcci_bus_type);
+	unregister_chrdev_region(ddcci_cdev_first, 128);
+}
+
+/* Let the kernel know the calls for module init and exit */
+module_init(ddcci_module_init);
+module_exit(ddcci_module_exit);
+
+/* Module description */
+MODULE_AUTHOR("Christoph Grenz <christophg+lkml@grenz-bonn.de>");
+MODULE_DESCRIPTION("DDC/CI bus driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/ddcci.h b/include/linux/ddcci.h
new file mode 100644
index 000000000000..690a9ff85d43
--- /dev/null
+++ b/include/linux/ddcci.h
@@ -0,0 +1,163 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *  DDC/CI bus driver
+ *
+ *  Copyright (c) 2015 Christoph Grenz
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#ifndef _DDCCI_H
+#define _DDCCI_H
+
+#include <linux/mod_devicetable.h>
+#include <linux/device.h>
+#include <linux/cdev.h>
+
+#define DDCCI_MODULE_PREFIX "ddcci:"
+
+/* Special addresses */
+
+/* default device address (even) */
+#define DDCCI_DEFAULT_DEVICE_ADDR	0x6E
+/* receiving host address for communication with default device address */
+#define DDCCI_HOST_ADDR_EVEN	0x50
+/* sending host address for communication with default device address */
+#define DDCCI_HOST_ADDR_ODD	0x51
+
+/* Command codes */
+
+/* Identification Request */
+#define DDCCI_COMMAND_ID	0xf1
+/* Identification Reply */
+#define DDCCI_REPLY_ID	0xe1
+/* Capabilities Request */
+#define DDCCI_COMMAND_CAPS	0xf3
+/* Capabilities Reply */
+#define DDCCI_REPLY_CAPS	0xe3
+
+/* Quirks */
+
+/* Device always responds with unset protocol flag */
+#define DDCCI_QUIRK_NO_PFLAG BIT(1)
+/* Device needs writing one byte at a time  */
+#define DDCCI_QUIRK_WRITE_BYTEWISE BIT(2)
+/* Device repeats first byte on read */
+#define DDCCI_QUIRK_SKIP_FIRST_BYTE BIT(3)
+
+/* Flags */
+
+#define DDCCI_FLAG_REMOVED BIT(1)
+#define DDCCI_FLAG_DEPENDENT BIT(2)
+#define DDCCI_FLAG_EXTERNAL BIT(3)
+
+extern struct bus_type ddcci_bus_type;
+
+struct ddcci_bus_drv_data;
+
+/* struct ddcci_device_id - identifies DDC/CI devices for probing */
+struct ddcci_device_id {
+	char prot[9];
+	char type[9];
+	char model[9];
+	char vendor[9];
+	char module[9];
+	kernel_ulong_t driver_data;	/* Data private to the driver */
+};
+#define DDCCI_ANY_ID "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
+
+/**
+ * struct ddcci_device - represent an DDC/CI device
+ * @outer_addr: Outer device address (I2C address << 1).
+ * @inner_addr: Inner device address.
+ * @flags: Device flags.
+ * @capabilities: Device capability string.
+ * @capabilities_len: Length of capability string.
+ * @i2c_client: Parent I2C device.
+ * @bus_drv_data: Driver internal data structure.
+ * @dev: Driver model device node for the slave.
+ * @cdev: Character device structure
+ * @prot: Device class ("protocol", from capability string)
+ * @type: Device subclass ("type", from capability string)
+ * @model: Device model (from capability string)
+ * @vendor: Device vendor (from identification command response)
+ * @module: Device module (from identification command response)
+ * @device_number: Device serial (from identification command response)
+ */
+struct ddcci_device {
+	unsigned short outer_addr;
+	unsigned short inner_addr;
+	int flags;
+	char *capabilities;
+	size_t capabilities_len;
+	struct i2c_client *i2c_client;
+	struct ddcci_bus_drv_data *bus_drv_data;
+	struct device dev;
+	struct cdev cdev;
+	char prot[9];
+	char type[9];
+	char model[9];
+	char vendor[9];
+	char module[9];
+	int device_number;
+};
+#define to_ddcci_device(d) container_of(d, struct ddcci_device, dev)
+
+/**
+ * struct ddcci_driver - represent an DDC/CI device driver
+ * @probe: Callback for device binding
+ * @remove: Callback for device unbinding
+ * @driver: Device driver model driver
+ * @id_table: List of DDC/CI devices supported by this driver
+ *
+ * The driver.owner field should be set to the module owner of this driver.
+ * The driver.name field should be set to the name of this driver.
+ */
+struct ddcci_driver {
+	int (*probe)(struct ddcci_device *, const struct ddcci_device_id *);
+	int (*remove)(struct ddcci_device *);
+	struct device_driver driver;
+	struct ddcci_device_id *id_table;
+};
+#define to_ddcci_driver(d) container_of(d, struct ddcci_driver, driver)
+
+int ddcci_register_driver(struct module *owner, struct ddcci_driver *driver);
+#define ddcci_add_driver(driver) \
+	ddcci_register_driver(THIS_MODULE, driver)
+void ddcci_del_driver(struct ddcci_driver *driver);
+
+struct ddcci_device *ddcci_verify_device(struct device *dev);
+
+#define module_ddcci_driver(__ddcci_driver) \
+	module_driver(__ddcci_driver, ddcci_add_driver, \
+			ddcci_del_driver)
+
+int ddcci_device_write(struct ddcci_device *, bool p_flag, unsigned char *data,
+		       unsigned char length);
+int ddcci_device_read(struct ddcci_device *, bool p_flag, unsigned char *buffer,
+		      unsigned char length);
+int ddcci_device_writeread(struct ddcci_device *, bool p_flag,
+			   unsigned char *buffer, unsigned char length,
+			   unsigned char maxlength);
+
+static inline void *ddcci_get_drvdata(const struct ddcci_device *dev)
+{
+	return dev_get_drvdata(&dev->dev);
+}
+
+static inline void ddcci_set_drvdata(struct ddcci_device *dev, void *data)
+{
+	dev_set_drvdata(&dev->dev, data);
+}
+
+unsigned long ddcci_quirks(struct ddcci_device *dev);
+
+const char *ddcci_find_capstr_item(const char *capabilities, const char *tag,
+				   size_t *length);
+
+#endif
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v10 2/3] drivers: ddcci: add drivers for DDCCI
  2022-04-03 23:08 [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI Yusuf Khan
  2022-04-03 23:08 ` [PATCH v10 1/3] " Yusuf Khan
@ 2022-04-03 23:08 ` Yusuf Khan
  2022-04-03 23:08 ` [PATCH v10 3/3] " Yusuf Khan
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Yusuf Khan @ 2022-04-03 23:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: jasowang, mikelley, mst, gregkh, javier, arnd, will, axboe,
	Yusuf Khan, Christoph Grenz

This patch adds the backlight driver that utilizes the DDCCI
driver from patch one to add a backlight driver.

Signed-off-by: Yusuf Khan <yusisamerican@gmail.com>
Signed-off-by: Christoph Grenz <christophg+lkml@grenz-bonn.de>
---
 drivers/video/backlight/Kconfig           |  11 +
 drivers/video/backlight/Makefile          |   1 +
 drivers/video/backlight/ddcci-backlight.c | 411 ++++++++++++++++++++++
 3 files changed, 423 insertions(+)
 create mode 100644 drivers/video/backlight/ddcci-backlight.c

diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index e32694c13da5..7a26088c3c3f 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -289,6 +289,17 @@ config BACKLIGHT_QCOM_WLED
 	  If you have the Qualcomm PMIC, say Y to enable a driver for the
 	  WLED block. Currently it supports PM8941 and PMI8998.
 
+config BACKLIGHT_DDCCI
+	tristate "DDCCI Backlight Driver"
+	depends on DDCCI
+	help
+	  If you have a DDC/CI supporing monitor, say Y to enable a driver
+	  to control its backlight using DDC/CI. This could be useful if
+	  your monitor does not include a backlight driver. For this to be
+	  useful you need to enable DDCCI support which can be found in
+	  Device Drivers -> Character devices and that further depends on
+	  I2C.
+
 config BACKLIGHT_RT4831
 	tristate "Richtek RT4831 Backlight Driver"
 	depends on MFD_RT4831
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index cae2c83422ae..7bfb6e506b35 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -58,3 +58,4 @@ obj-$(CONFIG_BACKLIGHT_WM831X)		+= wm831x_bl.o
 obj-$(CONFIG_BACKLIGHT_ARCXCNN) 	+= arcxcnn_bl.o
 obj-$(CONFIG_BACKLIGHT_RAVE_SP)		+= rave-sp-backlight.o
 obj-$(CONFIG_BACKLIGHT_LED)		+= led_bl.o
+obj-$(CONFIG_BACKLIGHT_DDCCI)		+= ddcci-backlight.o
diff --git a/drivers/video/backlight/ddcci-backlight.c b/drivers/video/backlight/ddcci-backlight.c
new file mode 100644
index 000000000000..d37eb142311d
--- /dev/null
+++ b/drivers/video/backlight/ddcci-backlight.c
@@ -0,0 +1,411 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *  DDC/CI monitor backlight driver
+ *
+ *  Copyright (c) 2015 Christoph Grenz
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/backlight.h>
+#include <linux/module.h>
+#include <linux/fb.h>
+#include <linux/sysfs.h>
+
+#include <linux/ddcci.h>
+
+
+#define DDCCI_COMMAND_READ	0x01	/* read ctrl value */
+#define DDCCI_REPLY_READ	0x02	/* read ctrl value reply */
+#define DDCCI_COMMAND_WRITE	0x03	/* write ctrl value */
+#define DDCCI_COMMAND_SAVE	0x0c	/* save current settings */
+
+#define DDCCI_MONITOR_LUMINANCE	0x10
+#define DDCCI_MONITOR_BACKLIGHT	0x13
+#define DDCCI_MONITOR_BL_WHITE		0x6B
+
+static bool convenience_symlink = true;
+
+struct ddcci_monitor_drv_data {
+	struct ddcci_device *device;
+	struct backlight_device *bl_dev;
+	struct device *fb_dev;
+	unsigned char used_vcp;
+};
+
+static int ddcci_monitor_writectrl(struct ddcci_device *device,
+				   unsigned char ctrl, unsigned short value)
+{
+	unsigned char buf[4];
+	int ret;
+
+	buf[0] = DDCCI_COMMAND_WRITE;
+	buf[1] = ctrl;
+	buf[2] = (value >> 8);
+	buf[3] = (value & 255);
+
+	ret = ddcci_device_write(device, true, buf, sizeof(buf));
+
+	return ret;
+}
+
+static int ddcci_monitor_readctrl(struct ddcci_device *device,
+				  unsigned char ctrl, unsigned short *value,
+				  unsigned short *maximum)
+{
+	int ret;
+	unsigned char buf[10];
+
+	buf[0] = DDCCI_COMMAND_READ;
+	buf[1] = ctrl;
+
+	ret = ddcci_device_writeread(device, true, buf, 2, sizeof(buf));
+	if (ret < 0)
+		return ret;
+
+	if (ret == 0)
+		return -ENOTSUPP;
+
+	if (ret == 8 && buf[0] == DDCCI_REPLY_READ && buf[2] == ctrl) {
+		if (value)
+			*value = buf[6] * 256 + buf[7];
+
+		if (maximum)
+			*maximum = buf[4] * 256 + buf[5];
+
+		if (buf[1] == 1)
+			return -ENOTSUPP;
+		if (buf[1] != 0)
+			return -EIO;
+		return 0;
+	}
+
+	return -EIO;
+}
+
+static int ddcci_backlight_check_fb(struct backlight_device *bl,
+				   struct fb_info *info)
+{
+	struct ddcci_monitor_drv_data *drv_data = bl_get_data(bl);
+
+	return drv_data->fb_dev == NULL || drv_data->fb_dev == info->dev;
+}
+
+static int ddcci_backlight_update_status(struct backlight_device *bl)
+{
+	struct ddcci_monitor_drv_data *drv_data = bl_get_data(bl);
+	int brightness = bl->props.brightness;
+	int ret;
+
+	if (bl->props.power != FB_BLANK_UNBLANK ||
+	    bl->props.state & BL_CORE_FBBLANK)
+		brightness = 0;
+
+	ret = ddcci_monitor_writectrl(drv_data->device, drv_data->used_vcp,
+				      brightness);
+	if (ret > 0)
+		ret = 0;
+	return ret;
+}
+
+static int ddcci_backlight_get_brightness(struct backlight_device *bl)
+{
+	unsigned short value = 0, maxval = 0;
+	int ret;
+	struct ddcci_monitor_drv_data *drv_data = bl_get_data(bl);
+
+	ret = ddcci_monitor_readctrl(drv_data->device, drv_data->used_vcp,
+				     &value, &maxval);
+	if (ret < 0)
+		return ret;
+
+	bl->props.brightness = value;
+	bl->props.max_brightness = maxval;
+	ret = value;
+
+	return ret;
+}
+
+static const struct backlight_ops ddcci_backlight_ops = {
+	.options	= 0,
+	.update_status	= ddcci_backlight_update_status,
+	.get_brightness = ddcci_backlight_get_brightness,
+	.check_fb	= ddcci_backlight_check_fb,
+};
+
+static const char *ddcci_monitor_vcp_name(unsigned char vcp)
+{
+	switch (vcp) {
+	case DDCCI_MONITOR_BL_WHITE:
+		return "backlight";
+	case DDCCI_MONITOR_LUMINANCE:
+		return "luminance";
+	default:
+		return "???";
+	}
+}
+
+static const char *ddcci_monitor_next_vcp_item(const char *ptr)
+{
+	int depth = 0;
+
+	/* Sanity check */
+	if (ptr == NULL || ptr[0] == '\0')
+		return NULL;
+
+	/* Find next white space outside of parentheses */
+	while ((ptr = strpbrk(ptr, " ()"))) {
+		if (!ptr || depth == INT_MAX)
+			return NULL;
+		else if (*ptr == '(')
+			depth++;
+		else if (depth > 0) {
+			if (*ptr == ')')
+				depth--;
+		} else
+			break;
+		++ptr;
+	}
+
+	/* Skip over whitespace */
+	ptr = skip_spaces(ptr);
+
+	/* Check if we're now at the end of the list */
+	if (*ptr == '\0' || *ptr == ')')
+		return NULL;
+
+	return ptr;
+}
+
+static bool ddcci_monitor_find_vcp(unsigned char vcp, const char *s)
+{
+	const char *ptr = s;
+	char vcp_hex[3];
+
+	/* Sanity check */
+	if (s == NULL || s[0] == '\0')
+		return false;
+
+	/* Create hex representation of VCP */
+	if (snprintf(vcp_hex, 3, "%02hhX", vcp) != 2) {
+		pr_err("snprintf failed to convert to hex. This should not happen.\n");
+		return false;
+	}
+
+	/* Search for it */
+	do {
+		if (strncasecmp(vcp_hex, ptr, 2) == 0) {
+			if (ptr[2] == ' ' || ptr[2] == '(' || ptr[2] == ')')
+				return true;
+		}
+	} while ((ptr = ddcci_monitor_next_vcp_item(ptr)));
+
+	return false;
+}
+
+static int ddcci_backlight_create_symlink(struct ddcci_device *ddcci_dev)
+{
+	int i, result;
+	struct device *dev = &ddcci_dev->dev;
+	struct kernfs_node *dirent;
+
+	for (i = 0; i < 3; ++i) {
+		dev = dev->parent;
+		if (!dev) {
+			dev_dbg(&ddcci_dev->dev, "failed to create convenience symlink: ancestor device not found\n");
+			return -ENOENT;
+		}
+	}
+	dirent = sysfs_get_dirent(dev->kobj.sd, "ddcci_backlight");
+	if (dirent) {
+		sysfs_put(dirent);
+		dev_dbg(&ddcci_dev->dev, "failed to create convenience symlink: %s/ddcci_backlight already exists\n", dev_name(dev));
+		return -EEXIST;
+	}
+
+	result = sysfs_create_link(&dev->kobj, &ddcci_dev->dev.kobj, "ddcci_backlight");
+	if (result == 0)
+		dev_dbg(&ddcci_dev->dev, "created symlink %s/ddcci_backlight\n", dev_name(dev));
+	else
+		dev_info(&ddcci_dev->dev, "failed to create convenience symlink: %d\n", result);
+	return result;
+}
+
+static int ddcci_backlight_remove_symlink(struct ddcci_device *ddcci_dev)
+{
+	int i;
+	struct device *dev = &ddcci_dev->dev;
+	struct kernfs_node *dirent;
+
+	for (i = 0; i < 3; ++i) {
+		dev = dev->parent;
+		if (!dev)
+			return -ENOENT;
+	}
+	dirent = sysfs_get_dirent(dev->kobj.sd, "ddcci_backlight");
+	if (!dirent)
+		return -ENOENT;
+
+	if ((dirent->flags & KERNFS_LINK) == 0) {
+		sysfs_put(dirent);
+		dev_dbg(&ddcci_dev->dev, "won't remove %s/ddcci_backlight: not a symlink\n", dev_name(dev));
+		return -EINVAL;
+	}
+
+	if (dirent->symlink.target_kn != ddcci_dev->dev.kobj.sd) {
+		sysfs_put(dirent);
+		dev_dbg(&ddcci_dev->dev, "won't remove %s/ddcci_backlight: we are not the link target\n", dev_name(dev));
+		return -EINVAL;
+	}
+
+	sysfs_put(dirent);
+
+	sysfs_remove_link(&dev->kobj, "ddcci_backlight");
+	dev_dbg(&ddcci_dev->dev, "removed symlink %s/ddcci_backlight\n", dev_name(dev));
+	return 0;
+}
+
+static int ddcci_monitor_probe(struct ddcci_device *dev,
+			       const struct ddcci_device_id *id)
+{
+	struct ddcci_monitor_drv_data *drv_data;
+	struct backlight_properties props;
+	struct backlight_device *bl = NULL;
+	int ret = 0;
+	bool support_luminance, support_bl_white;
+	unsigned short brightness = 0, max_brightness = 0;
+	const char *vcps;
+
+	dev_dbg(&dev->dev, "probing monitor backlight device\n");
+
+	/* Get VCP list */
+	vcps = ddcci_find_capstr_item(dev->capabilities, "vcp", NULL);
+	if (IS_ERR(vcps)) {
+		dev_info(&dev->dev,
+			 "monitor doesn't provide a list of supported controls.\n");
+		support_bl_white = support_luminance = true;
+	} else {
+		/* Check VCP list for supported VCPs */
+		support_bl_white = ddcci_monitor_find_vcp(DDCCI_MONITOR_BL_WHITE, vcps);
+		support_luminance = ddcci_monitor_find_vcp(DDCCI_MONITOR_LUMINANCE, vcps);
+		/* Fallback to trying if no support is found */
+		if (!support_bl_white && !support_luminance) {
+			dev_info(&dev->dev,
+				 "monitor doesn't announce support for backlight or luminance controls.\n");
+			support_bl_white = support_luminance = true;
+		}
+	}
+
+	/* Initialize driver data structure */
+	drv_data = devm_kzalloc(&dev->dev, sizeof(struct ddcci_monitor_drv_data),
+				GFP_KERNEL);
+	if (!drv_data)
+		return -ENOMEM;
+	drv_data->device = dev;
+
+	if (support_bl_white) {
+		/* Try getting backlight level */
+		dev_dbg(&dev->dev,
+			"trying to access \"backlight level white\" control\n");
+		ret = ddcci_monitor_readctrl(drv_data->device, DDCCI_MONITOR_BL_WHITE,
+						&brightness, &max_brightness);
+		if (ret < 0) {
+			if (ret == -ENOTSUPP)
+				dev_info(&dev->dev,
+					"monitor does not support reading backlight level\n");
+			else
+				goto err_free;
+		} else {
+			drv_data->used_vcp = DDCCI_MONITOR_BL_WHITE;
+		}
+	}
+
+	if (support_luminance && !drv_data->used_vcp) {
+		/* Try getting luminance */
+		dev_dbg(&dev->dev,
+			"trying to access \"luminance\" control\n");
+		ret = ddcci_monitor_readctrl(drv_data->device, DDCCI_MONITOR_LUMINANCE,
+					     &brightness, &max_brightness);
+		if (ret < 0) {
+			if (ret == -ENOTSUPP)
+				dev_info(&dev->dev,
+					"monitor does not support reading luminance\n");
+			else
+				goto err_free;
+		} else {
+			drv_data->used_vcp = DDCCI_MONITOR_LUMINANCE;
+		}
+		drv_data->used_vcp = DDCCI_MONITOR_LUMINANCE;
+	}
+
+	if (!drv_data->used_vcp)
+		goto err_free;
+
+	/* Create brightness device */
+	memset(&props, 0, sizeof(props));
+	props.type = BACKLIGHT_RAW;
+	props.max_brightness = max_brightness;
+	props.brightness = brightness;
+	bl = devm_backlight_device_register(&dev->dev, dev_name(&dev->dev),
+					    &dev->dev, drv_data,
+					    &ddcci_backlight_ops, &props);
+	drv_data->bl_dev = bl;
+	if (IS_ERR(bl)) {
+		dev_err(&dev->dev, "failed to register backlight\n");
+		return PTR_ERR(bl);
+	}
+	dev_info(&dev->dev, "registered %s as backlight device %s\n",
+		 ddcci_monitor_vcp_name(drv_data->used_vcp),
+		 dev_name(&dev->dev));
+
+	if (convenience_symlink)
+		ddcci_backlight_create_symlink(dev);
+
+	goto end;
+err_free:
+	devm_kfree(&dev->dev, drv_data);
+end:
+	return ret;
+}
+
+static int ddcci_monitor_remove(struct ddcci_device *dev)
+{
+	dev_dbg(&dev->dev, "removing device\n");
+	ddcci_backlight_remove_symlink(dev);
+	return 0;
+}
+
+static struct ddcci_device_id ddcci_monitor_idtable[] = {
+	{ "monitor", DDCCI_ANY_ID, DDCCI_ANY_ID, DDCCI_ANY_ID, DDCCI_ANY_ID, 0 },
+	{}
+};
+
+static struct ddcci_driver ddcci_backlight_driver = {
+	.driver = {
+		.name	= "ddcci-backlight",
+		.owner	= THIS_MODULE,
+	},
+
+	.id_table	= ddcci_monitor_idtable,
+	.probe		= ddcci_monitor_probe,
+	.remove		= ddcci_monitor_remove,
+};
+
+module_ddcci_driver(ddcci_backlight_driver);
+
+/* Module parameter description */
+module_param(convenience_symlink, bool, 0644);
+MODULE_PARM_DESC(convenience_symlink, "add convenience symlink \"ddcci_backlight\" to ancestor device in sysfs (default true)");
+
+MODULE_AUTHOR("Christoph Grenz <christophg+lkml@grenz-bonn.de>");
+MODULE_DESCRIPTION("DDC/CI generic monitor backlight driver");
+MODULE_VERSION("0.4.2");
+MODULE_LICENSE("GPL");
+
+MODULE_ALIAS("ddcci:monitor-*-*-*-*");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v10 3/3] drivers: ddcci: add drivers for DDCCI
  2022-04-03 23:08 [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI Yusuf Khan
  2022-04-03 23:08 ` [PATCH v10 1/3] " Yusuf Khan
  2022-04-03 23:08 ` [PATCH v10 2/3] " Yusuf Khan
@ 2022-04-03 23:08 ` Yusuf Khan
  2022-04-03 23:34 ` [PATCH v10 0/3] " Randy Dunlap
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Yusuf Khan @ 2022-04-03 23:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: jasowang, mikelley, mst, gregkh, javier, arnd, will, axboe,
	Yusuf Khan, Christoph Grenz

This patch adds Documentation for the DDCCI drivers.

Signed-off-by: Yusuf Khan <yusisamerican@gmail.com>
Signed-off-by: Christoph Grenz <christophg+lkml@grenz-bonn.de>
---
 Documentation/ABI/testing/sysfs-driver-ddcci |  57 +++++++++
 Documentation/driver-api/ddcci.rst           | 122 +++++++++++++++++++
 2 files changed, 179 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-ddcci
 create mode 100644 Documentation/driver-api/ddcci.rst

diff --git a/Documentation/ABI/testing/sysfs-driver-ddcci b/Documentation/ABI/testing/sysfs-driver-ddcci
new file mode 100644
index 000000000000..19f77ccf3ed0
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-driver-ddcci
@@ -0,0 +1,57 @@
+What:		/sys/bus/ddcci/ddcci<I²C bus number>i<hex address>
+Date:		March 2022
+KernelVersion:	5.18
+Contact:	Christoph Grenz <christophg+lkml@grenz-bonn.de>
+Description:	This file is a user interface for an internal
+		dependent device on the I2C bus, it exports the same
+		information as the master device(/sys/bus/ddcci/
+		ddcci<I²C bus number>) that is referenced in this
+		document.
+
+What:		/sys/bus/ddcci/ddcci<I²C bus number>e<hex address>
+Date:		March 2022
+KernelVersion:	5.18
+Contact:	Christoph Grenz <christophg+lkml@grenz-bonn.de>
+Description:	This file is a user interface for an external
+		dependent device on the I2C bus, it exports the same
+		information as the master device(/sys/bus/ddcci/
+		ddcci<I²C bus number>) that is referenced in this
+		document.
+
+What:		/sys/bus/ddcci/ddcci<I²C bus number>
+Date:		March 2022
+KernelVersion:	5.18
+Contact:	Christoph Grenz <christophg+lkml@grenz-bonn.de>
+Description:	This file provides the user interface for the
+		master device on the I2C bus. It exports the following
+		peices of information:
+		- idProt
+		ACCESS.bus protocol supported by the device. Usually
+		"monitor".
+
+		- idType
+		ACCESS.bus device subtype. Usually "LCD" or "CRT".
+
+		- idModel
+		ACCESS.bus device model identifier. Usually a
+		shortened form of the device model name.
+
+		- idVendor
+		ACCESS.bus device vendor identifier. Empty if the
+		Identification command is not supported.
+
+		- idModule
+		ACCESS.bus device module identifier. Empty if the
+		Identification command is not supported.
+
+		- idSerial
+		32 bit device number. A fixed serial number if it's
+		positive, a temporary serial number if negative and zero
+		if the Identification command is not supported.
+
+		- modalias
+		A combined identifier for driver selection. It has the form:
+		ddcci:<idProt>-<idType>-<idModel>-<idVendor>-<idModule>.
+		All non-alphanumeric characters (including whitespace)
+		in the model, vendor or module parts are replaced by
+		underscores to prevent issues with software like systemd-udevd.
diff --git a/Documentation/driver-api/ddcci.rst b/Documentation/driver-api/ddcci.rst
new file mode 100644
index 000000000000..2b7de1ac2656
--- /dev/null
+++ b/Documentation/driver-api/ddcci.rst
@@ -0,0 +1,122 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+==============
+DDC/CI
+==============
+
+1. Introduction
+===============
+DDC/CI is a control protocol for monitor settings supported by most
+monitors since about 2005. It is based on ACCESS.bus (an early USB predecessor).
+This could be used to create drivers that communicate with the DDCCI component,
+see ddcci-backlight for an example.
+
+2. sysfs interface
+==================
+Each detected DDC/CI device gets a directory in /sys/bus/ddcci/devices.
+The main device on a bus is named ddcci[I²C bus number].
+Internal dependent devices are named ddcci[I²C bus number]i[hex address]
+External dependent devices are named ddcci[I²C bus number]e[hex address]
+There the following files export information about the device:
+
+capabilities
+The full ACCESS.bus capabilities string. It contains the protocol,
+type and model of the device, a list of all supported command
+codes, etc. See the ACCESS.bus spec for more information.
+
+- idProt
+ACCESS.bus protocol supported by the device. Usually "monitor".
+
+- idType
+ACCESS.bus device subtype. Usually "LCD" or "CRT".
+
+- idModel
+ACCESS.bus device model identifier. Usually a shortened form of the
+device model name.
+
+- idVendor
+ACCESS.bus device vendor identifier. Empty if the Identification command
+is not supported.
+
+- idModule
+ACCESS.bus device module identifier. Empty if the Identification command
+is not supported.
+
+- idSerial
+32 bit device number. A fixed serial number if it's positive, a temporary
+serial number if negative and zero if the
+Identification command is not supported.
+
+- modalias
+A combined identifier for driver selection. It has the form:
+ddcci:<idProt>-<idType>-<idModel>-<idVendor>-<idModule>.
+All non-alphanumeric characters (including whitespace) in the model,
+vendor or module parts are replaced by underscores to prevent issues
+with software like systemd-udevd.
+
+3. Character device interface
+=============================
+For each DDC/CI device a character device in
+/dev/bus/ddcci/[I²C bus number]/ is created,
+127 devices are assigned in total.
+
+The main device on the bus is named display.
+
+Internal dependent devices are named i[hex address]
+
+External dependent devices are named e[hex address]
+
+These character devices can be used to issue commands to a DDC/CI device
+more easily than over i2c-dev devices. They should be opened unbuffered.
+To send a command just write the command byte and the arguments with a
+single write() operation. The length byte and checksum are automatically
+calculated.
+
+To read a response use read() with a buffer big enough for the expected answer.
+
+NOTE: The maximum length of a DDC/CI message is 32 bytes.
+
+4. ddcci-backlight (monitor backlight driver)
+=============================================
+[This is not specific to the DDC/CI backlight driver, if you already dealt with
+backlight drivers, skip over this.]
+
+For each monitor that supports accessing the Backlight Level White
+or the Luminance property, a backlight device of type "raw" named like the
+corresponding ddcci device is created. You can find them in /sys/class/backlight/.
+For convenience a symlink "ddcci_backlight" on the device associated with the
+display connector in /sys/class/drm/ to the backlight device is created, as
+long as the graphics driver allows to make this association.
+
+5. Limitations
+==============
+
+-Dependent devices (sub devices using DDC/CI directly wired to the monitor,
+like  Calibration devices, IR remotes, etc.) aren't automatically detected.
+You can force detection of external dependent devices by writing
+"ddcci-dependent [address]" into /sys/bus/i2c/i2c-?/new_device.
+
+There is no direct synchronization if you manually change the luminance
+with the buttons on your monitor, as this can only be realized through polling
+and some monitors close their OSD every time a DDC/CI command is received.
+
+Monitor hotplugging is not detected. You need to detach/reattach the I²C driver
+or reload the module.
+
+6. Debugging
+============
+Both drivers use the dynamic debugging feature of the Linux kernel.
+To get detailed debugging messages, set the dyndbg module parameter.
+If you want to enable debugging permanently across reboots, create a file
+/etc/modprobe.d/ddcci.conf containing lines like the following before loading the modules:
+
+options ddcci dyndbg
+options ddcci-backlight dyndbg
+
+7. Origin
+============
+This driver originally came from Christoph Grenz in DKMS form here:
+https://gitlab.com/ddcci-driver-linux/ddcci-driver-linux
+with multiple backups available on the wayback machine. It also
+inlcudes a example program for the usage of this driver in
+userland.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI
  2022-04-03 23:08 [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI Yusuf Khan
                   ` (2 preceding siblings ...)
  2022-04-03 23:08 ` [PATCH v10 3/3] " Yusuf Khan
@ 2022-04-03 23:34 ` Randy Dunlap
  2022-04-04  4:57 ` Greg KH
  2022-04-04 11:10   ` Hans de Goede
  5 siblings, 0 replies; 13+ messages in thread
From: Randy Dunlap @ 2022-04-03 23:34 UTC (permalink / raw)
  To: Yusuf Khan, linux-kernel
  Cc: jasowang, mikelley, mst, gregkh, javier, arnd, will, axboe,
	Christoph Grenz, kernel test robot

Hi--

On 4/3/22 16:08, Yusuf Khan wrote:
> This patch adds the DDCCI driver by Christoph Grenz into the kernel.
> The original gitlab page is loacted at https://gitlab.com/ddcci-driv
> er-linux/ddcci-driver-linux/-/tree/master.
> 
...

> 
> v10: Change patch title to "drivers: ddcci: add drivers for DDCCI
> and change" and change patch descriptions to add more detailed
> explanations of function.

Greg KH recently said [1] that the Subject: for each patch should not
be the same, yet they still are the same. This is not good.


[1] https://lore.kernel.org/lkml/YkANDAyCMBBBWEs0@kroah.com/

-- 
~Randy

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI
  2022-04-03 23:08 [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI Yusuf Khan
                   ` (3 preceding siblings ...)
  2022-04-03 23:34 ` [PATCH v10 0/3] " Randy Dunlap
@ 2022-04-04  4:57 ` Greg KH
  2022-04-04 11:10   ` Hans de Goede
  5 siblings, 0 replies; 13+ messages in thread
From: Greg KH @ 2022-04-04  4:57 UTC (permalink / raw)
  To: Yusuf Khan
  Cc: linux-kernel, jasowang, mikelley, mst, javier, arnd, will, axboe,
	Christoph Grenz, kernel test robot

On Sun, Apr 03, 2022 at 04:08:48PM -0700, Yusuf Khan wrote:
> v10: Change patch title to "drivers: ddcci: add drivers for DDCCI
> and change" and change patch descriptions to add more detailed
> explanations of function.

As Randy points out, the subjects can not all be the same as obviously
the patches are not doing all the same thing.  Please read the kernel
documentation for how to write good subject lines and good changelog
texts.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v10 1/3] drivers: ddcci: add drivers for DDCCI
  2022-04-03 23:08 ` [PATCH v10 1/3] " Yusuf Khan
@ 2022-04-04  4:58   ` Greg KH
  2022-04-04 13:11   ` [PATCH] drivers: ddcci: fix platform_no_drv_owner.cocci warnings kernel test robot
  2022-04-04 13:14   ` [PATCH v10 1/3] drivers: ddcci: add drivers for DDCCI kernel test robot
  2 siblings, 0 replies; 13+ messages in thread
From: Greg KH @ 2022-04-04  4:58 UTC (permalink / raw)
  To: Yusuf Khan
  Cc: linux-kernel, jasowang, mikelley, mst, javier, arnd, will, axboe,
	Christoph Grenz

On Sun, Apr 03, 2022 at 04:08:49PM -0700, Yusuf Khan wrote:
> This patch adds the main DDCCI driver. This interfaces with I2C to allow the
> kernel to communicate with DDCCI supporting monitors, it exports a chardev
> and sysfs interface for userspace.

Where is the Documentation/ABI/ entries for the sysfs code, and where is
the userspace code that uses the chardev interface?  And why chardev?

This text says _what_ you are doing, but not _why_ you are doing it.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI
  2022-04-03 23:08 [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI Yusuf Khan
@ 2022-04-04 11:10   ` Hans de Goede
  2022-04-03 23:08 ` [PATCH v10 2/3] " Yusuf Khan
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Hans de Goede @ 2022-04-04 11:10 UTC (permalink / raw)
  To: Yusuf Khan, linux-kernel, Sebastian Wick, dri-devel, Martin Peres
  Cc: jasowang, mikelley, mst, gregkh, javier, arnd, will, axboe,
	Christoph Grenz, kernel test robot

Hi Yusuf,

On 4/4/22 01:08, Yusuf Khan wrote:
> This patch adds the DDCCI driver by Christoph Grenz into the kernel.
> The original gitlab page is loacted at https://gitlab.com/ddcci-driv
> er-linux/ddcci-driver-linux/-/tree/master.
> 
> DDC/CI is a control protocol for monitor settings supported by most
> monitors since about 2005. A chardev and sysfs interface is provided.
> A backlight driver using DDCCI is also provided in the seccond patch.
> 
> Signed-off-by: Yusuf Khan <yusisamerican@gmail.com>
> Signed-off-by: Christoph Grenz <christophg+lkml@grenz-bonn.de>

Thank you for your submission of this patch series.

I must say that I'm a bit surprised that this series was NOT
also send to the drm/kms subsystem maintainers and mailinglists
since this deals with monitors and thus is highly relevant for
those folks. Luckily I saw an article about this at Phoronix
(you write in the changelog that you believe that there is
no interaction with the DRM/KMS subsystems but that is wrong).

One very important thing which I'm missing in this cover-letter
is why you want to have this in the kernel at all? There are
already various tools which do DDCCI from userspace just fine.

I guess you may be interested in offering /sys/class/backlight
functionality for external monitors. That is actually something
which I'm interested in too, but it is not that simple.

The current /sys/class/backlight interface does not offer a
way for userspace to map a /sys/class/backlight device to
a specific display-output / monitor. So userspace currently
assumes that there is only 1 (1 valid) /sys/class/backlight
device and that that *always* belongs to the internal LCD
panel of a laptop.

So just adding /sys/class/backlight device(s) for internal
monitors without addressing the short-comings of the existing
userspace interface is simply not possible because it would
break existing userspace which is something which is not
allowed.

So NACK from me for the backlight part at least and without
that, I really see no reason to do this in the kernel rather
then userspace.

I've recently been discussing this with a colleague of mine,
Sebastian Wick and as a result of that I'm giving a talk
with a proposal for a better userspace API for this at
kernel-recipes:
https://kernel-recipes.org/en/2022/talks/new-userspace-api-for-display-panel-brightness-control/

I hope to start working on a RFC patch series for this soon.

IMHO merging this series should be put on hold until we
have a better idea of how we want to solve the userspace
API challenges, esp. the monitor <-> /sys/class/backlight
mapping problem.

Regards,

Hans



p.s.

This is not the first time this has come up:

https://lore.kernel.org/all/4b17ba08-39f3-57dd-5aad-d37d844b02c6@linux.intel.com/
https://www.x.org/wiki/Events/XDC2014/XDC2014GoedeBacklight/



> ---
> v2: Fix typos.
> 
> v3: Add documentation, move files around, replace semaphores with
> mutexes, and replaced <asm-generic/fcntl.h> with <linux/fcntl.h>.
> "imirkin"(which due to his involvement in the dri-devel irc channel
> I cant help but assume to be a DRM developer) said that the DDC/CI
> bus does not intefere with the buses that DRM is involved with.
> 
> v4: Move some documentation, fix grammer mistakes, remove usages of
> likely(), and clarify some documentation.
> 
> v5: Fix grammer mistakes, remove usages of likely(), and clarify
> some documentation.
> 
> v6: Change contact information to reference Christoph Grenz.
> 
> v7: Remove all instances of the unlikely() macro.
> 
> v8: Modify documentation to provide updated date and kernel
> documentation, fix SPDX lines, use isalpha instead of redefining
> logic, change maximum amount of bytes that can be written to be
> conformant with DDC/CI specification, prevent userspace from holding
> locks with the open file descriptor, remove ddcci_cdev_seek, dont
> refine sysfs_emit() logic, use EXPORT_SYMBOL_GPL instead of
> EXPORT_SYMBOL, remove ddcci_device_remove_void, remove module
> paramaters and version, and split into 2 patches.
> 
> v9: Fix IS_ANY_ID matching for compilers and archs where char is
> unsigned char and use the cannonical patch format.
> Reported-by: kernel test robot <lkp@intel.com>
> 
> v10: Change patch title to "drivers: ddcci: add drivers for DDCCI
> and change" and change patch descriptions to add more detailed
> explanations of function.
> 
> Patch 1: Add the main DDCCI component.
> 
> Patch 2: Add the backlight driver that utilizes the DDCCI driver.
> 
> Patch 3: Add documentation for the DDCCI drivers.
> 
> Yusuf Khan (3):
>   drivers: ddcci: add drivers for DDCCI
>   drivers: ddcci: add drivers for DDCCI
>   drivers: ddcci: add drivers for DDCCI
> 
>  Documentation/ABI/testing/sysfs-driver-ddcci |   57 +
>  Documentation/driver-api/ddcci.rst           |  122 ++
>  drivers/char/Kconfig                         |   11 +
>  drivers/char/Makefile                        |    1 +
>  drivers/char/ddcci.c                         | 1805 ++++++++++++++++++
>  drivers/video/backlight/Kconfig              |   11 +
>  drivers/video/backlight/Makefile             |    1 +
>  drivers/video/backlight/ddcci-backlight.c    |  411 ++++
>  include/linux/ddcci.h                        |  163 ++
>  9 files changed, 2582 insertions(+)
>  create mode 100644 Documentation/ABI/testing/sysfs-driver-ddcci
>  create mode 100644 Documentation/driver-api/ddcci.rst
>  create mode 100644 drivers/char/ddcci.c
>  create mode 100644 drivers/video/backlight/ddcci-backlight.c
>  create mode 100644 include/linux/ddcci.h
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI
@ 2022-04-04 11:10   ` Hans de Goede
  0 siblings, 0 replies; 13+ messages in thread
From: Hans de Goede @ 2022-04-04 11:10 UTC (permalink / raw)
  To: Yusuf Khan, linux-kernel, Sebastian Wick, dri-devel, Martin Peres
  Cc: axboe, javier, kernel test robot, arnd, mst, gregkh, jasowang,
	Christoph Grenz, mikelley, will

Hi Yusuf,

On 4/4/22 01:08, Yusuf Khan wrote:
> This patch adds the DDCCI driver by Christoph Grenz into the kernel.
> The original gitlab page is loacted at https://gitlab.com/ddcci-driv
> er-linux/ddcci-driver-linux/-/tree/master.
> 
> DDC/CI is a control protocol for monitor settings supported by most
> monitors since about 2005. A chardev and sysfs interface is provided.
> A backlight driver using DDCCI is also provided in the seccond patch.
> 
> Signed-off-by: Yusuf Khan <yusisamerican@gmail.com>
> Signed-off-by: Christoph Grenz <christophg+lkml@grenz-bonn.de>

Thank you for your submission of this patch series.

I must say that I'm a bit surprised that this series was NOT
also send to the drm/kms subsystem maintainers and mailinglists
since this deals with monitors and thus is highly relevant for
those folks. Luckily I saw an article about this at Phoronix
(you write in the changelog that you believe that there is
no interaction with the DRM/KMS subsystems but that is wrong).

One very important thing which I'm missing in this cover-letter
is why you want to have this in the kernel at all? There are
already various tools which do DDCCI from userspace just fine.

I guess you may be interested in offering /sys/class/backlight
functionality for external monitors. That is actually something
which I'm interested in too, but it is not that simple.

The current /sys/class/backlight interface does not offer a
way for userspace to map a /sys/class/backlight device to
a specific display-output / monitor. So userspace currently
assumes that there is only 1 (1 valid) /sys/class/backlight
device and that that *always* belongs to the internal LCD
panel of a laptop.

So just adding /sys/class/backlight device(s) for internal
monitors without addressing the short-comings of the existing
userspace interface is simply not possible because it would
break existing userspace which is something which is not
allowed.

So NACK from me for the backlight part at least and without
that, I really see no reason to do this in the kernel rather
then userspace.

I've recently been discussing this with a colleague of mine,
Sebastian Wick and as a result of that I'm giving a talk
with a proposal for a better userspace API for this at
kernel-recipes:
https://kernel-recipes.org/en/2022/talks/new-userspace-api-for-display-panel-brightness-control/

I hope to start working on a RFC patch series for this soon.

IMHO merging this series should be put on hold until we
have a better idea of how we want to solve the userspace
API challenges, esp. the monitor <-> /sys/class/backlight
mapping problem.

Regards,

Hans



p.s.

This is not the first time this has come up:

https://lore.kernel.org/all/4b17ba08-39f3-57dd-5aad-d37d844b02c6@linux.intel.com/
https://www.x.org/wiki/Events/XDC2014/XDC2014GoedeBacklight/



> ---
> v2: Fix typos.
> 
> v3: Add documentation, move files around, replace semaphores with
> mutexes, and replaced <asm-generic/fcntl.h> with <linux/fcntl.h>.
> "imirkin"(which due to his involvement in the dri-devel irc channel
> I cant help but assume to be a DRM developer) said that the DDC/CI
> bus does not intefere with the buses that DRM is involved with.
> 
> v4: Move some documentation, fix grammer mistakes, remove usages of
> likely(), and clarify some documentation.
> 
> v5: Fix grammer mistakes, remove usages of likely(), and clarify
> some documentation.
> 
> v6: Change contact information to reference Christoph Grenz.
> 
> v7: Remove all instances of the unlikely() macro.
> 
> v8: Modify documentation to provide updated date and kernel
> documentation, fix SPDX lines, use isalpha instead of redefining
> logic, change maximum amount of bytes that can be written to be
> conformant with DDC/CI specification, prevent userspace from holding
> locks with the open file descriptor, remove ddcci_cdev_seek, dont
> refine sysfs_emit() logic, use EXPORT_SYMBOL_GPL instead of
> EXPORT_SYMBOL, remove ddcci_device_remove_void, remove module
> paramaters and version, and split into 2 patches.
> 
> v9: Fix IS_ANY_ID matching for compilers and archs where char is
> unsigned char and use the cannonical patch format.
> Reported-by: kernel test robot <lkp@intel.com>
> 
> v10: Change patch title to "drivers: ddcci: add drivers for DDCCI
> and change" and change patch descriptions to add more detailed
> explanations of function.
> 
> Patch 1: Add the main DDCCI component.
> 
> Patch 2: Add the backlight driver that utilizes the DDCCI driver.
> 
> Patch 3: Add documentation for the DDCCI drivers.
> 
> Yusuf Khan (3):
>   drivers: ddcci: add drivers for DDCCI
>   drivers: ddcci: add drivers for DDCCI
>   drivers: ddcci: add drivers for DDCCI
> 
>  Documentation/ABI/testing/sysfs-driver-ddcci |   57 +
>  Documentation/driver-api/ddcci.rst           |  122 ++
>  drivers/char/Kconfig                         |   11 +
>  drivers/char/Makefile                        |    1 +
>  drivers/char/ddcci.c                         | 1805 ++++++++++++++++++
>  drivers/video/backlight/Kconfig              |   11 +
>  drivers/video/backlight/Makefile             |    1 +
>  drivers/video/backlight/ddcci-backlight.c    |  411 ++++
>  include/linux/ddcci.h                        |  163 ++
>  9 files changed, 2582 insertions(+)
>  create mode 100644 Documentation/ABI/testing/sysfs-driver-ddcci
>  create mode 100644 Documentation/driver-api/ddcci.rst
>  create mode 100644 drivers/char/ddcci.c
>  create mode 100644 drivers/video/backlight/ddcci-backlight.c
>  create mode 100644 include/linux/ddcci.h
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH] drivers: ddcci: fix platform_no_drv_owner.cocci warnings
  2022-04-03 23:08 ` [PATCH v10 1/3] " Yusuf Khan
  2022-04-04  4:58   ` Greg KH
@ 2022-04-04 13:11   ` kernel test robot
  2022-04-04 13:14   ` [PATCH v10 1/3] drivers: ddcci: add drivers for DDCCI kernel test robot
  2 siblings, 0 replies; 13+ messages in thread
From: kernel test robot @ 2022-04-04 13:11 UTC (permalink / raw)
  To: Yusuf Khan, linux-kernel
  Cc: kbuild-all, jasowang, mikelley, mst, gregkh, javier, arnd, will,
	axboe, Yusuf Khan, Christoph Grenz

From: kernel test robot <lkp@intel.com>

drivers/char/ddcci.c:1721:3-8: No need to set .owner here. The core will do it.

 Remove .owner field if calls are used which set it automatically

Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci

CC: Yusuf Khan <yusisamerican@gmail.com>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: kernel test robot <lkp@intel.com>
---

url:    https://github.com/intel-lab-lkp/linux/commits/Yusuf-Khan/drivers-ddcci-add-drivers-for-DDCCI/20220404-080905
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 37fd83916da2e4cae03d350015c82a67b1b334c4
:::::: branch date: 13 hours ago
:::::: commit date: 13 hours ago

 drivers/char/ddcci.c |    1 -
 1 file changed, 1 deletion(-)

--- a/drivers/char/ddcci.c
+++ b/drivers/char/ddcci.c
@@ -1718,7 +1718,6 @@ MODULE_DEVICE_TABLE(i2c, ddcci_idtable);
 static struct i2c_driver ddcci_driver = {
 	.driver = {
 		.name	= "ddcci",
-		.owner	= THIS_MODULE,
 	},
 
 	.id_table	= ddcci_idtable,

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v10 1/3] drivers: ddcci: add drivers for DDCCI
  2022-04-03 23:08 ` [PATCH v10 1/3] " Yusuf Khan
  2022-04-04  4:58   ` Greg KH
  2022-04-04 13:11   ` [PATCH] drivers: ddcci: fix platform_no_drv_owner.cocci warnings kernel test robot
@ 2022-04-04 13:14   ` kernel test robot
  2 siblings, 0 replies; 13+ messages in thread
From: kernel test robot @ 2022-04-04 13:14 UTC (permalink / raw)
  To: Yusuf Khan, linux-kernel
  Cc: kbuild-all, jasowang, mikelley, mst, gregkh, javier, arnd, will,
	axboe, Yusuf Khan, Christoph Grenz

Hi Yusuf,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on linus/master lee-backlight/for-backlight-next linux/master v5.18-rc1 next-20220404]
[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/intel-lab-lkp/linux/commits/Yusuf-Khan/drivers-ddcci-add-drivers-for-DDCCI/20220404-080905
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 37fd83916da2e4cae03d350015c82a67b1b334c4
config: i386-randconfig-c003-20220404 (https://download.01.org/0day-ci/archive/20220404/202204042140.TxY1fuSX-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.2.0-19) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


cocci warnings: (new ones prefixed by >>)
>> drivers/char/ddcci.c:1721:3-8: No need to set .owner here. The core will do it.

Please review and possibly fold the followup patch.

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v10 1/3] drivers: ddcci: add drivers for DDCCI
@ 2022-04-05 23:18 kernel test robot
  0 siblings, 0 replies; 13+ messages in thread
From: kernel test robot @ 2022-04-05 23:18 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 16662 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220403230850.2986-2-yusisamerican@gmail.com>
References: <20220403230850.2986-2-yusisamerican@gmail.com>
TO: Yusuf Khan <yusisamerican@gmail.com>
TO: linux-kernel(a)vger.kernel.org
CC: jasowang(a)redhat.com
CC: mikelley(a)microsoft.com
CC: mst(a)redhat.com
CC: gregkh(a)linuxfoundation.org
CC: javier(a)javigon.com
CC: arnd(a)arndb.de
CC: will(a)kernel.org
CC: axboe(a)kernel.dk
CC: Yusuf Khan <yusisamerican@gmail.com>
CC: Christoph Grenz <christophg+lkml@grenz-bonn.de>

Hi Yusuf,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on linus/master lee-backlight/for-backlight-next linux/master v5.18-rc1 next-20220405]
[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/intel-lab-lkp/linux/commits/Yusuf-Khan/drivers-ddcci-add-drivers-for-DDCCI/20220404-080905
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 37fd83916da2e4cae03d350015c82a67b1b334c4
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: x86_64-randconfig-c007-20220404 (https://download.01.org/0day-ci/archive/20220406/202204060730.maLYRE0n-lkp(a)intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project c4a1b07d0979e7ff20d7d541af666d822d66b566)
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/d2cd44349035e12259c3b06514ca5deccc5b2a3c
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Yusuf-Khan/drivers-ddcci-add-drivers-for-DDCCI/20220404-080905
        git checkout d2cd44349035e12259c3b06514ca5deccc5b2a3c
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)
               ^~~~~~
   drivers/acpi/acpi_video.c:954:2: note: Taking false branch
           if (result)
           ^
   drivers/acpi/acpi_video.c:961:6: note: Assuming field '_BQC' is not equal to 0
           if (!device->cap._BQC)
               ^~~~~~~~~~~~~~~~~
   drivers/acpi/acpi_video.c:961:2: note: Taking false branch
           if (!device->cap._BQC)
           ^
   drivers/acpi/acpi_video.c:966:6: note: 'result' is 0
           if (result)
               ^~~~~~
   drivers/acpi/acpi_video.c:966:2: note: Taking false branch
           if (result)
           ^
   drivers/acpi/acpi_video.c:970:6: note: 'result' is 0
           if (result)
               ^~~~~~
   drivers/acpi/acpi_video.c:970:2: note: Taking false branch
           if (result)
           ^
   drivers/acpi/acpi_video.c:976:19: note: Field '_BQC' is not equal to 0
           if (!device->cap._BQC)
                            ^
   drivers/acpi/acpi_video.c:976:2: note: Taking false branch
           if (!device->cap._BQC)
           ^
   drivers/acpi/acpi_video.c:979:10: note: Calling 'acpi_video_bqc_value_to_level'
           level = acpi_video_bqc_value_to_level(device, level_old);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/acpi_video.c:576:6: note: Branch condition evaluates to a garbage value
           if (device->brightness->flags._BQC_use_index) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/acpi_video.c:1171:2: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
           ^~~~~~
   drivers/acpi/acpi_video.c:1171:2: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
           strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
           ^~~~~~
   drivers/acpi/acpi_video.c:1172:2: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
           ^~~~~~
   drivers/acpi/acpi_video.c:1172:2: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
           strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
           ^~~~~~
   drivers/acpi/acpi_video.c:2067:2: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
           ^~~~~~
   drivers/acpi/acpi_video.c:2067:2: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
           strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
           ^~~~~~
   drivers/acpi/acpi_video.c:2068:2: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
           ^~~~~~
   drivers/acpi/acpi_video.c:2068:2: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
           strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
           ^~~~~~
   Suppressed 5 warnings (4 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (5 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (5 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (5 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (5 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (5 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (5 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (5 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
>> drivers/char/ddcci.c:1213:3: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores]
                   ret = driver->remove(device);
                   ^     ~~~~~~~~~~~~~~~~~~~~~~
   drivers/char/ddcci.c:1213:3: note: Value stored to 'ret' is never read
                   ret = driver->remove(device);
                   ^     ~~~~~~~~~~~~~~~~~~~~~~
   Suppressed 5 warnings (4 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   drivers/char/pcmcia/cm4000_cs.c:1570:4: warning: Value stored to 'rc' is never read [clang-analyzer-deadcode.DeadStores]
                           rc = 0;
                           ^    ~
   drivers/char/pcmcia/cm4000_cs.c:1570:4: note: Value stored to 'rc' is never read
                           rc = 0;
                           ^    ~
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   8 warnings generated.
   crypto/ecc.c:147:24: warning: The left operand of '&' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]
           return (vli[bit / 64] & ((u64)1 << (bit % 64)));
                                 ^
   crypto/ecc.c:1618:6: note: Assuming 'private_key' is non-null
           if (!private_key || !public_key || !curve ||
               ^~~~~~~~~~~~
   crypto/ecc.c:1618:6: note: Left side of '||' is false
   crypto/ecc.c:1618:22: note: Assuming 'public_key' is non-null
           if (!private_key || !public_key || !curve ||
                               ^~~~~~~~~~~
   crypto/ecc.c:1618:6: note: Left side of '||' is false
           if (!private_key || !public_key || !curve ||
               ^
   crypto/ecc.c:1618:38: note: 'curve' is non-null
           if (!private_key || !public_key || !curve ||
                                               ^~~~~
   crypto/ecc.c:1618:6: note: Left side of '||' is false
           if (!private_key || !public_key || !curve ||
               ^
   crypto/ecc.c:1619:6: note: Assuming the condition is false
               ndigits > ARRAY_SIZE(priv) || ndigits > ARRAY_SIZE(rand_z)) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   crypto/ecc.c:1618:6: note: Left side of '||' is false
           if (!private_key || !public_key || !curve ||
               ^
   crypto/ecc.c:1618:2: note: Taking false branch
           if (!private_key || !public_key || !curve ||
           ^
   crypto/ecc.c:1629:7: note: 'pk' is non-null
           if (!pk) {
                ^~
   crypto/ecc.c:1629:2: note: Taking false branch
           if (!pk) {
           ^
   crypto/ecc.c:1636:8: note: Calling 'ecc_is_pubkey_valid_partial'
           ret = ecc_is_pubkey_valid_partial(curve, pk);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   crypto/ecc.c:1553:14: note: Assuming 'pk->ndigits' is equal to 'curve->g.ndigits'
           if (WARN_ON(pk->ndigits != curve->g.ndigits))
                       ^
   include/asm-generic/bug.h:121:25: note: expanded from macro 'WARN_ON'
           int __ret_warn_on = !!(condition);                              \
                                  ^~~~~~~~~
   crypto/ecc.c:1553:6: note: Taking false branch
           if (WARN_ON(pk->ndigits != curve->g.ndigits))
               ^
   include/asm-generic/bug.h:122:2: note: expanded from macro 'WARN_ON'
           if (unlikely(__ret_warn_on))                                    \
           ^
   crypto/ecc.c:1553:2: note: Taking false branch
           if (WARN_ON(pk->ndigits != curve->g.ndigits))
           ^
   crypto/ecc.c:1557:2: note: Taking false branch
           if (ecc_point_is_zero(pk))
           ^
   crypto/ecc.c:1561:2: note: Taking false branch
           if (vli_cmp(curve->p, pk->x, pk->ndigits) != 1)
           ^
   crypto/ecc.c:1563:2: note: Taking false branch
           if (vli_cmp(curve->p, pk->y, pk->ndigits) != 1)
           ^
   crypto/ecc.c:1567:2: note: Calling 'vli_mod_square_fast'
           vli_mod_square_fast(yy, pk->y, curve); /* y^2 */
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   crypto/ecc.c:982:2: note: Calling 'vli_mmod_fast'

vim +/ret +1213 drivers/char/ddcci.c

d2cd44349035e1 Yusuf Khan 2022-04-03  1201  
d2cd44349035e1 Yusuf Khan 2022-04-03  1202  static void ddcci_device_remove(struct device *dev)
d2cd44349035e1 Yusuf Khan 2022-04-03  1203  {
d2cd44349035e1 Yusuf Khan 2022-04-03  1204  	struct ddcci_device	*device = ddcci_verify_device(dev);
d2cd44349035e1 Yusuf Khan 2022-04-03  1205  	struct ddcci_driver	*driver;
d2cd44349035e1 Yusuf Khan 2022-04-03  1206  	int ret = 0;
d2cd44349035e1 Yusuf Khan 2022-04-03  1207  
d2cd44349035e1 Yusuf Khan 2022-04-03  1208  	if (!device)
d2cd44349035e1 Yusuf Khan 2022-04-03  1209  		return;
d2cd44349035e1 Yusuf Khan 2022-04-03  1210  	driver = to_ddcci_driver(dev->driver);
d2cd44349035e1 Yusuf Khan 2022-04-03  1211  
d2cd44349035e1 Yusuf Khan 2022-04-03  1212  	if (driver->remove)
d2cd44349035e1 Yusuf Khan 2022-04-03 @1213  		ret = driver->remove(device);
d2cd44349035e1 Yusuf Khan 2022-04-03  1214  }
d2cd44349035e1 Yusuf Khan 2022-04-03  1215  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v10 1/3] drivers: ddcci: add drivers for DDCCI
@ 2022-04-04 10:19 kernel test robot
  0 siblings, 0 replies; 13+ messages in thread
From: kernel test robot @ 2022-04-04 10:19 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 4484 bytes --]

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220403230850.2986-2-yusisamerican@gmail.com>
References: <20220403230850.2986-2-yusisamerican@gmail.com>
TO: Yusuf Khan <yusisamerican@gmail.com>
TO: linux-kernel(a)vger.kernel.org
CC: jasowang(a)redhat.com
CC: mikelley(a)microsoft.com
CC: mst(a)redhat.com
CC: gregkh(a)linuxfoundation.org
CC: javier(a)javigon.com
CC: arnd(a)arndb.de
CC: will(a)kernel.org
CC: axboe(a)kernel.dk
CC: Yusuf Khan <yusisamerican@gmail.com>
CC: Christoph Grenz <christophg+lkml@grenz-bonn.de>

Hi Yusuf,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on linus/master lee-backlight/for-backlight-next linux/master v5.18-rc1 next-20220404]
[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/intel-lab-lkp/linux/commits/Yusuf-Khan/drivers-ddcci-add-drivers-for-DDCCI/20220404-080905
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 37fd83916da2e4cae03d350015c82a67b1b334c4
:::::: branch date: 10 hours ago
:::::: commit date: 10 hours ago
compiler: mipsel-linux-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


cppcheck possible warnings: (new ones prefixed by >>, may not real problems)

>> drivers/char/ddcci.c:678:6: warning: Redundant initialization for 'ret'. The initialized value is overwritten before it is read. [redundantInitialization]
    ret = cdev_add(&device->cdev, ddcci_cdev_next, 1);
        ^
   drivers/char/ddcci.c:663:10: note: ret is initialized
    int ret = -EINVAL;
            ^
   drivers/char/ddcci.c:678:6: note: ret is overwritten
    ret = cdev_add(&device->cdev, ddcci_cdev_next, 1);
        ^
   drivers/char/ddcci.c:1616:7: warning: Redundant initialization for 'ret'. The initialized value is overwritten before it is read. [redundantInitialization]
     ret = ddcci_detect_device(client, main_addr, 0);
         ^
   drivers/char/ddcci.c:1597:13: note: ret is initialized
    int i, ret = -ENODEV, tmp;
               ^
   drivers/char/ddcci.c:1616:7: note: ret is overwritten
     ret = ddcci_detect_device(client, main_addr, 0);
         ^

vim +/ret +678 drivers/char/ddcci.c

d2cd44349035e1 Yusuf Khan 2022-04-03  659  
d2cd44349035e1 Yusuf Khan 2022-04-03  660  /* Set up the character device for a DDC/CI device */
d2cd44349035e1 Yusuf Khan 2022-04-03  661  static int ddcci_setup_char_device(struct ddcci_device *device)
d2cd44349035e1 Yusuf Khan 2022-04-03  662  {
d2cd44349035e1 Yusuf Khan 2022-04-03  663  	int ret = -EINVAL;
d2cd44349035e1 Yusuf Khan 2022-04-03  664  
d2cd44349035e1 Yusuf Khan 2022-04-03  665  	/* Check if free minor exists */
d2cd44349035e1 Yusuf Khan 2022-04-03  666  	if (ddcci_cdev_next == ddcci_cdev_end) {
d2cd44349035e1 Yusuf Khan 2022-04-03  667  		dev_err(&device->dev, "no free major/minor\n");
d2cd44349035e1 Yusuf Khan 2022-04-03  668  		ret = -ENFILE;
d2cd44349035e1 Yusuf Khan 2022-04-03  669  		goto out;
d2cd44349035e1 Yusuf Khan 2022-04-03  670  	}
d2cd44349035e1 Yusuf Khan 2022-04-03  671  
d2cd44349035e1 Yusuf Khan 2022-04-03  672  	/* Initialize character device node */
d2cd44349035e1 Yusuf Khan 2022-04-03  673  	cdev_init(&device->cdev, &ddcci_fops);
d2cd44349035e1 Yusuf Khan 2022-04-03  674  	device->cdev.owner = THIS_MODULE;
d2cd44349035e1 Yusuf Khan 2022-04-03  675  
d2cd44349035e1 Yusuf Khan 2022-04-03  676  	/* Publish char device */
d2cd44349035e1 Yusuf Khan 2022-04-03  677  	device->dev.devt = ddcci_cdev_next;
d2cd44349035e1 Yusuf Khan 2022-04-03 @678  	ret = cdev_add(&device->cdev, ddcci_cdev_next, 1);
d2cd44349035e1 Yusuf Khan 2022-04-03  679  	if (ret) {
d2cd44349035e1 Yusuf Khan 2022-04-03  680  		device->dev.devt = 0;
d2cd44349035e1 Yusuf Khan 2022-04-03  681  		goto out;
d2cd44349035e1 Yusuf Khan 2022-04-03  682  	}
d2cd44349035e1 Yusuf Khan 2022-04-03  683  
d2cd44349035e1 Yusuf Khan 2022-04-03  684  	ddcci_cdev_next++;
d2cd44349035e1 Yusuf Khan 2022-04-03  685  out:
d2cd44349035e1 Yusuf Khan 2022-04-03  686  	return ret;
d2cd44349035e1 Yusuf Khan 2022-04-03  687  }
d2cd44349035e1 Yusuf Khan 2022-04-03  688  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-04-05 23:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03 23:08 [PATCH v10 0/3] drivers: ddcci: add drivers for DDCCI Yusuf Khan
2022-04-03 23:08 ` [PATCH v10 1/3] " Yusuf Khan
2022-04-04  4:58   ` Greg KH
2022-04-04 13:11   ` [PATCH] drivers: ddcci: fix platform_no_drv_owner.cocci warnings kernel test robot
2022-04-04 13:14   ` [PATCH v10 1/3] drivers: ddcci: add drivers for DDCCI kernel test robot
2022-04-03 23:08 ` [PATCH v10 2/3] " Yusuf Khan
2022-04-03 23:08 ` [PATCH v10 3/3] " Yusuf Khan
2022-04-03 23:34 ` [PATCH v10 0/3] " Randy Dunlap
2022-04-04  4:57 ` Greg KH
2022-04-04 11:10 ` Hans de Goede
2022-04-04 11:10   ` Hans de Goede
2022-04-04 10:19 [PATCH v10 1/3] " kernel test robot
2022-04-05 23:18 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.