]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/mipi-dsi: Create devm device attachment
authorMaxime Ripard <maxime@cerno.tech>
Fri, 10 Sep 2021 10:11:58 +0000 (12:11 +0200)
committerMaxime Ripard <maxime@cerno.tech>
Fri, 24 Sep 2021 17:25:33 +0000 (19:25 +0200)
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 <a.hajda@samsung.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://patchwork.freedesktop.org/patch/msgid/20210910101218.1632297-5-maxime@cerno.tech
drivers/gpu/drm/drm_mipi_dsi.c
include/drm/drm_mipi_dsi.h

index ddf67463eaa1e2a8188c010a51844bcc23069f55..18cef04df2f2d429e652101c602de50835fbaf29 100644 (file)
@@ -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)
 {
index d0032e435e087d020a49e4209edf272366c875c6..147e51b6d241950c62c3ede6127ef5885f65730e 100644 (file)
@@ -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,