Skip to contentSkip to conversation

Add SECO Boards CEC device driver

PATCH Superseded ektor5 5 participants 25 messages Oct 2, 2018 – Oct 11, 2018 Media (V4L/DVB)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

ektor5

author
#0 lore raw

cover Add SECO Boards CEC device driver

This series of patches aims to add CEC functionalities to SECO devices, in particular UDOO X86.

The communication is achieved via Braswell SMBus (i2c-i801) to the onboard STM32 microcontroller that handles the CEC signals. The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Ettore Chimenti (2):
media: add SECO cec driver
seco-cec: add Consumer-IR support

 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  21 +
 drivers/media/platform/Makefile            |   4 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 859 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 143 ++++
 6 files changed, 1034 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
Signature · 1 line
2.18.0
author
#1 lore raw

PATCH 1/2 media: add SECO cec driver

From: Ettore Chimenti <[email protected]>

This patch adds support to the CEC device implemented with a STM32 microcontroller in X86 SECO Boards, including UDOO X86.

The communication is achieved via Braswell integrated SMBus (i2c-i801). The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Inspired by cros-ec-cec implementation, attaches to i915 driver cec-notifier.

---
 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  11 +
 drivers/media/platform/Makefile            |   4 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 729 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 132 ++++
 6 files changed, 883 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
MAINTAINERS +6 -0
index 4ece30f15777..1062912a5ff4 100644
@@ -12972,6 +12972,12 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 F:	drivers/mmc/host/sdricoh_cs.c
 
+SECO BOARDS CEC DRIVER
+M:	Ettore Chimenti <[email protected]>
+S:	Maintained
+F:	drivers/media/platform/seco-cec/seco-cec.c
+F:	drivers/media/platform/seco-cec/seco-cec.h
+
 SECURE COMPUTING
 M:	Kees Cook <[email protected]>
 R:	Andy Lutomirski <[email protected]>
drivers/media/platform/Kconfig +11 -0
index 94c1fe0e9787..f477764b902a 100644
@@ -613,6 +613,17 @@ config VIDEO_TEGRA_HDMI_CEC
 	 The CEC bus is present in the HDMI connector and enables communication
 	 between compatible devices.
 
+config VIDEO_SECO_CEC
+       tristate "SECO Boards HDMI CEC driver"
+       depends on (X86 || IA64) || COMPILE_TEST
+       select CEC_CORE
+       select CEC_NOTIFIER
+       help
+         This is a driver for SECO Boards integrated CEC interface. It uses the
+         generic CEC framework interface.
+         CEC bus is present in the HDMI connector and enables communication
+         between compatible devices.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/Makefile +4 -0
index 41322ab65802..cc7365c787ba 100644
@@ -53,6 +53,10 @@ obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC)	+= tegra-cec/
 
 obj-y					+= stm32/
 
+obj-$(CONFIG_VIDEO_SECO_CEC)		+= seco-cec/
+
+obj-y                                   += blackfin/
+
 obj-y					+= davinci/
 
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
drivers/media/platform/seco-cec/Makefile new file +1 -0
new file mode 100644
index 000000000000..a3f2c6bd3ac0
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_SECO_CEC) += seco-cec.o
drivers/media/platform/seco-cec/seco-cec.c new file +729 -0

729 lines not on this page · raw message

drivers/media/platform/seco-cec/seco-cec.h new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
2.18.0
author
#8 lore raw

PATCH 2/2 seco-cec: add Consumer-IR support

In reply to ektor5

From: Ettore Chimenti <[email protected]>

Introduce support for Consumer-IR into seco-cec driver, as it shares the same interrupt for receiving messages.
The device decodes RC5 signals only, defaults to hauppauge mapping. It will spawn an input interface using the RC framework (like CEC device).

---
 drivers/media/platform/Kconfig             |  10 ++
 drivers/media/platform/seco-cec/seco-cec.c | 136 ++++++++++++++++++++-
 drivers/media/platform/seco-cec/seco-cec.h |  11 ++
 3 files changed, 154 insertions(+), 3 deletions(-)
drivers/media/platform/Kconfig +10 -0
index f477764b902a..5833f488eef8 100644
@@ -624,6 +624,16 @@ config VIDEO_SECO_CEC
          CEC bus is present in the HDMI connector and enables communication
          between compatible devices.
 
+config VIDEO_SECO_RC
+       bool "SECO Boards IR RC5 support"
+       depends on VIDEO_SECO_CEC
+       select RC_CORE
+       help
+	 If you say yes here you will get support for the
+	 SECO Boards Consumer-IR in seco-cec driver.
+         The embedded controller supports RC5 protocol only, default mapping
+         is set to rc-hauppauge.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/seco-cec/seco-cec.c +133 -3

181 lines not on this page · raw message

drivers/media/platform/seco-cec/seco-cec.h +11 -0
index cc7f0cba8e9e..c00660104a3e 100644
@@ -101,6 +101,17 @@
 
 #define SECOCEC_IR_READ_DATA		0x3e
 
+/*
+ * IR
+ */
+
+#define SECOCEC_IR_COMMAND_MASK		0x007F
+#define SECOCEC_IR_COMMAND_SHL		0
+#define SECOCEC_IR_ADDRESS_MASK		0x1F00
+#define SECOCEC_IR_ADDRESS_SHL		7
+#define SECOCEC_IR_TOGGLE_MASK		0x8000
+#define SECOCEC_IR_TOGGLE_SHL		15
+
 /*
  * Enabling register
  */
Signature · 1 line
2.18.0
#2 lore raw

Re: [PATCH 1/2] media: add SECO cec driver

In reply to ektor5

Hi Ettore,
thanks for the patch.

A few comments below, please have a look...

Quoted 51 lines · On Tue, Oct 02, 2018 at 06:59:55PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

This patch adds support to the CEC device implemented with a STM32 microcontroller in X86 SECO Boards, including UDOO X86.

The communication is achieved via Braswell integrated SMBus (i2c-i801). The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Inspired by cros-ec-cec implementation, attaches to i915 driver cec-notifier.

---
 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  11 +
 drivers/media/platform/Makefile            |   4 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 729 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 132 ++++
 6 files changed, 883 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
MAINTAINERS +6 -0
index 4ece30f15777..1062912a5ff4 100644
@@ -12972,6 +12972,12 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 F:	drivers/mmc/host/sdricoh_cs.c
 
+SECO BOARDS CEC DRIVER
+M:	Ettore Chimenti <[email protected]>
+S:	Maintained
+F:	drivers/media/platform/seco-cec/seco-cec.c
+F:	drivers/media/platform/seco-cec/seco-cec.h
+
 SECURE COMPUTING
 M:	Kees Cook <[email protected]>
 R:	Andy Lutomirski <[email protected]>
drivers/media/platform/Kconfig +0 -0
index 94c1fe0e9787..f477764b902a 100644
@@ -613,6 +613,17 @@ config VIDEO_TEGRA_HDMI_CEC
 	 The CEC bus is present in the HDMI connector and enables communication

drivers/media/platform/Kconfig config VIDEO_TEGRA_HDMI_CEC · line 623

Quoted 10 lines
drivers/media/platform/Kconfig +8 -0
 	 between compatible devices.
 
+config VIDEO_SECO_CEC
+       tristate "SECO Boards HDMI CEC driver"
+       depends on (X86 || IA64) || COMPILE_TEST
+       select CEC_CORE
+       select CEC_NOTIFIER
+       help
+         This is a driver for SECO Boards integrated CEC interface. It uses the
+         generic CEC framework interface.

Is it worth mentioning the software framework used for implementing the driver? Anyway, I see this is common to most of the CEC drivers here, so I guess it is fine

Quoted 11 lines
drivers/media/platform/Kconfig +3 -0
+         CEC bus is present in the HDMI connector and enables communication
+         between compatible devices.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/Makefile +0 -0
index 41322ab65802..cc7365c787ba 100644

drivers/media/platform/Makefile obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC) += tegra-cec/ · line 59

Quoted 7 lines
drivers/media/platform/Makefile +4 -0
@@ -53,6 +53,10 @@ obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC)	+= tegra-cec/
 
 obj-y					+= stm32/
 
+obj-$(CONFIG_VIDEO_SECO_CEC)		+= seco-cec/
+
+obj-y                                   += blackfin/
+

Ups! Is this a leftover from some BSP code? It breaks the build on media-tree master (and I guess on master too)

drivers/media/platform/seco-cec/Makefile line 1

Quoted 10 lines
drivers/media/platform/Makefile +0 -0
 obj-y					+= davinci/
 
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
drivers/media/platform/seco-cec/Makefile new file +1 -0
new file mode 100644
index 000000000000..a3f2c6bd3ac0
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_SECO_CEC) += seco-cec.o

This can simply be obj-y as you parse this makefile entry conditionally to the presence of the CONFIG_VIDEO_SECO_CEC symbol

drivers/media/platform/seco-cec/seco-cec.c line 1

Quoted 7 lines
drivers/media/platform/seco-cec/seco-cec.c new file +1 -0
new file mode 100644
index 000000000000..ba3b7c144a87
@@ -0,0 +1,729 @@
+// SPDX-License-Identifier: GPL-2.0 AND BSD-3-Clause

Just make sure the AND is what you want (I only see OR clauses in drivers/ code). See Documentation/process/license-rules.rst

drivers/media/platform/seco-cec/seco-cec.c line 3

Quoted 2 lines
drivers/media/platform/seco-cec/seco-cec.c new file +2 -0
+/*
+ *

Nit: empty comment line

drivers/media/platform/seco-cec/seco-cec.c line 9

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+ * CEC driver for SECO X86 Boards
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ *

Nit: empty comment line

Quoted 5 lines
drivers/media/platform/seco-cec/seco-cec.c new file +5 -0
+ */
+
+#include <linux/interrupt.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>

drivers/media/platform/seco-cec/seco-cec.c line 24

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/dmi.h>
+
+/* CEC Framework */
+#include <media/cec.h>
+
+#include "seco-cec.h"

I would question why a header file is needed as it is not included by anything else

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+struct secocec_data {
+	struct device *dev;
+	struct platform_device *pdev;
+	struct cec_adapter *cec_adap;
+	struct cec_notifier *notifier;
+	int irq;
+};
+
+#define smb_wr16(cmd, data) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \

drivers/media/platform/seco-cec/seco-cec.c line 44

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+					     cmd, data, SMBUS_WRITE, NULL)
+#define smb_rd16(cmd, res) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \
+				       cmd, 0, SMBUS_READ, res)
+
+static int smb_word_op(short data_format, u16 slave_addr, u8 cmd, u16 data,
+		       u8 operation, u16 *result)
+{
+	unsigned int count;
+	short _data_format;
+	int ret, status = 0;

In the rest of the function ret is used only once, and you can use status in its place. Please drop one of the two.

Quoted 13 lines
drivers/media/platform/seco-cec/seco-cec.c new file +13 -0
+
+	switch (data_format) {
+	case CMD_BYTE_DATA:
+		_data_format = BRA_SMB_CMD_BYTE_DATA;
+		break;
+	case CMD_WORD_DATA:
+		_data_format = BRA_SMB_CMD_WORD_DATA;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Active wait until ready */

drivers/media/platform/seco-cec/seco-cec.c line 67

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	for (count = 0; count <= SMBTIMEOUT; ++count) {
+		if (!(inb(HSTS) & BRA_INUSE_STS))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		/* Reset the lock instead of failing */
+		outb(0xff, HSTS);
+		pr_warn("%s: SMBTIMEOUT\n", __func__);

No pr_debug/pr_warn if possible, please.

Quoted 65 lines
drivers/media/platform/seco-cec/seco-cec.c new file +65 -0
+	}
+
+	outb(0x00, HCNT);
+	outb((u8)(slave_addr & 0xfe) | operation, XMIT_SLVA);
+	outb(cmd, HCMD);
+	inb(HCNT);
+
+	if (operation == SMBUS_WRITE) {
+		outb((u8)data, HDAT0);
+		outb((u8)(data >> 8), HDAT1);
+		pr_debug("%s: WRITE (0x%02x - count %05d): 0x%04x\n",
+			 __func__, cmd, count, data);
+	}
+
+	outb(BRA_START + _data_format, HCNT);
+
+	for (count = 0; count <= SMBTIMEOUT; count++) {
+		if (!(inb(HSTS) & BRA_HOST_BUSY))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		pr_debug("%s: SMBTIMEOUT_1\n", __func__);
+		status = -EBUSY;
+		goto err;
+	}
+
+	ret = inb(HSTS);
+	if (ret & BRA_HSTS_ERR_MASK) {
+		pr_debug("%s: HSTS(0x%02X): 0x%X\n", __func__, cmd, ret);
+		status = -EIO;
+		goto err;
+	}
+
+	if (operation == SMBUS_READ) {
+		*result = ((inb(HDAT0) & 0xff) + ((inb(HDAT1) & 0xff) << 8));
+		pr_debug("%s: READ (0x%02x - count %05d): 0x%04x\n",
+			 __func__, cmd, count, *result);
+	}
+
+err:
+	outb(0xff, HSTS);
+	return status;
+}
+
+static int secocec_adap_enable(struct cec_adapter *adap, bool enable)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 val = 0;
+	int status;
+
+	if (enable) {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Enable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);

drivers/media/platform/seco-cec/seco-cec.c line 142

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1,
+				  val | SECOCEC_ENABLE_REG_1_CEC);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device enabled");
+

Empty line

Quoted 172 lines
drivers/media/platform/seco-cec/seco-cec.c new file +172 -0
+	} else {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Disable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+				  ~SECOCEC_ENABLE_REG_1_CEC &
+				  ~SECOCEC_ENABLE_REG_1_IR);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device disabled");
+	}
+
+	return 0;
+err:
+	dev_err(dev, "Adapter setup failed (%d)", status);
+	return status;
+}
+
+static int secocec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr)
+{
+	u16 enable_val = 0;
+	int status;
+
+	/* Disable device */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &enable_val);
+	if (status)
+		return status;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val & ~SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	/* Write logical address */
+	status = smb_wr16(SECOCEC_DEVICE_LA, logical_addr);
+	if (status)
+		return status;
+
+	/* Re-enable device */
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	return 0;
+}
+
+static int secocec_adap_transmit(struct cec_adapter *adap, u8 attempts,
+				 u32 signal_free_time, struct cec_msg *msg)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 payload_len, payload_id_len, destination, val = 0;
+	u8 *payload_msg;
+	int status;
+	u8 i;
+
+	/* Device msg len already accounts for header */
+	payload_id_len = msg->len - 1;
+
+	/* Send data length */
+	status = smb_wr16(SECOCEC_WRITE_DATA_LENGTH, payload_id_len);
+	if (status)
+		goto err;
+
+	/* Send Operation ID if present */
+	if (payload_id_len > 0) {
+		status = smb_wr16(SECOCEC_WRITE_OPERATION_ID, msg->msg[1]);
+		if (status)
+			goto err;
+	}
+	/* Send data if present */
+	if (payload_id_len > 1) {
+		/* Only data; */
+		payload_len = msg->len - 2;
+		payload_msg = &msg->msg[2];
+
+		/* Copy message into registers */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			/* hi byte */
+			val = payload_msg[(i << 1) + 1] << 8;
+
+			/* lo byte */
+			val |= payload_msg[(i << 1)];
+
+			status = smb_wr16(SECOCEC_WRITE_DATA_00 + i, val);
+			if (status)
+				goto err;
+		}
+	}
+	/* Send msg source/destination and fire msg */
+	destination = msg->msg[0];
+	status = smb_wr16(SECOCEC_WRITE_BYTE0, destination);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Transmit failed (%d)", status);
+	return status;
+}
+
+static int secocec_tx_done(struct cec_adapter *adap, u16 status_val)
+{
+	int status = 0;
+
+	if (status_val & SECOCEC_STATUS_TX_ERROR_MASK) {
+		if (status_val & SECOCEC_STATUS_TX_NACK_ERROR) {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_NACK);
+			status = -EAGAIN;
+		} else {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_ERROR);
+			status = -EIO;
+		}
+	} else {
+		cec_transmit_attempt_done(adap, CEC_TX_STATUS_OK);
+	}
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_TX_ERROR_MASK |
+		SECOCEC_STATUS_MSG_SENT_MASK |
+		SECOCEC_STATUS_TX_NACK_ERROR;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+	return status;
+}
+
+static int secocec_rx_done(struct cec_adapter *adap, u16 status_val)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	struct cec_msg msg = { };
+	bool flag_overflow = false;
+	u8 payload_len, i = 0;
+	u8 *payload_msg;
+	u16 val = 0;
+	int status;
+
+	if (status_val & SECOCEC_STATUS_RX_OVERFLOW_MASK) {
+		dev_warn(dev, "Received more than 16 bytes. Discarding");
+		flag_overflow = true;
+	}
+
+	if (status_val & SECOCEC_STATUS_RX_ERROR_MASK) {
+		dev_warn(dev, "Message received with errors. Discarding");
+		status = -EIO;
+		goto rxerr;
+	}
+
+	/* Read message length */
+	status = smb_rd16(SECOCEC_READ_DATA_LENGTH, &val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Incoming message (payload len %d):", val);
+
+	/* Device msg len already accounts for the header */
+	msg.len = min(val + 1, CEC_MAX_MSG_SIZE);
+

drivers/media/platform/seco-cec/seco-cec.c line 324

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	/* Read logical address */
+	status = smb_rd16(SECOCEC_READ_BYTE0, &val);
+	if (status)
+		goto err;
+
+	/* device stores source LA and destination */
+	msg.msg[0] = val;
+
+	/* Read operation ID if present */
+	if (msg.len > 0) {

Am I wrong or msg.len is at least (val + 1) and val is never negative? If that's true, this condition is always verified.

Quoted 65 lines
drivers/media/platform/seco-cec/seco-cec.c new file +65 -0
+		status = smb_rd16(SECOCEC_READ_OPERATION_ID, &val);
+		if (status)
+			goto err;
+
+		msg.msg[1] = val;
+	}
+
+	/* Read data if present */
+	if (msg.len > 1) {
+		payload_len = msg.len - 2;
+		payload_msg = &msg.msg[2];
+
+		/* device stores 2 bytes in every 16-bit val */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			status = smb_rd16(SECOCEC_READ_DATA_00 + i, &val);
+			if (status)
+				goto err;
+
+			/* low byte, skipping header */
+			payload_msg[(i << 1)] = val & 0x00ff;
+
+			/* hi byte */
+			payload_msg[(i << 1) + 1] = (val & 0xff00) >> 8;
+		}
+	}
+
+	cec_received_msg(cec->cec_adap, &msg);
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+
+	status = smb_wr16(SECOCEC_STATUS, status_val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Message received successfully");
+
+	return 0;
+
+rxerr:
+	/* Reset error reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK |
+		SECOCEC_STATUS_RX_ERROR_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+err:
+	dev_err(dev, "Receive message failed (%d)", status);
+	return status;
+}
+
+struct cec_adap_ops secocec_cec_adap_ops = {
+	/* Low-level callbacks */
+	.adap_enable = secocec_adap_enable,
+	.adap_log_addr = secocec_adap_log_addr,
+	.adap_transmit = secocec_adap_transmit,
+};
+
+static irqreturn_t secocec_irq_handler(int irq, void *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;

drivers/media/platform/seco-cec/seco-cec.c line 399

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	u16 status_val, cec_val, val = 0;
+	int status;
+
+	/*  Read status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &status_val);
+	if (status)
+		goto err;
+
+	if (status_val & SECOCEC_STATUS_REG_1_CEC) {
+		dev_dbg(dev, "+++++ CEC Interrupt Caught");

Just be carefull in too much printouts while handling interrupts. Also, I would not insert custom printout formats (here and below in this functions). I would simply drop this one.

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+		/* Read CEC status register */
+		status = smb_rd16(SECOCEC_STATUS, &cec_val);
+		if (status)
+			goto err;
+

drivers/media/platform/seco-cec/seco-cec.c line 415

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		if (cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK)
+			secocec_rx_done(cec->cec_adap, cec_val);
+
+		if (cec_val & SECOCEC_STATUS_MSG_SENT_MASK)
+			secocec_tx_done(cec->cec_adap, cec_val);
+
+		if ((~cec_val & SECOCEC_STATUS_MSG_SENT_MASK) &&
+		    (~cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK))
+			dev_warn(dev,
+				 "Message not received or sent, but interrupt fired \\_\"._/");

No custom funny printouts please :)

drivers/media/platform/seco-cec/seco-cec.c line 421

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+		val = SECOCEC_STATUS_REG_1_CEC;
+	}
+
+	if (status_val & SECOCEC_STATUS_REG_1_IR) {
+		dev_dbg(dev, "IR RC5 Interrupt Caught");

How frequent is this one? Do you need to print it out?

drivers/media/platform/seco-cec/seco-cec.c line 431

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		val |= SECOCEC_STATUS_REG_1_IR;
+		/* TODO IRDA RX */
+	}
+
+	/*  Reset status register */
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "----- CEC Interrupt Handled");

Drop this one please

Quoted 33 lines
drivers/media/platform/seco-cec/seco-cec.c new file +33 -0
+
+	return IRQ_HANDLED;
+
+err:
+	dev_err(dev, "IRQ: Read/Write SMBus operation failed (%d)", status);
+
+	/*  Reset status register */
+	val = SECOCEC_STATUS_REG_1_CEC | SECOCEC_STATUS_REG_1_IR;
+	smb_wr16(SECOCEC_STATUS_REG_1, val);
+
+	return IRQ_HANDLED;
+}
+
+struct cec_dmi_match {
+	char *sys_vendor;
+	char *product_name;
+	char *devname;
+	char *conn;
+};
+
+static const struct cec_dmi_match secocec_dmi_match_table[] = {
+	/* UDOO X86 */
+	{ "SECO", "UDOO x86", "0000:00:02.0", "Port B" },
+};
+
+static int secocec_cec_get_notifier(struct cec_notifier **notify)
+{
+	int i;
+
+	for (i = 0 ; i < ARRAY_SIZE(secocec_dmi_match_table) ; ++i) {
+		const struct cec_dmi_match *m = &secocec_dmi_match_table[i];
+
+		if (dmi_match(DMI_SYS_VENDOR, m->sys_vendor) &&

drivers/media/platform/seco-cec/seco-cec.c line 474

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		    dmi_match(DMI_PRODUCT_NAME, m->product_name)) {
+			struct device *d;
+
+			/* Find the device, bail out if not yet registered */
+			d = bus_find_device_by_name(&pci_bus_type, NULL,
+						    m->devname);
+			if (!d)
+				return -EPROBE_DEFER;
+
+			*notify = cec_notifier_get_conn(d, m->conn);

Nit: it's usually nice to have an empty line before return (here and in other places). Not mandatory though.

Quoted 73 lines
drivers/media/platform/seco-cec/seco-cec.c new file +73 -0
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int secocec_acpi_probe(struct secocec_data *sdev)
+{
+	struct device *dev = sdev->dev;
+	struct gpio_desc *gpio;
+	int irq = 0;
+
+	gpio = devm_gpiod_get(dev, NULL, GPIOF_IN);
+	if (IS_ERR(gpio)) {
+		dev_err(dev, "Cannot request interrupt gpio");
+		return PTR_ERR(gpio);
+	}
+
+	irq = gpiod_to_irq(gpio);
+	if (irq < 0) {
+		dev_err(dev, "Cannot find valid irq");
+		return -ENODEV;
+	}
+	dev_dbg(dev, "irq-gpio is bound to IRQ %d", irq);
+
+	sdev->irq = irq;
+
+	return 0;
+}
+
+static int secocec_probe(struct platform_device *pdev)
+{
+	struct secocec_data *secocec;
+	struct device *dev = &pdev->dev;
+	u8 cec_caps;
+	int ret;
+	u16 val;
+
+	secocec = devm_kzalloc(dev, sizeof(*secocec), GFP_KERNEL);
+	if (!secocec)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, secocec);
+
+	/* Request SMBus regions */
+	if (!request_muxed_region(BRA_SMB_BASE_ADDR, 7, "CEC00001")) {
+		dev_err(dev, "Request memory region failed");
+		return -ENXIO;
+	}
+
+	secocec->pdev = pdev;
+	secocec->dev = dev;
+
+	if (!has_acpi_companion(dev)) {
+		dev_dbg(dev, "Cannot find any ACPI companion");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	ret = secocec_acpi_probe(secocec);
+	if (ret) {
+		dev_err(dev, "Cannot assign gpio to IRQ");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	dev_dbg(dev, "IRQ detected at %d", secocec->irq);
+
+	/* Firmware version check */
+	ret = smb_rd16(SECOCEC_VERSION, &val);
+	if (ret) {
+		dev_err(dev, "Cannot check fw version");

drivers/media/platform/seco-cec/seco-cec.c line 557

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		goto err;
+	}
+	if (val < SECOCEC_LATEST_FW) {
+		dev_err(dev, "CEC Firmware not supported (v.%04x). Use ver > v.%04x",
+			val, SECOCEC_LATEST_FW);
+		ret = -EINVAL;
+		goto err;
+	}
+
+#ifdef CONFIG_CEC_NOTIFIER

Your Kconfig entry selects CEC_NOTIFIER.

(I won't comment on the cec_notifier handling part, as I don't know much. I just see other drivers registering and getting the notifier using the cec_notifier_ functions, while it seems to me you don't. Maybe it's fine...)

Quoted 65 lines
drivers/media/platform/seco-cec/seco-cec.c new file +65 -0
+	ret = secocec_cec_get_notifier(&secocec->notifier);
+	if (ret) {
+		dev_err(dev, "no CEC notifier available\n");
+		goto err;
+	}
+#endif
+
+	ret = devm_request_threaded_irq(dev,
+					secocec->irq,
+					NULL,
+					secocec_irq_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					dev_name(&pdev->dev), secocec);
+
+	if (ret) {
+		dev_err(dev, "Cannot request IRQ %d", secocec->irq);
+		ret = -EIO;
+		goto err;
+	}
+
+	/* Allocate CEC adapter */
+	cec_caps = CEC_CAP_DEFAULTS;
+
+	secocec->cec_adap = cec_allocate_adapter(&secocec_cec_adap_ops,
+						 secocec,
+						 dev_name(dev),
+						 cec_caps, SECOCEC_MAX_ADDRS);
+
+	if (IS_ERR(secocec->cec_adap)) {
+		ret = PTR_ERR(secocec->cec_adap);
+		goto err;
+	}
+
+	ret = cec_register_adapter(secocec->cec_adap, dev);
+	if (ret)
+		goto err_delete_adapter;
+
+	if (secocec->notifier)
+		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
+
+	platform_set_drvdata(pdev, secocec);
+
+	dev_dbg(dev, "Device registered");
+
+	return ret;
+
+err_delete_adapter:
+	cec_delete_adapter(secocec->cec_adap);
+err:
+	dev_err(dev, "%s device probe failed\n", dev_name(dev));
+
+	return ret;
+}
+
+/* ----------------------------------------------------------------------- */
+
+static int secocec_remove(struct platform_device *pdev)
+{
+	struct secocec_data *secocec = platform_get_drvdata(pdev);
+
+	cec_unregister_adapter(secocec->cec_adap);
+
+	if (secocec->notifier)
+		cec_notifier_put(secocec->notifier);
+

drivers/media/platform/seco-cec/seco-cec.c line 632

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	release_region(BRA_SMB_BASE_ADDR, 7);
+
+	dev_dbg(&pdev->dev, "CEC device removed");
+
+	return 0;
+}
+
+/* ----------------------------------------------------------------------- */
+
+#ifdef CONFIG_PM_SLEEP

I see CONFIG_PM_SLEEP is only selected if support for 'suspend'/'hibernate' is enabled. Is this what you want, or you should check for CONFIG_PM?

Quoted 81 lines
drivers/media/platform/seco-cec/seco-cec.c new file +81 -0
+static int secocec_suspend(struct device *dev)
+{
+	u16 val;
+	int status;
+
+	dev_dbg(dev, "Device going to suspend, disabling");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Disable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+			  ~SECOCEC_ENABLE_REG_1_CEC & ~SECOCEC_ENABLE_REG_1_IR);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Suspend failed (err: %d)", status);
+	return status;
+}
+
+static int secocec_resume(struct device *dev)
+{
+	u16 val;
+	int status;
+
+	dev_dbg(dev, "Resuming device from suspend");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Device resumed from suspend");
+
+	return 0;
+
+err:
+	dev_err(dev, "Resume failed (err: %d)", status);
+	return status;
+}
+
+static SIMPLE_DEV_PM_OPS(secocec_pm_ops, secocec_suspend, secocec_resume);
+#define SECOCEC_PM_OPS (&secocec_pm_ops)
+#else
+#define SECOCEC_PM_OPS NULL
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id secocec_acpi_match[] = {
+	{"CEC00001", 0},
+	{},
+};
+
+MODULE_DEVICE_TABLE(acpi, secocec_acpi_match);
+#endif

drivers/media/platform/seco-cec/seco-cec.c line 723

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+static struct platform_driver secocec_driver = {
+	.driver = {
+		   .name = SECOCEC_DEV_NAME,
+		   .acpi_match_table = ACPI_PTR(secocec_acpi_match),
+		   .pm = SECOCEC_PM_OPS,
+	},
+	.probe = secocec_probe,
+	.remove = secocec_remove,
+};

As you can see most of my comments are nits or trivial things. I would wait for more feedbacks on the CEC and x86/SMbus part from others before sending v2 if I were you :)

Thanks
j

Quoted 147 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+module_platform_driver(secocec_driver);
+
+MODULE_DESCRIPTION("SECO CEC X86 Driver");
+MODULE_AUTHOR("Ettore Chimenti <[email protected]>");
+MODULE_LICENSE("Dual BSD/GPL");
drivers/media/platform/seco-cec/seco-cec.h new file +132 -1
new file mode 100644
index 000000000000..cc7f0cba8e9e
@@ -0,0 +1,132 @@
+/* SPDX-License-Identifier: GPL-2.0 AND BSD-3-Clause */
+/*
+ *
+ * SECO X86 Boards CEC register defines
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ *
+ */
+
+#ifndef __SECO_CEC_H__
+#define __SECO_CEC_H__
+
+#define SECOCEC_MAX_ADDRS		1
+#define SECOCEC_DEV_NAME		"secocec"
+#define SECOCEC_LATEST_FW		0x0f0b
+
+#define SMBTIMEOUT			0xffff
+#define SMB_POLL_UDELAY			10
+
+#define SMBUS_WRITE			0
+#define SMBUS_READ			1
+
+#define CMD_BYTE_DATA			0
+#define CMD_WORD_DATA			1
+
+/*
+ * SMBus definitons for Braswell
+ */
+
+#define BRA_DONE_STATUS			BIT(7)
+#define BRA_INUSE_STS			BIT(6)
+#define BRA_FAILED_OP			BIT(4)
+#define BRA_BUS_ERR			BIT(3)
+#define BRA_DEV_ERR			BIT(2)
+#define BRA_INTR			BIT(1)
+#define BRA_HOST_BUSY			BIT(0)
+#define BRA_HSTS_ERR_MASK   (BRA_FAILED_OP | BRA_BUS_ERR | BRA_DEV_ERR)
+
+#define BRA_PEC_EN			BIT(7)
+#define BRA_START			BIT(6)
+#define BRA_LAST__BYTE			BIT(5)
+#define BRA_INTREN			BIT(0)
+#define BRA_SMB_CMD			(7 << 2)
+#define BRA_SMB_CMD_QUICK		(0 << 2)
+#define BRA_SMB_CMD_BYTE		(1 << 2)
+#define BRA_SMB_CMD_BYTE_DATA		(2 << 2)
+#define BRA_SMB_CMD_WORD_DATA		(3 << 2)
+#define BRA_SMB_CMD_PROCESS_CALL	(4 << 2)
+#define BRA_SMB_CMD_BLOCK		(5 << 2)
+#define BRA_SMB_CMD_I2CREAD		(6 << 2)
+#define BRA_SMB_CMD_BLOCK_PROCESS	(7 << 2)
+
+#define BRA_SMB_BASE_ADDR  0x2040
+#define HSTS               (BRA_SMB_BASE_ADDR + 0)
+#define HCNT               (BRA_SMB_BASE_ADDR + 2)
+#define HCMD               (BRA_SMB_BASE_ADDR + 3)
+#define XMIT_SLVA          (BRA_SMB_BASE_ADDR + 4)
+#define HDAT0              (BRA_SMB_BASE_ADDR + 5)
+#define HDAT1              (BRA_SMB_BASE_ADDR + 6)
+
+/*
+ * Microcontroller Address
+ */
+
+#define SECOCEC_MICRO_ADDRESS		0x40
+
+/*
+ * STM32 SMBus Registers
+ */
+
+#define SECOCEC_VERSION			0x00
+#define SECOCEC_ENABLE_REG_1		0x01
+#define SECOCEC_ENABLE_REG_2		0x02
+#define SECOCEC_STATUS_REG_1		0x03
+#define SECOCEC_STATUS_REG_2		0x04
+
+#define SECOCEC_STATUS			0x28
+#define SECOCEC_DEVICE_LA		0x29
+#define SECOCEC_READ_OPERATION_ID	0x2a
+#define SECOCEC_READ_DATA_LENGTH	0x2b
+#define SECOCEC_READ_DATA_00		0x2c
+#define SECOCEC_READ_DATA_02		0x2d
+#define SECOCEC_READ_DATA_04		0x2e
+#define SECOCEC_READ_DATA_06		0x2f
+#define SECOCEC_READ_DATA_08		0x30
+#define SECOCEC_READ_DATA_10		0x31
+#define SECOCEC_READ_DATA_12		0x32
+#define SECOCEC_READ_BYTE0		0x33
+#define SECOCEC_WRITE_OPERATION_ID	0x34
+#define SECOCEC_WRITE_DATA_LENGTH	0x35
+#define SECOCEC_WRITE_DATA_00		0x36
+#define SECOCEC_WRITE_DATA_02		0x37
+#define SECOCEC_WRITE_DATA_04		0x38
+#define SECOCEC_WRITE_DATA_06		0x39
+#define SECOCEC_WRITE_DATA_08		0x3a
+#define SECOCEC_WRITE_DATA_10		0x3b
+#define SECOCEC_WRITE_DATA_12		0x3c
+#define SECOCEC_WRITE_BYTE0		0x3d
+
+#define SECOCEC_IR_READ_DATA		0x3e
+
+/*
+ * Enabling register
+ */
+
+#define SECOCEC_ENABLE_REG_1_CEC		0x1000
+#define SECOCEC_ENABLE_REG_1_IR			0x2000
+#define SECOCEC_ENABLE_REG_1_IR_PASSTHROUGH	0x4000
+
+/*
+ * Status register
+ */
+
+#define SECOCEC_STATUS_REG_1_CEC	SECOCEC_ENABLE_REG_1_CEC
+#define SECOCEC_STATUS_REG_1_IR		SECOCEC_ENABLE_REG_1_IR
+#define SECOCEC_STATUS_REG_1_IR_PASSTHR	SECOCEC_ENABLE_REG_1_IR_PASSTHR
+
+/*
+ * Status data
+ */
+
+#define SECOCEC_STATUS_MSG_RECEIVED_MASK	BIT(0)
+#define SECOCEC_STATUS_RX_ERROR_MASK		BIT(1)
+#define SECOCEC_STATUS_MSG_SENT_MASK		BIT(2)
+#define SECOCEC_STATUS_TX_ERROR_MASK		BIT(3)
+
+#define SECOCEC_STATUS_TX_NACK_ERROR		BIT(4)
+#define SECOCEC_STATUS_RX_OVERFLOW_MASK		BIT(5)
+
+#endif /* __SECO_CEC_H__ */
--

2.18.0

author
#3 lore raw

Re: [PATCH 1/2] media: add SECO cec driver

Hi Jacopo,
Thanks for the quick reply, I will respond inline,

Quoted 85 lines · jacopo mondi

Hi Ettore,
thanks for the patch.

A few comments below, please have a look...

Quoted 50 lines · On Tue, Oct 02, 2018 at 06:59:55PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

This patch adds support to the CEC device implemented with a STM32 microcontroller in X86 SECO Boards, including UDOO X86.

The communication is achieved via Braswell integrated SMBus (i2c-i801). The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Inspired by cros-ec-cec implementation, attaches to i915 driver cec-notifier.

---
 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  11 +
 drivers/media/platform/Makefile            |   4 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 729 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 132 ++++
 6 files changed, 883 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
MAINTAINERS +6 -0
index 4ece30f15777..1062912a5ff4 100644
@@ -12972,6 +12972,12 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 F:	drivers/mmc/host/sdricoh_cs.c
 
+SECO BOARDS CEC DRIVER
+M:	Ettore Chimenti <[email protected]>
+S:	Maintained
+F:	drivers/media/platform/seco-cec/seco-cec.c
+F:	drivers/media/platform/seco-cec/seco-cec.h
+
 SECURE COMPUTING > >  M:	Kees Cook <[email protected]>
 R:	Andy Lutomirski <[email protected]>
drivers/media/platform/Kconfig +0 -0
index 94c1fe0e9787..f477764b902a 100644
@@ -613,6 +613,17 @@ config VIDEO_TEGRA_HDMI_CEC
 	 The CEC bus is present in the HDMI connector and enables communication

drivers/media/platform/Kconfig config VIDEO_TEGRA_HDMI_CEC · line 623

Quoted 10 lines
drivers/media/platform/Kconfig +8 -0
 	 between compatible devices.
 
+config VIDEO_SECO_CEC
+       tristate "SECO Boards HDMI CEC driver"
+       depends on (X86 || IA64) || COMPILE_TEST
+       select CEC_CORE
+       select CEC_NOTIFIER
+       help
+         This is a driver for SECO Boards integrated CEC interface. It uses the
+         generic CEC framework interface.

Is it worth mentioning the software framework used for implementing the driver? Anyway, I see this is common to most of the CEC drivers here, so I guess it is fine

Quoted 14 lines
drivers/media/platform/Kconfig +3 -0
+         CEC bus is present in the HDMI connector and enables communication
+         between compatible devices.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/Makefile +0 -0
index 41322ab65802..cc7365c787ba 100644
@@ -53,6 +53,10 @@ obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC)	+= tegra-cec/
 
 obj-y					+= stm32/
 
Quoted 7 lines

drivers/media/platform/Makefile obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC) += tegra-cec/ · line 59

