Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp326795imm; Fri, 1 Jun 2018 01:23:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJeaJgvP6pQxadFIX853FTRltPqP95IFZHnWJqZ8ryKqiBvB+ABovpx+w+81Uk8LuHvkL7t X-Received: by 2002:a17:902:3303:: with SMTP id a3-v6mr10221510plc.209.1527841415421; Fri, 01 Jun 2018 01:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527841415; cv=none; d=google.com; s=arc-20160816; b=DLTH+2TbYU5jY9nvvO/6egEE3onnq7SB/dTsu7XapFpMAoTGm+vJUxurglhGYca4Gi 9CxhFeF4Bzxig6+ErjAn1vkDMxg4OvJrSyuUF+d4aVar9LY9L2r15qcLRdNsBe+GCOM1 HMHxbrufn/YKOcuUjRTHLOmJCZPHw1dYy0ikYU4kgDf1CYBk3IOe6BpkTyUyiXrfVnMY C5J4eDyGqzLoWjR7wFj0F/0NVOsouMZb5Bp8jhMVgUVzMfPn0IBhKlNY1clT/GC5VJc6 7dP7M3X3h4iCcPmC202ySQXT7UPh1mbemLarF/LOuj5lta8k6a7zU4lJ/Vf0R0ONQEAU ynig== 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=/vu3zBlSww3fbIYXMeJOEU7sc8OaKhykES6IpLaYsf4=; b=YSLPJMW1439H3Ko/pq/k1lpRhJprghtj+K2EP0IiCJ5asEprV7cuFr0tfu7uWk9hMv +Xa97N+VG9weg0IK2zJQVLgfP86jrAKCY5vgmCwV81tWG1ycDGHJueS4fV9jidu6MGAx V3e6o5LfpLutKmoObOIGGY7sge5baviuKgKZajuH5c4zcWehgildxahjVNf9dyUX9OJV YUS9PnBL/GoaVr02biJ04FBYZ/tW/31R2VqEAMTiGdh4td5o4Vf/QylmAbcJHawqfwFA I3vivUGhqbZUQFX7dS6YVqS7z9xnGFBpiSKZD8Fz/03R5aQvPVYwhbYFyo+NNqkJAulC TiTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=CH2ioqDD; 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 g3-v6si20319378plj.146.2018.06.01.01.23.19; Fri, 01 Jun 2018 01:23:35 -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=CH2ioqDD; 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 S1751710AbeFAIVW (ORCPT + 99 others); Fri, 1 Jun 2018 04:21:22 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:43129 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751057AbeFAITY (ORCPT ); Fri, 1 Jun 2018 04:19:24 -0400 Received: by mail-wr0-f195.google.com with SMTP id d2-v6so19989124wrm.10 for ; Fri, 01 Jun 2018 01:19:24 -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=/vu3zBlSww3fbIYXMeJOEU7sc8OaKhykES6IpLaYsf4=; b=CH2ioqDDHDduwi6Ifb2t9o2rqpCgoLRec1s7ffd5IGyYl8Bv+DDywRMxzEBXr+fRHj Q5T/x5C7lJ1iNW2p8SLrbgfUVngQzycJcNYk2PXOoLZ5kpI1QeZFUHAhQUgBF2ZESTqm dZguW8GGw/JFWDd/tIu++nvw+GEWUsr8xu25n4TtZB/9itAxFFD9j2TX/voHAsJSrx7i v4jKj2P3WXoLrdfBOcaFcFBmfLZsN8DG5Ni3GrweMaAG3su1lT8ZXD8qfgGpETFjU+Mb UPNOB08KGcHsJdA+qSMx0ATCQLnLBDGy3JF3ahP4RADqE8WH/7VWBQq6E/VUrYy4o2IA QIhg== 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=/vu3zBlSww3fbIYXMeJOEU7sc8OaKhykES6IpLaYsf4=; b=ZQiWcKQebbkMpMiMzWR20ohZiX0D4rKYOaEL419Nx3TP98FFGJauP9qgOpNrxPJM+O 17nyeGTTNvQqGK7OUVmz1k0COyKTkLMldnyKALjMSZe/JrF/twrXYunAdn7d3JTtyxTN EOf+7bu0N3VFhDKyj8dujz2Qx/1araUzOsPBTybJzkkHlPa9X7zj5nq2eX2IHqc/SBBr bjeFMAJcu9H35y+N9Ug1KA/reM5Vs9MqFjqcOjYCVCf8yAPa3ZrOOJf/LeZxYO7t3x17 +eS5/dQ/gyCUaZ7osjek3bNeZYS3+puEo7BBidz20lTYedMVBzaXS3vXIK2i5Ad5yBhb /BMQ== X-Gm-Message-State: ALKqPwe3iGHa8U3kKgCKnNA/bp4Upfnp/eUwMV5odwGGC/+HJm0Hj9jH TKqMWtJ27PqUcs7pIAvIuvmntA== X-Received: by 2002:adf:ab10:: with SMTP id q16-v6mr5388991wrc.239.1527841163428; Fri, 01 Jun 2018 01:19:23 -0700 (PDT) Received: from bender.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id h7-v6sm555949wmc.44.2018.06.01.01.19.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Jun 2018 01:19:22 -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 v7 1/6] media: cec-notifier: Get notifier by device and connector name Date: Fri, 1 Jun 2018 10:19:09 +0200 Message-Id: <1527841154-24832-2-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527841154-24832-1-git-send-email-narmstrong@baylibre.com> References: <1527841154-24832-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 Reviewed-by: Hans Verkuil --- 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