From patchwork Tue Dec 13 15:08:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 9472557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DC1FE6021C for ; Tue, 13 Dec 2016 15:11:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE9AF284F7 for ; Tue, 13 Dec 2016 15:11:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C38A7285DC; Tue, 13 Dec 2016 15:11:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B38C8284F7 for ; Tue, 13 Dec 2016 15:11:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cGoi0-000548-54; Tue, 13 Dec 2016 15:09:36 +0000 Received: from lb2-smtp-cloud3.xs4all.net ([194.109.24.26]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cGoh9-0004Xl-F9 for linux-arm-kernel@lists.infradead.org; Tue, 13 Dec 2016 15:08:47 +0000 Received: from marune.fritz.box ([IPv6:2001:983:e9a7:1:ef31:4dcf:822e:7392]) by smtp-cloud3.xs4all.net with ESMTP id KT8D1u00W3YS7uB01T8LeA; Tue, 13 Dec 2016 16:08:21 +0100 From: Hans Verkuil To: linux-media@vger.kernel.org Subject: [PATCH 3/4] cec: integrate HDMI notifier support Date: Tue, 13 Dec 2016 16:08:12 +0100 Message-Id: <20161213150813.37966-4-hverkuil@xs4all.nl> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161213150813.37966-1-hverkuil@xs4all.nl> References: <20161213150813.37966-1-hverkuil@xs4all.nl> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161213_070843_969112_F618A630 X-CRM114-Status: UNSURE ( 9.44 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, Russell King , dri-devel@lists.freedesktop.org, Javier Martinez Canillas , Hans Verkuil , Benjamin Gaignard , linux-arm-kernel@lists.infradead.org, Marek Szyprowski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil Support the HDMI notifier framework, simplifying drivers that depend on this. Signed-off-by: Hans Verkuil --- 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..c620a4c 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_HDMI_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_hdmi_notify(struct notifier_block *nb, unsigned long event, + void *data) +{ + struct cec_adapter *adap = container_of(nb, struct cec_adapter, nb); + struct hdmi_notifier *n = data; + unsigned int phys; + + dprintk(1, "event %lu\n", event); + + switch (event) { + case HDMI_DISCONNECTED: + cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false); + break; + + case HDMI_NEW_EDID: + phys = parse_hdmi_addr(n->edid); + cec_s_phys_addr(adap, phys, false); + break; + } + + return NOTIFY_OK; +} + +void cec_register_hdmi_notifier(struct cec_adapter *adap, + struct hdmi_notifier *notifier) +{ + if (WARN_ON(!adap->devnode.registered)) + return; + + adap->nb.notifier_call = cec_hdmi_notify; + adap->notifier = notifier; + hdmi_notifier_register(adap->notifier, &adap->nb); +} +EXPORT_SYMBOL_GPL(cec_register_hdmi_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_HDMI_NOTIFIERS + if (adap->notifier) + hdmi_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..3b4860d 100644 --- a/include/media/cec.h +++ b/include/media/cec.h @@ -28,6 +28,11 @@ #include #include #include +#ifdef CONFIG_HDMI_NOTIFIERS +#include +#include +#include +#endif #include #include @@ -173,6 +178,11 @@ struct cec_adapter { bool passthrough; struct cec_log_addrs log_addrs; +#ifdef CONFIG_HDMI_NOTIFIERS + struct hdmi_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_HDMI_NOTIFIERS +void cec_register_hdmi_notifier(struct cec_adapter *adap, + struct hdmi_notifier *notifier); +#endif + #else static inline int cec_register_adapter(struct cec_adapter *adap,