blob: 74a66e83d224b2c8214a18832bb3771946501b45 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Donghwa Leed84f7832012-04-05 19:36:21 +00002/*
3 * Copyright (C) 2012 Samsung Electronics
4 *
5 * Author: InKi Dae <inki.dae@samsung.com>
6 * Author: Donghwa Lee <dh09.lee@samsung.com>
Donghwa Leed84f7832012-04-05 19:36:21 +00007 */
8
9#include <common.h>
10#include <malloc.h>
Piotr Wilczek24e368a2014-03-07 14:59:39 +010011#include <fdtdec.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090012#include <linux/libfdt.h>
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020013#include <linux/compat.h>
Donghwa Leed84f7832012-04-05 19:36:21 +000014#include <linux/err.h>
15#include <asm/arch/dsim.h>
16#include <asm/arch/mipi_dsim.h>
17#include <asm/arch/power.h>
18#include <asm/arch/cpu.h>
19#include <asm/arch/clk.h>
20
21#include "exynos_mipi_dsi_lowlevel.h"
22#include "exynos_mipi_dsi_common.h"
23
24#define master_to_driver(a) (a->dsim_lcd_drv)
25#define master_to_device(a) (a->dsim_lcd_dev)
26
Piotr Wilczek24e368a2014-03-07 14:59:39 +010027DECLARE_GLOBAL_DATA_PTR;
28
Donghwa Leed84f7832012-04-05 19:36:21 +000029struct mipi_dsim_ddi {
30 int bus_id;
31 struct list_head list;
32 struct mipi_dsim_lcd_device *dsim_lcd_dev;
33 struct mipi_dsim_lcd_driver *dsim_lcd_drv;
34};
35
36static LIST_HEAD(dsim_ddi_list);
37static LIST_HEAD(dsim_lcd_dev_list);
38
39int exynos_mipi_dsi_register_lcd_device(struct mipi_dsim_lcd_device *lcd_dev)
40{
41 struct mipi_dsim_ddi *dsim_ddi;
42
43 if (!lcd_dev) {
44 debug("mipi_dsim_lcd_device is NULL.\n");
45 return -EFAULT;
46 }
47
48 if (!lcd_dev->name) {
49 debug("dsim_lcd_device name is NULL.\n");
50 return -EFAULT;
51 }
52
53 dsim_ddi = kzalloc(sizeof(struct mipi_dsim_ddi), GFP_KERNEL);
54 if (!dsim_ddi) {
55 debug("failed to allocate dsim_ddi object.\n");
56 return -EFAULT;
57 }
58
59 dsim_ddi->dsim_lcd_dev = lcd_dev;
60
61 list_add_tail(&dsim_ddi->list, &dsim_ddi_list);
62
63 return 0;
64}
65
66struct mipi_dsim_ddi
67 *exynos_mipi_dsi_find_lcd_device(struct mipi_dsim_lcd_driver *lcd_drv)
68{
69 struct mipi_dsim_ddi *dsim_ddi;
70 struct mipi_dsim_lcd_device *lcd_dev;
71
72 list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) {
73 lcd_dev = dsim_ddi->dsim_lcd_dev;
74 if (!lcd_dev)
75 continue;
76
77 if (lcd_drv->id >= 0) {
78 if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0 &&
79 lcd_drv->id == lcd_dev->id) {
80 /**
81 * bus_id would be used to identify
82 * connected bus.
83 */
84 dsim_ddi->bus_id = lcd_dev->bus_id;
85
86 return dsim_ddi;
87 }
88 } else {
89 if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0) {
90 /**
91 * bus_id would be used to identify
92 * connected bus.
93 */
94 dsim_ddi->bus_id = lcd_dev->bus_id;
95
96 return dsim_ddi;
97 }
98 }
99
100 kfree(dsim_ddi);
101 list_del(&dsim_ddi_list);
102 }
103
104 return NULL;
105}
106
107int exynos_mipi_dsi_register_lcd_driver(struct mipi_dsim_lcd_driver *lcd_drv)
108{
109 struct mipi_dsim_ddi *dsim_ddi;
110
111 if (!lcd_drv) {
112 debug("mipi_dsim_lcd_driver is NULL.\n");
113 return -EFAULT;
114 }
115
116 if (!lcd_drv->name) {
117 debug("dsim_lcd_driver name is NULL.\n");
118 return -EFAULT;
119 }
120
121 dsim_ddi = exynos_mipi_dsi_find_lcd_device(lcd_drv);
122 if (!dsim_ddi) {
123 debug("mipi_dsim_ddi object not found.\n");
124 return -EFAULT;
125 }
126
127 dsim_ddi->dsim_lcd_drv = lcd_drv;
128
129 debug("registered panel driver(%s) to mipi-dsi driver.\n",
130 lcd_drv->name);
131
132 return 0;
133
134}
135
136struct mipi_dsim_ddi
137 *exynos_mipi_dsi_bind_lcd_ddi(struct mipi_dsim_device *dsim,
138 const char *name)
139{
140 struct mipi_dsim_ddi *dsim_ddi;
141 struct mipi_dsim_lcd_driver *lcd_drv;
142 struct mipi_dsim_lcd_device *lcd_dev;
143
144 list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) {
145 lcd_drv = dsim_ddi->dsim_lcd_drv;
146 lcd_dev = dsim_ddi->dsim_lcd_dev;
147 if (!lcd_drv || !lcd_dev)
148 continue;
149
150 debug("lcd_drv->id = %d, lcd_dev->id = %d\n",
151 lcd_drv->id, lcd_dev->id);
152
153 if ((strcmp(lcd_drv->name, name) == 0)) {
154 lcd_dev->master = dsim;
155
156 dsim->dsim_lcd_dev = lcd_dev;
157 dsim->dsim_lcd_drv = lcd_drv;
158
159 return dsim_ddi;
160 }
161 }
162
163 return NULL;
164}
165
166/* define MIPI-DSI Master operations. */
167static struct mipi_dsim_master_ops master_ops = {
168 .cmd_write = exynos_mipi_dsi_wr_data,
169 .get_dsim_frame_done = exynos_mipi_dsi_get_frame_done_status,
170 .clear_dsim_frame_done = exynos_mipi_dsi_clear_frame_done,
171};
172
Simon Glassef4e7792016-02-21 21:08:46 -0700173int exynos_mipi_dsi_init(struct exynos_platform_mipi_dsim *dsim_pd)
Donghwa Leed84f7832012-04-05 19:36:21 +0000174{
175 struct mipi_dsim_device *dsim;
176 struct mipi_dsim_config *dsim_config;
177 struct mipi_dsim_ddi *dsim_ddi;
178
179 dsim = kzalloc(sizeof(struct mipi_dsim_device), GFP_KERNEL);
180 if (!dsim) {
181 debug("failed to allocate dsim object.\n");
182 return -EFAULT;
183 }
184
185 /* get mipi_dsim_config. */
186 dsim_config = dsim_pd->dsim_config;
187 if (dsim_config == NULL) {
188 debug("failed to get dsim config data.\n");
189 return -EFAULT;
190 }
191
192 dsim->pd = dsim_pd;
193 dsim->dsim_config = dsim_config;
194 dsim->master_ops = &master_ops;
195
196 /* bind lcd ddi matched with panel name. */
197 dsim_ddi = exynos_mipi_dsi_bind_lcd_ddi(dsim, dsim_pd->lcd_panel_name);
198 if (!dsim_ddi) {
199 debug("mipi_dsim_ddi object not found.\n");
200 return -ENOSYS;
201 }
202 if (dsim_pd->lcd_power)
203 dsim_pd->lcd_power();
204
205 if (dsim_pd->mipi_power)
206 dsim_pd->mipi_power();
207
208 /* phy_enable(unsigned int dev_index, unsigned int enable) */
209 if (dsim_pd->phy_enable)
210 dsim_pd->phy_enable(0, 1);
211
212 set_mipi_clk();
213
214 exynos_mipi_dsi_init_dsim(dsim);
215 exynos_mipi_dsi_init_link(dsim);
216 exynos_mipi_dsi_set_hs_enable(dsim);
217
218 /* set display timing. */
219 exynos_mipi_dsi_set_display_mode(dsim, dsim->dsim_config);
220
221 /* initialize mipi-dsi client(lcd panel). */
222 if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->mipi_panel_init) {
223 dsim_ddi->dsim_lcd_drv->mipi_panel_init(dsim);
224 dsim_ddi->dsim_lcd_drv->mipi_display_on(dsim);
225 }
226
227 debug("mipi-dsi driver(%s mode) has been probed.\n",
228 (dsim_config->e_interface == DSIM_COMMAND) ?
229 "CPU" : "RGB");
230
231 return 0;
232}
233
Simon Glass6d237092016-02-21 21:08:47 -0700234int exynos_dsim_config_parse_dt(const void *blob, struct mipi_dsim_config *dt,
235 struct mipi_dsim_lcd_device *lcd_dt)
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100236{
237 int node;
238
239 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_MIPI_DSI);
240 if (node <= 0) {
241 printf("exynos_mipi_dsi: Can't get device node for mipi dsi\n");
242 return -ENODEV;
243 }
244
Simon Glassf013e7a2016-02-21 21:08:45 -0700245 dt->e_interface = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100246 "samsung,dsim-config-e-interface", 0);
247
Simon Glassf013e7a2016-02-21 21:08:45 -0700248 dt->e_virtual_ch = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100249 "samsung,dsim-config-e-virtual-ch", 0);
250
Simon Glassf013e7a2016-02-21 21:08:45 -0700251 dt->e_pixel_format = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100252 "samsung,dsim-config-e-pixel-format", 0);
253
Simon Glassf013e7a2016-02-21 21:08:45 -0700254 dt->e_burst_mode = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100255 "samsung,dsim-config-e-burst-mode", 0);
256
Simon Glassf013e7a2016-02-21 21:08:45 -0700257 dt->e_no_data_lane = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100258 "samsung,dsim-config-e-no-data-lane", 0);
259
Simon Glassf013e7a2016-02-21 21:08:45 -0700260 dt->e_byte_clk = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100261 "samsung,dsim-config-e-byte-clk", 0);
262
Simon Glassf013e7a2016-02-21 21:08:45 -0700263 dt->hfp = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100264 "samsung,dsim-config-hfp", 0);
265
Simon Glassf013e7a2016-02-21 21:08:45 -0700266 dt->p = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100267 "samsung,dsim-config-p", 0);
Simon Glassf013e7a2016-02-21 21:08:45 -0700268 dt->m = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100269 "samsung,dsim-config-m", 0);
Simon Glassf013e7a2016-02-21 21:08:45 -0700270 dt->s = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100271 "samsung,dsim-config-s", 0);
272
Simon Glassf013e7a2016-02-21 21:08:45 -0700273 dt->pll_stable_time = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100274 "samsung,dsim-config-pll-stable-time", 0);
275
Simon Glassf013e7a2016-02-21 21:08:45 -0700276 dt->esc_clk = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100277 "samsung,dsim-config-esc-clk", 0);
278
Simon Glassf013e7a2016-02-21 21:08:45 -0700279 dt->stop_holding_cnt = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100280 "samsung,dsim-config-stop-holding-cnt", 0);
281
Simon Glassf013e7a2016-02-21 21:08:45 -0700282 dt->bta_timeout = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100283 "samsung,dsim-config-bta-timeout", 0);
284
Simon Glassf013e7a2016-02-21 21:08:45 -0700285 dt->rx_timeout = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100286 "samsung,dsim-config-rx-timeout", 0);
287
Simon Glass6d237092016-02-21 21:08:47 -0700288 lcd_dt->name = fdtdec_get_config_string(blob,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100289 "samsung,dsim-device-name");
290
Simon Glass6d237092016-02-21 21:08:47 -0700291 lcd_dt->id = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100292 "samsung,dsim-device-id", 0);
293
Simon Glass6d237092016-02-21 21:08:47 -0700294 lcd_dt->bus_id = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100295 "samsung,dsim-device-bus_id", 0);
296
Simon Glass6d237092016-02-21 21:08:47 -0700297 lcd_dt->reverse_panel = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100298 "samsung,dsim-device-reverse-panel", 0);
299
300 return 0;
301}
302
303void exynos_init_dsim_platform_data(vidinfo_t *vid)
304{
Simon Glassef4e7792016-02-21 21:08:46 -0700305 static struct mipi_dsim_config dsim_config_dt;
306 static struct exynos_platform_mipi_dsim dsim_platform_data_dt;
Simon Glass6d237092016-02-21 21:08:47 -0700307 static struct mipi_dsim_lcd_device mipi_lcd_device_dt;
Simon Glassf013e7a2016-02-21 21:08:45 -0700308
Simon Glass6d237092016-02-21 21:08:47 -0700309 if (exynos_dsim_config_parse_dt(gd->fdt_blob, &dsim_config_dt,
310 &mipi_lcd_device_dt))
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100311 debug("Can't get proper dsim config.\n");
312
313 strcpy(dsim_platform_data_dt.lcd_panel_name, mipi_lcd_device_dt.name);
314 dsim_platform_data_dt.dsim_config = &dsim_config_dt;
315 dsim_platform_data_dt.mipi_power = mipi_power;
316 dsim_platform_data_dt.phy_enable = set_mipi_phy_ctrl;
317 dsim_platform_data_dt.lcd_panel_info = (void *)vid;
318
319 mipi_lcd_device_dt.platform_data = (void *)&dsim_platform_data_dt;
320 exynos_mipi_dsi_register_lcd_device(&mipi_lcd_device_dt);
321
Simon Glassef4e7792016-02-21 21:08:46 -0700322 vid->dsim_platform_data_dt = &dsim_platform_data_dt;
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100323}