Skip to contentSkip to conversation

CEC drivers for iMX6 and TDA9950

RFC PATCH New Russell King - ARM Linux 5 participants 21 messages Aug 12, 2016 – Aug 31, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover CEC drivers for iMX6 and TDA9950

This series adds CEC drivers for the dw-hdmi and TDA9950 devices.

dw-hdmi integrates a CEC engine in the same device as the video and audio blocks, and so shares the IO space and IRQ with the main video driver.

The TDA9950 is not only a separate CEC device in its own right, but can also be found on the TDA998x family of HDMI encoders as a separate I2C device from the main TDA998x device.

The drivers are placed along-side their HDMI encoder drivers to keep the code for these drivers nearby. However, if there's a better location (eg, a CEC drivers subdirectory) then that would probably be a better location for these.

Both sets of drivers rely on the hdmi-notifier code, hence why they're part of the same patch series.

 drivers/gpu/drm/bridge/Kconfig            |   8 +
 drivers/gpu/drm/bridge/Makefile           |   1 +
 drivers/gpu/drm/bridge/dw-hdmi-cec.c      | 344 ++++++++++++++++++++
 drivers/gpu/drm/bridge/dw-hdmi.c          |  73 ++++-
 drivers/gpu/drm/bridge/dw-hdmi.h          |  45 ---
 drivers/gpu/drm/i2c/Kconfig               |   5 +
 drivers/gpu/drm/i2c/Makefile              |   1 +
 drivers/gpu/drm/i2c/tda9950.c             | 514 ++++++++++++++++++++++++++++++
 drivers/video/Kconfig                     |   3 +
 drivers/video/Makefile                    |   1 +
 drivers/video/hdmi-notifier.c             |  61 ++++
 include/linux/hdmi-notifier.h             |  44 +++
 include/linux/platform_data/dw_hdmi-cec.h |  16 +
 include/linux/platform_data/tda9950.h     |  15 +
 14 files changed, 1075 insertions(+), 56 deletions(-)
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#1 lore raw

RFC PATCH 1/5 video: add HDMI state notifier support

Add support for HDMI hotplug and EDID notifiers, which is used to convey information from HDMI drivers to their CEC and audio counterparts.

---
 drivers/video/Kconfig         |  3 +++
 drivers/video/Makefile        |  1 +
 drivers/video/hdmi-notifier.c | 61 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/hdmi-notifier.h | 44 +++++++++++++++++++++++++++++++
 4 files changed, 109 insertions(+)
 create mode 100644 drivers/video/hdmi-notifier.c
 create mode 100644 include/linux/hdmi-notifier.h
drivers/video/Kconfig +3 -0
index 3c20af999893..1ee7b9f9bb25 100644
@@ -36,6 +36,9 @@ config VIDEOMODE_HELPERS
 config HDMI
 	bool
 
+config HDMI_NOTIFIERS
+	bool
+
 if VT
 	source "drivers/video/console/Kconfig"
 endif
drivers/video/Makefile +1 -0
index 9ad3c17d6456..65f564906fb4 100644
@@ -1,5 +1,6 @@
 obj-$(CONFIG_VGASTATE)            += vgastate.o
 obj-$(CONFIG_HDMI)                += hdmi.o
+obj-$(CONFIG_HDMI_NOTIFIERS)      += hdmi-notifier.o
 
 obj-$(CONFIG_VT)		  += console/
 obj-$(CONFIG_LOGO)		  += logo/
drivers/video/hdmi-notifier.c new file +61 -0

61 lines not on this page · raw message

include/linux/hdmi-notifier.h new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.1.0
Acked-by on v1 1/5
#2 lore raw

Re: [PATCH RFC 1/5] video: add HDMI state notifier support

Quoted 4 lines · Russell King

Add support for HDMI hotplug and EDID notifiers, which is used to convey information from HDMI drivers to their CEC and audio counterparts.

I still don't really like the void *, but not enough to block this, so:

Regards,

Hans

Quoted 153 lines
---
 drivers/video/Kconfig         |  3 +++
 drivers/video/Makefile        |  1 +
 drivers/video/hdmi-notifier.c | 61 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/hdmi-notifier.h | 44 +++++++++++++++++++++++++++++++
 4 files changed, 109 insertions(+)
 create mode 100644 drivers/video/hdmi-notifier.c
 create mode 100644 include/linux/hdmi-notifier.h
drivers/video/Kconfig +3 -0
index 3c20af999893..1ee7b9f9bb25 100644
@@ -36,6 +36,9 @@ config VIDEOMODE_HELPERS
 config HDMI
 	bool
 
+config HDMI_NOTIFIERS
+	bool
+
 if VT
 	source "drivers/video/console/Kconfig"
 endif
drivers/video/Makefile +1 -0
index 9ad3c17d6456..65f564906fb4 100644
@@ -1,5 +1,6 @@
 obj-$(CONFIG_VGASTATE)            += vgastate.o
 obj-$(CONFIG_HDMI)                += hdmi.o
+obj-$(CONFIG_HDMI_NOTIFIERS)      += hdmi-notifier.o
 
 obj-$(CONFIG_VT)		  += console/
 obj-$(CONFIG_LOGO)		  += logo/
