All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv8 00/13] cec: improve notifier support, add connector info
@ 2019-06-24 16:03 ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media; +Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

This is a rework of Dariusz' v7 series:

https://www.spinics.net/lists/linux-media/msg151117.html

Rather than changing the existing CEC kAPI to allocate and
register CEC adapters I left it as-is. Instead new notifiers
functions are added to (un)register HDMI connector and CEC adapter
notifiers. These replace the current cec_notifier_get_conn and _put
functions.

For drivers that don't use notifiers the cec_s_conn_info function
was created so the connector info can be set directly as well.

This split in separate connector and CEC adapter functions is needed
since the notifier information is different between the two and this
makes it future proof since we will need to eventually support more
than one CEC adapter per HDMI connector.

By carefully designing these functions it is possible to convert
drivers to these new functions one-by-one, rather than as a painful
big-bang patch.

The plan is to merge the first three patches for kernel 5.3: these
patches provide the infrastructure needed by drm and cec drivers
to do the conversion during the 5.4 cycle, without requiring
patches that touch on multiple subsystems.

Once the conversion is done the new connector API can be exposed.
A patch documenting the new API is included as well, but it is
old and needs updating (the new CEC_CAP_CONNECTOR_INFO capability
isn't documented, and neither is the new 'have_connector_info'
field of the state changed event).

Various drivers have been converted as well as an example. These
are based on Dariusz' original series, but using the new notifier
functions.

Regards,

	Hans

Dariusz Marcinkiewicz (9):
  cec: add struct cec_connector_info support
  cec: expose the new connector info API
  drm_dp_cec: add connector info support.
  drm/i915/intel_hdmi: use cec_notifier_conn_(un)register
  dw-hdmi-cec: use cec_notifier_cec_adap_(un)register
  dw-hdmi: use cec_notifier_conn_(un)register
  tda9950: use cec_notifier_cec_adap_(un)register
  tda998x: use cec_notifier_conn_(un)register
  drm/vc4/vc4_hdmi: fill in connector info

Hans Verkuil (4):
  cec-notifier: rename variable, check kstrdup
  cec: add new notifier functions
  cec: document CEC_ADAP_G_CONNECTOR_INFO
  meson/ao-cec: use cec_notifier_cec_adap_(un)register

 Documentation/media/uapi/cec/cec-funcs.rst    |   1 +
 .../uapi/cec/cec-ioc-adap-g-conn-info.rst     | 109 +++++++++++++++++
 .../display/amdgpu_dm/amdgpu_dm_mst_types.c   |   2 +-
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c |   9 +-
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c     | 104 +++++++++-------
 drivers/gpu/drm/drm_dp_cec.c                  |  25 ++--
 drivers/gpu/drm/i2c/tda9950.c                 |  11 +-
 drivers/gpu/drm/i2c/tda998x_drv.c             |  56 ++++-----
 drivers/gpu/drm/i915/intel_dp.c               |   4 +-
 drivers/gpu/drm/i915/intel_hdmi.c             |  13 +-
 drivers/gpu/drm/nouveau/nouveau_connector.c   |   3 +-
 drivers/gpu/drm/vc4/vc4_hdmi.c                |  13 +-
 drivers/media/cec/cec-adap.c                  |  31 +++++
 drivers/media/cec/cec-api.c                   |  16 +++
 drivers/media/cec/cec-notifier.c              | 115 ++++++++++++++++--
 drivers/media/platform/meson/ao-cec.c         |  37 +++---
 include/drm/drm_dp_helper.h                   |  14 +--
 include/media/cec-notifier.h                  |  78 ++++++++++++
 include/media/cec.h                           |  19 +++
 include/uapi/linux/cec.h                      |  33 +++++
 20 files changed, 550 insertions(+), 143 deletions(-)
 create mode 100644 Documentation/media/uapi/cec/cec-ioc-adap-g-conn-info.rst

-- 
2.20.1


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

* [PATCHv8 00/13] cec: improve notifier support, add connector info
@ 2019-06-24 16:03 ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media; +Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

This is a rework of Dariusz' v7 series:

https://www.spinics.net/lists/linux-media/msg151117.html

Rather than changing the existing CEC kAPI to allocate and
register CEC adapters I left it as-is. Instead new notifiers
functions are added to (un)register HDMI connector and CEC adapter
notifiers. These replace the current cec_notifier_get_conn and _put
functions.

For drivers that don't use notifiers the cec_s_conn_info function
was created so the connector info can be set directly as well.

This split in separate connector and CEC adapter functions is needed
since the notifier information is different between the two and this
makes it future proof since we will need to eventually support more
than one CEC adapter per HDMI connector.

By carefully designing these functions it is possible to convert
drivers to these new functions one-by-one, rather than as a painful
big-bang patch.

The plan is to merge the first three patches for kernel 5.3: these
patches provide the infrastructure needed by drm and cec drivers
to do the conversion during the 5.4 cycle, without requiring
patches that touch on multiple subsystems.

Once the conversion is done the new connector API can be exposed.
A patch documenting the new API is included as well, but it is
old and needs updating (the new CEC_CAP_CONNECTOR_INFO capability
isn't documented, and neither is the new 'have_connector_info'
field of the state changed event).

Various drivers have been converted as well as an example. These
are based on Dariusz' original series, but using the new notifier
functions.

Regards,

	Hans

Dariusz Marcinkiewicz (9):
  cec: add struct cec_connector_info support
  cec: expose the new connector info API
  drm_dp_cec: add connector info support.
  drm/i915/intel_hdmi: use cec_notifier_conn_(un)register
  dw-hdmi-cec: use cec_notifier_cec_adap_(un)register
  dw-hdmi: use cec_notifier_conn_(un)register
  tda9950: use cec_notifier_cec_adap_(un)register
  tda998x: use cec_notifier_conn_(un)register
  drm/vc4/vc4_hdmi: fill in connector info

Hans Verkuil (4):
  cec-notifier: rename variable, check kstrdup
  cec: add new notifier functions
  cec: document CEC_ADAP_G_CONNECTOR_INFO
  meson/ao-cec: use cec_notifier_cec_adap_(un)register

 Documentation/media/uapi/cec/cec-funcs.rst    |   1 +
 .../uapi/cec/cec-ioc-adap-g-conn-info.rst     | 109 +++++++++++++++++
 .../display/amdgpu_dm/amdgpu_dm_mst_types.c   |   2 +-
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c |   9 +-
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c     | 104 +++++++++-------
 drivers/gpu/drm/drm_dp_cec.c                  |  25 ++--
 drivers/gpu/drm/i2c/tda9950.c                 |  11 +-
 drivers/gpu/drm/i2c/tda998x_drv.c             |  56 ++++-----
 drivers/gpu/drm/i915/intel_dp.c               |   4 +-
 drivers/gpu/drm/i915/intel_hdmi.c             |  13 +-
 drivers/gpu/drm/nouveau/nouveau_connector.c   |   3 +-
 drivers/gpu/drm/vc4/vc4_hdmi.c                |  13 +-
 drivers/media/cec/cec-adap.c                  |  31 +++++
 drivers/media/cec/cec-api.c                   |  16 +++
 drivers/media/cec/cec-notifier.c              | 115 ++++++++++++++++--
 drivers/media/platform/meson/ao-cec.c         |  37 +++---
 include/drm/drm_dp_helper.h                   |  14 +--
 include/media/cec-notifier.h                  |  78 ++++++++++++
 include/media/cec.h                           |  19 +++
 include/uapi/linux/cec.h                      |  33 +++++
 20 files changed, 550 insertions(+), 143 deletions(-)
 create mode 100644 Documentation/media/uapi/cec/cec-ioc-adap-g-conn-info.rst

-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 01/13] cec-notifier: rename variable, check kstrdup
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

dev -> hdmi_dev
conn -> conn_name

