Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1679022pxb; Mon, 23 Aug 2021 01:51:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaIg1PeR9NiBuODGAi69s/LSbXi9J1cGasTnG2jNxf2Q8dApdcZRYsoGbv/Dp63a74Qchk X-Received: by 2002:a5d:9599:: with SMTP id a25mr26239794ioo.86.1629708695404; Mon, 23 Aug 2021 01:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629708695; cv=none; d=google.com; s=arc-20160816; b=ny4qUa6yPfi5m6wjANXjVdRCbb55KPGUWLXpORbF0AXdc3e/8P0gCzWWinn2W8n+xR ILSe72TPpMymjq3r9mMxt9+BgsrWgotSHhYqalOZd0toL3WcSMVlYcPyT9EQnhsYN8IX c289x/YdKf8XdMgXk6UGNjcL/HhS6scK/YjFuhciHyqOXK1+fO1+dgweKZ7AR+Mf4UfX f82+pv6uQUFaMxTGRiukLqFBkbIbwPD1vUHiZTVd8DR9je4aTNBHk+r33ouC02DM7xzc 8DgivNJc5ErQaNfjhj1vP/x0UYn3JhIs60yOOF5tIwFScGTtZFdQK0cx6ua85EYMl/1t rWyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=ozNmHqW4eot36610HLCN2jfvbbHmClu9J/C1QfHxiwE=; b=X0b1NDGCBRxhCG864e/IYZdUqmY4QEPw/IPcMJQ3vyZp3FctbEykM3o0ZbOWEljdOH 5o/tyRlMkFfdPKNQn3ZUibMQoVF24tF2B60nZK/F/l2bfOD6iSYy0gDZwrdNEspN9RSp Z9w+NcBjfyYdVZocnnqlhH00VTQRHHfBgorV15Fu7HcnEZKMCtfj8+pZbn7p3F1l09Yr VGk5fuFDQ9J16Opc3aVW/kkHvBXf5C6mpFt5jJvdDye3AtZSyGbDw78ZwHjSz/jJANcv hPf0zpqHlREdI4XjdXgxyESVUb145SZzkVlXnh0ULjrCnUbjyyD4OD4oo/aDU2G0Hztf QPQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b=QRq3BK7U; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Lbn6KVs9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i23si13438888jam.111.2021.08.23.01.51.24; Mon, 23 Aug 2021 01:51:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b=QRq3BK7U; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Lbn6KVs9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232642AbhHWIuI (ORCPT + 99 others); Mon, 23 Aug 2021 04:50:08 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:53497 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235690AbhHWIsW (ORCPT ); Mon, 23 Aug 2021 04:48:22 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id C5059580C63; Mon, 23 Aug 2021 04:47:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 23 Aug 2021 04:47:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=ozNmHqW4eot36 610HLCN2jfvbbHmClu9J/C1QfHxiwE=; b=QRq3BK7UhXm0Es6GAPhxJmYDdi94+ 6eFRXrxY6i70AN573dVCjPZzsdAWVH81yxrskIik2oiC25naFbbZiPGFKwMtsWgv lGCc7ojQJpjGbnWwGp+SHO6yUNj5ocbhEL+0ePq3EFIYmU718SmwNPS5V8NqwlVj L5Q0djxOharweusZhOVCUY4yZDNbY4bWy30aV3hfl8w0yh5w+zB62zWXbi6ZRcvh 2vK1pdxy/bnSOoDB6pOHIDWfQ76ijKaL08C2EvWx+F6y3xR5MCDNxnCC1tZZG1Iz nCv2LcM8KrtPzn7+4KrkSugD2qLFmXgbeG0cxE0gVJs0m9DGCbL+6UxHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=ozNmHqW4eot36610HLCN2jfvbbHmClu9J/C1QfHxiwE=; b=Lbn6KVs9 BpFPkI3IBzJOVbxbbDKeF6mZhldG+i6mwhKG1VYEs52bWvUFRreUMrykg4CTQJJ+ Nv4Z+XRyJUT5O1Lyhwyeptvm417dYESjj+wbicdpPBT5YP/2szL75yig9LuQzvGm vsJhbU2M5NrPFnfc4DiibDE3eIQzfAUONYdHRw+uYTllOKFKQxIK5Mz2bNYUngTo ogRGCiRWR47RzXiQ6O7NK7L65BQdIzibrNvaBOY4fsUAlRpWU1tru2umGwidUEqI LFEKWMswVJZihck/fqYkcF38NKiJs5G6MRSlQU8OYlIwc/CZNsDwUtWQJp7g33FA IZjfhHAw5D49ng== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddthedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepvdekleevfeffkeejhfffueelteelfeduieefheduudfggffhhfffheevveeh hedvnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepmh grgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 23 Aug 2021 04:47:39 -0400 (EDT) From: Maxime Ripard To: Jonas Karlman , Sam Ravnborg , Jernej Skrabec , Thierry Reding , Daniel Vetter , David Airlie , Maarten Lankhorst , Thomas Zimmermann , Maxime Ripard , Neil Armstrong , Laurent Pinchart , Robert Foss , Andrzej Hajda Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH v3 3/8] drm/mipi-dsi: Create devm device registration Date: Mon, 23 Aug 2021 10:47:18 +0200 Message-Id: <20210823084723.1493908-4-maxime@cerno.tech> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210823084723.1493908-1-maxime@cerno.tech> References: <20210823084723.1493908-1-maxime@cerno.tech> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Devices that take their data through the MIPI-DSI bus but are controlled through a secondary bus like I2C have to register a secondary device on the MIPI-DSI bus through the mipi_dsi_device_register_full() function. At removal or when an error occurs, that device needs to be removed through a call to mipi_dsi_device_unregister(). Let's create a device-managed variant of the registration function that will automatically unregister the device at unbind. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_mipi_dsi.c | 46 ++++++++++++++++++++++++++++++++++ include/drm/drm_mipi_dsi.h | 3 +++ 2 files changed, 49 insertions(+) diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c index 5dd475e82995..ddf67463eaa1 100644 --- a/drivers/gpu/drm/drm_mipi_dsi.c +++ b/drivers/gpu/drm/drm_mipi_dsi.c @@ -246,6 +246,52 @@ void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi) } EXPORT_SYMBOL(mipi_dsi_device_unregister); +static void devm_mipi_dsi_device_unregister(void *arg) +{ + struct mipi_dsi_device *dsi = arg; + + mipi_dsi_device_unregister(dsi); +} + +/** + * devm_mipi_dsi_device_register_full - create a managed MIPI DSI device + * @dev: device to tie the MIPI-DSI device lifetime to + * @host: DSI host to which this device is connected + * @info: pointer to template containing DSI device information + * + * Create a MIPI DSI device by using the device information provided by + * mipi_dsi_device_info template + * + * This is the managed version of mipi_dsi_device_register_full() which + * automatically calls mipi_dsi_device_unregister() when @dev is + * unbound. + * + * Returns: + * A pointer to the newly created MIPI DSI device, or, a pointer encoded + * with an error + */ +struct mipi_dsi_device * +devm_mipi_dsi_device_register_full(struct device *dev, + struct mipi_dsi_host *host, + const struct mipi_dsi_device_info *info) +{ + struct mipi_dsi_device *dsi; + int ret; + + dsi = mipi_dsi_device_register_full(host, info); + if (IS_ERR(dsi)) + return dsi; + + ret = devm_add_action_or_reset(dev, + devm_mipi_dsi_device_unregister, + dsi); + if (ret) + return ERR_PTR(ret); + + return dsi; +} +EXPORT_SYMBOL_GPL(devm_mipi_dsi_device_register_full); + static DEFINE_MUTEX(host_lock); static LIST_HEAD(host_list); diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h index af7ba8071eb0..d0032e435e08 100644 --- a/include/drm/drm_mipi_dsi.h +++ b/include/drm/drm_mipi_dsi.h @@ -227,6 +227,9 @@ struct mipi_dsi_device * mipi_dsi_device_register_full(struct mipi_dsi_host *host, const struct mipi_dsi_device_info *info); void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi); +struct mipi_dsi_device * +devm_mipi_dsi_device_register_full(struct device *dev, struct mipi_dsi_host *host, + const struct mipi_dsi_device_info *info); struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np); int mipi_dsi_attach(struct mipi_dsi_device *dsi); int mipi_dsi_detach(struct mipi_dsi_device *dsi); -- 2.31.1