Quoted 4 lines
drivers/media/platform/Makefile +4 -0
+obj-$(CONFIG_VIDEO_SECO_CEC)		+= seco-cec/
+
+obj-y                                   += blackfin/
+

Ups! Is this a leftover from some BSP code? It breaks the build on media-tree master (and I guess on master too)

Ops! Yes, seems some merging/rebasing-related problem happened. Yes, will remove.

Quoted 14 lines

drivers/media/platform/seco-cec/Makefile line 1

Quoted 11 lines
drivers/media/platform/Makefile +0 -0
 obj-y					+= davinci/
 
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
drivers/media/platform/seco-cec/Makefile new file +1 -0
new file mode 100644
index 000000000000..a3f2c6bd3ac0
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_SECO_CEC) += seco-cec.o

This can simply be obj-y as you parse this makefile entry conditionally to the presence of the CONFIG_VIDEO_SECO_CEC symbol

I agree.

Quoted 11 lines

drivers/media/platform/seco-cec/seco-cec.c line 1

Quoted 8 lines
drivers/media/platform/seco-cec/seco-cec.c new file +1 -0
new file mode 100644
index 000000000000..ba3b7c144a87
@@ -0,0 +1,729 @@
+// SPDX-License-Identifier: GPL-2.0 AND BSD-3-Clause

Just make sure the AND is what you want (I only see OR clauses in drivers/ code). See Documentation/process/license-rules.rst

Yes, I was confused by the syntax, I agree with the OR in any case.

Quoted 21 lines

drivers/media/platform/seco-cec/seco-cec.c line 3

Quoted 3 lines
drivers/media/platform/seco-cec/seco-cec.c new file +2 -0
+/*
+ *

Nit: empty comment line

drivers/media/platform/seco-cec/seco-cec.c line 9

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+ * CEC driver for SECO X86 Boards
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ *

Nit: empty comment line

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+ */
+
+#include <linux/interrupt.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/dmi.h>
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 24

Quoted 5 lines
drivers/media/platform/seco-cec/seco-cec.c new file +5 -0
+
+/* CEC Framework */
+#include <media/cec.h>
+
+#include "seco-cec.h"

I would question why a header file is needed as it is not included by anything else

Well, I was working on a really big file with a lot of definitions at the beginning and I wasn't sure if the Consumer-IR could be nicer to split, that is why.

Quoted 42 lines
Quoted 11 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+struct secocec_data {
+	struct device *dev;
+	struct platform_device *pdev;
+	struct cec_adapter *cec_adap;
+	struct cec_notifier *notifier;
+	int irq;
+};
+
+#define smb_wr16(cmd, data) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \

drivers/media/platform/seco-cec/seco-cec.c line 44

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+					     cmd, data, SMBUS_WRITE, NULL)
+#define smb_rd16(cmd, res) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \
+				       cmd, 0, SMBUS_READ, res)
+
+static int smb_word_op(short data_format, u16 slave_addr, u8 cmd, u16 data,
+		       u8 operation, u16 *result)
+{
+	unsigned int count;
+	short _data_format;
+	int ret, status = 0;

In the rest of the function ret is used only once, and you can use status in its place. Please drop one of the two.

Quoted 17 lines
drivers/media/platform/seco-cec/seco-cec.c new file +17 -0
+
+	switch (data_format) {
+	case CMD_BYTE_DATA:
+		_data_format = BRA_SMB_CMD_BYTE_DATA;
+		break;
+	case CMD_WORD_DATA:
+		_data_format = BRA_SMB_CMD_WORD_DATA;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Active wait until ready */
+	for (count = 0; count <= SMBTIMEOUT; ++count) {
+		if (!(inb(HSTS) & BRA_INUSE_STS))
+			break;
+		udelay(SMB_POLL_UDELAY);
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 67

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+	}
+
+	if (count > SMBTIMEOUT) {
+		/* Reset the lock instead of failing */
+		outb(0xff, HSTS);
+		pr_warn("%s: SMBTIMEOUT\n", __func__);

No pr_debug/pr_warn if possible, please.

Yes, probably better to handle this in a different way.

Quoted 256 lines
Quoted 66 lines
drivers/media/platform/seco-cec/seco-cec.c new file +65 -0
+	}
+
+	outb(0x00, HCNT);
+	outb((u8)(slave_addr & 0xfe) | operation, XMIT_SLVA);
+	outb(cmd, HCMD);
+	inb(HCNT);
+
+	if (operation == SMBUS_WRITE) {
+		outb((u8)data, HDAT0);
+		outb((u8)(data >> 8), HDAT1);
+		pr_debug("%s: WRITE (0x%02x - count %05d): 0x%04x\n",
+			 __func__, cmd, count, data);
+	}
+
+	outb(BRA_START + _data_format, HCNT);
+
+	for (count = 0; count <= SMBTIMEOUT; count++) {
+		if (!(inb(HSTS) & BRA_HOST_BUSY))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		pr_debug("%s: SMBTIMEOUT_1\n", __func__);
+		status = -EBUSY;
+		goto err;
+	}
+
+	ret = inb(HSTS);
+	if (ret & BRA_HSTS_ERR_MASK) {
+		pr_debug("%s: HSTS(0x%02X): 0x%X\n", __func__, cmd, ret);
+		status = -EIO;
+		goto err;
+	}
+
+	if (operation == SMBUS_READ) {
+		*result = ((inb(HDAT0) & 0xff) + ((inb(HDAT1) & 0xff) << 8));
+		pr_debug("%s: READ (0x%02x - count %05d): 0x%04x\n",
+			 __func__, cmd, count, *result);
+	}
+
+err:
+	outb(0xff, HSTS);
+	return status;
+}
+
+static int secocec_adap_enable(struct cec_adapter *adap, bool enable)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 val = 0;
+	int status;
+
+	if (enable) {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Enable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);

drivers/media/platform/seco-cec/seco-cec.c line 142

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1,
+				  val | SECOCEC_ENABLE_REG_1_CEC);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device enabled");
+

Empty line

Quoted 177 lines
drivers/media/platform/seco-cec/seco-cec.c new file +177 -0
+	} else {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Disable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+				  ~SECOCEC_ENABLE_REG_1_CEC &
+				  ~SECOCEC_ENABLE_REG_1_IR);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device disabled");
+	}
+
+	return 0;
+err:
+	dev_err(dev, "Adapter setup failed (%d)", status);
+	return status;
+}
+
+static int secocec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr)
+{
+	u16 enable_val = 0;
+	int status;
+
+	/* Disable device */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &enable_val);
+	if (status)
+		return status;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val & ~SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	/* Write logical address */
+	status = smb_wr16(SECOCEC_DEVICE_LA, logical_addr);
+	if (status)
+		return status;
+
+	/* Re-enable device */
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	return 0;
+}
+
+static int secocec_adap_transmit(struct cec_adapter *adap, u8 attempts,
+				 u32 signal_free_time, struct cec_msg *msg)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 payload_len, payload_id_len, destination, val = 0;
+	u8 *payload_msg;
+	int status;
+	u8 i;
+
+	/* Device msg len already accounts for header */
+	payload_id_len = msg->len - 1;
+
+	/* Send data length */
+	status = smb_wr16(SECOCEC_WRITE_DATA_LENGTH, payload_id_len);
+	if (status)
+		goto err;
+
+	/* Send Operation ID if present */
+	if (payload_id_len > 0) {
+		status = smb_wr16(SECOCEC_WRITE_OPERATION_ID, msg->msg[1]);
+		if (status)
+			goto err;
+	}
+	/* Send data if present */
+	if (payload_id_len > 1) {
+		/* Only data; */
+		payload_len = msg->len - 2;
+		payload_msg = &msg->msg[2];
+
+		/* Copy message into registers */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			/* hi byte */
+			val = payload_msg[(i << 1) + 1] << 8;
+
+			/* lo byte */
+			val |= payload_msg[(i << 1)];
+
+			status = smb_wr16(SECOCEC_WRITE_DATA_00 + i, val);
+			if (status)
+				goto err;
+		}
+	}
+	/* Send msg source/destination and fire msg */
+	destination = msg->msg[0];
+	status = smb_wr16(SECOCEC_WRITE_BYTE0, destination);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Transmit failed (%d)", status);
+	return status;
+}
+
+static int secocec_tx_done(struct cec_adapter *adap, u16 status_val)
+{
+	int status = 0;
+
+	if (status_val & SECOCEC_STATUS_TX_ERROR_MASK) {
+		if (status_val & SECOCEC_STATUS_TX_NACK_ERROR) {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_NACK);
+			status = -EAGAIN;
+		} else {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_ERROR);
+			status = -EIO;
+		}
+	} else {
+		cec_transmit_attempt_done(adap, CEC_TX_STATUS_OK);
+	}
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_TX_ERROR_MASK |
+		SECOCEC_STATUS_MSG_SENT_MASK |
+		SECOCEC_STATUS_TX_NACK_ERROR;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+	return status;
+}
+
+static int secocec_rx_done(struct cec_adapter *adap, u16 status_val)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	struct cec_msg msg = { };
+	bool flag_overflow = false;
+	u8 payload_len, i = 0;
+	u8 *payload_msg;
+	u16 val = 0;
+	int status;
+
+	if (status_val & SECOCEC_STATUS_RX_OVERFLOW_MASK) {
+		dev_warn(dev, "Received more than 16 bytes. Discarding");
+		flag_overflow = true;
+	}
+
+	if (status_val & SECOCEC_STATUS_RX_ERROR_MASK) {
+		dev_warn(dev, "Message received with errors. Discarding");
+		status = -EIO;
+		goto rxerr;
+	}
+
+	/* Read message length */
+	status = smb_rd16(SECOCEC_READ_DATA_LENGTH, &val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Incoming message (payload len %d):", val);
+
+	/* Device msg len already accounts for the header */
+	msg.len = min(val + 1, CEC_MAX_MSG_SIZE);
+
+	/* Read logical address */
+	status = smb_rd16(SECOCEC_READ_BYTE0, &val);
+	if (status)
+		goto err;
+
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 324

Quoted 5 lines
drivers/media/platform/seco-cec/seco-cec.c new file +5 -0
+	/* device stores source LA and destination */
+	msg.msg[0] = val;
+
+	/* Read operation ID if present */
+	if (msg.len > 0) {

Am I wrong or msg.len is at least (val + 1) and val is never negative? If that's true, this condition is always verified.

Good one, have to correct this.

Quoted 72 lines
Quoted 72 lines
drivers/media/platform/seco-cec/seco-cec.c new file +71 -0
+		status = smb_rd16(SECOCEC_READ_OPERATION_ID, &val);
+		if (status)
+			goto err;
+
+		msg.msg[1] = val;
+	}
+
+	/* Read data if present */
+	if (msg.len > 1) {
+		payload_len = msg.len - 2;
+		payload_msg = &msg.msg[2];
+
+		/* device stores 2 bytes in every 16-bit val */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			status = smb_rd16(SECOCEC_READ_DATA_00 + i, &val);
+			if (status)
+				goto err;
+
+			/* low byte, skipping header */
+			payload_msg[(i << 1)] = val & 0x00ff;
+
+			/* hi byte */
+			payload_msg[(i << 1) + 1] = (val & 0xff00) >> 8;
+		}
+	}
+
+	cec_received_msg(cec->cec_adap, &msg);
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+
+	status = smb_wr16(SECOCEC_STATUS, status_val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Message received successfully");
+
+	return 0;
+
+rxerr:
+	/* Reset error reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK |
+		SECOCEC_STATUS_RX_ERROR_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+err:
+	dev_err(dev, "Receive message failed (%d)", status);
+	return status;
+}
+
+struct cec_adap_ops secocec_cec_adap_ops = {
+	/* Low-level callbacks */
+	.adap_enable = secocec_adap_enable,
+	.adap_log_addr = secocec_adap_log_addr,
+	.adap_transmit = secocec_adap_transmit,
+};
+
+static irqreturn_t secocec_irq_handler(int irq, void *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	u16 status_val, cec_val, val = 0;
+	int status;
+
+	/*  Read status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &status_val);
+	if (status)
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 399

Quoted 4 lines
drivers/media/platform/seco-cec/seco-cec.c new file +4 -0
+		goto err;
+
+	if (status_val & SECOCEC_STATUS_REG_1_CEC) {
+		dev_dbg(dev, "+++++ CEC Interrupt Caught");

Just be carefull in too much printouts while handling interrupts. Also, I would not insert custom printout formats (here and below in this functions). I would simply drop this one.

Yes, will drop.

Quoted 11 lines
Quoted 11 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+		/* Read CEC status register */
+		status = smb_rd16(SECOCEC_STATUS, &cec_val);
+		if (status)
+			goto err;
+
+		if (cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK)
+			secocec_rx_done(cec->cec_adap, cec_val);
+
+		if (cec_val & SECOCEC_STATUS_MSG_SENT_MASK)
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 415

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+			secocec_tx_done(cec->cec_adap, cec_val);
+
+		if ((~cec_val & SECOCEC_STATUS_MSG_SENT_MASK) &&
+		    (~cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK))
+			dev_warn(dev,
+				 "Message not received or sent, but interrupt fired \\_\"._/");

No custom funny printouts please :)

Ops. Left that :)

Quoted 9 lines

drivers/media/platform/seco-cec/seco-cec.c line 421

Quoted 7 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+		val = SECOCEC_STATUS_REG_1_CEC;
+	}
+
+	if (status_val & SECOCEC_STATUS_REG_1_IR) {
+		dev_dbg(dev, "IR RC5 Interrupt Caught");

How frequent is this one? Do you need to print it out?

Not too frequent, but I wanted to see if and how many IR messages were handled not in presence of RC commands. I would drop that too if not necessary.

Quoted 147 lines

drivers/media/platform/seco-cec/seco-cec.c line 431

Quoted 11 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		val |= SECOCEC_STATUS_REG_1_IR;
+		/* TODO IRDA RX */
+	}
+
+	/*  Reset status register */
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "----- CEC Interrupt Handled");

Drop this one please

Quoted 33 lines
drivers/media/platform/seco-cec/seco-cec.c new file +33 -0
+
+	return IRQ_HANDLED;
+
+err:
+	dev_err(dev, "IRQ: Read/Write SMBus operation failed (%d)", status);
+
+	/*  Reset status register */
+	val = SECOCEC_STATUS_REG_1_CEC | SECOCEC_STATUS_REG_1_IR;
+	smb_wr16(SECOCEC_STATUS_REG_1, val);
+
+	return IRQ_HANDLED;
+}
+
+struct cec_dmi_match {
+	char *sys_vendor;
+	char *product_name;
+	char *devname;
+	char *conn;
+};
+
+static const struct cec_dmi_match secocec_dmi_match_table[] = {
+	/* UDOO X86 */
+	{ "SECO", "UDOO x86", "0000:00:02.0", "Port B" },
+};
+
+static int secocec_cec_get_notifier(struct cec_notifier **notify)
+{
+	int i;
+
+	for (i = 0 ; i < ARRAY_SIZE(secocec_dmi_match_table) ; ++i) {
+		const struct cec_dmi_match *m = &secocec_dmi_match_table[i];
+
+		if (dmi_match(DMI_SYS_VENDOR, m->sys_vendor) &&

drivers/media/platform/seco-cec/seco-cec.c line 474

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		    dmi_match(DMI_PRODUCT_NAME, m->product_name)) {
+			struct device *d;
+
+			/* Find the device, bail out if not yet registered */
+			d = bus_find_device_by_name(&pci_bus_type, NULL,
+						    m->devname);
+			if (!d)
+				return -EPROBE_DEFER;
+
+			*notify = cec_notifier_get_conn(d, m->conn);

Nit: it's usually nice to have an empty line before return (here and in other places). Not mandatory though.

Quoted 73 lines
drivers/media/platform/seco-cec/seco-cec.c new file +73 -0
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int secocec_acpi_probe(struct secocec_data *sdev)
+{
+	struct device *dev = sdev->dev;
+	struct gpio_desc *gpio;
+	int irq = 0;
+
+	gpio = devm_gpiod_get(dev, NULL, GPIOF_IN);
+	if (IS_ERR(gpio)) {
+		dev_err(dev, "Cannot request interrupt gpio");
+		return PTR_ERR(gpio);
+	}
+
+	irq = gpiod_to_irq(gpio);
+	if (irq < 0) {
+		dev_err(dev, "Cannot find valid irq");
+		return -ENODEV;
+	}
+	dev_dbg(dev, "irq-gpio is bound to IRQ %d", irq);
+
+	sdev->irq = irq;
+
+	return 0;
+}
+
+static int secocec_probe(struct platform_device *pdev)
+{
+	struct secocec_data *secocec;
+	struct device *dev = &pdev->dev;
+	u8 cec_caps;
+	int ret;
+	u16 val;
+
+	secocec = devm_kzalloc(dev, sizeof(*secocec), GFP_KERNEL);
+	if (!secocec)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, secocec);
+
+	/* Request SMBus regions */
+	if (!request_muxed_region(BRA_SMB_BASE_ADDR, 7, "CEC00001")) {
+		dev_err(dev, "Request memory region failed");
+		return -ENXIO;
+	}
+
+	secocec->pdev = pdev;
+	secocec->dev = dev;
+
+	if (!has_acpi_companion(dev)) {
+		dev_dbg(dev, "Cannot find any ACPI companion");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	ret = secocec_acpi_probe(secocec);
+	if (ret) {
+		dev_err(dev, "Cannot assign gpio to IRQ");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	dev_dbg(dev, "IRQ detected at %d", secocec->irq);
+
+	/* Firmware version check */
+	ret = smb_rd16(SECOCEC_VERSION, &val);
+	if (ret) {
+		dev_err(dev, "Cannot check fw version");

drivers/media/platform/seco-cec/seco-cec.c line 557

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		goto err;
+	}
+	if (val < SECOCEC_LATEST_FW) {
+		dev_err(dev, "CEC Firmware not supported (v.%04x). Use ver > v.%04x",
+			val, SECOCEC_LATEST_FW);
+		ret = -EINVAL;
+		goto err;
+	}
+
+#ifdef CONFIG_CEC_NOTIFIER

Your Kconfig entry selects CEC_NOTIFIER.

Quoted 4 lines

(I won't comment on the cec_notifier handling part, as I don't know much. I just see other drivers registering and getting the notifier using the cec_notifier_ functions, while it seems to me you don't. Maybe it's fine...)

Left there to add optional support or when compiling the module out-of-tree. But without a proper Kconfig is useless. I agree.

Quoted 72 lines
Quoted 72 lines
drivers/media/platform/seco-cec/seco-cec.c new file +71 -0
+	ret = secocec_cec_get_notifier(&secocec->notifier);
+	if (ret) {
+		dev_err(dev, "no CEC notifier available\n");
+		goto err;
+	}
+#endif
+
+	ret = devm_request_threaded_irq(dev,
+					secocec->irq,
+					NULL,
+					secocec_irq_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					dev_name(&pdev->dev), secocec);
+
+	if (ret) {
+		dev_err(dev, "Cannot request IRQ %d", secocec->irq);
+		ret = -EIO;
+		goto err;
+	}
+
+	/* Allocate CEC adapter */
+	cec_caps = CEC_CAP_DEFAULTS;
+
+	secocec->cec_adap = cec_allocate_adapter(&secocec_cec_adap_ops,
+						 secocec,
+						 dev_name(dev),
+						 cec_caps, SECOCEC_MAX_ADDRS);
+
+	if (IS_ERR(secocec->cec_adap)) {
+		ret = PTR_ERR(secocec->cec_adap);
+		goto err;
+	}
+
+	ret = cec_register_adapter(secocec->cec_adap, dev);
+	if (ret)
+		goto err_delete_adapter;
+
+	if (secocec->notifier)
+		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
+
+	platform_set_drvdata(pdev, secocec);
+
+	dev_dbg(dev, "Device registered");
+
+	return ret;
+
+err_delete_adapter:
+	cec_delete_adapter(secocec->cec_adap);
+err:
+	dev_err(dev, "%s device probe failed\n", dev_name(dev));
+
+	return ret;
+}
+
+/* ----------------------------------------------------------------------- */
+
+static int secocec_remove(struct platform_device *pdev)
+{
+	struct secocec_data *secocec = platform_get_drvdata(pdev);
+
+	cec_unregister_adapter(secocec->cec_adap);
+
+	if (secocec->notifier)
+		cec_notifier_put(secocec->notifier);
+
+	release_region(BRA_SMB_BASE_ADDR, 7);
+
+	dev_dbg(&pdev->dev, "CEC device removed");
+
+	return 0;
+}
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 632

Quoted 4 lines
drivers/media/platform/seco-cec/seco-cec.c new file +4 -0
+
+/* ----------------------------------------------------------------------- */
+
+#ifdef CONFIG_PM_SLEEP

I see CONFIG_PM_SLEEP is only selected if support for 'suspend'/'hibernate' is enabled. Is this what you want, or you should check for CONFIG_PM?

I was just inspired by the implementation of cros-ec-cec, but I think this is right, because the device actually has suspend/hibernate states.

Quoted 97 lines
Quoted 82 lines
drivers/media/platform/seco-cec/seco-cec.c new file +81 -0
+static int secocec_suspend(struct device *dev)
+{
+	u16 val;
+	int status;
+
+	dev_dbg(dev, "Device going to suspend, disabling");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Disable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+			  ~SECOCEC_ENABLE_REG_1_CEC & ~SECOCEC_ENABLE_REG_1_IR);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Suspend failed (err: %d)", status);
+	return status;
+}
+
+static int secocec_resume(struct device *dev)
+{
+	u16 val;
+	int status;
+
+	dev_dbg(dev, "Resuming device from suspend");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Device resumed from suspend");
+
+	return 0;
+
+err:
+	dev_err(dev, "Resume failed (err: %d)", status);
+	return status;
+}
+
+static SIMPLE_DEV_PM_OPS(secocec_pm_ops, secocec_suspend, secocec_resume);
+#define SECOCEC_PM_OPS (&secocec_pm_ops)
+#else
+#define SECOCEC_PM_OPS NULL
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id secocec_acpi_match[] = {
+	{"CEC00001", 0},
+	{},
+};
+
+MODULE_DEVICE_TABLE(acpi, secocec_acpi_match);
+#endif

drivers/media/platform/seco-cec/seco-cec.c line 723

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+static struct platform_driver secocec_driver = {
+	.driver = {
+		   .name = SECOCEC_DEV_NAME,
+		   .acpi_match_table = ACPI_PTR(secocec_acpi_match),
+		   .pm = SECOCEC_PM_OPS,
+	},
+	.probe = secocec_probe,
+	.remove = secocec_remove,
+};

As you can see most of my comments are nits or trivial things. I would wait for more feedbacks on the CEC and x86/SMbus part from others before sending v2 if I were you :)

Quoted 3 lines

Thanks
j

Many thanks, this is my first patch, so I need plenty of comments. :)

Ettore

Quoted 148 lines
Quoted 148 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+module_platform_driver(secocec_driver);
+
+MODULE_DESCRIPTION("SECO CEC X86 Driver");
+MODULE_AUTHOR("Ettore Chimenti <[email protected]>");
+MODULE_LICENSE("Dual BSD/GPL");
drivers/media/platform/seco-cec/seco-cec.h new file +132 -1
new file mode 100644
index 000000000000..cc7f0cba8e9e
@@ -0,0 +1,132 @@
+/* SPDX-License-Identifier: GPL-2.0 AND BSD-3-Clause */
+/*
+ *
+ * SECO X86 Boards CEC register defines
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ *
+ */
+
+#ifndef __SECO_CEC_H__
+#define __SECO_CEC_H__
+
+#define SECOCEC_MAX_ADDRS		1
+#define SECOCEC_DEV_NAME		"secocec"
+#define SECOCEC_LATEST_FW		0x0f0b
+
+#define SMBTIMEOUT			0xffff
+#define SMB_POLL_UDELAY			10
+
+#define SMBUS_WRITE			0
+#define SMBUS_READ			1
+
+#define CMD_BYTE_DATA			0
+#define CMD_WORD_DATA			1
+
+/*
+ * SMBus definitons for Braswell
+ */
+
+#define BRA_DONE_STATUS			BIT(7)
+#define BRA_INUSE_STS			BIT(6)
+#define BRA_FAILED_OP			BIT(4)
+#define BRA_BUS_ERR			BIT(3)
+#define BRA_DEV_ERR			BIT(2)
+#define BRA_INTR			BIT(1)
+#define BRA_HOST_BUSY			BIT(0)
+#define BRA_HSTS_ERR_MASK   (BRA_FAILED_OP | BRA_BUS_ERR | BRA_DEV_ERR)
+
+#define BRA_PEC_EN			BIT(7)
+#define BRA_START			BIT(6)
+#define BRA_LAST__BYTE			BIT(5)
+#define BRA_INTREN			BIT(0)
+#define BRA_SMB_CMD			(7 << 2)
+#define BRA_SMB_CMD_QUICK		(0 << 2)
+#define BRA_SMB_CMD_BYTE		(1 << 2)
+#define BRA_SMB_CMD_BYTE_DATA		(2 << 2)
+#define BRA_SMB_CMD_WORD_DATA		(3 << 2)
+#define BRA_SMB_CMD_PROCESS_CALL	(4 << 2)
+#define BRA_SMB_CMD_BLOCK		(5 << 2)
+#define BRA_SMB_CMD_I2CREAD		(6 << 2)
+#define BRA_SMB_CMD_BLOCK_PROCESS	(7 << 2)
+
+#define BRA_SMB_BASE_ADDR  0x2040
+#define HSTS               (BRA_SMB_BASE_ADDR + 0)
+#define HCNT               (BRA_SMB_BASE_ADDR + 2)
+#define HCMD               (BRA_SMB_BASE_ADDR + 3)
+#define XMIT_SLVA          (BRA_SMB_BASE_ADDR + 4)
+#define HDAT0              (BRA_SMB_BASE_ADDR + 5)
+#define HDAT1              (BRA_SMB_BASE_ADDR + 6)
+
+/*
+ * Microcontroller Address
+ */
+
+#define SECOCEC_MICRO_ADDRESS		0x40
+
+/*
+ * STM32 SMBus Registers
+ */
+
+#define SECOCEC_VERSION			0x00
+#define SECOCEC_ENABLE_REG_1		0x01
+#define SECOCEC_ENABLE_REG_2		0x02
+#define SECOCEC_STATUS_REG_1		0x03
+#define SECOCEC_STATUS_REG_2		0x04
+
+#define SECOCEC_STATUS			0x28
+#define SECOCEC_DEVICE_LA		0x29
+#define SECOCEC_READ_OPERATION_ID	0x2a
+#define SECOCEC_READ_DATA_LENGTH	0x2b
+#define SECOCEC_READ_DATA_00		0x2c
+#define SECOCEC_READ_DATA_02		0x2d
+#define SECOCEC_READ_DATA_04		0x2e
+#define SECOCEC_READ_DATA_06		0x2f
+#define SECOCEC_READ_DATA_08		0x30
+#define SECOCEC_READ_DATA_10		0x31
+#define SECOCEC_READ_DATA_12		0x32
+#define SECOCEC_READ_BYTE0		0x33
+#define SECOCEC_WRITE_OPERATION_ID	0x34
+#define SECOCEC_WRITE_DATA_LENGTH	0x35
+#define SECOCEC_WRITE_DATA_00		0x36
+#define SECOCEC_WRITE_DATA_02		0x37
+#define SECOCEC_WRITE_DATA_04		0x38
+#define SECOCEC_WRITE_DATA_06		0x39
+#define SECOCEC_WRITE_DATA_08		0x3a
+#define SECOCEC_WRITE_DATA_10		0x3b
+#define SECOCEC_WRITE_DATA_12		0x3c
+#define SECOCEC_WRITE_BYTE0		0x3d
+
+#define SECOCEC_IR_READ_DATA		0x3e
+
+/*
+ * Enabling register
+ */
+
+#define SECOCEC_ENABLE_REG_1_CEC		0x1000
+#define SECOCEC_ENABLE_REG_1_IR			0x2000
+#define SECOCEC_ENABLE_REG_1_IR_PASSTHROUGH	0x4000
+
+/*
+ * Status register
+ */
+
+#define SECOCEC_STATUS_REG_1_CEC	SECOCEC_ENABLE_REG_1_CEC
+#define SECOCEC_STATUS_REG_1_IR		SECOCEC_ENABLE_REG_1_IR
+#define SECOCEC_STATUS_REG_1_IR_PASSTHR	SECOCEC_ENABLE_REG_1_IR_PASSTHR
+
+/*
+ * Status data
+ */
+
+#define SECOCEC_STATUS_MSG_RECEIVED_MASK	BIT(0)
+#define SECOCEC_STATUS_RX_ERROR_MASK		BIT(1)
+#define SECOCEC_STATUS_MSG_SENT_MASK		BIT(2)
+#define SECOCEC_STATUS_TX_ERROR_MASK		BIT(3)
+
+#define SECOCEC_STATUS_TX_NACK_ERROR		BIT(4)
+#define SECOCEC_STATUS_RX_OVERFLOW_MASK		BIT(5)
+
+#endif /* __SECO_CEC_H__ */
--

2.18.0

#4 lore raw

Re: [PATCH 1/2] media: add SECO cec driver

Hello,

Quoted 12 lines · On Wed, Oct 03, 2018 at 05:50:04PM +0200, ektor5 wrote:

Hi Jacopo,
Thanks for the quick reply, I will respond inline,

Quoted 8 lines · jacopo mondi

Hi Ettore,
thanks for the patch.

A few comments below, please have a look...

Quoted 2 lines · On Tue, Oct 02, 2018 at 06:59:55PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>
+/* ----------------------------------------------------------------------- */

[snip]

Quoted 10 lines
Quoted 6 lines

drivers/media/platform/seco-cec/seco-cec.c line 632

Quoted 2 lines
drivers/media/platform/seco-cec/seco-cec.c new file +2 -0
+
+#ifdef CONFIG_PM_SLEEP

I see CONFIG_PM_SLEEP is only selected if support for 'suspend'/'hibernate' is enabled. Is this what you want, or you should check for CONFIG_PM?

I was just inspired by the implementation of cros-ec-cec, but I think this is right, because the device actually has suspend/hibernate states.

Your device maybe does... I feel like CONFIG_PM is the right choice, but I let others to comment further.

Quoted 97 lines
Quoted 97 lines
Quoted 82 lines
drivers/media/platform/seco-cec/seco-cec.c new file +81 -0
+static int secocec_suspend(struct device *dev)
+{
+	u16 val;
+	int status;
+
+	dev_dbg(dev, "Device going to suspend, disabling");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Disable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+			  ~SECOCEC_ENABLE_REG_1_CEC & ~SECOCEC_ENABLE_REG_1_IR);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Suspend failed (err: %d)", status);
+	return status;
+}
+
+static int secocec_resume(struct device *dev)
+{
+	u16 val;
+	int status;
+
+	dev_dbg(dev, "Resuming device from suspend");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Device resumed from suspend");
+
+	return 0;
+
+err:
+	dev_err(dev, "Resume failed (err: %d)", status);
+	return status;
+}
+
+static SIMPLE_DEV_PM_OPS(secocec_pm_ops, secocec_suspend, secocec_resume);
+#define SECOCEC_PM_OPS (&secocec_pm_ops)
+#else
+#define SECOCEC_PM_OPS NULL
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id secocec_acpi_match[] = {
+	{"CEC00001", 0},
+	{},
+};
+
+MODULE_DEVICE_TABLE(acpi, secocec_acpi_match);
+#endif

drivers/media/platform/seco-cec/seco-cec.c line 723

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+static struct platform_driver secocec_driver = {
+	.driver = {
+		   .name = SECOCEC_DEV_NAME,
+		   .acpi_match_table = ACPI_PTR(secocec_acpi_match),
+		   .pm = SECOCEC_PM_OPS,
+	},
+	.probe = secocec_probe,
+	.remove = secocec_remove,
+};

As you can see most of my comments are nits or trivial things. I would wait for more feedbacks on the CEC and x86/SMbus part from others before sending v2 if I were you :)

Quoted 6 lines
Quoted 3 lines

Thanks
j

Many thanks, this is my first patch, so I need plenty of comments. :)

I wish my first patches were as good as this one!

Thanks for sharing
j

#5 lore raw

Re: [PATCH 1/2] media: add SECO cec driver

In reply to jacopo mondi
Quoted 59 lines · jacopo mondi

Hi Ettore,
thanks for the patch.

A few comments below, please have a look...

Quoted 53 lines · On Tue, Oct 02, 2018 at 06:59:55PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

This patch adds support to the CEC device implemented with a STM32 microcontroller in X86 SECO Boards, including UDOO X86.

The communication is achieved via Braswell integrated SMBus (i2c-i801). The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Inspired by cros-ec-cec implementation, attaches to i915 driver cec-notifier.

---
 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  11 +
 drivers/media/platform/Makefile            |   4 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 729 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 132 ++++
 6 files changed, 883 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
MAINTAINERS +6 -0
index 4ece30f15777..1062912a5ff4 100644
@@ -12972,6 +12972,12 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 F:	drivers/mmc/host/sdricoh_cs.c
 
+SECO BOARDS CEC DRIVER
+M:	Ettore Chimenti <[email protected]>
+S:	Maintained
+F:	drivers/media/platform/seco-cec/seco-cec.c
+F:	drivers/media/platform/seco-cec/seco-cec.h
+
 SECURE COMPUTING
 M:	Kees Cook <[email protected]>
 R:	Andy Lutomirski <[email protected]>
drivers/media/platform/Kconfig +0 -0
index 94c1fe0e9787..f477764b902a 100644
@@ -613,6 +613,17 @@ config VIDEO_TEGRA_HDMI_CEC
 	 The CEC bus is present in the HDMI connector and enables communication
 	 between compatible devices.
 
Quoted 12 lines

drivers/media/platform/Kconfig config VIDEO_TEGRA_HDMI_CEC · line 623

Quoted 8 lines
drivers/media/platform/Kconfig +8 -0
+config VIDEO_SECO_CEC
+       tristate "SECO Boards HDMI CEC driver"
+       depends on (X86 || IA64) || COMPILE_TEST
+       select CEC_CORE
+       select CEC_NOTIFIER
+       help
+         This is a driver for SECO Boards integrated CEC interface. It uses the
+         generic CEC framework interface.

Is it worth mentioning the software framework used for implementing the driver? Anyway, I see this is common to most of the CEC drivers here, so I guess it is fine

It's not worth mentioning :-)

Not sure how and why that phrase crept into cec driver Kconfigs.

Quoted 530 lines
Quoted 12 lines
drivers/media/platform/Kconfig +3 -0
+         CEC bus is present in the HDMI connector and enables communication
+         between compatible devices.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/Makefile +0 -0
index 41322ab65802..cc7365c787ba 100644

drivers/media/platform/Makefile obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC) += tegra-cec/ · line 59

Quoted 7 lines
drivers/media/platform/Makefile +4 -0
@@ -53,6 +53,10 @@ obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC)	+= tegra-cec/
 
 obj-y					+= stm32/
 
+obj-$(CONFIG_VIDEO_SECO_CEC)		+= seco-cec/
+
+obj-y                                   += blackfin/
+

Ups! Is this a leftover from some BSP code? It breaks the build on media-tree master (and I guess on master too)

drivers/media/platform/seco-cec/Makefile line 1

Quoted 10 lines
drivers/media/platform/Makefile +0 -0
 obj-y					+= davinci/
 
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
drivers/media/platform/seco-cec/Makefile new file +1 -0
new file mode 100644
index 000000000000..a3f2c6bd3ac0
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_SECO_CEC) += seco-cec.o

This can simply be obj-y as you parse this makefile entry conditionally to the presence of the CONFIG_VIDEO_SECO_CEC symbol

drivers/media/platform/seco-cec/seco-cec.c line 1

