From patchwork Mon Jan 23 10:23:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 9532059 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 5CB656042D for ; Mon, 23 Jan 2017 10:23:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AF7E27E3E for ; Mon, 23 Jan 2017 10:23:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35E4C27F93; Mon, 23 Jan 2017 10:23:58 +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=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D43EA27E3E for ; Mon, 23 Jan 2017 10:23:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0B9896E42C; Mon, 23 Jan 2017 10:23:57 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from lb3-smtp-cloud2.xs4all.net (lb3-smtp-cloud2.xs4all.net [194.109.24.29]) by gabe.freedesktop.org (Postfix) with ESMTPS id 034D76E42F for ; Mon, 23 Jan 2017 10:23:54 +0000 (UTC) Received: from tschai.lan ([46.9.235.119]) by smtp-cloud2.xs4all.net with ESMTP id bmPj1u00E2bEJta01mPp6V; Mon, 23 Jan 2017 11:23:54 +0100 Received: from tschai.fritz.box (localhost [127.0.0.1]) by tschai.lan (Postfix) with ESMTPSA id 2FC79180487; Mon, 23 Jan 2017 11:23:38 +0100 (CET) From: Hans Verkuil To: linux-media@vger.kernel.org Subject: [PATCHv3 3/5] cec: integrate HPD notifier support Date: Mon, 23 Jan 2017 11:23:35 +0100 Message-Id: <20170123102337.20947-4-hverkuil@xs4all.nl> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170123102337.20947-1-hverkuil@xs4all.nl> References: <20170123102337.20947-1-hverkuil@xs4all.nl> Cc: linux-samsung-soc@vger.kernel.org, Russell King , Krzysztof Kozlowski , Javier Martinez Canillas , Hans Verkuil , dri-devel@lists.freedesktop.org, Marek Szyprowski X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 aca3ab83a8a1..dd2c4a17aff5 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_NOTIFIER +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_NOTIFIER + 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 96a0aa770d61..f87a07ee36b3 100644 --- a/include/media/cec.h +++ b/include/media/cec.h @@ -28,6 +28,11 @@ #include #include #include +#ifdef CONFIG_HPD_NOTIFIER +#include +#include +#include +#endif #include #include @@ -173,6 +178,11 @@ struct cec_adapter { bool passthrough; struct cec_log_addrs log_addrs; +#ifdef CONFIG_HPD_NOTIFIER + 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_NOTIFIER +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,