blob: 804fcd0b248486cc4404152e2f0b6eb39c09f1f2 [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
Tom Riniabb9a042024-05-18 20:20:43 -06009#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 Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070014#include <dm/devres.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090015#include <linux/libfdt.h>
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020016#include <linux/compat.h>
Donghwa Leed84f7832012-04-05 19:36:21 +000017#include <linux/err.h>
18#include <asm/arch/dsim.h>
19#include <asm/arch/mipi_dsim.h>
20#include <asm/arch/power.h>
21#include <asm/arch/cpu.h>
22#include <asm/arch/clk.h>
23
24#include "exynos_mipi_dsi_lowlevel.h"
25#include "exynos_mipi_dsi_common.h"
26
27#define master_to_driver(a) (a->dsim_lcd_drv)
28#define master_to_device(a) (a->dsim_lcd_dev)
29
Piotr Wilczek24e368a2014-03-07 14:59:39 +010030DECLARE_GLOBAL_DATA_PTR;
31
Donghwa Leed84f7832012-04-05 19:36:21 +000032struct mipi_dsim_ddi {
33 int bus_id;
34 struct list_head list;
35 struct mipi_dsim_lcd_device *dsim_lcd_dev;
36 struct mipi_dsim_lcd_driver *dsim_lcd_drv;
37};
38
39static LIST_HEAD(dsim_ddi_list);
40static LIST_HEAD(dsim_lcd_dev_list);
41
42int exynos_mipi_dsi_register_lcd_device(struct mipi_dsim_lcd_device *lcd_dev)
43{
44 struct mipi_dsim_ddi *dsim_ddi;
45
46 if (!lcd_dev) {
47 debug("mipi_dsim_lcd_device is NULL.\n");
48 return -EFAULT;
49 }
50
51 if (!lcd_dev->name) {
52 debug("dsim_lcd_device name is NULL.\n");
53 return -EFAULT;
54 }
55
56 dsim_ddi = kzalloc(sizeof(struct mipi_dsim_ddi), GFP_KERNEL);
57 if (!dsim_ddi) {
58 debug("failed to allocate dsim_ddi object.\n");
59 return -EFAULT;
60 }
61
62 dsim_ddi->dsim_lcd_dev = lcd_dev;
63
64 list_add_tail(&dsim_ddi->list, &dsim_ddi_list);
65
66 return 0;
67}
68
69struct mipi_dsim_ddi
70 *exynos_mipi_dsi_find_lcd_device(struct mipi_dsim_lcd_driver *lcd_drv)
71{
72 struct mipi_dsim_ddi *dsim_ddi;
73 struct mipi_dsim_lcd_device *lcd_dev;
74
75 list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) {
76 lcd_dev = dsim_ddi->dsim_lcd_dev;
77 if (!lcd_dev)
78 continue;
79
80 if (lcd_drv->id >= 0) {
81 if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0 &&
82 lcd_drv->id == lcd_dev->id) {
83 /**
84 * bus_id would be used to identify
85 * connected bus.
86 */
87 dsim_ddi->bus_id = lcd_dev->bus_id;
88
89 return dsim_ddi;
90 }
91 } else {
92 if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0) {
93 /**
94 * bus_id would be used to identify
95 * connected bus.
96 */
97 dsim_ddi->bus_id = lcd_dev->bus_id;
98
99 return dsim_ddi;
100 }
101 }
102
103 kfree(dsim_ddi);
104 list_del(&dsim_ddi_list);
105 }
106
107 return NULL;
108}
109
110int exynos_mipi_dsi_register_lcd_driver(struct mipi_dsim_lcd_driver *lcd_drv)
111{
112 struct mipi_dsim_ddi *dsim_ddi;
113
114 if (!lcd_drv) {
115 debug("mipi_dsim_lcd_driver is NULL.\n");
116 return -EFAULT;
117 }
118
119 if (!lcd_drv->name) {
120 debug("dsim_lcd_driver name is NULL.\n");
121 return -EFAULT;
122 }
123
124 dsim_ddi = exynos_mipi_dsi_find_lcd_device(lcd_drv);
125 if (!dsim_ddi) {
126 debug("mipi_dsim_ddi object not found.\n");
127 return -EFAULT;
128 }
129
130 dsim_ddi->dsim_lcd_drv = lcd_drv;
131
132 debug("registered panel driver(%s) to mipi-dsi driver.\n",
133 lcd_drv->name);
134
135 return 0;
136
137}
138
139struct mipi_dsim_ddi
140 *exynos_mipi_dsi_bind_lcd_ddi(struct mipi_dsim_device *dsim,
141 const char *name)
142{
143 struct mipi_dsim_ddi *dsim_ddi;
144 struct mipi_dsim_lcd_driver *lcd_drv;
145 struct mipi_dsim_lcd_device *lcd_dev;
146
147 list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) {
148 lcd_drv = dsim_ddi->dsim_lcd_drv;
149 lcd_dev = dsim_ddi->dsim_lcd_dev;
150 if (!lcd_drv || !lcd_dev)
151 continue;
152
153 debug("lcd_drv->id = %d, lcd_dev->id = %d\n",
154 lcd_drv->id, lcd_dev->id);
155
156 if ((strcmp(lcd_drv->name, name) == 0)) {
157 lcd_dev->master = dsim;
158
159 dsim->dsim_lcd_dev = lcd_dev;
160 dsim->dsim_lcd_drv = lcd_drv;
161
162 return dsim_ddi;
163 }
164 }
165
166 return NULL;
167}
168
169/* define MIPI-DSI Master operations. */
170static struct mipi_dsim_master_ops master_ops = {
171 .cmd_write = exynos_mipi_dsi_wr_data,
172 .get_dsim_frame_done = exynos_mipi_dsi_get_frame_done_status,
173 .clear_dsim_frame_done = exynos_mipi_dsi_clear_frame_done,
174};
175
Simon Glassef4e7792016-02-21 21:08:46 -0700176int exynos_mipi_dsi_init(struct exynos_platform_mipi_dsim *dsim_pd)
Donghwa Leed84f7832012-04-05 19:36:21 +0000177{
178 struct mipi_dsim_device *dsim;
179 struct mipi_dsim_config *dsim_config;
180 struct mipi_dsim_ddi *dsim_ddi;
181
182 dsim = kzalloc(sizeof(struct mipi_dsim_device), GFP_KERNEL);
183 if (!dsim) {
184 debug("failed to allocate dsim object.\n");
185 return -EFAULT;
186 }
187
188 /* get mipi_dsim_config. */
189 dsim_config = dsim_pd->dsim_config;
190 if (dsim_config == NULL) {
191 debug("failed to get dsim config data.\n");
192 return -EFAULT;
193 }
194
195 dsim->pd = dsim_pd;
196 dsim->dsim_config = dsim_config;
197 dsim->master_ops = &master_ops;
198
199 /* bind lcd ddi matched with panel name. */
200 dsim_ddi = exynos_mipi_dsi_bind_lcd_ddi(dsim, dsim_pd->lcd_panel_name);
201 if (!dsim_ddi) {
202 debug("mipi_dsim_ddi object not found.\n");
203 return -ENOSYS;
204 }
205 if (dsim_pd->lcd_power)
206 dsim_pd->lcd_power();
207
208 if (dsim_pd->mipi_power)
209 dsim_pd->mipi_power();
210
211 /* phy_enable(unsigned int dev_index, unsigned int enable) */
212 if (dsim_pd->phy_enable)
213 dsim_pd->phy_enable(0, 1);
214
215 set_mipi_clk();
216
217 exynos_mipi_dsi_init_dsim(dsim);
218 exynos_mipi_dsi_init_link(dsim);
219 exynos_mipi_dsi_set_hs_enable(dsim);
220
221 /* set display timing. */
222 exynos_mipi_dsi_set_display_mode(dsim, dsim->dsim_config);
223
224 /* initialize mipi-dsi client(lcd panel). */
225 if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->mipi_panel_init) {
226 dsim_ddi->dsim_lcd_drv->mipi_panel_init(dsim);
227 dsim_ddi->dsim_lcd_drv->mipi_display_on(dsim);
228 }
229
230 debug("mipi-dsi driver(%s mode) has been probed.\n",
231 (dsim_config->e_interface == DSIM_COMMAND) ?
232 "CPU" : "RGB");
233
234 return 0;
235}
236
Simon Glass6d237092016-02-21 21:08:47 -0700237int exynos_dsim_config_parse_dt(const void *blob, struct mipi_dsim_config *dt,
238 struct mipi_dsim_lcd_device *lcd_dt)
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100239{
240 int node;
241
242 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_MIPI_DSI);
243 if (node <= 0) {
244 printf("exynos_mipi_dsi: Can't get device node for mipi dsi\n");
245 return -ENODEV;
246 }
247
Simon Glassf013e7a2016-02-21 21:08:45 -0700248 dt->e_interface = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100249 "samsung,dsim-config-e-interface", 0);
250
Simon Glassf013e7a2016-02-21 21:08:45 -0700251 dt->e_virtual_ch = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100252 "samsung,dsim-config-e-virtual-ch", 0);
253
Simon Glassf013e7a2016-02-21 21:08:45 -0700254 dt->e_pixel_format = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100255 "samsung,dsim-config-e-pixel-format", 0);
256
Simon Glassf013e7a2016-02-21 21:08:45 -0700257 dt->e_burst_mode = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100258 "samsung,dsim-config-e-burst-mode", 0);
259
Simon Glassf013e7a2016-02-21 21:08:45 -0700260 dt->e_no_data_lane = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100261 "samsung,dsim-config-e-no-data-lane", 0);
262
Simon Glassf013e7a2016-02-21 21:08:45 -0700263 dt->e_byte_clk = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100264 "samsung,dsim-config-e-byte-clk", 0);
265
Simon Glassf013e7a2016-02-21 21:08:45 -0700266 dt->hfp = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100267 "samsung,dsim-config-hfp", 0);
268
Simon Glassf013e7a2016-02-21 21:08:45 -0700269 dt->p = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100270 "samsung,dsim-config-p", 0);
Simon Glassf013e7a2016-02-21 21:08:45 -0700271 dt->m = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100272 "samsung,dsim-config-m", 0);
Simon Glassf013e7a2016-02-21 21:08:45 -0700273 dt->s = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100274 "samsung,dsim-config-s", 0);
275
Simon Glassf013e7a2016-02-21 21:08:45 -0700276 dt->pll_stable_time = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100277 "samsung,dsim-config-pll-stable-time", 0);
278
Simon Glassf013e7a2016-02-21 21:08:45 -0700279 dt->esc_clk = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100280 "samsung,dsim-config-esc-clk", 0);
281
Simon Glassf013e7a2016-02-21 21:08:45 -0700282 dt->stop_holding_cnt = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100283 "samsung,dsim-config-stop-holding-cnt", 0);
284
Simon Glassf013e7a2016-02-21 21:08:45 -0700285 dt->bta_timeout = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100286 "samsung,dsim-config-bta-timeout", 0);
287
Simon Glassf013e7a2016-02-21 21:08:45 -0700288 dt->rx_timeout = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100289 "samsung,dsim-config-rx-timeout", 0);
290
Simon Glass0034d962021-08-07 07:24:01 -0600291 lcd_dt->name = fdt_getprop(blob, node, "samsung,dsim-device-name",
292 NULL);
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100293
Simon Glass6d237092016-02-21 21:08:47 -0700294 lcd_dt->id = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100295 "samsung,dsim-device-id", 0);
296
Simon Glass6d237092016-02-21 21:08:47 -0700297 lcd_dt->bus_id = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100298 "samsung,dsim-device-bus_id", 0);
299
Simon Glass6d237092016-02-21 21:08:47 -0700300 lcd_dt->reverse_panel = fdtdec_get_int(blob, node,
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100301 "samsung,dsim-device-reverse-panel", 0);
302
303 return 0;
304}
305
306void exynos_init_dsim_platform_data(vidinfo_t *vid)
307{
Simon Glassef4e7792016-02-21 21:08:46 -0700308 static struct mipi_dsim_config dsim_config_dt;
309 static struct exynos_platform_mipi_dsim dsim_platform_data_dt;
Simon Glass6d237092016-02-21 21:08:47 -0700310 static struct mipi_dsim_lcd_device mipi_lcd_device_dt;
Simon Glassf013e7a2016-02-21 21:08:45 -0700311
Simon Glass6d237092016-02-21 21:08:47 -0700312 if (exynos_dsim_config_parse_dt(gd->fdt_blob, &dsim_config_dt,
313 &mipi_lcd_device_dt))
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100314 debug("Can't get proper dsim config.\n");
315
316 strcpy(dsim_platform_data_dt.lcd_panel_name, mipi_lcd_device_dt.name);
317 dsim_platform_data_dt.dsim_config = &dsim_config_dt;
318 dsim_platform_data_dt.mipi_power = mipi_power;
319 dsim_platform_data_dt.phy_enable = set_mipi_phy_ctrl;
320 dsim_platform_data_dt.lcd_panel_info = (void *)vid;
321
322 mipi_lcd_device_dt.platform_data = (void *)&dsim_platform_data_dt;
323 exynos_mipi_dsi_register_lcd_device(&mipi_lcd_device_dt);
324
Simon Glassef4e7792016-02-21 21:08:46 -0700325 vid->dsim_platform_data_dt = &dsim_platform_data_dt;
Piotr Wilczek24e368a2014-03-07 14:59:39 +0100326}