drivers/video/hdmi-notifier.c new file +61 -0
new file mode 100644
index 000000000000..f3b16552b0fe
@@ -0,0 +1,61 @@
+#include <linux/export.h>
+#include <linux/hdmi-notifier.h>
+#include <linux/notifier.h>
+#include <linux/string.h>
+
+static BLOCKING_NOTIFIER_HEAD(hdmi_notifier);
+
+int hdmi_register_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&hdmi_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(hdmi_register_notifier);
+
+int hdmi_unregister_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&hdmi_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(hdmi_unregister_notifier);
+
+void hdmi_event_connect(struct device *dev)
+{
+	struct hdmi_event_base base;
+
+	base.source = dev;
+
+	blocking_notifier_call_chain(&hdmi_notifier, HDMI_CONNECTED, &base);
+}
+EXPORT_SYMBOL_GPL(hdmi_event_connect);
+
+void hdmi_event_disconnect(struct device *dev)
+{
+	struct hdmi_event_base base;
+
+	base.source = dev;
+
+	blocking_notifier_call_chain(&hdmi_notifier, HDMI_DISCONNECTED, &base);
+}
+EXPORT_SYMBOL_GPL(hdmi_event_disconnect);
+
+void hdmi_event_new_edid(struct device *dev, const void *edid, size_t size)
+{
+	struct hdmi_event_new_edid new_edid;
+
+	new_edid.base.source = dev;
+	new_edid.edid = edid;
+	new_edid.size = size;
+
+	blocking_notifier_call_chain(&hdmi_notifier, HDMI_NEW_EDID, &new_edid);
+}
+EXPORT_SYMBOL_GPL(hdmi_event_new_edid);
+
+void hdmi_event_new_eld(struct device *dev, const u8 eld[128])
+{
+	struct hdmi_event_new_eld new_eld;
+
+	new_eld.base.source = dev;
+	memcpy(new_eld.eld, eld, sizeof(new_eld.eld));
+
+	blocking_notifier_call_chain(&hdmi_notifier, HDMI_NEW_ELD, &new_eld);
+}
+EXPORT_SYMBOL_GPL(hdmi_event_new_eld);
include/linux/hdmi-notifier.h new file +44 -0
new file mode 100644
index 000000000000..5fb710e5d68a
@@ -0,0 +1,44 @@
+#ifndef LINUX_HDMI_NOTIFIER_H
+#define LINUX_HDMI_NOTIFIER_H
+
+#include <linux/types.h>
+
+enum {
+	HDMI_CONNECTED,
+	HDMI_DISCONNECTED,
+	HDMI_NEW_EDID,
+	HDMI_NEW_ELD,
+};
+
+struct hdmi_event_base {
+	struct device *source;
+};
+
+struct hdmi_event_new_edid {
+	struct hdmi_event_base base;
+	const void *edid;
+	size_t size;
+};
+
+struct hdmi_event_new_eld {
+	struct hdmi_event_base base;
+	unsigned char eld[128];
+};
+
+union hdmi_event {
+	struct hdmi_event_base base;
+	struct hdmi_event_new_edid edid;
+	struct hdmi_event_new_eld eld;
+};
+
+struct notifier_block;
+
+int hdmi_register_notifier(struct notifier_block *nb);
+int hdmi_unregister_notifier(struct notifier_block *nb);
+
+void hdmi_event_connect(struct device *dev);
+void hdmi_event_disconnect(struct device *dev);
+void hdmi_event_new_edid(struct device *dev, const void *edid, size_t size);
+void hdmi_event_new_eld(struct device *dev, const u8 eld[128]);
+
+#endif
#3 lore raw

RFC PATCH 2/5 drm/bridge: dw_hdmi: remove CEC engine register definitions

In reply to Russell King - ARM Linux

We don't need the CEC engine register definitions, so let's remove them.

---
 drivers/gpu/drm/bridge/dw-hdmi.h | 45 ----------------------------------------
 1 file changed, 45 deletions(-)
drivers/gpu/drm/bridge/dw-hdmi.h +0 -45
index fc9a560429d6..26d6845efad6 100644
@@ -478,51 +478,6 @@
 #define HDMI_A_PRESETUP                         0x501A
 #define HDMI_A_SRM_BASE                         0x5020
 
-/* CEC Engine Registers */
-#define HDMI_CEC_CTRL                           0x7D00
-#define HDMI_CEC_STAT                           0x7D01
-#define HDMI_CEC_MASK                           0x7D02
-#define HDMI_CEC_POLARITY                       0x7D03
-#define HDMI_CEC_INT                            0x7D04
-#define HDMI_CEC_ADDR_L                         0x7D05
-#define HDMI_CEC_ADDR_H                         0x7D06
-#define HDMI_CEC_TX_CNT                         0x7D07
-#define HDMI_CEC_RX_CNT                         0x7D08
-#define HDMI_CEC_TX_DATA0                       0x7D10
-#define HDMI_CEC_TX_DATA1                       0x7D11
-#define HDMI_CEC_TX_DATA2                       0x7D12
-#define HDMI_CEC_TX_DATA3                       0x7D13
-#define HDMI_CEC_TX_DATA4                       0x7D14
-#define HDMI_CEC_TX_DATA5                       0x7D15
-#define HDMI_CEC_TX_DATA6                       0x7D16
-#define HDMI_CEC_TX_DATA7                       0x7D17
-#define HDMI_CEC_TX_DATA8                       0x7D18
-#define HDMI_CEC_TX_DATA9                       0x7D19
-#define HDMI_CEC_TX_DATA10                      0x7D1a
-#define HDMI_CEC_TX_DATA11                      0x7D1b
-#define HDMI_CEC_TX_DATA12                      0x7D1c
-#define HDMI_CEC_TX_DATA13                      0x7D1d
-#define HDMI_CEC_TX_DATA14                      0x7D1e
-#define HDMI_CEC_TX_DATA15                      0x7D1f
-#define HDMI_CEC_RX_DATA0                       0x7D20
-#define HDMI_CEC_RX_DATA1                       0x7D21
-#define HDMI_CEC_RX_DATA2                       0x7D22
-#define HDMI_CEC_RX_DATA3                       0x7D23
-#define HDMI_CEC_RX_DATA4                       0x7D24
-#define HDMI_CEC_RX_DATA5                       0x7D25
-#define HDMI_CEC_RX_DATA6                       0x7D26
-#define HDMI_CEC_RX_DATA7                       0x7D27
-#define HDMI_CEC_RX_DATA8                       0x7D28
-#define HDMI_CEC_RX_DATA9                       0x7D29
-#define HDMI_CEC_RX_DATA10                      0x7D2a
-#define HDMI_CEC_RX_DATA11                      0x7D2b
-#define HDMI_CEC_RX_DATA12                      0x7D2c
-#define HDMI_CEC_RX_DATA13                      0x7D2d
-#define HDMI_CEC_RX_DATA14                      0x7D2e
-#define HDMI_CEC_RX_DATA15                      0x7D2f
-#define HDMI_CEC_LOCK                           0x7D30
-#define HDMI_CEC_WKUPCTRL                       0x7D31
-
 /* I2C Master Registers (E-DDC) */
 #define HDMI_I2CM_SLAVE                         0x7E00
 #define HDMI_I2CM_ADDRESS                       0x7E01
Signature · 1 line
2.1.0
#4 lore raw

RFC PATCH 3/5 drm/bridge: dw_hdmi: add HDMI notifier support

In reply to Russell King - ARM Linux

Add HDMI notifiers to the HDMI bridge driver.

---
 drivers/gpu/drm/bridge/Kconfig   | 1 +
 drivers/gpu/drm/bridge/dw-hdmi.c | 9 +++++++++
 2 files changed, 10 insertions(+)
drivers/gpu/drm/bridge/Kconfig +1 -0
index 8f7423f18da5..6d97d9f2b164 100644
@@ -20,6 +20,7 @@ config DRM_ANALOGIX_ANX78XX
 config DRM_DW_HDMI
 	tristate
 	select DRM_KMS_HELPER
+	select HDMI_NOTIFIERS
 
 config DRM_DW_HDMI_AHB_AUDIO
 	tristate "Synopsis Designware AHB Audio interface"
