From patchwork Wed Apr 28 21:52:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12230107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C75BC43470 for ; Wed, 28 Apr 2021 21:53:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AFFA6109E for ; Wed, 28 Apr 2021 21:53:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230525AbhD1VyI (ORCPT ); Wed, 28 Apr 2021 17:54:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54101 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbhD1VyI (ORCPT ); Wed, 28 Apr 2021 17:54:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619646802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ERBBDzY8cgN0bD72/H5ijzJDtmdBQ5XjP50xYJ8nAQo=; b=BttGzIw7UtiGXiP+YDDl34dozVnA9lBGxjV1JfDtkNl8gqeoQb/3O4xBTU1WG1T5dolifS PbuzAKABfDLbvsRWz1KGG7UQeThNxEaV2FUtbS1FxCUGn7y5M3P6V79iEdzC6/Ayh0iCog LY3fEgZXIvV4pBhBE88zv6wB6mF5X3I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-596-01z3OwsINiWgdNb5_e3jNQ-1; Wed, 28 Apr 2021 17:53:18 -0400 X-MC-Unique: 01z3OwsINiWgdNb5_e3jNQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0D8D1107ACC7; Wed, 28 Apr 2021 21:53:17 +0000 (UTC) Received: from x1.localdomain (ovpn-115-166.ams2.redhat.com [10.36.115.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A8DB5C1BB; Wed, 28 Apr 2021 21:53:14 +0000 (UTC) From: Hans de Goede To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Daniel Vetter , David Airlie , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Greg Kroah-Hartman , Guenter Roeck , Heikki Krogerus Cc: Hans de Goede , intel-gfx , dri-devel@lists.freedesktop.org, platform-driver-x86@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 3/9] drm/connector: Add drm_connector_find_by_fwnode() function Date: Wed, 28 Apr 2021 23:52:51 +0200 Message-Id: <20210428215257.500088-4-hdegoede@redhat.com> In-Reply-To: <20210428215257.500088-1-hdegoede@redhat.com> References: <20210428215257.500088-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a function which allows other subsystems to find a connector based on a fwnode. This will be used by the USB-Type-C code to be able to find the DP connector to which to send hotplug events received by a Type-C port in DP-alternate-mode. Note this function is defined in drivers/gpu/drm/drm_sysfs.c because it needs access to the drm_sysfs_device_connector device_type struct. Signed-off-by: Hans de Goede --- drivers/gpu/drm/drm_sysfs.c | 38 +++++++++++++++++++++++++++++++++++++ include/drm/drm_connector.h | 1 + 2 files changed, 39 insertions(+) diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c index c1d3e2b843b7..ca71c46fad78 100644 --- a/drivers/gpu/drm/drm_sysfs.c +++ b/drivers/gpu/drm/drm_sysfs.c @@ -520,3 +520,41 @@ void drm_class_device_unregister(struct device *dev) return device_unregister(dev); } EXPORT_SYMBOL_GPL(drm_class_device_unregister); + +/** + * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode + * @fwnode: fwnode for which to find the matching drm_connector + * + * This functions looks up a drm_connector based on its associated fwnode. When + * a connector is found a reference to the connector is returned. The caller must + * call drm_connector_put() to release this reference when it is done with the + * connector. + * + * Returns: A reference to the found connector or NULL if no matching connector was found + */ +struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode) +{ + struct drm_connector *connector, *found = NULL; + struct class_dev_iter iter; + struct device *dev; + + if (!fwnode) + return NULL; + + class_dev_iter_init(&iter, drm_class, NULL, &drm_sysfs_device_connector); + while ((dev = class_dev_iter_next(&iter))) { + connector = to_drm_connector(dev); + + if ((connector->fwnode == fwnode) || + (connector->fwnode && connector->fwnode->secondary == fwnode)) { + drm_connector_get(connector); + found = connector; + break; + } + + } + class_dev_iter_exit(&iter); + + return found; +} +EXPORT_SYMBOL(drm_connector_find_by_fwnode); diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index d20bfd7576ed..1e5d154d1f4a 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -1696,6 +1696,7 @@ drm_connector_is_unregistered(struct drm_connector *connector) DRM_CONNECTOR_UNREGISTERED; } +struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode); const char *drm_get_connector_type_name(unsigned int connector_type); const char *drm_get_connector_status_name(enum drm_connector_status status); const char *drm_get_subpixel_order_name(enum subpixel_order order);