1 // SPDX-License-Identifier: GPL-2.0-only
3 * Exynos DRM Parallel output support.
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd
7 * Contacts: Andrzej Hajda <a.hajda@samsung.com>
10 #include <linux/of_graph.h>
11 #include <linux/regulator/consumer.h>
13 #include <drm/drm_atomic_helper.h>
14 #include <drm/drm_panel.h>
15 #include <drm/drm_print.h>
16 #include <drm/drm_probe_helper.h>
17 #include <drm/drm_simple_kms_helper.h>
19 #include <video/of_videomode.h>
20 #include <video/videomode.h>
22 #include "exynos_drm_crtc.h"
25 struct drm_encoder encoder
;
27 struct device_node
*panel_node
;
29 struct drm_panel
*panel
;
30 struct drm_connector connector
;
35 #define connector_to_dpi(c) container_of(c, struct exynos_dpi, connector)
37 static inline struct exynos_dpi
*encoder_to_dpi(struct drm_encoder
*e
)
39 return container_of(e
, struct exynos_dpi
, encoder
);
42 static enum drm_connector_status
43 exynos_dpi_detect(struct drm_connector
*connector
, bool force
)
45 return connector_status_connected
;
48 static void exynos_dpi_connector_destroy(struct drm_connector
*connector
)
50 drm_connector_unregister(connector
);
51 drm_connector_cleanup(connector
);
54 static const struct drm_connector_funcs exynos_dpi_connector_funcs
= {
55 .detect
= exynos_dpi_detect
,
56 .fill_modes
= drm_helper_probe_single_connector_modes
,
57 .destroy
= exynos_dpi_connector_destroy
,
58 .reset
= drm_atomic_helper_connector_reset
,
59 .atomic_duplicate_state
= drm_atomic_helper_connector_duplicate_state
,
60 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
63 static int exynos_dpi_get_modes(struct drm_connector
*connector
)
65 struct exynos_dpi
*ctx
= connector_to_dpi(connector
);
67 /* fimd timings gets precedence over panel modes */
69 struct drm_display_mode
*mode
;
71 mode
= drm_mode_create(connector
->dev
);
73 DRM_DEV_ERROR(ctx
->dev
,
74 "failed to create a new display mode\n");
77 drm_display_mode_from_videomode(ctx
->vm
, mode
);
78 mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
79 drm_mode_probed_add(connector
, mode
);
84 return drm_panel_get_modes(ctx
->panel
, connector
);
89 static const struct drm_connector_helper_funcs exynos_dpi_connector_helper_funcs
= {
90 .get_modes
= exynos_dpi_get_modes
,
93 static int exynos_dpi_create_connector(struct drm_encoder
*encoder
)
95 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
96 struct drm_connector
*connector
= &ctx
->connector
;
99 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
101 ret
= drm_connector_init(encoder
->dev
, connector
,
102 &exynos_dpi_connector_funcs
,
103 DRM_MODE_CONNECTOR_VGA
);
105 DRM_DEV_ERROR(ctx
->dev
,
106 "failed to initialize connector with drm\n");
110 drm_connector_helper_add(connector
, &exynos_dpi_connector_helper_funcs
);
111 drm_connector_attach_encoder(connector
, encoder
);
116 static void exynos_dpi_mode_set(struct drm_encoder
*encoder
,
117 struct drm_display_mode
*mode
,
118 struct drm_display_mode
*adjusted_mode
)
122 static void exynos_dpi_enable(struct drm_encoder
*encoder
)
124 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
127 drm_panel_prepare(ctx
->panel
);
128 drm_panel_enable(ctx
->panel
);
132 static void exynos_dpi_disable(struct drm_encoder
*encoder
)
134 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
137 drm_panel_disable(ctx
->panel
);
138 drm_panel_unprepare(ctx
->panel
);
142 static const struct drm_encoder_helper_funcs exynos_dpi_encoder_helper_funcs
= {
143 .mode_set
= exynos_dpi_mode_set
,
144 .enable
= exynos_dpi_enable
,
145 .disable
= exynos_dpi_disable
,
156 static int exynos_dpi_parse_dt(struct exynos_dpi
*ctx
)
158 struct device
*dev
= ctx
->dev
;
159 struct device_node
*dn
= dev
->of_node
;
160 struct device_node
*np
;
162 ctx
->panel_node
= of_graph_get_remote_node(dn
, FIMD_PORT_RGB
, 0);
164 np
= of_get_child_by_name(dn
, "display-timings");
166 struct videomode
*vm
;
171 vm
= devm_kzalloc(dev
, sizeof(*ctx
->vm
), GFP_KERNEL
);
175 ret
= of_get_videomode(dn
, vm
, 0);
186 if (!ctx
->panel_node
)
192 int exynos_dpi_bind(struct drm_device
*dev
, struct drm_encoder
*encoder
)
196 drm_simple_encoder_init(dev
, encoder
, DRM_MODE_ENCODER_TMDS
);
198 drm_encoder_helper_add(encoder
, &exynos_dpi_encoder_helper_funcs
);
200 ret
= exynos_drm_set_possible_crtcs(encoder
, EXYNOS_DISPLAY_TYPE_LCD
);
204 ret
= exynos_dpi_create_connector(encoder
);
206 DRM_DEV_ERROR(encoder_to_dpi(encoder
)->dev
,
207 "failed to create connector ret = %d\n", ret
);
208 drm_encoder_cleanup(encoder
);
215 struct drm_encoder
*exynos_dpi_probe(struct device
*dev
)
217 struct exynos_dpi
*ctx
;
220 ctx
= devm_kzalloc(dev
, sizeof(*ctx
), GFP_KERNEL
);
222 return ERR_PTR(-ENOMEM
);
226 ret
= exynos_dpi_parse_dt(ctx
);
228 devm_kfree(dev
, ctx
);
232 if (ctx
->panel_node
) {
233 ctx
->panel
= of_drm_find_panel(ctx
->panel_node
);
234 if (IS_ERR(ctx
->panel
))
235 return ERR_CAST(ctx
->panel
);
238 return &ctx
->encoder
;
241 int exynos_dpi_remove(struct drm_encoder
*encoder
)
243 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
245 exynos_dpi_disable(&ctx
->encoder
);