From patchwork Tue May 15 12:46:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10400993 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 A329E600F4 for ; Tue, 15 May 2018 12:47:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 906A3287B5 for ; Tue, 15 May 2018 12:47:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85402287B8; Tue, 15 May 2018 12:47:22 +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 02AC4287B5 for ; Tue, 15 May 2018 12:47:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3E3C96E216; Tue, 15 May 2018 12:47:21 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qk0-x243.google.com (mail-qk0-x243.google.com [IPv6:2607:f8b0:400d:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9812C6E216 for ; Tue, 15 May 2018 12:47:18 +0000 (UTC) Received: by mail-qk0-x243.google.com with SMTP id b22-v6so6905411qkj.9 for ; Tue, 15 May 2018 05:47:18 -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=BtCOpd5eqNJQmoKcrzpNK4LG0YPcRZvDx86aytEvZ7c=; b=BEkX1H0IzgH8FDZolcRT7OlrNVj3J3HxMPgahKYSjnedrVAakoCmgn7Xv/Q/woTPoI 6476vO57Vi5poM1eC1XHbJYQNtQ6FGY6is3kaNoNkwprg3vNVqrJi/EIJSROhLoqw/Bm J08acOKFQosZ5O75ujDZ+9VN2b79iX9RfQjzZz6shifSTFTBh+FvxHM3JxAlJFYj0+kO k51DT5FsXiq1BWdHMEDwFH/4Y5wD4aejdfJv85rn4DfmsM+n7JvInTlDCH3CUai4Wzec kb+Y0d5/PVN6LIY8PilQhaw2+aUqNmqY06orvn+23+s/H9VPMdyMXD3qv/dv17vd2AVG Blng== 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=BtCOpd5eqNJQmoKcrzpNK4LG0YPcRZvDx86aytEvZ7c=; b=QK6YBjK5ewDU5zyGAoUAgRrwN2qAZhsFWwGnlx9sHB282Ugjm/fw959zen0xLCBuz2 +SbnOBx9wh5kOnAlPo/TlOEr4j+EddVF/+prr+VjG+zNS6NDavLGUu4hXy26+xNW5EZM 3UMhFqX/aMTlQDkrl9Gv/3m+l7d2+l7qofVa7NJfVUc1UfdUTaVUv1XnzeAKpEGRUTQL ISCizIKlggeSAom2QNLgfVd5DbxRZBxzE70IrznoakAQ4dG1vNxNFOuKVT2WZvcKBcfn Rb+C2fP0PdbPUnp9Z4g7sbagTGnpTH3PwyDkKvPCtB8xfp4fcla5g+Zi0o+XGuqwlOt1 LVqQ== X-Gm-Message-State: ALKqPwfejuvhUHII77yLZyPkDCq68TD0sk7L7bDoTVbGlOiTI/rw6urC yD9OgzYxfWG6cMO7LVnfWruknA== X-Google-Smtp-Source: AB8JxZpDdKFSvPAo8bsIbzmZJ1eEvsnF8Ir4YUJIh77nTS4/gNpDO5M+iI/IFQkeN5fQpAk3jsZqrA== X-Received: by 2002:a37:7e47:: with SMTP id z68-v6mr12295753qkc.115.1526388437565; Tue, 15 May 2018 05:47:17 -0700 (PDT) Received: from localhost.localdomain ([2620:0:1043:fd00:748b:2433:2688:e1f]) by smtp.gmail.com with ESMTPSA id d88-v6sm9725530qkj.25.2018.05.15.05.47.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 May 2018 05:47:16 -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 14:46:57 +0200 Message-Id: <1526388421-18808-2-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526388421-18808-1-git-send-email-narmstrong@baylibre.com> References: <1526388421-18808-1-git-send-email-narmstrong@baylibre.com> Subject: [Intel-gfx] [PATCH 1/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 | 12 +++++++++--- include/media/cec-notifier.h | 30 ++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c index 16dffa0..7038abae1 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,14 @@ 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_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) { + if (n->dev == dev && + (!conn || !strcmp(n->conn, conn))) { kref_get(&n->kref); mutex_unlock(&cec_notifiers_lock); return n; @@ -46,6 +48,8 @@ struct cec_notifier *cec_notifier_get(struct device *dev) if (!n) goto unlock; n->dev = dev; + if (conn) + n->conn = kstrdup(conn, GFP_KERNEL); n->phys_addr = CEC_PHYS_ADDR_INVALID; mutex_init(&n->lock); kref_init(&n->kref); @@ -54,7 +58,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) { @@ -62,6 +66,8 @@ static void cec_notifier_release(struct kref *kref) container_of(kref, struct cec_notifier, kref); list_del(&n->head); + if (n->conn) + kfree(n->conn); kfree(n); } diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h index cf0add7..73f92c7 100644 --- a/include/media/cec-notifier.h +++ b/include/media/cec-notifier.h @@ -20,6 +20,23 @@ struct cec_notifier; #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER) /** + * 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 +48,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 +105,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) { }