Quoted 7 lines
drivers/media/platform/seco-cec/seco-cec.c new file +1 -0
new file mode 100644
index 000000000000..ba3b7c144a87
@@ -0,0 +1,729 @@
+// SPDX-License-Identifier: GPL-2.0 AND BSD-3-Clause

Just make sure the AND is what you want (I only see OR clauses in drivers/ code). See Documentation/process/license-rules.rst

drivers/media/platform/seco-cec/seco-cec.c line 3

Quoted 2 lines
drivers/media/platform/seco-cec/seco-cec.c new file +2 -0
+/*
+ *

Nit: empty comment line

drivers/media/platform/seco-cec/seco-cec.c line 9

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+ * CEC driver for SECO X86 Boards
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ *

Nit: empty comment line

Quoted 5 lines
drivers/media/platform/seco-cec/seco-cec.c new file +5 -0
+ */
+
+#include <linux/interrupt.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>

drivers/media/platform/seco-cec/seco-cec.c line 24

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/dmi.h>
+
+/* CEC Framework */
+#include <media/cec.h>
+
+#include "seco-cec.h"

I would question why a header file is needed as it is not included by anything else

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+struct secocec_data {
+	struct device *dev;
+	struct platform_device *pdev;
+	struct cec_adapter *cec_adap;
+	struct cec_notifier *notifier;
+	int irq;
+};
+
+#define smb_wr16(cmd, data) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \

drivers/media/platform/seco-cec/seco-cec.c line 44

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+					     cmd, data, SMBUS_WRITE, NULL)
+#define smb_rd16(cmd, res) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \
+				       cmd, 0, SMBUS_READ, res)
+
+static int smb_word_op(short data_format, u16 slave_addr, u8 cmd, u16 data,
+		       u8 operation, u16 *result)
+{
+	unsigned int count;
+	short _data_format;
+	int ret, status = 0;

In the rest of the function ret is used only once, and you can use status in its place. Please drop one of the two.

Quoted 13 lines
drivers/media/platform/seco-cec/seco-cec.c new file +13 -0
+
+	switch (data_format) {
+	case CMD_BYTE_DATA:
+		_data_format = BRA_SMB_CMD_BYTE_DATA;
+		break;
+	case CMD_WORD_DATA:
+		_data_format = BRA_SMB_CMD_WORD_DATA;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Active wait until ready */

drivers/media/platform/seco-cec/seco-cec.c line 67

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	for (count = 0; count <= SMBTIMEOUT; ++count) {
+		if (!(inb(HSTS) & BRA_INUSE_STS))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		/* Reset the lock instead of failing */
+		outb(0xff, HSTS);
+		pr_warn("%s: SMBTIMEOUT\n", __func__);

No pr_debug/pr_warn if possible, please.

Quoted 65 lines
drivers/media/platform/seco-cec/seco-cec.c new file +65 -0
+	}
+
+	outb(0x00, HCNT);
+	outb((u8)(slave_addr & 0xfe) | operation, XMIT_SLVA);
+	outb(cmd, HCMD);
+	inb(HCNT);
+
+	if (operation == SMBUS_WRITE) {
+		outb((u8)data, HDAT0);
+		outb((u8)(data >> 8), HDAT1);
+		pr_debug("%s: WRITE (0x%02x - count %05d): 0x%04x\n",
+			 __func__, cmd, count, data);
+	}
+
+	outb(BRA_START + _data_format, HCNT);
+
+	for (count = 0; count <= SMBTIMEOUT; count++) {
+		if (!(inb(HSTS) & BRA_HOST_BUSY))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		pr_debug("%s: SMBTIMEOUT_1\n", __func__);
+		status = -EBUSY;
+		goto err;
+	}
+
+	ret = inb(HSTS);
+	if (ret & BRA_HSTS_ERR_MASK) {
+		pr_debug("%s: HSTS(0x%02X): 0x%X\n", __func__, cmd, ret);
+		status = -EIO;
+		goto err;
+	}
+
+	if (operation == SMBUS_READ) {
+		*result = ((inb(HDAT0) & 0xff) + ((inb(HDAT1) & 0xff) << 8));
+		pr_debug("%s: READ (0x%02x - count %05d): 0x%04x\n",
+			 __func__, cmd, count, *result);
+	}
+
+err:
+	outb(0xff, HSTS);
+	return status;
+}
+
+static int secocec_adap_enable(struct cec_adapter *adap, bool enable)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 val = 0;
+	int status;
+
+	if (enable) {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Enable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);

drivers/media/platform/seco-cec/seco-cec.c line 142

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1,
+				  val | SECOCEC_ENABLE_REG_1_CEC);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device enabled");
+

Empty line

Quoted 172 lines
drivers/media/platform/seco-cec/seco-cec.c new file +172 -0
+	} else {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Disable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+				  ~SECOCEC_ENABLE_REG_1_CEC &
+				  ~SECOCEC_ENABLE_REG_1_IR);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device disabled");
+	}
+
+	return 0;
+err:
+	dev_err(dev, "Adapter setup failed (%d)", status);
+	return status;
+}
+
+static int secocec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr)
+{
+	u16 enable_val = 0;
+	int status;
+
+	/* Disable device */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &enable_val);
+	if (status)
+		return status;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val & ~SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	/* Write logical address */
+	status = smb_wr16(SECOCEC_DEVICE_LA, logical_addr);
+	if (status)
+		return status;
+
+	/* Re-enable device */
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	return 0;
+}
+
+static int secocec_adap_transmit(struct cec_adapter *adap, u8 attempts,
+				 u32 signal_free_time, struct cec_msg *msg)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 payload_len, payload_id_len, destination, val = 0;
+	u8 *payload_msg;
+	int status;
+	u8 i;
+
+	/* Device msg len already accounts for header */
+	payload_id_len = msg->len - 1;
+
+	/* Send data length */
+	status = smb_wr16(SECOCEC_WRITE_DATA_LENGTH, payload_id_len);
+	if (status)
+		goto err;
+
+	/* Send Operation ID if present */
+	if (payload_id_len > 0) {
+		status = smb_wr16(SECOCEC_WRITE_OPERATION_ID, msg->msg[1]);
+		if (status)
+			goto err;
+	}
+	/* Send data if present */
+	if (payload_id_len > 1) {
+		/* Only data; */
+		payload_len = msg->len - 2;
+		payload_msg = &msg->msg[2];
+
+		/* Copy message into registers */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			/* hi byte */
+			val = payload_msg[(i << 1) + 1] << 8;
+
+			/* lo byte */
+			val |= payload_msg[(i << 1)];
+
+			status = smb_wr16(SECOCEC_WRITE_DATA_00 + i, val);
+			if (status)
+				goto err;
+		}
+	}
+	/* Send msg source/destination and fire msg */
+	destination = msg->msg[0];
+	status = smb_wr16(SECOCEC_WRITE_BYTE0, destination);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Transmit failed (%d)", status);
+	return status;
+}
+
+static int secocec_tx_done(struct cec_adapter *adap, u16 status_val)
+{
+	int status = 0;
+
+	if (status_val & SECOCEC_STATUS_TX_ERROR_MASK) {
+		if (status_val & SECOCEC_STATUS_TX_NACK_ERROR) {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_NACK);
+			status = -EAGAIN;
+		} else {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_ERROR);
+			status = -EIO;
+		}
+	} else {
+		cec_transmit_attempt_done(adap, CEC_TX_STATUS_OK);
+	}
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_TX_ERROR_MASK |
+		SECOCEC_STATUS_MSG_SENT_MASK |
+		SECOCEC_STATUS_TX_NACK_ERROR;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+	return status;
+}
+
+static int secocec_rx_done(struct cec_adapter *adap, u16 status_val)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	struct cec_msg msg = { };
+	bool flag_overflow = false;
+	u8 payload_len, i = 0;
+	u8 *payload_msg;
+	u16 val = 0;
+	int status;
+
+	if (status_val & SECOCEC_STATUS_RX_OVERFLOW_MASK) {
+		dev_warn(dev, "Received more than 16 bytes. Discarding");
+		flag_overflow = true;
+	}
+
+	if (status_val & SECOCEC_STATUS_RX_ERROR_MASK) {
+		dev_warn(dev, "Message received with errors. Discarding");
+		status = -EIO;
+		goto rxerr;
+	}
+
+	/* Read message length */
+	status = smb_rd16(SECOCEC_READ_DATA_LENGTH, &val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Incoming message (payload len %d):", val);
+
+	/* Device msg len already accounts for the header */
+	msg.len = min(val + 1, CEC_MAX_MSG_SIZE);
+

drivers/media/platform/seco-cec/seco-cec.c line 324

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	/* Read logical address */
+	status = smb_rd16(SECOCEC_READ_BYTE0, &val);
+	if (status)
+		goto err;
+
+	/* device stores source LA and destination */
+	msg.msg[0] = val;
+
+	/* Read operation ID if present */
+	if (msg.len > 0) {

Am I wrong or msg.len is at least (val + 1) and val is never negative? If that's true, this condition is always verified.

Quoted 65 lines
drivers/media/platform/seco-cec/seco-cec.c new file +65 -0
+		status = smb_rd16(SECOCEC_READ_OPERATION_ID, &val);
+		if (status)
+			goto err;
+
+		msg.msg[1] = val;
+	}
+
+	/* Read data if present */
+	if (msg.len > 1) {
+		payload_len = msg.len - 2;
+		payload_msg = &msg.msg[2];
+
+		/* device stores 2 bytes in every 16-bit val */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			status = smb_rd16(SECOCEC_READ_DATA_00 + i, &val);
+			if (status)
+				goto err;
+
+			/* low byte, skipping header */
+			payload_msg[(i << 1)] = val & 0x00ff;
+
+			/* hi byte */
+			payload_msg[(i << 1) + 1] = (val & 0xff00) >> 8;
+		}
+	}
+
+	cec_received_msg(cec->cec_adap, &msg);
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+
+	status = smb_wr16(SECOCEC_STATUS, status_val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Message received successfully");
+
+	return 0;
+
+rxerr:
+	/* Reset error reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK |
+		SECOCEC_STATUS_RX_ERROR_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+err:
+	dev_err(dev, "Receive message failed (%d)", status);
+	return status;
+}
+
+struct cec_adap_ops secocec_cec_adap_ops = {
+	/* Low-level callbacks */
+	.adap_enable = secocec_adap_enable,
+	.adap_log_addr = secocec_adap_log_addr,
+	.adap_transmit = secocec_adap_transmit,
+};
+
+static irqreturn_t secocec_irq_handler(int irq, void *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;

drivers/media/platform/seco-cec/seco-cec.c line 399

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	u16 status_val, cec_val, val = 0;
+	int status;
+
+	/*  Read status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &status_val);
+	if (status)
+		goto err;
+
+	if (status_val & SECOCEC_STATUS_REG_1_CEC) {
+		dev_dbg(dev, "+++++ CEC Interrupt Caught");

Just be carefull in too much printouts while handling interrupts. Also, I would not insert custom printout formats (here and below in this functions). I would simply drop this one.

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+		/* Read CEC status register */
+		status = smb_rd16(SECOCEC_STATUS, &cec_val);
+		if (status)
+			goto err;
+

drivers/media/platform/seco-cec/seco-cec.c line 415

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		if (cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK)
+			secocec_rx_done(cec->cec_adap, cec_val);
+
+		if (cec_val & SECOCEC_STATUS_MSG_SENT_MASK)
+			secocec_tx_done(cec->cec_adap, cec_val);
+
+		if ((~cec_val & SECOCEC_STATUS_MSG_SENT_MASK) &&
+		    (~cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK))
+			dev_warn(dev,
+				 "Message not received or sent, but interrupt fired \\_\"._/");

No custom funny printouts please :)

drivers/media/platform/seco-cec/seco-cec.c line 421

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+		val = SECOCEC_STATUS_REG_1_CEC;
+	}
+
+	if (status_val & SECOCEC_STATUS_REG_1_IR) {
+		dev_dbg(dev, "IR RC5 Interrupt Caught");

How frequent is this one? Do you need to print it out?

drivers/media/platform/seco-cec/seco-cec.c line 431

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		val |= SECOCEC_STATUS_REG_1_IR;
+		/* TODO IRDA RX */
+	}
+
+	/*  Reset status register */
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "----- CEC Interrupt Handled");

Drop this one please

Quoted 18 lines
drivers/media/platform/seco-cec/seco-cec.c new file +18 -0
+
+	return IRQ_HANDLED;
+
+err:
+	dev_err(dev, "IRQ: Read/Write SMBus operation failed (%d)", status);
+
+	/*  Reset status register */
+	val = SECOCEC_STATUS_REG_1_CEC | SECOCEC_STATUS_REG_1_IR;
+	smb_wr16(SECOCEC_STATUS_REG_1, val);
+
+	return IRQ_HANDLED;
+}
+
+struct cec_dmi_match {
+	char *sys_vendor;
+	char *product_name;
+	char *devname;
+	char *conn;
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 457

Quoted 8 lines
drivers/media/platform/seco-cec/seco-cec.c new file +8 -0
+};
+
+static const struct cec_dmi_match secocec_dmi_match_table[] = {
+	/* UDOO X86 */
+	{ "SECO", "UDOO x86", "0000:00:02.0", "Port B" },
+};
+
+static int secocec_cec_get_notifier(struct cec_notifier **notify)

If you compare this driver with cros-ec-cec.c, then you'll see that there this function is under "#if IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_DMI)".

I think you should do the same and (just like cros-ec-cec.c) add a dummy function in the #else part.

Quoted 98 lines
Quoted 7 lines
drivers/media/platform/seco-cec/seco-cec.c new file +7 -0
+{
+	int i;
+
+	for (i = 0 ; i < ARRAY_SIZE(secocec_dmi_match_table) ; ++i) {
+		const struct cec_dmi_match *m = &secocec_dmi_match_table[i];
+
+		if (dmi_match(DMI_SYS_VENDOR, m->sys_vendor) &&

drivers/media/platform/seco-cec/seco-cec.c line 474

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		    dmi_match(DMI_PRODUCT_NAME, m->product_name)) {
+			struct device *d;
+
+			/* Find the device, bail out if not yet registered */
+			d = bus_find_device_by_name(&pci_bus_type, NULL,
+						    m->devname);
+			if (!d)
+				return -EPROBE_DEFER;
+
+			*notify = cec_notifier_get_conn(d, m->conn);

Nit: it's usually nice to have an empty line before return (here and in other places). Not mandatory though.

Quoted 77 lines
drivers/media/platform/seco-cec/seco-cec.c new file +77 -0
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int secocec_acpi_probe(struct secocec_data *sdev)
+{
+	struct device *dev = sdev->dev;
+	struct gpio_desc *gpio;
+	int irq = 0;
+
+	gpio = devm_gpiod_get(dev, NULL, GPIOF_IN);
+	if (IS_ERR(gpio)) {
+		dev_err(dev, "Cannot request interrupt gpio");
+		return PTR_ERR(gpio);
+	}
+
+	irq = gpiod_to_irq(gpio);
+	if (irq < 0) {
+		dev_err(dev, "Cannot find valid irq");
+		return -ENODEV;
+	}
+	dev_dbg(dev, "irq-gpio is bound to IRQ %d", irq);
+
+	sdev->irq = irq;
+
+	return 0;
+}
+
+static int secocec_probe(struct platform_device *pdev)
+{
+	struct secocec_data *secocec;
+	struct device *dev = &pdev->dev;
+	u8 cec_caps;
+	int ret;
+	u16 val;
+
+	secocec = devm_kzalloc(dev, sizeof(*secocec), GFP_KERNEL);
+	if (!secocec)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, secocec);
+
+	/* Request SMBus regions */
+	if (!request_muxed_region(BRA_SMB_BASE_ADDR, 7, "CEC00001")) {
+		dev_err(dev, "Request memory region failed");
+		return -ENXIO;
+	}
+
+	secocec->pdev = pdev;
+	secocec->dev = dev;
+
+	if (!has_acpi_companion(dev)) {
+		dev_dbg(dev, "Cannot find any ACPI companion");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	ret = secocec_acpi_probe(secocec);
+	if (ret) {
+		dev_err(dev, "Cannot assign gpio to IRQ");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	dev_dbg(dev, "IRQ detected at %d", secocec->irq);
+
+	/* Firmware version check */
+	ret = smb_rd16(SECOCEC_VERSION, &val);
+	if (ret) {
+		dev_err(dev, "Cannot check fw version");
+		goto err;
+	}
+	if (val < SECOCEC_LATEST_FW) {
+		dev_err(dev, "CEC Firmware not supported (v.%04x). Use ver > v.%04x",
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 557

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+			val, SECOCEC_LATEST_FW);
+		ret = -EINVAL;
+		goto err;
+	}
+
+#ifdef CONFIG_CEC_NOTIFIER

Your Kconfig entry selects CEC_NOTIFIER.

Yes, this #ifdef line can be dropped.

Quoted 5 lines

(I won't comment on the cec_notifier handling part, as I don't know much. I just see other drivers registering and getting the notifier using the cec_notifier_ functions, while it seems to me you don't. Maybe it's fine...)

It's fine :-)

Quoted 20 lines
Quoted 20 lines
drivers/media/platform/seco-cec/seco-cec.c new file +19 -0
+	ret = secocec_cec_get_notifier(&secocec->notifier);
+	if (ret) {
+		dev_err(dev, "no CEC notifier available\n");
+		goto err;
+	}
+#endif
+
+	ret = devm_request_threaded_irq(dev,
+					secocec->irq,
+					NULL,
+					secocec_irq_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					dev_name(&pdev->dev), secocec);
+
+	if (ret) {
+		dev_err(dev, "Cannot request IRQ %d", secocec->irq);
+		ret = -EIO;
+		goto err;
+	}
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 584

Quoted 8 lines
drivers/media/platform/seco-cec/seco-cec.c new file +8 -0
+
+	/* Allocate CEC adapter */
+	cec_caps = CEC_CAP_DEFAULTS;
+
+	secocec->cec_adap = cec_allocate_adapter(&secocec_cec_adap_ops,
+						 secocec,
+						 dev_name(dev),
+						 cec_caps, SECOCEC_MAX_ADDRS);

You can drop cec_caps and just pass CEC_CAP_DEFAULTS directly.

Quoted 292 lines
Quoted 38 lines
drivers/media/platform/seco-cec/seco-cec.c new file +38 -0
+
+	if (IS_ERR(secocec->cec_adap)) {
+		ret = PTR_ERR(secocec->cec_adap);
+		goto err;
+	}
+
+	ret = cec_register_adapter(secocec->cec_adap, dev);
+	if (ret)
+		goto err_delete_adapter;
+
+	if (secocec->notifier)
+		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
+
+	platform_set_drvdata(pdev, secocec);
+
+	dev_dbg(dev, "Device registered");
+
+	return ret;
+
+err_delete_adapter:
+	cec_delete_adapter(secocec->cec_adap);
+err:
+	dev_err(dev, "%s device probe failed\n", dev_name(dev));
+
+	return ret;
+}
+
+/* ----------------------------------------------------------------------- */
+
+static int secocec_remove(struct platform_device *pdev)
+{
+	struct secocec_data *secocec = platform_get_drvdata(pdev);
+
+	cec_unregister_adapter(secocec->cec_adap);
+
+	if (secocec->notifier)
+		cec_notifier_put(secocec->notifier);
+

drivers/media/platform/seco-cec/seco-cec.c line 632

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	release_region(BRA_SMB_BASE_ADDR, 7);
+
+	dev_dbg(&pdev->dev, "CEC device removed");
+
+	return 0;
+}
+
+/* ----------------------------------------------------------------------- */
+
+#ifdef CONFIG_PM_SLEEP

I see CONFIG_PM_SLEEP is only selected if support for 'suspend'/'hibernate' is enabled. Is this what you want, or you should check for CONFIG_PM?

Quoted 81 lines
drivers/media/platform/seco-cec/seco-cec.c new file +81 -0
+static int secocec_suspend(struct device *dev)
+{
+	u16 val;
+	int status;
+
+	dev_dbg(dev, "Device going to suspend, disabling");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Disable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+			  ~SECOCEC_ENABLE_REG_1_CEC & ~SECOCEC_ENABLE_REG_1_IR);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Suspend failed (err: %d)", status);
+	return status;
+}
+
+static int secocec_resume(struct device *dev)
+{
+	u16 val;
+	int status;
+
+	dev_dbg(dev, "Resuming device from suspend");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Device resumed from suspend");
+
+	return 0;
+
+err:
+	dev_err(dev, "Resume failed (err: %d)", status);
+	return status;
+}
+
+static SIMPLE_DEV_PM_OPS(secocec_pm_ops, secocec_suspend, secocec_resume);
+#define SECOCEC_PM_OPS (&secocec_pm_ops)
+#else
+#define SECOCEC_PM_OPS NULL
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id secocec_acpi_match[] = {
+	{"CEC00001", 0},
+	{},
+};
+
+MODULE_DEVICE_TABLE(acpi, secocec_acpi_match);
+#endif

drivers/media/platform/seco-cec/seco-cec.c line 723

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+static struct platform_driver secocec_driver = {
+	.driver = {
+		   .name = SECOCEC_DEV_NAME,
+		   .acpi_match_table = ACPI_PTR(secocec_acpi_match),
+		   .pm = SECOCEC_PM_OPS,
+	},
+	.probe = secocec_probe,
+	.remove = secocec_remove,
+};

As you can see most of my comments are nits or trivial things. I would wait for more feedbacks on the CEC and x86/SMbus part from others before sending v2 if I were you :)

Thanks
j

Quoted 139 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+module_platform_driver(secocec_driver);
+
+MODULE_DESCRIPTION("SECO CEC X86 Driver");
+MODULE_AUTHOR("Ettore Chimenti <[email protected]>");
+MODULE_LICENSE("Dual BSD/GPL");
drivers/media/platform/seco-cec/seco-cec.h new file +127 -0
new file mode 100644
index 000000000000..cc7f0cba8e9e
@@ -0,0 +1,132 @@
+/* SPDX-License-Identifier: GPL-2.0 AND BSD-3-Clause */
+/*
+ *
+ * SECO X86 Boards CEC register defines
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ *
+ */
+
+#ifndef __SECO_CEC_H__
+#define __SECO_CEC_H__
+
+#define SECOCEC_MAX_ADDRS		1
+#define SECOCEC_DEV_NAME		"secocec"
+#define SECOCEC_LATEST_FW		0x0f0b
+
+#define SMBTIMEOUT			0xffff
+#define SMB_POLL_UDELAY			10
+
+#define SMBUS_WRITE			0
+#define SMBUS_READ			1
+
+#define CMD_BYTE_DATA			0
+#define CMD_WORD_DATA			1
+
+/*
+ * SMBus definitons for Braswell
+ */
+
+#define BRA_DONE_STATUS			BIT(7)
+#define BRA_INUSE_STS			BIT(6)
+#define BRA_FAILED_OP			BIT(4)
+#define BRA_BUS_ERR			BIT(3)
+#define BRA_DEV_ERR			BIT(2)
+#define BRA_INTR			BIT(1)
+#define BRA_HOST_BUSY			BIT(0)
+#define BRA_HSTS_ERR_MASK   (BRA_FAILED_OP | BRA_BUS_ERR | BRA_DEV_ERR)
+
+#define BRA_PEC_EN			BIT(7)
+#define BRA_START			BIT(6)
+#define BRA_LAST__BYTE			BIT(5)
+#define BRA_INTREN			BIT(0)
+#define BRA_SMB_CMD			(7 << 2)
+#define BRA_SMB_CMD_QUICK		(0 << 2)
+#define BRA_SMB_CMD_BYTE		(1 << 2)
+#define BRA_SMB_CMD_BYTE_DATA		(2 << 2)
+#define BRA_SMB_CMD_WORD_DATA		(3 << 2)
+#define BRA_SMB_CMD_PROCESS_CALL	(4 << 2)
+#define BRA_SMB_CMD_BLOCK		(5 << 2)
+#define BRA_SMB_CMD_I2CREAD		(6 << 2)
+#define BRA_SMB_CMD_BLOCK_PROCESS	(7 << 2)
+
+#define BRA_SMB_BASE_ADDR  0x2040
+#define HSTS               (BRA_SMB_BASE_ADDR + 0)
+#define HCNT               (BRA_SMB_BASE_ADDR + 2)
+#define HCMD               (BRA_SMB_BASE_ADDR + 3)
+#define XMIT_SLVA          (BRA_SMB_BASE_ADDR + 4)
+#define HDAT0              (BRA_SMB_BASE_ADDR + 5)
+#define HDAT1              (BRA_SMB_BASE_ADDR + 6)
+
+/*
+ * Microcontroller Address
+ */
+
+#define SECOCEC_MICRO_ADDRESS		0x40
+
+/*
+ * STM32 SMBus Registers
+ */
+
+#define SECOCEC_VERSION			0x00
+#define SECOCEC_ENABLE_REG_1		0x01
+#define SECOCEC_ENABLE_REG_2		0x02
+#define SECOCEC_STATUS_REG_1		0x03
+#define SECOCEC_STATUS_REG_2		0x04
+
+#define SECOCEC_STATUS			0x28
+#define SECOCEC_DEVICE_LA		0x29
+#define SECOCEC_READ_OPERATION_ID	0x2a
+#define SECOCEC_READ_DATA_LENGTH	0x2b
+#define SECOCEC_READ_DATA_00		0x2c
+#define SECOCEC_READ_DATA_02		0x2d
+#define SECOCEC_READ_DATA_04		0x2e
+#define SECOCEC_READ_DATA_06		0x2f
+#define SECOCEC_READ_DATA_08		0x30
+#define SECOCEC_READ_DATA_10		0x31
+#define SECOCEC_READ_DATA_12		0x32
+#define SECOCEC_READ_BYTE0		0x33
+#define SECOCEC_WRITE_OPERATION_ID	0x34
+#define SECOCEC_WRITE_DATA_LENGTH	0x35
+#define SECOCEC_WRITE_DATA_00		0x36
+#define SECOCEC_WRITE_DATA_02		0x37
+#define SECOCEC_WRITE_DATA_04		0x38
+#define SECOCEC_WRITE_DATA_06		0x39
+#define SECOCEC_WRITE_DATA_08		0x3a
+#define SECOCEC_WRITE_DATA_10		0x3b
+#define SECOCEC_WRITE_DATA_12		0x3c
+#define SECOCEC_WRITE_BYTE0		0x3d
+
+#define SECOCEC_IR_READ_DATA		0x3e
+
+/*
+ * Enabling register
+ */
+
+#define SECOCEC_ENABLE_REG_1_CEC		0x1000
+#define SECOCEC_ENABLE_REG_1_IR			0x2000
+#define SECOCEC_ENABLE_REG_1_IR_PASSTHROUGH	0x4000
+
+/*
+ * Status register
+ */
+
+#define SECOCEC_STATUS_REG_1_CEC	SECOCEC_ENABLE_REG_1_CEC
+#define SECOCEC_STATUS_REG_1_IR		SECOCEC_ENABLE_REG_1_IR
+#define SECOCEC_STATUS_REG_1_IR_PASSTHR	SECOCEC_ENABLE_REG_1_IR_PASSTHR
+
+/*
+ * Status data
+ */
+
+#define SECOCEC_STATUS_MSG_RECEIVED_MASK	BIT(0)
+#define SECOCEC_STATUS_RX_ERROR_MASK		BIT(1)
+#define SECOCEC_STATUS_MSG_SENT_MASK		BIT(2)
+#define SECOCEC_STATUS_TX_ERROR_MASK		BIT(3)
Quoted 8 lines
Quoted 8 lines
drivers/media/platform/seco-cec/seco-cec.h new file +5 -1
+
+#define SECOCEC_STATUS_TX_NACK_ERROR		BIT(4)
+#define SECOCEC_STATUS_RX_OVERFLOW_MASK		BIT(5)
+
+#endif /* __SECO_CEC_H__ */
--

2.18.0

Regards,

Hans

#12 lore raw
In reply to ektor5

Hi Ettore,

Quoted 10 lines · On 02/10/2018 18:59, ektor5 wrote:

This series of patches aims to add CEC functionalities to SECO devices, in particular UDOO X86.

The communication is achieved via Braswell SMBus (i2c-i801) to the onboard STM32 microcontroller that handles the CEC signals. The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Glad to see another user of the i915 cec notifier !

Neil

Quoted 16 lines

Ettore Chimenti (2):
media: add SECO cec driver
seco-cec: add Consumer-IR support

 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  21 +
 drivers/media/platform/Makefile            |   4 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 859 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 143 ++++
 6 files changed, 1034 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
#9 lore raw

Re: [PATCH 2/2] seco-cec: add Consumer-IR support

In reply to ektor5
Quoted 22 lines · On Tue, Oct 02, 2018 at 06:59:56PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

Introduce support for Consumer-IR into seco-cec driver, as it shares the same interrupt for receiving messages.
The device decodes RC5 signals only, defaults to hauppauge mapping. It will spawn an input interface using the RC framework (like CEC device).

---
 drivers/media/platform/Kconfig             |  10 ++
 drivers/media/platform/seco-cec/seco-cec.c | 136 ++++++++++++++++++++-
 drivers/media/platform/seco-cec/seco-cec.h |  11 ++
 3 files changed, 154 insertions(+), 3 deletions(-)
drivers/media/platform/Kconfig +0 -0
index f477764b902a..5833f488eef8 100644
@@ -624,6 +624,16 @@ config VIDEO_SECO_CEC
          CEC bus is present in the HDMI connector and enables communication
          between compatible devices.

drivers/media/platform/Kconfig config VIDEO_SECO_CEC · line 635

Quoted 10 lines
drivers/media/platform/Kconfig +9 -0
 
+config VIDEO_SECO_RC
+       bool "SECO Boards IR RC5 support"
+       depends on VIDEO_SECO_CEC
+       select RC_CORE
+       help
+	 If you say yes here you will get support for the
+	 SECO Boards Consumer-IR in seco-cec driver.
+         The embedded controller supports RC5 protocol only, default mapping
+         is set to rc-hauppauge.

Strange mixture of spaces/tabs.

Quoted 9 lines
drivers/media/platform/Kconfig +1 -0
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/seco-cec/seco-cec.c +0 -0
index ba3b7c144a87..ee1949395cf4 100644

drivers/media/platform/seco-cec/seco-cec.c struct secocec_data { · line 33

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c +3 -0
@@ -28,6 +28,9 @@ struct secocec_data {
 	struct platform_device *pdev;
 	struct cec_adapter *cec_adap;
 	struct cec_notifier *notifier;
+	struct rc_dev *irda_rc;
+	char irda_input_name[32];
+	char irda_input_phys[32];

IrDA is a completely different encoding than RC-5, CIR or anything rc-core supports; RC-5 is much lower transmission speed. Please do not conflate the two, and rename it either ir_input_phys or rc_input_phys (same for the rest of the functions/members in the rest of the file).

Quoted 9 lines
drivers/media/platform/seco-cec/seco-cec.c +2 -0
 	int irq;
 };
 
@@ -383,6 +386,119 @@ struct cec_adap_ops secocec_cec_adap_ops = {
 	.adap_transmit = secocec_adap_transmit,
 };
 
+#ifdef CONFIG_VIDEO_SECO_RC
+static int secocec_irda_probe(void *priv)

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 400

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c +10 -0
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	int status;
+	u16 val;
+
+	/* Prepare the RC input device */
+	cec->irda_rc = devm_rc_allocate_device(dev, RC_DRIVER_SCANCODE);
+	if (!cec->irda_rc) {
+		dev_err(dev, "Failed to allocate memory for rc_dev");

No need to dev_err() here, kmalloc() will have already reported the error.

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 405

Quoted 5 lines
drivers/media/platform/seco-cec/seco-cec.c +5 -0
+		return -ENOMEM;
+	}
+
+	snprintf(cec->irda_input_name, sizeof(cec->irda_input_name),
+		 "IrDA RC for %s", dev_name(dev));

Since it's an RC device there is no need to put RC in the name. Just use dev_name() as the device_name.

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 417

Quoted 12 lines
drivers/media/platform/seco-cec/seco-cec.c +12 -0
+	snprintf(cec->irda_input_phys, sizeof(cec->irda_input_phys),
+		 "%s/input0", dev_name(dev));
+
+	cec->irda_rc->device_name = cec->irda_input_name;
+	cec->irda_rc->input_phys = cec->irda_input_phys;
+	cec->irda_rc->input_id.bustype = BUS_HOST;
+	cec->irda_rc->input_id.vendor = 0;
+	cec->irda_rc->input_id.product = 0;
+	cec->irda_rc->input_id.version = 1;
+	cec->irda_rc->driver_name = SECOCEC_DEV_NAME;
+	cec->irda_rc->allowed_protocols = RC_PROTO_BIT_RC5;
+	cec->irda_rc->enabled_protocols = RC_PROTO_BIT_RC5;

No need to set enabled_protocols.

Quoted 53 lines
drivers/media/platform/seco-cec/seco-cec.c +53 -0
+	cec->irda_rc->priv = cec;
+	cec->irda_rc->map_name = RC_MAP_HAUPPAUGE;
+	cec->irda_rc->timeout = MS_TO_NS(100);
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status != 0)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status != 0)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status != 0)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  val | SECOCEC_ENABLE_REG_1_IR);
+	if (status != 0)
+		goto err;
+
+	dev_dbg(dev, "IR enabled");
+
+	status = devm_rc_register_device(dev, cec->irda_rc);
+
+	if (status) {
+		dev_err(dev, "Failed to prepare input device");
+		cec->irda_rc = NULL;
+		goto err;
+	}
+
+	return 0;
+
+err:
+	smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+
+	smb_wr16(SECOCEC_ENABLE_REG_1,
+		 val & ~SECOCEC_ENABLE_REG_1_IR);
+
+	dev_dbg(dev, "IR disabled");
+	return status;
+}
+
+static int secocec_irda_rx(struct secocec_data *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	u16 val, status, key, addr, toggle;
+
+	if (!cec->irda_rc)
+		return -ENODEV;

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 480

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c +10 -0
+
+	status = smb_rd16(SECOCEC_IR_READ_DATA, &val);
+	if (status != 0)
+		goto err;
+
+	key = val & SECOCEC_IR_COMMAND_MASK;
+	addr = (val & SECOCEC_IR_ADDRESS_MASK) >> SECOCEC_IR_ADDRESS_SHL;
+	toggle = (val & SECOCEC_IR_TOGGLE_MASK) >> SECOCEC_IR_TOGGLE_SHL;
+
+	rc_keydown(cec->irda_rc, RC_PROTO_RC5, key, toggle);

Here you are just reported the key, not the address. Please use:

	rc_keydown(cec->rc, RC_PROTO_RC5, RC_SCANCODE_RC5(addr, key), toggle);

In fact, you could do:

	rc_keydown(cec->rc, RC_PROTO_RC5, val & 0x1f7f, toggle);

I presume the compile is clever enough to fold those shift instructions.

Quoted 46 lines
drivers/media/platform/seco-cec/seco-cec.c +27 -1
+
+	dev_dbg(dev, "IR key pressed: 0x%02x addr 0x%02x toggle 0x%02x", key,
+		addr, toggle);
+
+	return 0;
+
+err:
+	dev_err(dev, "IR Receive message failed (%d)", status);
+	return -EIO;
+}
+#else
+static void secocec_irda_rx(struct secocec_data *priv)
+{
+}
+
+static int secocec_irda_probe(void *priv)
+{
+	return 0;
+}
+#endif
+
 static irqreturn_t secocec_irq_handler(int irq, void *priv)
 {
 	struct secocec_data *cec = priv;
@@ -420,7 +536,8 @@ static irqreturn_t secocec_irq_handler(int irq, void *priv)
 	if (status_val & SECOCEC_STATUS_REG_1_IR) {
 		dev_dbg(dev, "IR RC5 Interrupt Caught");
 		val |= SECOCEC_STATUS_REG_1_IR;
-		/* TODO IRDA RX */
+
+		secocec_irda_rx(cec);
 	}
 
 	/*  Reset status register */
@@ -595,6 +712,10 @@ static int secocec_probe(struct platform_device *pdev)
 	if (secocec->notifier)
 		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
 
+	ret = secocec_irda_probe(secocec);
+	if (ret)
+		goto err_delete_adapter;
+
 	platform_set_drvdata(pdev, secocec);
 
 	dev_dbg(dev, "Device registered");

drivers/media/platform/seco-cec/seco-cec.c static int secocec_probe(struct platform_device *pdev) · line 744

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c +6 -0
@@ -614,7 +735,16 @@ static int secocec_probe(struct platform_device *pdev)
 static int secocec_remove(struct platform_device *pdev)
 {
 	struct secocec_data *secocec = platform_get_drvdata(pdev);
+	u16 val;
+
+	if (secocec->irda_rc) {
+		smb_rd16(SECOCEC_ENABLE_REG_1, &val);
 
+		smb_wr16(SECOCEC_ENABLE_REG_1,
+			 val & ~SECOCEC_ENABLE_REG_1_IR);

Those two fit on one line.

Quoted 50 lines
drivers/media/platform/seco-cec/seco-cec.c +5 -2
+
+		dev_dbg(&pdev->dev, "IR disabled");
+	}
 	cec_unregister_adapter(secocec->cec_adap);
 
 	if (secocec->notifier)
@@ -632,8 +762,8 @@ static int secocec_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int secocec_suspend(struct device *dev)
 {
-	u16 val;
 	int status;
+	u16 val;
 
 	dev_dbg(dev, "Device going to suspend, disabling");
 
@@ -665,8 +795,8 @@ static int secocec_suspend(struct device *dev)
 
 static int secocec_resume(struct device *dev)
 {
-	u16 val;
 	int status;
+	u16 val;
 
 	dev_dbg(dev, "Resuming device from suspend");
 
drivers/media/platform/seco-cec/seco-cec.h +11 -0
index cc7f0cba8e9e..c00660104a3e 100644
@@ -101,6 +101,17 @@
 
 #define SECOCEC_IR_READ_DATA		0x3e
 
+/*
+ * IR
+ */
+
+#define SECOCEC_IR_COMMAND_MASK		0x007F
+#define SECOCEC_IR_COMMAND_SHL		0
+#define SECOCEC_IR_ADDRESS_MASK		0x1F00
+#define SECOCEC_IR_ADDRESS_SHL		7
+#define SECOCEC_IR_TOGGLE_MASK		0x8000
+#define SECOCEC_IR_TOGGLE_SHL		15
+
 /*
  * Enabling register
  */
Signature · 1 line
2.18.0

Thanks,
Sean

author
#13 lore raw
In reply to Neil Armstrong
Quoted 11 lines · Neil Armstrong

Hi Ettore,

Quoted 8 lines · On 02/10/2018 18:59, ektor5 wrote:

This series of patches aims to add CEC functionalities to SECO devices, in particular UDOO X86.

The communication is achieved via Braswell SMBus (i2c-i801) to the onboard STM32 microcontroller that handles the CEC signals. The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

Quoted 4 lines
Quoted 2 lines

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Glad to see another user of the i915 cec notifier !

Thanks to you for the patch! It works really well!

Ettore

Quoted 20 lines

Neil

Quoted 16 lines

Ettore Chimenti (2):
media: add SECO cec driver
seco-cec: add Consumer-IR support

 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  21 +
 drivers/media/platform/Makefile            |   4 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 859 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 143 ++++
 6 files changed, 1034 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
author
#6 lore raw

Re: [PATCH 1/2] media: add SECO cec driver

In reply to Hans Verkuil

Hi Hans,

Quoted 73 lines · Hans Verkuil
Quoted 59 lines · jacopo mondi

Hi Ettore,
thanks for the patch.

A few comments below, please have a look...

Quoted 53 lines · On Tue, Oct 02, 2018 at 06:59:55PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

This patch adds support to the CEC device implemented with a STM32 microcontroller in X86 SECO Boards, including UDOO X86.

The communication is achieved via Braswell integrated SMBus (i2c-i801). The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Inspired by cros-ec-cec implementation, attaches to i915 driver cec-notifier.

---
 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  11 +
 drivers/media/platform/Makefile            |   4 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 729 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 132 ++++
 6 files changed, 883 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
MAINTAINERS +6 -0
index 4ece30f15777..1062912a5ff4 100644
@@ -12972,6 +12972,12 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 F:	drivers/mmc/host/sdricoh_cs.c
 
+SECO BOARDS CEC DRIVER
+M:	Ettore Chimenti <[email protected]>
+S:	Maintained
+F:	drivers/media/platform/seco-cec/seco-cec.c
+F:	drivers/media/platform/seco-cec/seco-cec.h
+
 SECURE COMPUTING
 M:	Kees Cook <[email protected]>
 R:	Andy Lutomirski <[email protected]>
drivers/media/platform/Kconfig +0 -0
index 94c1fe0e9787..f477764b902a 100644
@@ -613,6 +613,17 @@ config VIDEO_TEGRA_HDMI_CEC
 	 The CEC bus is present in the HDMI connector and enables communication
 	 between compatible devices.
 
Quoted 12 lines

drivers/media/platform/Kconfig config VIDEO_TEGRA_HDMI_CEC · line 623

Quoted 8 lines
drivers/media/platform/Kconfig +8 -0
+config VIDEO_SECO_CEC
+       tristate "SECO Boards HDMI CEC driver"
+       depends on (X86 || IA64) || COMPILE_TEST
+       select CEC_CORE
+       select CEC_NOTIFIER
+       help
+         This is a driver for SECO Boards integrated CEC interface. It uses the
+         generic CEC framework interface.

Is it worth mentioning the software framework used for implementing the driver? Anyway, I see this is common to most of the CEC drivers here, so I guess it is fine

Quoted 3 lines

It's not worth mentioning :-)

Not sure how and why that phrase crept into cec driver Kconfigs.

Ok, will remove that and add some more useful information. :)

Quoted 543 lines
Quoted 531 lines
Quoted 13 lines
drivers/media/platform/Kconfig +3 -0
+         CEC bus is present in the HDMI connector and enables communication
+         between compatible devices.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/Makefile +0 -0
index 41322ab65802..cc7365c787ba 100644

drivers/media/platform/Makefile obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC) += tegra-cec/ · line 59

Quoted 7 lines
drivers/media/platform/Makefile +4 -0
@@ -53,6 +53,10 @@ obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC)	+= tegra-cec/
 
 obj-y					+= stm32/
 
+obj-$(CONFIG_VIDEO_SECO_CEC)		+= seco-cec/
+
+obj-y                                   += blackfin/
+

Ups! Is this a leftover from some BSP code? It breaks the build on media-tree master (and I guess on master too)

drivers/media/platform/seco-cec/Makefile line 1

Quoted 10 lines
drivers/media/platform/Makefile +0 -0
 obj-y					+= davinci/
 
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
drivers/media/platform/seco-cec/Makefile new file +1 -0
new file mode 100644
index 000000000000..a3f2c6bd3ac0
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_SECO_CEC) += seco-cec.o