drivers/gpu/drm/bridge/dw-hdmi.c +9 -0
index c9d941283d30..cb6e03efbebf 100644
@@ -16,6 +16,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/hdmi.h>
+#include <linux/hdmi-notifier.h>
 #include <linux/mutex.h>
 #include <linux/of_device.h>
 #include <linux/spinlock.h>
@@ -1447,9 +1448,11 @@ static int dw_hdmi_connector_get_modes(struct drm_connector *connector)
 		hdmi->sink_is_hdmi = drm_detect_hdmi_monitor(edid);
 		hdmi->sink_has_audio = drm_detect_monitor_audio(edid);
 		drm_mode_connector_update_edid_property(connector, edid);
+		hdmi_event_new_edid(hdmi->dev, edid, 0);
 		ret = drm_add_edid_modes(connector, edid);
 		/* Store the ELD */
 		drm_edid_to_eld(connector, edid);
+		hdmi_event_new_eld(hdmi->dev, connector->eld);
 		kfree(edid);
 	} else {
 		dev_dbg(hdmi->dev, "failed to get edid\n");
@@ -1601,6 +1604,12 @@ static irqreturn_t dw_hdmi_irq(int irq, void *dev_id)
 			dw_hdmi_update_phy_mask(hdmi);
 		}
 		mutex_unlock(&hdmi->mutex);
