Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4908841imm; Mon, 14 May 2018 15:41:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrIyrcCZem2ndV3kaycbi5vR2bhwyYQyr06xYOKLrGNKIENiGhKU6zCjcdepH/nw3JjSOBe X-Received: by 2002:a17:902:547:: with SMTP id 65-v6mr11868328plf.388.1526337682707; Mon, 14 May 2018 15:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526337682; cv=none; d=google.com; s=arc-20160816; b=fjsGwdpu3+4qaH/c2EFMVn3UoaO/5H++W9Yl1UHtRl9UXoSKsG5FcOwpKMaNMFoBdH 4BUHsT/dqBW/yrh4rkOjNfQrwIuktfra3IzhOs25pRz5UyIypFnK7TkjHTc2DgHJ0QnF OgezhBRVqDRHlr9vwt1APk/yxSAModjbtJhwme/+5ZK4y2/ottnx6vgG5240f4MhzwX+ ySFl+g18AvUY8eQEVjUPVH9UA5QvpGwarfgKIpB+E5NVya8UP1CroXGa5WXeq02YcGRp sJWeCQhdBPArXPwakbHxU5ll/XksMAS3tdo2HjWiWfulj9roo3JcoSN06EC93YGOMIAI 4b+Q== 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=pdQ1jEpM1qoumqPW2T2SDEALwYLGFfPAUFRPeMybPyU=; b=n7gfhUHwc0xUTCkJ3RVg/3EpES7ye4CN3nBLvbzFRI1h5bcAnj4Mmp5MKRDqxnB+6V 310TH8rqJg1d26EgQXX657SH5yWQx4Itv4Pr5NE7yj1JAozomfUxbUZrskN0u3Fj5vGT TVDsqsjri+ULSCI+ahL89PN06pFmL8YMnJ99Yok/11zq5eUDjCPwL87CoUpaJtCpc8E1 /QsPCYqyQtRyz+m9idA1AjL+iJf9WtmrE0FBPbfj3441zvkZGSxbXkt97wERd+OU4ZWP bJ7TRc5Ofkpd/WaQO1NPIYxkgC+KiAFvokagBB4tHMNRDoWLQRbLWhrSVslvXTKz8dQC /pdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=2E525g5g; 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 j3-v6si10020622pld.300.2018.05.14.15.41.07; Mon, 14 May 2018 15:41:22 -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=2E525g5g; 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 S1752506AbeENWkx (ORCPT + 99 others); Mon, 14 May 2018 18:40:53 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36726 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752402AbeENWkr (ORCPT ); Mon, 14 May 2018 18:40:47 -0400 Received: by mail-lf0-f68.google.com with SMTP id t129-v6so20389041lff.3 for ; Mon, 14 May 2018 15:40:46 -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=jPz8f5WfJCqnlDWSRK7x2IOfdMMbkxPQgMa/+O5cQulaxFUhRaH9oK9JZs68wHIaXp 0QwFfn3HOoyqtiIvr7r2gtNtWIl86JhHnHXtretnwvxzmUr7CW95l1IxgyMV/mhn8+OQ 1Eq8bKwUWnlQXpXxmNCVj43qDP2QXn24GkzJTGNLV6++PqF2mcU0vq9vDOJdHtRvxys6 ikNec51+R3yfHiurS+ohH2iryzLLw4RIrwNFik9rLxWLGh3GQC1T7EgjAJn1X9gdDeSM GFRN6mBT2QDvlT+eLHle6huU579SIt03qsenHmwKXt1SSi0JDoqigSaGkFstOjDb7xj1 EIHQ== X-Gm-Message-State: ALKqPwfBWlFUIfzsbfvPIswrWMwh7SXlqVblN4y8DEVEo8YC6TL/tphh woEW2p4YmRefrCutgzCHkiLkrQ== 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 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 Subject: [RFC PATCH 2/5] media: cec-notifier: Get notifier by device and connector name 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> 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 | 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) { } -- 2.7.4