This can simply be obj-y as you parse this makefile entry conditionally to the presence of the CONFIG_VIDEO_SECO_CEC symbol

drivers/media/platform/seco-cec/seco-cec.c line 1

Quoted 7 lines
drivers/media/platform/seco-cec/seco-cec.c new file +1 -0
new file mode 100644
index 000000000000..ba3b7c144a87
@@ -0,0 +1,729 @@
+// SPDX-License-Identifier: GPL-2.0 AND BSD-3-Clause

Just make sure the AND is what you want (I only see OR clauses in drivers/ code). See Documentation/process/license-rules.rst

drivers/media/platform/seco-cec/seco-cec.c line 3

Quoted 2 lines
drivers/media/platform/seco-cec/seco-cec.c new file +2 -0
+/*
+ *

Nit: empty comment line

drivers/media/platform/seco-cec/seco-cec.c line 9

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+ * CEC driver for SECO X86 Boards
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ *

Nit: empty comment line

Quoted 5 lines
drivers/media/platform/seco-cec/seco-cec.c new file +5 -0
+ */
+
+#include <linux/interrupt.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>

drivers/media/platform/seco-cec/seco-cec.c line 24

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/dmi.h>
+
+/* CEC Framework */
+#include <media/cec.h>
+
+#include "seco-cec.h"

I would question why a header file is needed as it is not included by anything else

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+struct secocec_data {
+	struct device *dev;
+	struct platform_device *pdev;
+	struct cec_adapter *cec_adap;
+	struct cec_notifier *notifier;
+	int irq;
+};
+
+#define smb_wr16(cmd, data) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \

drivers/media/platform/seco-cec/seco-cec.c line 44

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+					     cmd, data, SMBUS_WRITE, NULL)
+#define smb_rd16(cmd, res) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \
+				       cmd, 0, SMBUS_READ, res)
+
+static int smb_word_op(short data_format, u16 slave_addr, u8 cmd, u16 data,
+		       u8 operation, u16 *result)
+{
+	unsigned int count;
+	short _data_format;
+	int ret, status = 0;

In the rest of the function ret is used only once, and you can use status in its place. Please drop one of the two.

Quoted 13 lines
drivers/media/platform/seco-cec/seco-cec.c new file +13 -0
+
+	switch (data_format) {
+	case CMD_BYTE_DATA:
+		_data_format = BRA_SMB_CMD_BYTE_DATA;
+		break;
+	case CMD_WORD_DATA:
+		_data_format = BRA_SMB_CMD_WORD_DATA;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Active wait until ready */

drivers/media/platform/seco-cec/seco-cec.c line 67

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	for (count = 0; count <= SMBTIMEOUT; ++count) {
+		if (!(inb(HSTS) & BRA_INUSE_STS))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		/* Reset the lock instead of failing */
+		outb(0xff, HSTS);
+		pr_warn("%s: SMBTIMEOUT\n", __func__);

No pr_debug/pr_warn if possible, please.

Quoted 65 lines
drivers/media/platform/seco-cec/seco-cec.c new file +65 -0
+	}
+
+	outb(0x00, HCNT);
+	outb((u8)(slave_addr & 0xfe) | operation, XMIT_SLVA);
+	outb(cmd, HCMD);
+	inb(HCNT);
+
+	if (operation == SMBUS_WRITE) {
+		outb((u8)data, HDAT0);
+		outb((u8)(data >> 8), HDAT1);
+		pr_debug("%s: WRITE (0x%02x - count %05d): 0x%04x\n",
+			 __func__, cmd, count, data);
+	}
+
+	outb(BRA_START + _data_format, HCNT);
+
+	for (count = 0; count <= SMBTIMEOUT; count++) {
+		if (!(inb(HSTS) & BRA_HOST_BUSY))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		pr_debug("%s: SMBTIMEOUT_1\n", __func__);
+		status = -EBUSY;
+		goto err;
+	}
+
+	ret = inb(HSTS);
+	if (ret & BRA_HSTS_ERR_MASK) {
+		pr_debug("%s: HSTS(0x%02X): 0x%X\n", __func__, cmd, ret);
+		status = -EIO;
+		goto err;
+	}
+
+	if (operation == SMBUS_READ) {
+		*result = ((inb(HDAT0) & 0xff) + ((inb(HDAT1) & 0xff) << 8));
+		pr_debug("%s: READ (0x%02x - count %05d): 0x%04x\n",
+			 __func__, cmd, count, *result);
+	}
+
+err:
+	outb(0xff, HSTS);
+	return status;
+}
+
+static int secocec_adap_enable(struct cec_adapter *adap, bool enable)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 val = 0;
+	int status;
+
+	if (enable) {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Enable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);

drivers/media/platform/seco-cec/seco-cec.c line 142

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1,
+				  val | SECOCEC_ENABLE_REG_1_CEC);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device enabled");
+

Empty line

Quoted 172 lines
drivers/media/platform/seco-cec/seco-cec.c new file +172 -0
+	} else {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Disable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+				  ~SECOCEC_ENABLE_REG_1_CEC &
+				  ~SECOCEC_ENABLE_REG_1_IR);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device disabled");
+	}
+
+	return 0;
+err:
+	dev_err(dev, "Adapter setup failed (%d)", status);
+	return status;
+}
+
+static int secocec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr)
+{
+	u16 enable_val = 0;
+	int status;
+
+	/* Disable device */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &enable_val);
+	if (status)
+		return status;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val & ~SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	/* Write logical address */
+	status = smb_wr16(SECOCEC_DEVICE_LA, logical_addr);
+	if (status)
+		return status;
+
+	/* Re-enable device */
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	return 0;
+}
+
+static int secocec_adap_transmit(struct cec_adapter *adap, u8 attempts,
+				 u32 signal_free_time, struct cec_msg *msg)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 payload_len, payload_id_len, destination, val = 0;
+	u8 *payload_msg;
+	int status;
+	u8 i;
+
+	/* Device msg len already accounts for header */
+	payload_id_len = msg->len - 1;
+
+	/* Send data length */
+	status = smb_wr16(SECOCEC_WRITE_DATA_LENGTH, payload_id_len);
+	if (status)
+		goto err;
+
+	/* Send Operation ID if present */
+	if (payload_id_len > 0) {
+		status = smb_wr16(SECOCEC_WRITE_OPERATION_ID, msg->msg[1]);
+		if (status)
+			goto err;
+	}
+	/* Send data if present */
+	if (payload_id_len > 1) {
+		/* Only data; */
+		payload_len = msg->len - 2;
+		payload_msg = &msg->msg[2];
+
+		/* Copy message into registers */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			/* hi byte */
+			val = payload_msg[(i << 1) + 1] << 8;
+
+			/* lo byte */
+			val |= payload_msg[(i << 1)];
+
+			status = smb_wr16(SECOCEC_WRITE_DATA_00 + i, val);
+			if (status)
+				goto err;
+		}
+	}
+	/* Send msg source/destination and fire msg */
+	destination = msg->msg[0];
+	status = smb_wr16(SECOCEC_WRITE_BYTE0, destination);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Transmit failed (%d)", status);
+	return status;
+}
+
+static int secocec_tx_done(struct cec_adapter *adap, u16 status_val)
+{
+	int status = 0;
+
+	if (status_val & SECOCEC_STATUS_TX_ERROR_MASK) {
+		if (status_val & SECOCEC_STATUS_TX_NACK_ERROR) {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_NACK);
+			status = -EAGAIN;
+		} else {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_ERROR);
+			status = -EIO;
+		}
+	} else {
+		cec_transmit_attempt_done(adap, CEC_TX_STATUS_OK);
+	}
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_TX_ERROR_MASK |
+		SECOCEC_STATUS_MSG_SENT_MASK |
+		SECOCEC_STATUS_TX_NACK_ERROR;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+	return status;
+}
+
+static int secocec_rx_done(struct cec_adapter *adap, u16 status_val)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	struct cec_msg msg = { };
+	bool flag_overflow = false;
+	u8 payload_len, i = 0;
+	u8 *payload_msg;
+	u16 val = 0;
+	int status;
+
+	if (status_val & SECOCEC_STATUS_RX_OVERFLOW_MASK) {
+		dev_warn(dev, "Received more than 16 bytes. Discarding");
+		flag_overflow = true;
+	}
+
+	if (status_val & SECOCEC_STATUS_RX_ERROR_MASK) {
+		dev_warn(dev, "Message received with errors. Discarding");
+		status = -EIO;
+		goto rxerr;
+	}
+
+	/* Read message length */
+	status = smb_rd16(SECOCEC_READ_DATA_LENGTH, &val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Incoming message (payload len %d):", val);
+
+	/* Device msg len already accounts for the header */
+	msg.len = min(val + 1, CEC_MAX_MSG_SIZE);
+

drivers/media/platform/seco-cec/seco-cec.c line 324

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	/* Read logical address */
+	status = smb_rd16(SECOCEC_READ_BYTE0, &val);
+	if (status)
+		goto err;
+
+	/* device stores source LA and destination */
+	msg.msg[0] = val;
+
+	/* Read operation ID if present */
+	if (msg.len > 0) {

Am I wrong or msg.len is at least (val + 1) and val is never negative? If that's true, this condition is always verified.

Quoted 65 lines
drivers/media/platform/seco-cec/seco-cec.c new file +65 -0
+		status = smb_rd16(SECOCEC_READ_OPERATION_ID, &val);
+		if (status)
+			goto err;
+
+		msg.msg[1] = val;
+	}
+
+	/* Read data if present */
+	if (msg.len > 1) {
+		payload_len = msg.len - 2;
+		payload_msg = &msg.msg[2];
+
+		/* device stores 2 bytes in every 16-bit val */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			status = smb_rd16(SECOCEC_READ_DATA_00 + i, &val);
+			if (status)
+				goto err;
+
+			/* low byte, skipping header */
+			payload_msg[(i << 1)] = val & 0x00ff;
+
+			/* hi byte */
+			payload_msg[(i << 1) + 1] = (val & 0xff00) >> 8;
+		}
+	}
+
+	cec_received_msg(cec->cec_adap, &msg);
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+
+	status = smb_wr16(SECOCEC_STATUS, status_val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Message received successfully");
+
+	return 0;
+
+rxerr:
+	/* Reset error reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK |
+		SECOCEC_STATUS_RX_ERROR_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+err:
+	dev_err(dev, "Receive message failed (%d)", status);
+	return status;
+}
+
+struct cec_adap_ops secocec_cec_adap_ops = {
+	/* Low-level callbacks */
+	.adap_enable = secocec_adap_enable,
+	.adap_log_addr = secocec_adap_log_addr,
+	.adap_transmit = secocec_adap_transmit,
+};
+
+static irqreturn_t secocec_irq_handler(int irq, void *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;

drivers/media/platform/seco-cec/seco-cec.c line 399

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	u16 status_val, cec_val, val = 0;
+	int status;
+
+	/*  Read status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &status_val);
+	if (status)
+		goto err;
+
+	if (status_val & SECOCEC_STATUS_REG_1_CEC) {
+		dev_dbg(dev, "+++++ CEC Interrupt Caught");

Just be carefull in too much printouts while handling interrupts. Also, I would not insert custom printout formats (here and below in this functions). I would simply drop this one.

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+		/* Read CEC status register */
+		status = smb_rd16(SECOCEC_STATUS, &cec_val);
+		if (status)
+			goto err;
+

drivers/media/platform/seco-cec/seco-cec.c line 415

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		if (cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK)
+			secocec_rx_done(cec->cec_adap, cec_val);
+
+		if (cec_val & SECOCEC_STATUS_MSG_SENT_MASK)
+			secocec_tx_done(cec->cec_adap, cec_val);
+
+		if ((~cec_val & SECOCEC_STATUS_MSG_SENT_MASK) &&
+		    (~cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK))
+			dev_warn(dev,
+				 "Message not received or sent, but interrupt fired \\_\"._/");

No custom funny printouts please :)

drivers/media/platform/seco-cec/seco-cec.c line 421

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+		val = SECOCEC_STATUS_REG_1_CEC;
+	}
+
+	if (status_val & SECOCEC_STATUS_REG_1_IR) {
+		dev_dbg(dev, "IR RC5 Interrupt Caught");

How frequent is this one? Do you need to print it out?

drivers/media/platform/seco-cec/seco-cec.c line 431

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		val |= SECOCEC_STATUS_REG_1_IR;
+		/* TODO IRDA RX */
+	}
+
+	/*  Reset status register */
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "----- CEC Interrupt Handled");

Drop this one please

Quoted 18 lines
drivers/media/platform/seco-cec/seco-cec.c new file +18 -0
+
+	return IRQ_HANDLED;
+
+err:
+	dev_err(dev, "IRQ: Read/Write SMBus operation failed (%d)", status);
+
+	/*  Reset status register */
+	val = SECOCEC_STATUS_REG_1_CEC | SECOCEC_STATUS_REG_1_IR;
+	smb_wr16(SECOCEC_STATUS_REG_1, val);
+
+	return IRQ_HANDLED;
+}
+
+struct cec_dmi_match {
+	char *sys_vendor;
+	char *product_name;
+	char *devname;
+	char *conn;
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 457

Quoted 8 lines
drivers/media/platform/seco-cec/seco-cec.c new file +8 -0
+};
+
+static const struct cec_dmi_match secocec_dmi_match_table[] = {
+	/* UDOO X86 */
+	{ "SECO", "UDOO x86", "0000:00:02.0", "Port B" },
+};
+
+static int secocec_cec_get_notifier(struct cec_notifier **notify)

If you compare this driver with cros-ec-cec.c, then you'll see that there this function is under "#if IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_DMI)".

Quoted 2 lines

I think you should do the same and (just like cros-ec-cec.c) add a dummy function in the #else part.

I'm not sure about this. Doing so, compiling without CONFIG_PCI or CONFIG_DMI, it will fail later when no notifier is found (now it will probably fail at compile time). Should I select them in the Kconfig or it is better to eventually disable the notifier and go on adding CEC_CAP_PHYS_ADDR to device capabilities?

