From patchwork Mon May 14 22:40:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10399525 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 ED029601F7 for ; Mon, 14 May 2018 22:40:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1530928585 for ; Mon, 14 May 2018 22:40:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0960A2858D; Mon, 14 May 2018 22:40:54 +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=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 94F6128585 for ; Mon, 14 May 2018 22:40:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D39F6E134; Mon, 14 May 2018 22:40:49 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-lf0-x241.google.com (mail-lf0-x241.google.com [IPv6:2a00:1450:4010:c07::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 66A9A6E047 for ; Mon, 14 May 2018 22:40:47 +0000 (UTC) Received: by mail-lf0-x241.google.com with SMTP id y72-v6so20390665lfd.2 for ; Mon, 14 May 2018 15:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pdQ1jEpM1qoumqPW2T2SDEALwYLGFfPAUFRPeMybPyU=; b=2E525g5gtA56QuOj0j/h0NDuyNRDdQuWvH2+2aRCg7p0rTcICkkiNhEHfJk6h5u8LQ fD2liQYgJyIxQDKYv0Cvx8srDiFcmZQjZB7BgSaIDxTmonHG3ZD8XKmIbou7SKrKEjp4 Rka9AXh5l9UfWki6jJ+iDHmNCGILQdkG676HXW8DMZZcSBKFs48bRWjj1jKbzJY0mQ7l ane/vfcYOGtuVpFNbvYTbfGkTWHR9F1uo5zzTVAmc2Y8qClnQRtCkLxd2i1/x6yrgNj2 p9Ikt6KNH4zFt1Nkl/XA1hUHhm2zPoXANSKB/Ijm9d/rR5u1cW/k98X8bNpLLw5kR74U jxqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pdQ1jEpM1qoumqPW2T2SDEALwYLGFfPAUFRPeMybPyU=; b=C4ycBRGmYPYdCba8OseW1opTwgZhC+At56MnZ1dpPxP8P9O1CA+VemNZxxkLfxI1Qu +UeJJsNBnIqDzIkgDvCIOMWP0Q8ykF62CP1sN2nY0tPczxahrlqVOv9hS2T4u70/tzrb SQ7oCKush6wQln7A9Efo2gFZ0hVpIl0TQDGA0IHZ6VEbYuquQbK9keg9rzUW33Q2Lyem 5G8o87MNhjR45OjJ6CaCVtAEsZyZyrW/TtR/Jk96JcGwRzRY/aQ3hC5iHmwGHimLr+Cg DEQM/r+4nvUOhr8cgKxQPeTi6l9fOSfGDIi5X4OXfgxjtztA01VRUGizA95nCNuaGgS4 1ttg== X-Gm-Message-State: ALKqPweqhJt6841YsUTfmsO4D1jg0hyzWGaAQLUHClR8BsgUZ+dlOhY/ mjSDICtMT43jeG28Yv8tUdPm5A== X-Google-Smtp-Source: AB8JxZrl7J8Wx+yTkoqocn2vDg8nyKzq2Eh1a/AHVVzXzv/CB4WwdMso6XHunkXW32n9+qs/Kex6Vw== X-Received: by 2002:a19:d00e:: with SMTP id h14-v6mr8815236lfg.133.1526337645662; Mon, 14 May 2018 15:40:45 -0700 (PDT) Received: from bender.ownit.se (89-253-66-137.customers.ownit.se. [89.253.66.137]) by smtp.gmail.com with ESMTPSA id f196-v6sm2071149lff.59.2018.05.14.15.40.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 15:40:44 -0700 (PDT) From: Neil Armstrong To: airlied@linux.ie, hans.verkuil@cisco.com, lee.jones@linaro.org, olof@lixom.net, seanpaul@google.com Date: Tue, 15 May 2018 00:40:36 +0200 Message-Id: <1526337639-3568-3-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526337639-3568-1-git-send-email-narmstrong@baylibre.com> References: <1526337639-3568-1-git-send-email-narmstrong@baylibre.com> Subject: [Intel-gfx] [RFC PATCH 2/5] media: cec-notifier: Get notifier by device and connector name X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Neil Armstrong , sadolfsson@google.com, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, fparent@baylibre.com, felixe@google.com, bleung@google.com, darekm@google.com, linux-media@vger.kernel.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP In non device-tree world, we can need to get the notifier by the driver name directly and eventually defer probe if not yet created. This patch adds a variant of the get function by using the device name instead and will not create a notifier if not yet created. But the i915 driver exposes at least 2 HDMI connectors, this patch also adds the possibility to add a connector name tied to the notifier device to form a tuple and associate different CEC controllers for each HDMI connectors. Signed-off-by: Neil Armstrong --- drivers/media/cec/cec-notifier.c | 30 ++++++++++++++++++++++++--- include/media/cec-notifier.h | 44 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c index 16dffa0..716070a 100644 --- a/drivers/media/cec/cec-notifier.c +++ b/drivers/media/cec/cec-notifier.c @@ -21,6 +21,7 @@ struct cec_notifier { struct list_head head; struct kref kref; struct device *dev; + const char *conn; struct cec_adapter *cec_adap; void (*callback)(struct cec_adapter *adap, u16 pa); @@ -30,13 +31,34 @@ struct cec_notifier { static LIST_HEAD(cec_notifiers); static DEFINE_MUTEX(cec_notifiers_lock); -struct cec_notifier *cec_notifier_get(struct device *dev) +struct cec_notifier *cec_notifier_get_byname(const char *name, + const char *conn) { struct cec_notifier *n; mutex_lock(&cec_notifiers_lock); list_for_each_entry(n, &cec_notifiers, head) { - if (n->dev == dev) { + if (!strcmp(dev_name(n->dev), name) && + (!conn || !strcmp(n->conn, conn))) { + kref_get(&n->kref); + mutex_unlock(&cec_notifiers_lock); + return n; + } + } + mutex_unlock(&cec_notifiers_lock); + + return NULL; +} +EXPORT_SYMBOL_GPL(cec_notifier_get_byname); + +struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn) +{ + 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))) { kref_get(&n->kref); mutex_unlock(&cec_notifiers_lock); return n; @@ -46,6 +68,8 @@ struct cec_notifier *cec_notifier_get(struct device *dev) if (!n) goto unlock; n->dev = dev; + if (conn) + n->conn = devm_kstrdup(dev, conn, GFP_KERNEL); n->phys_addr = CEC_PHYS_ADDR_INVALID; mutex_init(&n->lock); kref_init(&n->kref); @@ -54,7 +78,7 @@ struct cec_notifier *cec_notifier_get(struct device *dev) mutex_unlock(&cec_notifiers_lock); return n; } -EXPORT_SYMBOL_GPL(cec_notifier_get); +EXPORT_SYMBOL_GPL(cec_notifier_get_conn); static void cec_notifier_release(struct kref *kref) { diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h index cf0add7..70f2974 100644 --- a/include/media/cec-notifier.h +++ b/include/media/cec-notifier.h @@ -20,6 +20,37 @@ struct cec_notifier; #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER) /** + * cec_notifier_get_byname - find a cec_notifier for the given device name + * and connector tuple. + * @name: device name that sends the events. + * @conn: the connector name from which the event occurs + * + * If a notifier for device @name exists, then increase the refcount and + * return that notifier. + * + * If it doesn't exist, return NULL + */ +struct cec_notifier *cec_notifier_get_byname(const char *name, + const char *conn); + +/** + * cec_notifier_get_conn - find or create a new cec_notifier for the given + * device and connector tuple. + * @dev: device that sends the events. + * @conn: the connector name from which the event occurs + * + * If a notifier for device @dev 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_get_conn(struct device *dev, + const char *conn); + +/** * cec_notifier_get - find or create a new cec_notifier for the given device. * @dev: device that sends the events. * @@ -31,7 +62,10 @@ struct cec_notifier; * * Return NULL if the memory could not be allocated. */ -struct cec_notifier *cec_notifier_get(struct device *dev); +static inline struct cec_notifier *cec_notifier_get(struct device *dev) +{ + return cec_notifier_get_conn(dev, NULL); +} /** * cec_notifier_put - decrease refcount and delete when the refcount reaches 0. @@ -85,12 +119,18 @@ void cec_register_cec_notifier(struct cec_adapter *adap, struct cec_notifier *notifier); #else -static inline struct cec_notifier *cec_notifier_get(struct device *dev) +static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev, + const char *conn) { /* A non-NULL pointer is expected on success */ return (struct cec_notifier *)0xdeadfeed; } +static inline struct cec_notifier *cec_notifier_get(struct device *dev) +{ + return cec_notifier_get_conn(dev, NULL); +} + static inline void cec_notifier_put(struct cec_notifier *n) { }