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 .dpms
= drm_atomic_helper_connector_dpms
,
63 .detect
= exynos_dpi_detect
,
64 .fill_modes
= drm_helper_probe_single_connector_modes
,
65 .destroy
= exynos_dpi_connector_destroy
,
66 .reset
= drm_atomic_helper_connector_reset
,
67 .atomic_duplicate_state
= drm_atomic_helper_connector_duplicate_state
,
68 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
71 static int exynos_dpi_get_modes(struct drm_connector
*connector
)
73 struct exynos_dpi
*ctx
= connector_to_dpi(connector
);
75 /* fimd timings gets precedence over panel modes */
77 struct drm_display_mode
*mode
;
79 mode
= drm_mode_create(connector
->dev
);
81 DRM_ERROR("failed to create a new display mode\n");
84 drm_display_mode_from_videomode(ctx
->vm
, mode
);
85 mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
86 drm_mode_probed_add(connector
, mode
);
91 return ctx
->panel
->funcs
->get_modes(ctx
->panel
);
96 static const struct drm_connector_helper_funcs exynos_dpi_connector_helper_funcs
= {
97 .get_modes
= exynos_dpi_get_modes
,
100 static int exynos_dpi_create_connector(struct drm_encoder
*encoder
)
102 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
103 struct drm_connector
*connector
= &ctx
->connector
;
106 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
108 ret
= drm_connector_init(encoder
->dev
, connector
,
109 &exynos_dpi_connector_funcs
,
110 DRM_MODE_CONNECTOR_VGA
);
112 DRM_ERROR("failed to initialize connector with drm\n");
116 drm_connector_helper_add(connector
, &exynos_dpi_connector_helper_funcs
);
117 drm_connector_register(connector
);
118 drm_mode_connector_attach_encoder(connector
, encoder
);
123 static void exynos_dpi_mode_set(struct drm_encoder
*encoder
,
124 struct drm_display_mode
*mode
,
125 struct drm_display_mode
*adjusted_mode
)
129 static void exynos_dpi_enable(struct drm_encoder
*encoder
)
131 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
134 drm_panel_prepare(ctx
->panel
);
135 drm_panel_enable(ctx
->panel
);
139 static void exynos_dpi_disable(struct drm_encoder
*encoder
)
141 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
144 drm_panel_disable(ctx
->panel
);
145 drm_panel_unprepare(ctx
->panel
);
149 static const struct drm_encoder_helper_funcs exynos_dpi_encoder_helper_funcs
= {
150 .mode_set
= exynos_dpi_mode_set
,
151 .enable
= exynos_dpi_enable
,
152 .disable
= exynos_dpi_disable
,
155 static const struct drm_encoder_funcs exynos_dpi_encoder_funcs
= {
156 .destroy
= drm_encoder_cleanup
,
167 static struct device_node
*exynos_dpi_of_find_panel_node(struct device
*dev
)
169 struct device_node
*np
, *ep
;
171 ep
= of_graph_get_endpoint_by_regs(dev
->of_node
, FIMD_PORT_RGB
, 0);
175 np
= of_graph_get_remote_port_parent(ep
);
181 static int exynos_dpi_parse_dt(struct exynos_dpi
*ctx
)
183 struct device
*dev
= ctx
->dev
;
184 struct device_node
*dn
= dev
->of_node
;
185 struct device_node
*np
;
187 ctx
->panel_node
= exynos_dpi_of_find_panel_node(dev
);
189 np
= of_get_child_by_name(dn
, "display-timings");
191 struct videomode
*vm
;
196 vm
= devm_kzalloc(dev
, sizeof(*ctx
->vm
), GFP_KERNEL
);
200 ret
= of_get_videomode(dn
, vm
, 0);
211 if (!ctx
->panel_node
)
217 int exynos_dpi_bind(struct drm_device
*dev
, struct drm_encoder
*encoder
)
221 ret
= exynos_drm_crtc_get_pipe_from_type(dev
, EXYNOS_DISPLAY_TYPE_LCD
);
225 encoder
->possible_crtcs
= 1 << ret
;
227 DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder
->possible_crtcs
);
229 drm_encoder_init(dev
, encoder
, &exynos_dpi_encoder_funcs
,
230 DRM_MODE_ENCODER_TMDS
, NULL
);
232 drm_encoder_helper_add(encoder
, &exynos_dpi_encoder_helper_funcs
);
234 ret
= exynos_dpi_create_connector(encoder
);
236 DRM_ERROR("failed to create connector ret = %d\n", ret
);
237 drm_encoder_cleanup(encoder
);
244 struct drm_encoder
*exynos_dpi_probe(struct device
*dev
)
246 struct exynos_dpi
*ctx
;
249 ctx
= devm_kzalloc(dev
, sizeof(*ctx
), GFP_KERNEL
);
251 return ERR_PTR(-ENOMEM
);
255 ret
= exynos_dpi_parse_dt(ctx
);
257 devm_kfree(dev
, ctx
);
261 if (ctx
->panel_node
) {
262 ctx
->panel
= of_drm_find_panel(ctx
->panel_node
);
264 return ERR_PTR(-EPROBE_DEFER
);
267 return &ctx
->encoder
;
270 int exynos_dpi_remove(struct drm_encoder
*encoder
)
272 struct exynos_dpi
*ctx
= encoder_to_dpi(encoder
);
274 exynos_dpi_disable(&ctx
->encoder
);
277 drm_panel_detach(ctx
->panel
);