Quoted 108 lines
Quoted 99 lines
Quoted 8 lines
drivers/media/platform/seco-cec/seco-cec.c new file +7 -0
+{
+	int i;
+
+	for (i = 0 ; i < ARRAY_SIZE(secocec_dmi_match_table) ; ++i) {
+		const struct cec_dmi_match *m = &secocec_dmi_match_table[i];
+
+		if (dmi_match(DMI_SYS_VENDOR, m->sys_vendor) &&

drivers/media/platform/seco-cec/seco-cec.c line 474

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+		    dmi_match(DMI_PRODUCT_NAME, m->product_name)) {
+			struct device *d;
+
+			/* Find the device, bail out if not yet registered */
+			d = bus_find_device_by_name(&pci_bus_type, NULL,
+						    m->devname);
+			if (!d)
+				return -EPROBE_DEFER;
+
+			*notify = cec_notifier_get_conn(d, m->conn);

Nit: it's usually nice to have an empty line before return (here and in other places). Not mandatory though.

Quoted 77 lines
drivers/media/platform/seco-cec/seco-cec.c new file +77 -0
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int secocec_acpi_probe(struct secocec_data *sdev)
+{
+	struct device *dev = sdev->dev;
+	struct gpio_desc *gpio;
+	int irq = 0;
+
+	gpio = devm_gpiod_get(dev, NULL, GPIOF_IN);
+	if (IS_ERR(gpio)) {
+		dev_err(dev, "Cannot request interrupt gpio");
+		return PTR_ERR(gpio);
+	}
+
+	irq = gpiod_to_irq(gpio);
+	if (irq < 0) {
+		dev_err(dev, "Cannot find valid irq");
+		return -ENODEV;
+	}
+	dev_dbg(dev, "irq-gpio is bound to IRQ %d", irq);
+
+	sdev->irq = irq;
+
+	return 0;
+}
+
+static int secocec_probe(struct platform_device *pdev)
+{
+	struct secocec_data *secocec;
+	struct device *dev = &pdev->dev;
+	u8 cec_caps;
+	int ret;
+	u16 val;
+
+	secocec = devm_kzalloc(dev, sizeof(*secocec), GFP_KERNEL);
+	if (!secocec)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, secocec);
+
+	/* Request SMBus regions */
+	if (!request_muxed_region(BRA_SMB_BASE_ADDR, 7, "CEC00001")) {
+		dev_err(dev, "Request memory region failed");
+		return -ENXIO;
+	}
+
+	secocec->pdev = pdev;
+	secocec->dev = dev;
+
+	if (!has_acpi_companion(dev)) {
+		dev_dbg(dev, "Cannot find any ACPI companion");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	ret = secocec_acpi_probe(secocec);
+	if (ret) {
+		dev_err(dev, "Cannot assign gpio to IRQ");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	dev_dbg(dev, "IRQ detected at %d", secocec->irq);
+
+	/* Firmware version check */
+	ret = smb_rd16(SECOCEC_VERSION, &val);
+	if (ret) {
+		dev_err(dev, "Cannot check fw version");
+		goto err;
+	}
+	if (val < SECOCEC_LATEST_FW) {
+		dev_err(dev, "CEC Firmware not supported (v.%04x). Use ver > v.%04x",
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 557

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+			val, SECOCEC_LATEST_FW);
+		ret = -EINVAL;
+		goto err;
+	}
+
+#ifdef CONFIG_CEC_NOTIFIER

Your Kconfig entry selects CEC_NOTIFIER.

Quoted 1 line

Yes, this #ifdef line can be dropped.

Yes, agree.

Quoted 343 lines
Quoted 6 lines

(I won't comment on the cec_notifier handling part, as I don't know much. I just see other drivers registering and getting the notifier using the cec_notifier_ functions, while it seems to me you don't. Maybe it's fine...)

It's fine :-)

Quoted 20 lines
Quoted 20 lines
drivers/media/platform/seco-cec/seco-cec.c new file +19 -0
+	ret = secocec_cec_get_notifier(&secocec->notifier);
+	if (ret) {
+		dev_err(dev, "no CEC notifier available\n");
+		goto err;
+	}
+#endif
+
+	ret = devm_request_threaded_irq(dev,
+					secocec->irq,
+					NULL,
+					secocec_irq_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					dev_name(&pdev->dev), secocec);
+
+	if (ret) {
+		dev_err(dev, "Cannot request IRQ %d", secocec->irq);
+		ret = -EIO;
+		goto err;
+	}
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 584

Quoted 8 lines
drivers/media/platform/seco-cec/seco-cec.c new file +8 -0
+
+	/* Allocate CEC adapter */
+	cec_caps = CEC_CAP_DEFAULTS;
+
+	secocec->cec_adap = cec_allocate_adapter(&secocec_cec_adap_ops,
+						 secocec,
+						 dev_name(dev),
+						 cec_caps, SECOCEC_MAX_ADDRS);

You can drop cec_caps and just pass CEC_CAP_DEFAULTS directly.

Quoted 292 lines
Quoted 38 lines
drivers/media/platform/seco-cec/seco-cec.c new file +38 -0
+
+	if (IS_ERR(secocec->cec_adap)) {
+		ret = PTR_ERR(secocec->cec_adap);
+		goto err;
+	}
+
+	ret = cec_register_adapter(secocec->cec_adap, dev);
+	if (ret)
+		goto err_delete_adapter;
+
+	if (secocec->notifier)
+		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
+
+	platform_set_drvdata(pdev, secocec);
+
+	dev_dbg(dev, "Device registered");
+
+	return ret;
+
+err_delete_adapter:
+	cec_delete_adapter(secocec->cec_adap);
+err:
+	dev_err(dev, "%s device probe failed\n", dev_name(dev));
+
+	return ret;
+}
+
+/* ----------------------------------------------------------------------- */
+
+static int secocec_remove(struct platform_device *pdev)
+{
+	struct secocec_data *secocec = platform_get_drvdata(pdev);
+
+	cec_unregister_adapter(secocec->cec_adap);
+
+	if (secocec->notifier)
+		cec_notifier_put(secocec->notifier);
+

drivers/media/platform/seco-cec/seco-cec.c line 632

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	release_region(BRA_SMB_BASE_ADDR, 7);
+
+	dev_dbg(&pdev->dev, "CEC device removed");
+
+	return 0;
+}
+
+/* ----------------------------------------------------------------------- */
+
+#ifdef CONFIG_PM_SLEEP

I see CONFIG_PM_SLEEP is only selected if support for 'suspend'/'hibernate' is enabled. Is this what you want, or you should check for CONFIG_PM?

Quoted 81 lines
drivers/media/platform/seco-cec/seco-cec.c new file +81 -0
+static int secocec_suspend(struct device *dev)
+{
+	u16 val;
+	int status;
+
+	dev_dbg(dev, "Device going to suspend, disabling");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Disable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+			  ~SECOCEC_ENABLE_REG_1_CEC & ~SECOCEC_ENABLE_REG_1_IR);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Suspend failed (err: %d)", status);
+	return status;
+}
+
+static int secocec_resume(struct device *dev)
+{
+	u16 val;
+	int status;
+
+	dev_dbg(dev, "Resuming device from suspend");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Device resumed from suspend");
+
+	return 0;
+
+err:
+	dev_err(dev, "Resume failed (err: %d)", status);
+	return status;
+}
+
+static SIMPLE_DEV_PM_OPS(secocec_pm_ops, secocec_suspend, secocec_resume);
+#define SECOCEC_PM_OPS (&secocec_pm_ops)
+#else
+#define SECOCEC_PM_OPS NULL
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id secocec_acpi_match[] = {
+	{"CEC00001", 0},
+	{},
+};
+
+MODULE_DEVICE_TABLE(acpi, secocec_acpi_match);
+#endif

drivers/media/platform/seco-cec/seco-cec.c line 723

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+static struct platform_driver secocec_driver = {
+	.driver = {
+		   .name = SECOCEC_DEV_NAME,
+		   .acpi_match_table = ACPI_PTR(secocec_acpi_match),
+		   .pm = SECOCEC_PM_OPS,
+	},
+	.probe = secocec_probe,
+	.remove = secocec_remove,
+};

As you can see most of my comments are nits or trivial things. I would wait for more feedbacks on the CEC and x86/SMbus part from others before sending v2 if I were you :)

Thanks
j

Quoted 139 lines
drivers/media/platform/seco-cec/seco-cec.c new file +6 -0
+
+module_platform_driver(secocec_driver);
+
+MODULE_DESCRIPTION("SECO CEC X86 Driver");
+MODULE_AUTHOR("Ettore Chimenti <[email protected]>");
+MODULE_LICENSE("Dual BSD/GPL");
drivers/media/platform/seco-cec/seco-cec.h new file +127 -0
new file mode 100644
index 000000000000..cc7f0cba8e9e
@@ -0,0 +1,132 @@
+/* SPDX-License-Identifier: GPL-2.0 AND BSD-3-Clause */
+/*
+ *
+ * SECO X86 Boards CEC register defines
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ *
+ */
+
+#ifndef __SECO_CEC_H__
+#define __SECO_CEC_H__
+
+#define SECOCEC_MAX_ADDRS		1
+#define SECOCEC_DEV_NAME		"secocec"
+#define SECOCEC_LATEST_FW		0x0f0b
+
+#define SMBTIMEOUT			0xffff
+#define SMB_POLL_UDELAY			10
+
+#define SMBUS_WRITE			0
+#define SMBUS_READ			1
+
+#define CMD_BYTE_DATA			0
+#define CMD_WORD_DATA			1
+
+/*
+ * SMBus definitons for Braswell
+ */
+
+#define BRA_DONE_STATUS			BIT(7)
+#define BRA_INUSE_STS			BIT(6)
+#define BRA_FAILED_OP			BIT(4)
+#define BRA_BUS_ERR			BIT(3)
+#define BRA_DEV_ERR			BIT(2)
+#define BRA_INTR			BIT(1)
+#define BRA_HOST_BUSY			BIT(0)
+#define BRA_HSTS_ERR_MASK   (BRA_FAILED_OP | BRA_BUS_ERR | BRA_DEV_ERR)
+
+#define BRA_PEC_EN			BIT(7)
+#define BRA_START			BIT(6)
+#define BRA_LAST__BYTE			BIT(5)
+#define BRA_INTREN			BIT(0)
+#define BRA_SMB_CMD			(7 << 2)
+#define BRA_SMB_CMD_QUICK		(0 << 2)
+#define BRA_SMB_CMD_BYTE		(1 << 2)
+#define BRA_SMB_CMD_BYTE_DATA		(2 << 2)
+#define BRA_SMB_CMD_WORD_DATA		(3 << 2)
+#define BRA_SMB_CMD_PROCESS_CALL	(4 << 2)
+#define BRA_SMB_CMD_BLOCK		(5 << 2)
+#define BRA_SMB_CMD_I2CREAD		(6 << 2)
+#define BRA_SMB_CMD_BLOCK_PROCESS	(7 << 2)
+
+#define BRA_SMB_BASE_ADDR  0x2040
+#define HSTS               (BRA_SMB_BASE_ADDR + 0)
+#define HCNT               (BRA_SMB_BASE_ADDR + 2)
+#define HCMD               (BRA_SMB_BASE_ADDR + 3)
+#define XMIT_SLVA          (BRA_SMB_BASE_ADDR + 4)
+#define HDAT0              (BRA_SMB_BASE_ADDR + 5)
+#define HDAT1              (BRA_SMB_BASE_ADDR + 6)
+
+/*
+ * Microcontroller Address
+ */
+
+#define SECOCEC_MICRO_ADDRESS		0x40
+
+/*
+ * STM32 SMBus Registers
+ */
+
+#define SECOCEC_VERSION			0x00
+#define SECOCEC_ENABLE_REG_1		0x01
+#define SECOCEC_ENABLE_REG_2		0x02
+#define SECOCEC_STATUS_REG_1		0x03
+#define SECOCEC_STATUS_REG_2		0x04
+
+#define SECOCEC_STATUS			0x28
+#define SECOCEC_DEVICE_LA		0x29
+#define SECOCEC_READ_OPERATION_ID	0x2a
+#define SECOCEC_READ_DATA_LENGTH	0x2b
+#define SECOCEC_READ_DATA_00		0x2c
+#define SECOCEC_READ_DATA_02		0x2d
+#define SECOCEC_READ_DATA_04		0x2e
+#define SECOCEC_READ_DATA_06		0x2f
+#define SECOCEC_READ_DATA_08		0x30
+#define SECOCEC_READ_DATA_10		0x31
+#define SECOCEC_READ_DATA_12		0x32
+#define SECOCEC_READ_BYTE0		0x33
+#define SECOCEC_WRITE_OPERATION_ID	0x34
+#define SECOCEC_WRITE_DATA_LENGTH	0x35
+#define SECOCEC_WRITE_DATA_00		0x36
+#define SECOCEC_WRITE_DATA_02		0x37
+#define SECOCEC_WRITE_DATA_04		0x38
+#define SECOCEC_WRITE_DATA_06		0x39
+#define SECOCEC_WRITE_DATA_08		0x3a
+#define SECOCEC_WRITE_DATA_10		0x3b
+#define SECOCEC_WRITE_DATA_12		0x3c
+#define SECOCEC_WRITE_BYTE0		0x3d
+
+#define SECOCEC_IR_READ_DATA		0x3e
+
+/*
+ * Enabling register
+ */
+
+#define SECOCEC_ENABLE_REG_1_CEC		0x1000
+#define SECOCEC_ENABLE_REG_1_IR			0x2000
+#define SECOCEC_ENABLE_REG_1_IR_PASSTHROUGH	0x4000
+
+/*
+ * Status register
+ */
+
+#define SECOCEC_STATUS_REG_1_CEC	SECOCEC_ENABLE_REG_1_CEC
+#define SECOCEC_STATUS_REG_1_IR		SECOCEC_ENABLE_REG_1_IR
+#define SECOCEC_STATUS_REG_1_IR_PASSTHR	SECOCEC_ENABLE_REG_1_IR_PASSTHR
+
+/*
+ * Status data
+ */
+
+#define SECOCEC_STATUS_MSG_RECEIVED_MASK	BIT(0)
+#define SECOCEC_STATUS_RX_ERROR_MASK		BIT(1)
+#define SECOCEC_STATUS_MSG_SENT_MASK		BIT(2)
+#define SECOCEC_STATUS_TX_ERROR_MASK		BIT(3)
Quoted 8 lines
Quoted 8 lines
drivers/media/platform/seco-cec/seco-cec.h new file +5 -1
+
+#define SECOCEC_STATUS_TX_NACK_ERROR		BIT(4)
+#define SECOCEC_STATUS_RX_OVERFLOW_MASK		BIT(5)
+
+#endif /* __SECO_CEC_H__ */
--

2.18.0

Regards,

Quoted 1 line

Hans

Thanks a lot again,

Ettore

#7 lore raw

Re: [PATCH 1/2] media: add SECO cec driver

Quoted 7 lines · On 10/04/2018 11:31 PM, ektor5 wrote:

Hi Hans,

Quoted 5 lines
Quoted 1 line
Quoted 1 line

+static int secocec_cec_get_notifier(struct cec_notifier **notify)

If you compare this driver with cros-ec-cec.c, then you'll see that there this function is under "#if IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_DMI)".

Quoted 8 lines
Quoted 2 lines

I think you should do the same and (just like cros-ec-cec.c) add a dummy function in the #else part.

I'm not sure about this. Doing so, compiling without CONFIG_PCI or CONFIG_DMI, it will fail later when no notifier is found (now it will probably fail at compile time). Should I select them in the Kconfig or it is better to eventually disable the notifier and go on adding CEC_CAP_PHYS_ADDR to device capabilities?

After thinking about this some more, you can just add:

depends on PCI && DMI

in the Kconfig.

Much easier, really.

Regards,

Hans

author
#10 lore raw

Re: [PATCH 2/2] seco-cec: add Consumer-IR support

In reply to Sean Young

Hi Sean,

Quoted 24 lines · Sean Young
Quoted 23 lines · On Tue, Oct 02, 2018 at 06:59:56PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

Introduce support for Consumer-IR into seco-cec driver, as it shares the same interrupt for receiving messages.
The device decodes RC5 signals only, defaults to hauppauge mapping. It will spawn an input interface using the RC framework (like CEC device).

---
 drivers/media/platform/Kconfig             |  10 ++
 drivers/media/platform/seco-cec/seco-cec.c | 136 ++++++++++++++++++++-
 drivers/media/platform/seco-cec/seco-cec.h |  11 ++
 3 files changed, 154 insertions(+), 3 deletions(-)
drivers/media/platform/Kconfig +0 -0
index f477764b902a..5833f488eef8 100644
@@ -624,6 +624,16 @@ config VIDEO_SECO_CEC
          CEC bus is present in the HDMI connector and enables communication
          between compatible devices.
 
Quoted 11 lines

drivers/media/platform/Kconfig config VIDEO_SECO_CEC · line 635

Quoted 9 lines
drivers/media/platform/Kconfig +9 -0
+config VIDEO_SECO_RC
+       bool "SECO Boards IR RC5 support"
+       depends on VIDEO_SECO_CEC
+       select RC_CORE
+       help
+	 If you say yes here you will get support for the
+	 SECO Boards Consumer-IR in seco-cec driver.
+         The embedded controller supports RC5 protocol only, default mapping
+         is set to rc-hauppauge.

Strange mixture of spaces/tabs.

Ops. Yes, will fix.

Quoted 13 lines
Quoted 13 lines
drivers/media/platform/Kconfig +1 -0
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/seco-cec/seco-cec.c +0 -0
index ba3b7c144a87..ee1949395cf4 100644
@@ -28,6 +28,9 @@ struct secocec_data {
 	struct platform_device *pdev;
 	struct cec_adapter *cec_adap;
 	struct cec_notifier *notifier;
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c struct secocec_data { · line 33

Quoted 3 lines
drivers/media/platform/seco-cec/seco-cec.c +3 -0
+	struct rc_dev *irda_rc;
+	char irda_input_name[32];
+	char irda_input_phys[32];

IrDA is a completely different encoding than RC-5, CIR or anything rc-core supports; RC-5 is much lower transmission speed. Please do not conflate the two, and rename it either ir_input_phys or rc_input_phys (same for the rest of the functions/members in the rest of the file).

Yes, I figured out that in the middle of developing. I got rid of most of the "irda" references, but I have accidentally left some of them. Will finish the work.

Quoted 8 lines
Quoted 8 lines
drivers/media/platform/seco-cec/seco-cec.c +0 -0
 	int irq;
 };
 
@@ -383,6 +386,119 @@ struct cec_adap_ops secocec_cec_adap_ops = {
 	.adap_transmit = secocec_adap_transmit,
 };
 
Quoted 14 lines

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 400

Quoted 12 lines
drivers/media/platform/seco-cec/seco-cec.c +12 -0
+#ifdef CONFIG_VIDEO_SECO_RC
+static int secocec_irda_probe(void *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	int status;
+	u16 val;
+
+	/* Prepare the RC input device */
+	cec->irda_rc = devm_rc_allocate_device(dev, RC_DRIVER_SCANCODE);
+	if (!cec->irda_rc) {
+		dev_err(dev, "Failed to allocate memory for rc_dev");

No need to dev_err() here, kmalloc() will have already reported the error.

Ok, will remove.

Quoted 9 lines

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 405

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c +5 -0
+		return -ENOMEM;
+	}
+
+	snprintf(cec->irda_input_name, sizeof(cec->irda_input_name),
+		 "IrDA RC for %s", dev_name(dev));

Since it's an RC device there is no need to put RC in the name. Just use dev_name() as the device_name.

I took that from CEC RC Passthrough device name.

Quoted 15 lines

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 417

Quoted 13 lines
drivers/media/platform/seco-cec/seco-cec.c +12 -0
+	snprintf(cec->irda_input_phys, sizeof(cec->irda_input_phys),
+		 "%s/input0", dev_name(dev));
+
+	cec->irda_rc->device_name = cec->irda_input_name;
+	cec->irda_rc->input_phys = cec->irda_input_phys;
+	cec->irda_rc->input_id.bustype = BUS_HOST;
+	cec->irda_rc->input_id.vendor = 0;
+	cec->irda_rc->input_id.product = 0;
+	cec->irda_rc->input_id.version = 1;
+	cec->irda_rc->driver_name = SECOCEC_DEV_NAME;
+	cec->irda_rc->allowed_protocols = RC_PROTO_BIT_RC5;
+	cec->irda_rc->enabled_protocols = RC_PROTO_BIT_RC5;

No need to set enabled_protocols.

Ok.

Quoted 67 lines
Quoted 54 lines
drivers/media/platform/seco-cec/seco-cec.c +53 -0
+	cec->irda_rc->priv = cec;
+	cec->irda_rc->map_name = RC_MAP_HAUPPAUGE;
+	cec->irda_rc->timeout = MS_TO_NS(100);
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status != 0)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status != 0)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status != 0)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  val | SECOCEC_ENABLE_REG_1_IR);
+	if (status != 0)
+		goto err;
+
+	dev_dbg(dev, "IR enabled");
+
+	status = devm_rc_register_device(dev, cec->irda_rc);
+
+	if (status) {
+		dev_err(dev, "Failed to prepare input device");
+		cec->irda_rc = NULL;
+		goto err;
+	}
+
+	return 0;
+
+err:
+	smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+
+	smb_wr16(SECOCEC_ENABLE_REG_1,
+		 val & ~SECOCEC_ENABLE_REG_1_IR);
+
+	dev_dbg(dev, "IR disabled");
+	return status;
+}
+
+static int secocec_irda_rx(struct secocec_data *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	u16 val, status, key, addr, toggle;
+
+	if (!cec->irda_rc)
+		return -ENODEV;

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 480

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c +10 -0
+
+	status = smb_rd16(SECOCEC_IR_READ_DATA, &val);
+	if (status != 0)
+		goto err;
+
+	key = val & SECOCEC_IR_COMMAND_MASK;
+	addr = (val & SECOCEC_IR_ADDRESS_MASK) >> SECOCEC_IR_ADDRESS_SHL;
+	toggle = (val & SECOCEC_IR_TOGGLE_MASK) >> SECOCEC_IR_TOGGLE_SHL;
+
+	rc_keydown(cec->irda_rc, RC_PROTO_RC5, key, toggle);

Here you are just reported the key, not the address. Please use:

Quoted 7 lines
	rc_keydown(cec->rc, RC_PROTO_RC5, RC_SCANCODE_RC5(addr, key), toggle);

In fact, you could do:

	rc_keydown(cec->rc, RC_PROTO_RC5, val & 0x1f7f, toggle);

I presume the compile is clever enough to fold those shift instructions.

I wondered why the address wasn't used, it had to be together. Thanks. :)

Quoted 105 lines
Quoted 47 lines
drivers/media/platform/seco-cec/seco-cec.c +27 -1
+
+	dev_dbg(dev, "IR key pressed: 0x%02x addr 0x%02x toggle 0x%02x", key,
+		addr, toggle);
+
+	return 0;
+
+err:
+	dev_err(dev, "IR Receive message failed (%d)", status);
+	return -EIO;
+}
+#else
+static void secocec_irda_rx(struct secocec_data *priv)
+{
+}
+
+static int secocec_irda_probe(void *priv)
+{
+	return 0;
+}
+#endif
+
 static irqreturn_t secocec_irq_handler(int irq, void *priv)
 {
 	struct secocec_data *cec = priv;
@@ -420,7 +536,8 @@ static irqreturn_t secocec_irq_handler(int irq, void *priv)
 	if (status_val & SECOCEC_STATUS_REG_1_IR) {
 		dev_dbg(dev, "IR RC5 Interrupt Caught");
 		val |= SECOCEC_STATUS_REG_1_IR;
-		/* TODO IRDA RX */
+
+		secocec_irda_rx(cec);
 	}
 
 	/*  Reset status register */
@@ -595,6 +712,10 @@ static int secocec_probe(struct platform_device *pdev)
 	if (secocec->notifier)
 		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
 
+	ret = secocec_irda_probe(secocec);
+	if (ret)
+		goto err_delete_adapter;
+
 	platform_set_drvdata(pdev, secocec);
 
 	dev_dbg(dev, "Device registered");

drivers/media/platform/seco-cec/seco-cec.c static int secocec_probe(struct platform_device *pdev) · line 744

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c +6 -0
@@ -614,7 +735,16 @@ static int secocec_probe(struct platform_device *pdev)
 static int secocec_remove(struct platform_device *pdev)
 {
 	struct secocec_data *secocec = platform_get_drvdata(pdev);
+	u16 val;
+
+	if (secocec->irda_rc) {
+		smb_rd16(SECOCEC_ENABLE_REG_1, &val);
 
+		smb_wr16(SECOCEC_ENABLE_REG_1,
+			 val & ~SECOCEC_ENABLE_REG_1_IR);

Those two fit on one line.

Quoted 45 lines
drivers/media/platform/seco-cec/seco-cec.c +5 -2
+
+		dev_dbg(&pdev->dev, "IR disabled");
+	}
 	cec_unregister_adapter(secocec->cec_adap);
 
 	if (secocec->notifier)
@@ -632,8 +762,8 @@ static int secocec_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int secocec_suspend(struct device *dev)
 {
-	u16 val;
 	int status;
+	u16 val;
 
 	dev_dbg(dev, "Device going to suspend, disabling");
 
@@ -665,8 +795,8 @@ static int secocec_suspend(struct device *dev)
 
 static int secocec_resume(struct device *dev)
 {
-	u16 val;
 	int status;
+	u16 val;
 
 	dev_dbg(dev, "Resuming device from suspend");
 
drivers/media/platform/seco-cec/seco-cec.h +11 -0
index cc7f0cba8e9e..c00660104a3e 100644
@@ -101,6 +101,17 @@
 
 #define SECOCEC_IR_READ_DATA		0x3e
 
+/*
+ * IR
+ */
+
+#define SECOCEC_IR_COMMAND_MASK		0x007F
+#define SECOCEC_IR_COMMAND_SHL		0
+#define SECOCEC_IR_ADDRESS_MASK		0x1F00
+#define SECOCEC_IR_ADDRESS_SHL		7
+#define SECOCEC_IR_TOGGLE_MASK		0x8000
+#define SECOCEC_IR_TOGGLE_SHL		15
+
Quoted 8 lines
Quoted 5 lines
drivers/media/platform/seco-cec/seco-cec.h +0 -0
 /*
  * Enabling register
  */
Signature · 1 line
2.18.0

Thanks,
Sean

Thanks a lot,
Ettore

#11 lore raw

Re: [PATCH 2/2] seco-cec: add Consumer-IR support

Hi Ettore,

Quoted 102 lines · On Thu, Oct 04, 2018 at 11:46:45PM +0200, ektor5 wrote:

Hi Sean,

Quoted 24 lines · Sean Young
Quoted 23 lines · On Tue, Oct 02, 2018 at 06:59:56PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

Introduce support for Consumer-IR into seco-cec driver, as it shares the same interrupt for receiving messages.
The device decodes RC5 signals only, defaults to hauppauge mapping. It will spawn an input interface using the RC framework (like CEC device).

---
 drivers/media/platform/Kconfig             |  10 ++
 drivers/media/platform/seco-cec/seco-cec.c | 136 ++++++++++++++++++++-
 drivers/media/platform/seco-cec/seco-cec.h |  11 ++
 3 files changed, 154 insertions(+), 3 deletions(-)
drivers/media/platform/Kconfig +0 -0
index f477764b902a..5833f488eef8 100644
@@ -624,6 +624,16 @@ config VIDEO_SECO_CEC
          CEC bus is present in the HDMI connector and enables communication
          between compatible devices.
 
Quoted 11 lines

drivers/media/platform/Kconfig config VIDEO_SECO_CEC · line 635

Quoted 9 lines
drivers/media/platform/Kconfig +9 -0
+config VIDEO_SECO_RC
+       bool "SECO Boards IR RC5 support"
+       depends on VIDEO_SECO_CEC
+       select RC_CORE
+       help
+	 If you say yes here you will get support for the
+	 SECO Boards Consumer-IR in seco-cec driver.
+         The embedded controller supports RC5 protocol only, default mapping
+         is set to rc-hauppauge.

Strange mixture of spaces/tabs.

Ops. Yes, will fix.

Quoted 13 lines
Quoted 13 lines
drivers/media/platform/Kconfig +1 -0
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/seco-cec/seco-cec.c +0 -0
index ba3b7c144a87..ee1949395cf4 100644
@@ -28,6 +28,9 @@ struct secocec_data {
 	struct platform_device *pdev;
 	struct cec_adapter *cec_adap;
 	struct cec_notifier *notifier;
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c struct secocec_data { · line 33

Quoted 3 lines
drivers/media/platform/seco-cec/seco-cec.c +3 -0
+	struct rc_dev *irda_rc;
+	char irda_input_name[32];
+	char irda_input_phys[32];

IrDA is a completely different encoding than RC-5, CIR or anything rc-core supports; RC-5 is much lower transmission speed. Please do not conflate the two, and rename it either ir_input_phys or rc_input_phys (same for the rest of the functions/members in the rest of the file).

Yes, I figured out that in the middle of developing. I got rid of most of the "irda" references, but I have accidentally left some of them. Will finish the work.

Quoted 8 lines
Quoted 8 lines
drivers/media/platform/seco-cec/seco-cec.c +0 -0
 	int irq;
 };
 
@@ -383,6 +386,119 @@ struct cec_adap_ops secocec_cec_adap_ops = {
 	.adap_transmit = secocec_adap_transmit,
 };
 
Quoted 14 lines

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 400

Quoted 12 lines
drivers/media/platform/seco-cec/seco-cec.c +12 -0
+#ifdef CONFIG_VIDEO_SECO_RC
+static int secocec_irda_probe(void *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	int status;
+	u16 val;
+
+	/* Prepare the RC input device */
+	cec->irda_rc = devm_rc_allocate_device(dev, RC_DRIVER_SCANCODE);
+	if (!cec->irda_rc) {
+		dev_err(dev, "Failed to allocate memory for rc_dev");

No need to dev_err() here, kmalloc() will have already reported the error.

Ok, will remove.

Quoted 9 lines

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 405

Quoted 6 lines
drivers/media/platform/seco-cec/seco-cec.c +5 -0
+		return -ENOMEM;
+	}
+
+	snprintf(cec->irda_input_name, sizeof(cec->irda_input_name),
+		 "IrDA RC for %s", dev_name(dev));

Since it's an RC device there is no need to put RC in the name. Just use dev_name() as the device_name.

Quoted 1 line

I took that from CEC RC Passthrough device name.

Thanks for pointing that out, I've just submitted a patch to fix that one as well:

	https://patchwork.linuxtv.org/patch/52376/

Hans, what do you think?

Quoted 210 lines
Quoted 16 lines
Quoted 4 lines
drivers/media/platform/seco-cec/seco-cec.c +2 -0
+	snprintf(cec->irda_input_phys, sizeof(cec->irda_input_phys),
+		 "%s/input0", dev_name(dev));

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 417

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c +10 -0
+
+	cec->irda_rc->device_name = cec->irda_input_name;
+	cec->irda_rc->input_phys = cec->irda_input_phys;
+	cec->irda_rc->input_id.bustype = BUS_HOST;
+	cec->irda_rc->input_id.vendor = 0;
+	cec->irda_rc->input_id.product = 0;
+	cec->irda_rc->input_id.version = 1;
+	cec->irda_rc->driver_name = SECOCEC_DEV_NAME;
+	cec->irda_rc->allowed_protocols = RC_PROTO_BIT_RC5;
+	cec->irda_rc->enabled_protocols = RC_PROTO_BIT_RC5;

No need to set enabled_protocols.

Ok.

Quoted 67 lines
Quoted 54 lines
drivers/media/platform/seco-cec/seco-cec.c +53 -0
+	cec->irda_rc->priv = cec;
+	cec->irda_rc->map_name = RC_MAP_HAUPPAUGE;
+	cec->irda_rc->timeout = MS_TO_NS(100);
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status != 0)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status != 0)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status != 0)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  val | SECOCEC_ENABLE_REG_1_IR);
+	if (status != 0)
+		goto err;
+
+	dev_dbg(dev, "IR enabled");
+
+	status = devm_rc_register_device(dev, cec->irda_rc);
+
+	if (status) {
+		dev_err(dev, "Failed to prepare input device");
+		cec->irda_rc = NULL;
+		goto err;
+	}
+
+	return 0;
+
+err:
+	smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+
+	smb_wr16(SECOCEC_ENABLE_REG_1,
+		 val & ~SECOCEC_ENABLE_REG_1_IR);
+
+	dev_dbg(dev, "IR disabled");
+	return status;
+}
+
+static int secocec_irda_rx(struct secocec_data *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	u16 val, status, key, addr, toggle;
+
+	if (!cec->irda_rc)
+		return -ENODEV;

drivers/media/platform/seco-cec/seco-cec.c struct cec_adap_ops secocec_cec_adap_ops = { · line 480

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c +10 -0
+
+	status = smb_rd16(SECOCEC_IR_READ_DATA, &val);
+	if (status != 0)
+		goto err;
+
+	key = val & SECOCEC_IR_COMMAND_MASK;
+	addr = (val & SECOCEC_IR_ADDRESS_MASK) >> SECOCEC_IR_ADDRESS_SHL;
+	toggle = (val & SECOCEC_IR_TOGGLE_MASK) >> SECOCEC_IR_TOGGLE_SHL;
+
+	rc_keydown(cec->irda_rc, RC_PROTO_RC5, key, toggle);

Here you are just reported the key, not the address. Please use:

Quoted 7 lines
	rc_keydown(cec->rc, RC_PROTO_RC5, RC_SCANCODE_RC5(addr, key), toggle);

In fact, you could do:

	rc_keydown(cec->rc, RC_PROTO_RC5, val & 0x1f7f, toggle);

I presume the compile is clever enough to fold those shift instructions.

I wondered why the address wasn't used, it had to be together. Thanks. :)

Quoted 105 lines
Quoted 47 lines
drivers/media/platform/seco-cec/seco-cec.c +27 -1
+
+	dev_dbg(dev, "IR key pressed: 0x%02x addr 0x%02x toggle 0x%02x", key,
+		addr, toggle);
+
+	return 0;
+
+err:
+	dev_err(dev, "IR Receive message failed (%d)", status);
+	return -EIO;
+}
+#else
+static void secocec_irda_rx(struct secocec_data *priv)
+{
+}
+
+static int secocec_irda_probe(void *priv)
+{
+	return 0;
+}
+#endif
+
 static irqreturn_t secocec_irq_handler(int irq, void *priv)
 {
 	struct secocec_data *cec = priv;
@@ -420,7 +536,8 @@ static irqreturn_t secocec_irq_handler(int irq, void *priv)
 	if (status_val & SECOCEC_STATUS_REG_1_IR) {
 		dev_dbg(dev, "IR RC5 Interrupt Caught");
 		val |= SECOCEC_STATUS_REG_1_IR;
-		/* TODO IRDA RX */
+
+		secocec_irda_rx(cec);
 	}
 
 	/*  Reset status register */
@@ -595,6 +712,10 @@ static int secocec_probe(struct platform_device *pdev)
 	if (secocec->notifier)
 		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
 
+	ret = secocec_irda_probe(secocec);
+	if (ret)
+		goto err_delete_adapter;
+
 	platform_set_drvdata(pdev, secocec);
 
 	dev_dbg(dev, "Device registered");

drivers/media/platform/seco-cec/seco-cec.c static int secocec_probe(struct platform_device *pdev) · line 744

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c +6 -0
@@ -614,7 +735,16 @@ static int secocec_probe(struct platform_device *pdev)
 static int secocec_remove(struct platform_device *pdev)
 {
 	struct secocec_data *secocec = platform_get_drvdata(pdev);
+	u16 val;
+
+	if (secocec->irda_rc) {
+		smb_rd16(SECOCEC_ENABLE_REG_1, &val);
 
+		smb_wr16(SECOCEC_ENABLE_REG_1,
+			 val & ~SECOCEC_ENABLE_REG_1_IR);

Those two fit on one line.

Quoted 45 lines
drivers/media/platform/seco-cec/seco-cec.c +5 -2
+
+		dev_dbg(&pdev->dev, "IR disabled");
+	}
 	cec_unregister_adapter(secocec->cec_adap);
 
 	if (secocec->notifier)
@@ -632,8 +762,8 @@ static int secocec_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int secocec_suspend(struct device *dev)
 {
-	u16 val;
 	int status;
+	u16 val;
 
 	dev_dbg(dev, "Device going to suspend, disabling");
 
@@ -665,8 +795,8 @@ static int secocec_suspend(struct device *dev)
 
 static int secocec_resume(struct device *dev)
 {
-	u16 val;
 	int status;
+	u16 val;
 
 	dev_dbg(dev, "Resuming device from suspend");
 
drivers/media/platform/seco-cec/seco-cec.h +11 -0
index cc7f0cba8e9e..c00660104a3e 100644
@@ -101,6 +101,17 @@
 
 #define SECOCEC_IR_READ_DATA		0x3e
 
+/*
+ * IR
+ */
+
+#define SECOCEC_IR_COMMAND_MASK		0x007F
+#define SECOCEC_IR_COMMAND_SHL		0
+#define SECOCEC_IR_ADDRESS_MASK		0x1F00
+#define SECOCEC_IR_ADDRESS_SHL		7
+#define SECOCEC_IR_TOGGLE_MASK		0x8000
+#define SECOCEC_IR_TOGGLE_SHL		15
+
Quoted 8 lines
Quoted 5 lines
drivers/media/platform/seco-cec/seco-cec.h +0 -0
 /*
  * Enabling register
  */
Signature · 1 line
2.18.0

Thanks,
Sean

Quoted 2 lines

Thanks a lot,
Ettore

Thanks,
Sean

author
#14 lore raw

v2 cover Add SECO Boards CEC device driver

In reply to ektor5

This series of patches aims to add CEC functionalities to SECO devices, in particular UDOO X86.

The communication is achieved via Braswell SMBus (i2c-i801) to the onboard STM32 microcontroller that handles the CEC signals. The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

v2:
- Removed useless debug prints
- Added DMI && PCI to dependences
- Removed useless ifdefs
- Renamed all irda references to ir
- Fixed SPDX clause
- Several style fixes

Ettore Chimenti (2):
media: add SECO cec driver
seco-cec: add Consumer-IR support

 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  22 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 829 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 141 ++++
 6 files changed, 1001 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
Signature · 1 line
2.18.0
author
#15 lore raw

PATCH v2 1/2 media: add SECO cec driver

From: Ettore Chimenti <[email protected]>

This patch adds support to the CEC device implemented with a STM32 microcontroller in X86 SECO Boards, including UDOO X86.

The communication is achieved via Braswell integrated SMBus (i2c-i801). The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Inspired by cros-ec-cec implementation, attaches to i915 driver cec-notifier.

---
 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  12 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 706 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 130 ++++
 6 files changed, 857 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
MAINTAINERS +6 -0
index 4ece30f15777..1062912a5ff4 100644
@@ -12972,6 +12972,12 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 F:	drivers/mmc/host/sdricoh_cs.c
 
+SECO BOARDS CEC DRIVER
+M:	Ettore Chimenti <[email protected]>
+S:	Maintained
+F:	drivers/media/platform/seco-cec/seco-cec.c
+F:	drivers/media/platform/seco-cec/seco-cec.h
+
 SECURE COMPUTING
 M:	Kees Cook <[email protected]>
 R:	Andy Lutomirski <[email protected]>
drivers/media/platform/Kconfig +12 -0
index 94c1fe0e9787..51cd1fd005e3 100644
@@ -613,6 +613,18 @@ config VIDEO_TEGRA_HDMI_CEC
 	 The CEC bus is present in the HDMI connector and enables communication
 	 between compatible devices.
 
+config VIDEO_SECO_CEC
+	tristate "SECO Boards HDMI CEC driver"
+	depends on (X86 || IA64) || COMPILE_TEST
+	depends on PCI && DMI
+	select CEC_CORE
+	select CEC_NOTIFIER
+	help
+	  This is a driver for SECO Boards integrated CEC interface.
+	  Selecting it will enable support for this device.
+	  CEC bus is present in the HDMI connector and enables communication
+	  between compatible devices.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/Makefile +2 -0
index 41322ab65802..5d2b06c4c68a 100644
@@ -53,6 +53,8 @@ obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC)	+= tegra-cec/
 
 obj-y					+= stm32/
 
+obj-$(CONFIG_VIDEO_SECO_CEC)		+= seco-cec/
+
 obj-y					+= davinci/
 
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
drivers/media/platform/seco-cec/Makefile new file +1 -0
new file mode 100644
index 000000000000..09900b087d02
@@ -0,0 +1 @@
+obj-y += seco-cec.o
drivers/media/platform/seco-cec/seco-cec.c new file +706 -0

706 lines not on this page · raw message

drivers/media/platform/seco-cec/seco-cec.h new file +130 -0

130 lines not on this page · raw message

Signature · 1 line
2.18.0
author
#19 lore raw

PATCH v2 2/2 seco-cec: add Consumer-IR support

In reply to ektor5

From: Ettore Chimenti <[email protected]>

Introduce support for Consumer-IR into seco-cec driver, as it shares the same interrupt for receiving messages.
The device decodes RC5 signals only, defaults to hauppauge mapping. It will spawn an input interface using the RC framework (like CEC device).

---
 drivers/media/platform/Kconfig             |  10 ++
 drivers/media/platform/seco-cec/seco-cec.c | 125 ++++++++++++++++++++-
 drivers/media/platform/seco-cec/seco-cec.h |  11 ++
 3 files changed, 145 insertions(+), 1 deletion(-)
drivers/media/platform/Kconfig +10 -0
index 51cd1fd005e3..e6b45da2af6d 100644
@@ -625,6 +625,16 @@ config VIDEO_SECO_CEC
 	  CEC bus is present in the HDMI connector and enables communication
 	  between compatible devices.
 
+config VIDEO_SECO_RC
+	bool "SECO Boards IR RC5 support"
+	depends on VIDEO_SECO_CEC
+	select RC_CORE
+	help
+	  If you say yes here you will get support for the
+	  SECO Boards Consumer-IR in seco-cec driver.
+	  The embedded controller supports RC5 protocol only, default mapping
+	  is set to rc-hauppauge.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/seco-cec/seco-cec.c +124 -1

156 lines not on this page · raw message

drivers/media/platform/seco-cec/seco-cec.h +11 -0
index 93020900935e..3f1aad89b073 100644
@@ -99,6 +99,17 @@
 
 #define SECOCEC_IR_READ_DATA		0x3e
 
+/*
+ * IR
+ */
+
+#define SECOCEC_IR_COMMAND_MASK		0x007F
+#define SECOCEC_IR_COMMAND_SHL		0
+#define SECOCEC_IR_ADDRESS_MASK		0x1F00
+#define SECOCEC_IR_ADDRESS_SHL		7
+#define SECOCEC_IR_TOGGLE_MASK		0x8000
+#define SECOCEC_IR_TOGGLE_SHL		15
+
 /*
  * Enabling register
  */
Signature · 1 line
2.18.0
Reviewed-by on v2 2/2
#20 lore raw

Re: [PATCH v2 2/2] seco-cec: add Consumer-IR support

Quoted 9 lines · On Fri, Oct 05, 2018 at 07:33:59PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

Introduce support for Consumer-IR into seco-cec driver, as it shares the same interrupt for receiving messages.
The device decodes RC5 signals only, defaults to hauppauge mapping. It will spawn an input interface using the RC framework (like CEC device).

Looks great, thanks!

Quoted 216 lines
---
 drivers/media/platform/Kconfig             |  10 ++
 drivers/media/platform/seco-cec/seco-cec.c | 125 ++++++++++++++++++++-
 drivers/media/platform/seco-cec/seco-cec.h |  11 ++
 3 files changed, 145 insertions(+), 1 deletion(-)
drivers/media/platform/Kconfig +10 -0
index 51cd1fd005e3..e6b45da2af6d 100644
@@ -625,6 +625,16 @@ config VIDEO_SECO_CEC
 	  CEC bus is present in the HDMI connector and enables communication
 	  between compatible devices.
 
+config VIDEO_SECO_RC
+	bool "SECO Boards IR RC5 support"
+	depends on VIDEO_SECO_CEC
+	select RC_CORE
+	help
+	  If you say yes here you will get support for the
+	  SECO Boards Consumer-IR in seco-cec driver.
+	  The embedded controller supports RC5 protocol only, default mapping
+	  is set to rc-hauppauge.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/seco-cec/seco-cec.c +124 -1
index 990e88f979a2..6ae42fc855ef 100644
@@ -26,6 +26,8 @@ struct secocec_data {
 	struct platform_device *pdev;
 	struct cec_adapter *cec_adap;
 	struct cec_notifier *notifier;
+	struct rc_dev *ir;
+	char ir_input_phys[32];
 	int irq;
 };
 
@@ -371,6 +373,114 @@ struct cec_adap_ops secocec_cec_adap_ops = {
 	.adap_transmit = secocec_adap_transmit,
 };
 
+#ifdef CONFIG_VIDEO_SECO_RC
+static int secocec_ir_probe(void *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	int status;
+	u16 val;
+
+	/* Prepare the RC input device */
+	cec->ir = devm_rc_allocate_device(dev, RC_DRIVER_SCANCODE);
+	if (!cec->ir)
+		return -ENOMEM;
+
+	snprintf(cec->ir_input_phys, sizeof(cec->ir_input_phys),
+		 "%s/input0", dev_name(dev));
+
+	cec->ir->device_name = dev_name(dev);
+	cec->ir->input_phys = cec->ir_input_phys;
+	cec->ir->input_id.bustype = BUS_HOST;
+	cec->ir->input_id.vendor = 0;
+	cec->ir->input_id.product = 0;
+	cec->ir->input_id.version = 1;
+	cec->ir->driver_name = SECOCEC_DEV_NAME;
+	cec->ir->allowed_protocols = RC_PROTO_BIT_RC5;
+	cec->ir->priv = cec;
+	cec->ir->map_name = RC_MAP_HAUPPAUGE;
+	cec->ir->timeout = MS_TO_NS(100);
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status != 0)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status != 0)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status != 0)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  val | SECOCEC_ENABLE_REG_1_IR);
+	if (status != 0)
+		goto err;
+
+	dev_dbg(dev, "IR enabled");
+
+	status = devm_rc_register_device(dev, cec->ir);
+
+	if (status) {
+		dev_err(dev, "Failed to prepare input device");
+		cec->ir = NULL;
+		goto err;
+	}
+
+	return 0;
+
+err:
+	smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+
+	smb_wr16(SECOCEC_ENABLE_REG_1,
+		 val & ~SECOCEC_ENABLE_REG_1_IR);
+
+	dev_dbg(dev, "IR disabled");
+	return status;
+}
+
+static int secocec_ir_rx(struct secocec_data *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	u16 val, status, key, addr, toggle;
+
+	if (!cec->ir)
+		return -ENODEV;
+
+	status = smb_rd16(SECOCEC_IR_READ_DATA, &val);
+	if (status != 0)
+		goto err;
+
+	key = val & SECOCEC_IR_COMMAND_MASK;
+	addr = (val & SECOCEC_IR_ADDRESS_MASK) >> SECOCEC_IR_ADDRESS_SHL;
+	toggle = (val & SECOCEC_IR_TOGGLE_MASK) >> SECOCEC_IR_TOGGLE_SHL;
+
+	rc_keydown(cec->ir, RC_PROTO_RC5, RC_SCANCODE_RC5(addr, key), toggle);
+
+	dev_dbg(dev, "IR key pressed: 0x%02x addr 0x%02x toggle 0x%02x", key,
+		addr, toggle);
+
+	return 0;
+
+err:
+	dev_err(dev, "IR Receive message failed (%d)", status);
+	return -EIO;
+}
+#else
+static void secocec_ir_rx(struct secocec_data *priv)
+{
+}
+
+static int secocec_ir_probe(void *priv)
+{
+	return 0;
+}
+#endif
+
 static irqreturn_t secocec_irq_handler(int irq, void *priv)
 {
 	struct secocec_data *cec = priv;
@@ -406,7 +516,8 @@ static irqreturn_t secocec_irq_handler(int irq, void *priv)
 	if (status_val & SECOCEC_STATUS_REG_1_IR) {
 		dev_dbg(dev, "IR RC5 Interrupt Caught");
 		val |= SECOCEC_STATUS_REG_1_IR;
-		/* TODO IRDA RX */
+
+		secocec_ir_rx(cec);
 	}
 
 	/*  Reset status register */
@@ -576,6 +687,10 @@ static int secocec_probe(struct platform_device *pdev)
 	if (secocec->notifier)
 		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
 
+	ret = secocec_ir_probe(secocec);
+	if (ret)
+		goto err_delete_adapter;
+
 	platform_set_drvdata(pdev, secocec);
 
 	dev_dbg(dev, "Device registered");
@@ -593,7 +708,15 @@ static int secocec_probe(struct platform_device *pdev)
 static int secocec_remove(struct platform_device *pdev)
 {
 	struct secocec_data *secocec = platform_get_drvdata(pdev);
+	u16 val;
+
+	if (secocec->ir) {
+		smb_rd16(SECOCEC_ENABLE_REG_1, &val);
 
+		smb_wr16(SECOCEC_ENABLE_REG_1, val & ~SECOCEC_ENABLE_REG_1_IR);
+
+		dev_dbg(&pdev->dev, "IR disabled");
+	}
 	cec_unregister_adapter(secocec->cec_adap);
 
 	if (secocec->notifier)
drivers/media/platform/seco-cec/seco-cec.h +11 -0
index 93020900935e..3f1aad89b073 100644
@@ -99,6 +99,17 @@
 
 #define SECOCEC_IR_READ_DATA		0x3e
 
+/*
+ * IR
+ */
+
+#define SECOCEC_IR_COMMAND_MASK		0x007F
+#define SECOCEC_IR_COMMAND_SHL		0
+#define SECOCEC_IR_ADDRESS_MASK		0x1F00
+#define SECOCEC_IR_ADDRESS_SHL		7
+#define SECOCEC_IR_TOGGLE_MASK		0x8000
+#define SECOCEC_IR_TOGGLE_SHL		15
+
 /*
  * Enabling register
  */
Signature · 1 line
2.18.0
#16 lore raw

Re: [PATCH v2 1/2] media: add SECO cec driver

In reply to ektor5

Hi Ettore,
some more comments below.

Quoted 9 lines · On Fri, Oct 05, 2018 at 07:33:58PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

This patch adds support to the CEC device implemented with a STM32 microcontroller in X86 SECO Boards, including UDOO X86.

The communication is achieved via Braswell integrated SMBus (i2c-i801). The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

Quoted 7 lines

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Inspired by cros-ec-cec implementation, attaches to i915 driver cec-notifier.

Iterations of the same patchset are not usually sent 'in-reply-to' mode as far as I've seen.

Quoted 86 lines
---
 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  12 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 706 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 130 ++++
 6 files changed, 857 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
MAINTAINERS +6 -0
index 4ece30f15777..1062912a5ff4 100644
@@ -12972,6 +12972,12 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 F:	drivers/mmc/host/sdricoh_cs.c
 
+SECO BOARDS CEC DRIVER
+M:	Ettore Chimenti <[email protected]>
+S:	Maintained
+F:	drivers/media/platform/seco-cec/seco-cec.c
+F:	drivers/media/platform/seco-cec/seco-cec.h
+
 SECURE COMPUTING
 M:	Kees Cook <[email protected]>
 R:	Andy Lutomirski <[email protected]>
drivers/media/platform/Kconfig +12 -0
index 94c1fe0e9787..51cd1fd005e3 100644
@@ -613,6 +613,18 @@ config VIDEO_TEGRA_HDMI_CEC
 	 The CEC bus is present in the HDMI connector and enables communication
 	 between compatible devices.
 
+config VIDEO_SECO_CEC
+	tristate "SECO Boards HDMI CEC driver"
+	depends on (X86 || IA64) || COMPILE_TEST
+	depends on PCI && DMI
+	select CEC_CORE
+	select CEC_NOTIFIER
+	help
+	  This is a driver for SECO Boards integrated CEC interface.
+	  Selecting it will enable support for this device.
+	  CEC bus is present in the HDMI connector and enables communication
+	  between compatible devices.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/Makefile +2 -0
index 41322ab65802..5d2b06c4c68a 100644
@@ -53,6 +53,8 @@ obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC)	+= tegra-cec/
 
 obj-y					+= stm32/
 
+obj-$(CONFIG_VIDEO_SECO_CEC)		+= seco-cec/
+
 obj-y					+= davinci/
 
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
drivers/media/platform/seco-cec/Makefile new file +1 -0
new file mode 100644
index 000000000000..09900b087d02
@@ -0,0 +1 @@
+obj-y += seco-cec.o
drivers/media/platform/seco-cec/seco-cec.c new file +8 -0
new file mode 100644
index 000000000000..990e88f979a2
@@ -0,0 +1,706 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+/*
+ * CEC driver for SECO X86 Boards
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ */

drivers/media/platform/seco-cec/seco-cec.c line 18

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+#include <linux/interrupt.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/dmi.h>
+

Please keep headers alphabetically sorted, it's easier to identify duplications or unnecessary inclusions

Quoted 37 lines
drivers/media/platform/seco-cec/seco-cec.c new file +37 -0
+/* CEC Framework */
+#include <media/cec.h>
+
+#include "seco-cec.h"
+
+struct secocec_data {
+	struct device *dev;
+	struct platform_device *pdev;
+	struct cec_adapter *cec_adap;
+	struct cec_notifier *notifier;
+	int irq;
+};
+
+#define smb_wr16(cmd, data) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \
+					     cmd, data, SMBUS_WRITE, NULL)
+#define smb_rd16(cmd, res) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \
+				       cmd, 0, SMBUS_READ, res)
+
+static int smb_word_op(short data_format, u16 slave_addr, u8 cmd, u16 data,
+		       u8 operation, u16 *result)
+{
+	unsigned int count;
+	short _data_format;
+	int status = 0;
+
+	switch (data_format) {
+	case CMD_BYTE_DATA:
+		_data_format = BRA_SMB_CMD_BYTE_DATA;
+		break;
+	case CMD_WORD_DATA:
+		_data_format = BRA_SMB_CMD_WORD_DATA;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Active wait until ready */

drivers/media/platform/seco-cec/seco-cec.c line 65

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	for (count = 0; count <= SMBTIMEOUT; ++count) {
+		if (!(inb(HSTS) & BRA_INUSE_STS))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		/* Reset the lock instead of failing */
+		outb(0xff, HSTS);
+		pr_warn("%s: SMBTIMEOUT\n", __func__);

Still a pr_ debug function here. No big deal, but you could easily pass a reference to your device here. Up to you (and others to no agree this is fine)

Quoted 12 lines
drivers/media/platform/seco-cec/seco-cec.c new file +12 -0
+	}
+
+	outb(0x00, HCNT);
+	outb((u8)(slave_addr & 0xfe) | operation, XMIT_SLVA);
+	outb(cmd, HCMD);
+	inb(HCNT);
+
+	if (operation == SMBUS_WRITE) {
+		outb((u8)data, HDAT0);
+		outb((u8)(data >> 8), HDAT1);
+	}
+

drivers/media/platform/seco-cec/seco-cec.c line 87

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	outb(BRA_START + _data_format, HCNT);
+
+	for (count = 0; count <= SMBTIMEOUT; count++) {
+		if (!(inb(HSTS) & BRA_HOST_BUSY))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		pr_debug("%s: SMBTIMEOUT_1\n", __func__);

As you return an error this seems more like a pr_err (or dev_err if possible)

Quoted 106 lines
drivers/media/platform/seco-cec/seco-cec.c new file +106 -0
+		status = -EBUSY;
+		goto err;
+	}
+
+	if (inb(HSTS) & BRA_HSTS_ERR_MASK) {
+		status = -EIO;
+		goto err;
+	}
+
+	if (operation == SMBUS_READ)
+		*result = ((inb(HDAT0) & 0xff) + ((inb(HDAT1) & 0xff) << 8));
+
+err:
+	outb(0xff, HSTS);
+	return status;
+}
+
+static int secocec_adap_enable(struct cec_adapter *adap, bool enable)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 val = 0;
+	int status;
+
+	if (enable) {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Enable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1,
+				  val | SECOCEC_ENABLE_REG_1_CEC);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device enabled");
+	} else {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Disable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+				  ~SECOCEC_ENABLE_REG_1_CEC &
+				  ~SECOCEC_ENABLE_REG_1_IR);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device disabled");
+	}
+
+	return 0;
+err:
+	dev_err(dev, "Adapter setup failed (%d)", status);
+	return status;
+}
+
+static int secocec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr)
+{
+	u16 enable_val = 0;
+	int status;
+
+	/* Disable device */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &enable_val);
+	if (status)
+		return status;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val & ~SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	/* Write logical address */
+	status = smb_wr16(SECOCEC_DEVICE_LA, logical_addr);
+	if (status)
+		return status;
+
+	/* Re-enable device */
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	return 0;
+}
+
+static int secocec_adap_transmit(struct cec_adapter *adap, u8 attempts,
+				 u32 signal_free_time, struct cec_msg *msg)

