Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp373670imm; Mon, 21 May 2018 07:25:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpyNU6u93gvRIL4iqqgLVyEYyX1JkySOC9A8Ah3J67SgUqRkgVqKoF2kRKvFR0DLI6FU22B X-Received: by 2002:a65:4443:: with SMTP id e3-v6mr16197555pgq.348.1526912715647; Mon, 21 May 2018 07:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526912715; cv=none; d=google.com; s=arc-20160816; b=ECfODHeQ1/8tnARPejOHOS+WM7WaWL9/uvyOxFfo310aLT8bdmhbKdKlhtWAI7AUeU 2Ogp14pHZ3BXh448A07dRZkC8aVPFEzfEY0ElZ2jDCNCeXwxvyHzlyDYXcuG6Rw+rrnR fwiRZxGXrfCfJid/S7Ex106bZQDQDG+S/pWRqUE5/wKBWC8fdkfQ5Pkc4LP1ptZ3D+5G 9EsYIa4YDfrtNoudCpFC4PuqhJKIXVthsdwVj/HDVgos6KBm6qZMOarHB0DaTGMEudTS e3n/1HX28zbrJpb4XtpUvJjqFJ+k6E4Fos38vsAjTGtrQaYaM7ACJXC570Xo3kEycm1P NosQ== 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=LwIsM0V0hWRsW2GZkNGBUMYQRS/8kZTx229COeVYd5lcw+V7yOVnA5TrvACENit11q aYT7Vfbyb+4/oHSO8KPqXaxsl66XZ58v6q5vSp6lyC08Noo/aOx+ECQEsP5yVaKnImZv /iw+SjdlRHoli9/TWgPgF81uBVLB7G1lyg5vOkgSJF59CaTbzq4qByH41XVSj0AS2huG b6LI0ErFPjwotvHOeScU6I2CkM7KBrULSsF/4PWJMZedfwHhIsRc/8y1ReAomzYU+XLp 04rmVlc8RLsPzT/d0rJmuKB13Mj9DN+Dn5fIDuOwlPQlWGxjukFo2v2tI5L5Xpf4nXjm 0kfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=vSEaQM2a; 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 m10-v6si11104746pge.245.2018.05.21.07.25.00; Mon, 21 May 2018 07:25:15 -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=vSEaQM2a; 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 S1752943AbeEUOXG (ORCPT + 99 others); Mon, 21 May 2018 10:23:06 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:40383 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751682AbeEUOVx (ORCPT ); Mon, 21 May 2018 10:21:53 -0400 Received: by mail-wr0-f195.google.com with SMTP id v60-v6so16196914wrc.7 for ; Mon, 21 May 2018 07:21:52 -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=vSEaQM2aDQy21647//qeTaa6tCG3OVthB22fr4GLsvkCwSuqjB3R5h9mRG+2xcIUhP Zh536qtOvd0EBJxyWbgU+pJhxjoU89vrEC3SHw7pEZTF2AAK9pipp57iR19bV27ezDqr +/ZNYD3pN1X8AAg3mvEAKACYb/RQQf2pbzOqLEFAI7xNMom2UoSH6420pEwqIJHYY11Y GcKeqwqgEYa5eICWQ3KYSNQ1tqlTEFSBFzbj+m67EVmUSKKtYNkywb7Wb5TsC12bM+9i Orcz0c+VsD6bjlYBfHcl3qllBiH4uYDXC1vfUJnoHAjb7ZFwelUM8EPfH63v6OSkQKHS Kc7w== 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=Odl3EFbbePkpA05pKZV+PvVgGo6yFMvu9upCte72MUSU8AI4AA7HgFxe+3XVLE0acw XNTl0v88cTgynxqoUirpwjPLAu2j+Qla5eFMmPYEQh2loiutj0CwDQQiZSy3km4s4Yby IFTlVm1brTf3y0/+jm1vhPFHC4KqiIDQ3CAzbaITVfsMMBW/pSGUYEVTJ/BY579eXy18 Zi03CO/JitspL0M7Uelu+R3q/lvmaxj5s9vYLxJCi5f4CgWwHyMKR7bq3VEPa6V8Wp8V Kd/XbHXRJVWzJitfAh/b9GOK7xFd0718HB3CDmNe6WA7UH630HCNMrSy2zAZTuQ+7TMg C+ng== X-Gm-Message-State: ALKqPweRVB+Oj/fxNkJMsxpub8LT9ojQpyRjAPlFr59VYgzcc4ljS55G pqnFJlD6eSO6sRiKL0HGNOwcGQ== X-Received: by 2002:adf:bc8f:: with SMTP id g15-v6mr15731773wrh.266.1526912511608; Mon, 21 May 2018 07:21:51 -0700 (PDT) Received: from bender.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id m69-v6sm27213446wmd.47.2018.05.21.07.21.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 May 2018 07:21:50 -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: [PATCH v4 1/5] media: cec-notifier: Get notifier by device and connector name Date: Mon, 21 May 2018 16:21:42 +0200 Message-Id: <1526912506-18406-2-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526912506-18406-1-git-send-email-narmstrong@baylibre.com> References: <1526912506-18406-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