From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from lb2-smtp-cloud6.xs4all.net ([194.109.24.28]:36798 "EHLO lb2-smtp-cloud6.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933072AbdABOTX (ORCPT ); Mon, 2 Jan 2017 09:19:23 -0500 From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Russell King , dri-devel@lists.freedesktop.org, Marek Szyprowski , Javier Martinez Canillas , Benjamin Gaignard , linux-samsung-soc@vger.kernel.org, Krzysztof Kozlowski , Inki Dae , Hans Verkuil Subject: [PATCHv2 3/4] cec: integrate HPD notifier support Date: Mon, 2 Jan 2017 15:19:06 +0100 Message-Id: <1483366747-34288-4-git-send-email-hverkuil@xs4all.nl> In-Reply-To: <1483366747-34288-1-git-send-email-hverkuil@xs4all.nl> References: <1483366747-34288-1-git-send-email-hverkuil@xs4all.nl> Sender: linux-media-owner@vger.kernel.org List-ID: From: Hans Verkuil Support the HPD notifier framework, simplifying drivers that depend on this. Signed-off-by: Hans Verkuil Tested-by: Marek Szyprowski --- drivers/media/cec/cec-core.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ include/media/cec.h | 15 +++++++++++++ 2 files changed, 65 insertions(+) diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c index aca3ab8..a466dbe 100644 --- a/drivers/media/cec/cec-core.c +++ b/drivers/media/cec/cec-core.c @@ -195,6 +195,52 @@ static void cec_devnode_unregister(struct cec_devnode *devnode) put_device(&devnode->dev); } +#ifdef CONFIG_HPD_NOTIFIERS +static u16 parse_hdmi_addr(const struct edid *edid) +{ + if (!edid || edid->extensions == 0) + return CEC_PHYS_ADDR_INVALID; + + return cec_get_edid_phys_addr((u8 *)edid, + EDID_LENGTH * (edid->extensions + 1), NULL); +} + +static int cec_hpd_notify(struct notifier_block *nb, unsigned long event, + void *data) +{ + struct cec_adapter *adap = container_of(nb, struct cec_adapter, nb); + struct hpd_notifier *n = data; + unsigned int phys; + + dprintk(1, "event %lu\n", event); + + switch (event) { + case HPD_DISCONNECTED: + cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false); + break; + + case HPD_NEW_EDID: + phys = parse_hdmi_addr(n->edid); + cec_s_phys_addr(adap, phys, false); + break; + } + + return NOTIFY_OK; +} + +void cec_register_hpd_notifier(struct cec_adapter *adap, + struct hpd_notifier *notifier) +{ + if (WARN_ON(!adap->devnode.registered)) + return; + + adap->nb.notifier_call = cec_hpd_notify; + adap->notifier = notifier; + hpd_notifier_register(adap->notifier, &adap->nb); +} +EXPORT_SYMBOL_GPL(cec_register_hpd_notifier); +#endif + struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, void *priv, const char *name, u32 caps, u8 available_las) @@ -344,6 +390,10 @@ void cec_unregister_adapter(struct cec_adapter *adap) adap->rc = NULL; #endif debugfs_remove_recursive(adap->cec_dir); +#ifdef CONFIG_HPD_NOTIFIERS + if (adap->notifier) + hpd_notifier_unregister(adap->notifier, &adap->nb); +#endif cec_devnode_unregister(&adap->devnode); } EXPORT_SYMBOL_GPL(cec_unregister_adapter); diff --git a/include/media/cec.h b/include/media/cec.h index 96a0aa7..d6c7b20 100644 --- a/include/media/cec.h +++ b/include/media/cec.h @@ -28,6 +28,11 @@ #include #include #include +#ifdef CONFIG_HPD_NOTIFIERS +#include +#include +#include +#endif #include #include @@ -173,6 +178,11 @@ struct cec_adapter { bool passthrough; struct cec_log_addrs log_addrs; +#ifdef CONFIG_HPD_NOTIFIERS + struct hpd_notifier *notifier; + struct notifier_block nb; +#endif + struct dentry *cec_dir; struct dentry *status_file; @@ -213,6 +223,11 @@ void cec_transmit_done(struct cec_adapter *adap, u8 status, u8 arb_lost_cnt, u8 nack_cnt, u8 low_drive_cnt, u8 error_cnt); void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg); +#ifdef CONFIG_HPD_NOTIFIERS +void cec_register_hpd_notifier(struct cec_adapter *adap, + struct hpd_notifier *notifier); +#endif + #else static inline int cec_register_adapter(struct cec_adapter *adap, -- 2.8.1