Also check the result of kstrdup, and clean up on error.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/cec/cec-notifier.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c
index 9598c7778871..ce10dfd400bb 100644
--- a/drivers/media/cec/cec-notifier.c
+++ b/drivers/media/cec/cec-notifier.c
@@ -21,8 +21,8 @@ struct cec_notifier {
 	struct mutex lock;
 	struct list_head head;
 	struct kref kref;
-	struct device *dev;
-	const char *conn;
+	struct device *hdmi_dev;
+	const char *conn_name;
 	struct cec_adapter *cec_adap;
 	void (*callback)(struct cec_adapter *adap, u16 pa);
 
@@ -32,14 +32,15 @@ struct cec_notifier {
 static LIST_HEAD(cec_notifiers);
 static DEFINE_MUTEX(cec_notifiers_lock);
 
-struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
+struct cec_notifier *
+cec_notifier_get_conn(struct device *hdmi_dev, const char *conn_name)
 {
 	struct cec_notifier *n;
 
 	mutex_lock(&cec_notifiers_lock);
 	list_for_each_entry(n, &cec_notifiers, head) {
-		if (n->dev == dev &&
-		    (!conn || !strcmp(n->conn, conn))) {
+		if (n->hdmi_dev == hdmi_dev &&
+		    (!conn_name || !strcmp(n->conn_name, conn_name))) {
 			kref_get(&n->kref);
 			mutex_unlock(&cec_notifiers_lock);
 			return n;
@@ -48,10 +49,17 @@ struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
 	n = kzalloc(sizeof(*n), GFP_KERNEL);
 	if (!n)
 		goto unlock;
-	n->dev = dev;
-	if (conn)
-		n->conn = kstrdup(conn, GFP_KERNEL);
+	n->hdmi_dev = hdmi_dev;
+	if (conn_name) {
+		n->conn_name = kstrdup(conn_name, GFP_KERNEL);
+		if (!n->conn_name) {
+			kfree(n);
+			n = NULL;
+			goto unlock;
+		}
+	}
 	n->phys_addr = CEC_PHYS_ADDR_INVALID;
+
 	mutex_init(&n->lock);
 	kref_init(&n->kref);
 	list_add_tail(&n->head, &cec_notifiers);
@@ -67,7 +75,7 @@ static void cec_notifier_release(struct kref *kref)
 		container_of(kref, struct cec_notifier, kref);
 
 	list_del(&n->head);
-	kfree(n->conn);
+	kfree(n->conn_name);
 	kfree(n);
 }
 
-- 
2.20.1


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

* [PATCHv8 01/13] cec-notifier: rename variable, check kstrdup
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

dev -> hdmi_dev
conn -> conn_name

Also check the result of kstrdup, and clean up on error.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/cec/cec-notifier.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c
index 9598c7778871..ce10dfd400bb 100644
--- a/drivers/media/cec/cec-notifier.c
+++ b/drivers/media/cec/cec-notifier.c
@@ -21,8 +21,8 @@ struct cec_notifier {
 	struct mutex lock;
 	struct list_head head;
 	struct kref kref;
-	struct device *dev;
-	const char *conn;
+	struct device *hdmi_dev;
+	const char *conn_name;
 	struct cec_adapter *cec_adap;
 	void (*callback)(struct cec_adapter *adap, u16 pa);
 
@@ -32,14 +32,15 @@ struct cec_notifier {
 static LIST_HEAD(cec_notifiers);
 static DEFINE_MUTEX(cec_notifiers_lock);
 
-struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
+struct cec_notifier *
+cec_notifier_get_conn(struct device *hdmi_dev, const char *conn_name)
 {
 	struct cec_notifier *n;
 
 	mutex_lock(&cec_notifiers_lock);
 	list_for_each_entry(n, &cec_notifiers, head) {
-		if (n->dev == dev &&
-		    (!conn || !strcmp(n->conn, conn))) {
+		if (n->hdmi_dev == hdmi_dev &&
+		    (!conn_name || !strcmp(n->conn_name, conn_name))) {
 			kref_get(&n->kref);
 			mutex_unlock(&cec_notifiers_lock);
 			return n;
@@ -48,10 +49,17 @@ struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
 	n = kzalloc(sizeof(*n), GFP_KERNEL);
 	if (!n)
 		goto unlock;
-	n->dev = dev;
-	if (conn)
-		n->conn = kstrdup(conn, GFP_KERNEL);
+	n->hdmi_dev = hdmi_dev;
+	if (conn_name) {
+		n->conn_name = kstrdup(conn_name, GFP_KERNEL);
+		if (!n->conn_name) {
+			kfree(n);
+			n = NULL;
+			goto unlock;
+		}
+	}
 	n->phys_addr = CEC_PHYS_ADDR_INVALID;
+
 	mutex_init(&n->lock);
 	kref_init(&n->kref);
 	list_add_tail(&n->head, &cec_notifiers);
@@ -67,7 +75,7 @@ static void cec_notifier_release(struct kref *kref)
 		container_of(kref, struct cec_notifier, kref);
 
 	list_del(&n->head);
-	kfree(n->conn);
+	kfree(n->conn_name);
 	kfree(n);
 }
 
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 02/13] cec: add struct cec_connector_info support
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

From: Dariusz Marcinkiewicz <darekm@google.com>

Define struct cec_connector_info in media/cec.h and define
CEC_CAP_CONNECTOR_INFO. In a later patch this will be moved to
uapi/linux/cec.h.

For now just define this together with the cec_fill_conn_info_from_drm
and cec_s_conn_info functions: this allows both drm and media to make
use of this without requiring cross-subsystem changes.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Co-developed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/cec/cec-adap.c | 29 +++++++++++++++++++++++
 drivers/media/cec/cec-core.c |  5 ++++
 include/media/cec.h          | 45 +++++++++++++++++++++++++++++++++++-
 3 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/drivers/media/cec/cec-adap.c b/drivers/media/cec/cec-adap.c
index ac3683a7b2ab..451c61bde4d4 100644
--- a/drivers/media/cec/cec-adap.c
+++ b/drivers/media/cec/cec-adap.c
@@ -16,7 +16,10 @@
 #include <linux/string.h>
 #include <linux/types.h>
 
+#include <drm/drm_connector.h>
+#include <drm/drm_device.h>
 #include <drm/drm_edid.h>
+#include <drm/drm_file.h>
 
 #include "cec-priv.h"
 
@@ -75,6 +78,16 @@ u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
 }
 EXPORT_SYMBOL_GPL(cec_get_edid_phys_addr);
 
+void cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info,
+				 const struct drm_connector *connector)
+{
+	memset(conn_info, 0, sizeof(*conn_info));
+	conn_info->type = CEC_CONNECTOR_TYPE_DRM;
+	conn_info->drm.card_no = connector->dev->primary->index;
+	conn_info->drm.connector_id = connector->base.id;
+}
+EXPORT_SYMBOL_GPL(cec_fill_conn_info_from_drm);
+
 /*
  * Queue a new event for this filehandle. If ts == 0, then set it
  * to the current time.
@@ -1598,6 +1611,22 @@ void cec_s_phys_addr_from_edid(struct cec_adapter *adap,
 }
 EXPORT_SYMBOL_GPL(cec_s_phys_addr_from_edid);
 
+void cec_s_conn_info(struct cec_adapter *adap,
+		     const struct cec_connector_info *conn_info)
+{
+	if (!(adap->capabilities & CEC_CAP_CONNECTOR_INFO))
+		return;
+
+	mutex_lock(&adap->lock);
+	if (conn_info)
+		adap->conn_info = *conn_info;
+	else
+		memset(&adap->conn_info, 0, sizeof(adap->conn_info));
+	cec_post_state_event(adap);
+	mutex_unlock(&adap->lock);
+}
+EXPORT_SYMBOL_GPL(cec_s_conn_info);
+
 /*
  * Called from either the ioctl or a driver to set the logical addresses.
  *
diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c
index db7adffcdc76..e45b792d26fb 100644
--- a/drivers/media/cec/cec-core.c
+++ b/drivers/media/cec/cec-core.c
@@ -189,6 +189,11 @@ static void cec_cec_notify(struct cec_adapter *adap, u16 pa)
 	cec_s_phys_addr(adap, pa, false);
 }
 
+void cec_notifier_register(struct cec_notifier *n,
+			   struct cec_adapter *adap,
+			   void (*callback)(struct cec_adapter *adap, u16 pa));
+void cec_notifier_unregister(struct cec_notifier *n);
+
 void cec_register_cec_notifier(struct cec_adapter *adap,
 			       struct cec_notifier *notifier)
 {
diff --git a/include/media/cec.h b/include/media/cec.h
index 707411ef8ba2..45f2c98ed75b 100644
--- a/include/media/cec.h
+++ b/include/media/cec.h
@@ -17,7 +17,9 @@
 #include <linux/timer.h>
 #include <linux/cec-funcs.h>
 #include <media/rc-core.h>
-#include <media/cec-notifier.h>
+
+/* CEC_ADAP_G_CONNECTOR_INFO is available */
+#define CEC_CAP_CONNECTOR_INFO	0
 
 #define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \
 			  CEC_CAP_PASSTHROUGH | CEC_CAP_RC)
@@ -53,6 +55,7 @@ struct cec_devnode {
 struct cec_adapter;
 struct cec_data;
 struct cec_pin;
+struct cec_notifier;
 
 struct cec_data {
 	struct list_head list;
@@ -144,6 +147,27 @@ struct cec_adap_ops {
  */
 #define CEC_MAX_MSG_TX_QUEUE_SZ		(18 * 1)
 
+/**
+ * struct cec_event_connector - tells if and which connector is associated
+ * with the CEC adapter.
+ * @card_no: drm card number
+ * @connector_id: drm connector ID
+ */
+struct cec_drm_connector_info {
+	__u32 card_no;
+	__u32 connector_id;
+};
+
+#define CEC_CONNECTOR_TYPE_NO_CONNECTOR	0
+#define CEC_CONNECTOR_TYPE_DRM		1
+struct cec_connector_info {
+	__u32 type;
+	union {
+		struct cec_drm_connector_info drm;
+		__u32 raw[16];
+	};
+};
+
 struct cec_adapter {
 	struct module *owner;
 	char name[32];
@@ -182,6 +206,7 @@ struct cec_adapter {
 	struct cec_fh *cec_initiator;
 	bool passthrough;
 	struct cec_log_addrs log_addrs;
+	struct cec_connector_info conn_info;
 
 	u32 tx_timeouts;
 
@@ -233,6 +258,7 @@ static inline bool cec_is_registered(const struct cec_adapter *adap)
 	((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf
 
 struct edid;
+struct drm_connector;
 
 #if IS_REACHABLE(CONFIG_CEC_CORE)
 struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
@@ -247,6 +273,8 @@ void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr,
 		     bool block);
 void cec_s_phys_addr_from_edid(struct cec_adapter *adap,
 			       const struct edid *edid);
+void cec_s_conn_info(struct cec_adapter *adap,
+		     const struct cec_connector_info *conn_info);
 int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg,
 		     bool block);
 
@@ -331,6 +359,9 @@ void cec_queue_pin_5v_event(struct cec_adapter *adap, bool is_high, ktime_t ts);
 u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
 			   unsigned int *offset);
 
+void cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info,
+				 const struct drm_connector *connector);
+
 #else
 
 static inline int cec_register_adapter(struct cec_adapter *adap,
@@ -365,6 +396,18 @@ static inline u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
 	return CEC_PHYS_ADDR_INVALID;
 }
 
+static inline void cec_s_conn_info(struct cec_adapter *adap,
+				   const struct cec_connector_info *conn_info)
+{
+}
+
+static inline void
+cec_fill_conn_info_from_drm(const struct drm_connector *connector,
+			    struct cec_connector_info *conn_info)
+{
+	memset(conn_info, 0, sizeof(*conn_info));
+}
+
 #endif
 
 /**
-- 
2.20.1


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

* [PATCHv8 02/13] cec: add struct cec_connector_info support
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

From: Dariusz Marcinkiewicz <darekm@google.com>

Define struct cec_connector_info in media/cec.h and define
CEC_CAP_CONNECTOR_INFO. In a later patch this will be moved to
uapi/linux/cec.h.

For now just define this together with the cec_fill_conn_info_from_drm
and cec_s_conn_info functions: this allows both drm and media to make
use of this without requiring cross-subsystem changes.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Co-developed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/cec/cec-adap.c | 29 +++++++++++++++++++++++
 drivers/media/cec/cec-core.c |  5 ++++
 include/media/cec.h          | 45 +++++++++++++++++++++++++++++++++++-
 3 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/drivers/media/cec/cec-adap.c b/drivers/media/cec/cec-adap.c
index ac3683a7b2ab..451c61bde4d4 100644
--- a/drivers/media/cec/cec-adap.c
+++ b/drivers/media/cec/cec-adap.c
@@ -16,7 +16,10 @@
 #include <linux/string.h>
 #include <linux/types.h>
 
+#include <drm/drm_connector.h>
+#include <drm/drm_device.h>
 #include <drm/drm_edid.h>
+#include <drm/drm_file.h>
 
 #include "cec-priv.h"
 
@@ -75,6 +78,16 @@ u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
 }
 EXPORT_SYMBOL_GPL(cec_get_edid_phys_addr);
 
+void cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info,
+				 const struct drm_connector *connector)
+{
+	memset(conn_info, 0, sizeof(*conn_info));
+	conn_info->type = CEC_CONNECTOR_TYPE_DRM;
+	conn_info->drm.card_no = connector->dev->primary->index;
+	conn_info->drm.connector_id = connector->base.id;
+}
+EXPORT_SYMBOL_GPL(cec_fill_conn_info_from_drm);
+
 /*
  * Queue a new event for this filehandle. If ts == 0, then set it
  * to the current time.
@@ -1598,6 +1611,22 @@ void cec_s_phys_addr_from_edid(struct cec_adapter *adap,
 }
 EXPORT_SYMBOL_GPL(cec_s_phys_addr_from_edid);
 
+void cec_s_conn_info(struct cec_adapter *adap,
+		     const struct cec_connector_info *conn_info)
+{
+	if (!(adap->capabilities & CEC_CAP_CONNECTOR_INFO))
+		return;
+
+	mutex_lock(&adap->lock);
+	if (conn_info)
+		adap->conn_info = *conn_info;
+	else
+		memset(&adap->conn_info, 0, sizeof(adap->conn_info));
+	cec_post_state_event(adap);
+	mutex_unlock(&adap->lock);
+}
+EXPORT_SYMBOL_GPL(cec_s_conn_info);
+
 /*
  * Called from either the ioctl or a driver to set the logical addresses.
  *
diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c
index db7adffcdc76..e45b792d26fb 100644
--- a/drivers/media/cec/cec-core.c
+++ b/drivers/media/cec/cec-core.c
@@ -189,6 +189,11 @@ static void cec_cec_notify(struct cec_adapter *adap, u16 pa)
 	cec_s_phys_addr(adap, pa, false);
 }
 
+void cec_notifier_register(struct cec_notifier *n,
+			   struct cec_adapter *adap,
+			   void (*callback)(struct cec_adapter *adap, u16 pa));
+void cec_notifier_unregister(struct cec_notifier *n);
+
 void cec_register_cec_notifier(struct cec_adapter *adap,
 			       struct cec_notifier *notifier)
 {
diff --git a/include/media/cec.h b/include/media/cec.h
index 707411ef8ba2..45f2c98ed75b 100644
--- a/include/media/cec.h
+++ b/include/media/cec.h
@@ -17,7 +17,9 @@
 #include <linux/timer.h>
 #include <linux/cec-funcs.h>
 #include <media/rc-core.h>
-#include <media/cec-notifier.h>
+
+/* CEC_ADAP_G_CONNECTOR_INFO is available */
+#define CEC_CAP_CONNECTOR_INFO	0
 
 #define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \
 			  CEC_CAP_PASSTHROUGH | CEC_CAP_RC)
@@ -53,6 +55,7 @@ struct cec_devnode {
 struct cec_adapter;
 struct cec_data;
 struct cec_pin;
+struct cec_notifier;
 
 struct cec_data {
 	struct list_head list;
@@ -144,6 +147,27 @@ struct cec_adap_ops {
  */
 #define CEC_MAX_MSG_TX_QUEUE_SZ		(18 * 1)
 
+/**
+ * struct cec_event_connector - tells if and which connector is associated
+ * with the CEC adapter.
+ * @card_no: drm card number
+ * @connector_id: drm connector ID
+ */
+struct cec_drm_connector_info {
+	__u32 card_no;
+	__u32 connector_id;
+};
+
+#define CEC_CONNECTOR_TYPE_NO_CONNECTOR	0
+#define CEC_CONNECTOR_TYPE_DRM		1
+struct cec_connector_info {
+	__u32 type;
+	union {
+		struct cec_drm_connector_info drm;
+		__u32 raw[16];
+	};
+};
+
 struct cec_adapter {
 	struct module *owner;
 	char name[32];
@@ -182,6 +206,7 @@ struct cec_adapter {
 	struct cec_fh *cec_initiator;
 	bool passthrough;
 	struct cec_log_addrs log_addrs;
+	struct cec_connector_info conn_info;
 
 	u32 tx_timeouts;
 
@@ -233,6 +258,7 @@ static inline bool cec_is_registered(const struct cec_adapter *adap)
 	((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf
 
 struct edid;
+struct drm_connector;
 
 #if IS_REACHABLE(CONFIG_CEC_CORE)
 struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
@@ -247,6 +273,8 @@ void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr,
 		     bool block);
 void cec_s_phys_addr_from_edid(struct cec_adapter *adap,
 			       const struct edid *edid);
+void cec_s_conn_info(struct cec_adapter *adap,
+		     const struct cec_connector_info *conn_info);
 int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg,
 		     bool block);
 
@@ -331,6 +359,9 @@ void cec_queue_pin_5v_event(struct cec_adapter *adap, bool is_high, ktime_t ts);
 u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
 			   unsigned int *offset);
 
+void cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info,
+				 const struct drm_connector *connector);
+
 #else
 
 static inline int cec_register_adapter(struct cec_adapter *adap,
@@ -365,6 +396,18 @@ static inline u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
 	return CEC_PHYS_ADDR_INVALID;
 }
 
+static inline void cec_s_conn_info(struct cec_adapter *adap,
+				   const struct cec_connector_info *conn_info)
+{
+}
+
+static inline void
+cec_fill_conn_info_from_drm(const struct drm_connector *connector,
+			    struct cec_connector_info *conn_info)
+{
+	memset(conn_info, 0, sizeof(*conn_info));
+}
+
 #endif
 
 /**
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 03/13] cec: add new notifier functions
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

In order to support multiple CEC devices for an HDMI connector,
and to support cec_connector_info, drivers should use either a
cec_notifier_conn_(un)register pair of functions (HDMI drivers)
or a cec_notifier_cec_adap_(un)register pair (CEC adapter drivers).

This replaces cec_notifier_get_conn/cec_notifier_put.

For CEC adapters it is also no longer needed to call cec_notifier_register,
cec_register_cec_notifier and cec_notifier_unregister. This is now
all handled internally by the new functions.

The called_cec_notifier_register bool is needed to handle the case where
a CEC adapter driver called the old cec_notifier_register() function
instead of cec_notifier_cec_adap_unregister().

Once those old functions are removed in the future, that bool can also
be removed.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/cec/cec-notifier.c | 89 ++++++++++++++++++++++++++++++++
 include/media/cec-notifier.h     | 78 ++++++++++++++++++++++++++++
 2 files changed, 167 insertions(+)

diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c
index ce10dfd400bb..49d6ec198d38 100644
--- a/drivers/media/cec/cec-notifier.c
+++ b/drivers/media/cec/cec-notifier.c
@@ -22,9 +22,11 @@ struct cec_notifier {
 	struct list_head head;
 	struct kref kref;
 	struct device *hdmi_dev;
+	struct cec_connector_info conn_info;
 	const char *conn_name;
 	struct cec_adapter *cec_adap;
 	void (*callback)(struct cec_adapter *adap, u16 pa);
+	bool called_cec_notifier_register;
 
 	u16 phys_addr;
 };
@@ -87,6 +89,85 @@ void cec_notifier_put(struct cec_notifier *n)
 }
 EXPORT_SYMBOL_GPL(cec_notifier_put);
 
+struct cec_notifier *
+cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
+			   const struct cec_connector_info *conn_info)
+{
+	struct cec_notifier *n = cec_notifier_get_conn(hdmi_dev, conn_name);
+
+	if (!n)
+		return n;
+
+	mutex_lock(&n->lock);
+	n->phys_addr = CEC_PHYS_ADDR_INVALID;
+	if (conn_info)
+		n->conn_info = *conn_info;
+	else
+		memset(&n->conn_info, 0, sizeof(n->conn_info));
+	if (n->cec_adap) {
+		cec_phys_addr_invalidate(n->cec_adap);
+		cec_s_conn_info(n->cec_adap, conn_info);
+	}
+	mutex_unlock(&n->lock);
+	return n;
+}
+EXPORT_SYMBOL_GPL(cec_notifier_conn_register);
+
+void cec_notifier_conn_unregister(struct cec_notifier *n)
+{
+	if (!n)
+		return;
+
+	mutex_lock(&n->lock);
+	memset(&n->conn_info, 0, sizeof(n->conn_info));
+	n->phys_addr = CEC_PHYS_ADDR_INVALID;
+	if (n->cec_adap) {
+		cec_phys_addr_invalidate(n->cec_adap);
+		cec_s_conn_info(n->cec_adap, NULL);
+	}
+	mutex_unlock(&n->lock);
+	cec_notifier_put(n);
+}
+EXPORT_SYMBOL_GPL(cec_notifier_conn_unregister);
+
+struct cec_notifier *
+cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
+			       struct cec_adapter *adap)
+{
+	struct cec_notifier *n;
+
+	if (WARN_ON(!adap))
+		return NULL;
+
+	n = cec_notifier_get_conn(hdmi_dev, conn_name);
+	if (!n)
+		return n;
+
+	mutex_lock(&n->lock);
+	n->cec_adap = adap;
+	adap->conn_info = n->conn_info;
+	adap->notifier = n;
+	cec_s_phys_addr(adap, n->phys_addr, false);
+	mutex_unlock(&n->lock);
+	return n;
+}
+EXPORT_SYMBOL_GPL(cec_notifier_cec_adap_register);
+
+void cec_notifier_cec_adap_unregister(struct cec_notifier *n)
+{
+	if (!n)
+		return;
+
+	mutex_lock(&n->lock);
+	memset(&n->cec_adap->conn_info, 0, sizeof(n->cec_adap->conn_info));
+	n->cec_adap->notifier = NULL;
+	n->cec_adap = NULL;
+	n->callback = NULL;
+	mutex_unlock(&n->lock);
+	cec_notifier_put(n);
+}
+EXPORT_SYMBOL_GPL(cec_notifier_cec_adap_unregister);
+
 void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
 {
 	if (n == NULL)
@@ -96,6 +177,8 @@ void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
 	n->phys_addr = pa;
 	if (n->callback)
 		n->callback(n->cec_adap, n->phys_addr);
+	else if (n->cec_adap)
+		cec_s_phys_addr(n->cec_adap, n->phys_addr, false);
 	mutex_unlock(&n->lock);
 }
 EXPORT_SYMBOL_GPL(cec_notifier_set_phys_addr);
@@ -121,6 +204,7 @@ void cec_notifier_register(struct cec_notifier *n,
 {
 	kref_get(&n->kref);
 	mutex_lock(&n->lock);
+	n->called_cec_notifier_register = true;
 	n->cec_adap = adap;
 	n->callback = callback;
 	n->callback(adap, n->phys_addr);
@@ -130,8 +214,13 @@ EXPORT_SYMBOL_GPL(cec_notifier_register);
 
 void cec_notifier_unregister(struct cec_notifier *n)
 {
+	/* Do nothing unless cec_notifier_register was called first */
+	if (!n->called_cec_notifier_register)
+		return;
+
 	mutex_lock(&n->lock);
 	n->callback = NULL;
+	n->called_cec_notifier_register = false;
 	mutex_unlock(&n->lock);
 	cec_notifier_put(n);
 }
diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h
index 57b3a9f6ea1d..313b6905c203 100644
--- a/include/media/cec-notifier.h
+++ b/include/media/cec-notifier.h
@@ -42,6 +42,60 @@ struct cec_notifier *cec_notifier_get_conn(struct device *dev,
  */
 void cec_notifier_put(struct cec_notifier *n);
 
+/**
+ * cec_notifier_conn_register - find or create a new cec_notifier for the given
+ * HDMI device and connector tuple.
+ * @hdmi_dev: HDMI device that sends the events.
+ * @conn_name: the connector name from which the event occurs. May be NULL
+ * if there is always only one HDMI connector created by the HDMI device.
+ * @conn_info: the connector info from which the event occurs (may be NULL)
+ *
+ * If a notifier for device @dev and connector @conn_name already exists, then
+ * increase the refcount and return that notifier.
+ *
+ * If it doesn't exist, then allocate a new notifier struct and return a
+ * pointer to that new struct.
+ *
+ * Return NULL if the memory could not be allocated.
+ */
+struct cec_notifier *
+cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
+			   const struct cec_connector_info *conn_info);
+
+/**
+ * cec_notifier_conn_unregister - decrease refcount and delete when the
+ * refcount reaches 0.
+ * @n: notifier
+ */
+void cec_notifier_conn_unregister(struct cec_notifier *n);
+
+/**
+ * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
+ * given device.
+ * @hdmi_dev: HDMI device that sends the events.
+ * @conn_name: the connector name from which the event occurs. May be NULL
+ * if there is always only one HDMI connector created by the HDMI device.
+ * @adap: the cec adapter that registered this notifier.
+ *
+ * If a notifier for device @dev and connector @conn_name already exists, then
+ * increase the refcount and return that notifier.
+ *
+ * If it doesn't exist, then allocate a new notifier struct and return a
+ * pointer to that new struct.
+ *
+ * Return NULL if the memory could not be allocated.
+ */
+struct cec_notifier *
+cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
+			       struct cec_adapter *adap);
+
+/**
+ * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
+ * refcount reaches 0.
+ * @n: notifier
+ */
+void cec_notifier_cec_adap_unregister(struct cec_notifier *n);
+
 /**
  * cec_notifier_set_phys_addr - set a new physical address.
  * @n: the CEC notifier
@@ -110,6 +164,30 @@ static inline void cec_notifier_put(struct cec_notifier *n)
 {
 }
 
+static inline struct cec_notifier *
+cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
+			   const struct cec_connector_info *conn_info)
+{
+	/* A non-NULL pointer is expected on success */
+	return (struct cec_notifier *)0xdeadfeed;
+}
+
+static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
+{
+}
+
+static inline struct cec_notifier *
+cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
+			       struct cec_adapter *adap)
+{
+	/* A non-NULL pointer is expected on success */
+	return (struct cec_notifier *)0xdeadfeed;
+}
+
+static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n)
+{
+}
+
 static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
 {
 }
-- 
2.20.1


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

* [PATCHv8 03/13] cec: add new notifier functions
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

In order to support multiple CEC devices for an HDMI connector,
and to support cec_connector_info, drivers should use either a
cec_notifier_conn_(un)register pair of functions (HDMI drivers)
or a cec_notifier_cec_adap_(un)register pair (CEC adapter drivers).

This replaces cec_notifier_get_conn/cec_notifier_put.

For CEC adapters it is also no longer needed to call cec_notifier_register,
cec_register_cec_notifier and cec_notifier_unregister. This is now
all handled internally by the new functions.

The called_cec_notifier_register bool is needed to handle the case where
a CEC adapter driver called the old cec_notifier_register() function
instead of cec_notifier_cec_adap_unregister().

Once those old functions are removed in the future, that bool can also
be removed.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/cec/cec-notifier.c | 89 ++++++++++++++++++++++++++++++++
 include/media/cec-notifier.h     | 78 ++++++++++++++++++++++++++++
 2 files changed, 167 insertions(+)

diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c
index ce10dfd400bb..49d6ec198d38 100644
--- a/drivers/media/cec/cec-notifier.c
+++ b/drivers/media/cec/cec-notifier.c
@@ -22,9 +22,11 @@ struct cec_notifier {
 	struct list_head head;
 	struct kref kref;
 	struct device *hdmi_dev;
+	struct cec_connector_info conn_info;
 	const char *conn_name;
 	struct cec_adapter *cec_adap;
 	void (*callback)(struct cec_adapter *adap, u16 pa);
+	bool called_cec_notifier_register;
 
 	u16 phys_addr;
 };
@@ -87,6 +89,85 @@ void cec_notifier_put(struct cec_notifier *n)
 }
 EXPORT_SYMBOL_GPL(cec_notifier_put);
 
+struct cec_notifier *
+cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
+			   const struct cec_connector_info *conn_info)
+{
+	struct cec_notifier *n = cec_notifier_get_conn(hdmi_dev, conn_name);
+
+	if (!n)
+		return n;
+
+	mutex_lock(&n->lock);
+	n->phys_addr = CEC_PHYS_ADDR_INVALID;
+	if (conn_info)
+		n->conn_info = *conn_info;
+	else
+		memset(&n->conn_info, 0, sizeof(n->conn_info));
+	if (n->cec_adap) {
+		cec_phys_addr_invalidate(n->cec_adap);
+		cec_s_conn_info(n->cec_adap, conn_info);
+	}
+	mutex_unlock(&n->lock);
+	return n;
+}
+EXPORT_SYMBOL_GPL(cec_notifier_conn_register);
+
+void cec_notifier_conn_unregister(struct cec_notifier *n)
+{
+	if (!n)
+		return;
+
+	mutex_lock(&n->lock);
+	memset(&n->conn_info, 0, sizeof(n->conn_info));
+	n->phys_addr = CEC_PHYS_ADDR_INVALID;
+	if (n->cec_adap) {
+		cec_phys_addr_invalidate(n->cec_adap);
+		cec_s_conn_info(n->cec_adap, NULL);
+	}
+	mutex_unlock(&n->lock);
+	cec_notifier_put(n);
+}
+EXPORT_SYMBOL_GPL(cec_notifier_conn_unregister);
+
+struct cec_notifier *
+cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
+			       struct cec_adapter *adap)
+{
+	struct cec_notifier *n;
+
+	if (WARN_ON(!adap))
+		return NULL;
+
+	n = cec_notifier_get_conn(hdmi_dev, conn_name);
+	if (!n)
+		return n;
+
+	mutex_lock(&n->lock);
+	n->cec_adap = adap;
+	adap->conn_info = n->conn_info;
+	adap->notifier = n;
+	cec_s_phys_addr(adap, n->phys_addr, false);
+	mutex_unlock(&n->lock);
+	return n;
+}
+EXPORT_SYMBOL_GPL(cec_notifier_cec_adap_register);
+
+void cec_notifier_cec_adap_unregister(struct cec_notifier *n)
+{
+	if (!n)
+		return;
+
+	mutex_lock(&n->lock);
+	memset(&n->cec_adap->conn_info, 0, sizeof(n->cec_adap->conn_info));
+	n->cec_adap->notifier = NULL;
+	n->cec_adap = NULL;
+	n->callback = NULL;
+	mutex_unlock(&n->lock);
+	cec_notifier_put(n);
+}
+EXPORT_SYMBOL_GPL(cec_notifier_cec_adap_unregister);
+
 void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
 {
 	if (n == NULL)
@@ -96,6 +177,8 @@ void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
 	n->phys_addr = pa;
 	if (n->callback)
 		n->callback(n->cec_adap, n->phys_addr);
+	else if (n->cec_adap)
+		cec_s_phys_addr(n->cec_adap, n->phys_addr, false);
 	mutex_unlock(&n->lock);
 }
 EXPORT_SYMBOL_GPL(cec_notifier_set_phys_addr);
@@ -121,6 +204,7 @@ void cec_notifier_register(struct cec_notifier *n,
 {
 	kref_get(&n->kref);
 	mutex_lock(&n->lock);
+	n->called_cec_notifier_register = true;
 	n->cec_adap = adap;
 	n->callback = callback;
 	n->callback(adap, n->phys_addr);
@@ -130,8 +214,13 @@ EXPORT_SYMBOL_GPL(cec_notifier_register);
 
 void cec_notifier_unregister(struct cec_notifier *n)
 {
+	/* Do nothing unless cec_notifier_register was called first */
+	if (!n->called_cec_notifier_register)
+		return;
+
 	mutex_lock(&n->lock);
 	n->callback = NULL;
+	n->called_cec_notifier_register = false;
 	mutex_unlock(&n->lock);
 	cec_notifier_put(n);
 }
diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h
index 57b3a9f6ea1d..313b6905c203 100644
--- a/include/media/cec-notifier.h
+++ b/include/media/cec-notifier.h
@@ -42,6 +42,60 @@ struct cec_notifier *cec_notifier_get_conn(struct device *dev,
  */
 void cec_notifier_put(struct cec_notifier *n);
 
+/**
+ * cec_notifier_conn_register - find or create a new cec_notifier for the given
+ * HDMI device and connector tuple.
+ * @hdmi_dev: HDMI device that sends the events.
+ * @conn_name: the connector name from which the event occurs. May be NULL
+ * if there is always only one HDMI connector created by the HDMI device.
+ * @conn_info: the connector info from which the event occurs (may be NULL)
+ *
+ * If a notifier for device @dev and connector @conn_name already exists, then
+ * increase the refcount and return that notifier.
+ *
+ * If it doesn't exist, then allocate a new notifier struct and return a
+ * pointer to that new struct.
+ *
+ * Return NULL if the memory could not be allocated.
+ */
+struct cec_notifier *
+cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
+			   const struct cec_connector_info *conn_info);
+
+/**
+ * cec_notifier_conn_unregister - decrease refcount and delete when the
+ * refcount reaches 0.
+ * @n: notifier
+ */
+void cec_notifier_conn_unregister(struct cec_notifier *n);
+
+/**
+ * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
+ * given device.
+ * @hdmi_dev: HDMI device that sends the events.
+ * @conn_name: the connector name from which the event occurs. May be NULL
+ * if there is always only one HDMI connector created by the HDMI device.
+ * @adap: the cec adapter that registered this notifier.
+ *
+ * If a notifier for device @dev and connector @conn_name already exists, then
+ * increase the refcount and return that notifier.
+ *
+ * If it doesn't exist, then allocate a new notifier struct and return a
+ * pointer to that new struct.
+ *
+ * Return NULL if the memory could not be allocated.
+ */
+struct cec_notifier *
+cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
+			       struct cec_adapter *adap);
+
+/**
+ * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
+ * refcount reaches 0.
+ * @n: notifier
+ */
+void cec_notifier_cec_adap_unregister(struct cec_notifier *n);
+
 /**
  * cec_notifier_set_phys_addr - set a new physical address.
  * @n: the CEC notifier
@@ -110,6 +164,30 @@ static inline void cec_notifier_put(struct cec_notifier *n)
 {
 }
 
+static inline struct cec_notifier *
+cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
+			   const struct cec_connector_info *conn_info)
+{
+	/* A non-NULL pointer is expected on success */
+	return (struct cec_notifier *)0xdeadfeed;
+}
+
+static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
+{
+}
+
+static inline struct cec_notifier *
+cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
+			       struct cec_adapter *adap)
+{
+	/* A non-NULL pointer is expected on success */
+	return (struct cec_notifier *)0xdeadfeed;
+}
+
+static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n)
+{
+}
+
 static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
 {
 }
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 04/13] cec: expose the new connector info API
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

From: Dariusz Marcinkiewicz <darekm@google.com>

Until now the connector info API was a kernel-internal API only.
This moves it to the public API and adds the new ioctl to retrieve
this information.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/cec/cec-adap.c |  2 ++
 drivers/media/cec/cec-api.c  | 16 ++++++++++++++++
 drivers/media/cec/cec-core.c |  5 -----
 include/media/cec.h          | 26 +-------------------------
 include/uapi/linux/cec.h     | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 52 insertions(+), 30 deletions(-)

diff --git a/drivers/media/cec/cec-adap.c b/drivers/media/cec/cec-adap.c
index 451c61bde4d4..059c83525024 100644
--- a/drivers/media/cec/cec-adap.c
+++ b/drivers/media/cec/cec-adap.c
@@ -319,6 +319,8 @@ static void cec_post_state_event(struct cec_adapter *adap)
 
 	ev.state_change.phys_addr = adap->phys_addr;
 	ev.state_change.log_addr_mask = adap->log_addrs.log_addr_mask;
+	ev.state_change.have_conn_info =
+		adap->conn_info.type != CEC_CONNECTOR_TYPE_NO_CONNECTOR;
 	cec_queue_event(adap, &ev);
 }
 
diff --git a/drivers/media/cec/cec-api.c b/drivers/media/cec/cec-api.c
index 12d676484472..cba0099beab2 100644
--- a/drivers/media/cec/cec-api.c
+++ b/drivers/media/cec/cec-api.c
@@ -187,6 +187,17 @@ static long cec_adap_s_log_addrs(struct cec_adapter *adap, struct cec_fh *fh,
 	return 0;
 }
 
