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>
17 #include <linux/regulator/consumer.h>
19 #include <video/of_videomode.h>
20 #include <video/videomode.h>
22 #include "exynos_drm_drv.h"
26 struct device_node
*panel_node
;
28 struct drm_panel
*panel
;
29 struct drm_connector connector
;
30 struct drm_encoder
*encoder
;
36 #define connector_to_dpi(c) container_of(c, struct exynos_dpi, connector)
38 static enum drm_connector_status
39 exynos_dpi_detect(struct drm_connector
*connector
, bool force
)
41 struct exynos_dpi
*ctx
= connector_to_dpi(connector
);
43 if (ctx
->panel
&& !ctx
->panel
->connector
)
44 drm_panel_attach(ctx
->panel
, &ctx
->connector
);
46 return connector_status_connected
;
49 static void exynos_dpi_connector_destroy(struct drm_connector
*connector
)
51 drm_sysfs_connector_remove(connector
);
52 drm_connector_cleanup(connector
);
55 static struct drm_connector_funcs exynos_dpi_connector_funcs
= {
56 .dpms
= drm_helper_connector_dpms
,
57 .detect
= exynos_dpi_detect
,
58 .fill_modes
= drm_helper_probe_single_connector_modes
,
59 .destroy
= exynos_dpi_connector_destroy
,
62 static int exynos_dpi_get_modes(struct drm_connector
*connector
)
64 struct exynos_dpi
*ctx
= connector_to_dpi(connector
);
66 /* fimd timings gets precedence over panel modes */
68 struct drm_display_mode
*mode
;
70 mode
= drm_mode_create(connector
->dev
);
72 DRM_ERROR("failed to create a new display mode\n");
75 drm_display_mode_from_videomode(ctx
->vm
, mode
);
76 mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
77 drm_mode_probed_add(connector
, mode
);
82 return ctx
->panel
->funcs
->get_modes(ctx
->panel
);
87 static struct drm_encoder
*
88 exynos_dpi_best_encoder(struct drm_connector
*connector
)
90 struct exynos_dpi
*ctx
= connector_to_dpi(connector
);
95 static struct drm_connector_helper_funcs exynos_dpi_connector_helper_funcs
= {
96 .get_modes
= exynos_dpi_get_modes
,
97 .best_encoder
= exynos_dpi_best_encoder
,
100 static int exynos_dpi_create_connector(struct exynos_drm_display
*display
,
101 struct drm_encoder
*encoder
)
103 struct exynos_dpi
*ctx
= display
->ctx
;
104 struct drm_connector
*connector
= &ctx
->connector
;
107 ctx
->encoder
= encoder
;
109 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
111 ret
= drm_connector_init(encoder
->dev
, connector
,
112 &exynos_dpi_connector_funcs
,
113 DRM_MODE_CONNECTOR_VGA
);
115 DRM_ERROR("failed to initialize connector with drm\n");
119 drm_connector_helper_add(connector
, &exynos_dpi_connector_helper_funcs
);
120 drm_sysfs_connector_add(connector
);
121 drm_mode_connector_attach_encoder(connector
, encoder
);
126 static void exynos_dpi_poweron(struct exynos_dpi
*ctx
)
129 drm_panel_enable(ctx
->panel
);
132 static void exynos_dpi_poweroff(struct exynos_dpi
*ctx
)
135 drm_panel_disable(ctx
->panel
);
138 static void exynos_dpi_dpms(struct exynos_drm_display
*display
, int mode
)
140 struct exynos_dpi
*ctx
= display
->ctx
;
143 case DRM_MODE_DPMS_ON
:
144 if (ctx
->dpms_mode
!= DRM_MODE_DPMS_ON
)
145 exynos_dpi_poweron(ctx
);
147 case DRM_MODE_DPMS_STANDBY
:
148 case DRM_MODE_DPMS_SUSPEND
:
149 case DRM_MODE_DPMS_OFF
:
150 if (ctx
->dpms_mode
== DRM_MODE_DPMS_ON
)
151 exynos_dpi_poweroff(ctx
);
156 ctx
->dpms_mode
= mode
;
159 static struct exynos_drm_display_ops exynos_dpi_display_ops
= {
160 .create_connector
= exynos_dpi_create_connector
,
161 .dpms
= exynos_dpi_dpms
164 static struct exynos_drm_display exynos_dpi_display
= {
165 .type
= EXYNOS_DISPLAY_TYPE_LCD
,
166 .ops
= &exynos_dpi_display_ops
,
169 /* of_* functions will be removed after merge of of_graph patches */
170 static struct device_node
*
171 of_get_child_by_name_reg(struct device_node
*parent
, const char *name
, u32 reg
)
173 struct device_node
*np
;
175 for_each_child_of_node(parent
, np
) {
178 if (!np
->name
|| of_node_cmp(np
->name
, name
))
181 if (of_property_read_u32(np
, "reg", &r
) < 0)
191 static struct device_node
*of_graph_get_port_by_reg(struct device_node
*parent
,
194 struct device_node
*ports
, *port
;
196 ports
= of_get_child_by_name(parent
, "ports");
200 port
= of_get_child_by_name_reg(parent
, "port", reg
);
207 static struct device_node
*
208 of_graph_get_endpoint_by_reg(struct device_node
*port
, u32 reg
)
210 return of_get_child_by_name_reg(port
, "endpoint", reg
);
213 static struct device_node
*
214 of_graph_get_remote_port_parent(const struct device_node
*node
)
216 struct device_node
*np
;
219 np
= of_parse_phandle(node
, "remote-endpoint", 0);
221 /* Walk 3 levels up only if there is 'ports' node. */
222 for (depth
= 3; depth
&& np
; depth
--) {
223 np
= of_get_next_parent(np
);
224 if (depth
== 2 && of_node_cmp(np
->name
, "ports"))
238 static struct device_node
*exynos_dpi_of_find_panel_node(struct device
*dev
)
240 struct device_node
*np
, *ep
;
242 np
= of_graph_get_port_by_reg(dev
->of_node
, FIMD_PORT_RGB
);
246 ep
= of_graph_get_endpoint_by_reg(np
, 0);
251 np
= of_graph_get_remote_port_parent(ep
);
257 static int exynos_dpi_parse_dt(struct exynos_dpi
*ctx
)
259 struct device
*dev
= ctx
->dev
;
260 struct device_node
*dn
= dev
->of_node
;
261 struct device_node
*np
;
263 ctx
->panel_node
= exynos_dpi_of_find_panel_node(dev
);
265 np
= of_get_child_by_name(dn
, "display-timings");
267 struct videomode
*vm
;
272 vm
= devm_kzalloc(dev
, sizeof(*ctx
->vm
), GFP_KERNEL
);
276 ret
= of_get_videomode(dn
, vm
, 0);
287 if (!ctx
->panel_node
)
293 struct exynos_drm_display
*exynos_dpi_probe(struct device
*dev
)
295 struct exynos_dpi
*ctx
;
298 ret
= exynos_drm_component_add(dev
,
299 EXYNOS_DEVICE_TYPE_CONNECTOR
,
300 exynos_dpi_display
.type
);
304 ctx
= devm_kzalloc(dev
, sizeof(*ctx
), GFP_KERNEL
);
306 goto err_del_component
;
309 exynos_dpi_display
.ctx
= ctx
;
310 ctx
->dpms_mode
= DRM_MODE_DPMS_OFF
;
312 ret
= exynos_dpi_parse_dt(ctx
);
314 devm_kfree(dev
, ctx
);
315 goto err_del_component
;
318 if (ctx
->panel_node
) {
319 ctx
->panel
= of_drm_find_panel(ctx
->panel_node
);
321 exynos_drm_component_del(dev
,
322 EXYNOS_DEVICE_TYPE_CONNECTOR
);
323 return ERR_PTR(-EPROBE_DEFER
);
327 return &exynos_dpi_display
;
330 exynos_drm_component_del(dev
, EXYNOS_DEVICE_TYPE_CONNECTOR
);
335 int exynos_dpi_remove(struct device
*dev
)
337 struct drm_encoder
*encoder
= exynos_dpi_display
.encoder
;
338 struct exynos_dpi
*ctx
= exynos_dpi_display
.ctx
;
340 exynos_dpi_dpms(&exynos_dpi_display
, DRM_MODE_DPMS_OFF
);
341 encoder
->funcs
->destroy(encoder
);
342 drm_connector_cleanup(&ctx
->connector
);
344 exynos_drm_component_del(dev
, EXYNOS_DEVICE_TYPE_CONNECTOR
);