2 * Exynos DRM Parallel output support.
4 * Copyright (c) 2014 Samsung Electronics Co., Ltd
6 * Contacts: Andrzej Hajda <a.hajda@samsung.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <drm/drm_crtc_helper.h>
15 #include <drm/drm_panel.h>
16 #include <drm/drm_atomic_helper.h>
18 #include <linux/of_graph.h>
19 #include <linux/regulator/consumer.h>
21 #include <video/of_videomode.h>
22 #include <video/videomode.h>
24 #include "exynos_drm_crtc.h"
27 struct drm_encoder encoder
;
29 struct device_node
*panel_node
;
31 struct drm_panel
*panel
;
32 struct drm_connector connector
;
37 #define connector_to_dpi(c) container_of(c, struct exynos_dpi, connector)
39 static inline struct exynos_dpi
*encoder_to_dpi(struct drm_encoder
*e
)
41 return container_of(e
, struct exynos_dpi
, encoder
);
44 static enum drm_connector_status
45 exynos_dpi_detect(struct drm_connector
*connector
, bool force
)
47 struct exynos_dpi
*ctx
= connector_to_dpi(connector
);
49 if (ctx
->panel
&& !ctx
->panel
->connector
)
50 drm_panel_attach(ctx
->panel
, &ctx
->connector
);
52 return connector_status_connected
;
55 static void exynos_dpi_connector_destroy(struct drm_connector
*connector
)
57 drm_connector_unregister(connector
);
58 drm_connector_cleanup(connector
);
61 static const struct drm_connector_funcs exynos_dpi_connector_funcs
= {
62 .detect
= exynos_dpi_detect
,
63 .fill_modes
= drm_helper_probe_single_connector_modes
,
64 .destroy
= exynos_dpi_connector_destroy
,
65 .reset
= drm_atomic_helper_connector_reset
,
66 .atomic_duplicate_state
= drm_atomic_helper_connector_duplicate_state
,
67 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
70 static int exynos_dpi_get_modes(struct drm_connector
*connector
)
72 struct exynos_dpi
*ctx
= connector_to_dpi(connector
);
74 /* fimd timings gets precedence over panel modes */
76 struct drm_display_mode
*mode
;
78 mode
= drm_mode_create(connector
->dev
);
80 DRM_ERROR("failed to create a new display mode\n");
83 drm_display_mode_from_videomode(ctx
->vm
, mode
);
84 mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
85 drm_mode_probed_add(connector
, mode
);
90 return ctx
->panel
->funcs
->get_modes(ctx
->panel
);
95 static const struct drm_connector_helper_funcs exynos_dpi_connector_helper_funcs
= {
96 .get_modes
= exynos_dpi_get_modes
,
99 static int exynos_dpi_create_connector(struct drm_encoder
*encoder
)
101 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
102 struct drm_connector
*connector
= &ctx
->connector
;
105 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
107 ret
= drm_connector_init(encoder
->dev
, connector
,
108 &exynos_dpi_connector_funcs
,
109 DRM_MODE_CONNECTOR_VGA
);
111 DRM_ERROR("failed to initialize connector with drm\n");
115 drm_connector_helper_add(connector
, &exynos_dpi_connector_helper_funcs
);
116 drm_connector_attach_encoder(connector
, encoder
);
121 static void exynos_dpi_mode_set(struct drm_encoder
*encoder
,
122 struct drm_display_mode
*mode
,
123 struct drm_display_mode
*adjusted_mode
)
127 static void exynos_dpi_enable(struct drm_encoder
*encoder
)
129 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
132 drm_panel_prepare(ctx
->panel
);
133 drm_panel_enable(ctx
->panel
);
137 static void exynos_dpi_disable(struct drm_encoder
*encoder
)
139 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
142 drm_panel_disable(ctx
->panel
);
143 drm_panel_unprepare(ctx
->panel
);
147 static const struct drm_encoder_helper_funcs exynos_dpi_encoder_helper_funcs
= {
148 .mode_set
= exynos_dpi_mode_set
,
149 .enable
= exynos_dpi_enable
,
150 .disable
= exynos_dpi_disable
,
153 static const struct drm_encoder_funcs exynos_dpi_encoder_funcs
= {
154 .destroy
= drm_encoder_cleanup
,
165 static int exynos_dpi_parse_dt(struct exynos_dpi
*ctx
)
167 struct device
*dev
= ctx
->dev
;
168 struct device_node
*dn
= dev
->of_node
;
169 struct device_node
*np
;
171 ctx
->panel_node
= of_graph_get_remote_node(dn
, FIMD_PORT_RGB
, 0);
173 np
= of_get_child_by_name(dn
, "display-timings");
175 struct videomode
*vm
;
180 vm
= devm_kzalloc(dev
, sizeof(*ctx
->vm
), GFP_KERNEL
);
184 ret
= of_get_videomode(dn
, vm
, 0);
195 if (!ctx
->panel_node
)
201 int exynos_dpi_bind(struct drm_device
*dev
, struct drm_encoder
*encoder
)
205 drm_encoder_init(dev
, encoder
, &exynos_dpi_encoder_funcs
,
206 DRM_MODE_ENCODER_TMDS
, NULL
);
208 drm_encoder_helper_add(encoder
, &exynos_dpi_encoder_helper_funcs
);
210 ret
= exynos_drm_set_possible_crtcs(encoder
, EXYNOS_DISPLAY_TYPE_LCD
);
214 ret
= exynos_dpi_create_connector(encoder
);
216 DRM_ERROR("failed to create connector ret = %d\n", ret
);
217 drm_encoder_cleanup(encoder
);
224 struct drm_encoder
*exynos_dpi_probe(struct device
*dev
)
226 struct exynos_dpi
*ctx
;
229 ctx
= devm_kzalloc(dev
, sizeof(*ctx
), GFP_KERNEL
);
231 return ERR_PTR(-ENOMEM
);
235 ret
= exynos_dpi_parse_dt(ctx
);
237 devm_kfree(dev
, ctx
);
241 if (ctx
->panel_node
) {
242 ctx
->panel
= of_drm_find_panel(ctx
->panel_node
);
243 if (IS_ERR(ctx
->panel
))
244 return ERR_CAST(ctx
->panel
);
247 return &ctx
->encoder
;
250 int exynos_dpi_remove(struct drm_encoder
*encoder
)
252 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
254 exynos_dpi_disable(&ctx
->encoder
);
257 drm_panel_detach(ctx
->panel
);