blob: fd963821ac7cd348acf59d4f1bfb6f29f6d5f667 [file] [log] [blame]
Donghwa Leed84f7832012-04-05 19:36:21 +00001/*
2 * Copyright (C) 2012 Samsung Electronics
3 *
4 * Author: InKi Dae <inki.dae@samsung.com>
5 * Author: Donghwa Lee <dh09.lee@samsung.com>
6 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02007 * SPDX-License-Identifier: GPL-2.0+
Donghwa Leed84f7832012-04-05 19:36:21 +00008 */
9
10#include <common.h>
11#include <malloc.h>
Piotr Wilczek24e368a2014-03-07 14:59:39 +010012#include <fdtdec.h>
13#include <libfdt.h>
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020014#include <linux/compat.h>
Donghwa Leed84f7832012-04-05 19:36:21 +000015#include <linux/err.h>
16#include <asm/arch/dsim.h>
17#include <asm/arch/mipi_dsim.h>
18#include <asm/arch/power.h>
19#include <asm/arch/cpu.h>
20#include <asm/arch/clk.h>
21
22#include "exynos_mipi_dsi_lowlevel.h"
23#include "exynos_mipi_dsi_common.h"
24
25#define master_to_driver(a) (a->dsim_lcd_drv)
26#define master_to_device(a) (a->dsim_lcd_dev)
27
Piotr Wilczek24e368a2014-03-07 14:59:39 +010028DECLARE_GLOBAL_DATA_PTR;
29
Donghwa Leed84f7832012-04-05 19:36:21 +000030static struct exynos_platform_mipi_dsim *dsim_pd;
Piotr Wilczek24e368a2014-03-07 14:59:39 +010031static struct exynos_platform_mipi_dsim dsim_platform_data_dt;
32static struct mipi_dsim_lcd_device mipi_lcd_device_dt;
Donghwa Leed84f7832012-04-05 19:36:21 +000033
34struct mipi_dsim_ddi {
35 int bus_id;
36 struct list_head list;
37 struct mipi_dsim_lcd_device *dsim_lcd_dev;
38 struct mipi_dsim_lcd_driver *dsim_lcd_drv;
39};
40
41static LIST_HEAD(dsim_ddi_list);
42static LIST_HEAD(dsim_lcd_dev_list);
43
44int exynos_mipi_dsi_register_lcd_device(struct mipi_dsim_lcd_device *lcd_dev)
45{
46 struct mipi_dsim_ddi *dsim_ddi;
47
48 if (!lcd_dev) {
49 debug("mipi_dsim_lcd_device is NULL.\n");
50 return -EFAULT;
51 }
52
53 if (!lcd_dev->name) {
54 debug("dsim_lcd_device name is NULL.\n");
55 return -EFAULT;
56 }
57
58 dsim_ddi = kzalloc(sizeof(struct mipi_dsim_ddi), GFP_KERNEL);
59 if (!dsim_ddi) {
60 debug("failed to allocate dsim_ddi object.\n");
61 return -EFAULT;
62 }
63
64 dsim_ddi->dsim_lcd_dev = lcd_dev;
65
66 list_add_tail(&dsim_ddi->list, &dsim_ddi_list);
67
68 return 0;
69}
70
71struct mipi_dsim_ddi
72 *exynos_mipi_dsi_find_lcd_device(struct mipi_dsim_lcd_driver *lcd_drv)
73{
74 struct mipi_dsim_ddi *dsim_ddi;
75 struct mipi_dsim_lcd_device *lcd_dev;
76
77 list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) {
78 lcd_dev = dsim_ddi->dsim_lcd_dev;
79 if (!lcd_dev)
80 continue;
81
82 if (lcd_drv->id >= 0) {
83 if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0 &&
84 lcd_drv->id == lcd_dev->id) {
85 /**
86 * bus_id would be used to identify
87 * connected bus.
88 */
89 dsim_ddi->bus_id = lcd_dev->bus_id;
90
91 return dsim_ddi;
92 }
93 } else {
94 if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0) {
95 /**
96 * bus_id would be used to identify
97 * connected bus.
98 */
99 dsim_ddi->bus_id = lcd_dev->bus_id;
100
101 return dsim_ddi;
102 }
103 }
104
105 kfree(dsim_ddi);
106 list_del(&dsim_ddi_list);
107 }
108
109 return NULL;
110}
111
112int exynos_mipi_dsi_register_lcd_driver(struct mipi_dsim_lcd_driver *lcd_drv)
113{
114 struct mipi_dsim_ddi *dsim_ddi;
115
116 if (!lcd_drv) {
117 debug("mipi_dsim_lcd_driver is NULL.\n");
118 return -EFAULT;
119 }
120
121 if (!lcd_drv->name) {
122 debug("dsim_lcd_driver name is NULL.\n");
123 return -EFAULT;
124 }
125
126 dsim_ddi = exynos_mipi_dsi_find_lcd_device(lcd_drv);
127 if (!dsim_ddi) {
128 debug("mipi_dsim_ddi object not found.\n");
129 return -EFAULT;
130 }
131
132 dsim_ddi->dsim_lcd_drv = lcd_drv;
133
134 debug("registered panel driver(%s) to mipi-dsi driver.\n",
135 lcd_drv->name);
136
137 return 0;
138
139}
140
141struct mipi_dsim_ddi
142 *exynos_mipi_dsi_bind_lcd_ddi(struct mipi_dsim_device *dsim,
143 const char *name)
144{
145 struct mipi_dsim_ddi *dsim_ddi;
146 struct mipi_dsim_lcd_driver *lcd_drv;
147 struct mipi_dsim_lcd_device *lcd_dev;
148
149 list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) {
150 lcd_drv = dsim_ddi->dsim_lcd_drv;
151 lcd_dev = dsim_ddi->dsim_lcd_dev;
152 if (!lcd_drv || !lcd_dev)
153 continue;
154
155 debug("lcd_drv->id = %d, lcd_dev->id = %d\n",
156 lcd_drv->id, lcd_dev->id);
157
158 if ((strcmp(lcd_drv->name, name) == 0)) {
159 lcd_dev->master = dsim;
160
161 dsim->dsim_lcd_dev = lcd_dev;
162 dsim->dsim_lcd_drv = lcd_drv;
163
164 return dsim_ddi;
165 }
166 }
167
168 return NULL;
169}
170
171/* define MIPI-DSI Master operations. */
172static struct mipi_dsim_master_ops master_ops = {
173 .cmd_write = exynos_mipi_dsi_wr_data,
174 .get_dsim_frame_done = exynos_mipi_dsi_get_frame_done_status,
175 .clear_dsim_frame_done = exynos_mipi_dsi_clear_frame_done,
176};
177
178int exynos_mipi_dsi_init(void)
179{
180 struct mipi_dsim_device *dsim;
181 struct mipi_dsim_config *dsim_config;
182 struct mipi_dsim_ddi *dsim_ddi;
183
184 dsim = kzalloc(sizeof(struct mipi_dsim_device), GFP_KERNEL);
185 if (!dsim) {
186 debug("failed to allocate dsim object.\n");
187 return -EFAULT;
188 }
189
190 /* get mipi_dsim_config. */
191 dsim_config = dsim_pd->dsim_config;
192 if (dsim_config == NULL) {
193 debug("failed to get dsim config data.\n");
194 return -EFAULT;
195 }
196
197 dsim->pd = dsim_pd;
198 dsim->dsim_config = dsim_config;
199 dsim->master_ops = &master_ops;
200
201 /* bind lcd ddi matched with panel name. */
202 dsim_ddi = exynos_mipi_dsi_bind_lcd_ddi(dsim, dsim_pd->lcd_panel_name);
203 if (!dsim_ddi) {
204 debug("mipi_dsim_ddi object not found.\n");
205 return -ENOSYS;
206 }
207 if (dsim_pd->lcd_power)
208 dsim_pd->lcd_power();
209
210 if (dsim_pd->mipi_power)
211 dsim_pd->mipi_power();
212
213 /* phy_enable(unsigned int dev_index, unsigned int enable) */
214 if (dsim_pd->phy_enable)
215 dsim_pd->phy_enable(0, 1);
216
217 set_mipi_clk();
218
219 exynos_mipi_dsi_init_dsim(dsim);
220 exynos_mipi_dsi_init_link(dsim);
221 exynos_mipi_dsi_set_hs_enable(dsim);
222
223 /* set display timing. */
224 exynos_mipi_dsi_set_display_mode(dsim, dsim->dsim_config);
225
226 /* initialize mipi-dsi client(lcd panel). */
227 if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->mipi_panel_init) {
228 dsim_ddi->dsim_lcd_drv->mipi_panel_init(dsim);
229 dsim_ddi->dsim_lcd_drv->mipi_display_on(dsim);
230 }
231
232 debug("mipi-dsi driver(%s mode) has been probed.\n",
233 (dsim_config->e_interface == DSIM_COMMAND) ?
234 "CPU" : "RGB");
235
236 return 0;
237}
238
239void exynos_set_dsim_platform_data(struct exynos_platform_mipi_dsim *pd)
240{
241 if (pd == NULL) {
242 debug("pd is NULL\n");
243 return;
244 }
245
246 dsim_pd = pd;
247}
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100248
Simon Glassf013e7a2016-02-21 21:08:45 -0700249int exynos_dsim_config_parse_dt(const void *blob, struct mipi_dsim_config *dt)
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100250{
251 int node;
252
253 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_MIPI_DSI);
254 if (node <= 0) {
255 printf("exynos_mipi_dsi: Can't get device node for mipi dsi\n");
256 return -ENODEV;
257 }
258
Simon Glassf013e7a2016-02-21 21:08:45 -0700259 dt->e_interface = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100260 "samsung,dsim-config-e-interface", 0);
261
Simon Glassf013e7a2016-02-21 21:08:45 -0700262 dt->e_virtual_ch = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100263 "samsung,dsim-config-e-virtual-ch", 0);
264
Simon Glassf013e7a2016-02-21 21:08:45 -0700265 dt->e_pixel_format = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100266 "samsung,dsim-config-e-pixel-format", 0);
267
Simon Glassf013e7a2016-02-21 21:08:45 -0700268 dt->e_burst_mode = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100269 "samsung,dsim-config-e-burst-mode", 0);
270
Simon Glassf013e7a2016-02-21 21:08:45 -0700271 dt->e_no_data_lane = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100272 "samsung,dsim-config-e-no-data-lane", 0);
273
Simon Glassf013e7a2016-02-21 21:08:45 -0700274 dt->e_byte_clk = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100275 "samsung,dsim-config-e-byte-clk", 0);
276
Simon Glassf013e7a2016-02-21 21:08:45 -0700277 dt->hfp = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100278 "samsung,dsim-config-hfp", 0);
279
Simon Glassf013e7a2016-02-21 21:08:45 -0700280 dt->p = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100281 "samsung,dsim-config-p", 0);
Simon Glassf013e7a2016-02-21 21:08:45 -0700282 dt->m = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100283 "samsung,dsim-config-m", 0);
Simon Glassf013e7a2016-02-21 21:08:45 -0700284 dt->s = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100285 "samsung,dsim-config-s", 0);
286
Simon Glassf013e7a2016-02-21 21:08:45 -0700287 dt->pll_stable_time = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100288 "samsung,dsim-config-pll-stable-time", 0);
289
Simon Glassf013e7a2016-02-21 21:08:45 -0700290 dt->esc_clk = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100291 "samsung,dsim-config-esc-clk", 0);
292
Simon Glassf013e7a2016-02-21 21:08:45 -0700293 dt->stop_holding_cnt = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100294 "samsung,dsim-config-stop-holding-cnt", 0);
295
Simon Glassf013e7a2016-02-21 21:08:45 -0700296 dt->bta_timeout = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100297 "samsung,dsim-config-bta-timeout", 0);
298
Simon Glassf013e7a2016-02-21 21:08:45 -0700299 dt->rx_timeout = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100300 "samsung,dsim-config-rx-timeout", 0);
301
302 mipi_lcd_device_dt.name = fdtdec_get_config_string(blob,
303 "samsung,dsim-device-name");
304
305 mipi_lcd_device_dt.id = fdtdec_get_int(blob, node,
306 "samsung,dsim-device-id", 0);
307
308 mipi_lcd_device_dt.bus_id = fdtdec_get_int(blob, node,
309 "samsung,dsim-device-bus_id", 0);
310
311 mipi_lcd_device_dt.reverse_panel = fdtdec_get_int(blob, node,
312 "samsung,dsim-device-reverse-panel", 0);
313
314 return 0;
315}
316
317void exynos_init_dsim_platform_data(vidinfo_t *vid)
318{
Simon Glassf013e7a2016-02-21 21:08:45 -0700319 struct mipi_dsim_config dsim_config_dt;
320
321 if (exynos_dsim_config_parse_dt(gd->fdt_blob, &dsim_config_dt))
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100322 debug("Can't get proper dsim config.\n");
323
324 strcpy(dsim_platform_data_dt.lcd_panel_name, mipi_lcd_device_dt.name);
325 dsim_platform_data_dt.dsim_config = &dsim_config_dt;
326 dsim_platform_data_dt.mipi_power = mipi_power;
327 dsim_platform_data_dt.phy_enable = set_mipi_phy_ctrl;
328 dsim_platform_data_dt.lcd_panel_info = (void *)vid;
329
330 mipi_lcd_device_dt.platform_data = (void *)&dsim_platform_data_dt;
331 exynos_mipi_dsi_register_lcd_device(&mipi_lcd_device_dt);
332
333 dsim_pd = &dsim_platform_data_dt;
334}