+
+		if ((phy_stat & (HDMI_PHY_RX_SENSE | HDMI_PHY_HPD)) == 0)
+			hdmi_event_disconnect(hdmi->dev);
+		else if ((phy_stat & (HDMI_PHY_RX_SENSE | HDMI_PHY_HPD)) ==
+			 (HDMI_IH_PHY_STAT0_RX_SENSE | HDMI_PHY_HPD))
+			hdmi_event_connect(hdmi->dev);
 	}
 
 	if (intr_stat & HDMI_IH_PHY_STAT0_HPD) {
Signature · 1 line
2.1.0
#5 lore raw

RFC PATCH 4/5 drm/bridge: add dw-hdmi cec driver using Hans Verkil's CEC code

In reply to Russell King - ARM Linux

Add a CEC driver for the dw-hdmi hardware using Hans Verkil's CEC implementation.

---
 drivers/gpu/drm/bridge/Kconfig            |   7 +
 drivers/gpu/drm/bridge/Makefile           |   1 +
 drivers/gpu/drm/bridge/dw-hdmi-cec.c      | 344 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/bridge/dw-hdmi.c          |  64 +++++-
 include/linux/platform_data/dw_hdmi-cec.h |  16 ++
 5 files changed, 421 insertions(+), 11 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/dw-hdmi-cec.c
 create mode 100644 include/linux/platform_data/dw_hdmi-cec.h
drivers/gpu/drm/bridge/Kconfig +7 -0
index 6d97d9f2b164..3ad19d16f4ca 100644
@@ -33,6 +33,13 @@ config DRM_DW_HDMI_AHB_AUDIO
 	  Designware HDMI block.  This is used in conjunction with
 	  the i.MX6 HDMI driver.
 
+config DRM_DW_HDMI_CEC
+	tristate "Synopsis Designware CEC interface"
+	depends on DRM_DW_HDMI && MEDIA_CEC
+	help
+	  Support the CE interface which is part of the Synopsis
+	  Designware HDMI block.
+
 config DRM_NXP_PTN3460
 	tristate "NXP PTN3460 DP/LVDS bridge"
 	depends on OF
drivers/gpu/drm/bridge/Makefile +1 -0
index 96b13b30e6ab..4869441d35f4 100644
@@ -3,6 +3,7 @@ ccflags-y := -Iinclude/drm
 obj-$(CONFIG_DRM_ANALOGIX_ANX78XX) += analogix-anx78xx.o
 obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
 obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
+obj-$(CONFIG_DRM_DW_HDMI_CEC) += dw-hdmi-cec.o
 obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
 obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
 obj-$(CONFIG_DRM_ANALOGIX_DP) += analogix/
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +344 -0

344 lines not on this page · raw message

drivers/gpu/drm/bridge/dw-hdmi.c +53 -11

139 lines not on this page · raw message

include/linux/platform_data/dw_hdmi-cec.h new file +16 -0
new file mode 100644
index 000000000000..5ff40cc237a8
@@ -0,0 +1,16 @@
+#ifndef DW_HDMI_CEC_H
+#define DW_HDMI_CEC_H
+
+struct dw_hdmi_cec_ops {
+	void (*enable)(void *);
+	void (*disable)(void *);
+};
+
+struct dw_hdmi_cec_data {
+	void __iomem *base;
+	int irq;
+	const struct dw_hdmi_cec_ops *ops;
+	void *ops_data;
+};
+
+#endif
Signature · 1 line
2.1.0
#6 lore raw

Re: [PATCH RFC 4/5] drm/bridge: add dw-hdmi cec driver using Hans Verkil's CEC code

Quoted 1 line · Russell King

Add a CEC driver for the dw-hdmi hardware using Hans Verkil's CEC

That's Verkuil :-)

BTW, since cec is part of the media subsystem please include linux-media for the next round.

Regards,

Hans

#7 lore raw

Re: [PATCH RFC 4/5] drm/bridge: add dw-hdmi cec driver using Hans Verkil's CEC code

Quoted 4 lines · Hans Verkuil
Quoted 1 line · Russell King

Add a CEC driver for the dw-hdmi hardware using Hans Verkil's CEC

That's Verkuil :-)

Oops, sorry about that.

Quoted 2 lines

BTW, since cec is part of the media subsystem please include linux-media for the next round.

I can't guarantee that, I'm quite forgetful.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#8 lore raw

Re: [PATCH RFC 4/5] drm/bridge: add dw-hdmi cec driver using Hans Verkil's CEC code

In reply to Russell King

Hi Russell,

Quoted 14 lines · Russell King

Add a CEC driver for the dw-hdmi hardware using Hans Verkil's CEC implementation.

---
 drivers/gpu/drm/bridge/Kconfig            |   7 +
 drivers/gpu/drm/bridge/Makefile           |   1 +
 drivers/gpu/drm/bridge/dw-hdmi-cec.c      | 344 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/bridge/dw-hdmi.c          |  64 +++++-
 include/linux/platform_data/dw_hdmi-cec.h |  16 ++
 5 files changed, 421 insertions(+), 11 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/dw-hdmi-cec.c
 create mode 100644 include/linux/platform_data/dw_hdmi-cec.h

<snip>

Quoted 27 lines
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +27 -0
+static unsigned int parse_hdmi_addr(const struct edid *edid)
+{
+	if (!edid || edid->extensions == 0)
+		return (u16)~0;
+
+	return cec_get_edid_phys_addr((u8 *)edid,
+				EDID_LENGTH * (edid->extensions + 1), NULL);
+}
+
+static int dw_hdmi_cec_notify(struct notifier_block *nb, unsigned long event,
+			      void *data)
+{
+	struct dw_hdmi_cec *cec = container_of(nb, struct dw_hdmi_cec, nb);
+	union hdmi_event *event_block = data;
+	unsigned int phys;
+
+	dev_info(event_block->base.source, "event %lu\n", event);
+
+	if (event_block->base.source != cec->adap->devnode.parent)
+		return NOTIFY_OK;
+
+	switch (event) {
+	case HDMI_CONNECTED:
+		break;
+
+	case HDMI_DISCONNECTED:
+		cec_s_phys_addr(cec->adap, CEC_PHYS_ADDR_INVALID, false);

drivers/gpu/drm/bridge/dw-hdmi-cec.c line 243

Quoted 10 lines
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +10 -0
+		break;
+
+	case HDMI_NEW_EDID:
+		phys = parse_hdmi_addr(event_block->edid.edid);
+		cec_s_phys_addr(cec->adap, phys, false);
+		break;
+	}
+
+	return NOTIFY_OK;
+}

Wouldn't it make a lot of sense to integrate this into the cec framework?

All you need is to pass an hdmi_notifier_dev as argument to cec_allocate_adapter() and you can integrate this.

If you are OK with that, then I can make patches for that.

Regards,

Hans

#9 lore raw

Re: [PATCH RFC 4/5] drm/bridge: add dw-hdmi cec driver using Hans Verkil's CEC code

Quoted 60 lines · Hans Verkuil

Hi Russell,

Quoted 14 lines · Russell King

Add a CEC driver for the dw-hdmi hardware using Hans Verkil's CEC implementation.

---
 drivers/gpu/drm/bridge/Kconfig            |   7 +
 drivers/gpu/drm/bridge/Makefile           |   1 +
 drivers/gpu/drm/bridge/dw-hdmi-cec.c      | 344 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/bridge/dw-hdmi.c          |  64 +++++-
 include/linux/platform_data/dw_hdmi-cec.h |  16 ++
 5 files changed, 421 insertions(+), 11 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/dw-hdmi-cec.c
 create mode 100644 include/linux/platform_data/dw_hdmi-cec.h

<snip>

Quoted 27 lines
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +27 -0
+static unsigned int parse_hdmi_addr(const struct edid *edid)
+{
+	if (!edid || edid->extensions == 0)
+		return (u16)~0;
+
+	return cec_get_edid_phys_addr((u8 *)edid,
+				EDID_LENGTH * (edid->extensions + 1), NULL);
+}
+
+static int dw_hdmi_cec_notify(struct notifier_block *nb, unsigned long event,
+			      void *data)
+{
+	struct dw_hdmi_cec *cec = container_of(nb, struct dw_hdmi_cec, nb);
+	union hdmi_event *event_block = data;
+	unsigned int phys;
+
+	dev_info(event_block->base.source, "event %lu\n", event);
+
+	if (event_block->base.source != cec->adap->devnode.parent)
+		return NOTIFY_OK;
+
+	switch (event) {
+	case HDMI_CONNECTED:
+		break;
+
+	case HDMI_DISCONNECTED:
+		cec_s_phys_addr(cec->adap, CEC_PHYS_ADDR_INVALID, false);

drivers/gpu/drm/bridge/dw-hdmi-cec.c line 243

Quoted 10 lines
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +10 -0
+		break;
+
+	case HDMI_NEW_EDID:
+		phys = parse_hdmi_addr(event_block->edid.edid);
+		cec_s_phys_addr(cec->adap, phys, false);
+		break;
+	}
+
+	return NOTIFY_OK;
+}

Wouldn't it make a lot of sense to integrate this into the cec framework?

Quoted 4 lines

All you need is to pass an hdmi_notifier_dev as argument to cec_allocate_adapter() and you can integrate this.

If you are OK with that, then I can make patches for that.

It's not just about CEC. It's also used for passing information between the video and audio parts, so tying this into CEC is wrong.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#10 lore raw

Re: [PATCH RFC 4/5] drm/bridge: add dw-hdmi cec driver using Hans Verkil's CEC code

Quoted 61 lines · Russell King - ARM Linux
Quoted 60 lines · Hans Verkuil

Hi Russell,

Quoted 14 lines · Russell King

Add a CEC driver for the dw-hdmi hardware using Hans Verkil's CEC implementation.

---
 drivers/gpu/drm/bridge/Kconfig            |   7 +
 drivers/gpu/drm/bridge/Makefile           |   1 +
 drivers/gpu/drm/bridge/dw-hdmi-cec.c      | 344 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/bridge/dw-hdmi.c          |  64 +++++-
 include/linux/platform_data/dw_hdmi-cec.h |  16 ++
 5 files changed, 421 insertions(+), 11 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/dw-hdmi-cec.c
 create mode 100644 include/linux/platform_data/dw_hdmi-cec.h

<snip>

Quoted 27 lines
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +27 -0
+static unsigned int parse_hdmi_addr(const struct edid *edid)
+{
+	if (!edid || edid->extensions == 0)
+		return (u16)~0;
+
+	return cec_get_edid_phys_addr((u8 *)edid,
+				EDID_LENGTH * (edid->extensions + 1), NULL);
+}
+
+static int dw_hdmi_cec_notify(struct notifier_block *nb, unsigned long event,
+			      void *data)
+{
+	struct dw_hdmi_cec *cec = container_of(nb, struct dw_hdmi_cec, nb);
+	union hdmi_event *event_block = data;
+	unsigned int phys;
+
+	dev_info(event_block->base.source, "event %lu\n", event);
+
+	if (event_block->base.source != cec->adap->devnode.parent)
+		return NOTIFY_OK;
+
+	switch (event) {
+	case HDMI_CONNECTED:
+		break;
+
+	case HDMI_DISCONNECTED:
+		cec_s_phys_addr(cec->adap, CEC_PHYS_ADDR_INVALID, false);

drivers/gpu/drm/bridge/dw-hdmi-cec.c line 243

Quoted 10 lines
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +10 -0
+		break;
+
+	case HDMI_NEW_EDID:
+		phys = parse_hdmi_addr(event_block->edid.edid);
+		cec_s_phys_addr(cec->adap, phys, false);
+		break;
+	}
+
+	return NOTIFY_OK;
+}

Wouldn't it make a lot of sense to integrate this into the cec framework?

Quoted 7 lines
Quoted 4 lines

All you need is to pass an hdmi_notifier_dev as argument to cec_allocate_adapter() and you can integrate this.

If you are OK with that, then I can make patches for that.

It's not just about CEC. It's also used for passing information between the video and audio parts, so tying this into CEC is wrong.

I'm not saying that the hdmi notifier should be integrated, just that the CEC core can register itself as a notifier and handle cec_s_phys_addr.

Regards,

Hans

#11 lore raw

Re: [PATCH RFC 4/5] drm/bridge: add dw-hdmi cec driver using Hans Verkil's CEC code

Quoted 67 lines · Hans Verkuil
Quoted 64 lines · Russell King - ARM Linux
Quoted 63 lines · Hans Verkuil

Hi Russell,

Quoted 14 lines · Russell King

Add a CEC driver for the dw-hdmi hardware using Hans Verkil's CEC implementation.

---
 drivers/gpu/drm/bridge/Kconfig            |   7 +
 drivers/gpu/drm/bridge/Makefile           |   1 +
 drivers/gpu/drm/bridge/dw-hdmi-cec.c      | 344 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/bridge/dw-hdmi.c          |  64 +++++-
 include/linux/platform_data/dw_hdmi-cec.h |  16 ++
 5 files changed, 421 insertions(+), 11 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/dw-hdmi-cec.c
 create mode 100644 include/linux/platform_data/dw_hdmi-cec.h

<snip>

Quoted 27 lines
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +27 -0
+static unsigned int parse_hdmi_addr(const struct edid *edid)
+{
+	if (!edid || edid->extensions == 0)
+		return (u16)~0;
+
+	return cec_get_edid_phys_addr((u8 *)edid,
+				EDID_LENGTH * (edid->extensions + 1), NULL);
+}
+
+static int dw_hdmi_cec_notify(struct notifier_block *nb, unsigned long event,
+			      void *data)
+{
+	struct dw_hdmi_cec *cec = container_of(nb, struct dw_hdmi_cec, nb);
+	union hdmi_event *event_block = data;
+	unsigned int phys;
+
+	dev_info(event_block->base.source, "event %lu\n", event);
+
+	if (event_block->base.source != cec->adap->devnode.parent)
+		return NOTIFY_OK;
+
+	switch (event) {
+	case HDMI_CONNECTED:
+		break;
+
+	case HDMI_DISCONNECTED:
+		cec_s_phys_addr(cec->adap, CEC_PHYS_ADDR_INVALID, false);

drivers/gpu/drm/bridge/dw-hdmi-cec.c line 243

Quoted 10 lines
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +10 -0
+		break;
+
+	case HDMI_NEW_EDID:
+		phys = parse_hdmi_addr(event_block->edid.edid);
+		cec_s_phys_addr(cec->adap, phys, false);
+		break;
+	}
+
+	return NOTIFY_OK;
+}

Wouldn't it make a lot of sense to integrate this into the cec framework?

All you need is to pass an hdmi_notifier_dev as argument to cec_allocate_adapter() and you can integrate this.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

If you are OK with that, then I can make patches for that.

It's not just about CEC. It's also used for passing information between the video and audio parts, so tying this into CEC is wrong.

I'm not saying that the hdmi notifier should be integrated, just that the CEC core can register itself as a notifier and handle cec_s_phys_addr.

Yes, that would decrease the amount of code duplication.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#12 lore raw

Re: [PATCH RFC 4/5] drm/bridge: add dw-hdmi cec driver using Hans Verkil's CEC code

In reply to Russell King

Hi Russell,

Quoted 8 lines · Russell King
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +8 -0
+	ret = devm_request_threaded_irq(&pdev->dev, cec->irq,
+					dw_hdmi_cec_hardirq,
+					dw_hdmi_cec_thread, IRQF_SHARED,
+					DEV_NAME, cec->adap);
+	if (ret < 0)
+		return ret;
+
+	ret = cec_register_adapter(cec->adap);

drivers/gpu/drm/bridge/dw-hdmi-cec.c line 316

Quoted 10 lines
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +10 -0
+	if (ret < 0)
+		return ret;
+
+	/*
+	 * CEC documentation says we must not call cec_delete_adapter
+	 * after a successful call to cec_register_adapter().
+	 */
+	devm_remove_action(&pdev->dev, dw_hdmi_cec_del, cec);
+
+	hdmi_register_notifier(&cec->nb);

The notifier is registered here, but who provides CEC with the initial physical address? As I understand it, it only tells you when things change, not what the initial state is.

Regards,

Hans

#13 lore raw

Re: [PATCH RFC 4/5] drm/bridge: add dw-hdmi cec driver using Hans Verkil's CEC code

Quoted 17 lines · Hans Verkuil

Hi Russell,

Quoted 14 lines · Russell King
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +14 -0
+	ret = devm_request_threaded_irq(&pdev->dev, cec->irq,
+					dw_hdmi_cec_hardirq,
+					dw_hdmi_cec_thread, IRQF_SHARED,
+					DEV_NAME, cec->adap);
+	if (ret < 0)
+		return ret;
+
+	ret = cec_register_adapter(cec->adap);
+	if (ret < 0)
+		return ret;
+
+	/*
+	 * CEC documentation says we must not call cec_delete_adapter
+	 * after a successful call to cec_register_adapter().
Quoted 8 lines

drivers/gpu/drm/bridge/dw-hdmi-cec.c line 316

Quoted 4 lines
drivers/gpu/drm/bridge/dw-hdmi-cec.c new file +4 -0
+	 */
+	devm_remove_action(&pdev->dev, dw_hdmi_cec_del, cec);
+
+	hdmi_register_notifier(&cec->nb);

The notifier is registered here, but who provides CEC with the initial physical address? As I understand it, it only tells you when things change, not what the initial state is.

Correct, that's a short-coming of this. Solving that is not really an easy problem - the hdmi notifiers don't track the state (they aren't really aware of state themselves), nor do they track who the originator of the messages is (again, because they don't track state.)

Fixing that requires a much more complex solution - I don't think I've time to solve that (as illustrated by this reply taking over a week.)

So, we can either decide that we're not going to merge any CEC drivers and other HDMI audio drivers until we solve this problem, denying people the ability to use CEC, or we can merge what we have now and work on solving the problem later.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#14 lore raw

RFC PATCH 5/5 drm/i2c: add tda998x/tda9950 CEC driver

In reply to Russell King - ARM Linux

Add a CEC driver for the TDA9950, which is a stand-alone I2C CEC device. The TDA9950 contains a command processor which handles retransmissions and the low level bus protocol. The driver just has to read and write the messages, and handle error conditions.

---
 drivers/gpu/drm/i2c/Kconfig           |   5 +
 drivers/gpu/drm/i2c/Makefile          |   1 +
 drivers/gpu/drm/i2c/tda9950.c         | 514 ++++++++++++++++++++++++++++++++++
 include/linux/platform_data/tda9950.h |  15 +
 4 files changed, 535 insertions(+)
 create mode 100644 drivers/gpu/drm/i2c/tda9950.c
 create mode 100644 include/linux/platform_data/tda9950.h
drivers/gpu/drm/i2c/Kconfig +5 -0
index 22c7ed63a001..f4af13203993 100644
@@ -31,4 +31,9 @@ config DRM_I2C_NXP_TDA998X
 	help
 	  Support for NXP Semiconductors TDA998X HDMI encoders.
 
+config DRM_I2C_NXP_TDA9950
+	tristate "NXP Semiconductors TDA9950/TDA998X HDMI CEC"
+	depends on MEDIA_CEC
+	select HDMI_NOTIFIERS
+
 endmenu
drivers/gpu/drm/i2c/Makefile +1 -0
index 2c72eb584ab7..07bed58410e9 100644
@@ -10,3 +10,4 @@ obj-$(CONFIG_DRM_I2C_SIL164) += sil164.o
 
 tda998x-y := tda998x_drv.o
 obj-$(CONFIG_DRM_I2C_NXP_TDA998X) += tda998x.o
+obj-$(CONFIG_DRM_I2C_NXP_TDA9950) += tda9950.o
drivers/gpu/drm/i2c/tda9950.c new file +514 -0

514 lines not on this page · raw message

include/linux/platform_data/tda9950.h new file +15 -0
new file mode 100644
index 000000000000..08da9c989dad
@@ -0,0 +1,15 @@
+#ifndef LINUX_PLATFORM_DATA_TDA9950_H
+#define LINUX_PLATFORM_DATA_TDA9950_H
+
+struct device;
+
+struct tda9950_glue {
+	struct device *parent;
+	void *data;
+	int (*init)(void *);
+	void (*exit)(void *);
+	int (*open)(void *);
+	void (*release)(void *);
+};
+
+#endif
Signature · 1 line
2.1.0
#15 lore raw

Re: [PATCH RFC 5/5] drm/i2c: add tda998x/tda9950 CEC driver

Quoted 15 lines · Russell King

Add a CEC driver for the TDA9950, which is a stand-alone I2C CEC device. The TDA9950 contains a command processor which handles retransmissions and the low level bus protocol. The driver just has to read and write the messages, and handle error conditions.

---
 drivers/gpu/drm/i2c/Kconfig           |   5 +
 drivers/gpu/drm/i2c/Makefile          |   1 +
 drivers/gpu/drm/i2c/tda9950.c         | 514 ++++++++++++++++++++++++++++++++++
 include/linux/platform_data/tda9950.h |  15 +
 4 files changed, 535 insertions(+)
 create mode 100644 drivers/gpu/drm/i2c/tda9950.c
 create mode 100644 include/linux/platform_data/tda9950.h

<snip>

drivers/gpu/drm/i2c/tda9950.c line 217

Quoted 8 lines
drivers/gpu/drm/i2c/tda9950.c new file +8 -0
+static int tda9950_cec_adap_log_addr(struct cec_adapter *adap, u8 addr)
+{
+	struct tda9950_priv *priv = adap->priv;
+	u16 addresses;
+	u8 buf[2];
+
+	if (addr == CEC_LOG_ADDR_INVALID)
+		addresses = priv->addresses = BIT(15);

I saw this in patch 4/5 as well: why set bit 15? I would expect that this is just set to 0. And priv->addresses doesn't seem to be used anywhere.

Quoted 11 lines
drivers/gpu/drm/i2c/tda9950.c new file +11 -0
+	else
+		addresses = priv->addresses |= BIT(addr);
+
+	/* TDA9950 doesn't want address 15 set */
+	addr &= 0x7fff;
+	buf[0] = addresses >> 8;
+	buf[1] = addresses;
+
+	return tda9950_write_range(priv->client, REG_ACKH, buf, 2);
+}
+

<snip>

drivers/gpu/drm/i2c/tda9950.c line 310

Quoted 8 lines
drivers/gpu/drm/i2c/tda9950.c new file +8 -0
+static int tda9950_cec_adap_enable(struct cec_adapter *adap, bool enable)
+{
+	struct tda9950_priv *priv = adap->priv;
+
+	if (!enable) {
+		tda9950_release(priv);
+		return 0;
+	} else {

Nitpick: no need for 'else' here since the 'if' always returns.

drivers/gpu/drm/i2c/tda9950.c line 313

Quoted 3 lines
drivers/gpu/drm/i2c/tda9950.c new file +3 -0
+		return tda9950_open(priv);
+	}
+}

Regards,

Hans

#16 lore raw

Re: [PATCH RFC 5/5] drm/i2c: add tda998x/tda9950 CEC driver

Quoted 19 lines · Hans Verkuil
Quoted 15 lines · Russell King

Add a CEC driver for the TDA9950, which is a stand-alone I2C CEC device. The TDA9950 contains a command processor which handles retransmissions and the low level bus protocol. The driver just has to read and write the messages, and handle error conditions.

---

drivers/gpu/drm/i2c/Kconfig           |   5 +
drivers/gpu/drm/i2c/Makefile          |   1 +
drivers/gpu/drm/i2c/tda9950.c         | 514 ++++++++++++++++++++++++++++++++++
include/linux/platform_data/tda9950.h |  15 +
4 files changed, 535 insertions(+)

create mode 100644 drivers/gpu/drm/i2c/tda9950.c create mode 100644 include/linux/platform_data/tda9950.h

<snip>

Quoted 11 lines

drivers/gpu/drm/i2c/tda9950.c line 217

Quoted 8 lines
drivers/gpu/drm/i2c/tda9950.c new file +8 -0
+static int tda9950_cec_adap_log_addr(struct cec_adapter *adap, u8 addr)
+{
+	struct tda9950_priv *priv = adap->priv;
+	u16 addresses;
+	u8 buf[2];
+
+	if (addr == CEC_LOG_ADDR_INVALID)
+		addresses = priv->addresses = BIT(15);

I saw this in patch 4/5 as well: why set bit 15? I would expect that this is just set to 0. And priv->addresses doesn't seem to be used anywhere.

It's needed to be set so that the hardware receives messages sent to the broadcast (15) address.

Quoted 2 lines

drivers/gpu/drm/i2c/tda9950.c line 219

Quoted 2 lines
drivers/gpu/drm/i2c/tda9950.c new file +2 -0
+	else
+		addresses = priv->addresses |= BIT(addr);

For the second point, read this line, paying close attention to the |=.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#17 lore raw

Re: [PATCH RFC 5/5] drm/i2c: add tda998x/tda9950 CEC driver

In reply to Hans Verkuil
Quoted 19 lines · Hans Verkuil
Quoted 15 lines · Russell King

Add a CEC driver for the TDA9950, which is a stand-alone I2C CEC device. The TDA9950 contains a command processor which handles retransmissions and the low level bus protocol. The driver just has to read and write the messages, and handle error conditions.

---
 drivers/gpu/drm/i2c/Kconfig           |   5 +
 drivers/gpu/drm/i2c/Makefile          |   1 +
 drivers/gpu/drm/i2c/tda9950.c         | 514 ++++++++++++++++++++++++++++++++++
 include/linux/platform_data/tda9950.h |  15 +
 4 files changed, 535 insertions(+)
 create mode 100644 drivers/gpu/drm/i2c/tda9950.c
 create mode 100644 include/linux/platform_data/tda9950.h

<snip>

Quoted 11 lines

drivers/gpu/drm/i2c/tda9950.c line 217

Quoted 8 lines
drivers/gpu/drm/i2c/tda9950.c new file +8 -0
+static int tda9950_cec_adap_log_addr(struct cec_adapter *adap, u8 addr)
+{
+    struct tda9950_priv *priv = adap->priv;
+    u16 addresses;
+    u8 buf[2];
+
+    if (addr == CEC_LOG_ADDR_INVALID)
+        addresses = priv->addresses = BIT(15);

I saw this in patch 4/5 as well: why set bit 15? I would expect that this is just set to 0. And priv->addresses doesn't seem to be used anywhere.

Yeah, you are right, priv->addresses is used. I've been reviewing too many patches today.

The whole BIT(15) part remains weird. If log_addr is called with LOG_ADDR_INVALID as argument, then the intention is that no more messages are to be received (unless the hardware is in snooping mode). So there is no need to receive broadcast messages either.

That said, I now realize that if userspace wants to configure the CEC device as 'Unregistered', then adap_log_addr is never called, which would be required if the hardware has to enable support to receive broadcast messages.

In addition cec_received_msg should ignore received messages if log_addr_mask of struct cec_log_addrs is 0. I think it will just pass on messages right now, and that's not right.

I will look at this tomorrow when my brain isn't fried and do some more testing with 'Unregistered' scenarios.

Quoted 6 lines

drivers/gpu/drm/i2c/tda9950.c line 222

Quoted 6 lines
drivers/gpu/drm/i2c/tda9950.c new file +5 -0
+    else
+        addresses = priv->addresses |= BIT(addr);
+
+    /* TDA9950 doesn't want address 15 set */
+    addr &= 0x7fff;

Shouldn't this be 'addresses' instead of 'addr'? 'addr' makes no sense here.

And if so, then I still don't understand setting BIT(15), since that bit is removed by the &=.

Quoted 6 lines

drivers/gpu/drm/i2c/tda9950.c line 228

Quoted 6 lines
drivers/gpu/drm/i2c/tda9950.c new file +6 -0
+    buf[0] = addresses >> 8;
+    buf[1] = addresses;
+
+    return tda9950_write_range(priv->client, REG_ACKH, buf, 2);
+}
+

Regards,

Hans

#18 lore raw

Re: [PATCH RFC 5/5] drm/i2c: add tda998x/tda9950 CEC driver

Quoted 32 lines · Hans Verkuil
Quoted 19 lines · Hans Verkuil
Quoted 15 lines · Russell King

Add a CEC driver for the TDA9950, which is a stand-alone I2C CEC device. The TDA9950 contains a command processor which handles retransmissions and the low level bus protocol. The driver just has to read and write the messages, and handle error conditions.

---

drivers/gpu/drm/i2c/Kconfig           |   5 +
drivers/gpu/drm/i2c/Makefile          |   1 +
drivers/gpu/drm/i2c/tda9950.c         | 514 ++++++++++++++++++++++++++++++++++
include/linux/platform_data/tda9950.h |  15 +
4 files changed, 535 insertions(+)

create mode 100644 drivers/gpu/drm/i2c/tda9950.c create mode 100644 include/linux/platform_data/tda9950.h

<snip>

Quoted 11 lines

drivers/gpu/drm/i2c/tda9950.c line 217

Quoted 8 lines
drivers/gpu/drm/i2c/tda9950.c new file +8 -0
+static int tda9950_cec_adap_log_addr(struct cec_adapter *adap, u8 addr)
+{
+    struct tda9950_priv *priv = adap->priv;
+    u16 addresses;
+    u8 buf[2];
+
+    if (addr == CEC_LOG_ADDR_INVALID)
+        addresses = priv->addresses = BIT(15);

I saw this in patch 4/5 as well: why set bit 15? I would expect that this is just set to 0. And priv->addresses doesn't seem to be used anywhere.

Quoted 7 lines

Yeah, you are right, priv->addresses is used. I've been reviewing too many patches today.

The whole BIT(15) part remains weird. If log_addr is called with LOG_ADDR_INVALID as argument, then the intention is that no more messages are to be received (unless the hardware is in snooping mode). So there is no need to receive broadcast messages either.

What about hardware where you can't stop it receiving broadcast addresses? Should drivers manually check for this in their interrupt handler?

Quoted 4 lines

That said, I now realize that if userspace wants to configure the CEC device as 'Unregistered', then adap_log_addr is never called, which would be required if the hardware has to enable support to receive broadcast messages.

I don't see how that could possibly work. The CEC specification requires that we receive broadcast addressed messages so that (eg) the current source can be tracked. Being present on the bus, and participating as an active source requires the reception of broadcast messages so that you know when you stop being an active source.

Nothing (afaics) enables broadcast address reception in the kernel side, nor using cec-ctl in userspace.

Quoted 10 lines
Quoted 5 lines

drivers/gpu/drm/i2c/tda9950.c line 222

Quoted 5 lines
drivers/gpu/drm/i2c/tda9950.c new file +5 -0
+    else
+        addresses = priv->addresses |= BIT(addr);
+
+    /* TDA9950 doesn't want address 15 set */
+    addr &= 0x7fff;

Shouldn't this be 'addresses' instead of 'addr'? 'addr' makes no sense here.

And if so, then I still don't understand setting BIT(15), since that bit is removed by the &=.

You're right in this case, but for dw-hdmi, bit 15 must be set for broadcast messages to be received.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#19 lore raw

Re: [PATCH RFC 5/5] drm/i2c: add tda998x/tda9950 CEC driver

Quoted 57 lines · Russell King - ARM Linux
Quoted 32 lines · Hans Verkuil
Quoted 19 lines · Hans Verkuil
Quoted 15 lines · Russell King

Add a CEC driver for the TDA9950, which is a stand-alone I2C CEC device. The TDA9950 contains a command processor which handles retransmissions and the low level bus protocol. The driver just has to read and write the messages, and handle error conditions.

---

drivers/gpu/drm/i2c/Kconfig           |   5 +
drivers/gpu/drm/i2c/Makefile          |   1 +
drivers/gpu/drm/i2c/tda9950.c         | 514 ++++++++++++++++++++++++++++++++++
include/linux/platform_data/tda9950.h |  15 +
4 files changed, 535 insertions(+)

create mode 100644 drivers/gpu/drm/i2c/tda9950.c create mode 100644 include/linux/platform_data/tda9950.h

<snip>

Quoted 11 lines

drivers/gpu/drm/i2c/tda9950.c line 217

Quoted 8 lines
drivers/gpu/drm/i2c/tda9950.c new file +8 -0
+static int tda9950_cec_adap_log_addr(struct cec_adapter *adap, u8 addr)
+{
+    struct tda9950_priv *priv = adap->priv;
+    u16 addresses;
+    u8 buf[2];
+
+    if (addr == CEC_LOG_ADDR_INVALID)
+        addresses = priv->addresses = BIT(15);

I saw this in patch 4/5 as well: why set bit 15? I would expect that this is just set to 0. And priv->addresses doesn't seem to be used anywhere.

Quoted 7 lines

Yeah, you are right, priv->addresses is used. I've been reviewing too many patches today.

The whole BIT(15) part remains weird. If log_addr is called with LOG_ADDR_INVALID as argument, then the intention is that no more messages are to be received (unless the hardware is in snooping mode). So there is no need to receive broadcast messages either.

What about hardware where you can't stop it receiving broadcast addresses? Should drivers manually check for this in their interrupt handler?

Quoted 4 lines

That said, I now realize that if userspace wants to configure the CEC device as 'Unregistered', then adap_log_addr is never called, which would be required if the hardware has to enable support to receive broadcast messages.

I don't see how that could possibly work. The CEC specification requires that we receive broadcast addressed messages so that (eg) the current source can be tracked. Being present on the bus, and participating as an active source requires the reception of broadcast messages so that you know when you stop being an active source.

Quoted 2 lines

Nothing (afaics) enables broadcast address reception in the kernel side, nor using cec-ctl in userspace.

There are three possible 'states' of a CEC adapter w.r.t. logical addresses:

1) There is no physical address or no logical addresses have been set by the application (CEC_ADAP_S_LOG_ADDRS): in that case the device will not participate on the bus, it doesn't care about receiving messages let alone replying to them. The only exception is if the device can snoop messages, that is allowed even if CEC_ADAP_S_LOG_ADDRS is never called. That is ideal to have a 'neutral' observer of the bus that just listens but never participates. Not all hardware supports snooping, though.

2) CEC_ADAP_S_LOG_ADDRS is called and the device becomes an 'Unregistered' device (i.e. it gets logical address 15). In that case it should receive broadcast messages and be able to transmit messages.

3) CEC_ADAP_S_LOG_ADDRS is called and the device claims one or more logical addresses in the range 0-14. Then it can receive broadcast and directed messages, and of course transmit messages.

From the point of view of the hardware state 1 is selected if adap_log_addr is called with LOG_ADDR_INVALID. Some hardware might still receive broadcast messages (because they can't turn that off) and those should be filtered out by the CEC framework. But I think that doesn't happen, which would be a bug. I'll verify that tomorrow.

State 2 is a problem for hardware that has to enable support to receive broadcast messages since adap_log_addr is never called with LOG_ADDR_UNREGISTERED as argument. I missed that, since the hardware I tested with always accepts broadcast messages. I'll look into this tomorrow as well. It should be easy to fix.

State 3 works OK.

So for the dw-hdmi cec driver that means that for state 1 you set 'addresses' to 0, for state 2 you set it to BIT(15) and for state 3 you always OR with BIT(15). At least, as I understand your hardware.

BTW, if either the tda or dw-hdmi supports snooping mode, then I strongly recommend supporting that. It's great for debugging.

Regards,

Hans

Quoted 15 lines
Quoted 11 lines
Quoted 6 lines

drivers/gpu/drm/i2c/tda9950.c line 222

Quoted 6 lines
drivers/gpu/drm/i2c/tda9950.c new file +5 -0
+    else
+        addresses = priv->addresses |= BIT(addr);
+
+    /* TDA9950 doesn't want address 15 set */
+    addr &= 0x7fff;

Shouldn't this be 'addresses' instead of 'addr'? 'addr' makes no sense here.

And if so, then I still don't understand setting BIT(15), since that bit is removed by the &=.

You're right in this case, but for dw-hdmi, bit 15 must be set for broadcast messages to be received.

#20 lore raw

Re: [PATCH RFC 5/5] drm/i2c: add tda998x/tda9950 CEC driver

Quoted 30 lines · Hans Verkuil

There are three possible 'states' of a CEC adapter w.r.t. logical addresses:

1) There is no physical address or no logical addresses have been set by the application (CEC_ADAP_S_LOG_ADDRS): in that case the device will not participate on the bus, it doesn't care about receiving messages let alone replying to them. The only exception is if the device can snoop messages, that is allowed even if CEC_ADAP_S_LOG_ADDRS is never called. That is ideal to have a 'neutral' observer of the bus that just listens but never participates. Not all hardware supports snooping, though.

2) CEC_ADAP_S_LOG_ADDRS is called and the device becomes an 'Unregistered' device (i.e. it gets logical address 15). In that case it should receive broadcast messages and be able to transmit messages.

3) CEC_ADAP_S_LOG_ADDRS is called and the device claims one or more logical addresses in the range 0-14. Then it can receive broadcast and directed messages, and of course transmit messages.

From the point of view of the hardware state 1 is selected if adap_log_addr is called with LOG_ADDR_INVALID. Some hardware might still receive broadcast messages (because they can't turn that off) and those should be filtered out by the CEC framework. But I think that doesn't happen, which would be a bug. I'll verify that tomorrow.

State 2 is a problem for hardware that has to enable support to receive broadcast messages since adap_log_addr is never called with LOG_ADDR_UNREGISTERED as argument. I missed that, since the hardware I tested with always accepts broadcast messages. I'll look into this tomorrow as well. It should be easy to fix.

Quoted 5 lines

State 3 works OK.

So for the dw-hdmi cec driver that means that for state 1 you set 'addresses' to 0, for state 2 you set it to BIT(15) and for state 3 you always OR with BIT(15). At least, as I understand your hardware.

Thanks, I think that needs documenting in Documentation/cec.txt.

Quoted 2 lines

BTW, if either the tda or dw-hdmi supports snooping mode, then I strongly recommend supporting that. It's great for debugging.

Neither do.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.