blob: 042aa9a5b9ebcbaf82fbe893255d2558d77a43fd [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>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Donghwa Leed84f7832012-04-05 19:36:21 +000011#include <malloc.h>
Piotr Wilczek24e368a2014-03-07 14:59:39 +010012#include <fdtdec.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070013#include <dm/devres.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090014#include <linux/libfdt.h>
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020015#include <linux/compat.h>
Donghwa Leed84f7832012-04-05 19:36:21 +000016#include <linux/err.h>
17#include <asm/arch/dsim.h>
18#include <asm/arch/mipi_dsim.h>
19#include <asm/arch/power.h>
20#include <asm/arch/cpu.h>
21#include <asm/arch/clk.h>
22
23#include "exynos_mipi_dsi_lowlevel.h"
24#include "exynos_mipi_dsi_common.h"
25
26#define master_to_driver(a) (a->dsim_lcd_drv)
27#define master_to_device(a) (a->dsim_lcd_dev)
28
Piotr Wilczek24e368a2014-03-07 14:59:39 +010029DECLARE_GLOBAL_DATA_PTR;
30
Donghwa Leed84f7832012-04-05 19:36:21 +000031struct mipi_dsim_ddi {
32 int bus_id;
33 struct list_head list;
34 struct mipi_dsim_lcd_device *dsim_lcd_dev;
35 struct mipi_dsim_lcd_driver *dsim_lcd_drv;
36};
37
38static LIST_HEAD(dsim_ddi_list);
39static LIST_HEAD(dsim_lcd_dev_list);
40
41int exynos_mipi_dsi_register_lcd_device(struct mipi_dsim_lcd_device *lcd_dev)
42{
43 struct mipi_dsim_ddi *dsim_ddi;
44
45 if (!lcd_dev) {
46 debug("mipi_dsim_lcd_device is NULL.\n");
47 return -EFAULT;
48 }
49
50 if (!lcd_dev->name) {
51 debug("dsim_lcd_device name is NULL.\n");
52 return -EFAULT;
53 }
54
55 dsim_ddi = kzalloc(sizeof(struct mipi_dsim_ddi), GFP_KERNEL);
56 if (!dsim_ddi) {
57 debug("failed to allocate dsim_ddi object.\n");
58 return -EFAULT;
59 }
60
61 dsim_ddi->dsim_lcd_dev = lcd_dev;
62
63 list_add_tail(&dsim_ddi->list, &dsim_ddi_list);
64
65 return 0;
66}
67
68struct mipi_dsim_ddi
69 *exynos_mipi_dsi_find_lcd_device(struct mipi_dsim_lcd_driver *lcd_drv)
70{
71 struct mipi_dsim_ddi *dsim_ddi;
72 struct mipi_dsim_lcd_device *lcd_dev;
73
74 list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) {
75 lcd_dev = dsim_ddi->dsim_lcd_dev;
76 if (!lcd_dev)
77 continue;
78
79 if (lcd_drv->id >= 0) {
80 if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0 &&
81 lcd_drv->id == lcd_dev->id) {
82 /**
83 * bus_id would be used to identify
84 * connected bus.
85 */
86 dsim_ddi->bus_id = lcd_dev->bus_id;
87
88 return dsim_ddi;
89 }
90 } else {
91 if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0) {
92 /**
93 * bus_id would be used to identify
94 * connected bus.
95 */
96 dsim_ddi->bus_id = lcd_dev->bus_id;
97
98 return dsim_ddi;
99 }
100 }
101
102 kfree(dsim_ddi);
103 list_del(&dsim_ddi_list);
104 }
105
106 return NULL;
107}
108
109int exynos_mipi_dsi_register_lcd_driver(struct mipi_dsim_lcd_driver *lcd_drv)
110{
111 struct mipi_dsim_ddi *dsim_ddi;
112
113 if (!lcd_drv) {
114 debug("mipi_dsim_lcd_driver is NULL.\n");
115 return -EFAULT;
116 }
117
118 if (!lcd_drv->name) {
119 debug("dsim_lcd_driver name is NULL.\n");
120 return -EFAULT;
121 }
122
123 dsim_ddi = exynos_mipi_dsi_find_lcd_device(lcd_drv);
124 if (!dsim_ddi) {
125 debug("mipi_dsim_ddi object not found.\n");
126 return -EFAULT;
127 }
128
129 dsim_ddi->dsim_lcd_drv = lcd_drv;
130
131 debug("registered panel driver(%s) to mipi-dsi driver.\n",
132 lcd_drv->name);
133
134 return 0;
135
136}
137
138struct mipi_dsim_ddi
139 *exynos_mipi_dsi_bind_lcd_ddi(struct mipi_dsim_device *dsim,
140 const char *name)
141{
142 struct mipi_dsim_ddi *dsim_ddi;
143 struct mipi_dsim_lcd_driver *lcd_drv;
144 struct mipi_dsim_lcd_device *lcd_dev;
145
146 list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) {
147 lcd_drv = dsim_ddi->dsim_lcd_drv;
148 lcd_dev = dsim_ddi->dsim_lcd_dev;
149 if (!lcd_drv || !lcd_dev)
150 continue;
151
152 debug("lcd_drv->id = %d, lcd_dev->id = %d\n",
153 lcd_drv->id, lcd_dev->id);
154
155 if ((strcmp(lcd_drv->name, name) == 0)) {
156 lcd_dev->master = dsim;
157
158 dsim->dsim_lcd_dev = lcd_dev;
159 dsim->dsim_lcd_drv = lcd_drv;
160
161 return dsim_ddi;
162 }
163 }
164
165 return NULL;
166}
167
168/* define MIPI-DSI Master operations. */
169static struct mipi_dsim_master_ops master_ops = {
170 .cmd_write = exynos_mipi_dsi_wr_data,
171 .get_dsim_frame_done = exynos_mipi_dsi_get_frame_done_status,
172 .clear_dsim_frame_done = exynos_mipi_dsi_clear_frame_done,
173};
174
Simon Glassef4e7792016-02-21 21:08:46 -0700175int exynos_mipi_dsi_init(struct exynos_platform_mipi_dsim *dsim_pd)
Donghwa Leed84f7832012-04-05 19:36:21 +0000176{
177 struct mipi_dsim_device *dsim;
178 struct mipi_dsim_config *dsim_config;
179 struct mipi_dsim_ddi *dsim_ddi;
180
181 dsim = kzalloc(sizeof(struct mipi_dsim_device), GFP_KERNEL);
182 if (!dsim) {
183 debug("failed to allocate dsim object.\n");
184 return -EFAULT;
185 }
186
187 /* get mipi_dsim_config. */
188 dsim_config = dsim_pd->dsim_config;
189 if (dsim_config == NULL) {
190 debug("failed to get dsim config data.\n");
191 return -EFAULT;
192 }
193
194 dsim->pd = dsim_pd;
195 dsim->dsim_config = dsim_config;
196 dsim->master_ops = &master_ops;
197
198 /* bind lcd ddi matched with panel name. */
199 dsim_ddi = exynos_mipi_dsi_bind_lcd_ddi(dsim, dsim_pd->lcd_panel_name);
200 if (!dsim_ddi) {
201 debug("mipi_dsim_ddi object not found.\n");
202 return -ENOSYS;
203 }
204 if (dsim_pd->lcd_power)
205 dsim_pd->lcd_power();
206
207 if (dsim_pd->mipi_power)
208 dsim_pd->mipi_power();
209
210 /* phy_enable(unsigned int dev_index, unsigned int enable) */
211 if (dsim_pd->phy_enable)
212 dsim_pd->phy_enable(0, 1);
213
214 set_mipi_clk();
215
216 exynos_mipi_dsi_init_dsim(dsim);
217 exynos_mipi_dsi_init_link(dsim);
218 exynos_mipi_dsi_set_hs_enable(dsim);
219
220 /* set display timing. */
221 exynos_mipi_dsi_set_display_mode(dsim, dsim->dsim_config);
222
223 /* initialize mipi-dsi client(lcd panel). */
224 if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->mipi_panel_init) {
225 dsim_ddi->dsim_lcd_drv->mipi_panel_init(dsim);
226 dsim_ddi->dsim_lcd_drv->mipi_display_on(dsim);
227 }
228
229 debug("mipi-dsi driver(%s mode) has been probed.\n",
230 (dsim_config->e_interface == DSIM_COMMAND) ?
231 "CPU" : "RGB");
232
233 return 0;
234}
235
Simon Glass6d237092016-02-21 21:08:47 -0700236int exynos_dsim_config_parse_dt(const void *blob, struct mipi_dsim_config *dt,
237 struct mipi_dsim_lcd_device *lcd_dt)
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100238{
239 int node;
240
241 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_MIPI_DSI);
242 if (node <= 0) {
243 printf("exynos_mipi_dsi: Can't get device node for mipi dsi\n");
244 return -ENODEV;
245 }
246
Simon Glassf013e7a2016-02-21 21:08:45 -0700247 dt->e_interface = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100248 "samsung,dsim-config-e-interface", 0);
249
Simon Glassf013e7a2016-02-21 21:08:45 -0700250 dt->e_virtual_ch = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100251 "samsung,dsim-config-e-virtual-ch", 0);
252
Simon Glassf013e7a2016-02-21 21:08:45 -0700253 dt->e_pixel_format = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100254 "samsung,dsim-config-e-pixel-format", 0);
255
Simon Glassf013e7a2016-02-21 21:08:45 -0700256 dt->e_burst_mode = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100257 "samsung,dsim-config-e-burst-mode", 0);
258
Simon Glassf013e7a2016-02-21 21:08:45 -0700259 dt->e_no_data_lane = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100260 "samsung,dsim-config-e-no-data-lane", 0);
261
Simon Glassf013e7a2016-02-21 21:08:45 -0700262 dt->e_byte_clk = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100263 "samsung,dsim-config-e-byte-clk", 0);
264
Simon Glassf013e7a2016-02-21 21:08:45 -0700265 dt->hfp = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100266 "samsung,dsim-config-hfp", 0);
267
Simon Glassf013e7a2016-02-21 21:08:45 -0700268 dt->p = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100269 "samsung,dsim-config-p", 0);
Simon Glassf013e7a2016-02-21 21:08:45 -0700270 dt->m = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100271 "samsung,dsim-config-m", 0);
Simon Glassf013e7a2016-02-21 21:08:45 -0700272 dt->s = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100273 "samsung,dsim-config-s", 0);
274
Simon Glassf013e7a2016-02-21 21:08:45 -0700275 dt->pll_stable_time = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100276 "samsung,dsim-config-pll-stable-time", 0);
277
Simon Glassf013e7a2016-02-21 21:08:45 -0700278 dt->esc_clk = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100279 "samsung,dsim-config-esc-clk", 0);
280
Simon Glassf013e7a2016-02-21 21:08:45 -0700281 dt->stop_holding_cnt = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100282 "samsung,dsim-config-stop-holding-cnt", 0);
283
Simon Glassf013e7a2016-02-21 21:08:45 -0700284 dt->bta_timeout = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100285 "samsung,dsim-config-bta-timeout", 0);
286
Simon Glassf013e7a2016-02-21 21:08:45 -0700287 dt->rx_timeout = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100288 "samsung,dsim-config-rx-timeout", 0);
289
Simon Glass6d237092016-02-21 21:08:47 -0700290 lcd_dt->name = fdtdec_get_config_string(blob,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100291 "samsung,dsim-device-name");
292
Simon Glass6d237092016-02-21 21:08:47 -0700293 lcd_dt->id = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100294 "samsung,dsim-device-id", 0);
295
Simon Glass6d237092016-02-21 21:08:47 -0700296 lcd_dt->bus_id = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100297 "samsung,dsim-device-bus_id", 0);
298
Simon Glass6d237092016-02-21 21:08:47 -0700299 lcd_dt->reverse_panel = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100300 "samsung,dsim-device-reverse-panel", 0);
301
302 return 0;
303}
304
305void exynos_init_dsim_platform_data(vidinfo_t *vid)
306{
Simon Glassef4e7792016-02-21 21:08:46 -0700307 static struct mipi_dsim_config dsim_config_dt;
308 static struct exynos_platform_mipi_dsim dsim_platform_data_dt;
Simon Glass6d237092016-02-21 21:08:47 -0700309 static struct mipi_dsim_lcd_device mipi_lcd_device_dt;
Simon Glassf013e7a2016-02-21 21:08:45 -0700310
Simon Glass6d237092016-02-21 21:08:47 -0700311 if (exynos_dsim_config_parse_dt(gd->fdt_blob, &dsim_config_dt,
312 &mipi_lcd_device_dt))
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100313 debug("Can't get proper dsim config.\n");
314
315 strcpy(dsim_platform_data_dt.lcd_panel_name, mipi_lcd_device_dt.name);
316 dsim_platform_data_dt.dsim_config = &dsim_config_dt;
317 dsim_platform_data_dt.mipi_power = mipi_power;
318 dsim_platform_data_dt.phy_enable = set_mipi_phy_ctrl;
319 dsim_platform_data_dt.lcd_panel_info = (void *)vid;
320
321 mipi_lcd_device_dt.platform_data = (void *)&dsim_platform_data_dt;
322 exynos_mipi_dsi_register_lcd_device(&mipi_lcd_device_dt);
323
Simon Glassef4e7792016-02-21 21:08:46 -0700324 vid->dsim_platform_data_dt = &dsim_platform_data_dt;
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100325}