Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp552514imm; Tue, 15 May 2018 05:50:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr1wZcOyfxssmjZZVBSz3CuY2H+5FEs/8I3zjsQMkBCmPh/E5guZ7VMEiLvQs+IVLhQgv3k X-Received: by 2002:a17:902:968d:: with SMTP id n13-v6mr13928140plp.168.1526388607636; Tue, 15 May 2018 05:50:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526388607; cv=none; d=google.com; s=arc-20160816; b=BWF8QXNg+H5gbpeAGza+4TnSwa/8ScM5n+TDOLA1GqG0r7WvX2vtcs2j9yGhTVoaud xk2V7opSy1yGVreWp95fG5tDw0WSZwXoEHVAcqvG7CIdeC758VVtIOJARxjIxRewk/cT EijPGSdvRFCUOIduOzMa0G+dK2DPnlmoi4QBDwtRnuryYdyxkoKiahowKI3tUJP6l/Xh qQA39vsOhChNrpPWC8nzjM768V3XSBrfCLEZrqofQa14glsFnobOqteoQtIRT09WLBlw dSHrl23YDt48flWhm3BjtG/48q2737OJGz6ANT/EWlAybQ9R/bcr6kiVkOBTdrchLHjr IUNQ== 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=BtCOpd5eqNJQmoKcrzpNK4LG0YPcRZvDx86aytEvZ7c=; b=fLfLHaylDvKidZSEU64eviReYv8FY0cO2La7yJsSb8ffh2rBnZ8rLHqar+7J3vfRdQ MywnbkY/ZBL5/2E/wYZPIX5Fa2QPwBMBhEzK2Ukr6DU0jQXgGA0h78+TpGiX5WYTDfhw q8E3d+HOpt+KR6DYMKPfsG+xaTRPaANw2LAA8i5maw1QY2dam4NvZsma1OuGDvibWHzh kWqIXV7X2KkSObrrRA1gYV0gmuEKmwKQzIkCX/G0Z2uG5+H6mHQ2fByMVCoMyZfy9bNq lTPHo4TpDUQiBsE5FZHCTAdw2pUz129D5MGx1kKW25h/qekRZYXry2MCjdw8fn+KxOVE +Fuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=BEkX1H0I; 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 y185-v6si9335930pgd.316.2018.05.15.05.49.52; Tue, 15 May 2018 05:50:07 -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=BEkX1H0I; 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 S1753481AbeEOMrX (ORCPT + 99 others); Tue, 15 May 2018 08:47:23 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:40429 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752952AbeEOMrS (ORCPT ); Tue, 15 May 2018 08:47:18 -0400 Received: by mail-qk0-f196.google.com with SMTP id s83-v6so7655053qke.7 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=UTNml2G4I/YbfsonoLE6ftM7GBByWmQ//fL+1nZFIMLxTeH1xebWU3inktIoj0uJMR 8nR09uC4l7wlXyPLfHoATTexYNWpEuIZ47xAC/SlrtZn8FUdiTAxCbgg3X0rW/uI6ASH nHl8p58jJIylnSxIWXY3ZbViYm17Q5bTWsMROGpswGVtzs4pJC+CHoy11WffT4tmN+Ar KaT0HuLyRJv1h/eAH5uL7cM0NvJlZnmupTrtPBhsjTlomCvLLn7vWTD7Yw1zsikwlXeJ Sha+Plb9iV+IGd6l+D1byHvue4qjBAX5h828CqDctcoZB6c6ZMOeL1F1RyNmjCdEjNrd B2Qg== X-Gm-Message-State: ALKqPwcCQCZBmetwJjqokZiVDfopDPxne7x93+4x9YKvNlmO/PVpHfvf QbBSoDW+9UVpDLvbffpP0goOBQ== 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 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 1/5] media: cec-notifier: Get notifier by device and connector name 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> 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 | 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) { } -- 2.7.4