cec_notifier_phys_addr_invalidate must call cec_phys_addr_invalidate
instead of cec_s_phys_addr. This ensures that the CEC framework knowns
that there is no HPD.

Also update cec_notifier_cec_adap_register(): it has to remember if
the last set physical address was from an EDID or because there was
a disconnect.

Signed-off-by: Hans Verkuil <[email protected]>
---
 drivers/media/cec/core/cec-notifier.c | 26 +++++++++++++++++++--
 include/media/cec-notifier.h          | 33 +++++++++++++++------------
 2 files changed, 43 insertions(+), 16 deletions(-)

diff --git a/drivers/media/cec/core/cec-notifier.c 
b/drivers/media/cec/core/cec-notifier.c
index 8cf1474d0361..5a4588487ea3 100644
--- a/drivers/media/cec/core/cec-notifier.c
+++ b/drivers/media/cec/core/cec-notifier.c
@@ -29,6 +29,7 @@ struct cec_notifier {
        struct cec_adapter *cec_adap;
 
        u16 phys_addr;
+       bool edid_present;
 };
 
 static LIST_HEAD(cec_notifiers);
@@ -113,6 +114,7 @@ cec_notifier_conn_register(struct device *hdmi_dev, const 
char *port_name,
 
        mutex_lock(&n->lock);
        n->phys_addr = CEC_PHYS_ADDR_INVALID;
+       n->edid_present = false;
        if (conn_info)
                n->conn_info = *conn_info;
        else
@@ -135,6 +137,7 @@ void cec_notifier_conn_unregister(struct cec_notifier *n)
        mutex_lock(&n->lock);
        memset(&n->conn_info, 0, sizeof(n->conn_info));
        n->phys_addr = CEC_PHYS_ADDR_INVALID;
+       n->edid_present = false;
        if (n->cec_adap) {
                if (!n->cec_adap->adap_controls_phys_addr)
                        cec_phys_addr_invalidate(n->cec_adap);
@@ -162,8 +165,12 @@ cec_notifier_cec_adap_register(struct device *hdmi_dev, 
const char *port_name,
        n->cec_adap = adap;
        adap->conn_info = n->conn_info;
        adap->notifier = n;
-       if (!adap->adap_controls_phys_addr)
-               cec_s_phys_addr(adap, n->phys_addr, false);
+       if (!adap->adap_controls_phys_addr) {
+               if (n->phys_addr == CEC_PHYS_ADDR_INVALID && !n->edid_present)
+                       cec_phys_addr_invalidate(adap);
+               else
+                       cec_s_phys_addr(adap, n->phys_addr, false);
+       }
        mutex_unlock(&n->lock);
        return n;
 }
@@ -190,6 +197,7 @@ void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 
pa)
 
        mutex_lock(&n->lock);
        n->phys_addr = pa;
+       n->edid_present = true;
        if (n->cec_adap && !n->cec_adap->adap_controls_phys_addr)
                cec_s_phys_addr(n->cec_adap, n->phys_addr, false);
        mutex_unlock(&n->lock);
@@ -216,6 +224,20 @@ void cec_notifier_set_phys_addr_from_edid(struct 
cec_notifier *n,
 }
 EXPORT_SYMBOL_GPL(cec_notifier_set_phys_addr_from_edid);
 
+void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
+{
+       if (!n)
+               return;
+
+       mutex_lock(&n->lock);
+       n->phys_addr = CEC_PHYS_ADDR_INVALID;
+       n->edid_present = false;
+       if (n->cec_adap && !n->cec_adap->adap_controls_phys_addr)
+               cec_phys_addr_invalidate(n->cec_adap);
+       mutex_unlock(&n->lock);
+}
+EXPORT_SYMBOL_GPL(cec_notifier_phys_addr_invalidate);
+
 struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
 {
        struct platform_device *hdmi_pdev;
diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h
index b1c839734124..15e9bcb5b887 100644
--- a/include/media/cec-notifier.h
+++ b/include/media/cec-notifier.h
@@ -80,7 +80,10 @@ void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
  * @n: the CEC notifier
  * @pa: the CEC physical address
  *
- * Set a new CEC physical address.
+ * Set a new CEC physical address. @pa may be f.f.f.f, indicating that
+ * the EDID does not contain a valid Physical Address.
+ * Use @cec_notifier_phys_addr_invalidate() when there is no EDID at all,
+ * i.e. there is no video sink connected.
  * Does nothing if @n == NULL.
  */
 void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
@@ -96,6 +99,17 @@ void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 
pa);
 void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
                                          const struct edid *edid);
 
+/**
+ * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
+ *
+ * @n: the CEC notifier
+ *
+ * This is a simple helper function to invalidate the physical
+ * address when the video sink disappears.
+ * Does nothing if @n == NULL.
+ */
+void cec_notifier_phys_addr_invalidate(struct cec_notifier *n);
+
 /**
  * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
  * @dev: the device with the "hdmi-phandle" device tree property
@@ -143,6 +157,10 @@ static inline void 
cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
 {
 }
 
+static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
+{
+}
+
 static inline struct device *cec_notifier_parse_hdmi_phandle(struct device 
*dev)
 {
        return ERR_PTR(-ENODEV);
@@ -150,17 +168,4 @@ static inline struct device 
*cec_notifier_parse_hdmi_phandle(struct device *dev)
 
 #endif
 
-/**
- * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
- *
- * @n: the CEC notifier
- *
- * This is a simple helper function to invalidate the physical
- * address. Does nothing if @n == NULL.
- */
-static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
-{
-       cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
-}
-
 #endif
-- 
2.53.0

Reply via email to