drivers/media/platform/seco-cec/seco-cec.c line 203

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 payload_len, payload_id_len, destination, val = 0;
+	u8 *payload_msg;
+	int status;
+	u8 i;
+
+	/* Device msg len already accounts for header */
+	payload_id_len = msg->len - 1;

Does it make sense to continue if payload_id_len == 0 ? You're going to send the length only (0) and that's it. Is your device happy with this? Please consider returning here if it is not.

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+	/* Send data length */
+	status = smb_wr16(SECOCEC_WRITE_DATA_LENGTH, payload_id_len);
+	if (status)
+		goto err;
+
+	/* Send Operation ID if present */
+	if (payload_id_len > 0) {
+		status = smb_wr16(SECOCEC_WRITE_OPERATION_ID, msg->msg[1]);
+		if (status)

drivers/media/platform/seco-cec/seco-cec.c line 223

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+			goto err;
+	}
+	/* Send data if present */
+	if (payload_id_len > 1) {
+		/* Only data; */
+		payload_len = msg->len - 2;
+		payload_msg = &msg->msg[2];
+
+		/* Copy message into registers */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {

Am I wrong or with an odd message length you're going to access memory after msg->msg[] ends?

If len is, say, 5, you're going to cycle from 0 to 2 (as 5 / 2 + (5 %
2) == 3)

drivers/media/platform/seco-cec/seco-cec.c line 225

Quoted 2 lines
drivers/media/platform/seco-cec/seco-cec.c new file +2 -0
+			/* hi byte */
+			val = payload_msg[(i << 1) + 1] << 8;

And here during the last iteration you'll access payload_msg[2 << 1 + 1] which is after payload_msg end. Please make sure you catch this and skip this assignment.

           index: 0  1  2  3  4
payload_msg[5] = [x, y, w, v, z]
i = 0
        val = y << 8 | x;
i = 1
        val = v << 8 | w;
i = 2
        val = ?? < 8 | z;

I'm not sure how msg->msg is allocated or initialized, nor what is its actual length, but this feels buggy to me.

What do you think?

Thanks
j

Quoted 620 lines
drivers/media/platform/seco-cec/seco-cec.c new file +481 -0
+
+			/* lo byte */
+			val |= payload_msg[(i << 1)];
+
+			status = smb_wr16(SECOCEC_WRITE_DATA_00 + i, val);
+			if (status)
+				goto err;
+		}
+	}
+	/* Send msg source/destination and fire msg */
+	destination = msg->msg[0];
+	status = smb_wr16(SECOCEC_WRITE_BYTE0, destination);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Transmit failed (%d)", status);
+	return status;
+}
+
+static int secocec_tx_done(struct cec_adapter *adap, u16 status_val)
+{
+	int status = 0;
+
+	if (status_val & SECOCEC_STATUS_TX_ERROR_MASK) {
+		if (status_val & SECOCEC_STATUS_TX_NACK_ERROR) {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_NACK);
+			status = -EAGAIN;
+		} else {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_ERROR);
+			status = -EIO;
+		}
+	} else {
+		cec_transmit_attempt_done(adap, CEC_TX_STATUS_OK);
+	}
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_TX_ERROR_MASK |
+		SECOCEC_STATUS_MSG_SENT_MASK |
+		SECOCEC_STATUS_TX_NACK_ERROR;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+	return status;
+}
+
+static int secocec_rx_done(struct cec_adapter *adap, u16 status_val)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	struct cec_msg msg = { };
+	bool flag_overflow = false;
+	u8 payload_len, i = 0;
+	u8 *payload_msg;
+	u16 val = 0;
+	int status;
+
+	if (status_val & SECOCEC_STATUS_RX_OVERFLOW_MASK) {
+		dev_warn(dev, "Received more than 16 bytes. Discarding");
+		flag_overflow = true;
+	}
+
+	if (status_val & SECOCEC_STATUS_RX_ERROR_MASK) {
+		dev_warn(dev, "Message received with errors. Discarding");
+		status = -EIO;
+		goto rxerr;
+	}
+
+	/* Read message length */
+	status = smb_rd16(SECOCEC_READ_DATA_LENGTH, &val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Incoming message (payload len %d):", val);
+
+	/* Device msg len already accounts for the header */
+	msg.len = min(val + 1, CEC_MAX_MSG_SIZE);
+
+	/* Read logical address */
+	status = smb_rd16(SECOCEC_READ_BYTE0, &val);
+	if (status)
+		goto err;
+
+	/* device stores source LA and destination */
+	msg.msg[0] = val;
+
+	/* Read operation ID */
+	status = smb_rd16(SECOCEC_READ_OPERATION_ID, &val);
+	if (status)
+		goto err;
+
+	msg.msg[1] = val;
+
+	/* Read data if present */
+	if (msg.len > 1) {
+		payload_len = msg.len - 2;
+		payload_msg = &msg.msg[2];
+
+		/* device stores 2 bytes in every 16-bit val */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			status = smb_rd16(SECOCEC_READ_DATA_00 + i, &val);
+			if (status)
+				goto err;
+
+			/* low byte, skipping header */
+			payload_msg[(i << 1)] = val & 0x00ff;
+
+			/* hi byte */
+			payload_msg[(i << 1) + 1] = (val & 0xff00) >> 8;
+		}
+	}
+
+	cec_received_msg(cec->cec_adap, &msg);
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+
+	status = smb_wr16(SECOCEC_STATUS, status_val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Message received successfully");
+
+	return 0;
+
+rxerr:
+	/* Reset error reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK |
+		SECOCEC_STATUS_RX_ERROR_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+err:
+	dev_err(dev, "Receive message failed (%d)", status);
+	return status;
+}
+
+struct cec_adap_ops secocec_cec_adap_ops = {
+	/* Low-level callbacks */
+	.adap_enable = secocec_adap_enable,
+	.adap_log_addr = secocec_adap_log_addr,
+	.adap_transmit = secocec_adap_transmit,
+};
+
+static irqreturn_t secocec_irq_handler(int irq, void *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	u16 status_val, cec_val, val = 0;
+	int status;
+
+	/*  Read status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &status_val);
+	if (status)
+		goto err;
+
+	if (status_val & SECOCEC_STATUS_REG_1_CEC) {
+		/* Read CEC status register */
+		status = smb_rd16(SECOCEC_STATUS, &cec_val);
+		if (status)
+			goto err;
+
+		if (cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK)
+			secocec_rx_done(cec->cec_adap, cec_val);
+
+		if (cec_val & SECOCEC_STATUS_MSG_SENT_MASK)
+			secocec_tx_done(cec->cec_adap, cec_val);
+
+		if ((~cec_val & SECOCEC_STATUS_MSG_SENT_MASK) &&
+		    (~cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK))
+			dev_warn(dev,
+				 "Message not received or sent, but interrupt fired");
+
+		val = SECOCEC_STATUS_REG_1_CEC;
+	}
+
+	if (status_val & SECOCEC_STATUS_REG_1_IR) {
+		dev_dbg(dev, "IR RC5 Interrupt Caught");
+		val |= SECOCEC_STATUS_REG_1_IR;
+		/* TODO IRDA RX */
+	}
+
+	/*  Reset status register */
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	return IRQ_HANDLED;
+
+err:
+	dev_err(dev, "IRQ: Read/Write SMBus operation failed (%d)", status);
+
+	/*  Reset status register */
+	val = SECOCEC_STATUS_REG_1_CEC | SECOCEC_STATUS_REG_1_IR;
+	smb_wr16(SECOCEC_STATUS_REG_1, val);
+
+	return IRQ_HANDLED;
+}
+
+struct cec_dmi_match {
+	char *sys_vendor;
+	char *product_name;
+	char *devname;
+	char *conn;
+};
+
+static const struct cec_dmi_match secocec_dmi_match_table[] = {
+	/* UDOO X86 */
+	{ "SECO", "UDOO x86", "0000:00:02.0", "Port B" },
+};
+
+static int secocec_cec_get_notifier(struct cec_notifier **notify)
+{
+	int i;
+
+	for (i = 0 ; i < ARRAY_SIZE(secocec_dmi_match_table) ; ++i) {
+		const struct cec_dmi_match *m = &secocec_dmi_match_table[i];
+
+		if (dmi_match(DMI_SYS_VENDOR, m->sys_vendor) &&
+		    dmi_match(DMI_PRODUCT_NAME, m->product_name)) {
+			struct device *d;
+
+			/* Find the device, bail out if not yet registered */
+			d = bus_find_device_by_name(&pci_bus_type, NULL,
+						    m->devname);
+			if (!d)
+				return -EPROBE_DEFER;
+
+			*notify = cec_notifier_get_conn(d, m->conn);
+
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int secocec_acpi_probe(struct secocec_data *sdev)
+{
+	struct device *dev = sdev->dev;
+	struct gpio_desc *gpio;
+	int irq = 0;
+
+	gpio = devm_gpiod_get(dev, NULL, GPIOF_IN);
+	if (IS_ERR(gpio)) {
+		dev_err(dev, "Cannot request interrupt gpio");
+		return PTR_ERR(gpio);
+	}
+
+	irq = gpiod_to_irq(gpio);
+	if (irq < 0) {
+		dev_err(dev, "Cannot find valid irq");
+		return -ENODEV;
+	}
+	dev_dbg(dev, "irq-gpio is bound to IRQ %d", irq);
+
+	sdev->irq = irq;
+
+	return 0;
+}
+
+static int secocec_probe(struct platform_device *pdev)
+{
+	struct secocec_data *secocec;
+	struct device *dev = &pdev->dev;
+	int ret;
+	u16 val;
+
+	secocec = devm_kzalloc(dev, sizeof(*secocec), GFP_KERNEL);
+	if (!secocec)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, secocec);
+
+	/* Request SMBus regions */
+	if (!request_muxed_region(BRA_SMB_BASE_ADDR, 7, "CEC00001")) {
+		dev_err(dev, "Request memory region failed");
+		return -ENXIO;
+	}
+
+	secocec->pdev = pdev;
+	secocec->dev = dev;
+
+	if (!has_acpi_companion(dev)) {
+		dev_dbg(dev, "Cannot find any ACPI companion");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	ret = secocec_acpi_probe(secocec);
+	if (ret) {
+		dev_err(dev, "Cannot assign gpio to IRQ");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	dev_dbg(dev, "IRQ detected at %d", secocec->irq);
+
+	/* Firmware version check */
+	ret = smb_rd16(SECOCEC_VERSION, &val);
+	if (ret) {
+		dev_err(dev, "Cannot check fw version");
+		goto err;
+	}
+	if (val < SECOCEC_LATEST_FW) {
+		dev_err(dev, "CEC Firmware not supported (v.%04x). Use ver > v.%04x",
+			val, SECOCEC_LATEST_FW);
+		ret = -EINVAL;
+		goto err;
+	}
+
+	ret = secocec_cec_get_notifier(&secocec->notifier);
+	if (ret) {
+		dev_err(dev, "no CEC notifier available\n");
+		goto err;
+	}
+
+	ret = devm_request_threaded_irq(dev,
+					secocec->irq,
+					NULL,
+					secocec_irq_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					dev_name(&pdev->dev), secocec);
+
+	if (ret) {
+		dev_err(dev, "Cannot request IRQ %d", secocec->irq);
+		ret = -EIO;
+		goto err;
+	}
+
+	/* Allocate CEC adapter */
+	secocec->cec_adap = cec_allocate_adapter(&secocec_cec_adap_ops,
+						 secocec,
+						 dev_name(dev),
+						 CEC_CAP_DEFAULTS,
+						 SECOCEC_MAX_ADDRS);
+
+	if (IS_ERR(secocec->cec_adap)) {
+		ret = PTR_ERR(secocec->cec_adap);
+		goto err;
+	}
+
+	ret = cec_register_adapter(secocec->cec_adap, dev);
+	if (ret)
+		goto err_delete_adapter;
+
+	if (secocec->notifier)
+		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
+
+	platform_set_drvdata(pdev, secocec);
+
+	dev_dbg(dev, "Device registered");
+
+	return ret;
+
+err_delete_adapter:
+	cec_delete_adapter(secocec->cec_adap);
+err:
+	dev_err(dev, "%s device probe failed\n", dev_name(dev));
+
+	return ret;
+}
+
+static int secocec_remove(struct platform_device *pdev)
+{
+	struct secocec_data *secocec = platform_get_drvdata(pdev);
+
+	cec_unregister_adapter(secocec->cec_adap);
+
+	if (secocec->notifier)
+		cec_notifier_put(secocec->notifier);
+
+	release_region(BRA_SMB_BASE_ADDR, 7);
+
+	dev_dbg(&pdev->dev, "CEC device removed");
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int secocec_suspend(struct device *dev)
+{
+	int status;
+	u16 val;
+
+	dev_dbg(dev, "Device going to suspend, disabling");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Disable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+			  ~SECOCEC_ENABLE_REG_1_CEC & ~SECOCEC_ENABLE_REG_1_IR);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Suspend failed (err: %d)", status);
+	return status;
+}
+
+static int secocec_resume(struct device *dev)
+{
+	int status;
+	u16 val;
+
+	dev_dbg(dev, "Resuming device from suspend");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Device resumed from suspend");
+
+	return 0;
+
+err:
+	dev_err(dev, "Resume failed (err: %d)", status);
+	return status;
+}
+
+static SIMPLE_DEV_PM_OPS(secocec_pm_ops, secocec_suspend, secocec_resume);
+#define SECOCEC_PM_OPS (&secocec_pm_ops)
+#else
+#define SECOCEC_PM_OPS NULL
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id secocec_acpi_match[] = {
+	{"CEC00001", 0},
+	{},
+};
+
+MODULE_DEVICE_TABLE(acpi, secocec_acpi_match);
+#endif
+
+static struct platform_driver secocec_driver = {
+	.driver = {
+		   .name = SECOCEC_DEV_NAME,
+		   .acpi_match_table = ACPI_PTR(secocec_acpi_match),
+		   .pm = SECOCEC_PM_OPS,
+	},
+	.probe = secocec_probe,
+	.remove = secocec_remove,
+};
+
+module_platform_driver(secocec_driver);
+
+MODULE_DESCRIPTION("SECO CEC X86 Driver");
+MODULE_AUTHOR("Ettore Chimenti <[email protected]>");
+MODULE_LICENSE("Dual BSD/GPL");
drivers/media/platform/seco-cec/seco-cec.h new file +130 -1
new file mode 100644
index 000000000000..93020900935e
@@ -0,0 +1,130 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
+/*
+ * SECO X86 Boards CEC register defines
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ */
+
+#ifndef __SECO_CEC_H__
+#define __SECO_CEC_H__
+
+#define SECOCEC_MAX_ADDRS		1
+#define SECOCEC_DEV_NAME		"secocec"
+#define SECOCEC_LATEST_FW		0x0f0b
+
+#define SMBTIMEOUT			0xffff
+#define SMB_POLL_UDELAY			10
+
+#define SMBUS_WRITE			0
+#define SMBUS_READ			1
+
+#define CMD_BYTE_DATA			0
+#define CMD_WORD_DATA			1
+
+/*
+ * SMBus definitons for Braswell
+ */
+
+#define BRA_DONE_STATUS			BIT(7)
+#define BRA_INUSE_STS			BIT(6)
+#define BRA_FAILED_OP			BIT(4)
+#define BRA_BUS_ERR			BIT(3)
+#define BRA_DEV_ERR			BIT(2)
+#define BRA_INTR			BIT(1)
+#define BRA_HOST_BUSY			BIT(0)
+#define BRA_HSTS_ERR_MASK   (BRA_FAILED_OP | BRA_BUS_ERR | BRA_DEV_ERR)
+
+#define BRA_PEC_EN			BIT(7)
+#define BRA_START			BIT(6)
+#define BRA_LAST__BYTE			BIT(5)
+#define BRA_INTREN			BIT(0)
+#define BRA_SMB_CMD			(7 << 2)
+#define BRA_SMB_CMD_QUICK		(0 << 2)
+#define BRA_SMB_CMD_BYTE		(1 << 2)
+#define BRA_SMB_CMD_BYTE_DATA		(2 << 2)
+#define BRA_SMB_CMD_WORD_DATA		(3 << 2)
+#define BRA_SMB_CMD_PROCESS_CALL	(4 << 2)
+#define BRA_SMB_CMD_BLOCK		(5 << 2)
+#define BRA_SMB_CMD_I2CREAD		(6 << 2)
+#define BRA_SMB_CMD_BLOCK_PROCESS	(7 << 2)
+
+#define BRA_SMB_BASE_ADDR  0x2040
+#define HSTS               (BRA_SMB_BASE_ADDR + 0)
+#define HCNT               (BRA_SMB_BASE_ADDR + 2)
+#define HCMD               (BRA_SMB_BASE_ADDR + 3)
+#define XMIT_SLVA          (BRA_SMB_BASE_ADDR + 4)
+#define HDAT0              (BRA_SMB_BASE_ADDR + 5)
+#define HDAT1              (BRA_SMB_BASE_ADDR + 6)
+
+/*
+ * Microcontroller Address
+ */
+
+#define SECOCEC_MICRO_ADDRESS		0x40
+
+/*
+ * STM32 SMBus Registers
+ */
+
+#define SECOCEC_VERSION			0x00
+#define SECOCEC_ENABLE_REG_1		0x01
+#define SECOCEC_ENABLE_REG_2		0x02
+#define SECOCEC_STATUS_REG_1		0x03
+#define SECOCEC_STATUS_REG_2		0x04
+
+#define SECOCEC_STATUS			0x28
+#define SECOCEC_DEVICE_LA		0x29
+#define SECOCEC_READ_OPERATION_ID	0x2a
+#define SECOCEC_READ_DATA_LENGTH	0x2b
+#define SECOCEC_READ_DATA_00		0x2c
+#define SECOCEC_READ_DATA_02		0x2d
+#define SECOCEC_READ_DATA_04		0x2e
+#define SECOCEC_READ_DATA_06		0x2f
+#define SECOCEC_READ_DATA_08		0x30
+#define SECOCEC_READ_DATA_10		0x31
+#define SECOCEC_READ_DATA_12		0x32
+#define SECOCEC_READ_BYTE0		0x33
+#define SECOCEC_WRITE_OPERATION_ID	0x34
+#define SECOCEC_WRITE_DATA_LENGTH	0x35
+#define SECOCEC_WRITE_DATA_00		0x36
+#define SECOCEC_WRITE_DATA_02		0x37
+#define SECOCEC_WRITE_DATA_04		0x38
+#define SECOCEC_WRITE_DATA_06		0x39
+#define SECOCEC_WRITE_DATA_08		0x3a
+#define SECOCEC_WRITE_DATA_10		0x3b
+#define SECOCEC_WRITE_DATA_12		0x3c
+#define SECOCEC_WRITE_BYTE0		0x3d
+
+#define SECOCEC_IR_READ_DATA		0x3e
+
+/*
+ * Enabling register
+ */
+
+#define SECOCEC_ENABLE_REG_1_CEC		0x1000
+#define SECOCEC_ENABLE_REG_1_IR			0x2000
+#define SECOCEC_ENABLE_REG_1_IR_PASSTHROUGH	0x4000
+
+/*
+ * Status register
+ */
+
+#define SECOCEC_STATUS_REG_1_CEC	SECOCEC_ENABLE_REG_1_CEC
+#define SECOCEC_STATUS_REG_1_IR		SECOCEC_ENABLE_REG_1_IR
+#define SECOCEC_STATUS_REG_1_IR_PASSTHR	SECOCEC_ENABLE_REG_1_IR_PASSTHR
+
+/*
+ * Status data
+ */
+
+#define SECOCEC_STATUS_MSG_RECEIVED_MASK	BIT(0)
+#define SECOCEC_STATUS_RX_ERROR_MASK		BIT(1)
+#define SECOCEC_STATUS_MSG_SENT_MASK		BIT(2)
+#define SECOCEC_STATUS_TX_ERROR_MASK		BIT(3)
+
+#define SECOCEC_STATUS_TX_NACK_ERROR		BIT(4)
+#define SECOCEC_STATUS_RX_OVERFLOW_MASK		BIT(5)
+
+#endif /* __SECO_CEC_H__ */
--

2.18.0

#21 lore raw
In reply to ektor5

Hi Ettore,

Quoted 10 lines · On 10/05/2018 07:33 PM, ektor5 wrote:

This series of patches aims to add CEC functionalities to SECO devices, in particular UDOO X86.

The communication is achieved via Braswell SMBus (i2c-i801) to the onboard STM32 microcontroller that handles the CEC signals. The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

This series looks good to me. But can you do one more test:

Update your kernel to the latest media_tree master and also update your v4l-utils repo to the latest master code.

With all that in place please run:

cec-compliance -A

(have the HDMI output connected to a CEC-capable TV when running this test).

Please report back the output of cec-compliance.

A bunch of CEC bug fixes and improvements were merged yesterday, and the cec-compliance adapter test is improved to check for issues that were hard to find in the past.

So it will be good to have a final check of this driver.

Regards,

Hans

Quoted 24 lines

v2:
- Removed useless debug prints
- Added DMI && PCI to dependences
- Removed useless ifdefs
- Renamed all irda references to ir
- Fixed SPDX clause
- Several style fixes

Ettore Chimenti (2):
media: add SECO cec driver
seco-cec: add Consumer-IR support

 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  22 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 829 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 141 ++++
 6 files changed, 1001 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
#17 lore raw

Re: [PATCH v2 1/2] media: add SECO cec driver

In reply to jacopo mondi
Quoted 314 lines · jacopo mondi

Hi Ettore,
some more comments below.

Quoted 9 lines · On Fri, Oct 05, 2018 at 07:33:58PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

This patch adds support to the CEC device implemented with a STM32 microcontroller in X86 SECO Boards, including UDOO X86.

The communication is achieved via Braswell integrated SMBus (i2c-i801). The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

Quoted 7 lines

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Inspired by cros-ec-cec implementation, attaches to i915 driver cec-notifier.

Iterations of the same patchset are not usually sent 'in-reply-to' mode as far as I've seen.

Quoted 86 lines
---
 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  12 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 706 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 130 ++++
 6 files changed, 857 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
MAINTAINERS +6 -0
index 4ece30f15777..1062912a5ff4 100644
@@ -12972,6 +12972,12 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 F:	drivers/mmc/host/sdricoh_cs.c
 
+SECO BOARDS CEC DRIVER
+M:	Ettore Chimenti <[email protected]>
+S:	Maintained
+F:	drivers/media/platform/seco-cec/seco-cec.c
+F:	drivers/media/platform/seco-cec/seco-cec.h
+
 SECURE COMPUTING
 M:	Kees Cook <[email protected]>
 R:	Andy Lutomirski <[email protected]>
drivers/media/platform/Kconfig +12 -0
index 94c1fe0e9787..51cd1fd005e3 100644
@@ -613,6 +613,18 @@ config VIDEO_TEGRA_HDMI_CEC
 	 The CEC bus is present in the HDMI connector and enables communication
 	 between compatible devices.
 
+config VIDEO_SECO_CEC
+	tristate "SECO Boards HDMI CEC driver"
+	depends on (X86 || IA64) || COMPILE_TEST
+	depends on PCI && DMI
+	select CEC_CORE
+	select CEC_NOTIFIER
+	help
+	  This is a driver for SECO Boards integrated CEC interface.
+	  Selecting it will enable support for this device.
+	  CEC bus is present in the HDMI connector and enables communication
+	  between compatible devices.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/Makefile +2 -0
index 41322ab65802..5d2b06c4c68a 100644
@@ -53,6 +53,8 @@ obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC)	+= tegra-cec/
 
 obj-y					+= stm32/
 
+obj-$(CONFIG_VIDEO_SECO_CEC)		+= seco-cec/
+
 obj-y					+= davinci/
 
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
drivers/media/platform/seco-cec/Makefile new file +1 -0
new file mode 100644
index 000000000000..09900b087d02
@@ -0,0 +1 @@
+obj-y += seco-cec.o
drivers/media/platform/seco-cec/seco-cec.c new file +8 -0
new file mode 100644
index 000000000000..990e88f979a2
@@ -0,0 +1,706 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+/*
+ * CEC driver for SECO X86 Boards
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ */

drivers/media/platform/seco-cec/seco-cec.c line 18

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+#include <linux/interrupt.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/dmi.h>
+

Please keep headers alphabetically sorted, it's easier to identify duplications or unnecessary inclusions

Quoted 37 lines
drivers/media/platform/seco-cec/seco-cec.c new file +37 -0
+/* CEC Framework */
+#include <media/cec.h>
+
+#include "seco-cec.h"
+
+struct secocec_data {
+	struct device *dev;
+	struct platform_device *pdev;
+	struct cec_adapter *cec_adap;
+	struct cec_notifier *notifier;
+	int irq;
+};
+
+#define smb_wr16(cmd, data) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \
+					     cmd, data, SMBUS_WRITE, NULL)
+#define smb_rd16(cmd, res) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \
+				       cmd, 0, SMBUS_READ, res)
+
+static int smb_word_op(short data_format, u16 slave_addr, u8 cmd, u16 data,
+		       u8 operation, u16 *result)
+{
+	unsigned int count;
+	short _data_format;
+	int status = 0;
+
+	switch (data_format) {
+	case CMD_BYTE_DATA:
+		_data_format = BRA_SMB_CMD_BYTE_DATA;
+		break;
+	case CMD_WORD_DATA:
+		_data_format = BRA_SMB_CMD_WORD_DATA;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Active wait until ready */

drivers/media/platform/seco-cec/seco-cec.c line 65

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	for (count = 0; count <= SMBTIMEOUT; ++count) {
+		if (!(inb(HSTS) & BRA_INUSE_STS))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		/* Reset the lock instead of failing */
+		outb(0xff, HSTS);
+		pr_warn("%s: SMBTIMEOUT\n", __func__);

Still a pr_ debug function here. No big deal, but you could easily pass a reference to your device here. Up to you (and others to no agree this is fine)

Quoted 12 lines
drivers/media/platform/seco-cec/seco-cec.c new file +12 -0
+	}
+
+	outb(0x00, HCNT);
+	outb((u8)(slave_addr & 0xfe) | operation, XMIT_SLVA);
+	outb(cmd, HCMD);
+	inb(HCNT);
+
+	if (operation == SMBUS_WRITE) {
+		outb((u8)data, HDAT0);
+		outb((u8)(data >> 8), HDAT1);
+	}
+

drivers/media/platform/seco-cec/seco-cec.c line 87

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+	outb(BRA_START + _data_format, HCNT);
+
+	for (count = 0; count <= SMBTIMEOUT; count++) {
+		if (!(inb(HSTS) & BRA_HOST_BUSY))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		pr_debug("%s: SMBTIMEOUT_1\n", __func__);

As you return an error this seems more like a pr_err (or dev_err if possible)

Quoted 112 lines
drivers/media/platform/seco-cec/seco-cec.c new file +112 -0
+		status = -EBUSY;
+		goto err;
+	}
+
+	if (inb(HSTS) & BRA_HSTS_ERR_MASK) {
+		status = -EIO;
+		goto err;
+	}
+
+	if (operation == SMBUS_READ)
+		*result = ((inb(HDAT0) & 0xff) + ((inb(HDAT1) & 0xff) << 8));
+
+err:
+	outb(0xff, HSTS);
+	return status;
+}
+
+static int secocec_adap_enable(struct cec_adapter *adap, bool enable)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 val = 0;
+	int status;
+
+	if (enable) {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Enable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1,
+				  val | SECOCEC_ENABLE_REG_1_CEC);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device enabled");
+	} else {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Disable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+				  ~SECOCEC_ENABLE_REG_1_CEC &
+				  ~SECOCEC_ENABLE_REG_1_IR);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device disabled");
+	}
+
+	return 0;
+err:
+	dev_err(dev, "Adapter setup failed (%d)", status);
+	return status;
+}
+
+static int secocec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr)
+{
+	u16 enable_val = 0;
+	int status;
+
+	/* Disable device */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &enable_val);
+	if (status)
+		return status;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val & ~SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	/* Write logical address */
+	status = smb_wr16(SECOCEC_DEVICE_LA, logical_addr);
+	if (status)
+		return status;
+
+	/* Re-enable device */
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	return 0;
+}
+
+static int secocec_adap_transmit(struct cec_adapter *adap, u8 attempts,
+				 u32 signal_free_time, struct cec_msg *msg)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 payload_len, payload_id_len, destination, val = 0;
+	u8 *payload_msg;
+	int status;
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 203

Quoted 4 lines
drivers/media/platform/seco-cec/seco-cec.c new file +4 -0
+	u8 i;
+
+	/* Device msg len already accounts for header */
+	payload_id_len = msg->len - 1;

Does it make sense to continue if payload_id_len == 0 ? You're going to send the length only (0) and that's it. Is your device happy with this? Please consider returning here if it is not.

This is OK. If msg->len == 1, then this is a 'PING' CEC message consisting of the header byte only without any payload.

Quoted 44 lines
Quoted 11 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+	/* Send data length */
+	status = smb_wr16(SECOCEC_WRITE_DATA_LENGTH, payload_id_len);
+	if (status)
+		goto err;
+
+	/* Send Operation ID if present */
+	if (payload_id_len > 0) {
+		status = smb_wr16(SECOCEC_WRITE_OPERATION_ID, msg->msg[1]);
+		if (status)

drivers/media/platform/seco-cec/seco-cec.c line 223

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+			goto err;
+	}
+	/* Send data if present */
+	if (payload_id_len > 1) {
+		/* Only data; */
+		payload_len = msg->len - 2;
+		payload_msg = &msg->msg[2];
+
+		/* Copy message into registers */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {

Am I wrong or with an odd message length you're going to access memory after msg->msg[] ends?

If len is, say, 5, you're going to cycle from 0 to 2 (as 5 / 2 + (5 %
2) == 3)

drivers/media/platform/seco-cec/seco-cec.c line 225

Quoted 2 lines
drivers/media/platform/seco-cec/seco-cec.c new file +2 -0
+			/* hi byte */
+			val = payload_msg[(i << 1) + 1] << 8;

And here during the last iteration you'll access payload_msg[2 << 1 + 1] which is after payload_msg end. Please make sure you catch this and skip this assignment.

           index: 0  1  2  3  4
payload_msg[5] = [x, y, w, v, z]
i = 0
        val = y << 8 | x;
i = 1
        val = v << 8 | w;
i = 2
        val = ?? < 8 | z;
Quoted 2 lines

I'm not sure how msg->msg is allocated or initialized, nor what is its actual length, but this feels buggy to me.

msg->msg is a fixed size 16 byte array.

But it is a weird for-loop.

I'd just do:

	for (i = 0; i < payload_len; i += 2) {
	}

Less confusing.

Regards,

Hans

Quoted 626 lines

What do you think?

Thanks
j

