blob: 528229faffe4bf1a6ec223ad5983e09d860ba615 [file] [log] [blame]
Jingoo Hane9474be2012-02-03 18:01:55 +09001/*
2 * Samsung SoC DP (Display Port) interface driver.
3 *
4 * Copyright (C) 2012 Samsung Electronics Co., Ltd.
5 * Author: Jingoo Han <jg1.han@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/module.h>
14#include <linux/platform_device.h>
Jingoo Hane9474be2012-02-03 18:01:55 +090015#include <linux/err.h>
16#include <linux/clk.h>
Ajay Kumar80185562015-01-20 22:08:46 +053017#include <linux/of_graph.h>
Inki Daef37cd5e2014-05-09 14:25:20 +090018#include <linux/component.h>
Sean Paul1417f102014-01-30 16:19:23 -050019#include <video/of_display_timing.h>
20#include <video/of_videomode.h>
Yakir Yang3424e3a2016-03-29 09:57:03 +080021#include <video/videomode.h>
Jingoo Hane9474be2012-02-03 18:01:55 +090022
Sean Paul1417f102014-01-30 16:19:23 -050023#include <drm/drmP.h>
Sean Paulcaa5d1e2014-01-30 16:19:30 -050024#include <drm/drm_crtc.h>
25#include <drm/drm_crtc_helper.h>
Ajay Kumar5f1dcd8b2014-07-31 23:12:14 +053026#include <drm/drm_panel.h>
Sean Paul1417f102014-01-30 16:19:23 -050027
Yakir Yang3424e3a2016-03-29 09:57:03 +080028#include <drm/bridge/analogix_dp.h>
29#include <drm/exynos_drm.h>
30
Gustavo Padovan2b8376c2015-08-15 12:14:08 -030031#include "exynos_drm_crtc.h"
Jingoo Hane9474be2012-02-03 18:01:55 +090032
Yakir Yang3424e3a2016-03-29 09:57:03 +080033#define to_dp(nm) container_of(nm, struct exynos_dp_device, nm)
Sean Paulcaa5d1e2014-01-30 16:19:30 -050034
Yakir Yang3424e3a2016-03-29 09:57:03 +080035struct exynos_dp_device {
36 struct drm_encoder encoder;
Yakir Yangd90efc92016-06-08 10:13:27 -040037 struct drm_connector *connector;
Yakir Yang3424e3a2016-03-29 09:57:03 +080038 struct drm_bridge *ptn_bridge;
39 struct drm_device *drm_dev;
40 struct device *dev;
Krzysztof Kozlowski1c363c72015-04-07 22:28:50 +090041
Yakir Yang3424e3a2016-03-29 09:57:03 +080042 struct videomode vm;
43 struct analogix_dp_plat_data plat_data;
Sean Paul1634ba22014-02-24 19:20:15 +090044};
45
Baoyou Xied42c0962016-09-25 15:54:59 +080046static int exynos_dp_crtc_clock_enable(struct analogix_dp_plat_data *plat_data,
Yakir Yang3424e3a2016-03-29 09:57:03 +080047 bool enable)
Jingoo Hane9474be2012-02-03 18:01:55 +090048{
Yakir Yang3424e3a2016-03-29 09:57:03 +080049 struct exynos_dp_device *dp = to_dp(plat_data);
50 struct drm_encoder *encoder = &dp->encoder;
Jingoo Hane9474be2012-02-03 18:01:55 +090051
Andrzej Hajda196e0592016-04-30 01:39:08 +090052 if (!encoder->crtc)
53 return -EPERM;
Jingoo Han24db03a2012-05-25 16:21:08 +090054
Andrzej Hajda196e0592016-04-30 01:39:08 +090055 exynos_drm_pipe_clk_enable(to_exynos_crtc(encoder->crtc), enable);
Jingoo Hane9474be2012-02-03 18:01:55 +090056
57 return 0;
58}
59
Yakir Yang3424e3a2016-03-29 09:57:03 +080060static int exynos_dp_poweron(struct analogix_dp_plat_data *plat_data)
Jingoo Hane9474be2012-02-03 18:01:55 +090061{
Yakir Yang3424e3a2016-03-29 09:57:03 +080062 return exynos_dp_crtc_clock_enable(plat_data, true);
Jingoo Hane9474be2012-02-03 18:01:55 +090063}
64
Yakir Yang3424e3a2016-03-29 09:57:03 +080065static int exynos_dp_poweroff(struct analogix_dp_plat_data *plat_data)
Jingoo Hane9474be2012-02-03 18:01:55 +090066{
Yakir Yang3424e3a2016-03-29 09:57:03 +080067 return exynos_dp_crtc_clock_enable(plat_data, false);
Jingoo Hane9474be2012-02-03 18:01:55 +090068}
69
Yakir Yangfcc150c2016-06-29 17:15:35 +080070static int exynos_dp_get_modes(struct analogix_dp_plat_data *plat_data,
71 struct drm_connector *connector)
Jingoo Hane9474be2012-02-03 18:01:55 +090072{
Yakir Yang3424e3a2016-03-29 09:57:03 +080073 struct exynos_dp_device *dp = to_dp(plat_data);
Sean Paulcaa5d1e2014-01-30 16:19:30 -050074 struct drm_display_mode *mode;
Yakir Yang3424e3a2016-03-29 09:57:03 +080075 int num_modes = 0;
Sean Paulcaa5d1e2014-01-30 16:19:30 -050076
Yakir Yang3424e3a2016-03-29 09:57:03 +080077 if (dp->plat_data.panel)
78 return num_modes;
Ajay Kumar5f1dcd8b2014-07-31 23:12:14 +053079
Sean Paulcaa5d1e2014-01-30 16:19:30 -050080 mode = drm_mode_create(connector->dev);
81 if (!mode) {
82 DRM_ERROR("failed to create a new display mode.\n");
Yakir Yang3424e3a2016-03-29 09:57:03 +080083 return num_modes;
Sean Paulcaa5d1e2014-01-30 16:19:30 -050084 }
85
Andrzej Hajda27d60e32016-02-12 13:13:56 +010086 drm_display_mode_from_videomode(&dp->vm, mode);
Sean Paulcaa5d1e2014-01-30 16:19:30 -050087 connector->display_info.width_mm = mode->width_mm;
88 connector->display_info.height_mm = mode->height_mm;
89
90 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
91 drm_mode_set_name(mode);
92 drm_mode_probed_add(connector, mode);
93
Yakir Yang3424e3a2016-03-29 09:57:03 +080094 return num_modes + 1;
Sean Paulcaa5d1e2014-01-30 16:19:30 -050095}
96
Yakir Yang3424e3a2016-03-29 09:57:03 +080097static int exynos_dp_bridge_attach(struct analogix_dp_plat_data *plat_data,
98 struct drm_bridge *bridge,
99 struct drm_connector *connector)
Sean Paulcaa5d1e2014-01-30 16:19:30 -0500100{
Yakir Yang3424e3a2016-03-29 09:57:03 +0800101 struct exynos_dp_device *dp = to_dp(plat_data);
Gustavo Padovan07c42702015-11-02 20:00:03 +0900102 struct drm_encoder *encoder = &dp->encoder;
Sean Paulcaa5d1e2014-01-30 16:19:30 -0500103 int ret;
104
Yakir Yang3424e3a2016-03-29 09:57:03 +0800105 drm_connector_register(connector);
Yakir Yangd90efc92016-06-08 10:13:27 -0400106 dp->connector = connector;
Yakir Yang3424e3a2016-03-29 09:57:03 +0800107
Sean Paul1634ba22014-02-24 19:20:15 +0900108 /* Pre-empt DP connector creation if there's a bridge */
Gustavo Padovan07c42702015-11-02 20:00:03 +0900109 if (dp->ptn_bridge) {
Yakir Yang3424e3a2016-03-29 09:57:03 +0800110 bridge->next = dp->ptn_bridge;
111 dp->ptn_bridge->encoder = encoder;
112 ret = drm_bridge_attach(encoder->dev, dp->ptn_bridge);
113 if (ret) {
114 DRM_ERROR("Failed to attach bridge to drm\n");
115 bridge->next = NULL;
116 return ret;
Ajay Kumar5f1dcd8b2014-07-31 23:12:14 +0530117 }
118 }
119
Gustavo Padovan07c42702015-11-02 20:00:03 +0900120 return 0;
121}
122
Gustavo Padovan07c42702015-11-02 20:00:03 +0900123static void exynos_dp_mode_set(struct drm_encoder *encoder,
124 struct drm_display_mode *mode,
125 struct drm_display_mode *adjusted_mode)
126{
127}
128
Yakir Yang3424e3a2016-03-29 09:57:03 +0800129static void exynos_dp_nop(struct drm_encoder *encoder)
Gustavo Padovan07c42702015-11-02 20:00:03 +0900130{
Yakir Yang3424e3a2016-03-29 09:57:03 +0800131 /* do nothing */
Gustavo Padovan07c42702015-11-02 20:00:03 +0900132}
133
Ville Syrjälä800ba2b2015-12-15 12:21:06 +0100134static const struct drm_encoder_helper_funcs exynos_dp_encoder_helper_funcs = {
Gustavo Padovan2b8376c2015-08-15 12:14:08 -0300135 .mode_set = exynos_dp_mode_set,
Yakir Yang3424e3a2016-03-29 09:57:03 +0800136 .enable = exynos_dp_nop,
137 .disable = exynos_dp_nop,
Sean Paul1417f102014-01-30 16:19:23 -0500138};
139
Ville Syrjälä800ba2b2015-12-15 12:21:06 +0100140static const struct drm_encoder_funcs exynos_dp_encoder_funcs = {
Gustavo Padovan2b8376c2015-08-15 12:14:08 -0300141 .destroy = drm_encoder_cleanup,
142};
143
Sean Paul1417f102014-01-30 16:19:23 -0500144static int exynos_dp_dt_parse_panel(struct exynos_dp_device *dp)
145{
146 int ret;
147
Andrzej Hajda27d60e32016-02-12 13:13:56 +0100148 ret = of_get_videomode(dp->dev->of_node, &dp->vm, OF_USE_NATIVE_MODE);
Sean Paul1417f102014-01-30 16:19:23 -0500149 if (ret) {
150 DRM_ERROR("failed: of_get_videomode() : %d\n", ret);
151 return ret;
152 }
153 return 0;
154}
155
Inki Daef37cd5e2014-05-09 14:25:20 +0900156static int exynos_dp_bind(struct device *dev, struct device *master, void *data)
Jingoo Hane9474be2012-02-03 18:01:55 +0900157{
Andrzej Hajda1df6e5f2014-11-17 09:54:24 +0100158 struct exynos_dp_device *dp = dev_get_drvdata(dev);
Gustavo Padovan2b8376c2015-08-15 12:14:08 -0300159 struct drm_encoder *encoder = &dp->encoder;
Yakir Yang3424e3a2016-03-29 09:57:03 +0800160 struct drm_device *drm_dev = data;
161 int pipe, ret;
Jingoo Hane9474be2012-02-03 18:01:55 +0900162
Yakir Yang3424e3a2016-03-29 09:57:03 +0800163 /*
164 * Just like the probe function said, we don't need the
165 * device drvrate anymore, we should leave the charge to
166 * analogix dp driver, set the device drvdata to NULL.
167 */
168 dev_set_drvdata(dev, NULL);
Jingoo Hane9474be2012-02-03 18:01:55 +0900169
Yakir Yang3424e3a2016-03-29 09:57:03 +0800170 dp->dev = dev;
171 dp->drm_dev = drm_dev;
Ajay Kumarc4e235c2012-10-13 05:48:00 +0900172
Yakir Yang3424e3a2016-03-29 09:57:03 +0800173 dp->plat_data.dev_type = EXYNOS_DP;
174 dp->plat_data.power_on = exynos_dp_poweron;
175 dp->plat_data.power_off = exynos_dp_poweroff;
176 dp->plat_data.attach = exynos_dp_bridge_attach;
177 dp->plat_data.get_modes = exynos_dp_get_modes;
Ajay Kumarc4e235c2012-10-13 05:48:00 +0900178
Yakir Yang3424e3a2016-03-29 09:57:03 +0800179 if (!dp->plat_data.panel && !dp->ptn_bridge) {
Ajay Kumar5f1dcd8b2014-07-31 23:12:14 +0530180 ret = exynos_dp_dt_parse_panel(dp);
181 if (ret)
182 return ret;
183 }
Sean Paul1417f102014-01-30 16:19:23 -0500184
Gustavo Padovan2b8376c2015-08-15 12:14:08 -0300185 pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev,
186 EXYNOS_DISPLAY_TYPE_LCD);
187 if (pipe < 0)
188 return pipe;
Gustavo Padovana2986e82015-08-05 20:24:20 -0300189
Gustavo Padovan2b8376c2015-08-15 12:14:08 -0300190 encoder->possible_crtcs = 1 << pipe;
191
192 DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
193
194 drm_encoder_init(drm_dev, encoder, &exynos_dp_encoder_funcs,
Ville Syrjälä13a3d912015-12-09 16:20:18 +0200195 DRM_MODE_ENCODER_TMDS, NULL);
Gustavo Padovan2b8376c2015-08-15 12:14:08 -0300196
197 drm_encoder_helper_add(encoder, &exynos_dp_encoder_helper_funcs);
198
Yakir Yang3424e3a2016-03-29 09:57:03 +0800199 dp->plat_data.encoder = encoder;
Gustavo Padovana2986e82015-08-05 20:24:20 -0300200
Yakir Yang3424e3a2016-03-29 09:57:03 +0800201 return analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data);
Inki Daef37cd5e2014-05-09 14:25:20 +0900202}
203
204static void exynos_dp_unbind(struct device *dev, struct device *master,
Yakir Yangbcbb7032016-03-29 09:57:19 +0800205 void *data)
Inki Daef37cd5e2014-05-09 14:25:20 +0900206{
Yakir Yang3424e3a2016-03-29 09:57:03 +0800207 return analogix_dp_unbind(dev, master, data);
Inki Daef37cd5e2014-05-09 14:25:20 +0900208}
209
210static const struct component_ops exynos_dp_ops = {
211 .bind = exynos_dp_bind,
212 .unbind = exynos_dp_unbind,
213};
214
215static int exynos_dp_probe(struct platform_device *pdev)
216{
Ajay Kumar5f1dcd8b2014-07-31 23:12:14 +0530217 struct device *dev = &pdev->dev;
Javier Martinez Canillas37e11062016-01-29 12:09:31 -0300218 struct device_node *np = NULL, *endpoint = NULL;
Ajay Kumar5f1dcd8b2014-07-31 23:12:14 +0530219 struct exynos_dp_device *dp;
Inki Daedf5225b2014-05-29 18:28:02 +0900220
Ajay Kumar5f1dcd8b2014-07-31 23:12:14 +0530221 dp = devm_kzalloc(&pdev->dev, sizeof(struct exynos_dp_device),
Yakir Yangbcbb7032016-03-29 09:57:19 +0800222 GFP_KERNEL);
Ajay Kumar5f1dcd8b2014-07-31 23:12:14 +0530223 if (!dp)
224 return -ENOMEM;
225
Yakir Yang3424e3a2016-03-29 09:57:03 +0800226 /*
227 * We just use the drvdata until driver run into component
228 * add function, and then we would set drvdata to null, so
229 * that analogix dp driver would take charge of the drvdata.
230 */
Andrzej Hajda1df6e5f2014-11-17 09:54:24 +0100231 platform_set_drvdata(pdev, dp);
232
Inki Daea9fa8522015-11-26 21:34:18 +0900233 /* This is for the backward compatibility. */
Javier Martinez Canillas37e11062016-01-29 12:09:31 -0300234 np = of_parse_phandle(dev->of_node, "panel", 0);
235 if (np) {
Yakir Yang3424e3a2016-03-29 09:57:03 +0800236 dp->plat_data.panel = of_drm_find_panel(np);
Javier Martinez Canillas37e11062016-01-29 12:09:31 -0300237 of_node_put(np);
Yakir Yang3424e3a2016-03-29 09:57:03 +0800238 if (!dp->plat_data.panel)
Ajay Kumar5f1dcd8b2014-07-31 23:12:14 +0530239 return -EPROBE_DEFER;
Inki Daea9fa8522015-11-26 21:34:18 +0900240 goto out;
Javier Martinez Canillas37e11062016-01-29 12:09:31 -0300241 }
Inki Daea9fa8522015-11-26 21:34:18 +0900242
Ajay Kumar80185562015-01-20 22:08:46 +0530243 endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
244 if (endpoint) {
Javier Martinez Canillas37e11062016-01-29 12:09:31 -0300245 np = of_graph_get_remote_port_parent(endpoint);
246 if (np) {
247 /* The remote port can be either a panel or a bridge */
Yakir Yang3424e3a2016-03-29 09:57:03 +0800248 dp->plat_data.panel = of_drm_find_panel(np);
249 if (!dp->plat_data.panel) {
Javier Martinez Canillas37e11062016-01-29 12:09:31 -0300250 dp->ptn_bridge = of_drm_find_bridge(np);
251 if (!dp->ptn_bridge) {
252 of_node_put(np);
253 return -EPROBE_DEFER;
254 }
255 }
256 of_node_put(np);
257 } else {
258 DRM_ERROR("no remote endpoint device node found.\n");
259 return -EINVAL;
260 }
261 } else {
262 DRM_ERROR("no port endpoint subnode found.\n");
263 return -EINVAL;
Ajay Kumar80185562015-01-20 22:08:46 +0530264 }
265
Inki Daea9fa8522015-11-26 21:34:18 +0900266out:
Yakir Yang3424e3a2016-03-29 09:57:03 +0800267 return component_add(&pdev->dev, &exynos_dp_ops);
Jingoo Hane9474be2012-02-03 18:01:55 +0900268}
269
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800270static int exynos_dp_remove(struct platform_device *pdev)
Jingoo Hane9474be2012-02-03 18:01:55 +0900271{
Inki Daedf5225b2014-05-29 18:28:02 +0900272 component_del(&pdev->dev, &exynos_dp_ops);
Inki Daedf5225b2014-05-29 18:28:02 +0900273
Jingoo Hane9474be2012-02-03 18:01:55 +0900274 return 0;
275}
276
Gustavo Padovan613d38532015-11-02 20:32:36 +0900277#ifdef CONFIG_PM
278static int exynos_dp_suspend(struct device *dev)
279{
Yakir Yang3424e3a2016-03-29 09:57:03 +0800280 return analogix_dp_suspend(dev);
Gustavo Padovan613d38532015-11-02 20:32:36 +0900281}
282
283static int exynos_dp_resume(struct device *dev)
284{
Yakir Yang3424e3a2016-03-29 09:57:03 +0800285 return analogix_dp_resume(dev);
Gustavo Padovan613d38532015-11-02 20:32:36 +0900286}
287#endif
288
289static const struct dev_pm_ops exynos_dp_pm_ops = {
290 SET_RUNTIME_PM_OPS(exynos_dp_suspend, exynos_dp_resume, NULL)
291};
292
Ajay Kumarc4e235c2012-10-13 05:48:00 +0900293static const struct of_device_id exynos_dp_match[] = {
294 { .compatible = "samsung,exynos5-dp" },
295 {},
296};
Sjoerd Simonsbd024b82014-07-30 11:29:41 +0900297MODULE_DEVICE_TABLE(of, exynos_dp_match);
Ajay Kumarc4e235c2012-10-13 05:48:00 +0900298
Sean Paul1417f102014-01-30 16:19:23 -0500299struct platform_driver dp_driver = {
Jingoo Hane9474be2012-02-03 18:01:55 +0900300 .probe = exynos_dp_probe,
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800301 .remove = exynos_dp_remove,
Jingoo Hane9474be2012-02-03 18:01:55 +0900302 .driver = {
303 .name = "exynos-dp",
304 .owner = THIS_MODULE,
Gustavo Padovan613d38532015-11-02 20:32:36 +0900305 .pm = &exynos_dp_pm_ops,
Jingoo Hanf9b1e012013-10-16 21:58:15 +0530306 .of_match_table = exynos_dp_match,
Jingoo Hane9474be2012-02-03 18:01:55 +0900307 },
308};
309
Jingoo Hane9474be2012-02-03 18:01:55 +0900310MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
Yakir Yang3424e3a2016-03-29 09:57:03 +0800311MODULE_DESCRIPTION("Samsung Specific Analogix-DP Driver Extension");
Jingoo Han8f589bb2014-06-03 21:46:11 +0900312MODULE_LICENSE("GPL v2");