Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1317856pxb; Fri, 10 Sep 2021 03:14:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrrdxGVDCJLgeh3WfPaYPgODg5ytYiIrjU0tiPWbTtNA34Fix21M4uZwZitP224qumop/G X-Received: by 2002:a50:cd9d:: with SMTP id p29mr8087104edi.30.1631268897456; Fri, 10 Sep 2021 03:14:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631268897; cv=none; d=google.com; s=arc-20160816; b=IsPDfG8gKC3XVd8ygXN0Z3CWOqdnUaDQ503k1wZ6ON9Cbnw5o5LqEH7K8+Lt+MPPVt gRZjq1k7S3sVGvNGG5FzMeP1c42t12FJ6ZufwZjqy6dPGQSBz2xeXmZVKaPb0PJF00Hw 4MeJnZ2vaf/6B7g0+viOsrvpB31d8fknAZMvTE3fYWV9hp5aCELT43U564Tnb9f+vb7c TUsrxUAxAz2VQCFHtkw5XMnmmNdOlosIJefi+Kaq4T0mTsl9muqeKIIET1jgFyfhDlNy 19c5QXYpPG95u72a7tzmLnNQ6690+KPSf7F91o0z6PsTRxO+kdlblbINQoydHAnblIfJ m2Rw== 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=//PdX3qAZ6LQHC2/gchQ+ogB7t0gtOhnylWlMf4N1sE=; b=uiiwA1zYMC7MG3ZC8dBxYxJhh3KrhDjPhiJh5eAyI0YWI3IKiNQEi90XEMYJmNJjNA krqDxSSym5qtd1v48PSrw0HRVq+1Mlf3v072SfPWAI+GQUScBjd1G4Ma43qLmumueaRv V/a29TswXWpnHzQhy/aeHgcm5woyFKcyf7N51buRyMMM4UuLUqh3W+o4st/l+baOtIwf 5quBoOljNY62M7YMu0WmBU0RNscHDSZRZ19zFFfJ3Cxil9bujW51IXLLLdMn5SOqBkdA chaX5Y1/CcVy2Ep91lFOkZy02NwqkguAOXFwHzO6grYOHJxsl3oegwwGUQHb9GNan7ic jqyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b=1tXCQiVE; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=RsLhHWUH; 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 qb40si5230171ejc.635.2021.09.10.03.14.33; Fri, 10 Sep 2021 03:14:57 -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=1tXCQiVE; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=RsLhHWUH; 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 S232334AbhIJKOJ (ORCPT + 99 others); Fri, 10 Sep 2021 06:14:09 -0400 Received: from wnew4-smtp.messagingengine.com ([64.147.123.18]:59503 "EHLO wnew4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232317AbhIJKOG (ORCPT ); Fri, 10 Sep 2021 06:14:06 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.west.internal (Postfix) with ESMTP id 68B1B2B0094B; Fri, 10 Sep 2021 06:12:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 10 Sep 2021 06:12:50 -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=//PdX3qAZ6LQH C2/gchQ+ogB7t0gtOhnylWlMf4N1sE=; b=1tXCQiVETicjO+Q+IyuF1yNhGbldj whfNJ3aghKYKx0cstTMih1p0MN2tMom9CQXKM1J47++Oxy2ofKO7aFvWXI19Tsvs lHueFIeNtR7mK7J8hvolPypwT24xeUrk/bZuCs0wtXqaE57AhrJdj+zwTisbRi1P QCzReNDx943cgbkhed/K1zNi4L/JNMFsHsTRAlCY3ranVFwMy5D+7OfBjOCG6xTX gLLuh45ta3LA4XsBoCka1jov085XeXTkozRHqemiWV+bMf2+v0FN5wwgdvxn/8wn hCDZ+SucEMDzpeoSAd9Ld/bBLershkUDPJsdB9AZMuj5QpXe/WppEoUHg== 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=//PdX3qAZ6LQHC2/gchQ+ogB7t0gtOhnylWlMf4N1sE=; b=RsLhHWUH s6qspdu3NxZNEPg3DM4rCKh+OTtjz0P65tgZXxGtjn81KwedEhRRz4oFIoWaPu9g LglxAtPlAoLxKo2Kno1l3Rrnq35+EXel0gj6F1s2nFhD7leemD5Zxs7tgaLprMLG 4fyZrS6ZC8CYC6L72ZlxtaQVwVjdnIkBqRPLy4yY/X+TdvJZJrhLrKUnVe/2gl17 Oyd5M/MmxsFSo+fFybpUYfB3xVmv048+qUx0T6ApXoe3IGtz2ijDnIt85qm0FX4i 9ntBJ7f8pNAd8T+hqtjox7Li/lXgXjfCWVG9CeDxvbsmnBC767CijNPocyI6f4+m 9t8PqqKFOn6JlA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudeguddgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepvdekleevfeffkeejhfffueelteelfeduieefheduudfggffhhfffheevveeh hedvnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepmh grgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 Sep 2021 06:12:47 -0400 (EDT) From: Maxime Ripard To: Andrzej Hajda , Sam Ravnborg , Daniel Vetter , David Airlie , Jonas Karlman , Laurent Pinchart , Thierry Reding , Maarten Lankhorst , Thomas Zimmermann , Maxime Ripard , Neil Armstrong , Robert Foss , Jernej Skrabec Cc: Sean Paul , freedreno@lists.freedesktop.org, Kyungmin Park , linux-kernel@vger.kernel.org, Xinliang Liu , Seung-Woo Kim , Tian Tao , Inki Dae , linux-samsung-soc@vger.kernel.org, linux-arm-msm@vger.kernel.org, Rob Clark , dri-devel@lists.freedesktop.org, John Stultz , Chen Feng , Xinwei Kong , Joonyoung Shim Subject: [PATCH v4 04/24] drm/mipi-dsi: Create devm device attachment Date: Fri, 10 Sep 2021 12:11:58 +0200 Message-Id: <20210910101218.1632297-5-maxime@cerno.tech> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210910101218.1632297-1-maxime@cerno.tech> References: <20210910101218.1632297-1-maxime@cerno.tech> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org MIPI-DSI devices need to call mipi_dsi_attach() when their probe is done to attach against their host. However, at removal or when an error occurs, that attachment needs to be undone through a call to mipi_dsi_detach(). Let's create a device-managed variant of the attachment function that will automatically detach the device at unbind. Reviewed-by: Andrzej Hajda Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_mipi_dsi.c | 35 ++++++++++++++++++++++++++++++++++ include/drm/drm_mipi_dsi.h | 1 + 2 files changed, 36 insertions(+) diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c index ddf67463eaa1..18cef04df2f2 100644 --- a/drivers/gpu/drm/drm_mipi_dsi.c +++ b/drivers/gpu/drm/drm_mipi_dsi.c @@ -391,6 +391,41 @@ int mipi_dsi_detach(struct mipi_dsi_device *dsi) } EXPORT_SYMBOL(mipi_dsi_detach); +static void devm_mipi_dsi_detach(void *arg) +{ + struct mipi_dsi_device *dsi = arg; + + mipi_dsi_detach(dsi); +} + +/** + * devm_mipi_dsi_attach - Attach a MIPI-DSI device to its DSI Host + * @dev: device to tie the MIPI-DSI device attachment lifetime to + * @dsi: DSI peripheral + * + * This is the managed version of mipi_dsi_attach() which automatically + * calls mipi_dsi_detach() when @dev is unbound. + * + * Returns: + * 0 on success, a negative error code on failure. + */ +int devm_mipi_dsi_attach(struct device *dev, + struct mipi_dsi_device *dsi) +{ + int ret; + + ret = mipi_dsi_attach(dsi); + if (ret) + return ret; + + ret = devm_add_action_or_reset(dev, devm_mipi_dsi_detach, dsi); + if (ret) + return ret; + + return 0; +} +EXPORT_SYMBOL_GPL(devm_mipi_dsi_attach); + static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi, struct mipi_dsi_msg *msg) { diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h index d0032e435e08..147e51b6d241 100644 --- a/include/drm/drm_mipi_dsi.h +++ b/include/drm/drm_mipi_dsi.h @@ -233,6 +233,7 @@ devm_mipi_dsi_device_register_full(struct device *dev, struct mipi_dsi_host *hos 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); +int devm_mipi_dsi_attach(struct device *dev, struct mipi_dsi_device *dsi); int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi); int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi); int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi, -- 2.31.1