Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1864969imm; Thu, 24 May 2018 01:58:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpAvJu8Rj6v2/61UZeCOmETU+FI0HiHbkQJoa3Ydh51c2Vvi92e5vya+vV9+jEpgjej3ARL X-Received: by 2002:a17:902:205:: with SMTP id 5-v6mr6281222plc.301.1527152288336; Thu, 24 May 2018 01:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527152288; cv=none; d=google.com; s=arc-20160816; b=oZuH0YuYfyF+bmi5Xyue2HWNC3q8dySgmhQ6Hnh3aMKxdlKuwjwX9nzi++Vgf45qrz BT5U9e+99nXzGVvSSwovhEDCBdCLkECpVqDa0dHrz4e28/nkh80k1Tgpp68Ykg4PvcQC kGv/IwsxVAIALfI6Fd5QDRWloI0Y0Jbq/Kxi5i8tBsWI7vkeqTN0Nfuwomufjwsmr409 pZ02HSstMZ9VLpWPGBN8jwRcyodU8szo5Y1LM605YeeeZBQOHrop2V3qNZfQvE0qqNhV 8V0HDdYdJTabITbk24tGD34n8LGFJ0rS54WD5lmVAsLr1sdtp48BlUkzDiZc85u2wVqM aODQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=HGItCk8tB+qz9r6eO3SQ1D6ZEAn5mfuOUC3Y35WojUQ=; b=FMzgQJbVivr7lTgx/cMhHQVKxMxemKrftbTi19bOnyVhluK3aJI5+TjnF+Gj1ihzbi afe1lXw2npoGVbIsuUunMKWVukSe0gWU6kzNpS1o4+1I9MwAb5muYtr/GMpW4C/lzJJf FIznET77HYve3DwhQbkLnbqPHowxAVk7OJ5yuAU6u9HaxarXb63I6Fv3ChtBUPjbMsBX krOmMXpquoV58N0lQqGY/BCyJG97V5ss5ITTRemrCgvqBufZXxy0wtMuv1u4g97jV+u2 T+EUuRyF73k6c/gW2eR28oYOGFJOqTxKVTsHfHXVvQqRRurGYwo3igFVFOjvLRKDX/Ag 8Azw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=fO8jP9Qh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si21142561plf.308.2018.05.24.01.57.54; Thu, 24 May 2018 01:58:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=fO8jP9Qh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965673AbeEXI5D (ORCPT + 99 others); Thu, 24 May 2018 04:57:03 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:38830 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965380AbeEXIzI (ORCPT ); Thu, 24 May 2018 04:55:08 -0400 Received: by mail-wm0-f67.google.com with SMTP id m129-v6so2915914wmb.3 for ; Thu, 24 May 2018 01:55:08 -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=HGItCk8tB+qz9r6eO3SQ1D6ZEAn5mfuOUC3Y35WojUQ=; b=fO8jP9QhWhLqYLTcH97pbeuSttUejGb6YSBktHFzRt7x4nCbirekMdtimRC4GjHrEF E0/J4h77kSRo2CAAM/y/Vdsl08zWOhnGlKPQ/SohgVE6JRK6g53GdtoY6aXjVIDW/4l7 0KhcOAhwn2XihGUKPp+XAXQzqrNiZVrc84h9LOQznCOpVJJQ8StWiw9g6Q33J/ySv6oZ 6mWy7Uu7mtMy6wR1ncCb8EcJ8GMOXg+MJ1lEDOMbcx/EvTmUC8y3BX/VYnNF2bp+D9eA qS7wlGGWEe/DeACXCxpxTlJUgXmFfR//vB4Ci9be1sRwUSLk2yM/UAFimmO8NZN31NOd aroQ== 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=HGItCk8tB+qz9r6eO3SQ1D6ZEAn5mfuOUC3Y35WojUQ=; b=OfCq41uUvsJYWN+ZczVm5oeeXrtR894cZVq6n/pH1iUUHY7+gM99uU309NasGaxgSN LUpAdj8eQBpi01LRC7T6Lb2mtA9+MD2ODyjJ3W4gD4pd8x1dXkKk/7HW6foKpd/by8Mh KaSLuSw04yVgrLzj8KKkUHJE6XLv42Dev6ezcJSAuzrcWSpNl52NhgwMQ3nc4AX3C0AD JTPgj+5MKGm5nPbPRscYKTALMbrAmIVfOXGpBMC2K2p9xq/d8r8fpD8U4ShCpFUkgzW2 WfOworEu/tbu2tDibPSMTn21sSz3pvwnUSEDG/DpPv3U0LZfbX4Q8k6jvskv4mA4urFE AWkg== X-Gm-Message-State: ALKqPwdBezH/9ESsf23btU0pFhNuq6QNxR2eNZtdYMGTJFWzJxm+UAUt 7UnU4tJniVI+Dhek7OrmC47WWw== X-Received: by 2002:a1c:d9d3:: with SMTP id q202-v6mr6267543wmg.84.1527152107534; Thu, 24 May 2018 01:55:07 -0700 (PDT) Received: from bender.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id z192-v6sm3348462wmc.10.2018.05.24.01.55.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 May 2018 01:55:06 -0700 (PDT) From: Neil Armstrong To: airlied@linux.ie, hans.verkuil@cisco.com, lee.jones@linaro.org, olof@lixom.net, seanpaul@google.com Cc: Neil Armstrong , sadolfsson@google.com, felixe@google.com, bleung@google.com, darekm@google.com, marcheu@chromium.org, fparent@baylibre.com, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, eballetbo@gmail.com Subject: [PATCH v5 1/6] media: cec-notifier: Get notifier by device and connector name Date: Thu, 24 May 2018 10:54:56 +0200 Message-Id: <1527152101-17278-2-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527152101-17278-1-git-send-email-narmstrong@baylibre.com> References: <1527152101-17278-1-git-send-email-narmstrong@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 11 ++++++++--- include/media/cec-notifier.h | 27 ++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c index 16dffa0..dd2078b 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,7 @@ static void cec_notifier_release(struct kref *kref) container_of(kref, struct cec_notifier, kref); list_del(&n->head); + kfree(n->conn); kfree(n); } diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h index cf0add7..814eeef 100644 --- a/include/media/cec-notifier.h +++ b/include/media/cec-notifier.h @@ -20,8 +20,10 @@ struct cec_notifier; #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER) /** - * cec_notifier_get - find or create a new cec_notifier for the given device. + * 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. @@ -31,7 +33,8 @@ struct cec_notifier; * * Return NULL if the memory could not be allocated. */ -struct cec_notifier *cec_notifier_get(struct device *dev); +struct cec_notifier *cec_notifier_get_conn(struct device *dev, + const char *conn); /** * cec_notifier_put - decrease refcount and delete when the refcount reaches 0. @@ -85,7 +88,8 @@ 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; @@ -121,6 +125,23 @@ static inline void cec_register_cec_notifier(struct cec_adapter *adap, #endif /** + * cec_notifier_get - find or create a new cec_notifier for the given device. + * @dev: device that sends the events. + * + * 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. + */ +static inline struct cec_notifier *cec_notifier_get(struct device *dev) +{ + return cec_notifier_get_conn(dev, NULL); +} + +/** * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID * * @n: the CEC notifier -- 2.7.4