Quoted 620 lines
drivers/media/platform/seco-cec/seco-cec.c new file +481 -0
+
+			/* lo byte */
+			val |= payload_msg[(i << 1)];
+
+			status = smb_wr16(SECOCEC_WRITE_DATA_00 + i, val);
+			if (status)
+				goto err;
+		}
+	}
+	/* Send msg source/destination and fire msg */
+	destination = msg->msg[0];
+	status = smb_wr16(SECOCEC_WRITE_BYTE0, destination);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Transmit failed (%d)", status);
+	return status;
+}
+
+static int secocec_tx_done(struct cec_adapter *adap, u16 status_val)
+{
+	int status = 0;
+
+	if (status_val & SECOCEC_STATUS_TX_ERROR_MASK) {
+		if (status_val & SECOCEC_STATUS_TX_NACK_ERROR) {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_NACK);
+			status = -EAGAIN;
+		} else {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_ERROR);
+			status = -EIO;
+		}
+	} else {
+		cec_transmit_attempt_done(adap, CEC_TX_STATUS_OK);
+	}
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_TX_ERROR_MASK |
+		SECOCEC_STATUS_MSG_SENT_MASK |
+		SECOCEC_STATUS_TX_NACK_ERROR;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+	return status;
+}
+
+static int secocec_rx_done(struct cec_adapter *adap, u16 status_val)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	struct cec_msg msg = { };
+	bool flag_overflow = false;
+	u8 payload_len, i = 0;
+	u8 *payload_msg;
+	u16 val = 0;
+	int status;
+
+	if (status_val & SECOCEC_STATUS_RX_OVERFLOW_MASK) {
+		dev_warn(dev, "Received more than 16 bytes. Discarding");
+		flag_overflow = true;
+	}
+
+	if (status_val & SECOCEC_STATUS_RX_ERROR_MASK) {
+		dev_warn(dev, "Message received with errors. Discarding");
+		status = -EIO;
+		goto rxerr;
+	}
+
+	/* Read message length */
+	status = smb_rd16(SECOCEC_READ_DATA_LENGTH, &val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Incoming message (payload len %d):", val);
+
+	/* Device msg len already accounts for the header */
+	msg.len = min(val + 1, CEC_MAX_MSG_SIZE);
+
+	/* Read logical address */
+	status = smb_rd16(SECOCEC_READ_BYTE0, &val);
+	if (status)
+		goto err;
+
+	/* device stores source LA and destination */
+	msg.msg[0] = val;
+
+	/* Read operation ID */
+	status = smb_rd16(SECOCEC_READ_OPERATION_ID, &val);
+	if (status)
+		goto err;
+
+	msg.msg[1] = val;
+
+	/* Read data if present */
+	if (msg.len > 1) {
+		payload_len = msg.len - 2;
+		payload_msg = &msg.msg[2];
+
+		/* device stores 2 bytes in every 16-bit val */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			status = smb_rd16(SECOCEC_READ_DATA_00 + i, &val);
+			if (status)
+				goto err;
+
+			/* low byte, skipping header */
+			payload_msg[(i << 1)] = val & 0x00ff;
+
+			/* hi byte */
+			payload_msg[(i << 1) + 1] = (val & 0xff00) >> 8;
+		}
+	}
+
+	cec_received_msg(cec->cec_adap, &msg);
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+
+	status = smb_wr16(SECOCEC_STATUS, status_val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Message received successfully");
+
+	return 0;
+
+rxerr:
+	/* Reset error reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK |
+		SECOCEC_STATUS_RX_ERROR_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+err:
+	dev_err(dev, "Receive message failed (%d)", status);
+	return status;
+}
+
+struct cec_adap_ops secocec_cec_adap_ops = {
+	/* Low-level callbacks */
+	.adap_enable = secocec_adap_enable,
+	.adap_log_addr = secocec_adap_log_addr,
+	.adap_transmit = secocec_adap_transmit,
+};
+
+static irqreturn_t secocec_irq_handler(int irq, void *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	u16 status_val, cec_val, val = 0;
+	int status;
+
+	/*  Read status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &status_val);
+	if (status)
+		goto err;
+
+	if (status_val & SECOCEC_STATUS_REG_1_CEC) {
+		/* Read CEC status register */
+		status = smb_rd16(SECOCEC_STATUS, &cec_val);
+		if (status)
+			goto err;
+
+		if (cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK)
+			secocec_rx_done(cec->cec_adap, cec_val);
+
+		if (cec_val & SECOCEC_STATUS_MSG_SENT_MASK)
+			secocec_tx_done(cec->cec_adap, cec_val);
+
+		if ((~cec_val & SECOCEC_STATUS_MSG_SENT_MASK) &&
+		    (~cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK))
+			dev_warn(dev,
+				 "Message not received or sent, but interrupt fired");
+
+		val = SECOCEC_STATUS_REG_1_CEC;
+	}
+
+	if (status_val & SECOCEC_STATUS_REG_1_IR) {
+		dev_dbg(dev, "IR RC5 Interrupt Caught");
+		val |= SECOCEC_STATUS_REG_1_IR;
+		/* TODO IRDA RX */
+	}
+
+	/*  Reset status register */
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	return IRQ_HANDLED;
+
+err:
+	dev_err(dev, "IRQ: Read/Write SMBus operation failed (%d)", status);
+
+	/*  Reset status register */
+	val = SECOCEC_STATUS_REG_1_CEC | SECOCEC_STATUS_REG_1_IR;
+	smb_wr16(SECOCEC_STATUS_REG_1, val);
+
+	return IRQ_HANDLED;
+}
+
+struct cec_dmi_match {
+	char *sys_vendor;
+	char *product_name;
+	char *devname;
+	char *conn;
+};
+
+static const struct cec_dmi_match secocec_dmi_match_table[] = {
+	/* UDOO X86 */
+	{ "SECO", "UDOO x86", "0000:00:02.0", "Port B" },
+};
+
+static int secocec_cec_get_notifier(struct cec_notifier **notify)
+{
+	int i;
+
+	for (i = 0 ; i < ARRAY_SIZE(secocec_dmi_match_table) ; ++i) {
+		const struct cec_dmi_match *m = &secocec_dmi_match_table[i];
+
+		if (dmi_match(DMI_SYS_VENDOR, m->sys_vendor) &&
+		    dmi_match(DMI_PRODUCT_NAME, m->product_name)) {
+			struct device *d;
+
+			/* Find the device, bail out if not yet registered */
+			d = bus_find_device_by_name(&pci_bus_type, NULL,
+						    m->devname);
+			if (!d)
+				return -EPROBE_DEFER;
+
+			*notify = cec_notifier_get_conn(d, m->conn);
+
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int secocec_acpi_probe(struct secocec_data *sdev)
+{
+	struct device *dev = sdev->dev;
+	struct gpio_desc *gpio;
+	int irq = 0;
+
+	gpio = devm_gpiod_get(dev, NULL, GPIOF_IN);
+	if (IS_ERR(gpio)) {
+		dev_err(dev, "Cannot request interrupt gpio");
+		return PTR_ERR(gpio);
+	}
+
+	irq = gpiod_to_irq(gpio);
+	if (irq < 0) {
+		dev_err(dev, "Cannot find valid irq");
+		return -ENODEV;
+	}
+	dev_dbg(dev, "irq-gpio is bound to IRQ %d", irq);
+
+	sdev->irq = irq;
+
+	return 0;
+}
+
+static int secocec_probe(struct platform_device *pdev)
+{
+	struct secocec_data *secocec;
+	struct device *dev = &pdev->dev;
+	int ret;
+	u16 val;
+
+	secocec = devm_kzalloc(dev, sizeof(*secocec), GFP_KERNEL);
+	if (!secocec)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, secocec);
+
+	/* Request SMBus regions */
+	if (!request_muxed_region(BRA_SMB_BASE_ADDR, 7, "CEC00001")) {
+		dev_err(dev, "Request memory region failed");
+		return -ENXIO;
+	}
+
+	secocec->pdev = pdev;
+	secocec->dev = dev;
+
+	if (!has_acpi_companion(dev)) {
+		dev_dbg(dev, "Cannot find any ACPI companion");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	ret = secocec_acpi_probe(secocec);
+	if (ret) {
+		dev_err(dev, "Cannot assign gpio to IRQ");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	dev_dbg(dev, "IRQ detected at %d", secocec->irq);
+
+	/* Firmware version check */
+	ret = smb_rd16(SECOCEC_VERSION, &val);
+	if (ret) {
+		dev_err(dev, "Cannot check fw version");
+		goto err;
+	}
+	if (val < SECOCEC_LATEST_FW) {
+		dev_err(dev, "CEC Firmware not supported (v.%04x). Use ver > v.%04x",
+			val, SECOCEC_LATEST_FW);
+		ret = -EINVAL;
+		goto err;
+	}
+
+	ret = secocec_cec_get_notifier(&secocec->notifier);
+	if (ret) {
+		dev_err(dev, "no CEC notifier available\n");
+		goto err;
+	}
+
+	ret = devm_request_threaded_irq(dev,
+					secocec->irq,
+					NULL,
+					secocec_irq_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					dev_name(&pdev->dev), secocec);
+
+	if (ret) {
+		dev_err(dev, "Cannot request IRQ %d", secocec->irq);
+		ret = -EIO;
+		goto err;
+	}
+
+	/* Allocate CEC adapter */
+	secocec->cec_adap = cec_allocate_adapter(&secocec_cec_adap_ops,
+						 secocec,
+						 dev_name(dev),
+						 CEC_CAP_DEFAULTS,
+						 SECOCEC_MAX_ADDRS);
+
+	if (IS_ERR(secocec->cec_adap)) {
+		ret = PTR_ERR(secocec->cec_adap);
+		goto err;
+	}
+
+	ret = cec_register_adapter(secocec->cec_adap, dev);
+	if (ret)
+		goto err_delete_adapter;
+
+	if (secocec->notifier)
+		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
+
+	platform_set_drvdata(pdev, secocec);
+
+	dev_dbg(dev, "Device registered");
+
+	return ret;
+
+err_delete_adapter:
+	cec_delete_adapter(secocec->cec_adap);
+err:
+	dev_err(dev, "%s device probe failed\n", dev_name(dev));
+
+	return ret;
+}
+
+static int secocec_remove(struct platform_device *pdev)
+{
+	struct secocec_data *secocec = platform_get_drvdata(pdev);
+
+	cec_unregister_adapter(secocec->cec_adap);
+
+	if (secocec->notifier)
+		cec_notifier_put(secocec->notifier);
+
+	release_region(BRA_SMB_BASE_ADDR, 7);
+
+	dev_dbg(&pdev->dev, "CEC device removed");
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int secocec_suspend(struct device *dev)
+{
+	int status;
+	u16 val;
+
+	dev_dbg(dev, "Device going to suspend, disabling");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Disable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+			  ~SECOCEC_ENABLE_REG_1_CEC & ~SECOCEC_ENABLE_REG_1_IR);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Suspend failed (err: %d)", status);
+	return status;
+}
+
+static int secocec_resume(struct device *dev)
+{
+	int status;
+	u16 val;
+
+	dev_dbg(dev, "Resuming device from suspend");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Device resumed from suspend");
+
+	return 0;
+
+err:
+	dev_err(dev, "Resume failed (err: %d)", status);
+	return status;
+}
+
+static SIMPLE_DEV_PM_OPS(secocec_pm_ops, secocec_suspend, secocec_resume);
+#define SECOCEC_PM_OPS (&secocec_pm_ops)
+#else
+#define SECOCEC_PM_OPS NULL
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id secocec_acpi_match[] = {
+	{"CEC00001", 0},
+	{},
+};
+
+MODULE_DEVICE_TABLE(acpi, secocec_acpi_match);
+#endif
+
+static struct platform_driver secocec_driver = {
+	.driver = {
+		   .name = SECOCEC_DEV_NAME,
+		   .acpi_match_table = ACPI_PTR(secocec_acpi_match),
+		   .pm = SECOCEC_PM_OPS,
+	},
+	.probe = secocec_probe,
+	.remove = secocec_remove,
+};
+
+module_platform_driver(secocec_driver);
+
+MODULE_DESCRIPTION("SECO CEC X86 Driver");
+MODULE_AUTHOR("Ettore Chimenti <[email protected]>");
+MODULE_LICENSE("Dual BSD/GPL");
drivers/media/platform/seco-cec/seco-cec.h new file +130 -1
new file mode 100644
index 000000000000..93020900935e
@@ -0,0 +1,130 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
+/*
+ * SECO X86 Boards CEC register defines
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ */
+
+#ifndef __SECO_CEC_H__
+#define __SECO_CEC_H__
+
+#define SECOCEC_MAX_ADDRS		1
+#define SECOCEC_DEV_NAME		"secocec"
+#define SECOCEC_LATEST_FW		0x0f0b
+
+#define SMBTIMEOUT			0xffff
+#define SMB_POLL_UDELAY			10
+
+#define SMBUS_WRITE			0
+#define SMBUS_READ			1
+
+#define CMD_BYTE_DATA			0
+#define CMD_WORD_DATA			1
+
+/*
+ * SMBus definitons for Braswell
+ */
+
+#define BRA_DONE_STATUS			BIT(7)
+#define BRA_INUSE_STS			BIT(6)
+#define BRA_FAILED_OP			BIT(4)
+#define BRA_BUS_ERR			BIT(3)
+#define BRA_DEV_ERR			BIT(2)
+#define BRA_INTR			BIT(1)
+#define BRA_HOST_BUSY			BIT(0)
+#define BRA_HSTS_ERR_MASK   (BRA_FAILED_OP | BRA_BUS_ERR | BRA_DEV_ERR)
+
+#define BRA_PEC_EN			BIT(7)
+#define BRA_START			BIT(6)
+#define BRA_LAST__BYTE			BIT(5)
+#define BRA_INTREN			BIT(0)
+#define BRA_SMB_CMD			(7 << 2)
+#define BRA_SMB_CMD_QUICK		(0 << 2)
+#define BRA_SMB_CMD_BYTE		(1 << 2)
+#define BRA_SMB_CMD_BYTE_DATA		(2 << 2)
+#define BRA_SMB_CMD_WORD_DATA		(3 << 2)
+#define BRA_SMB_CMD_PROCESS_CALL	(4 << 2)
+#define BRA_SMB_CMD_BLOCK		(5 << 2)
+#define BRA_SMB_CMD_I2CREAD		(6 << 2)
+#define BRA_SMB_CMD_BLOCK_PROCESS	(7 << 2)
+
+#define BRA_SMB_BASE_ADDR  0x2040
+#define HSTS               (BRA_SMB_BASE_ADDR + 0)
+#define HCNT               (BRA_SMB_BASE_ADDR + 2)
+#define HCMD               (BRA_SMB_BASE_ADDR + 3)
+#define XMIT_SLVA          (BRA_SMB_BASE_ADDR + 4)
+#define HDAT0              (BRA_SMB_BASE_ADDR + 5)
+#define HDAT1              (BRA_SMB_BASE_ADDR + 6)
+
+/*
+ * Microcontroller Address
+ */
+
+#define SECOCEC_MICRO_ADDRESS		0x40
+
+/*
+ * STM32 SMBus Registers
+ */
+
+#define SECOCEC_VERSION			0x00
+#define SECOCEC_ENABLE_REG_1		0x01
+#define SECOCEC_ENABLE_REG_2		0x02
+#define SECOCEC_STATUS_REG_1		0x03
+#define SECOCEC_STATUS_REG_2		0x04
+
+#define SECOCEC_STATUS			0x28
+#define SECOCEC_DEVICE_LA		0x29
+#define SECOCEC_READ_OPERATION_ID	0x2a
+#define SECOCEC_READ_DATA_LENGTH	0x2b
+#define SECOCEC_READ_DATA_00		0x2c
+#define SECOCEC_READ_DATA_02		0x2d
+#define SECOCEC_READ_DATA_04		0x2e
+#define SECOCEC_READ_DATA_06		0x2f
+#define SECOCEC_READ_DATA_08		0x30
+#define SECOCEC_READ_DATA_10		0x31
+#define SECOCEC_READ_DATA_12		0x32
+#define SECOCEC_READ_BYTE0		0x33
+#define SECOCEC_WRITE_OPERATION_ID	0x34
+#define SECOCEC_WRITE_DATA_LENGTH	0x35
+#define SECOCEC_WRITE_DATA_00		0x36
+#define SECOCEC_WRITE_DATA_02		0x37
+#define SECOCEC_WRITE_DATA_04		0x38
+#define SECOCEC_WRITE_DATA_06		0x39
+#define SECOCEC_WRITE_DATA_08		0x3a
+#define SECOCEC_WRITE_DATA_10		0x3b
+#define SECOCEC_WRITE_DATA_12		0x3c
+#define SECOCEC_WRITE_BYTE0		0x3d
+
+#define SECOCEC_IR_READ_DATA		0x3e
+
+/*
+ * Enabling register
+ */
+
+#define SECOCEC_ENABLE_REG_1_CEC		0x1000
+#define SECOCEC_ENABLE_REG_1_IR			0x2000
+#define SECOCEC_ENABLE_REG_1_IR_PASSTHROUGH	0x4000
+
+/*
+ * Status register
+ */
+
+#define SECOCEC_STATUS_REG_1_CEC	SECOCEC_ENABLE_REG_1_CEC
+#define SECOCEC_STATUS_REG_1_IR		SECOCEC_ENABLE_REG_1_IR
+#define SECOCEC_STATUS_REG_1_IR_PASSTHR	SECOCEC_ENABLE_REG_1_IR_PASSTHR
+
+/*
+ * Status data
+ */
+
+#define SECOCEC_STATUS_MSG_RECEIVED_MASK	BIT(0)
+#define SECOCEC_STATUS_RX_ERROR_MASK		BIT(1)
+#define SECOCEC_STATUS_MSG_SENT_MASK		BIT(2)
+#define SECOCEC_STATUS_TX_ERROR_MASK		BIT(3)
+
+#define SECOCEC_STATUS_TX_NACK_ERROR		BIT(4)
+#define SECOCEC_STATUS_RX_OVERFLOW_MASK		BIT(5)
+
+#endif /* __SECO_CEC_H__ */
--

2.18.0

author
#18 lore raw

Re: [PATCH v2 1/2] media: add SECO cec driver

In reply to jacopo mondi
Quoted 16 lines · jacopo mondi

Hi Ettore,
some more comments below.

Quoted 12 lines · On Fri, Oct 05, 2018 at 07:33:58PM +0200, ektor5 wrote:

From: Ettore Chimenti <[email protected]>

This patch adds support to the CEC device implemented with a STM32 microcontroller in X86 SECO Boards, including UDOO X86.

The communication is achieved via Braswell integrated SMBus (i2c-i801). The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

Quoted 7 lines
Quoted 4 lines

Inspired by cros-ec-cec implementation, attaches to i915 driver cec-notifier.

Iterations of the same patchset are not usually sent 'in-reply-to' mode as far as I've seen.

Yes, sorry. Thought it was useul. :)

Quoted 92 lines
Quoted 92 lines
---
 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  12 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 706 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 130 ++++
 6 files changed, 857 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
MAINTAINERS +6 -0
index 4ece30f15777..1062912a5ff4 100644
@@ -12972,6 +12972,12 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 F:	drivers/mmc/host/sdricoh_cs.c
 
+SECO BOARDS CEC DRIVER
+M:	Ettore Chimenti <[email protected]>
+S:	Maintained
+F:	drivers/media/platform/seco-cec/seco-cec.c
+F:	drivers/media/platform/seco-cec/seco-cec.h
+
 SECURE COMPUTING
 M:	Kees Cook <[email protected]>
 R:	Andy Lutomirski <[email protected]>
drivers/media/platform/Kconfig +12 -0
index 94c1fe0e9787..51cd1fd005e3 100644
@@ -613,6 +613,18 @@ config VIDEO_TEGRA_HDMI_CEC
 	 The CEC bus is present in the HDMI connector and enables communication
 	 between compatible devices.
 
+config VIDEO_SECO_CEC
+	tristate "SECO Boards HDMI CEC driver"
+	depends on (X86 || IA64) || COMPILE_TEST
+	depends on PCI && DMI
+	select CEC_CORE
+	select CEC_NOTIFIER
+	help
+	  This is a driver for SECO Boards integrated CEC interface.
+	  Selecting it will enable support for this device.
+	  CEC bus is present in the HDMI connector and enables communication
+	  between compatible devices.
+
 endif #CEC_PLATFORM_DRIVERS
 
 menuconfig SDR_PLATFORM_DRIVERS
drivers/media/platform/Makefile +2 -0
index 41322ab65802..5d2b06c4c68a 100644
@@ -53,6 +53,8 @@ obj-$(CONFIG_VIDEO_TEGRA_HDMI_CEC)	+= tegra-cec/
 
 obj-y					+= stm32/
 
+obj-$(CONFIG_VIDEO_SECO_CEC)		+= seco-cec/
+
 obj-y					+= davinci/
 
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
drivers/media/platform/seco-cec/Makefile new file +1 -0
new file mode 100644
index 000000000000..09900b087d02
@@ -0,0 +1 @@
+obj-y += seco-cec.o
drivers/media/platform/seco-cec/seco-cec.c new file +13 -0
new file mode 100644
index 000000000000..990e88f979a2
@@ -0,0 +1,706 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+/*
+ * CEC driver for SECO X86 Boards
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/acpi.h>
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 18

Quoted 5 lines
drivers/media/platform/seco-cec/seco-cec.c new file +5 -0
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/dmi.h>
+

Please keep headers alphabetically sorted, it's easier to identify duplications or unnecessary inclusions

Yes, seems ok.

Quoted 44 lines
Quoted 44 lines
drivers/media/platform/seco-cec/seco-cec.c new file +43 -0
+/* CEC Framework */
+#include <media/cec.h>
+
+#include "seco-cec.h"
+
+struct secocec_data {
+	struct device *dev;
+	struct platform_device *pdev;
+	struct cec_adapter *cec_adap;
+	struct cec_notifier *notifier;
+	int irq;
+};
+
+#define smb_wr16(cmd, data) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \
+					     cmd, data, SMBUS_WRITE, NULL)
+#define smb_rd16(cmd, res) smb_word_op(CMD_WORD_DATA, SECOCEC_MICRO_ADDRESS, \
+				       cmd, 0, SMBUS_READ, res)
+
+static int smb_word_op(short data_format, u16 slave_addr, u8 cmd, u16 data,
+		       u8 operation, u16 *result)
+{
+	unsigned int count;
+	short _data_format;
+	int status = 0;
+
+	switch (data_format) {
+	case CMD_BYTE_DATA:
+		_data_format = BRA_SMB_CMD_BYTE_DATA;
+		break;
+	case CMD_WORD_DATA:
+		_data_format = BRA_SMB_CMD_WORD_DATA;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Active wait until ready */
+	for (count = 0; count <= SMBTIMEOUT; ++count) {
+		if (!(inb(HSTS) & BRA_INUSE_STS))
+			break;
+		udelay(SMB_POLL_UDELAY);
+	}
+
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 65

Quoted 4 lines
drivers/media/platform/seco-cec/seco-cec.c new file +4 -0
+	if (count > SMBTIMEOUT) {
+		/* Reset the lock instead of failing */
+		outb(0xff, HSTS);
+		pr_warn("%s: SMBTIMEOUT\n", __func__);

Still a pr_ debug function here. No big deal, but you could easily pass a reference to your device here. Up to you (and others to no agree this is fine)

I've left it by mistake, it doesn't provide any additional info.

Quoted 18 lines
Quoted 18 lines
drivers/media/platform/seco-cec/seco-cec.c new file +17 -0
+	}
+
+	outb(0x00, HCNT);
+	outb((u8)(slave_addr & 0xfe) | operation, XMIT_SLVA);
+	outb(cmd, HCMD);
+	inb(HCNT);
+
+	if (operation == SMBUS_WRITE) {
+		outb((u8)data, HDAT0);
+		outb((u8)(data >> 8), HDAT1);
+	}
+
+	outb(BRA_START + _data_format, HCNT);
+
+	for (count = 0; count <= SMBTIMEOUT; count++) {
+		if (!(inb(HSTS) & BRA_HOST_BUSY))
+			break;
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 87

Quoted 5 lines
drivers/media/platform/seco-cec/seco-cec.c new file +5 -0
+		udelay(SMB_POLL_UDELAY);
+	}
+
+	if (count > SMBTIMEOUT) {
+		pr_debug("%s: SMBTIMEOUT_1\n", __func__);

As you return an error this seems more like a pr_err (or dev_err if possible)

Same here. The error code speaks for itself.

Quoted 113 lines
Quoted 113 lines
drivers/media/platform/seco-cec/seco-cec.c new file +112 -0
+		status = -EBUSY;
+		goto err;
+	}
+
+	if (inb(HSTS) & BRA_HSTS_ERR_MASK) {
+		status = -EIO;
+		goto err;
+	}
+
+	if (operation == SMBUS_READ)
+		*result = ((inb(HDAT0) & 0xff) + ((inb(HDAT1) & 0xff) << 8));
+
+err:
+	outb(0xff, HSTS);
+	return status;
+}
+
+static int secocec_adap_enable(struct cec_adapter *adap, bool enable)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 val = 0;
+	int status;
+
+	if (enable) {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Enable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1,
+				  val | SECOCEC_ENABLE_REG_1_CEC);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device enabled");
+	} else {
+		/* Clear the status register */
+		status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+		if (status)
+			goto err;
+
+		/* Disable the interrupts */
+		status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+		if (status)
+			goto err;
+
+		status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+				  ~SECOCEC_ENABLE_REG_1_CEC &
+				  ~SECOCEC_ENABLE_REG_1_IR);
+		if (status)
+			goto err;
+
+		dev_dbg(dev, "Device disabled");
+	}
+
+	return 0;
+err:
+	dev_err(dev, "Adapter setup failed (%d)", status);
+	return status;
+}
+
+static int secocec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr)
+{
+	u16 enable_val = 0;
+	int status;
+
+	/* Disable device */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &enable_val);
+	if (status)
+		return status;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val & ~SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	/* Write logical address */
+	status = smb_wr16(SECOCEC_DEVICE_LA, logical_addr);
+	if (status)
+		return status;
+
+	/* Re-enable device */
+	status = smb_wr16(SECOCEC_ENABLE_REG_1,
+			  enable_val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		return status;
+
+	return 0;
+}
+
+static int secocec_adap_transmit(struct cec_adapter *adap, u8 attempts,
+				 u32 signal_free_time, struct cec_msg *msg)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	u16 payload_len, payload_id_len, destination, val = 0;
+	u8 *payload_msg;
+	int status;
Quoted 8 lines

drivers/media/platform/seco-cec/seco-cec.c line 203

Quoted 4 lines
drivers/media/platform/seco-cec/seco-cec.c new file +4 -0
+	u8 i;
+
+	/* Device msg len already accounts for header */
+	payload_id_len = msg->len - 1;

Does it make sense to continue if payload_id_len == 0 ? You're going to send the length only (0) and that's it. Is your device happy with this? Please consider returning here if it is not.

I agree with Hans, len == 0 means it is a PING message.

Quoted 44 lines
Quoted 11 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+
+	/* Send data length */
+	status = smb_wr16(SECOCEC_WRITE_DATA_LENGTH, payload_id_len);
+	if (status)
+		goto err;
+
+	/* Send Operation ID if present */
+	if (payload_id_len > 0) {
+		status = smb_wr16(SECOCEC_WRITE_OPERATION_ID, msg->msg[1]);
+		if (status)

drivers/media/platform/seco-cec/seco-cec.c line 223

Quoted 10 lines
drivers/media/platform/seco-cec/seco-cec.c new file +10 -0
+			goto err;
+	}
+	/* Send data if present */
+	if (payload_id_len > 1) {
+		/* Only data; */
+		payload_len = msg->len - 2;
+		payload_msg = &msg->msg[2];
+
+		/* Copy message into registers */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {

Am I wrong or with an odd message length you're going to access memory after msg->msg[] ends?

If len is, say, 5, you're going to cycle from 0 to 2 (as 5 / 2 + (5 %
2) == 3)

drivers/media/platform/seco-cec/seco-cec.c line 225

Quoted 2 lines
drivers/media/platform/seco-cec/seco-cec.c new file +2 -0
+			/* hi byte */
+			val = payload_msg[(i << 1) + 1] << 8;

And here during the last iteration you'll access payload_msg[2 << 1 + 1] which is after payload_msg end. Please make sure you catch this and skip this assignment.

           index: 0  1  2  3  4
payload_msg[5] = [x, y, w, v, z]
i = 0
        val = y << 8 | x;
i = 1
        val = v << 8 | w;
i = 2
        val = ?? < 8 | z;
Quoted 4 lines

I'm not sure how msg->msg is allocated or initialized, nor what is its actual length, but this feels buggy to me.

What do you think?

Yes, the msg->msg is actually a fixed lenght array of 16 bytes, but the device have only 8 registers of 2 bytes, so it is impossible to go out-of-bound. Also, there is no need of caring of the last odd byte, because msg->len already accounts for the legit bytes in msg->msg.

I will fix as suggested by Hans, I found it fine to implement.

Quoted 3 lines

Thanks
j

Thanks again,
Ettore