+static long cec_adap_g_connector_info(struct cec_adapter *adap,
+				      struct cec_log_addrs __user *parg)
+{
+	if (!(adap->capabilities & CEC_CAP_CONNECTOR_INFO))
+		return -ENOTTY;
+	if (copy_to_user(parg, &adap->conn_info,
+			 sizeof(adap->conn_info)))
+		return -EFAULT;
+	return 0;
+}
+
 static long cec_transmit(struct cec_adapter *adap, struct cec_fh *fh,
 			 bool block, struct cec_msg __user *parg)
 {
@@ -506,6 +517,9 @@ static long cec_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	case CEC_ADAP_S_LOG_ADDRS:
 		return cec_adap_s_log_addrs(adap, fh, block, parg);
 
+	case CEC_ADAP_G_CONNECTOR_INFO:
+		return cec_adap_g_connector_info(adap, parg);
+
 	case CEC_TRANSMIT:
 		return cec_transmit(adap, fh, block, parg);
 
@@ -578,6 +592,8 @@ static int cec_open(struct inode *inode, struct file *filp)
 	/* Queue up initial state events */
 	ev.state_change.phys_addr = adap->phys_addr;
 	ev.state_change.log_addr_mask = adap->log_addrs.log_addr_mask;
+	ev.state_change.have_conn_info =
+		adap->conn_info.type != CEC_CONNECTOR_TYPE_NO_CONNECTOR;
 	cec_queue_event_fh(fh, &ev, 0);
 #ifdef CONFIG_CEC_PIN
 	if (adap->pin && adap->pin->ops->read_hpd) {
diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c
index e45b792d26fb..db7adffcdc76 100644
--- a/drivers/media/cec/cec-core.c
+++ b/drivers/media/cec/cec-core.c
@@ -189,11 +189,6 @@ static void cec_cec_notify(struct cec_adapter *adap, u16 pa)
 	cec_s_phys_addr(adap, pa, false);
 }
 
-void cec_notifier_register(struct cec_notifier *n,
-			   struct cec_adapter *adap,
-			   void (*callback)(struct cec_adapter *adap, u16 pa));
-void cec_notifier_unregister(struct cec_notifier *n);
-
 void cec_register_cec_notifier(struct cec_adapter *adap,
 			       struct cec_notifier *notifier)
 {
diff --git a/include/media/cec.h b/include/media/cec.h
index 45f2c98ed75b..2c30df40e2ce 100644
--- a/include/media/cec.h
+++ b/include/media/cec.h
@@ -17,9 +17,7 @@
 #include <linux/timer.h>
 #include <linux/cec-funcs.h>
 #include <media/rc-core.h>
-
-/* CEC_ADAP_G_CONNECTOR_INFO is available */
-#define CEC_CAP_CONNECTOR_INFO	0
+#include <media/cec-notifier.h>
 
 #define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \
 			  CEC_CAP_PASSTHROUGH | CEC_CAP_RC)
@@ -55,7 +53,6 @@ struct cec_devnode {
 struct cec_adapter;
 struct cec_data;
 struct cec_pin;
-struct cec_notifier;
 
 struct cec_data {
 	struct list_head list;
@@ -147,27 +144,6 @@ struct cec_adap_ops {
  */
 #define CEC_MAX_MSG_TX_QUEUE_SZ		(18 * 1)
 
-/**
- * struct cec_event_connector - tells if and which connector is associated
- * with the CEC adapter.
- * @card_no: drm card number
- * @connector_id: drm connector ID
- */
-struct cec_drm_connector_info {
-	__u32 card_no;
-	__u32 connector_id;
-};
-
-#define CEC_CONNECTOR_TYPE_NO_CONNECTOR	0
-#define CEC_CONNECTOR_TYPE_DRM		1
-struct cec_connector_info {
-	__u32 type;
-	union {
-		struct cec_drm_connector_info drm;
-		__u32 raw[16];
-	};
-};
-
 struct cec_adapter {
 	struct module *owner;
 	char name[32];
diff --git a/include/uapi/linux/cec.h b/include/uapi/linux/cec.h
index 5704fa0292b5..414df75c0ab8 100644
--- a/include/uapi/linux/cec.h
+++ b/include/uapi/linux/cec.h
@@ -317,6 +317,8 @@ static inline int cec_is_unconfigured(__u16 log_addr_mask)
 #define CEC_CAP_NEEDS_HPD	(1 << 6)
 /* Hardware can monitor CEC pin transitions */
 #define CEC_CAP_MONITOR_PIN	(1 << 7)
+/* CEC_ADAP_G_CONNECTOR_INFO is available */
+#define CEC_CAP_CONNECTOR_INFO	(1 << 8)
 
 /**
  * struct cec_caps - CEC capabilities structure.
@@ -398,10 +400,17 @@ struct cec_log_addrs {
  * struct cec_event_state_change - used when the CEC adapter changes state.
  * @phys_addr: the current physical address
  * @log_addr_mask: the current logical address mask
+ * @have_conn_info: if non-zero, then HDMI connector information is available.
+ *	This field is only valid if CEC_CAP_CONNECTOR_INFO is set. If that
+ *	capability is set and @have_conn_info is zero, then that indicates
+ *	that the HDMI connector device is not instantiated, either because
+ *	the HDMI driver is still configuring the device or because the HDMI
+ *	device was unbound.
  */
 struct cec_event_state_change {
 	__u16 phys_addr;
 	__u16 log_addr_mask;
+	__u16 have_conn_info;
 };
 
 /**
@@ -412,6 +421,27 @@ struct cec_event_lost_msgs {
 	__u32 lost_msgs;
 };
 
+/**
+ * struct cec_event_connector - tells if and which connector is associated
+ * with the CEC adapter.
+ * @card_no: drm card number
+ * @connector_id: drm connector ID
+ */
+struct cec_drm_connector_info {
+	__u32 card_no;
+	__u32 connector_id;
+};
+
+#define CEC_CONNECTOR_TYPE_NO_CONNECTOR	0
+#define CEC_CONNECTOR_TYPE_DRM		1
+struct cec_connector_info {
+	__u32 type;
+	union {
+		struct cec_drm_connector_info drm;
+		__u32 raw[16];
+	};
+};
+
 /**
  * struct cec_event - CEC event structure
  * @ts: the timestamp of when the event was sent.
@@ -476,6 +506,9 @@ struct cec_event {
 #define CEC_G_MODE		_IOR('a',  8, __u32)
 #define CEC_S_MODE		_IOW('a',  9, __u32)
 
+/* Gets the connector info */
+#define CEC_ADAP_G_CONNECTOR_INFO _IOR('a',  10, struct cec_connector_info)
+
 /*
  * The remainder of this header defines all CEC messages and operands.
  * The format matters since it the cec-ctl utility parses it to generate
-- 
2.20.1


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

* [PATCHv8 04/13] cec: expose the new connector info API
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

From: Dariusz Marcinkiewicz <darekm@google.com>

Until now the connector info API was a kernel-internal API only.
This moves it to the public API and adds the new ioctl to retrieve
this information.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/cec/cec-adap.c |  2 ++
 drivers/media/cec/cec-api.c  | 16 ++++++++++++++++
 drivers/media/cec/cec-core.c |  5 -----
 include/media/cec.h          | 26 +-------------------------
 include/uapi/linux/cec.h     | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 52 insertions(+), 30 deletions(-)

diff --git a/drivers/media/cec/cec-adap.c b/drivers/media/cec/cec-adap.c
index 451c61bde4d4..059c83525024 100644
--- a/drivers/media/cec/cec-adap.c
+++ b/drivers/media/cec/cec-adap.c
@@ -319,6 +319,8 @@ static void cec_post_state_event(struct cec_adapter *adap)
 
 	ev.state_change.phys_addr = adap->phys_addr;
 	ev.state_change.log_addr_mask = adap->log_addrs.log_addr_mask;
+	ev.state_change.have_conn_info =
+		adap->conn_info.type != CEC_CONNECTOR_TYPE_NO_CONNECTOR;
 	cec_queue_event(adap, &ev);
 }
 
diff --git a/drivers/media/cec/cec-api.c b/drivers/media/cec/cec-api.c
index 12d676484472..cba0099beab2 100644
--- a/drivers/media/cec/cec-api.c
+++ b/drivers/media/cec/cec-api.c
@@ -187,6 +187,17 @@ static long cec_adap_s_log_addrs(struct cec_adapter *adap, struct cec_fh *fh,
 	return 0;
 }
 
+static long cec_adap_g_connector_info(struct cec_adapter *adap,
+				      struct cec_log_addrs __user *parg)
+{
+	if (!(adap->capabilities & CEC_CAP_CONNECTOR_INFO))
+		return -ENOTTY;
+	if (copy_to_user(parg, &adap->conn_info,
+			 sizeof(adap->conn_info)))
+		return -EFAULT;
+	return 0;
+}
+
 static long cec_transmit(struct cec_adapter *adap, struct cec_fh *fh,
 			 bool block, struct cec_msg __user *parg)
 {
@@ -506,6 +517,9 @@ static long cec_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	case CEC_ADAP_S_LOG_ADDRS:
 		return cec_adap_s_log_addrs(adap, fh, block, parg);
 
+	case CEC_ADAP_G_CONNECTOR_INFO:
+		return cec_adap_g_connector_info(adap, parg);
+
 	case CEC_TRANSMIT:
 		return cec_transmit(adap, fh, block, parg);
 
@@ -578,6 +592,8 @@ static int cec_open(struct inode *inode, struct file *filp)
 	/* Queue up initial state events */
 	ev.state_change.phys_addr = adap->phys_addr;
 	ev.state_change.log_addr_mask = adap->log_addrs.log_addr_mask;
+	ev.state_change.have_conn_info =
+		adap->conn_info.type != CEC_CONNECTOR_TYPE_NO_CONNECTOR;
 	cec_queue_event_fh(fh, &ev, 0);
 #ifdef CONFIG_CEC_PIN
 	if (adap->pin && adap->pin->ops->read_hpd) {
diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c
index e45b792d26fb..db7adffcdc76 100644
--- a/drivers/media/cec/cec-core.c
+++ b/drivers/media/cec/cec-core.c
@@ -189,11 +189,6 @@ static void cec_cec_notify(struct cec_adapter *adap, u16 pa)
 	cec_s_phys_addr(adap, pa, false);
 }
 
-void cec_notifier_register(struct cec_notifier *n,
-			   struct cec_adapter *adap,
-			   void (*callback)(struct cec_adapter *adap, u16 pa));
-void cec_notifier_unregister(struct cec_notifier *n);
-
 void cec_register_cec_notifier(struct cec_adapter *adap,
 			       struct cec_notifier *notifier)
 {
diff --git a/include/media/cec.h b/include/media/cec.h
index 45f2c98ed75b..2c30df40e2ce 100644
--- a/include/media/cec.h
+++ b/include/media/cec.h
@@ -17,9 +17,7 @@
 #include <linux/timer.h>
 #include <linux/cec-funcs.h>
 #include <media/rc-core.h>
-
-/* CEC_ADAP_G_CONNECTOR_INFO is available */
-#define CEC_CAP_CONNECTOR_INFO	0
+#include <media/cec-notifier.h>
 
 #define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \
 			  CEC_CAP_PASSTHROUGH | CEC_CAP_RC)
@@ -55,7 +53,6 @@ struct cec_devnode {
 struct cec_adapter;
 struct cec_data;
 struct cec_pin;
-struct cec_notifier;
 
 struct cec_data {
 	struct list_head list;
@@ -147,27 +144,6 @@ struct cec_adap_ops {
  */
 #define CEC_MAX_MSG_TX_QUEUE_SZ		(18 * 1)
 
-/**
- * struct cec_event_connector - tells if and which connector is associated
- * with the CEC adapter.
- * @card_no: drm card number
- * @connector_id: drm connector ID
- */
-struct cec_drm_connector_info {
-	__u32 card_no;
-	__u32 connector_id;
-};
-
-#define CEC_CONNECTOR_TYPE_NO_CONNECTOR	0
-#define CEC_CONNECTOR_TYPE_DRM		1
-struct cec_connector_info {
-	__u32 type;
-	union {
-		struct cec_drm_connector_info drm;
-		__u32 raw[16];
-	};
-};
-
 struct cec_adapter {
 	struct module *owner;
 	char name[32];
diff --git a/include/uapi/linux/cec.h b/include/uapi/linux/cec.h
index 5704fa0292b5..414df75c0ab8 100644
--- a/include/uapi/linux/cec.h
+++ b/include/uapi/linux/cec.h
@@ -317,6 +317,8 @@ static inline int cec_is_unconfigured(__u16 log_addr_mask)
 #define CEC_CAP_NEEDS_HPD	(1 << 6)
 /* Hardware can monitor CEC pin transitions */
 #define CEC_CAP_MONITOR_PIN	(1 << 7)
+/* CEC_ADAP_G_CONNECTOR_INFO is available */
+#define CEC_CAP_CONNECTOR_INFO	(1 << 8)
 
 /**
  * struct cec_caps - CEC capabilities structure.
@@ -398,10 +400,17 @@ struct cec_log_addrs {
  * struct cec_event_state_change - used when the CEC adapter changes state.
  * @phys_addr: the current physical address
  * @log_addr_mask: the current logical address mask
+ * @have_conn_info: if non-zero, then HDMI connector information is available.
+ *	This field is only valid if CEC_CAP_CONNECTOR_INFO is set. If that
+ *	capability is set and @have_conn_info is zero, then that indicates
+ *	that the HDMI connector device is not instantiated, either because
+ *	the HDMI driver is still configuring the device or because the HDMI
+ *	device was unbound.
  */
 struct cec_event_state_change {
 	__u16 phys_addr;
 	__u16 log_addr_mask;
+	__u16 have_conn_info;
 };
 
 /**
@@ -412,6 +421,27 @@ struct cec_event_lost_msgs {
 	__u32 lost_msgs;
 };
 
+/**
+ * struct cec_event_connector - tells if and which connector is associated
+ * with the CEC adapter.
+ * @card_no: drm card number
+ * @connector_id: drm connector ID
+ */
+struct cec_drm_connector_info {
+	__u32 card_no;
+	__u32 connector_id;
+};
+
+#define CEC_CONNECTOR_TYPE_NO_CONNECTOR	0
+#define CEC_CONNECTOR_TYPE_DRM		1
+struct cec_connector_info {
+	__u32 type;
+	union {
+		struct cec_drm_connector_info drm;
+		__u32 raw[16];
+	};
+};
+
 /**
  * struct cec_event - CEC event structure
  * @ts: the timestamp of when the event was sent.
@@ -476,6 +506,9 @@ struct cec_event {
 #define CEC_G_MODE		_IOR('a',  8, __u32)
 #define CEC_S_MODE		_IOW('a',  9, __u32)
 
+/* Gets the connector info */
+#define CEC_ADAP_G_CONNECTOR_INFO _IOR('a',  10, struct cec_connector_info)
+
 /*
  * The remainder of this header defines all CEC messages and operands.
  * The format matters since it the cec-ctl utility parses it to generate
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 05/13] cec: document CEC_ADAP_G_CONNECTOR_INFO
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

Document the new CEC_ADAP_G_CONNECTOR_INFO ioctl.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 Documentation/media/uapi/cec/cec-funcs.rst    |   1 +
 .../uapi/cec/cec-ioc-adap-g-conn-info.rst     | 109 ++++++++++++++++++
 2 files changed, 110 insertions(+)
 create mode 100644 Documentation/media/uapi/cec/cec-ioc-adap-g-conn-info.rst

diff --git a/Documentation/media/uapi/cec/cec-funcs.rst b/Documentation/media/uapi/cec/cec-funcs.rst
index 620590b168c9..dc6da9c639a8 100644
--- a/Documentation/media/uapi/cec/cec-funcs.rst
+++ b/Documentation/media/uapi/cec/cec-funcs.rst
@@ -24,6 +24,7 @@ Function Reference
     cec-ioc-adap-g-caps
     cec-ioc-adap-g-log-addrs
     cec-ioc-adap-g-phys-addr
+    cec-ioc-adap-g-conn-info
     cec-ioc-dqevent
     cec-ioc-g-mode
     cec-ioc-receive
diff --git a/Documentation/media/uapi/cec/cec-ioc-adap-g-conn-info.rst b/Documentation/media/uapi/cec/cec-ioc-adap-g-conn-info.rst
new file mode 100644
index 000000000000..87f475d7dfed
--- /dev/null
+++ b/Documentation/media/uapi/cec/cec-ioc-adap-g-conn-info.rst
@@ -0,0 +1,109 @@
+.. SPDX-License-Identifier: GPL-2.0
+..
+.. Copyright 2019 Google LLC
+..
+.. This documentation is free software; you can redistribute it and/or
+.. modify it under the terms of the GNU General Public License
+.. version 2 as published by the Free Software Foundation.
+..
+.. This documentation is distributed in the hope that it will be useful,
+.. but WITHOUT ANY WARRANTY; without even the implied warranty of
+.. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.. GNU General Public License for more details.
+..
+.. _CEC_ADAP_G_CONNECTOR_INFO:
+
+*******************************
+ioctl CEC_ADAP_G_CONNECTOR_INFO
+*******************************
+
+Name
+====
+
+CEC_ADAP_G_CONNECTOR_INFO - Query HDMI connector information
+
+Synopsis
+========
+
+.. c:function:: int ioctl( int fd, CEC_ADAP_G_CONNECTOR_INFO, struct cec_connector_info *argp )
+    :name: CEC_ADAP_G_CONNECTOR_INFO
+
+Arguments
+=========
+
+``fd``
+    File descriptor returned by :c:func:`open() <cec-open>`.
+
+``argp``
+
+
+Description
+===========
+
+Using this ioctl an application can learn which HDMI connector this CEC
+device corresponds to. While calling this ioctl the application should
+provide pointer to a cec_connector_info struct which will be populated
+by the kernel with the info provided by the adapter's driver. Not all
+drivers supply this information.
+
+.. tabularcolumns:: |p{1.0cm}|p{4.4cm}|p{2.5cm}|p{9.6cm}|
+
+.. c:type:: cec_connector_info
+
+.. flat-table:: struct cec_connector_info
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 1 8
+
+    * - __u32
+      - ``type``
+      - The type of connector this adapter is associated with.
+    * - union
+      - ``(anonymous)``
+      -
+    * -
+      - ``struct cec_drm_connector_info``
+      - drm
+      - :ref:`cec-drm-connector-info`.
+
+
+.. tabularcolumns:: |p{4.4cm}|p{2.5cm}|p{10.6cm}|
+
+.. _connector-type:
+
+.. flat-table:: Connector types
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       3 1 8
+
+    * .. _`CEC-CONNECTOR-TYPE-NO-CONNECTOR`:
+
+      - ``CEC_CONNECTOR_TYPE_NO_CONNECTOR``
+      - 0
+      - No connector is associated with the adapter/the information is not provided by the driver.
+    * .. _`CEC-CONNECTOR-TYPE-DRM`:
+
+      - ``CEC_CONNECTOR_TYPE_DRM``
+      - 1
+      - Indicates that a DRM connector is associated with this adapter. Info about the
+        connector can be found in :ref:`cec-drm-connector-info`.
+
+.. tabularcolumns:: |p{4.4cm}|p{2.5cm}|p{10.6cm}|
+
+.. c:type:: cec_drm_connector_info
+
+.. _cec-drm-connector-info:
+
+.. flat-table:: struct cec_drm_connector_info
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       3 1 8
+
+    * .. _`CEC-DRM-CONNECTOR-TYPE-CARD-NO`:
+
+      - __u32
+      - ``card_no``
+      - DRM card number - the digit from a card's path, e.g. 0 in case of /dev/card0.
+    * .. _`CEC-DRM-CONNECTOR-TYPE-CONNECTOR_ID`:
+
+      - __u32
-- 
2.20.1


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

* [PATCHv8 05/13] cec: document CEC_ADAP_G_CONNECTOR_INFO
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

Document the new CEC_ADAP_G_CONNECTOR_INFO ioctl.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 Documentation/media/uapi/cec/cec-funcs.rst    |   1 +
 .../uapi/cec/cec-ioc-adap-g-conn-info.rst     | 109 ++++++++++++++++++
 2 files changed, 110 insertions(+)
 create mode 100644 Documentation/media/uapi/cec/cec-ioc-adap-g-conn-info.rst

diff --git a/Documentation/media/uapi/cec/cec-funcs.rst b/Documentation/media/uapi/cec/cec-funcs.rst
index 620590b168c9..dc6da9c639a8 100644
--- a/Documentation/media/uapi/cec/cec-funcs.rst
+++ b/Documentation/media/uapi/cec/cec-funcs.rst
@@ -24,6 +24,7 @@ Function Reference
     cec-ioc-adap-g-caps
     cec-ioc-adap-g-log-addrs
     cec-ioc-adap-g-phys-addr
+    cec-ioc-adap-g-conn-info
     cec-ioc-dqevent
     cec-ioc-g-mode
     cec-ioc-receive
diff --git a/Documentation/media/uapi/cec/cec-ioc-adap-g-conn-info.rst b/Documentation/media/uapi/cec/cec-ioc-adap-g-conn-info.rst
new file mode 100644
index 000000000000..87f475d7dfed
--- /dev/null
+++ b/Documentation/media/uapi/cec/cec-ioc-adap-g-conn-info.rst
@@ -0,0 +1,109 @@
+.. SPDX-License-Identifier: GPL-2.0
+..
+.. Copyright 2019 Google LLC
+..
+.. This documentation is free software; you can redistribute it and/or
+.. modify it under the terms of the GNU General Public License
+.. version 2 as published by the Free Software Foundation.
+..
+.. This documentation is distributed in the hope that it will be useful,
+.. but WITHOUT ANY WARRANTY; without even the implied warranty of
+.. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.. GNU General Public License for more details.
+..
+.. _CEC_ADAP_G_CONNECTOR_INFO:
+
+*******************************
+ioctl CEC_ADAP_G_CONNECTOR_INFO
+*******************************
+
+Name
+====
+
+CEC_ADAP_G_CONNECTOR_INFO - Query HDMI connector information
+
+Synopsis
+========
+
+.. c:function:: int ioctl( int fd, CEC_ADAP_G_CONNECTOR_INFO, struct cec_connector_info *argp )
+    :name: CEC_ADAP_G_CONNECTOR_INFO
+
+Arguments
+=========
+
+``fd``
+    File descriptor returned by :c:func:`open() <cec-open>`.
+
+``argp``
+
+
+Description
+===========
+
+Using this ioctl an application can learn which HDMI connector this CEC
+device corresponds to. While calling this ioctl the application should
+provide pointer to a cec_connector_info struct which will be populated
+by the kernel with the info provided by the adapter's driver. Not all
+drivers supply this information.
+
+.. tabularcolumns:: |p{1.0cm}|p{4.4cm}|p{2.5cm}|p{9.6cm}|
+
+.. c:type:: cec_connector_info
+
+.. flat-table:: struct cec_connector_info
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 1 8
+
+    * - __u32
+      - ``type``
+      - The type of connector this adapter is associated with.
+    * - union
+      - ``(anonymous)``
+      -
+    * -
+      - ``struct cec_drm_connector_info``
+      - drm
+      - :ref:`cec-drm-connector-info`.
+
+
+.. tabularcolumns:: |p{4.4cm}|p{2.5cm}|p{10.6cm}|
+
+.. _connector-type:
+
+.. flat-table:: Connector types
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       3 1 8
+
+    * .. _`CEC-CONNECTOR-TYPE-NO-CONNECTOR`:
+
+      - ``CEC_CONNECTOR_TYPE_NO_CONNECTOR``
+      - 0
+      - No connector is associated with the adapter/the information is not provided by the driver.
+    * .. _`CEC-CONNECTOR-TYPE-DRM`:
+
+      - ``CEC_CONNECTOR_TYPE_DRM``
+      - 1
+      - Indicates that a DRM connector is associated with this adapter. Info about the
+        connector can be found in :ref:`cec-drm-connector-info`.
+
+.. tabularcolumns:: |p{4.4cm}|p{2.5cm}|p{10.6cm}|
+
+.. c:type:: cec_drm_connector_info
+
+.. _cec-drm-connector-info:
+
+.. flat-table:: struct cec_drm_connector_info
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       3 1 8
+
+    * .. _`CEC-DRM-CONNECTOR-TYPE-CARD-NO`:
+
+      - __u32
+      - ``card_no``
+      - DRM card number - the digit from a card's path, e.g. 0 in case of /dev/card0.
+    * .. _`CEC-DRM-CONNECTOR-TYPE-CONNECTOR_ID`:
+
+      - __u32
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 06/13] drm_dp_cec: add connector info support.
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

From: Dariusz Marcinkiewicz <darekm@google.com>

Pass the connector info to the CEC adapter. This makes it possible
to associate the CEC adapter with the corresponding drm connector.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 .../display/amdgpu_dm/amdgpu_dm_mst_types.c   |  2 +-
 drivers/gpu/drm/drm_dp_cec.c                  | 25 ++++++++++++-------
 drivers/gpu/drm/i915/intel_dp.c               |  4 +--
 drivers/gpu/drm/nouveau/nouveau_connector.c   |  3 +--
 include/drm/drm_dp_helper.h                   | 14 +++++------
 5 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
index 6e205ee36ac3..7f2eb4eb1035 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -394,7 +394,7 @@ void amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,
 
 	drm_dp_aux_register(&aconnector->dm_dp_aux.aux);
 	drm_dp_cec_register_connector(&aconnector->dm_dp_aux.aux,
-				      aconnector->base.name, dm->adev->dev);
+				      &aconnector->base);
 	aconnector->mst_mgr.cbs = &dm_mst_cbs;
 	drm_dp_mst_topology_mgr_init(
 		&aconnector->mst_mgr,
diff --git a/drivers/gpu/drm/drm_dp_cec.c b/drivers/gpu/drm/drm_dp_cec.c
index b15cee85b702..b457c16c3a8b 100644
--- a/drivers/gpu/drm/drm_dp_cec.c
+++ b/drivers/gpu/drm/drm_dp_cec.c
@@ -8,7 +8,9 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <drm/drm_connector.h>
 #include <drm/drm_dp_helper.h>
+#include <drm/drmP.h>
 #include <media/cec.h>
 
 /*
@@ -295,7 +297,10 @@ static void drm_dp_cec_unregister_work(struct work_struct *work)
  */
 void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid)
 {
-	u32 cec_caps = CEC_CAP_DEFAULTS | CEC_CAP_NEEDS_HPD;
+	struct drm_connector *connector = aux->cec.connector;
+	u32 cec_caps = CEC_CAP_DEFAULTS | CEC_CAP_NEEDS_HPD |
+		       CEC_CAP_CONNECTOR_INFO;
+	struct cec_connector_info conn_info;
 	unsigned int num_las = 1;
 	u8 cap;
 
@@ -344,13 +349,17 @@ void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid)
 
 	/* Create a new adapter */
 	aux->cec.adap = cec_allocate_adapter(&drm_dp_cec_adap_ops,
-					     aux, aux->cec.name, cec_caps,
+					     aux, connector->name, cec_caps,
 					     num_las);
 	if (IS_ERR(aux->cec.adap)) {
 		aux->cec.adap = NULL;
 		goto unlock;
 	}
-	if (cec_register_adapter(aux->cec.adap, aux->cec.parent)) {
+
+	cec_fill_conn_info_from_drm(&conn_info, connector);
+	cec_s_conn_info(aux->cec.adap, &conn_info);
+
+	if (cec_register_adapter(aux->cec.adap, connector->dev->dev)) {
 		cec_delete_adapter(aux->cec.adap);
 		aux->cec.adap = NULL;
 	} else {
@@ -406,22 +415,20 @@ EXPORT_SYMBOL(drm_dp_cec_unset_edid);
 /**
  * drm_dp_cec_register_connector() - register a new connector
  * @aux: DisplayPort AUX channel
- * @name: name of the CEC device
- * @parent: parent device
+ * @connector: drm connector
  *
  * A new connector was registered with associated CEC adapter name and
  * CEC adapter parent device. After registering the name and parent
  * drm_dp_cec_set_edid() is called to check if the connector supports
  * CEC and to register a CEC adapter if that is the case.
  */
-void drm_dp_cec_register_connector(struct drm_dp_aux *aux, const char *name,
-				   struct device *parent)
+void drm_dp_cec_register_connector(struct drm_dp_aux *aux,
+				   struct drm_connector *connector)
 {
 	WARN_ON(aux->cec.adap);
 	if (WARN_ON(!aux->transfer))
 		return;
-	aux->cec.name = name;
-	aux->cec.parent = parent;
+	aux->cec.connector = connector;
 	INIT_DELAYED_WORK(&aux->cec.unregister_work,
 			  drm_dp_cec_unregister_work);
 }
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 560274d1c50b..1dfd16848e03 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -5518,7 +5518,6 @@ static int
 intel_dp_connector_register(struct drm_connector *connector)
 {
 	struct intel_dp *intel_dp = intel_attached_dp(connector);
-	struct drm_device *dev = connector->dev;
 	int ret;
 
 	ret = intel_connector_register(connector);
@@ -5533,8 +5532,7 @@ intel_dp_connector_register(struct drm_connector *connector)
 	intel_dp->aux.dev = connector->kdev;
 	ret = drm_dp_aux_register(&intel_dp->aux);
 	if (!ret)
-		drm_dp_cec_register_connector(&intel_dp->aux,
-					      connector->name, dev->dev);
+		drm_dp_cec_register_connector(&intel_dp->aux, connector);
 	return ret;
 }
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
index 4116ee62adaf..4438824ca88b 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.c
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -1413,8 +1413,7 @@ nouveau_connector_create(struct drm_device *dev,
 	switch (type) {
 	case DRM_MODE_CONNECTOR_DisplayPort:
 	case DRM_MODE_CONNECTOR_eDP:
-		drm_dp_cec_register_connector(&nv_connector->aux,
-					      connector->name, dev->dev);
+		drm_dp_cec_register_connector(&nv_connector->aux, connector);
 		break;
 	}
 
diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
index 97ce790a5b5a..eeb42abc343c 100644
--- a/include/drm/drm_dp_helper.h
+++ b/include/drm/drm_dp_helper.h
@@ -1208,6 +1208,7 @@ struct drm_dp_aux_msg {
 
 struct cec_adapter;
 struct edid;
+struct drm_connector;
 
 /**
  * struct drm_dp_aux_cec - DisplayPort CEC-Tunneling-over-AUX
@@ -1220,8 +1221,7 @@ struct edid;
 struct drm_dp_aux_cec {
 	struct mutex lock;
 	struct cec_adapter *adap;
-	const char *name;
-	struct device *parent;
+	struct drm_connector *connector;
 	struct delayed_work unregister_work;
 };
 
@@ -1418,8 +1418,8 @@ drm_dp_has_quirk(const struct drm_dp_desc *desc, enum drm_dp_quirk quirk)
 
 #ifdef CONFIG_DRM_DP_CEC
 void drm_dp_cec_irq(struct drm_dp_aux *aux);
-void drm_dp_cec_register_connector(struct drm_dp_aux *aux, const char *name,
-				   struct device *parent);
+void drm_dp_cec_register_connector(struct drm_dp_aux *aux,
+				   struct drm_connector *connector);
 void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux);
 void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid);
 void drm_dp_cec_unset_edid(struct drm_dp_aux *aux);
@@ -1428,9 +1428,9 @@ static inline void drm_dp_cec_irq(struct drm_dp_aux *aux)
 {
 }
 
-static inline void drm_dp_cec_register_connector(struct drm_dp_aux *aux,
-						 const char *name,
-						 struct device *parent)
+static inline void
+drm_dp_cec_register_connector(struct drm_dp_aux *aux,
+			      struct drm_connector *connector)
 {
 }
 
-- 
2.20.1


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

* [PATCHv8 06/13] drm_dp_cec: add connector info support.
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

From: Dariusz Marcinkiewicz <darekm@google.com>

Pass the connector info to the CEC adapter. This makes it possible
to associate the CEC adapter with the corresponding drm connector.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 .../display/amdgpu_dm/amdgpu_dm_mst_types.c   |  2 +-
 drivers/gpu/drm/drm_dp_cec.c                  | 25 ++++++++++++-------
 drivers/gpu/drm/i915/intel_dp.c               |  4 +--
 drivers/gpu/drm/nouveau/nouveau_connector.c   |  3 +--
 include/drm/drm_dp_helper.h                   | 14 +++++------
 5 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
index 6e205ee36ac3..7f2eb4eb1035 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -394,7 +394,7 @@ void amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,
 
 	drm_dp_aux_register(&aconnector->dm_dp_aux.aux);
 	drm_dp_cec_register_connector(&aconnector->dm_dp_aux.aux,
-				      aconnector->base.name, dm->adev->dev);
+				      &aconnector->base);
 	aconnector->mst_mgr.cbs = &dm_mst_cbs;
 	drm_dp_mst_topology_mgr_init(
 		&aconnector->mst_mgr,
diff --git a/drivers/gpu/drm/drm_dp_cec.c b/drivers/gpu/drm/drm_dp_cec.c
index b15cee85b702..b457c16c3a8b 100644
--- a/drivers/gpu/drm/drm_dp_cec.c
+++ b/drivers/gpu/drm/drm_dp_cec.c
@@ -8,7 +8,9 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <drm/drm_connector.h>
 #include <drm/drm_dp_helper.h>
+#include <drm/drmP.h>
 #include <media/cec.h>
 
 /*
@@ -295,7 +297,10 @@ static void drm_dp_cec_unregister_work(struct work_struct *work)
  */
 void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid)
 {
-	u32 cec_caps = CEC_CAP_DEFAULTS | CEC_CAP_NEEDS_HPD;
+	struct drm_connector *connector = aux->cec.connector;
+	u32 cec_caps = CEC_CAP_DEFAULTS | CEC_CAP_NEEDS_HPD |
+		       CEC_CAP_CONNECTOR_INFO;
+	struct cec_connector_info conn_info;
 	unsigned int num_las = 1;
 	u8 cap;
 
@@ -344,13 +349,17 @@ void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid)
 
 	/* Create a new adapter */
 	aux->cec.adap = cec_allocate_adapter(&drm_dp_cec_adap_ops,
-					     aux, aux->cec.name, cec_caps,
+					     aux, connector->name, cec_caps,
 					     num_las);
 	if (IS_ERR(aux->cec.adap)) {
 		aux->cec.adap = NULL;
 		goto unlock;
 	}
-	if (cec_register_adapter(aux->cec.adap, aux->cec.parent)) {
+
+	cec_fill_conn_info_from_drm(&conn_info, connector);
+	cec_s_conn_info(aux->cec.adap, &conn_info);
+
+	if (cec_register_adapter(aux->cec.adap, connector->dev->dev)) {
 		cec_delete_adapter(aux->cec.adap);
 		aux->cec.adap = NULL;
 	} else {
@@ -406,22 +415,20 @@ EXPORT_SYMBOL(drm_dp_cec_unset_edid);
 /**
  * drm_dp_cec_register_connector() - register a new connector
  * @aux: DisplayPort AUX channel
- * @name: name of the CEC device
- * @parent: parent device
+ * @connector: drm connector
  *
  * A new connector was registered with associated CEC adapter name and
  * CEC adapter parent device. After registering the name and parent
  * drm_dp_cec_set_edid() is called to check if the connector supports
  * CEC and to register a CEC adapter if that is the case.
  */
-void drm_dp_cec_register_connector(struct drm_dp_aux *aux, const char *name,
-				   struct device *parent)
+void drm_dp_cec_register_connector(struct drm_dp_aux *aux,
+				   struct drm_connector *connector)
 {
 	WARN_ON(aux->cec.adap);
 	if (WARN_ON(!aux->transfer))
 		return;
-	aux->cec.name = name;
-	aux->cec.parent = parent;
+	aux->cec.connector = connector;
 	INIT_DELAYED_WORK(&aux->cec.unregister_work,
 			  drm_dp_cec_unregister_work);
 }
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 560274d1c50b..1dfd16848e03 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -5518,7 +5518,6 @@ static int
 intel_dp_connector_register(struct drm_connector *connector)
 {
 	struct intel_dp *intel_dp = intel_attached_dp(connector);
-	struct drm_device *dev = connector->dev;
 	int ret;
 
 	ret = intel_connector_register(connector);
@@ -5533,8 +5532,7 @@ intel_dp_connector_register(struct drm_connector *connector)
 	intel_dp->aux.dev = connector->kdev;
 	ret = drm_dp_aux_register(&intel_dp->aux);
 	if (!ret)
-		drm_dp_cec_register_connector(&intel_dp->aux,
-					      connector->name, dev->dev);
+		drm_dp_cec_register_connector(&intel_dp->aux, connector);
 	return ret;
 }
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
index 4116ee62adaf..4438824ca88b 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.c
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -1413,8 +1413,7 @@ nouveau_connector_create(struct drm_device *dev,
 	switch (type) {
 	case DRM_MODE_CONNECTOR_DisplayPort:
 	case DRM_MODE_CONNECTOR_eDP:
-		drm_dp_cec_register_connector(&nv_connector->aux,
-					      connector->name, dev->dev);
+		drm_dp_cec_register_connector(&nv_connector->aux, connector);
 		break;
 	}
 
diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
index 97ce790a5b5a..eeb42abc343c 100644
--- a/include/drm/drm_dp_helper.h
+++ b/include/drm/drm_dp_helper.h
@@ -1208,6 +1208,7 @@ struct drm_dp_aux_msg {
 
 struct cec_adapter;
 struct edid;
+struct drm_connector;
 
 /**
  * struct drm_dp_aux_cec - DisplayPort CEC-Tunneling-over-AUX
@@ -1220,8 +1221,7 @@ struct edid;
 struct drm_dp_aux_cec {
 	struct mutex lock;
 	struct cec_adapter *adap;
-	const char *name;
-	struct device *parent;
+	struct drm_connector *connector;
 	struct delayed_work unregister_work;
 };
 
@@ -1418,8 +1418,8 @@ drm_dp_has_quirk(const struct drm_dp_desc *desc, enum drm_dp_quirk quirk)
 
 #ifdef CONFIG_DRM_DP_CEC
 void drm_dp_cec_irq(struct drm_dp_aux *aux);
-void drm_dp_cec_register_connector(struct drm_dp_aux *aux, const char *name,
-				   struct device *parent);
+void drm_dp_cec_register_connector(struct drm_dp_aux *aux,
+				   struct drm_connector *connector);
 void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux);
 void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid);
 void drm_dp_cec_unset_edid(struct drm_dp_aux *aux);
@@ -1428,9 +1428,9 @@ static inline void drm_dp_cec_irq(struct drm_dp_aux *aux)
 {
 }
 
-static inline void drm_dp_cec_register_connector(struct drm_dp_aux *aux,
-						 const char *name,
-						 struct device *parent)
+static inline void
+drm_dp_cec_register_connector(struct drm_dp_aux *aux,
+			      struct drm_connector *connector)
 {
 }
 
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 07/13] drm/i915/intel_hdmi: use cec_notifier_conn_(un)register
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

From: Dariusz Marcinkiewicz <darekm@google.com>

Use the new cec_notifier_conn_(un)register() functions to
(un)register the notifier for the HDMI connector, and fill in
the cec_connector_info.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/i915/intel_hdmi.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 34be2cfd0ec8..05a5ccc1517e 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -2670,8 +2670,9 @@ intel_hdmi_connector_register(struct drm_connector *connector)
 
 static void intel_hdmi_destroy(struct drm_connector *connector)
 {
-	if (intel_attached_hdmi(connector)->cec_notifier)
-		cec_notifier_put(intel_attached_hdmi(connector)->cec_notifier);
+	struct cec_notifier *n = intel_attached_hdmi(connector)->cec_notifier;
+
+	cec_notifier_conn_unregister(n);
 
 	intel_connector_destroy(connector);
 }
@@ -2968,6 +2969,7 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
 	struct drm_device *dev = intel_encoder->base.dev;
 	struct drm_i915_private *dev_priv = to_i915(dev);
 	enum port port = intel_encoder->port;
+	struct cec_connector_info conn_info;
 
 	DRM_DEBUG_KMS("Adding HDMI connector on port %c\n",
 		      port_name(port));
@@ -3020,8 +3022,11 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
 		I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
 	}
 
-	intel_hdmi->cec_notifier = cec_notifier_get_conn(dev->dev,
-							 port_identifier(port));
+	cec_fill_conn_info_from_drm(&conn_info, connector);
+
+	intel_hdmi->cec_notifier =
+		cec_notifier_conn_register(dev->dev, port_identifier(port),
+					   &conn_info);
 	if (!intel_hdmi->cec_notifier)
 		DRM_DEBUG_KMS("CEC notifier get failed\n");
 }
-- 
2.20.1


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

* [PATCHv8 07/13] drm/i915/intel_hdmi: use cec_notifier_conn_(un)register
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

From: Dariusz Marcinkiewicz <darekm@google.com>

Use the new cec_notifier_conn_(un)register() functions to
(un)register the notifier for the HDMI connector, and fill in
the cec_connector_info.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/i915/intel_hdmi.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 34be2cfd0ec8..05a5ccc1517e 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -2670,8 +2670,9 @@ intel_hdmi_connector_register(struct drm_connector *connector)
 
 static void intel_hdmi_destroy(struct drm_connector *connector)
 {
-	if (intel_attached_hdmi(connector)->cec_notifier)
-		cec_notifier_put(intel_attached_hdmi(connector)->cec_notifier);
+	struct cec_notifier *n = intel_attached_hdmi(connector)->cec_notifier;
+
+	cec_notifier_conn_unregister(n);
 
 	intel_connector_destroy(connector);
 }
@@ -2968,6 +2969,7 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
 	struct drm_device *dev = intel_encoder->base.dev;
 	struct drm_i915_private *dev_priv = to_i915(dev);
 	enum port port = intel_encoder->port;
+	struct cec_connector_info conn_info;
 
 	DRM_DEBUG_KMS("Adding HDMI connector on port %c\n",
 		      port_name(port));
@@ -3020,8 +3022,11 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
 		I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
 	}
 
-	intel_hdmi->cec_notifier = cec_notifier_get_conn(dev->dev,
-							 port_identifier(port));
+	cec_fill_conn_info_from_drm(&conn_info, connector);
+
+	intel_hdmi->cec_notifier =
+		cec_notifier_conn_register(dev->dev, port_identifier(port),
+					   &conn_info);
 	if (!intel_hdmi->cec_notifier)
 		DRM_DEBUG_KMS("CEC notifier get failed\n");
 }
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 08/13] dw-hdmi-cec: use cec_notifier_cec_adap_(un)register
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

From: Dariusz Marcinkiewicz <darekm@google.com>

Use the new cec_notifier_cec_adap_(un)register() functions to
(un)register the notifier for the CEC adapter.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c
index 6c323510f128..6f7ecacb7d1f 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c
@@ -281,13 +281,14 @@ static int dw_hdmi_cec_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
-	cec->notify = cec_notifier_get(pdev->dev.parent);
+	cec->notify = cec_notifier_cec_adap_register(pdev->dev.parent,
+						     NULL, cec->adap);
 	if (!cec->notify)
 		return -ENOMEM;
 
 	ret = cec_register_adapter(cec->adap, pdev->dev.parent);
 	if (ret < 0) {
-		cec_notifier_put(cec->notify);
+		cec_notifier_cec_adap_unregister(cec->notify);
 		return ret;
 	}
 
@@ -297,8 +298,6 @@ static int dw_hdmi_cec_probe(struct platform_device *pdev)
 	 */
 	devm_remove_action(&pdev->dev, dw_hdmi_cec_del, cec);
 
-	cec_register_cec_notifier(cec->adap, cec->notify);
-
 	return 0;
 }
 
@@ -306,8 +305,8 @@ static int dw_hdmi_cec_remove(struct platform_device *pdev)
 {
 	struct dw_hdmi_cec *cec = platform_get_drvdata(pdev);
 
+	cec_notifier_cec_adap_unregister(cec->notify);
 	cec_unregister_adapter(cec->adap);
-	cec_notifier_put(cec->notify);
 
 	return 0;
 }
-- 
2.20.1


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

* [PATCHv8 08/13] dw-hdmi-cec: use cec_notifier_cec_adap_(un)register
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

From: Dariusz Marcinkiewicz <darekm@google.com>

Use the new cec_notifier_cec_adap_(un)register() functions to
(un)register the notifier for the CEC adapter.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c
index 6c323510f128..6f7ecacb7d1f 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c
@@ -281,13 +281,14 @@ static int dw_hdmi_cec_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
-	cec->notify = cec_notifier_get(pdev->dev.parent);
+	cec->notify = cec_notifier_cec_adap_register(pdev->dev.parent,
+						     NULL, cec->adap);
 	if (!cec->notify)
 		return -ENOMEM;
 
 	ret = cec_register_adapter(cec->adap, pdev->dev.parent);
 	if (ret < 0) {
-		cec_notifier_put(cec->notify);
+		cec_notifier_cec_adap_unregister(cec->notify);
 		return ret;
 	}
 
@@ -297,8 +298,6 @@ static int dw_hdmi_cec_probe(struct platform_device *pdev)
 	 */
 	devm_remove_action(&pdev->dev, dw_hdmi_cec_del, cec);
 
-	cec_register_cec_notifier(cec->adap, cec->notify);
-
 	return 0;
 }
 
@@ -306,8 +305,8 @@ static int dw_hdmi_cec_remove(struct platform_device *pdev)
 {
 	struct dw_hdmi_cec *cec = platform_get_drvdata(pdev);
 
+	cec_notifier_cec_adap_unregister(cec->notify);
 	cec_unregister_adapter(cec->adap);
-	cec_notifier_put(cec->notify);
 
 	return 0;
 }
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 09/13] dw-hdmi: use cec_notifier_conn_(un)register
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

From: Dariusz Marcinkiewicz <darekm@google.com>

Use the new cec_notifier_conn_(un)register() functions to
(un)register the notifier for the HDMI connector, and fill in
the cec_connector_info.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 104 ++++++++++++----------
 1 file changed, 58 insertions(+), 46 deletions(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
index 045b1b13fd0e..fc4d3b5f71d0 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
@@ -133,6 +133,8 @@ struct dw_hdmi {
 	struct drm_connector connector;
 	struct drm_bridge bridge;
 
+	int irq;
+
 	unsigned int version;
 
 	struct platform_device *audio;
@@ -184,6 +186,7 @@ struct dw_hdmi {
 	void (*enable_audio)(struct dw_hdmi *hdmi);
 	void (*disable_audio)(struct dw_hdmi *hdmi);
 
+	bool cec_configured;
 	struct cec_notifier *cec_notifier;
 };
 
@@ -2108,11 +2111,35 @@ static const struct drm_connector_helper_funcs dw_hdmi_connector_helper_funcs =
 	.get_modes = dw_hdmi_connector_get_modes,
 };
 
+static void dw_hdmi_cec_enable(struct dw_hdmi *hdmi)
+{
+	mutex_lock(&hdmi->mutex);
+	hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CECCLK_DISABLE;
+	hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
+	mutex_unlock(&hdmi->mutex);
+}
+
+static void dw_hdmi_cec_disable(struct dw_hdmi *hdmi)
+{
+	mutex_lock(&hdmi->mutex);
+	hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CECCLK_DISABLE;
+	hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
+	mutex_unlock(&hdmi->mutex);
+}
+
+static const struct dw_hdmi_cec_ops dw_hdmi_cec_ops = {
+	.write = hdmi_writeb,
+	.read = hdmi_readb,
+	.enable = dw_hdmi_cec_enable,
+	.disable = dw_hdmi_cec_disable,
+};
+
 static int dw_hdmi_bridge_attach(struct drm_bridge *bridge)
 {
 	struct dw_hdmi *hdmi = bridge->driver_private;
 	struct drm_encoder *encoder = bridge->encoder;
 	struct drm_connector *connector = &hdmi->connector;
+	struct cec_connector_info conn_info;
 
 	connector->interlace_allowed = 1;
 	connector->polled = DRM_CONNECTOR_POLL_HPD;
@@ -2124,6 +2151,33 @@ static int dw_hdmi_bridge_attach(struct drm_bridge *bridge)
 
 	drm_connector_attach_encoder(connector, encoder);
 
+	cec_fill_conn_info_from_drm(&conn_info, connector);
+
+	hdmi->cec_notifier = cec_notifier_conn_register(hdmi->dev, NULL,
+							&conn_info);
+	if (!hdmi->cec_notifier)
+		return -ENOMEM;
+
+	if (hdmi->cec_configured) {
+		struct platform_device_info pdevinfo;
+		struct dw_hdmi_cec_data cec;
+
+		memset(&pdevinfo, 0, sizeof(pdevinfo));
+		pdevinfo.parent = hdmi->dev;
+		pdevinfo.id = PLATFORM_DEVID_AUTO;
+
+		cec.hdmi = hdmi;
+		cec.ops = &dw_hdmi_cec_ops;
+		cec.irq = hdmi->irq;
+
+		pdevinfo.name = "dw-hdmi-cec";
+		pdevinfo.data = &cec;
+		pdevinfo.size_data = sizeof(cec);
+		pdevinfo.dma_mask = 0;
+
+		hdmi->cec = platform_device_register_full(&pdevinfo);
+	}
+
 	return 0;
 }
 
@@ -2393,29 +2447,6 @@ static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi)
 	return -ENODEV;
 }
 
-static void dw_hdmi_cec_enable(struct dw_hdmi *hdmi)
-{
-	mutex_lock(&hdmi->mutex);
-	hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CECCLK_DISABLE;
-	hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
-	mutex_unlock(&hdmi->mutex);
-}
-
-static void dw_hdmi_cec_disable(struct dw_hdmi *hdmi)
-{
-	mutex_lock(&hdmi->mutex);
-	hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CECCLK_DISABLE;
-	hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
-	mutex_unlock(&hdmi->mutex);
-}
-
-static const struct dw_hdmi_cec_ops dw_hdmi_cec_ops = {
-	.write = hdmi_writeb,
-	.read = hdmi_readb,
-	.enable = dw_hdmi_cec_enable,
-	.disable = dw_hdmi_cec_disable,
-};
-
 static const struct regmap_config hdmi_regmap_8bit_config = {
 	.reg_bits	= 32,
 	.val_bits	= 8,
@@ -2438,7 +2469,6 @@ __dw_hdmi_probe(struct platform_device *pdev,
 	struct device_node *np = dev->of_node;
 	struct platform_device_info pdevinfo;
 	struct device_node *ddc_node;
-	struct dw_hdmi_cec_data cec;
 	struct dw_hdmi *hdmi;
 	struct resource *iores = NULL;
 	int irq;
@@ -2588,6 +2618,7 @@ __dw_hdmi_probe(struct platform_device *pdev,
 		ret = irq;
 		goto err_iahb;
 	}
+	hdmi->irq = irq;
 
 	ret = devm_request_threaded_irq(dev, irq, dw_hdmi_hardirq,
 					dw_hdmi_irq, IRQF_SHARED,
@@ -2595,12 +2626,6 @@ __dw_hdmi_probe(struct platform_device *pdev,
 	if (ret)
 		goto err_iahb;
 
-	hdmi->cec_notifier = cec_notifier_get(dev);
-	if (!hdmi->cec_notifier) {
-		ret = -ENOMEM;
-		goto err_iahb;
-	}
-
 	/*
 	 * To prevent overflows in HDMI_IH_FC_STAT2, set the clk regenerator
 	 * N and cts values before enabling phy
@@ -2663,18 +2688,8 @@ __dw_hdmi_probe(struct platform_device *pdev,
 		hdmi->audio = platform_device_register_full(&pdevinfo);
 	}
 
-	if (config0 & HDMI_CONFIG0_CEC) {
-		cec.hdmi = hdmi;
-		cec.ops = &dw_hdmi_cec_ops;
-		cec.irq = irq;
-
-		pdevinfo.name = "dw-hdmi-cec";
-		pdevinfo.data = &cec;
-		pdevinfo.size_data = sizeof(cec);
-		pdevinfo.dma_mask = 0;
-
-		hdmi->cec = platform_device_register_full(&pdevinfo);
-	}
+	if (config0 & HDMI_CONFIG0_CEC)
+		hdmi->cec_configured = true;
 
 	/* Reset HDMI DDC I2C master controller and mute I2CM interrupts */
 	if (hdmi->i2c)
@@ -2688,9 +2703,6 @@ __dw_hdmi_probe(struct platform_device *pdev,
 		hdmi->ddc = NULL;
 	}
 
-	if (hdmi->cec_notifier)
-		cec_notifier_put(hdmi->cec_notifier);
-
 	clk_disable_unprepare(hdmi->iahb_clk);
 	if (hdmi->cec_clk)
 		clk_disable_unprepare(hdmi->cec_clk);
@@ -2713,7 +2725,7 @@ static void __dw_hdmi_remove(struct dw_hdmi *hdmi)
 	hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0);
 
 	if (hdmi->cec_notifier)
-		cec_notifier_put(hdmi->cec_notifier);
+		cec_notifier_conn_unregister(hdmi->cec_notifier);
 
 	clk_disable_unprepare(hdmi->iahb_clk);
 	clk_disable_unprepare(hdmi->isfr_clk);
-- 
2.20.1


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

* [PATCHv8 09/13] dw-hdmi: use cec_notifier_conn_(un)register
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

From: Dariusz Marcinkiewicz <darekm@google.com>

Use the new cec_notifier_conn_(un)register() functions to
(un)register the notifier for the HDMI connector, and fill in
the cec_connector_info.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 104 ++++++++++++----------
 1 file changed, 58 insertions(+), 46 deletions(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
index 045b1b13fd0e..fc4d3b5f71d0 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
@@ -133,6 +133,8 @@ struct dw_hdmi {
 	struct drm_connector connector;
 	struct drm_bridge bridge;
 
+	int irq;
+
 	unsigned int version;
 
 	struct platform_device *audio;
@@ -184,6 +186,7 @@ struct dw_hdmi {
 	void (*enable_audio)(struct dw_hdmi *hdmi);
 	void (*disable_audio)(struct dw_hdmi *hdmi);
 
+	bool cec_configured;
 	struct cec_notifier *cec_notifier;
 };
 
@@ -2108,11 +2111,35 @@ static const struct drm_connector_helper_funcs dw_hdmi_connector_helper_funcs =
 	.get_modes = dw_hdmi_connector_get_modes,
 };
 
+static void dw_hdmi_cec_enable(struct dw_hdmi *hdmi)
+{
+	mutex_lock(&hdmi->mutex);
+	hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CECCLK_DISABLE;
+	hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
+	mutex_unlock(&hdmi->mutex);
+}
+
+static void dw_hdmi_cec_disable(struct dw_hdmi *hdmi)
+{
+	mutex_lock(&hdmi->mutex);
+	hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CECCLK_DISABLE;
+	hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
+	mutex_unlock(&hdmi->mutex);
+}
+
+static const struct dw_hdmi_cec_ops dw_hdmi_cec_ops = {
+	.write = hdmi_writeb,
+	.read = hdmi_readb,
+	.enable = dw_hdmi_cec_enable,
+	.disable = dw_hdmi_cec_disable,
+};
+
 static int dw_hdmi_bridge_attach(struct drm_bridge *bridge)
 {
 	struct dw_hdmi *hdmi = bridge->driver_private;
 	struct drm_encoder *encoder = bridge->encoder;
 	struct drm_connector *connector = &hdmi->connector;
+	struct cec_connector_info conn_info;
 
 	connector->interlace_allowed = 1;
 	connector->polled = DRM_CONNECTOR_POLL_HPD;
@@ -2124,6 +2151,33 @@ static int dw_hdmi_bridge_attach(struct drm_bridge *bridge)
 
 	drm_connector_attach_encoder(connector, encoder);
 
+	cec_fill_conn_info_from_drm(&conn_info, connector);
+
+	hdmi->cec_notifier = cec_notifier_conn_register(hdmi->dev, NULL,
+							&conn_info);
+	if (!hdmi->cec_notifier)
+		return -ENOMEM;
+
+	if (hdmi->cec_configured) {
+		struct platform_device_info pdevinfo;
+		struct dw_hdmi_cec_data cec;
+
+		memset(&pdevinfo, 0, sizeof(pdevinfo));
+		pdevinfo.parent = hdmi->dev;
+		pdevinfo.id = PLATFORM_DEVID_AUTO;
+
+		cec.hdmi = hdmi;
+		cec.ops = &dw_hdmi_cec_ops;
+		cec.irq = hdmi->irq;
+
+		pdevinfo.name = "dw-hdmi-cec";
+		pdevinfo.data = &cec;
+		pdevinfo.size_data = sizeof(cec);
+		pdevinfo.dma_mask = 0;
+
+		hdmi->cec = platform_device_register_full(&pdevinfo);
+	}
+
 	return 0;
 }
 
@@ -2393,29 +2447,6 @@ static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi)
 	return -ENODEV;
 }
 
-static void dw_hdmi_cec_enable(struct dw_hdmi *hdmi)
-{
-	mutex_lock(&hdmi->mutex);
-	hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CECCLK_DISABLE;
-	hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
-	mutex_unlock(&hdmi->mutex);
-}
-
-static void dw_hdmi_cec_disable(struct dw_hdmi *hdmi)
-{
-	mutex_lock(&hdmi->mutex);
-	hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CECCLK_DISABLE;
-	hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
-	mutex_unlock(&hdmi->mutex);
-}
-
-static const struct dw_hdmi_cec_ops dw_hdmi_cec_ops = {
-	.write = hdmi_writeb,
-	.read = hdmi_readb,
-	.enable = dw_hdmi_cec_enable,
-	.disable = dw_hdmi_cec_disable,
-};
-
 static const struct regmap_config hdmi_regmap_8bit_config = {
 	.reg_bits	= 32,
 	.val_bits	= 8,
@@ -2438,7 +2469,6 @@ __dw_hdmi_probe(struct platform_device *pdev,
 	struct device_node *np = dev->of_node;
 	struct platform_device_info pdevinfo;
 	struct device_node *ddc_node;
-	struct dw_hdmi_cec_data cec;
 	struct dw_hdmi *hdmi;
 	struct resource *iores = NULL;
 	int irq;
@@ -2588,6 +2618,7 @@ __dw_hdmi_probe(struct platform_device *pdev,
 		ret = irq;
 		goto err_iahb;
 	}
+	hdmi->irq = irq;
 
 	ret = devm_request_threaded_irq(dev, irq, dw_hdmi_hardirq,
 					dw_hdmi_irq, IRQF_SHARED,
@@ -2595,12 +2626,6 @@ __dw_hdmi_probe(struct platform_device *pdev,
 	if (ret)
 		goto err_iahb;
 
-	hdmi->cec_notifier = cec_notifier_get(dev);
-	if (!hdmi->cec_notifier) {
-		ret = -ENOMEM;
-		goto err_iahb;
-	}
-
 	/*
 	 * To prevent overflows in HDMI_IH_FC_STAT2, set the clk regenerator
 	 * N and cts values before enabling phy
@@ -2663,18 +2688,8 @@ __dw_hdmi_probe(struct platform_device *pdev,
 		hdmi->audio = platform_device_register_full(&pdevinfo);
 	}
 
-	if (config0 & HDMI_CONFIG0_CEC) {
-		cec.hdmi = hdmi;
-		cec.ops = &dw_hdmi_cec_ops;
-		cec.irq = irq;
-
-		pdevinfo.name = "dw-hdmi-cec";
-		pdevinfo.data = &cec;
-		pdevinfo.size_data = sizeof(cec);
-		pdevinfo.dma_mask = 0;
-
-		hdmi->cec = platform_device_register_full(&pdevinfo);
-	}
+	if (config0 & HDMI_CONFIG0_CEC)
+		hdmi->cec_configured = true;
 
 	/* Reset HDMI DDC I2C master controller and mute I2CM interrupts */
 	if (hdmi->i2c)
@@ -2688,9 +2703,6 @@ __dw_hdmi_probe(struct platform_device *pdev,
 		hdmi->ddc = NULL;
 	}
 
-	if (hdmi->cec_notifier)
-		cec_notifier_put(hdmi->cec_notifier);
-
 	clk_disable_unprepare(hdmi->iahb_clk);
 	if (hdmi->cec_clk)
 		clk_disable_unprepare(hdmi->cec_clk);
@@ -2713,7 +2725,7 @@ static void __dw_hdmi_remove(struct dw_hdmi *hdmi)
 	hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0);
 
 	if (hdmi->cec_notifier)
-		cec_notifier_put(hdmi->cec_notifier);
+		cec_notifier_conn_unregister(hdmi->cec_notifier);
 
 	clk_disable_unprepare(hdmi->iahb_clk);
 	clk_disable_unprepare(hdmi->isfr_clk);
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 10/13] meson/ao-cec: use cec_notifier_cec_adap_(un)register
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

Use the new cec_notifier_cec_adap_(un)register() functions to
(un)register the notifier for the CEC adapter.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/platform/meson/ao-cec.c | 37 +++++++++++++--------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/media/platform/meson/ao-cec.c b/drivers/media/platform/meson/ao-cec.c
index facf9b029e79..b80eb8f9b422 100644
--- a/drivers/media/platform/meson/ao-cec.c
+++ b/drivers/media/platform/meson/ao-cec.c
@@ -616,20 +616,22 @@ static int meson_ao_cec_probe(struct platform_device *pdev)
 
 	spin_lock_init(&ao_cec->cec_reg_lock);
 
-	ao_cec->notify = cec_notifier_get(hdmi_dev);
-	if (!ao_cec->notify)
-		return -ENOMEM;
-
 	ao_cec->adap = cec_allocate_adapter(&meson_ao_cec_ops, ao_cec,
 					    "meson_ao_cec",
 					    CEC_CAP_LOG_ADDRS |
 					    CEC_CAP_TRANSMIT |
 					    CEC_CAP_RC |
-					    CEC_CAP_PASSTHROUGH,
+					    CEC_CAP_PASSTHROUGH |
+					    CEC_CAP_CONNECTOR_INFO,
 					    1); /* Use 1 for now */
-	if (IS_ERR(ao_cec->adap)) {
-		ret = PTR_ERR(ao_cec->adap);
-		goto out_probe_notify;
+	if (IS_ERR(ao_cec->adap))
+		return PTR_ERR(ao_cec->adap);
+
+	ao_cec->notify = cec_notifier_cec_adap_register(hdmi_dev, NULL,
+							ao_cec->adap);
+	if (!ao_cec->notify) {
+		ret = -ENOMEM;
+		goto out_probe_adapter;
 	}
 
 	ao_cec->adap->owner = THIS_MODULE;
@@ -638,7 +640,7 @@ static int meson_ao_cec_probe(struct platform_device *pdev)
 	ao_cec->base = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(ao_cec->base)) {
 		ret = PTR_ERR(ao_cec->base);
-		goto out_probe_adapter;
+		goto out_probe_notify;
 	}
 
 	irq = platform_get_irq(pdev, 0);
@@ -648,20 +650,20 @@ static int meson_ao_cec_probe(struct platform_device *pdev)
 					0, NULL, ao_cec);
 	if (ret) {
 		dev_err(&pdev->dev, "irq request failed\n");
-		goto out_probe_adapter;
+		goto out_probe_notify;
 	}
 
 	ao_cec->core = devm_clk_get(&pdev->dev, "core");
 	if (IS_ERR(ao_cec->core)) {
 		dev_err(&pdev->dev, "core clock request failed\n");
 		ret = PTR_ERR(ao_cec->core);
-		goto out_probe_adapter;
+		goto out_probe_notify;
 	}
 
 	ret = clk_prepare_enable(ao_cec->core);
 	if (ret) {
 		dev_err(&pdev->dev, "core clock enable failed\n");
-		goto out_probe_adapter;
+		goto out_probe_notify;
 	}
 
 	ret = clk_set_rate(ao_cec->core, CEC_CLK_RATE);
@@ -685,19 +687,17 @@ static int meson_ao_cec_probe(struct platform_device *pdev)
 	writel_relaxed(CEC_GEN_CNTL_RESET,
 		       ao_cec->base + CEC_GEN_CNTL_REG);
 
-	cec_register_cec_notifier(ao_cec->adap, ao_cec->notify);
-
 	return 0;
 
 out_probe_clk:
 	clk_disable_unprepare(ao_cec->core);
 
+out_probe_notify:
+	cec_notifier_cec_adap_unregister(ao_cec->notify);
+
 out_probe_adapter:
 	cec_delete_adapter(ao_cec->adap);
 
-out_probe_notify:
-	cec_notifier_put(ao_cec->notify);
-
 	dev_err(&pdev->dev, "CEC controller registration failed\n");
 
 	return ret;
@@ -709,10 +709,9 @@ static int meson_ao_cec_remove(struct platform_device *pdev)
 
 	clk_disable_unprepare(ao_cec->core);
 
+	cec_notifier_cec_adap_unregister(ao_cec->notify);
 	cec_unregister_adapter(ao_cec->adap);
 
-	cec_notifier_put(ao_cec->notify);
-
 	return 0;
 }
 
-- 
2.20.1


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

* [PATCHv8 10/13] meson/ao-cec: use cec_notifier_cec_adap_(un)register
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

Use the new cec_notifier_cec_adap_(un)register() functions to
(un)register the notifier for the CEC adapter.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/platform/meson/ao-cec.c | 37 +++++++++++++--------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/media/platform/meson/ao-cec.c b/drivers/media/platform/meson/ao-cec.c
index facf9b029e79..b80eb8f9b422 100644
--- a/drivers/media/platform/meson/ao-cec.c
+++ b/drivers/media/platform/meson/ao-cec.c
@@ -616,20 +616,22 @@ static int meson_ao_cec_probe(struct platform_device *pdev)
 
 	spin_lock_init(&ao_cec->cec_reg_lock);
 
-	ao_cec->notify = cec_notifier_get(hdmi_dev);
-	if (!ao_cec->notify)
-		return -ENOMEM;
-
 	ao_cec->adap = cec_allocate_adapter(&meson_ao_cec_ops, ao_cec,
 					    "meson_ao_cec",
 					    CEC_CAP_LOG_ADDRS |
 					    CEC_CAP_TRANSMIT |
 					    CEC_CAP_RC |
-					    CEC_CAP_PASSTHROUGH,
+					    CEC_CAP_PASSTHROUGH |
+					    CEC_CAP_CONNECTOR_INFO,
 					    1); /* Use 1 for now */
-	if (IS_ERR(ao_cec->adap)) {
-		ret = PTR_ERR(ao_cec->adap);
-		goto out_probe_notify;
+	if (IS_ERR(ao_cec->adap))
+		return PTR_ERR(ao_cec->adap);
+
+	ao_cec->notify = cec_notifier_cec_adap_register(hdmi_dev, NULL,
+							ao_cec->adap);
+	if (!ao_cec->notify) {
+		ret = -ENOMEM;
+		goto out_probe_adapter;
 	}
 
 	ao_cec->adap->owner = THIS_MODULE;
@@ -638,7 +640,7 @@ static int meson_ao_cec_probe(struct platform_device *pdev)
 	ao_cec->base = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(ao_cec->base)) {
 		ret = PTR_ERR(ao_cec->base);
-		goto out_probe_adapter;
+		goto out_probe_notify;
 	}
 
 	irq = platform_get_irq(pdev, 0);
@@ -648,20 +650,20 @@ static int meson_ao_cec_probe(struct platform_device *pdev)
 					0, NULL, ao_cec);
 	if (ret) {
 		dev_err(&pdev->dev, "irq request failed\n");
-		goto out_probe_adapter;
+		goto out_probe_notify;
 	}
 
 	ao_cec->core = devm_clk_get(&pdev->dev, "core");
 	if (IS_ERR(ao_cec->core)) {
 		dev_err(&pdev->dev, "core clock request failed\n");
 		ret = PTR_ERR(ao_cec->core);
-		goto out_probe_adapter;
+		goto out_probe_notify;
 	}
 
 	ret = clk_prepare_enable(ao_cec->core);
 	if (ret) {
 		dev_err(&pdev->dev, "core clock enable failed\n");
-		goto out_probe_adapter;
+		goto out_probe_notify;
 	}
 
 	ret = clk_set_rate(ao_cec->core, CEC_CLK_RATE);
@@ -685,19 +687,17 @@ static int meson_ao_cec_probe(struct platform_device *pdev)
 	writel_relaxed(CEC_GEN_CNTL_RESET,
 		       ao_cec->base + CEC_GEN_CNTL_REG);
 
-	cec_register_cec_notifier(ao_cec->adap, ao_cec->notify);
-
 	return 0;
 
 out_probe_clk:
 	clk_disable_unprepare(ao_cec->core);
 
+out_probe_notify:
+	cec_notifier_cec_adap_unregister(ao_cec->notify);
+
 out_probe_adapter:
 	cec_delete_adapter(ao_cec->adap);
 
-out_probe_notify:
-	cec_notifier_put(ao_cec->notify);
-
 	dev_err(&pdev->dev, "CEC controller registration failed\n");
 
 	return ret;
@@ -709,10 +709,9 @@ static int meson_ao_cec_remove(struct platform_device *pdev)
 
 	clk_disable_unprepare(ao_cec->core);
 
+	cec_notifier_cec_adap_unregister(ao_cec->notify);
 	cec_unregister_adapter(ao_cec->adap);
 
-	cec_notifier_put(ao_cec->notify);
-
 	return 0;
 }
 
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 11/13] tda9950: use cec_notifier_cec_adap_(un)register
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

From: Dariusz Marcinkiewicz <darekm@google.com>

Use the new cec_notifier_cec_adap_(un)register() functions to
(un)register the notifier for the CEC adapter.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/i2c/tda9950.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i2c/tda9950.c b/drivers/gpu/drm/i2c/tda9950.c
index 250b5e02a314..2f3381f0b2bf 100644
--- a/drivers/gpu/drm/i2c/tda9950.c
+++ b/drivers/gpu/drm/i2c/tda9950.c
@@ -423,7 +423,7 @@ static int tda9950_probe(struct i2c_client *client,
 		priv->hdmi = glue->parent;
 
 	priv->adap = cec_allocate_adapter(&tda9950_cec_ops, priv, "tda9950",
-					  CEC_CAP_DEFAULTS,
+					  CEC_CAP_DEFAULTS | CEC_CAP_CONNECTOR_INFO,
 					  CEC_MAX_LOG_ADDRS);
 	if (IS_ERR(priv->adap))
 		return PTR_ERR(priv->adap);
@@ -460,13 +460,14 @@ static int tda9950_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	priv->notify = cec_notifier_get(priv->hdmi);
+	priv->notify = cec_notifier_cec_adap_register(priv->hdmi, NULL,
+						      priv->adap);
 	if (!priv->notify)
 		return -ENOMEM;
 
 	ret = cec_register_adapter(priv->adap, priv->hdmi);
 	if (ret < 0) {
-		cec_notifier_put(priv->notify);
+		cec_notifier_cec_adap_unregister(priv->notify);
 		return ret;
 	}
 
@@ -476,8 +477,6 @@ static int tda9950_probe(struct i2c_client *client,
 	 */
 	devm_remove_action(dev, tda9950_cec_del, priv);
 
-	cec_register_cec_notifier(priv->adap, priv->notify);
-
 	return 0;
 }
 
@@ -485,8 +484,8 @@ static int tda9950_remove(struct i2c_client *client)
 {
 	struct tda9950_priv *priv = i2c_get_clientdata(client);
 
+	cec_notifier_cec_adap_unregister(priv->notify);
 	cec_unregister_adapter(priv->adap);
-	cec_notifier_put(priv->notify);
 
 	return 0;
 }
-- 
2.20.1


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

* [PATCHv8 11/13] tda9950: use cec_notifier_cec_adap_(un)register
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

From: Dariusz Marcinkiewicz <darekm@google.com>

Use the new cec_notifier_cec_adap_(un)register() functions to
(un)register the notifier for the CEC adapter.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/i2c/tda9950.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i2c/tda9950.c b/drivers/gpu/drm/i2c/tda9950.c
index 250b5e02a314..2f3381f0b2bf 100644
--- a/drivers/gpu/drm/i2c/tda9950.c
+++ b/drivers/gpu/drm/i2c/tda9950.c
@@ -423,7 +423,7 @@ static int tda9950_probe(struct i2c_client *client,
 		priv->hdmi = glue->parent;
 
 	priv->adap = cec_allocate_adapter(&tda9950_cec_ops, priv, "tda9950",
-					  CEC_CAP_DEFAULTS,
+					  CEC_CAP_DEFAULTS | CEC_CAP_CONNECTOR_INFO,
 					  CEC_MAX_LOG_ADDRS);
 	if (IS_ERR(priv->adap))
 		return PTR_ERR(priv->adap);
@@ -460,13 +460,14 @@ static int tda9950_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	priv->notify = cec_notifier_get(priv->hdmi);
+	priv->notify = cec_notifier_cec_adap_register(priv->hdmi, NULL,
+						      priv->adap);
 	if (!priv->notify)
 		return -ENOMEM;
 
 	ret = cec_register_adapter(priv->adap, priv->hdmi);
 	if (ret < 0) {
-		cec_notifier_put(priv->notify);
+		cec_notifier_cec_adap_unregister(priv->notify);
 		return ret;
 	}
 
@@ -476,8 +477,6 @@ static int tda9950_probe(struct i2c_client *client,
 	 */
 	devm_remove_action(dev, tda9950_cec_del, priv);
 
-	cec_register_cec_notifier(priv->adap, priv->notify);
-
 	return 0;
 }
 
@@ -485,8 +484,8 @@ static int tda9950_remove(struct i2c_client *client)
 {
 	struct tda9950_priv *priv = i2c_get_clientdata(client);
 
+	cec_notifier_cec_adap_unregister(priv->notify);
 	cec_unregister_adapter(priv->adap);
-	cec_notifier_put(priv->notify);
 
 	return 0;
 }
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 12/13] tda998x: use cec_notifier_conn_(un)register
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

From: Dariusz Marcinkiewicz <darekm@google.com>

Use the new cec_notifier_conn_(un)register() functions to
(un)register the notifier for the HDMI connector, and fill in
the cec_connector_info.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/i2c/tda998x_drv.c | 56 +++++++++++++++----------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c
index 7f34601bb515..019e1f2f008c 100644
--- a/drivers/gpu/drm/i2c/tda998x_drv.c
+++ b/drivers/gpu/drm/i2c/tda998x_drv.c
@@ -1253,6 +1253,8 @@ static int tda998x_connector_init(struct tda998x_priv *priv,
 				  struct drm_device *drm)
 {
 	struct drm_connector *connector = &priv->connector;
+	struct cec_connector_info conn_info;
+	struct i2c_board_info cec_info;
 	int ret;
 
 	connector->interlace_allowed = 1;
@@ -1269,6 +1271,31 @@ static int tda998x_connector_init(struct tda998x_priv *priv,
 	if (ret)
 		return ret;
 
+	/*
+	 * Some TDA998x are actually two I2C devices merged onto one piece
+	 * of silicon: TDA9989 and TDA19989 combine the HDMI transmitter
+	 * with a slightly modified TDA9950 CEC device.  The CEC device
+	 * is at the TDA9950 address, with the address pins strapped across
+	 * to the TDA998x address pins.  Hence, it always has the same
+	 * offset.
+	 */
+	memset(&cec_info, 0, sizeof(cec_info));
+	strlcpy(cec_info.type, "tda9950", sizeof(cec_info.type));
+	cec_info.addr = priv->cec_addr;
+	cec_info.platform_data = &priv->cec_glue;
+	cec_info.irq = priv->hdmi->irq;
+
+	priv->cec = i2c_new_device(priv->hdmi->adapter, &cec_info);
+	if (!priv->cec)
+		return -ENODEV;
+
+	cec_fill_conn_info_from_drm(&conn_info, connector);
+
+	priv->cec_notify = cec_notifier_conn_register(priv->cec_glue.parent,
+						      NULL, &conn_info);
+	if (!priv->cec_notify)
+		return -ENOMEM;
+
 	drm_connector_attach_encoder(&priv->connector,
 				     priv->bridge.encoder);
 
@@ -1651,14 +1678,13 @@ static void tda998x_destroy(struct device *dev)
 	i2c_unregister_device(priv->cec);
 
 	if (priv->cec_notify)
-		cec_notifier_put(priv->cec_notify);
+		cec_notifier_conn_unregister(priv->cec_notify);
 }
 
 static int tda998x_create(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct device_node *np = client->dev.of_node;
-	struct i2c_board_info cec_info;
 	struct tda998x_priv *priv;
 	u32 video;
 	int rev_lo, rev_hi, ret;
@@ -1776,12 +1802,6 @@ static int tda998x_create(struct device *dev)
 		cec_write(priv, REG_CEC_RXSHPDINTENA, CEC_RXSHPDLEV_HPD);
 	}
 
-	priv->cec_notify = cec_notifier_get(dev);
-	if (!priv->cec_notify) {
-		ret = -ENOMEM;
-		goto fail;
-	}
-
 	priv->cec_glue.parent = dev;
 	priv->cec_glue.data = priv;
 	priv->cec_glue.init = tda998x_cec_hook_init;
@@ -1789,26 +1809,6 @@ static int tda998x_create(struct device *dev)
 	priv->cec_glue.open = tda998x_cec_hook_open;
 	priv->cec_glue.release = tda998x_cec_hook_release;
 
-	/*
-	 * Some TDA998x are actually two I2C devices merged onto one piece
-	 * of silicon: TDA9989 and TDA19989 combine the HDMI transmitter
-	 * with a slightly modified TDA9950 CEC device.  The CEC device
-	 * is at the TDA9950 address, with the address pins strapped across
-	 * to the TDA998x address pins.  Hence, it always has the same
-	 * offset.
-	 */
-	memset(&cec_info, 0, sizeof(cec_info));
-	strlcpy(cec_info.type, "tda9950", sizeof(cec_info.type));
-	cec_info.addr = priv->cec_addr;
-	cec_info.platform_data = &priv->cec_glue;
-	cec_info.irq = client->irq;
-
-	priv->cec = i2c_new_device(client->adapter, &cec_info);
-	if (!priv->cec) {
-		ret = -ENODEV;
-		goto fail;
-	}
-
 	/* enable EDID read irq: */
 	reg_set(priv, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD);
 
-- 
2.20.1


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

* [PATCHv8 12/13] tda998x: use cec_notifier_conn_(un)register
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

From: Dariusz Marcinkiewicz <darekm@google.com>

Use the new cec_notifier_conn_(un)register() functions to
(un)register the notifier for the HDMI connector, and fill in
the cec_connector_info.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/i2c/tda998x_drv.c | 56 +++++++++++++++----------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c
index 7f34601bb515..019e1f2f008c 100644
--- a/drivers/gpu/drm/i2c/tda998x_drv.c
+++ b/drivers/gpu/drm/i2c/tda998x_drv.c
@@ -1253,6 +1253,8 @@ static int tda998x_connector_init(struct tda998x_priv *priv,
 				  struct drm_device *drm)
 {
 	struct drm_connector *connector = &priv->connector;
+	struct cec_connector_info conn_info;
+	struct i2c_board_info cec_info;
 	int ret;
 
 	connector->interlace_allowed = 1;
@@ -1269,6 +1271,31 @@ static int tda998x_connector_init(struct tda998x_priv *priv,
 	if (ret)
 		return ret;
 
+	/*
+	 * Some TDA998x are actually two I2C devices merged onto one piece
+	 * of silicon: TDA9989 and TDA19989 combine the HDMI transmitter
+	 * with a slightly modified TDA9950 CEC device.  The CEC device
+	 * is at the TDA9950 address, with the address pins strapped across
+	 * to the TDA998x address pins.  Hence, it always has the same
+	 * offset.
+	 */
+	memset(&cec_info, 0, sizeof(cec_info));
+	strlcpy(cec_info.type, "tda9950", sizeof(cec_info.type));
+	cec_info.addr = priv->cec_addr;
+	cec_info.platform_data = &priv->cec_glue;
+	cec_info.irq = priv->hdmi->irq;
+
+	priv->cec = i2c_new_device(priv->hdmi->adapter, &cec_info);
+	if (!priv->cec)
+		return -ENODEV;
+
+	cec_fill_conn_info_from_drm(&conn_info, connector);
+
+	priv->cec_notify = cec_notifier_conn_register(priv->cec_glue.parent,
+						      NULL, &conn_info);
+	if (!priv->cec_notify)
+		return -ENOMEM;
+
 	drm_connector_attach_encoder(&priv->connector,
 				     priv->bridge.encoder);
 
@@ -1651,14 +1678,13 @@ static void tda998x_destroy(struct device *dev)
 	i2c_unregister_device(priv->cec);
 
 	if (priv->cec_notify)
-		cec_notifier_put(priv->cec_notify);
+		cec_notifier_conn_unregister(priv->cec_notify);
 }
 
 static int tda998x_create(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct device_node *np = client->dev.of_node;
-	struct i2c_board_info cec_info;
 	struct tda998x_priv *priv;
 	u32 video;
 	int rev_lo, rev_hi, ret;
@@ -1776,12 +1802,6 @@ static int tda998x_create(struct device *dev)
 		cec_write(priv, REG_CEC_RXSHPDINTENA, CEC_RXSHPDLEV_HPD);
 	}
 
-	priv->cec_notify = cec_notifier_get(dev);
-	if (!priv->cec_notify) {
-		ret = -ENOMEM;
-		goto fail;
-	}
-
 	priv->cec_glue.parent = dev;
 	priv->cec_glue.data = priv;
 	priv->cec_glue.init = tda998x_cec_hook_init;
@@ -1789,26 +1809,6 @@ static int tda998x_create(struct device *dev)
 	priv->cec_glue.open = tda998x_cec_hook_open;
 	priv->cec_glue.release = tda998x_cec_hook_release;
 
-	/*
-	 * Some TDA998x are actually two I2C devices merged onto one piece
-	 * of silicon: TDA9989 and TDA19989 combine the HDMI transmitter
-	 * with a slightly modified TDA9950 CEC device.  The CEC device
-	 * is at the TDA9950 address, with the address pins strapped across
-	 * to the TDA998x address pins.  Hence, it always has the same
-	 * offset.
-	 */
-	memset(&cec_info, 0, sizeof(cec_info));
-	strlcpy(cec_info.type, "tda9950", sizeof(cec_info.type));
-	cec_info.addr = priv->cec_addr;
-	cec_info.platform_data = &priv->cec_glue;
-	cec_info.irq = client->irq;
-
-	priv->cec = i2c_new_device(client->adapter, &cec_info);
-	if (!priv->cec) {
-		ret = -ENODEV;
-		goto fail;
-	}
-
 	/* enable EDID read irq: */
 	reg_set(priv, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD);
 
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8 13/13] drm/vc4/vc4_hdmi: fill in connector info
  2019-06-24 16:03 ` Hans Verkuil
@ 2019-06-24 16:03   ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang, Hans Verkuil

From: Dariusz Marcinkiewicz <darekm@google.com>

Fill in the connector info, allowing userspace to associate
the CEC device with the drm connector.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
index 99fc8569e0f5..a998bb35b375 100644
--- a/drivers/gpu/drm/vc4/vc4_hdmi.c
+++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
@@ -1279,6 +1279,9 @@ static const struct cec_adap_ops vc4_hdmi_cec_adap_ops = {
 
 static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 {
+#ifdef CONFIG_DRM_VC4_HDMI_CEC
+	struct cec_connector_info conn_info;
+#endif
 	struct platform_device *pdev = to_platform_device(dev);
 	struct drm_device *drm = dev_get_drvdata(master);
 	struct vc4_dev *vc4 = drm->dev_private;
@@ -1397,13 +1400,15 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 #ifdef CONFIG_DRM_VC4_HDMI_CEC
 	hdmi->cec_adap = cec_allocate_adapter(&vc4_hdmi_cec_adap_ops,
 					      vc4, "vc4",
-					      CEC_CAP_TRANSMIT |
-					      CEC_CAP_LOG_ADDRS |
-					      CEC_CAP_PASSTHROUGH |
-					      CEC_CAP_RC, 1);
+					      CEC_CAP_DEFAULTS |
+					      CEC_CAP_CONNECTOR_INFO, 1);
 	ret = PTR_ERR_OR_ZERO(hdmi->cec_adap);
 	if (ret < 0)
 		goto err_destroy_conn;
+
+	cec_fill_conn_info_from_drm(&conn_info, hdmi->connector);
+	cec_s_conn_info(hdmi->cec_adap, &conn_info);
+
 	HDMI_WRITE(VC4_HDMI_CPU_MASK_SET, 0xffffffff);
 	value = HDMI_READ(VC4_HDMI_CEC_CNTRL_1);
 	value &= ~VC4_HDMI_CEC_DIV_CLK_CNT_MASK;
-- 
2.20.1


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

* [PATCHv8 13/13] drm/vc4/vc4_hdmi: fill in connector info
@ 2019-06-24 16:03   ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-24 16:03 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

From: Dariusz Marcinkiewicz <darekm@google.com>

Fill in the connector info, allowing userspace to associate
the CEC device with the drm connector.

Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
index 99fc8569e0f5..a998bb35b375 100644
--- a/drivers/gpu/drm/vc4/vc4_hdmi.c
+++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
@@ -1279,6 +1279,9 @@ static const struct cec_adap_ops vc4_hdmi_cec_adap_ops = {
 
 static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 {
+#ifdef CONFIG_DRM_VC4_HDMI_CEC
+	struct cec_connector_info conn_info;
+#endif
 	struct platform_device *pdev = to_platform_device(dev);
 	struct drm_device *drm = dev_get_drvdata(master);
 	struct vc4_dev *vc4 = drm->dev_private;
@@ -1397,13 +1400,15 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 #ifdef CONFIG_DRM_VC4_HDMI_CEC
 	hdmi->cec_adap = cec_allocate_adapter(&vc4_hdmi_cec_adap_ops,
 					      vc4, "vc4",
-					      CEC_CAP_TRANSMIT |
-					      CEC_CAP_LOG_ADDRS |
-					      CEC_CAP_PASSTHROUGH |
-					      CEC_CAP_RC, 1);
+					      CEC_CAP_DEFAULTS |
+					      CEC_CAP_CONNECTOR_INFO, 1);
 	ret = PTR_ERR_OR_ZERO(hdmi->cec_adap);
 	if (ret < 0)
 		goto err_destroy_conn;
+
+	cec_fill_conn_info_from_drm(&conn_info, hdmi->connector);
+	cec_s_conn_info(hdmi->cec_adap, &conn_info);
+
 	HDMI_WRITE(VC4_HDMI_CPU_MASK_SET, 0xffffffff);
 	value = HDMI_READ(VC4_HDMI_CEC_CNTRL_1);
 	value &= ~VC4_HDMI_CEC_DIV_CLK_CNT_MASK;
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCHv8 12/13] tda998x: use cec_notifier_conn_(un)register
  2019-06-24 16:03   ` Hans Verkuil
@ 2019-06-24 22:37     ` kbuild test robot
  -1 siblings, 0 replies; 46+ messages in thread
From: kbuild test robot @ 2019-06-24 22:37 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: kbuild-all, linux-media, Dariusz Marcinkiewicz, dri-devel,
	Cheng-yi Chiang, Hans Verkuil

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

Hi Hans,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.2-rc6 next-20190621]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Hans-Verkuil/cec-improve-notifier-support-add-connector-info/20190625-043917
base:   git://linuxtv.org/media_tree.git master
config: x86_64-rhel-7.2 (attached as .config)
compiler: clang version 9.0.0 (git://gitmirror/llvm_project fb2bd4a9398b35ee4f732ea0847d9c1226fc4cf3)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

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

All errors (new ones prefixed by >>):

>> drivers/gpu//drm/i2c/tda998x_drv.c:1292:30: error: incompatible pointer types passing 'struct cec_connector_info *' to parameter of type 'const struct drm_connector *' [-Werror,-Wincompatible-pointer-types]
           cec_fill_conn_info_from_drm(&conn_info, connector);
                                       ^~~~~~~~~~
   include/media/cec.h:381:57: note: passing argument to parameter 'connector' here
   cec_fill_conn_info_from_drm(const struct drm_connector *connector,
                                                           ^
>> drivers/gpu//drm/i2c/tda998x_drv.c:1292:42: error: incompatible pointer types passing 'struct drm_connector *' to parameter of type 'struct cec_connector_info *' [-Werror,-Wincompatible-pointer-types]
           cec_fill_conn_info_from_drm(&conn_info, connector);
                                                   ^~~~~~~~~
   include/media/cec.h:382:35: note: passing argument to parameter 'conn_info' here
                               struct cec_connector_info *conn_info)
                                                          ^
   2 errors generated.

vim +1292 drivers/gpu//drm/i2c/tda998x_drv.c

  1251	
  1252	static int tda998x_connector_init(struct tda998x_priv *priv,
  1253					  struct drm_device *drm)
  1254	{
  1255		struct drm_connector *connector = &priv->connector;
  1256		struct cec_connector_info conn_info;
  1257		struct i2c_board_info cec_info;
  1258		int ret;
  1259	
  1260		connector->interlace_allowed = 1;
  1261	
  1262		if (priv->hdmi->irq)
  1263			connector->polled = DRM_CONNECTOR_POLL_HPD;
  1264		else
  1265			connector->polled = DRM_CONNECTOR_POLL_CONNECT |
  1266				DRM_CONNECTOR_POLL_DISCONNECT;
  1267	
  1268		drm_connector_helper_add(connector, &tda998x_connector_helper_funcs);
  1269		ret = drm_connector_init(drm, connector, &tda998x_connector_funcs,
  1270					 DRM_MODE_CONNECTOR_HDMIA);
  1271		if (ret)
  1272			return ret;
  1273	
  1274		/*
  1275		 * Some TDA998x are actually two I2C devices merged onto one piece
  1276		 * of silicon: TDA9989 and TDA19989 combine the HDMI transmitter
  1277		 * with a slightly modified TDA9950 CEC device.  The CEC device
  1278		 * is at the TDA9950 address, with the address pins strapped across
  1279		 * to the TDA998x address pins.  Hence, it always has the same
  1280		 * offset.
  1281		 */
  1282		memset(&cec_info, 0, sizeof(cec_info));
  1283		strlcpy(cec_info.type, "tda9950", sizeof(cec_info.type));
  1284		cec_info.addr = priv->cec_addr;
  1285		cec_info.platform_data = &priv->cec_glue;
  1286		cec_info.irq = priv->hdmi->irq;
  1287	
  1288		priv->cec = i2c_new_device(priv->hdmi->adapter, &cec_info);
  1289		if (!priv->cec)
  1290			return -ENODEV;
  1291	
> 1292		cec_fill_conn_info_from_drm(&conn_info, connector);
  1293	
  1294		priv->cec_notify = cec_notifier_conn_register(priv->cec_glue.parent,
  1295							      NULL, &conn_info);
  1296		if (!priv->cec_notify)
  1297			return -ENOMEM;
  1298	
  1299		drm_connector_attach_encoder(&priv->connector,
  1300					     priv->bridge.encoder);
  1301	
  1302		return 0;
  1303	}
  1304	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 43223 bytes --]

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

* Re: [PATCHv8 12/13] tda998x: use cec_notifier_conn_(un)register
@ 2019-06-24 22:37     ` kbuild test robot
  0 siblings, 0 replies; 46+ messages in thread
From: kbuild test robot @ 2019-06-24 22:37 UTC (permalink / raw)
  Cc: linux-media, dri-devel, kbuild-all, Hans Verkuil,
	Dariusz Marcinkiewicz, Cheng-yi Chiang

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

Hi Hans,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.2-rc6 next-20190621]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Hans-Verkuil/cec-improve-notifier-support-add-connector-info/20190625-043917
base:   git://linuxtv.org/media_tree.git master
config: x86_64-rhel-7.2 (attached as .config)
compiler: clang version 9.0.0 (git://gitmirror/llvm_project fb2bd4a9398b35ee4f732ea0847d9c1226fc4cf3)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

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

All errors (new ones prefixed by >>):

>> drivers/gpu//drm/i2c/tda998x_drv.c:1292:30: error: incompatible pointer types passing 'struct cec_connector_info *' to parameter of type 'const struct drm_connector *' [-Werror,-Wincompatible-pointer-types]
           cec_fill_conn_info_from_drm(&conn_info, connector);
                                       ^~~~~~~~~~
   include/media/cec.h:381:57: note: passing argument to parameter 'connector' here
   cec_fill_conn_info_from_drm(const struct drm_connector *connector,
                                                           ^
>> drivers/gpu//drm/i2c/tda998x_drv.c:1292:42: error: incompatible pointer types passing 'struct drm_connector *' to parameter of type 'struct cec_connector_info *' [-Werror,-Wincompatible-pointer-types]
           cec_fill_conn_info_from_drm(&conn_info, connector);
                                                   ^~~~~~~~~
   include/media/cec.h:382:35: note: passing argument to parameter 'conn_info' here
                               struct cec_connector_info *conn_info)
                                                          ^
   2 errors generated.

vim +1292 drivers/gpu//drm/i2c/tda998x_drv.c

  1251	
  1252	static int tda998x_connector_init(struct tda998x_priv *priv,
  1253					  struct drm_device *drm)
  1254	{
  1255		struct drm_connector *connector = &priv->connector;
  1256		struct cec_connector_info conn_info;
  1257		struct i2c_board_info cec_info;
  1258		int ret;
  1259	
  1260		connector->interlace_allowed = 1;
  1261	
  1262		if (priv->hdmi->irq)
  1263			connector->polled = DRM_CONNECTOR_POLL_HPD;
  1264		else
  1265			connector->polled = DRM_CONNECTOR_POLL_CONNECT |
  1266				DRM_CONNECTOR_POLL_DISCONNECT;
  1267	
  1268		drm_connector_helper_add(connector, &tda998x_connector_helper_funcs);
  1269		ret = drm_connector_init(drm, connector, &tda998x_connector_funcs,
  1270					 DRM_MODE_CONNECTOR_HDMIA);
  1271		if (ret)
  1272			return ret;
  1273	
  1274		/*
  1275		 * Some TDA998x are actually two I2C devices merged onto one piece
  1276		 * of silicon: TDA9989 and TDA19989 combine the HDMI transmitter
  1277		 * with a slightly modified TDA9950 CEC device.  The CEC device
  1278		 * is at the TDA9950 address, with the address pins strapped across
  1279		 * to the TDA998x address pins.  Hence, it always has the same
  1280		 * offset.
  1281		 */
  1282		memset(&cec_info, 0, sizeof(cec_info));
  1283		strlcpy(cec_info.type, "tda9950", sizeof(cec_info.type));
  1284		cec_info.addr = priv->cec_addr;
  1285		cec_info.platform_data = &priv->cec_glue;
  1286		cec_info.irq = priv->hdmi->irq;
  1287	
  1288		priv->cec = i2c_new_device(priv->hdmi->adapter, &cec_info);
  1289		if (!priv->cec)
  1290			return -ENODEV;
  1291	
> 1292		cec_fill_conn_info_from_drm(&conn_info, connector);
  1293	
  1294		priv->cec_notify = cec_notifier_conn_register(priv->cec_glue.parent,
  1295							      NULL, &conn_info);
  1296		if (!priv->cec_notify)
  1297			return -ENOMEM;
  1298	
  1299		drm_connector_attach_encoder(&priv->connector,
  1300					     priv->bridge.encoder);
  1301	
  1302		return 0;
  1303	}
  1304	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 43223 bytes --]

[-- Attachment #3: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCHv8 09/13] dw-hdmi: use cec_notifier_conn_(un)register
  2019-06-24 16:03   ` Hans Verkuil
@ 2019-06-25  0:43     ` kbuild test robot
  -1 siblings, 0 replies; 46+ messages in thread
From: kbuild test robot @ 2019-06-25  0:43 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: kbuild-all, linux-media, Dariusz Marcinkiewicz, dri-devel,
	Cheng-yi Chiang, Hans Verkuil

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

Hi Hans,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.2-rc6 next-20190621]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Hans-Verkuil/cec-improve-notifier-support-add-connector-info/20190625-043917
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-x014-201925 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

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

All errors (new ones prefixed by >>):

   drivers/gpu/drm/bridge/synopsys/dw-hdmi.c: In function 'dw_hdmi_bridge_attach':
>> drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:2154:30: error: passing argument 1 of 'cec_fill_conn_info_from_drm' from incompatible pointer type [-Werror=incompatible-pointer-types]
     cec_fill_conn_info_from_drm(&conn_info, connector);
                                 ^
   In file included from include/media/cec-notifier.h:13:0,
                    from drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:36:
   include/media/cec.h:381:1: note: expected 'const struct drm_connector *' but argument is of type 'struct cec_connector_info *'
    cec_fill_conn_info_from_drm(const struct drm_connector *connector,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:2154:42: error: passing argument 2 of 'cec_fill_conn_info_from_drm' from incompatible pointer type [-Werror=incompatible-pointer-types]
     cec_fill_conn_info_from_drm(&conn_info, connector);
                                             ^~~~~~~~~
   In file included from include/media/cec-notifier.h:13:0,
                    from drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:36:
   include/media/cec.h:381:1: note: expected 'struct cec_connector_info *' but argument is of type 'struct drm_connector *'
    cec_fill_conn_info_from_drm(const struct drm_connector *connector,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   Cyclomatic Complexity 1 include/linux/err.h:ERR_PTR
   Cyclomatic Complexity 1 include/linux/err.h:PTR_ERR
   Cyclomatic Complexity 1 include/linux/spinlock.h:spinlock_check
   Cyclomatic Complexity 1 include/linux/spinlock.h:spin_lock_irq
   Cyclomatic Complexity 1 include/linux/spinlock.h:spin_unlock_irq
   Cyclomatic Complexity 1 include/linux/spinlock.h:spin_unlock_irqrestore
   Cyclomatic Complexity 1 include/linux/completion.h:reinit_completion
   Cyclomatic Complexity 1 include/linux/kobject.h:kobject_name
   Cyclomatic Complexity 1 include/linux/device.h:dev_get_drvdata
   Cyclomatic Complexity 1 include/linux/device.h:dev_set_drvdata
   Cyclomatic Complexity 1 include/linux/i2c.h:i2c_get_adapdata
   Cyclomatic Complexity 1 include/linux/i2c.h:i2c_set_adapdata
   Cyclomatic Complexity 1 include/drm/drm_modeset_helper_vtables.h:drm_connector_helper_add
   Cyclomatic Complexity 1 include/media/cec-notifier.h:cec_notifier_conn_register
   Cyclomatic Complexity 1 include/media/cec-notifier.h:cec_notifier_conn_unregister
   Cyclomatic Complexity 1 include/media/cec-notifier.h:cec_notifier_set_phys_addr
   Cyclomatic Complexity 1 include/media/cec-notifier.h:cec_notifier_set_phys_addr_from_edid
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_i2c_func
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_bus_fmt_is_rgb
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_bus_fmt_is_yuv444
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_bus_fmt_is_yuv422
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_bus_fmt_is_yuv420
   Cyclomatic Complexity 5 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_bus_fmt_color_depth
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:is_color_space_conversion
   Cyclomatic Complexity 6 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:is_color_space_decimation
   Cyclomatic Complexity 6 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:is_color_space_interpolation
   Cyclomatic Complexity 35 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_compute_n
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_audio_enable
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_audio_disable
   Cyclomatic Complexity 23 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_support_scdc
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_poweroff
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_update_phy_mask
   Cyclomatic Complexity 7 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_bridge_mode_valid
   Cyclomatic Complexity 4 include/linux/device.h:dev_name
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_modb
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_mask_writeb
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_gen2_pddq
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_gen2_txpwron
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_enable_tmds
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_enable_powerdown
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_sel_data_en_pol
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_sel_interface_control
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_enable_svsret
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_phy_test_clear
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_tx_hdcp_config
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_writeb
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_set_cts_n
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_set_clk_regenerator
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_set_sample_rate
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_clk_regenerator_update_pixel_clock
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_init_clk_regenerator
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_ahb_audio_disable
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_ahb_audio_enable
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_reset
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_i2c_set_addr
   Cyclomatic Complexity 12 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_update_hpd
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_setup_hpd
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_disable_overflow_interrupts
   Cyclomatic Complexity 5 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_enable_video_path
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_enable_audio_clk
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_i2s_audio_disable
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_i2s_audio_enable
   Cyclomatic Complexity 26 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_video_packetize
   Cyclomatic Complexity 14 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_update_csc_coeffs
   Cyclomatic Complexity 9 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_video_csc
   Cyclomatic Complexity 12 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_video_sample
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_cec_disable
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_cec_enable
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_setup_i2c
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_i2c_init
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_readb
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_phy_wait_i2c_done
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_i2c_write
   Cyclomatic Complexity 24 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_phy_configure_dwc_hdmi_3d_tx
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_read_hpd
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_clear_overflow
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:initialize_hdmi_ih_mutes
   Cyclomatic Complexity 6 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_set_high_tmds_clock_ratio
   Cyclomatic Complexity 1 include/drm/drm_scdc_helper.h:drm_scdc_readb
   Cyclomatic Complexity 1 include/drm/drm_scdc_helper.h:drm_scdc_writeb
   Cyclomatic Complexity 28 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_av_composer
   Cyclomatic Complexity 37 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_config_AVI
   Cyclomatic Complexity 10 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_config_vendor_specific_infoframe
   Cyclomatic Complexity 25 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_setup
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_poweron

vim +/cec_fill_conn_info_from_drm +2154 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c

  2136	
  2137	static int dw_hdmi_bridge_attach(struct drm_bridge *bridge)
  2138	{
  2139		struct dw_hdmi *hdmi = bridge->driver_private;
  2140		struct drm_encoder *encoder = bridge->encoder;
  2141		struct drm_connector *connector = &hdmi->connector;
  2142		struct cec_connector_info conn_info;
  2143	
  2144		connector->interlace_allowed = 1;
  2145		connector->polled = DRM_CONNECTOR_POLL_HPD;
  2146	
  2147		drm_connector_helper_add(connector, &dw_hdmi_connector_helper_funcs);
  2148	
  2149		drm_connector_init(bridge->dev, connector, &dw_hdmi_connector_funcs,
  2150				   DRM_MODE_CONNECTOR_HDMIA);
  2151	
  2152		drm_connector_attach_encoder(connector, encoder);
  2153	
> 2154		cec_fill_conn_info_from_drm(&conn_info, connector);
  2155	
  2156		hdmi->cec_notifier = cec_notifier_conn_register(hdmi->dev, NULL,
  2157								&conn_info);
  2158		if (!hdmi->cec_notifier)
  2159			return -ENOMEM;
  2160	
  2161		if (hdmi->cec_configured) {
  2162			struct platform_device_info pdevinfo;
  2163			struct dw_hdmi_cec_data cec;
  2164	
  2165			memset(&pdevinfo, 0, sizeof(pdevinfo));
  2166			pdevinfo.parent = hdmi->dev;
  2167			pdevinfo.id = PLATFORM_DEVID_AUTO;
  2168	
  2169			cec.hdmi = hdmi;
  2170			cec.ops = &dw_hdmi_cec_ops;
  2171			cec.irq = hdmi->irq;
  2172	
  2173			pdevinfo.name = "dw-hdmi-cec";
  2174			pdevinfo.data = &cec;
  2175			pdevinfo.size_data = sizeof(cec);
  2176			pdevinfo.dma_mask = 0;
  2177	
  2178			hdmi->cec = platform_device_register_full(&pdevinfo);
  2179		}
  2180	
  2181		return 0;
  2182	}
  2183	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33736 bytes --]

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

* Re: [PATCHv8 09/13] dw-hdmi: use cec_notifier_conn_(un)register
@ 2019-06-25  0:43     ` kbuild test robot
  0 siblings, 0 replies; 46+ messages in thread
From: kbuild test robot @ 2019-06-25  0:43 UTC (permalink / raw)
  Cc: linux-media, dri-devel, kbuild-all, Hans Verkuil,
	Dariusz Marcinkiewicz, Cheng-yi Chiang

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

Hi Hans,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.2-rc6 next-20190621]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Hans-Verkuil/cec-improve-notifier-support-add-connector-info/20190625-043917
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-x014-201925 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

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

All errors (new ones prefixed by >>):

   drivers/gpu/drm/bridge/synopsys/dw-hdmi.c: In function 'dw_hdmi_bridge_attach':
>> drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:2154:30: error: passing argument 1 of 'cec_fill_conn_info_from_drm' from incompatible pointer type [-Werror=incompatible-pointer-types]
     cec_fill_conn_info_from_drm(&conn_info, connector);
                                 ^
   In file included from include/media/cec-notifier.h:13:0,
                    from drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:36:
   include/media/cec.h:381:1: note: expected 'const struct drm_connector *' but argument is of type 'struct cec_connector_info *'
    cec_fill_conn_info_from_drm(const struct drm_connector *connector,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:2154:42: error: passing argument 2 of 'cec_fill_conn_info_from_drm' from incompatible pointer type [-Werror=incompatible-pointer-types]
     cec_fill_conn_info_from_drm(&conn_info, connector);
                                             ^~~~~~~~~
   In file included from include/media/cec-notifier.h:13:0,
                    from drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:36:
   include/media/cec.h:381:1: note: expected 'struct cec_connector_info *' but argument is of type 'struct drm_connector *'
    cec_fill_conn_info_from_drm(const struct drm_connector *connector,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   Cyclomatic Complexity 1 include/linux/err.h:ERR_PTR
   Cyclomatic Complexity 1 include/linux/err.h:PTR_ERR
   Cyclomatic Complexity 1 include/linux/spinlock.h:spinlock_check
   Cyclomatic Complexity 1 include/linux/spinlock.h:spin_lock_irq
   Cyclomatic Complexity 1 include/linux/spinlock.h:spin_unlock_irq
   Cyclomatic Complexity 1 include/linux/spinlock.h:spin_unlock_irqrestore
   Cyclomatic Complexity 1 include/linux/completion.h:reinit_completion
   Cyclomatic Complexity 1 include/linux/kobject.h:kobject_name
   Cyclomatic Complexity 1 include/linux/device.h:dev_get_drvdata
   Cyclomatic Complexity 1 include/linux/device.h:dev_set_drvdata
   Cyclomatic Complexity 1 include/linux/i2c.h:i2c_get_adapdata
   Cyclomatic Complexity 1 include/linux/i2c.h:i2c_set_adapdata
   Cyclomatic Complexity 1 include/drm/drm_modeset_helper_vtables.h:drm_connector_helper_add
   Cyclomatic Complexity 1 include/media/cec-notifier.h:cec_notifier_conn_register
   Cyclomatic Complexity 1 include/media/cec-notifier.h:cec_notifier_conn_unregister
   Cyclomatic Complexity 1 include/media/cec-notifier.h:cec_notifier_set_phys_addr
   Cyclomatic Complexity 1 include/media/cec-notifier.h:cec_notifier_set_phys_addr_from_edid
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_i2c_func
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_bus_fmt_is_rgb
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_bus_fmt_is_yuv444
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_bus_fmt_is_yuv422
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_bus_fmt_is_yuv420
   Cyclomatic Complexity 5 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_bus_fmt_color_depth
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:is_color_space_conversion
   Cyclomatic Complexity 6 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:is_color_space_decimation
   Cyclomatic Complexity 6 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:is_color_space_interpolation
   Cyclomatic Complexity 35 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_compute_n
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_audio_enable
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_audio_disable
   Cyclomatic Complexity 23 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_support_scdc
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_poweroff
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_update_phy_mask
   Cyclomatic Complexity 7 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_bridge_mode_valid
   Cyclomatic Complexity 4 include/linux/device.h:dev_name
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_modb
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_mask_writeb
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_gen2_pddq
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_gen2_txpwron
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_enable_tmds
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_enable_powerdown
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_sel_data_en_pol
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_sel_interface_control
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_enable_svsret
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_phy_test_clear
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_tx_hdcp_config
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_writeb
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_set_cts_n
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_set_clk_regenerator
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_set_sample_rate
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_clk_regenerator_update_pixel_clock
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_init_clk_regenerator
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_ahb_audio_disable
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_ahb_audio_enable
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_reset
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_i2c_set_addr
   Cyclomatic Complexity 12 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_update_hpd
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_setup_hpd
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_disable_overflow_interrupts
   Cyclomatic Complexity 5 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_enable_video_path
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_enable_audio_clk
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_i2s_audio_disable
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_i2s_audio_enable
   Cyclomatic Complexity 26 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_video_packetize
   Cyclomatic Complexity 14 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_update_csc_coeffs
   Cyclomatic Complexity 9 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_video_csc
   Cyclomatic Complexity 12 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_video_sample
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_cec_disable
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_cec_enable
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_setup_i2c
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_i2c_init
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_readb
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_phy_wait_i2c_done
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_i2c_write
   Cyclomatic Complexity 24 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_phy_configure_dwc_hdmi_3d_tx
   Cyclomatic Complexity 2 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_phy_read_hpd
   Cyclomatic Complexity 4 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_clear_overflow
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:initialize_hdmi_ih_mutes
   Cyclomatic Complexity 6 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_set_high_tmds_clock_ratio
   Cyclomatic Complexity 1 include/drm/drm_scdc_helper.h:drm_scdc_readb
   Cyclomatic Complexity 1 include/drm/drm_scdc_helper.h:drm_scdc_writeb
   Cyclomatic Complexity 28 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_av_composer
   Cyclomatic Complexity 37 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_config_AVI
   Cyclomatic Complexity 10 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:hdmi_config_vendor_specific_infoframe
   Cyclomatic Complexity 25 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_setup
   Cyclomatic Complexity 1 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c:dw_hdmi_poweron

vim +/cec_fill_conn_info_from_drm +2154 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c

  2136	
  2137	static int dw_hdmi_bridge_attach(struct drm_bridge *bridge)
  2138	{
  2139		struct dw_hdmi *hdmi = bridge->driver_private;
  2140		struct drm_encoder *encoder = bridge->encoder;
  2141		struct drm_connector *connector = &hdmi->connector;
  2142		struct cec_connector_info conn_info;
  2143	
  2144		connector->interlace_allowed = 1;
  2145		connector->polled = DRM_CONNECTOR_POLL_HPD;
  2146	
  2147		drm_connector_helper_add(connector, &dw_hdmi_connector_helper_funcs);
  2148	
  2149		drm_connector_init(bridge->dev, connector, &dw_hdmi_connector_funcs,
  2150				   DRM_MODE_CONNECTOR_HDMIA);
  2151	
  2152		drm_connector_attach_encoder(connector, encoder);
  2153	
> 2154		cec_fill_conn_info_from_drm(&conn_info, connector);
  2155	
  2156		hdmi->cec_notifier = cec_notifier_conn_register(hdmi->dev, NULL,
  2157								&conn_info);
  2158		if (!hdmi->cec_notifier)
  2159			return -ENOMEM;
  2160	
  2161		if (hdmi->cec_configured) {
  2162			struct platform_device_info pdevinfo;
  2163			struct dw_hdmi_cec_data cec;
  2164	
  2165			memset(&pdevinfo, 0, sizeof(pdevinfo));
  2166			pdevinfo.parent = hdmi->dev;
  2167			pdevinfo.id = PLATFORM_DEVID_AUTO;
  2168	
  2169			cec.hdmi = hdmi;
  2170			cec.ops = &dw_hdmi_cec_ops;
  2171			cec.irq = hdmi->irq;
  2172	
  2173			pdevinfo.name = "dw-hdmi-cec";
  2174			pdevinfo.data = &cec;
  2175			pdevinfo.size_data = sizeof(cec);
  2176			pdevinfo.dma_mask = 0;
  2177	
  2178			hdmi->cec = platform_device_register_full(&pdevinfo);
  2179		}
  2180	
  2181		return 0;
  2182	}
  2183	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33736 bytes --]

[-- Attachment #3: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCHv8 02/13] cec: add struct cec_connector_info support
  2019-06-24 16:03   ` Hans Verkuil
@ 2019-06-25  6:28     ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-25  6:28 UTC (permalink / raw)
  To: linux-media; +Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

On 6/24/19 6:03 PM, Hans Verkuil wrote:
> From: Dariusz Marcinkiewicz <darekm@google.com>
> 
> Define struct cec_connector_info in media/cec.h and define
> CEC_CAP_CONNECTOR_INFO. In a later patch this will be moved to
> uapi/linux/cec.h.
> 
> For now just define this together with the cec_fill_conn_info_from_drm
> and cec_s_conn_info functions: this allows both drm and media to make
> use of this without requiring cross-subsystem changes.
> 
> Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
> Co-developed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> ---
>  drivers/media/cec/cec-adap.c | 29 +++++++++++++++++++++++
>  drivers/media/cec/cec-core.c |  5 ++++
>  include/media/cec.h          | 45 +++++++++++++++++++++++++++++++++++-
>  3 files changed, 78 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/cec/cec-adap.c b/drivers/media/cec/cec-adap.c
> index ac3683a7b2ab..451c61bde4d4 100644
> --- a/drivers/media/cec/cec-adap.c
> +++ b/drivers/media/cec/cec-adap.c
> @@ -16,7 +16,10 @@
>  #include <linux/string.h>
>  #include <linux/types.h>
>  
> +#include <drm/drm_connector.h>
> +#include <drm/drm_device.h>
>  #include <drm/drm_edid.h>
> +#include <drm/drm_file.h>
>  
>  #include "cec-priv.h"
>  
> @@ -75,6 +78,16 @@ u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
>  }
>  EXPORT_SYMBOL_GPL(cec_get_edid_phys_addr);
>  
> +void cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info,
> +				 const struct drm_connector *connector)
> +{
> +	memset(conn_info, 0, sizeof(*conn_info));
> +	conn_info->type = CEC_CONNECTOR_TYPE_DRM;
> +	conn_info->drm.card_no = connector->dev->primary->index;
> +	conn_info->drm.connector_id = connector->base.id;
> +}
> +EXPORT_SYMBOL_GPL(cec_fill_conn_info_from_drm);
> +
>  /*
>   * Queue a new event for this filehandle. If ts == 0, then set it
>   * to the current time.
> @@ -1598,6 +1611,22 @@ void cec_s_phys_addr_from_edid(struct cec_adapter *adap,
>  }
>  EXPORT_SYMBOL_GPL(cec_s_phys_addr_from_edid);
>  
> +void cec_s_conn_info(struct cec_adapter *adap,
> +		     const struct cec_connector_info *conn_info)
> +{
> +	if (!(adap->capabilities & CEC_CAP_CONNECTOR_INFO))
> +		return;
> +
> +	mutex_lock(&adap->lock);
> +	if (conn_info)
> +		adap->conn_info = *conn_info;
> +	else
> +		memset(&adap->conn_info, 0, sizeof(adap->conn_info));
> +	cec_post_state_event(adap);
> +	mutex_unlock(&adap->lock);
> +}
> +EXPORT_SYMBOL_GPL(cec_s_conn_info);
> +
>  /*
>   * Called from either the ioctl or a driver to set the logical addresses.
>   *
> diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c
> index db7adffcdc76..e45b792d26fb 100644
> --- a/drivers/media/cec/cec-core.c
> +++ b/drivers/media/cec/cec-core.c
> @@ -189,6 +189,11 @@ static void cec_cec_notify(struct cec_adapter *adap, u16 pa)
>  	cec_s_phys_addr(adap, pa, false);
>  }
>  
> +void cec_notifier_register(struct cec_notifier *n,
> +			   struct cec_adapter *adap,
> +			   void (*callback)(struct cec_adapter *adap, u16 pa));
> +void cec_notifier_unregister(struct cec_notifier *n);
> +
>  void cec_register_cec_notifier(struct cec_adapter *adap,
>  			       struct cec_notifier *notifier)
>  {
> diff --git a/include/media/cec.h b/include/media/cec.h
> index 707411ef8ba2..45f2c98ed75b 100644
> --- a/include/media/cec.h
> +++ b/include/media/cec.h
> @@ -17,7 +17,9 @@
>  #include <linux/timer.h>
>  #include <linux/cec-funcs.h>
>  #include <media/rc-core.h>
> -#include <media/cec-notifier.h>
> +
> +/* CEC_ADAP_G_CONNECTOR_INFO is available */
> +#define CEC_CAP_CONNECTOR_INFO	0
>  
>  #define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \
>  			  CEC_CAP_PASSTHROUGH | CEC_CAP_RC)
> @@ -53,6 +55,7 @@ struct cec_devnode {
>  struct cec_adapter;
>  struct cec_data;
>  struct cec_pin;
> +struct cec_notifier;
>  
>  struct cec_data {
>  	struct list_head list;
> @@ -144,6 +147,27 @@ struct cec_adap_ops {
>   */
>  #define CEC_MAX_MSG_TX_QUEUE_SZ		(18 * 1)
>  
> +/**
> + * struct cec_event_connector - tells if and which connector is associated
> + * with the CEC adapter.
> + * @card_no: drm card number
> + * @connector_id: drm connector ID
> + */
> +struct cec_drm_connector_info {
> +	__u32 card_no;
> +	__u32 connector_id;
> +};
> +
> +#define CEC_CONNECTOR_TYPE_NO_CONNECTOR	0
> +#define CEC_CONNECTOR_TYPE_DRM		1
> +struct cec_connector_info {
> +	__u32 type;
> +	union {
> +		struct cec_drm_connector_info drm;
> +		__u32 raw[16];
> +	};
> +};
> +
>  struct cec_adapter {
>  	struct module *owner;
>  	char name[32];
> @@ -182,6 +206,7 @@ struct cec_adapter {
>  	struct cec_fh *cec_initiator;
>  	bool passthrough;
>  	struct cec_log_addrs log_addrs;
> +	struct cec_connector_info conn_info;
>  
>  	u32 tx_timeouts;
>  
> @@ -233,6 +258,7 @@ static inline bool cec_is_registered(const struct cec_adapter *adap)
>  	((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf
>  
>  struct edid;
> +struct drm_connector;
>  
>  #if IS_REACHABLE(CONFIG_CEC_CORE)
>  struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
> @@ -247,6 +273,8 @@ void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr,
>  		     bool block);
>  void cec_s_phys_addr_from_edid(struct cec_adapter *adap,
>  			       const struct edid *edid);
> +void cec_s_conn_info(struct cec_adapter *adap,
> +		     const struct cec_connector_info *conn_info);
>  int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg,
>  		     bool block);
>  
> @@ -331,6 +359,9 @@ void cec_queue_pin_5v_event(struct cec_adapter *adap, bool is_high, ktime_t ts);
>  u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
>  			   unsigned int *offset);
>  
> +void cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info,
> +				 const struct drm_connector *connector);
> +
>  #else
>  
>  static inline int cec_register_adapter(struct cec_adapter *adap,
> @@ -365,6 +396,18 @@ static inline u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
>  	return CEC_PHYS_ADDR_INVALID;
>  }
>  
> +static inline void cec_s_conn_info(struct cec_adapter *adap,
> +				   const struct cec_connector_info *conn_info)
> +{
> +}
> +
> +static inline void
> +cec_fill_conn_info_from_drm(const struct drm_connector *connector,
> +			    struct cec_connector_info *conn_info)

Oops, these arguments are the wrong way around. conn_info comes first.

This is already fixed in my branch:

https://git.linuxtv.org/hverkuil/media_tree.git/log/?h=cec-conn

Regards,

	Hans

> +{
> +	memset(conn_info, 0, sizeof(*conn_info));
> +}
> +
>  #endif
>  
>  /**
> 


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

* Re: [PATCHv8 02/13] cec: add struct cec_connector_info support
@ 2019-06-25  6:28     ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-25  6:28 UTC (permalink / raw)
  To: linux-media; +Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

On 6/24/19 6:03 PM, Hans Verkuil wrote:
> From: Dariusz Marcinkiewicz <darekm@google.com>
> 
> Define struct cec_connector_info in media/cec.h and define
> CEC_CAP_CONNECTOR_INFO. In a later patch this will be moved to
> uapi/linux/cec.h.
> 
> For now just define this together with the cec_fill_conn_info_from_drm
> and cec_s_conn_info functions: this allows both drm and media to make
> use of this without requiring cross-subsystem changes.
> 
> Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
> Co-developed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> ---
>  drivers/media/cec/cec-adap.c | 29 +++++++++++++++++++++++
>  drivers/media/cec/cec-core.c |  5 ++++
>  include/media/cec.h          | 45 +++++++++++++++++++++++++++++++++++-
>  3 files changed, 78 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/cec/cec-adap.c b/drivers/media/cec/cec-adap.c
> index ac3683a7b2ab..451c61bde4d4 100644
> --- a/drivers/media/cec/cec-adap.c
> +++ b/drivers/media/cec/cec-adap.c
> @@ -16,7 +16,10 @@
>  #include <linux/string.h>
>  #include <linux/types.h>
>  
> +#include <drm/drm_connector.h>
> +#include <drm/drm_device.h>
>  #include <drm/drm_edid.h>
> +#include <drm/drm_file.h>
>  
>  #include "cec-priv.h"
>  
> @@ -75,6 +78,16 @@ u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
>  }
>  EXPORT_SYMBOL_GPL(cec_get_edid_phys_addr);
>  
> +void cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info,
> +				 const struct drm_connector *connector)
> +{
> +	memset(conn_info, 0, sizeof(*conn_info));
> +	conn_info->type = CEC_CONNECTOR_TYPE_DRM;
> +	conn_info->drm.card_no = connector->dev->primary->index;
> +	conn_info->drm.connector_id = connector->base.id;
> +}
> +EXPORT_SYMBOL_GPL(cec_fill_conn_info_from_drm);
> +
>  /*
>   * Queue a new event for this filehandle. If ts == 0, then set it
>   * to the current time.
> @@ -1598,6 +1611,22 @@ void cec_s_phys_addr_from_edid(struct cec_adapter *adap,
>  }
>  EXPORT_SYMBOL_GPL(cec_s_phys_addr_from_edid);
>  
> +void cec_s_conn_info(struct cec_adapter *adap,
> +		     const struct cec_connector_info *conn_info)
> +{
> +	if (!(adap->capabilities & CEC_CAP_CONNECTOR_INFO))
> +		return;
> +
> +	mutex_lock(&adap->lock);
> +	if (conn_info)
> +		adap->conn_info = *conn_info;
> +	else
> +		memset(&adap->conn_info, 0, sizeof(adap->conn_info));
> +	cec_post_state_event(adap);
> +	mutex_unlock(&adap->lock);
> +}
> +EXPORT_SYMBOL_GPL(cec_s_conn_info);
> +
>  /*
>   * Called from either the ioctl or a driver to set the logical addresses.
>   *
> diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c
> index db7adffcdc76..e45b792d26fb 100644
> --- a/drivers/media/cec/cec-core.c
> +++ b/drivers/media/cec/cec-core.c
> @@ -189,6 +189,11 @@ static void cec_cec_notify(struct cec_adapter *adap, u16 pa)
>  	cec_s_phys_addr(adap, pa, false);
>  }
>  
> +void cec_notifier_register(struct cec_notifier *n,
> +			   struct cec_adapter *adap,
> +			   void (*callback)(struct cec_adapter *adap, u16 pa));
> +void cec_notifier_unregister(struct cec_notifier *n);
> +
>  void cec_register_cec_notifier(struct cec_adapter *adap,
>  			       struct cec_notifier *notifier)
>  {
> diff --git a/include/media/cec.h b/include/media/cec.h
> index 707411ef8ba2..45f2c98ed75b 100644
> --- a/include/media/cec.h
> +++ b/include/media/cec.h
> @@ -17,7 +17,9 @@
>  #include <linux/timer.h>
>  #include <linux/cec-funcs.h>
>  #include <media/rc-core.h>
> -#include <media/cec-notifier.h>
> +
> +/* CEC_ADAP_G_CONNECTOR_INFO is available */
> +#define CEC_CAP_CONNECTOR_INFO	0
>  
>  #define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \
>  			  CEC_CAP_PASSTHROUGH | CEC_CAP_RC)
> @@ -53,6 +55,7 @@ struct cec_devnode {
>  struct cec_adapter;
>  struct cec_data;
>  struct cec_pin;
> +struct cec_notifier;
>  
>  struct cec_data {
>  	struct list_head list;
> @@ -144,6 +147,27 @@ struct cec_adap_ops {
>   */
>  #define CEC_MAX_MSG_TX_QUEUE_SZ		(18 * 1)
>  
> +/**
> + * struct cec_event_connector - tells if and which connector is associated
> + * with the CEC adapter.
> + * @card_no: drm card number
> + * @connector_id: drm connector ID
> + */
> +struct cec_drm_connector_info {
> +	__u32 card_no;
> +	__u32 connector_id;
> +};
> +
> +#define CEC_CONNECTOR_TYPE_NO_CONNECTOR	0
> +#define CEC_CONNECTOR_TYPE_DRM		1
> +struct cec_connector_info {
> +	__u32 type;
> +	union {
> +		struct cec_drm_connector_info drm;
> +		__u32 raw[16];
> +	};
> +};
> +
>  struct cec_adapter {
>  	struct module *owner;
>  	char name[32];
> @@ -182,6 +206,7 @@ struct cec_adapter {
>  	struct cec_fh *cec_initiator;
>  	bool passthrough;
>  	struct cec_log_addrs log_addrs;
> +	struct cec_connector_info conn_info;
>  
>  	u32 tx_timeouts;
>  
> @@ -233,6 +258,7 @@ static inline bool cec_is_registered(const struct cec_adapter *adap)
>  	((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf
>  
>  struct edid;
> +struct drm_connector;
>  
>  #if IS_REACHABLE(CONFIG_CEC_CORE)
>  struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
> @@ -247,6 +273,8 @@ void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr,
>  		     bool block);
>  void cec_s_phys_addr_from_edid(struct cec_adapter *adap,
>  			       const struct edid *edid);
> +void cec_s_conn_info(struct cec_adapter *adap,
> +		     const struct cec_connector_info *conn_info);
>  int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg,
>  		     bool block);
>  
> @@ -331,6 +359,9 @@ void cec_queue_pin_5v_event(struct cec_adapter *adap, bool is_high, ktime_t ts);
>  u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
>  			   unsigned int *offset);
>  
> +void cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info,
> +				 const struct drm_connector *connector);
> +
>  #else
>  
>  static inline int cec_register_adapter(struct cec_adapter *adap,
> @@ -365,6 +396,18 @@ static inline u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
>  	return CEC_PHYS_ADDR_INVALID;
>  }
>  
> +static inline void cec_s_conn_info(struct cec_adapter *adap,
> +				   const struct cec_connector_info *conn_info)
> +{
> +}
> +
> +static inline void
> +cec_fill_conn_info_from_drm(const struct drm_connector *connector,
> +			    struct cec_connector_info *conn_info)

Oops, these arguments are the wrong way around. conn_info comes first.

This is already fixed in my branch:

https://git.linuxtv.org/hverkuil/media_tree.git/log/?h=cec-conn

Regards,

	Hans

> +{
> +	memset(conn_info, 0, sizeof(*conn_info));
> +}
> +
>  #endif
>  
>  /**
> 

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCHv8.1 01/13] cec-notifier: rename variables, check kstrdup and n->conn_name
  2019-06-24 16:03   ` Hans Verkuil
@ 2019-06-25  7:07     ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-25  7:07 UTC (permalink / raw)
  To: linux-media; +Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

dev -> hdmi_dev
conn -> conn_name

Check if n->conn_name is not NULL before calling strcmp.
Check the result of kstrdup, and clean up on error.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
Changes since v8:

- check n->conn_name before calling strcmp to make the code more robust
---
 drivers/media/cec/cec-notifier.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c
index 9598c7778871..f72b19c351dd 100644
--- a/drivers/media/cec/cec-notifier.c
+++ b/drivers/media/cec/cec-notifier.c
@@ -21,8 +21,8 @@ struct cec_notifier {
 	struct mutex lock;
 	struct list_head head;
 	struct kref kref;
-	struct device *dev;
-	const char *conn;
+	struct device *hdmi_dev;
+	const char *conn_name;
 	struct cec_adapter *cec_adap;
 	void (*callback)(struct cec_adapter *adap, u16 pa);

@@ -32,14 +32,16 @@ struct cec_notifier {
 static LIST_HEAD(cec_notifiers);
 static DEFINE_MUTEX(cec_notifiers_lock);

-struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
+struct cec_notifier *
+cec_notifier_get_conn(struct device *hdmi_dev, const char *conn_name)
 {
 	struct cec_notifier *n;

 	mutex_lock(&cec_notifiers_lock);
 	list_for_each_entry(n, &cec_notifiers, head) {
-		if (n->dev == dev &&
-		    (!conn || !strcmp(n->conn, conn))) {
+		if (n->hdmi_dev == hdmi_dev &&
+		    (!conn_name ||
+		     (n->conn_name && !strcmp(n->conn_name, conn_name)))) {
 			kref_get(&n->kref);
 			mutex_unlock(&cec_notifiers_lock);
 			return n;
@@ -48,10 +50,17 @@ struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
 	n = kzalloc(sizeof(*n), GFP_KERNEL);
 	if (!n)
 		goto unlock;
-	n->dev = dev;
-	if (conn)
-		n->conn = kstrdup(conn, GFP_KERNEL);
+	n->hdmi_dev = hdmi_dev;
+	if (conn_name) {
+		n->conn_name = kstrdup(conn_name, GFP_KERNEL);
+		if (!n->conn_name) {
+			kfree(n);
+			n = NULL;
+			goto unlock;
+		}
+	}
 	n->phys_addr = CEC_PHYS_ADDR_INVALID;
+
 	mutex_init(&n->lock);
 	kref_init(&n->kref);
 	list_add_tail(&n->head, &cec_notifiers);
@@ -67,7 +76,7 @@ static void cec_notifier_release(struct kref *kref)
 		container_of(kref, struct cec_notifier, kref);

 	list_del(&n->head);
-	kfree(n->conn);
+	kfree(n->conn_name);
 	kfree(n);
 }

-- 
2.20.1



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

* [PATCHv8.1 01/13] cec-notifier: rename variables, check kstrdup and n->conn_name
@ 2019-06-25  7:07     ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-25  7:07 UTC (permalink / raw)
  To: linux-media; +Cc: Dariusz Marcinkiewicz, dri-devel, Cheng-yi Chiang

dev -> hdmi_dev
conn -> conn_name

Check if n->conn_name is not NULL before calling strcmp.
Check the result of kstrdup, and clean up on error.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
Changes since v8:

- check n->conn_name before calling strcmp to make the code more robust
---
 drivers/media/cec/cec-notifier.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c
index 9598c7778871..f72b19c351dd 100644
--- a/drivers/media/cec/cec-notifier.c
+++ b/drivers/media/cec/cec-notifier.c
@@ -21,8 +21,8 @@ struct cec_notifier {
 	struct mutex lock;
 	struct list_head head;
 	struct kref kref;
-	struct device *dev;
-	const char *conn;
+	struct device *hdmi_dev;
+	const char *conn_name;
 	struct cec_adapter *cec_adap;
 	void (*callback)(struct cec_adapter *adap, u16 pa);

@@ -32,14 +32,16 @@ struct cec_notifier {
 static LIST_HEAD(cec_notifiers);
 static DEFINE_MUTEX(cec_notifiers_lock);

-struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
+struct cec_notifier *
+cec_notifier_get_conn(struct device *hdmi_dev, const char *conn_name)
 {
 	struct cec_notifier *n;

 	mutex_lock(&cec_notifiers_lock);
 	list_for_each_entry(n, &cec_notifiers, head) {
-		if (n->dev == dev &&
-		    (!conn || !strcmp(n->conn, conn))) {
+		if (n->hdmi_dev == hdmi_dev &&
+		    (!conn_name ||
+		     (n->conn_name && !strcmp(n->conn_name, conn_name)))) {
 			kref_get(&n->kref);
 			mutex_unlock(&cec_notifiers_lock);
 			return n;
@@ -48,10 +50,17 @@ struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
 	n = kzalloc(sizeof(*n), GFP_KERNEL);
 	if (!n)
 		goto unlock;
-	n->dev = dev;
-	if (conn)
-		n->conn = kstrdup(conn, GFP_KERNEL);
+	n->hdmi_dev = hdmi_dev;
+	if (conn_name) {
+		n->conn_name = kstrdup(conn_name, GFP_KERNEL);
+		if (!n->conn_name) {
+			kfree(n);
+			n = NULL;
+			goto unlock;
+		}
+	}
 	n->phys_addr = CEC_PHYS_ADDR_INVALID;
+
 	mutex_init(&n->lock);
 	kref_init(&n->kref);
 	list_add_tail(&n->head, &cec_notifiers);
@@ -67,7 +76,7 @@ static void cec_notifier_release(struct kref *kref)
 		container_of(kref, struct cec_notifier, kref);

 	list_del(&n->head);
-	kfree(n->conn);
+	kfree(n->conn_name);
 	kfree(n);
 }

-- 
2.20.1


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCHv8 02/13] cec: add struct cec_connector_info support
  2019-06-24 16:03   ` Hans Verkuil
@ 2019-06-25 13:19     ` Dariusz Marcinkiewicz
  -1 siblings, 0 replies; 46+ messages in thread
From: Dariusz Marcinkiewicz @ 2019-06-25 13:19 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, dri-devel, Cheng-yi Chiang

Hi Hans.

Patches 1 and 2 look good to me. There is one comment here that I
forgot to update as the code evolved.

On Mon, Jun 24, 2019 at 6:03 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
...
> +/**
> + * struct cec_event_connector - tells if and which connector is associated
> + * with the CEC adapter.
> + * @card_no: drm card number
> + * @connector_id: drm connector ID
> + */
> +struct cec_drm_connector_info {
> +       __u32 card_no;
> +       __u32 connector_id;
> +};
> +
The comment for the above struct is now appropriate for the struct below.

> +#define CEC_CONNECTOR_TYPE_NO_CONNECTOR        0
> +#define CEC_CONNECTOR_TYPE_DRM         1
> +struct cec_connector_info {
> +       __u32 type;
> +       union {
> +               struct cec_drm_connector_info drm;
> +               __u32 raw[16];
> +       };
> +};
> +

Best regards.

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

* Re: [PATCHv8 02/13] cec: add struct cec_connector_info support
@ 2019-06-25 13:19     ` Dariusz Marcinkiewicz
  0 siblings, 0 replies; 46+ messages in thread
From: Dariusz Marcinkiewicz @ 2019-06-25 13:19 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Cheng-yi Chiang, dri-devel, linux-media

Hi Hans.

Patches 1 and 2 look good to me. There is one comment here that I
forgot to update as the code evolved.

On Mon, Jun 24, 2019 at 6:03 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
...
> +/**
> + * struct cec_event_connector - tells if and which connector is associated
> + * with the CEC adapter.
> + * @card_no: drm card number
> + * @connector_id: drm connector ID
> + */
> +struct cec_drm_connector_info {
> +       __u32 card_no;
> +       __u32 connector_id;
> +};
> +
The comment for the above struct is now appropriate for the struct below.

> +#define CEC_CONNECTOR_TYPE_NO_CONNECTOR        0
> +#define CEC_CONNECTOR_TYPE_DRM         1
> +struct cec_connector_info {
> +       __u32 type;
> +       union {
> +               struct cec_drm_connector_info drm;
> +               __u32 raw[16];
> +       };
> +};
> +

Best regards.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCHv8 03/13] cec: add new notifier functions
  2019-06-24 16:03   ` Hans Verkuil
@ 2019-06-25 13:48     ` Dariusz Marcinkiewicz
  -1 siblings, 0 replies; 46+ messages in thread
From: Dariusz Marcinkiewicz @ 2019-06-25 13:48 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, dri-devel, Cheng-yi Chiang

Hello.

Some small comments/questions.

On Mon, Jun 24, 2019 at 6:03 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>
...
> @@ -22,9 +22,11 @@ struct cec_notifier {
>         struct list_head head;
>         struct kref kref;
>         struct device *hdmi_dev;
> +       struct cec_connector_info conn_info;
>         const char *conn_name;
>         struct cec_adapter *cec_adap;
>         void (*callback)(struct cec_adapter *adap, u16 pa);
> +       bool called_cec_notifier_register;
If I read his correctly callback is set only by cec_notifier_register
(and not by the cec_notifier_cec_adap_register) so maybe that boolean
is not needed and just checking if the callback is set is enough to
tell those 2 cases apart?

...
> +struct cec_notifier *
> +cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
> +                              struct cec_adapter *adap)
> +{
> +       struct cec_notifier *n;
> +
> +       if (WARN_ON(!adap))
> +               return NULL;
> +
> +       n = cec_notifier_get_conn(hdmi_dev, conn_name);
> +       if (!n)
> +               return n;
> +
> +       mutex_lock(&n->lock);
> +       n->cec_adap = adap;
> +       adap->conn_info = n->conn_info;
Would it make sense to use cec_s_conn_info? There is a certain
asymmetry here  - cec_s_phys_addr is used to configure physical
address, which also takes the adapter's lock while setting the
physical address. That lock is not taken while the connector info is
being set (not sure if that really matters for the code paths that
would call into this function).

> +       adap->notifier = n;
> +       cec_s_phys_addr(adap, n->phys_addr, false);
> +       mutex_unlock(&n->lock);
> +       return n;
> +}
> +EXPORT_SYMBOL_GPL(cec_notifier_cec_adap_register);
> +
> +void cec_notifier_cec_adap_unregister(struct cec_notifier *n)
> +{
> +       if (!n)
> +               return;
> +
> +       mutex_lock(&n->lock);
> +       memset(&n->cec_adap->conn_info, 0, sizeof(n->cec_adap->conn_info));
Could cec_s_conn_info be used to reset the connector info?
Also, we explicitly clear connector info here. Since the notifier
provides both connector info and physical address, maybe it would make
sense to clear physical address as well?


...
>  void cec_notifier_unregister(struct cec_notifier *n)
>  {
> +       /* Do nothing unless cec_notifier_register was called first */
> +       if (!n->called_cec_notifier_register)
Could this check be made with n->lock held? cec_notifier_register sets
this value while holding that lock.
...


Thank you.

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

* Re: [PATCHv8 03/13] cec: add new notifier functions
@ 2019-06-25 13:48     ` Dariusz Marcinkiewicz
  0 siblings, 0 replies; 46+ messages in thread
From: Dariusz Marcinkiewicz @ 2019-06-25 13:48 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Cheng-yi Chiang, dri-devel, linux-media

Hello.

Some small comments/questions.

On Mon, Jun 24, 2019 at 6:03 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>
...
> @@ -22,9 +22,11 @@ struct cec_notifier {
>         struct list_head head;
>         struct kref kref;
>         struct device *hdmi_dev;
> +       struct cec_connector_info conn_info;
>         const char *conn_name;
>         struct cec_adapter *cec_adap;
>         void (*callback)(struct cec_adapter *adap, u16 pa);
> +       bool called_cec_notifier_register;
If I read his correctly callback is set only by cec_notifier_register
(and not by the cec_notifier_cec_adap_register) so maybe that boolean
is not needed and just checking if the callback is set is enough to
tell those 2 cases apart?

...
> +struct cec_notifier *
> +cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
> +                              struct cec_adapter *adap)
> +{
> +       struct cec_notifier *n;
> +
> +       if (WARN_ON(!adap))
> +               return NULL;
> +
> +       n = cec_notifier_get_conn(hdmi_dev, conn_name);
> +       if (!n)
> +               return n;
> +
> +       mutex_lock(&n->lock);
> +       n->cec_adap = adap;
> +       adap->conn_info = n->conn_info;
Would it make sense to use cec_s_conn_info? There is a certain
asymmetry here  - cec_s_phys_addr is used to configure physical
address, which also takes the adapter's lock while setting the
physical address. That lock is not taken while the connector info is
being set (not sure if that really matters for the code paths that
would call into this function).

> +       adap->notifier = n;
> +       cec_s_phys_addr(adap, n->phys_addr, false);
> +       mutex_unlock(&n->lock);
> +       return n;
> +}
> +EXPORT_SYMBOL_GPL(cec_notifier_cec_adap_register);
> +
> +void cec_notifier_cec_adap_unregister(struct cec_notifier *n)
> +{
> +       if (!n)
> +               return;
> +
> +       mutex_lock(&n->lock);
> +       memset(&n->cec_adap->conn_info, 0, sizeof(n->cec_adap->conn_info));
Could cec_s_conn_info be used to reset the connector info?
Also, we explicitly clear connector info here. Since the notifier
provides both connector info and physical address, maybe it would make
sense to clear physical address as well?


...
>  void cec_notifier_unregister(struct cec_notifier *n)
>  {
> +       /* Do nothing unless cec_notifier_register was called first */
> +       if (!n->called_cec_notifier_register)
Could this check be made with n->lock held? cec_notifier_register sets
this value while holding that lock.
...


Thank you.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCHv8 04/13] cec: expose the new connector info API
  2019-06-24 16:03   ` Hans Verkuil
@ 2019-06-25 13:59     ` Dariusz Marcinkiewicz
  -1 siblings, 0 replies; 46+ messages in thread
From: Dariusz Marcinkiewicz @ 2019-06-25 13:59 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, dri-devel, Cheng-yi Chiang

Hi.

This looks good except one comment about the ioctl.

On Mon, Jun 24, 2019 at 6:03 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>
...
> +static long cec_adap_g_connector_info(struct cec_adapter *adap,
> +                                     struct cec_log_addrs __user *parg)
> +{
> +       if (!(adap->capabilities & CEC_CAP_CONNECTOR_INFO))
> +               return -ENOTTY;
I guess access to adap->conn_info needs to be guarded by the lock now.

> +       if (copy_to_user(parg, &adap->conn_info,
> +                        sizeof(adap->conn_info)))
> +               return -EFAULT;
> +       return 0;
> +}

Best regards.

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

* Re: [PATCHv8 04/13] cec: expose the new connector info API
@ 2019-06-25 13:59     ` Dariusz Marcinkiewicz
  0 siblings, 0 replies; 46+ messages in thread
From: Dariusz Marcinkiewicz @ 2019-06-25 13:59 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Cheng-yi Chiang, dri-devel, linux-media

Hi.

This looks good except one comment about the ioctl.

On Mon, Jun 24, 2019 at 6:03 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>
...
> +static long cec_adap_g_connector_info(struct cec_adapter *adap,
> +                                     struct cec_log_addrs __user *parg)
> +{
> +       if (!(adap->capabilities & CEC_CAP_CONNECTOR_INFO))
> +               return -ENOTTY;
I guess access to adap->conn_info needs to be guarded by the lock now.

> +       if (copy_to_user(parg, &adap->conn_info,
> +                        sizeof(adap->conn_info)))
> +               return -EFAULT;
> +       return 0;
> +}

Best regards.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCHv8 03/13] cec: add new notifier functions
  2019-06-25 13:48     ` Dariusz Marcinkiewicz
@ 2019-06-25 14:26       ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-25 14:26 UTC (permalink / raw)
  To: Dariusz Marcinkiewicz; +Cc: linux-media, dri-devel, Cheng-yi Chiang

On 6/25/19 3:48 PM, Dariusz Marcinkiewicz wrote:
> Hello.
> 
> Some small comments/questions.
> 
> On Mon, Jun 24, 2019 at 6:03 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>>
> ...
>> @@ -22,9 +22,11 @@ struct cec_notifier {
>>         struct list_head head;
>>         struct kref kref;
>>         struct device *hdmi_dev;
>> +       struct cec_connector_info conn_info;
>>         const char *conn_name;
>>         struct cec_adapter *cec_adap;
>>         void (*callback)(struct cec_adapter *adap, u16 pa);
>> +       bool called_cec_notifier_register;
> If I read his correctly callback is set only by cec_notifier_register
> (and not by the cec_notifier_cec_adap_register) so maybe that boolean
> is not needed and just checking if the callback is set is enough to
> tell those 2 cases apart?

True. I'll change this.

> 
> ...
>> +struct cec_notifier *
>> +cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
>> +                              struct cec_adapter *adap)
>> +{
>> +       struct cec_notifier *n;
>> +
>> +       if (WARN_ON(!adap))
>> +               return NULL;
>> +
>> +       n = cec_notifier_get_conn(hdmi_dev, conn_name);
>> +       if (!n)
>> +               return n;
>> +
>> +       mutex_lock(&n->lock);
>> +       n->cec_adap = adap;
>> +       adap->conn_info = n->conn_info;
> Would it make sense to use cec_s_conn_info? There is a certain
> asymmetry here  - cec_s_phys_addr is used to configure physical
> address, which also takes the adapter's lock while setting the
> physical address. That lock is not taken while the connector info is
> being set (not sure if that really matters for the code paths that
> would call into this function).

I thought about that, but there is a side-effect if I do that:
both cec_s_conn_info and cec_s_phys_addr send a state_changed
event, and I want to avoid that. Doing it this way ensures that
there will be only one event.

But there is definitely room for improvement here and I want to
work on that for the next kernel.

> 
>> +       adap->notifier = n;
>> +       cec_s_phys_addr(adap, n->phys_addr, false);
>> +       mutex_unlock(&n->lock);
>> +       return n;
>> +}
>> +EXPORT_SYMBOL_GPL(cec_notifier_cec_adap_register);
>> +
>> +void cec_notifier_cec_adap_unregister(struct cec_notifier *n)
>> +{
>> +       if (!n)
>> +               return;
>> +
>> +       mutex_lock(&n->lock);
>> +       memset(&n->cec_adap->conn_info, 0, sizeof(n->cec_adap->conn_info));
> Could cec_s_conn_info be used to reset the connector info?
> Also, we explicitly clear connector info here. Since the notifier
> provides both connector info and physical address, maybe it would make
> sense to clear physical address as well?

Actually, this memset should be removed altogether. The connector info
doesn't change at all, it's just that right after this function is called
the whole CEC adapter will be unregistered. I thought that it might make
sense to zero the connector info, but really I should just leave it alone.

> 
> 
> ...
>>  void cec_notifier_unregister(struct cec_notifier *n)
>>  {
>> +       /* Do nothing unless cec_notifier_register was called first */
>> +       if (!n->called_cec_notifier_register)
> Could this check be made with n->lock held? cec_notifier_register sets
> this value while holding that lock.

It's not needed: you can never have a race here.

BTW, I'll be glad when I can remove these cec_notifier_(un)register
functions, they are pretty ugly and confusing.

Regards,

	Hans

> ...
> 
> 
> Thank you.
> 


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

* Re: [PATCHv8 03/13] cec: add new notifier functions
@ 2019-06-25 14:26       ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-25 14:26 UTC (permalink / raw)
  To: Dariusz Marcinkiewicz; +Cc: Cheng-yi Chiang, dri-devel, linux-media

On 6/25/19 3:48 PM, Dariusz Marcinkiewicz wrote:
> Hello.
> 
> Some small comments/questions.
> 
> On Mon, Jun 24, 2019 at 6:03 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>>
> ...
>> @@ -22,9 +22,11 @@ struct cec_notifier {
>>         struct list_head head;
>>         struct kref kref;
>>         struct device *hdmi_dev;
>> +       struct cec_connector_info conn_info;
>>         const char *conn_name;
>>         struct cec_adapter *cec_adap;
>>         void (*callback)(struct cec_adapter *adap, u16 pa);
>> +       bool called_cec_notifier_register;
> If I read his correctly callback is set only by cec_notifier_register
> (and not by the cec_notifier_cec_adap_register) so maybe that boolean
> is not needed and just checking if the callback is set is enough to
> tell those 2 cases apart?

True. I'll change this.

> 
> ...
>> +struct cec_notifier *
>> +cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
>> +                              struct cec_adapter *adap)
>> +{
>> +       struct cec_notifier *n;
>> +
>> +       if (WARN_ON(!adap))
>> +               return NULL;
>> +
>> +       n = cec_notifier_get_conn(hdmi_dev, conn_name);
>> +       if (!n)
>> +               return n;
>> +
>> +       mutex_lock(&n->lock);
>> +       n->cec_adap = adap;
>> +       adap->conn_info = n->conn_info;
> Would it make sense to use cec_s_conn_info? There is a certain
> asymmetry here  - cec_s_phys_addr is used to configure physical
> address, which also takes the adapter's lock while setting the
> physical address. That lock is not taken while the connector info is
> being set (not sure if that really matters for the code paths that
> would call into this function).

I thought about that, but there is a side-effect if I do that:
both cec_s_conn_info and cec_s_phys_addr send a state_changed
event, and I want to avoid that. Doing it this way ensures that
there will be only one event.

But there is definitely room for improvement here and I want to
work on that for the next kernel.

> 
>> +       adap->notifier = n;
>> +       cec_s_phys_addr(adap, n->phys_addr, false);
>> +       mutex_unlock(&n->lock);
>> +       return n;
>> +}
>> +EXPORT_SYMBOL_GPL(cec_notifier_cec_adap_register);
>> +
>> +void cec_notifier_cec_adap_unregister(struct cec_notifier *n)
>> +{
>> +       if (!n)
>> +               return;
>> +
>> +       mutex_lock(&n->lock);
>> +       memset(&n->cec_adap->conn_info, 0, sizeof(n->cec_adap->conn_info));
> Could cec_s_conn_info be used to reset the connector info?
> Also, we explicitly clear connector info here. Since the notifier
> provides both connector info and physical address, maybe it would make
> sense to clear physical address as well?

Actually, this memset should be removed altogether. The connector info
doesn't change at all, it's just that right after this function is called
the whole CEC adapter will be unregistered. I thought that it might make
sense to zero the connector info, but really I should just leave it alone.

> 
> 
> ...
>>  void cec_notifier_unregister(struct cec_notifier *n)
>>  {
>> +       /* Do nothing unless cec_notifier_register was called first */
>> +       if (!n->called_cec_notifier_register)
> Could this check be made with n->lock held? cec_notifier_register sets
> this value while holding that lock.

It's not needed: you can never have a race here.

BTW, I'll be glad when I can remove these cec_notifier_(un)register
functions, they are pretty ugly and confusing.

Regards,

	Hans

> ...
> 
> 
> Thank you.
> 

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCHv8 04/13] cec: expose the new connector info API
  2019-06-25 13:59     ` Dariusz Marcinkiewicz
@ 2019-06-25 14:28       ` Hans Verkuil
  -1 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-25 14:28 UTC (permalink / raw)
  To: Dariusz Marcinkiewicz; +Cc: linux-media, dri-devel, Cheng-yi Chiang

On 6/25/19 3:59 PM, Dariusz Marcinkiewicz wrote:
> Hi.
> 
> This looks good except one comment about the ioctl.
> 
> On Mon, Jun 24, 2019 at 6:03 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>>
> ...
>> +static long cec_adap_g_connector_info(struct cec_adapter *adap,
>> +                                     struct cec_log_addrs __user *parg)
>> +{
>> +       if (!(adap->capabilities & CEC_CAP_CONNECTOR_INFO))
>> +               return -ENOTTY;
> I guess access to adap->conn_info needs to be guarded by the lock now.

Good catch! Yes, this needs a lock.

Regards,

	Hans

> 
>> +       if (copy_to_user(parg, &adap->conn_info,
>> +                        sizeof(adap->conn_info)))
>> +               return -EFAULT;
>> +       return 0;
>> +}
> 
> Best regards.
> 


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

* Re: [PATCHv8 04/13] cec: expose the new connector info API
@ 2019-06-25 14:28       ` Hans Verkuil
  0 siblings, 0 replies; 46+ messages in thread
From: Hans Verkuil @ 2019-06-25 14:28 UTC (permalink / raw)
  To: Dariusz Marcinkiewicz; +Cc: Cheng-yi Chiang, dri-devel, linux-media

On 6/25/19 3:59 PM, Dariusz Marcinkiewicz wrote:
> Hi.
> 
> This looks good except one comment about the ioctl.
> 
> On Mon, Jun 24, 2019 at 6:03 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>>
> ...
>> +static long cec_adap_g_connector_info(struct cec_adapter *adap,
>> +                                     struct cec_log_addrs __user *parg)
>> +{
>> +       if (!(adap->capabilities & CEC_CAP_CONNECTOR_INFO))
>> +               return -ENOTTY;
> I guess access to adap->conn_info needs to be guarded by the lock now.

Good catch! Yes, this needs a lock.

Regards,

	Hans

> 
>> +       if (copy_to_user(parg, &adap->conn_info,
>> +                        sizeof(adap->conn_info)))
>> +               return -EFAULT;
>> +       return 0;
>> +}
> 
> Best regards.
> 

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2019-06-25 14:28 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24 16:03 [PATCHv8 00/13] cec: improve notifier support, add connector info Hans Verkuil
2019-06-24 16:03 ` Hans Verkuil
2019-06-24 16:03 ` [PATCHv8 01/13] cec-notifier: rename variable, check kstrdup Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-25  7:07   ` [PATCHv8.1 01/13] cec-notifier: rename variables, check kstrdup and n->conn_name Hans Verkuil
2019-06-25  7:07     ` Hans Verkuil
2019-06-24 16:03 ` [PATCHv8 02/13] cec: add struct cec_connector_info support Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-25  6:28   ` Hans Verkuil
2019-06-25  6:28     ` Hans Verkuil
2019-06-25 13:19   ` Dariusz Marcinkiewicz
2019-06-25 13:19     ` Dariusz Marcinkiewicz
2019-06-24 16:03 ` [PATCHv8 03/13] cec: add new notifier functions Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-25 13:48   ` Dariusz Marcinkiewicz
2019-06-25 13:48     ` Dariusz Marcinkiewicz
2019-06-25 14:26     ` Hans Verkuil
2019-06-25 14:26       ` Hans Verkuil
2019-06-24 16:03 ` [PATCHv8 04/13] cec: expose the new connector info API Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-25 13:59   ` Dariusz Marcinkiewicz
2019-06-25 13:59     ` Dariusz Marcinkiewicz
2019-06-25 14:28     ` Hans Verkuil
2019-06-25 14:28       ` Hans Verkuil
2019-06-24 16:03 ` [PATCHv8 05/13] cec: document CEC_ADAP_G_CONNECTOR_INFO Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-24 16:03 ` [PATCHv8 06/13] drm_dp_cec: add connector info support Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-24 16:03 ` [PATCHv8 07/13] drm/i915/intel_hdmi: use cec_notifier_conn_(un)register Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-24 16:03 ` [PATCHv8 08/13] dw-hdmi-cec: use cec_notifier_cec_adap_(un)register Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-24 16:03 ` [PATCHv8 09/13] dw-hdmi: use cec_notifier_conn_(un)register Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-25  0:43   ` kbuild test robot
2019-06-25  0:43     ` kbuild test robot
2019-06-24 16:03 ` [PATCHv8 10/13] meson/ao-cec: use cec_notifier_cec_adap_(un)register Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-24 16:03 ` [PATCHv8 11/13] tda9950: " Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-24 16:03 ` [PATCHv8 12/13] tda998x: use cec_notifier_conn_(un)register Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil
2019-06-24 22:37   ` kbuild test robot
2019-06-24 22:37     ` kbuild test robot
2019-06-24 16:03 ` [PATCHv8 13/13] drm/vc4/vc4_hdmi: fill in connector info Hans Verkuil
2019-06-24 16:03   ` Hans Verkuil

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