Quoted 621 lines
Quoted 621 lines
drivers/media/platform/seco-cec/seco-cec.c new file +481 -0
+
+			/* lo byte */
+			val |= payload_msg[(i << 1)];
+
+			status = smb_wr16(SECOCEC_WRITE_DATA_00 + i, val);
+			if (status)
+				goto err;
+		}
+	}
+	/* Send msg source/destination and fire msg */
+	destination = msg->msg[0];
+	status = smb_wr16(SECOCEC_WRITE_BYTE0, destination);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Transmit failed (%d)", status);
+	return status;
+}
+
+static int secocec_tx_done(struct cec_adapter *adap, u16 status_val)
+{
+	int status = 0;
+
+	if (status_val & SECOCEC_STATUS_TX_ERROR_MASK) {
+		if (status_val & SECOCEC_STATUS_TX_NACK_ERROR) {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_NACK);
+			status = -EAGAIN;
+		} else {
+			cec_transmit_attempt_done(adap, CEC_TX_STATUS_ERROR);
+			status = -EIO;
+		}
+	} else {
+		cec_transmit_attempt_done(adap, CEC_TX_STATUS_OK);
+	}
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_TX_ERROR_MASK |
+		SECOCEC_STATUS_MSG_SENT_MASK |
+		SECOCEC_STATUS_TX_NACK_ERROR;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+	return status;
+}
+
+static int secocec_rx_done(struct cec_adapter *adap, u16 status_val)
+{
+	struct secocec_data *cec = cec_get_drvdata(adap);
+	struct device *dev = cec->dev;
+	struct cec_msg msg = { };
+	bool flag_overflow = false;
+	u8 payload_len, i = 0;
+	u8 *payload_msg;
+	u16 val = 0;
+	int status;
+
+	if (status_val & SECOCEC_STATUS_RX_OVERFLOW_MASK) {
+		dev_warn(dev, "Received more than 16 bytes. Discarding");
+		flag_overflow = true;
+	}
+
+	if (status_val & SECOCEC_STATUS_RX_ERROR_MASK) {
+		dev_warn(dev, "Message received with errors. Discarding");
+		status = -EIO;
+		goto rxerr;
+	}
+
+	/* Read message length */
+	status = smb_rd16(SECOCEC_READ_DATA_LENGTH, &val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Incoming message (payload len %d):", val);
+
+	/* Device msg len already accounts for the header */
+	msg.len = min(val + 1, CEC_MAX_MSG_SIZE);
+
+	/* Read logical address */
+	status = smb_rd16(SECOCEC_READ_BYTE0, &val);
+	if (status)
+		goto err;
+
+	/* device stores source LA and destination */
+	msg.msg[0] = val;
+
+	/* Read operation ID */
+	status = smb_rd16(SECOCEC_READ_OPERATION_ID, &val);
+	if (status)
+		goto err;
+
+	msg.msg[1] = val;
+
+	/* Read data if present */
+	if (msg.len > 1) {
+		payload_len = msg.len - 2;
+		payload_msg = &msg.msg[2];
+
+		/* device stores 2 bytes in every 16-bit val */
+		for (i = 0; i < payload_len / 2 + payload_len % 2; i++) {
+			status = smb_rd16(SECOCEC_READ_DATA_00 + i, &val);
+			if (status)
+				goto err;
+
+			/* low byte, skipping header */
+			payload_msg[(i << 1)] = val & 0x00ff;
+
+			/* hi byte */
+			payload_msg[(i << 1) + 1] = (val & 0xff00) >> 8;
+		}
+	}
+
+	cec_received_msg(cec->cec_adap, &msg);
+
+	/* Reset status reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+
+	status = smb_wr16(SECOCEC_STATUS, status_val);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Message received successfully");
+
+	return 0;
+
+rxerr:
+	/* Reset error reg */
+	status_val = SECOCEC_STATUS_MSG_RECEIVED_MASK |
+		SECOCEC_STATUS_RX_ERROR_MASK;
+	if (flag_overflow)
+		status_val |= SECOCEC_STATUS_RX_OVERFLOW_MASK;
+	smb_wr16(SECOCEC_STATUS, status_val);
+
+err:
+	dev_err(dev, "Receive message failed (%d)", status);
+	return status;
+}
+
+struct cec_adap_ops secocec_cec_adap_ops = {
+	/* Low-level callbacks */
+	.adap_enable = secocec_adap_enable,
+	.adap_log_addr = secocec_adap_log_addr,
+	.adap_transmit = secocec_adap_transmit,
+};
+
+static irqreturn_t secocec_irq_handler(int irq, void *priv)
+{
+	struct secocec_data *cec = priv;
+	struct device *dev = cec->dev;
+	u16 status_val, cec_val, val = 0;
+	int status;
+
+	/*  Read status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &status_val);
+	if (status)
+		goto err;
+
+	if (status_val & SECOCEC_STATUS_REG_1_CEC) {
+		/* Read CEC status register */
+		status = smb_rd16(SECOCEC_STATUS, &cec_val);
+		if (status)
+			goto err;
+
+		if (cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK)
+			secocec_rx_done(cec->cec_adap, cec_val);
+
+		if (cec_val & SECOCEC_STATUS_MSG_SENT_MASK)
+			secocec_tx_done(cec->cec_adap, cec_val);
+
+		if ((~cec_val & SECOCEC_STATUS_MSG_SENT_MASK) &&
+		    (~cec_val & SECOCEC_STATUS_MSG_RECEIVED_MASK))
+			dev_warn(dev,
+				 "Message not received or sent, but interrupt fired");
+
+		val = SECOCEC_STATUS_REG_1_CEC;
+	}
+
+	if (status_val & SECOCEC_STATUS_REG_1_IR) {
+		dev_dbg(dev, "IR RC5 Interrupt Caught");
+		val |= SECOCEC_STATUS_REG_1_IR;
+		/* TODO IRDA RX */
+	}
+
+	/*  Reset status register */
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	return IRQ_HANDLED;
+
+err:
+	dev_err(dev, "IRQ: Read/Write SMBus operation failed (%d)", status);
+
+	/*  Reset status register */
+	val = SECOCEC_STATUS_REG_1_CEC | SECOCEC_STATUS_REG_1_IR;
+	smb_wr16(SECOCEC_STATUS_REG_1, val);
+
+	return IRQ_HANDLED;
+}
+
+struct cec_dmi_match {
+	char *sys_vendor;
+	char *product_name;
+	char *devname;
+	char *conn;
+};
+
+static const struct cec_dmi_match secocec_dmi_match_table[] = {
+	/* UDOO X86 */
+	{ "SECO", "UDOO x86", "0000:00:02.0", "Port B" },
+};
+
+static int secocec_cec_get_notifier(struct cec_notifier **notify)
+{
+	int i;
+
+	for (i = 0 ; i < ARRAY_SIZE(secocec_dmi_match_table) ; ++i) {
+		const struct cec_dmi_match *m = &secocec_dmi_match_table[i];
+
+		if (dmi_match(DMI_SYS_VENDOR, m->sys_vendor) &&
+		    dmi_match(DMI_PRODUCT_NAME, m->product_name)) {
+			struct device *d;
+
+			/* Find the device, bail out if not yet registered */
+			d = bus_find_device_by_name(&pci_bus_type, NULL,
+						    m->devname);
+			if (!d)
+				return -EPROBE_DEFER;
+
+			*notify = cec_notifier_get_conn(d, m->conn);
+
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int secocec_acpi_probe(struct secocec_data *sdev)
+{
+	struct device *dev = sdev->dev;
+	struct gpio_desc *gpio;
+	int irq = 0;
+
+	gpio = devm_gpiod_get(dev, NULL, GPIOF_IN);
+	if (IS_ERR(gpio)) {
+		dev_err(dev, "Cannot request interrupt gpio");
+		return PTR_ERR(gpio);
+	}
+
+	irq = gpiod_to_irq(gpio);
+	if (irq < 0) {
+		dev_err(dev, "Cannot find valid irq");
+		return -ENODEV;
+	}
+	dev_dbg(dev, "irq-gpio is bound to IRQ %d", irq);
+
+	sdev->irq = irq;
+
+	return 0;
+}
+
+static int secocec_probe(struct platform_device *pdev)
+{
+	struct secocec_data *secocec;
+	struct device *dev = &pdev->dev;
+	int ret;
+	u16 val;
+
+	secocec = devm_kzalloc(dev, sizeof(*secocec), GFP_KERNEL);
+	if (!secocec)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, secocec);
+
+	/* Request SMBus regions */
+	if (!request_muxed_region(BRA_SMB_BASE_ADDR, 7, "CEC00001")) {
+		dev_err(dev, "Request memory region failed");
+		return -ENXIO;
+	}
+
+	secocec->pdev = pdev;
+	secocec->dev = dev;
+
+	if (!has_acpi_companion(dev)) {
+		dev_dbg(dev, "Cannot find any ACPI companion");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	ret = secocec_acpi_probe(secocec);
+	if (ret) {
+		dev_err(dev, "Cannot assign gpio to IRQ");
+		ret = -ENODEV;
+		goto err;
+	}
+
+	dev_dbg(dev, "IRQ detected at %d", secocec->irq);
+
+	/* Firmware version check */
+	ret = smb_rd16(SECOCEC_VERSION, &val);
+	if (ret) {
+		dev_err(dev, "Cannot check fw version");
+		goto err;
+	}
+	if (val < SECOCEC_LATEST_FW) {
+		dev_err(dev, "CEC Firmware not supported (v.%04x). Use ver > v.%04x",
+			val, SECOCEC_LATEST_FW);
+		ret = -EINVAL;
+		goto err;
+	}
+
+	ret = secocec_cec_get_notifier(&secocec->notifier);
+	if (ret) {
+		dev_err(dev, "no CEC notifier available\n");
+		goto err;
+	}
+
+	ret = devm_request_threaded_irq(dev,
+					secocec->irq,
+					NULL,
+					secocec_irq_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					dev_name(&pdev->dev), secocec);
+
+	if (ret) {
+		dev_err(dev, "Cannot request IRQ %d", secocec->irq);
+		ret = -EIO;
+		goto err;
+	}
+
+	/* Allocate CEC adapter */
+	secocec->cec_adap = cec_allocate_adapter(&secocec_cec_adap_ops,
+						 secocec,
+						 dev_name(dev),
+						 CEC_CAP_DEFAULTS,
+						 SECOCEC_MAX_ADDRS);
+
+	if (IS_ERR(secocec->cec_adap)) {
+		ret = PTR_ERR(secocec->cec_adap);
+		goto err;
+	}
+
+	ret = cec_register_adapter(secocec->cec_adap, dev);
+	if (ret)
+		goto err_delete_adapter;
+
+	if (secocec->notifier)
+		cec_register_cec_notifier(secocec->cec_adap, secocec->notifier);
+
+	platform_set_drvdata(pdev, secocec);
+
+	dev_dbg(dev, "Device registered");
+
+	return ret;
+
+err_delete_adapter:
+	cec_delete_adapter(secocec->cec_adap);
+err:
+	dev_err(dev, "%s device probe failed\n", dev_name(dev));
+
+	return ret;
+}
+
+static int secocec_remove(struct platform_device *pdev)
+{
+	struct secocec_data *secocec = platform_get_drvdata(pdev);
+
+	cec_unregister_adapter(secocec->cec_adap);
+
+	if (secocec->notifier)
+		cec_notifier_put(secocec->notifier);
+
+	release_region(BRA_SMB_BASE_ADDR, 7);
+
+	dev_dbg(&pdev->dev, "CEC device removed");
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int secocec_suspend(struct device *dev)
+{
+	int status;
+	u16 val;
+
+	dev_dbg(dev, "Device going to suspend, disabling");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Disable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val &
+			  ~SECOCEC_ENABLE_REG_1_CEC & ~SECOCEC_ENABLE_REG_1_IR);
+	if (status)
+		goto err;
+
+	return 0;
+
+err:
+	dev_err(dev, "Suspend failed (err: %d)", status);
+	return status;
+}
+
+static int secocec_resume(struct device *dev)
+{
+	int status;
+	u16 val;
+
+	dev_dbg(dev, "Resuming device from suspend");
+
+	/* Clear the status register */
+	status = smb_rd16(SECOCEC_STATUS_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_STATUS_REG_1, val);
+	if (status)
+		goto err;
+
+	/* Enable the interrupts */
+	status = smb_rd16(SECOCEC_ENABLE_REG_1, &val);
+	if (status)
+		goto err;
+
+	status = smb_wr16(SECOCEC_ENABLE_REG_1, val | SECOCEC_ENABLE_REG_1_CEC);
+	if (status)
+		goto err;
+
+	dev_dbg(dev, "Device resumed from suspend");
+
+	return 0;
+
+err:
+	dev_err(dev, "Resume failed (err: %d)", status);
+	return status;
+}
+
+static SIMPLE_DEV_PM_OPS(secocec_pm_ops, secocec_suspend, secocec_resume);
+#define SECOCEC_PM_OPS (&secocec_pm_ops)
+#else
+#define SECOCEC_PM_OPS NULL
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id secocec_acpi_match[] = {
+	{"CEC00001", 0},
+	{},
+};
+
+MODULE_DEVICE_TABLE(acpi, secocec_acpi_match);
+#endif
+
+static struct platform_driver secocec_driver = {
+	.driver = {
+		   .name = SECOCEC_DEV_NAME,
+		   .acpi_match_table = ACPI_PTR(secocec_acpi_match),
+		   .pm = SECOCEC_PM_OPS,
+	},
+	.probe = secocec_probe,
+	.remove = secocec_remove,
+};
+
+module_platform_driver(secocec_driver);
+
+MODULE_DESCRIPTION("SECO CEC X86 Driver");
+MODULE_AUTHOR("Ettore Chimenti <[email protected]>");
+MODULE_LICENSE("Dual BSD/GPL");
drivers/media/platform/seco-cec/seco-cec.h new file +130 -1
new file mode 100644
index 000000000000..93020900935e
@@ -0,0 +1,130 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
+/*
+ * SECO X86 Boards CEC register defines
+ *
+ * Author:  Ettore Chimenti <[email protected]>
+ * Copyright (C) 2018, SECO Srl.
+ * Copyright (C) 2018, Aidilab Srl.
+ */
+
+#ifndef __SECO_CEC_H__
+#define __SECO_CEC_H__
+
+#define SECOCEC_MAX_ADDRS		1
+#define SECOCEC_DEV_NAME		"secocec"
+#define SECOCEC_LATEST_FW		0x0f0b
+
+#define SMBTIMEOUT			0xffff
+#define SMB_POLL_UDELAY			10
+
+#define SMBUS_WRITE			0
+#define SMBUS_READ			1
+
+#define CMD_BYTE_DATA			0
+#define CMD_WORD_DATA			1
+
+/*
+ * SMBus definitons for Braswell
+ */
+
+#define BRA_DONE_STATUS			BIT(7)
+#define BRA_INUSE_STS			BIT(6)
+#define BRA_FAILED_OP			BIT(4)
+#define BRA_BUS_ERR			BIT(3)
+#define BRA_DEV_ERR			BIT(2)
+#define BRA_INTR			BIT(1)
+#define BRA_HOST_BUSY			BIT(0)
+#define BRA_HSTS_ERR_MASK   (BRA_FAILED_OP | BRA_BUS_ERR | BRA_DEV_ERR)
+
+#define BRA_PEC_EN			BIT(7)
+#define BRA_START			BIT(6)
+#define BRA_LAST__BYTE			BIT(5)
+#define BRA_INTREN			BIT(0)
+#define BRA_SMB_CMD			(7 << 2)
+#define BRA_SMB_CMD_QUICK		(0 << 2)
+#define BRA_SMB_CMD_BYTE		(1 << 2)
+#define BRA_SMB_CMD_BYTE_DATA		(2 << 2)
+#define BRA_SMB_CMD_WORD_DATA		(3 << 2)
+#define BRA_SMB_CMD_PROCESS_CALL	(4 << 2)
+#define BRA_SMB_CMD_BLOCK		(5 << 2)
+#define BRA_SMB_CMD_I2CREAD		(6 << 2)
+#define BRA_SMB_CMD_BLOCK_PROCESS	(7 << 2)
+
+#define BRA_SMB_BASE_ADDR  0x2040
+#define HSTS               (BRA_SMB_BASE_ADDR + 0)
+#define HCNT               (BRA_SMB_BASE_ADDR + 2)
+#define HCMD               (BRA_SMB_BASE_ADDR + 3)
+#define XMIT_SLVA          (BRA_SMB_BASE_ADDR + 4)
+#define HDAT0              (BRA_SMB_BASE_ADDR + 5)
+#define HDAT1              (BRA_SMB_BASE_ADDR + 6)
+
+/*
+ * Microcontroller Address
+ */
+
+#define SECOCEC_MICRO_ADDRESS		0x40
+
+/*
+ * STM32 SMBus Registers
+ */
+
+#define SECOCEC_VERSION			0x00
+#define SECOCEC_ENABLE_REG_1		0x01
+#define SECOCEC_ENABLE_REG_2		0x02
+#define SECOCEC_STATUS_REG_1		0x03
+#define SECOCEC_STATUS_REG_2		0x04
+
+#define SECOCEC_STATUS			0x28
+#define SECOCEC_DEVICE_LA		0x29
+#define SECOCEC_READ_OPERATION_ID	0x2a
+#define SECOCEC_READ_DATA_LENGTH	0x2b
+#define SECOCEC_READ_DATA_00		0x2c
+#define SECOCEC_READ_DATA_02		0x2d
+#define SECOCEC_READ_DATA_04		0x2e
+#define SECOCEC_READ_DATA_06		0x2f
+#define SECOCEC_READ_DATA_08		0x30
+#define SECOCEC_READ_DATA_10		0x31
+#define SECOCEC_READ_DATA_12		0x32
+#define SECOCEC_READ_BYTE0		0x33
+#define SECOCEC_WRITE_OPERATION_ID	0x34
+#define SECOCEC_WRITE_DATA_LENGTH	0x35
+#define SECOCEC_WRITE_DATA_00		0x36
+#define SECOCEC_WRITE_DATA_02		0x37
+#define SECOCEC_WRITE_DATA_04		0x38
+#define SECOCEC_WRITE_DATA_06		0x39
+#define SECOCEC_WRITE_DATA_08		0x3a
+#define SECOCEC_WRITE_DATA_10		0x3b
+#define SECOCEC_WRITE_DATA_12		0x3c
+#define SECOCEC_WRITE_BYTE0		0x3d
+
+#define SECOCEC_IR_READ_DATA		0x3e
+
+/*
+ * Enabling register
+ */
+
+#define SECOCEC_ENABLE_REG_1_CEC		0x1000
+#define SECOCEC_ENABLE_REG_1_IR			0x2000
+#define SECOCEC_ENABLE_REG_1_IR_PASSTHROUGH	0x4000
+
+/*
+ * Status register
+ */
+
+#define SECOCEC_STATUS_REG_1_CEC	SECOCEC_ENABLE_REG_1_CEC
+#define SECOCEC_STATUS_REG_1_IR		SECOCEC_ENABLE_REG_1_IR
+#define SECOCEC_STATUS_REG_1_IR_PASSTHR	SECOCEC_ENABLE_REG_1_IR_PASSTHR
+
+/*
+ * Status data
+ */
+
+#define SECOCEC_STATUS_MSG_RECEIVED_MASK	BIT(0)
+#define SECOCEC_STATUS_RX_ERROR_MASK		BIT(1)
+#define SECOCEC_STATUS_MSG_SENT_MASK		BIT(2)
+#define SECOCEC_STATUS_TX_ERROR_MASK		BIT(3)
+
+#define SECOCEC_STATUS_TX_NACK_ERROR		BIT(4)
+#define SECOCEC_STATUS_RX_OVERFLOW_MASK		BIT(5)
+
+#endif /* __SECO_CEC_H__ */
--

2.18.0

author
#22 lore raw
In reply to Hans Verkuil

Hi Hans,

Quoted 25 lines · Hans Verkuil

Hi Ettore,

Quoted 10 lines · On 10/05/2018 07:33 PM, ektor5 wrote:

This series of patches aims to add CEC functionalities to SECO devices, in particular UDOO X86.

The communication is achieved via Braswell SMBus (i2c-i801) to the onboard STM32 microcontroller that handles the CEC signals. The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

This series looks good to me. But can you do one more test:

Update your kernel to the latest media_tree master and also update your v4l-utils repo to the latest master code.

With all that in place please run:

cec-compliance -A

(have the HDMI output connected to a CEC-capable TV when running this test).

Quoted 7 lines

Please report back the output of cec-compliance.

A bunch of CEC bug fixes and improvements were merged yesterday, and the cec-compliance adapter test is improved to check for issues that were hard to find in the past.

So it will be good to have a final check of this driver.

Here it is, compiled media-tree and latest v4l-utils:

udoo@udoo-UDOO-x86:~/v4l-utils/utils/cec-compliance$ uname -a
Linux udoo-UDOO-x86 4.19.0-041900rc7-generic #201810071631+cec SMP Tue Oct 9 17:36:11 CEST 2018 x86_64 x86_64 x86_64 GNU/Linux
udoo@udoo-UDOO-x86:~/v4l-utils/utils/cec-compliance$ ./cec-compliance -A
cec-compliance SHA                 : 06ad469e966aafaf39c1cc76e6e0953ec7d4f9c9
Driver Info:
	Driver Name                : secocec
	Adapter Name               : CEC00001:00
	Capabilities               : 0x0000000e
		Logical Addresses
		Transmit
		Passthrough
	Driver version             : 4.19.0
	Available Logical Addresses: 1
	Physical Address           : 3.0.0.0
	Logical Address Mask       : 0x0010
	CEC Version                : 2.0
	Vendor ID                  : 0x000c03 (HDMI)
	OSD Name                   : Playback
	Logical Addresses          : 1 
	  Logical Address          : 4 (Playback Device 1)
	    Primary Device Type    : Playback
	    Logical Address Type   : Playback
	    All Device Types       : Playback
	    RC TV Profile          : None
	    Device Features        :

None

Compliance test for device /dev/cec0:

The test results mean the following:
OK Supported correctly by the device.
OK (Not Supported) Not supported and not mandatory for the device.
OK (Presumed) Presumably supported. Manually check to confirm.
OK (Unexpected) Supported correctly but is not expected to be supported for this device.
OK (Refused) Supported by the device, but was refused.
FAIL Failed and was expected to be supported by this device.

Find remote devices:
Polling: OK

CEC API:
CEC_ADAP_G_CAPS: OK
CEC_DQEVENT: OK
CEC_ADAP_G/S_PHYS_ADDR: OK
CEC_ADAP_G/S_LOG_ADDRS: OK
CEC_TRANSMIT: OK
CEC_RECEIVE: OK
CEC_TRANSMIT/RECEIVE (non-blocking): OK (Presumed)
CEC_G/S_MODE: OK
fail: cec-test-adapter.cpp(1042): There were 142 pending messages for 83 transmitted messages
CEC_EVENT_LOST_MSGS: FAIL

Network topology:
System Information for device 0 (TV) from device 4 (Playback Device 1):
CEC Version : 1.4
Physical Address : 0.0.0.0
Primary Device Type : TV
Vendor ID : 0x00e091
OSD Name : Tx, OK, Rx, Timeout
Menu Language : kor
Power Status : On

Total: 10, Succeeded: 9, Failed: 1, Warnings: 0

Thanks,
Ettore

Quoted 30 lines

Regards,

Hans

Quoted 24 lines

v2:
- Removed useless debug prints
- Added DMI && PCI to dependences
- Removed useless ifdefs
- Renamed all irda references to ir
- Fixed SPDX clause
- Several style fixes

Ettore Chimenti (2):
media: add SECO cec driver
seco-cec: add Consumer-IR support

 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  22 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 829 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 141 ++++
 6 files changed, 1001 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
#23 lore raw
Quoted 79 lines · On 10/10/18 14:09, ektor5 wrote:

Hi Hans,

Quoted 25 lines · Hans Verkuil

Hi Ettore,

Quoted 10 lines · On 10/05/2018 07:33 PM, ektor5 wrote:

This series of patches aims to add CEC functionalities to SECO devices, in particular UDOO X86.

The communication is achieved via Braswell SMBus (i2c-i801) to the onboard STM32 microcontroller that handles the CEC signals. The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

This series looks good to me. But can you do one more test:

Update your kernel to the latest media_tree master and also update your v4l-utils repo to the latest master code.

With all that in place please run:

cec-compliance -A

(have the HDMI output connected to a CEC-capable TV when running this test).

Quoted 7 lines

Please report back the output of cec-compliance.

A bunch of CEC bug fixes and improvements were merged yesterday, and the cec-compliance adapter test is improved to check for issues that were hard to find in the past.

So it will be good to have a final check of this driver.

Here it is, compiled media-tree and latest v4l-utils:

udoo@udoo-UDOO-x86:~/v4l-utils/utils/cec-compliance$ uname -a
Linux udoo-UDOO-x86 4.19.0-041900rc7-generic #201810071631+cec SMP Tue Oct 9 17:36:11 CEST 2018 x86_64 x86_64 x86_64 GNU/Linux
udoo@udoo-UDOO-x86:~/v4l-utils/utils/cec-compliance$ ./cec-compliance -A
cec-compliance SHA                 : 06ad469e966aafaf39c1cc76e6e0953ec7d4f9c9
Driver Info:
	Driver Name                : secocec
	Adapter Name               : CEC00001:00
	Capabilities               : 0x0000000e
		Logical Addresses
		Transmit
		Passthrough
	Driver version             : 4.19.0
	Available Logical Addresses: 1
	Physical Address           : 3.0.0.0
	Logical Address Mask       : 0x0010
	CEC Version                : 2.0
	Vendor ID                  : 0x000c03 (HDMI)
	OSD Name                   : Playback
	Logical Addresses          : 1 
	  Logical Address          : 4 (Playback Device 1)
	    Primary Device Type    : Playback
	    Logical Address Type   : Playback
	    All Device Types       : Playback
	    RC TV Profile          : None
	    Device Features        :

None

Compliance test for device /dev/cec0:

The test results mean the following:
OK Supported correctly by the device.
OK (Not Supported) Not supported and not mandatory for the device.
OK (Presumed) Presumably supported. Manually check to confirm.
OK (Unexpected) Supported correctly but is not expected to be supported for this device.
OK (Refused) Supported by the device, but was refused.
FAIL Failed and was expected to be supported by this device.

Find remote devices:
Polling: OK

Quoted 10 lines

CEC API:
CEC_ADAP_G_CAPS: OK
CEC_DQEVENT: OK
CEC_ADAP_G/S_PHYS_ADDR: OK
CEC_ADAP_G/S_LOG_ADDRS: OK
CEC_TRANSMIT: OK
CEC_RECEIVE: OK
CEC_TRANSMIT/RECEIVE (non-blocking): OK (Presumed)
CEC_G/S_MODE: OK
fail: cec-test-adapter.cpp(1042): There were 142 pending messages for 83 transmitted messages

That's not good.

If you look in the kernel log, do you see 'timed out' cec messages?

Note: that message is a warning since commit 7ec2b3b941a666a942859684281b5f6460a0c234. Before that you first need to enable debugging:

echo 1 >/sys/module/cec/parameters/debug

My guess is that this might be a fw bug. Does the firmware handle Signal Free Time correctly? My guess is that it doesn't do that and that this test causes what is effectively a 'denial of service' situation: the transmitter gets blocked waiting for sufficient signal free time.

I have updated cec-compliance to give better information about what was received, so can you update cec-compliance and run again?

Also, run 'cec-ctl -m >cec.log' at the same time and mail me that log.

There are two types of CEC adapters: those that handle retransmits automatically (and they determine the Signal Free Time themselves) and those that don't do automatic retransmits, and there you normally need to program the Signal Free Time before starting the transmit.

This driver falls in the second category, but the SFT isn't set anywhere.

This particular adapter test actually tests this, and I have seen this symptom before if the SFT wasn't set correctly.

Regards,

Hans

Quoted 47 lines

CEC_EVENT_LOST_MSGS: FAIL

Network topology:
System Information for device 0 (TV) from device 4 (Playback Device 1):
CEC Version : 1.4
Physical Address : 0.0.0.0
Primary Device Type : TV
Vendor ID : 0x00e091
OSD Name : Tx, OK, Rx, Timeout
Menu Language : kor
Power Status : On

Total: 10, Succeeded: 9, Failed: 1, Warnings: 0

Thanks,
Ettore

Quoted 30 lines

Regards,

Hans

Quoted 24 lines

v2:
- Removed useless debug prints
- Added DMI && PCI to dependences
- Removed useless ifdefs
- Renamed all irda references to ir
- Fixed SPDX clause
- Several style fixes

Ettore Chimenti (2):
media: add SECO cec driver
seco-cec: add Consumer-IR support

 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  22 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 829 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 141 ++++
 6 files changed, 1001 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h
author
#24 lore raw
Quoted 91 lines · Hans Verkuil
Quoted 79 lines · On 10/10/18 14:09, ektor5 wrote:

Hi Hans,

Quoted 25 lines · Hans Verkuil

Hi Ettore,

Quoted 10 lines · On 10/05/2018 07:33 PM, ektor5 wrote:

This series of patches aims to add CEC functionalities to SECO devices, in particular UDOO X86.

The communication is achieved via Braswell SMBus (i2c-i801) to the onboard STM32 microcontroller that handles the CEC signals. The driver use direct access to the PCI addresses, due to the limitations of the specific driver in presence of ACPI calls.

The basic functionalities are tested with success with cec-ctl and cec-compliance.

This series looks good to me. But can you do one more test:

Update your kernel to the latest media_tree master and also update your v4l-utils repo to the latest master code.

With all that in place please run:

cec-compliance -A

(have the HDMI output connected to a CEC-capable TV when running this test).

Quoted 7 lines

Please report back the output of cec-compliance.

A bunch of CEC bug fixes and improvements were merged yesterday, and the cec-compliance adapter test is improved to check for issues that were hard to find in the past.

So it will be good to have a final check of this driver.

Here it is, compiled media-tree and latest v4l-utils:

udoo@udoo-UDOO-x86:~/v4l-utils/utils/cec-compliance$ uname -a
Linux udoo-UDOO-x86 4.19.0-041900rc7-generic #201810071631+cec SMP Tue Oct 9 17:36:11 CEST 2018 x86_64 x86_64 x86_64 GNU/Linux
udoo@udoo-UDOO-x86:~/v4l-utils/utils/cec-compliance$ ./cec-compliance -A
cec-compliance SHA                 : 06ad469e966aafaf39c1cc76e6e0953ec7d4f9c9
Driver Info:
	Driver Name                : secocec
	Adapter Name               : CEC00001:00
	Capabilities               : 0x0000000e
		Logical Addresses
		Transmit
		Passthrough
	Driver version             : 4.19.0
	Available Logical Addresses: 1
	Physical Address           : 3.0.0.0
	Logical Address Mask       : 0x0010
	CEC Version                : 2.0
	Vendor ID                  : 0x000c03 (HDMI)
	OSD Name                   : Playback
	Logical Addresses          : 1 
	  Logical Address          : 4 (Playback Device 1)
	    Primary Device Type    : Playback
	    Logical Address Type   : Playback
	    All Device Types       : Playback
	    RC TV Profile          : None
	    Device Features        :

None

Compliance test for device /dev/cec0:

The test results mean the following:
OK Supported correctly by the device.
OK (Not Supported) Not supported and not mandatory for the device.
OK (Presumed) Presumably supported. Manually check to confirm.
OK (Unexpected) Supported correctly but is not expected to be supported for this device.
OK (Refused) Supported by the device, but was refused.
FAIL Failed and was expected to be supported by this device.

Find remote devices:
Polling: OK

Quoted 10 lines

CEC API:
CEC_ADAP_G_CAPS: OK
CEC_DQEVENT: OK
CEC_ADAP_G/S_PHYS_ADDR: OK
CEC_ADAP_G/S_LOG_ADDRS: OK
CEC_TRANSMIT: OK
CEC_RECEIVE: OK
CEC_TRANSMIT/RECEIVE (non-blocking): OK (Presumed)
CEC_G/S_MODE: OK
fail: cec-test-adapter.cpp(1042): There were 142 pending messages for 83 transmitted messages

Quoted 3 lines

That's not good.

If you look in the kernel log, do you see 'timed out' cec messages?

No, actually I see a lot of 'cec_transmit_msg_fh: transmit queue full' messages.

Quoted 6 lines

Note: that message is a warning since commit 7ec2b3b941a666a942859684281b5f6460a0c234. Before that you first need to enable debugging:

echo 1 >/sys/module/cec/parameters/debug

Quoted 7 lines

My guess is that this might be a fw bug. Does the firmware handle Signal Free Time correctly? My guess is that it doesn't do that and that this test causes what is effectively a 'denial of service' situation: the transmitter gets blocked waiting for sufficient signal free time.

I have updated cec-compliance to give better information about what was received, so can you update cec-compliance and run again?

Yes, I've recompiled the two, in attachment there are both outputs plus the relative kernel messages.

Quoted 8 lines

Also, run 'cec-ctl -m >cec.log' at the same time and mail me that log.

There are two types of CEC adapters: those that handle retransmits automatically (and they determine the Signal Free Time themselves) and those that don't do automatic retransmits, and there you normally need to program the Signal Free Time before starting the transmit.

Quoted 4 lines

This driver falls in the second category, but the SFT isn't set anywhere.

This particular adapter test actually tests this, and I have seen this symptom before if the SFT wasn't set correctly.

I didn't know that, there is a place to put that parameter (or there is a default)? There is a way to evaluate a good value for that?

Thanks a lot,
Ettore

Quoted 53 lines

Regards,

Hans

Quoted 47 lines

CEC_EVENT_LOST_MSGS: FAIL

Network topology:
System Information for device 0 (TV) from device 4 (Playback Device 1):
CEC Version : 1.4
Physical Address : 0.0.0.0
Primary Device Type : TV
Vendor ID : 0x00e091
OSD Name : Tx, OK, Rx, Timeout
Menu Language : kor
Power Status : On

Total: 10, Succeeded: 9, Failed: 1, Warnings: 0

Thanks,
Ettore

Quoted 30 lines

Regards,

Hans

Quoted 24 lines

v2:
- Removed useless debug prints
- Added DMI && PCI to dependences
- Removed useless ifdefs
- Renamed all irda references to ir
- Fixed SPDX clause
- Several style fixes

Ettore Chimenti (2):
media: add SECO cec driver
seco-cec: add Consumer-IR support

 MAINTAINERS                                |   6 +
 drivers/media/platform/Kconfig             |  22 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/seco-cec/Makefile   |   1 +
 drivers/media/platform/seco-cec/seco-cec.c | 829 +++++++++++++++++++++
 drivers/media/platform/seco-cec/seco-cec.h | 141 ++++
 6 files changed, 1001 insertions(+)
 create mode 100644 drivers/media/platform/seco-cec/Makefile
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.c
 create mode 100644 drivers/media/platform/seco-cec/seco-cec.h

cec-compliance SHA : 06ad469e966aafaf39c1cc76e6e0953ec7d4f9c9
Driver Info:

	Driver Name                : secocec
	Adapter Name               : CEC00001:00
	Capabilities               : 0x0000000e

Logical Addresses
Transmit
Passthrough
Driver version : 4.19.0
Available Logical Addresses: 1
Physical Address : 2.1.0.0
Logical Address Mask : 0x0010
CEC Version : 2.0
Vendor ID : 0x000c03 (HDMI)
OSD Name : Playback
Logical Addresses : 1

Logical Address : 4 (Playback Device 1)
Primary Device Type : Playback
Logical Address Type : Playback
All Device Types : Playback
RC TV Profile : None
Device Features :
None

Compliance test for device /dev/cec0:

The test results mean the following:
OK Supported correctly by the device.
OK (Not Supported) Not supported and not mandatory for the device.
OK (Presumed) Presumably supported. Manually check to confirm.
OK (Unexpected) Supported correctly but is not expected to be supported for this device.
OK (Refused) Supported by the device, but was refused.
FAIL Failed and was expected to be supported by this device.

Find remote devices:
Polling: OK

CEC API:
CEC_ADAP_G_CAPS: OK
CEC_DQEVENT: OK
CEC_ADAP_G/S_PHYS_ADDR: OK
CEC_ADAP_G/S_LOG_ADDRS: OK
fail: cec-test-adapter.cpp(318): msg.rx_status & CEC_RX_STATUS_TIMEOUT
CEC_TRANSMIT: FAIL
CEC_RECEIVE: OK
CEC_TRANSMIT/RECEIVE (non-blocking): OK (Presumed)
CEC_G/S_MODE: OK
Successful transmits: 88
Received messages: 2
Received 54 messages immediately, and 36 over 6 seconds
fail: cec-test-adapter.cpp(1090): There were 90 messages in the receive queue for 89 transmits
CEC_EVENT_LOST_MSGS: FAIL

Network topology:
System Information for device 0 (TV) from device 4 (Playback Device 1):
CEC Version : Tx, OK, Rx, OK, Feature Abort
Physical Address : 0.0.0.0
Primary Device Type : TV
Vendor ID : Tx, OK, Rx, Timeout
OSD Name : Tx, OK, Rx, Timeout
Menu Language : ita
Power Status : On
System Information for device 5 (Audio System) from device 4 (Playback Device 1):
CEC Version : 1.4
Physical Address : 2.0.0.0
Primary Device Type : Audio System
Vendor ID : 0x00a0de
OSD Name : 'HTR-2071'
Power Status : On

Total: 10, Succeeded: 8, Failed: 2, Warnings: 0

Driver Info:

	Driver Name                : secocec
	Adapter Name               : CEC00001:00
	Capabilities               : 0x0000000e

Logical Addresses
Transmit
Passthrough
Driver version : 4.19.0
Available Logical Addresses: 1
Physical Address : 2.1.0.0
Logical Address Mask : 0x0010
CEC Version : 2.0
Vendor ID : 0x000c03 (HDMI)
OSD Name : Playback
Logical Addresses : 1

Logical Address : 4 (Playback Device 1)
Primary Device Type : Playback
Logical Address Type : Playback
All Device Types : Playback
RC TV Profile : None
Device Features :
None

Initial Event: State Change: PA: 2.1.0.0, LA mask: 0x0010 Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_POLL Transmitted by Playback Device 1 to Recording Device 1 (4 to 1): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Recording Device 2 (4 to 2): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Tuner 1 (4 to 3): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Audio System (4 to 5): CEC_MSG_POLL Transmitted by Playback Device 1 to Tuner 2 (4 to 6): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Tuner 3 (4 to 7): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Playback Device 2 (4 to 8): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Recording Device 3 (4 to 9): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Tuner 4 (4 to 10): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Playback Device 3 (4 to 11): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Reserved 1 (4 to 12): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Reserved 2 (4 to 13): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries
Transmitted by Playback Device 1 to Specific (4 to 14): CEC_MSG_POLL
Tx, Not Acknowledged (2), Max Retries

Event: State Change: PA: 2.1.0.0, LA mask: 0x0000
Transmitted by Recording Device 1 to Recording Device 1 (1 to 1): CEC_MSG_POLL
Tx, Not Acknowledged (4), Max Retries

Event: State Change: PA: 2.1.0.0, LA mask: 0x0002
Transmitted by Recording Device 1 to all (1 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):

	phys-addr: 2.1.0.0
	prim-devtype: record (0x01)
	Tx, Aborted, Max Retries

Event: State Change: PA: 2.1.0.0, LA mask: 0x0000
Transmitted by Recording Device 1 to all (1 to 15): CEC_MSG_REPORT_FEATURES (0xa6):

	cec-version: version-2-0 (0x06)
	all-device-types: 72 (0x48)
	rc-profile: 16 (0x10)
	rc-profile: tv-profile-none (0x00)
	dev-features: 14 (0x0e)
	dev-features: 0 (0x00)
	Tx, Aborted, Max Retries

Transmitted by Recording Device 1 to Recording Device 1 (1 to 1): CEC_MSG_POLL
Tx, Not Acknowledged (4), Max Retries

Event: State Change: PA: 2.1.0.0, LA mask: 0x0002
Transmitted by Recording Device 1 to all (1 to 15): CEC_MSG_REPORT_FEATURES (0xa6):

	cec-version: version-2-0 (0x06)
	all-device-types: 72 (0x48)
	rc-profile: 16 (0x10)
	rc-profile: tv-profile-none (0x00)
	dev-features: 14 (0x0e)
	dev-features: 0 (0x00)
Transmitted by Recording Device 1 to all (1 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 2.1.0.0
	prim-devtype: record (0x01)

Received from TV to Recording Device 1 (0 to 1): CEC_MSG_GIVE_OSD_NAME (0x46) Transmitted by Recording Device 1 to TV (1 to 0): CEC_MSG_SET_OSD_NAME (0x47):
name: Compliance
Received from Audio System to Recording Device 1 (5 to 1): CEC_MSG_GIVE_OSD_NAME (0x46) Transmitted by Recording Device 1 to Audio System (1 to 5): CEC_MSG_SET_OSD_NAME (0x47):
name: Compliance
Tx, Aborted, Max Retries

Event: State Change: PA: 2.1.0.0, LA mask: 0x0000
Transmitted by Playback Device 1 to Playback Device 1 (4 to 4): CEC_MSG_POLL
Tx, Not Acknowledged (4), Max Retries

Event: State Change: PA: 2.1.0.0, LA mask: 0x0010
Transmitted by Playback Device 1 to all (4 to 15): CEC_MSG_REPORT_FEATURES (0xa6):

	cec-version: version-2-0 (0x06)
	all-device-types: playback (0x10)
	rc-profile: tv-profile-none (0x00)
	dev-features: 0 (0x00)
Transmitted by Playback Device 1 to all (4 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 2.1.0.0
	prim-devtype: playback (0x04)

Transmitted by Unregistered to TV (15 to 0): CEC_MSG_POLL
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83) Received from TV to Playback Device 1 (0 to 4): CEC_MSG_GIVE_OSD_NAME (0x46) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_SET_OSD_NAME (0x47):
name: Playback
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83) Received from TV to all (0 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):

	phys-addr: 0.0.0.0
	prim-devtype: tv (0x00)
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83)
Received from TV to all (0 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 0.0.0.0
	prim-devtype: tv (0x00)
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83)
Received from TV to all (0 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 0.0.0.0
	prim-devtype: tv (0x00)
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83)
Received from TV to all (0 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 0.0.0.0
	prim-devtype: tv (0x00)

Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_POLL Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_POLL Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_POLL Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_POLL Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_POLL Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83) Received from TV to all (0 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):

	phys-addr: 0.0.0.0
	prim-devtype: tv (0x00)
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83)
Received from TV to all (0 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 0.0.0.0
	prim-devtype: tv (0x00)
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83)
Received from TV to all (0 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 0.0.0.0
	prim-devtype: tv (0x00)
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83)
Received from TV to all (0 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 0.0.0.0
	prim-devtype: tv (0x00)
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83)
Received from TV to all (0 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 0.0.0.0
	prim-devtype: tv (0x00)

Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f) Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):

	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_CEC_VERSION (0x9f)
Received from TV to Playback Device 1 (0 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 159 (0x9f)
	reason: unrecognized-op (0x00)
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83)
Received from TV to all (0 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 0.0.0.0
	prim-devtype: tv (0x00)

Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_DEVICE_VENDOR_ID (0x8c) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_OSD_NAME (0x46) Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GET_MENU_LANGUAGE (0x91) Received from TV to all (0 to 15): CEC_MSG_SET_MENU_LANGUAGE (0x32):
language: ita
Transmitted by Playback Device 1 to TV (4 to 0): CEC_MSG_GIVE_DEVICE_POWER_STATUS (0x8f) Received from TV to Playback Device 1 (0 to 4): CEC_MSG_REPORT_POWER_STATUS (0x90):

	pwr-state: on (0x00)
Transmitted by Playback Device 1 to Audio System (4 to 5): CEC_MSG_GET_CEC_VERSION (0x9f)
Received from Audio System to Playback Device 1 (5 to 4): CEC_MSG_CEC_VERSION (0x9e):
	cec-version: version-1-4 (0x05)
Transmitted by Playback Device 1 to Audio System (4 to 5): CEC_MSG_GIVE_PHYSICAL_ADDR (0x83)
Received from Audio System to all (5 to 15): CEC_MSG_REPORT_PHYSICAL_ADDR (0x84):
	phys-addr: 2.0.0.0
	prim-devtype: audiosystem (0x05)
Transmitted by Playback Device 1 to Audio System (4 to 5): CEC_MSG_GIVE_DEVICE_VENDOR_ID (0x8c)
Received from Audio System to all (5 to 15): CEC_MSG_DEVICE_VENDOR_ID (0x87):
	vendor-id: 41182 (0x0000a0de)
Transmitted by Playback Device 1 to Audio System (4 to 5): CEC_MSG_GIVE_OSD_NAME (0x46)
Received from Audio System to Playback Device 1 (5 to 4): CEC_MSG_SET_OSD_NAME (0x47):
	name: HTR-2071
Transmitted by Playback Device 1 to Audio System (4 to 5): CEC_MSG_GET_MENU_LANGUAGE (0x91)
Received from Audio System to Playback Device 1 (5 to 4): CEC_MSG_FEATURE_ABORT (0x00):
	abort-msg: 145 (0x91)
	reason: unrecognized-op (0x00)
Transmitted by Playback Device 1 to Audio System (4 to 5): CEC_MSG_GIVE_DEVICE_POWER_STATUS (0x8f)
Received from Audio System to Playback Device 1 (5 to 4): CEC_MSG_REPORT_POWER_STATUS (0x90):
	pwr-state: on (0x00)

Linux version 4.19.0-041900rc7-generic (root@udoo-UDOO-x86) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #201810071631+cec SMP Tue Oct 9 17:36:11 CEST 2018
seco_cec: loading out-of-tree module taints kernel.
seco_cec: module verification failed: signature and/or required key missing - tainting kernel
secocec CEC00001:00: irq-gpio is bound to IRQ 119
secocec CEC00001:00: IRQ detected at 119
secocec CEC00001:00: IR enabled
rc rc0: lirc_dev: driver secocec registered at minor = 0, scancode receiver, no transmitter
secocec CEC00001:00: Device registered
secocec CEC00001:00: Device enabled
secocec CEC00001:00: Device disabled
secocec CEC00001:00: Device enabled
secocec CEC00001:00: Device disabled
secocec CEC00001:00: Device enabled
secocec CEC00001:00: Device disabled
secocec CEC00001:00: Device enabled
cec-CEC00001:00: physical address: 2.1.0.0, claim 1 logical addresses
cec-CEC00001:00: config: la 1 pa 2.1.0.0
cec-CEC00001:00: physical address: 2.1.0.0, claim 1 logical addresses
cec-CEC00001:00: config: la 1 pa 2.1.0.0
cec-CEC00001:00: physical address: 2.1.0.0, claim 1 logical addresses
cec-CEC00001:00: config: la 4 pa 2.1.0.0
cec-CEC00001:00: cec_transmit_msg_fh: invalid poll message
cec-CEC00001:00: cec_transmit_msg_fh: can't reply to poll msg
cec-CEC00001:00: cec_transmit_msg_fh: invalid length 0
cec-CEC00001:00: cec_transmit_msg_fh: invalid length 17
cec-CEC00001:00: cec_transmit_msg_fh: can't reply to poll msg
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: physical address: 2.1.0.0, claim 1 logical addresses
cec-CEC00001:00: config: la 1 pa 2.1.0.0
cec-CEC00001:00: physical address: 2.1.0.0, claim 1 logical addresses
cec-CEC00001:00: config: la 1 pa 2.1.0.0
cec-CEC00001:00: physical address: 2.1.0.0, claim 1 logical addresses
cec-CEC00001:00: config: la 4 pa 2.1.0.0
cec-CEC00001:00: cec_transmit_msg_fh: invalid poll message
cec-CEC00001:00: cec_transmit_msg_fh: can't reply to poll msg
cec-CEC00001:00: cec_transmit_msg_fh: invalid length 0
cec-CEC00001:00: cec_transmit_msg_fh: invalid length 17
cec-CEC00001:00: cec_transmit_msg_fh: can't reply to poll msg
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: cec_s_mode: monitor modes require NO_INITIATOR
cec-CEC00001:00: cec_s_mode: MONITOR_ALL not supported
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: cec_transmit_msg_fh: transmit queue full
cec-CEC00001:00: reported physical address 0.0.0.0 for logical address 0
cec-CEC00001:00: reported physical address 2.0.0.0 for logical address 5