Commit | Line | Data |
---|---|---|
553c48cf TV |
1 | /* |
2 | * linux/drivers/video/omap2/dss/dpi.c | |
3 | * | |
4 | * Copyright (C) 2009 Nokia Corporation | |
5 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> | |
6 | * | |
7 | * Some code and ideas taken from drivers/video/omap/ driver | |
8 | * by Imre Deak. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License version 2 as published by | |
12 | * the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
17 | * more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along with | |
20 | * this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | */ | |
22 | ||
23 | #define DSS_SUBSYS_NAME "DPI" | |
24 | ||
25 | #include <linux/kernel.h> | |
553c48cf | 26 | #include <linux/delay.h> |
a8a35931 | 27 | #include <linux/export.h> |
8a2cfea8 | 28 | #include <linux/err.h> |
553c48cf | 29 | #include <linux/errno.h> |
8a2cfea8 TV |
30 | #include <linux/platform_device.h> |
31 | #include <linux/regulator/consumer.h> | |
13b1ba7d | 32 | #include <linux/string.h> |
553c48cf | 33 | |
a0b38cc4 | 34 | #include <video/omapdss.h> |
553c48cf TV |
35 | |
36 | #include "dss.h" | |
195e672a | 37 | #include "dss_features.h" |
553c48cf TV |
38 | |
39 | static struct { | |
00df43b8 TV |
40 | struct platform_device *pdev; |
41 | ||
8a2cfea8 | 42 | struct regulator *vdds_dsi_reg; |
a72b64b9 | 43 | struct platform_device *dsidev; |
5cf9a264 | 44 | |
c8a5e4e8 AT |
45 | struct mutex lock; |
46 | ||
c499144c | 47 | struct omap_video_timings timings; |
5cf9a264 | 48 | struct dss_lcd_mgr_config mgr_config; |
c6b393d4 | 49 | int data_lines; |
81b87f51 | 50 | |
1f68d9c4 | 51 | struct omap_dss_device output; |
553c48cf TV |
52 | } dpi; |
53 | ||
0e8276ef | 54 | static struct platform_device *dpi_get_dsidev(enum omap_channel channel) |
a72b64b9 | 55 | { |
bd0f5cc3 TV |
56 | /* |
57 | * XXX we can't currently use DSI PLL for DPI with OMAP3, as the DSI PLL | |
58 | * would also be used for DISPC fclk. Meaning, when the DPI output is | |
59 | * disabled, DISPC clock will be disabled, and TV out will stop. | |
60 | */ | |
61 | switch (omapdss_get_version()) { | |
62 | case OMAPDSS_VER_OMAP24xx: | |
63 | case OMAPDSS_VER_OMAP34xx_ES1: | |
64 | case OMAPDSS_VER_OMAP34xx_ES3: | |
65 | case OMAPDSS_VER_OMAP3630: | |
66 | case OMAPDSS_VER_AM35xx: | |
67 | return NULL; | |
bd0f5cc3 | 68 | |
f8ad984c TV |
69 | case OMAPDSS_VER_OMAP4430_ES1: |
70 | case OMAPDSS_VER_OMAP4430_ES2: | |
71 | case OMAPDSS_VER_OMAP4: | |
72 | switch (channel) { | |
73 | case OMAP_DSS_CHANNEL_LCD: | |
74 | return dsi_get_dsidev_from_id(0); | |
75 | case OMAP_DSS_CHANNEL_LCD2: | |
76 | return dsi_get_dsidev_from_id(1); | |
77 | default: | |
78 | return NULL; | |
79 | } | |
80 | ||
81 | case OMAPDSS_VER_OMAP5: | |
82 | switch (channel) { | |
83 | case OMAP_DSS_CHANNEL_LCD: | |
84 | return dsi_get_dsidev_from_id(0); | |
85 | case OMAP_DSS_CHANNEL_LCD3: | |
86 | return dsi_get_dsidev_from_id(1); | |
87 | default: | |
88 | return NULL; | |
89 | } | |
90 | ||
0e8276ef TV |
91 | default: |
92 | return NULL; | |
93 | } | |
a72b64b9 AT |
94 | } |
95 | ||
0e8276ef | 96 | static enum omap_dss_clk_source dpi_get_alt_clk_src(enum omap_channel channel) |
7636b3b4 | 97 | { |
0e8276ef TV |
98 | switch (channel) { |
99 | case OMAP_DSS_CHANNEL_LCD: | |
100 | return OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC; | |
101 | case OMAP_DSS_CHANNEL_LCD2: | |
102 | return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC; | |
103 | default: | |
104 | /* this shouldn't happen */ | |
105 | WARN_ON(1); | |
106 | return OMAP_DSS_CLK_SRC_FCK; | |
107 | } | |
7636b3b4 AT |
108 | } |
109 | ||
100c8262 TV |
110 | struct dpi_clk_calc_ctx { |
111 | struct platform_device *dsidev; | |
112 | ||
113 | /* inputs */ | |
114 | ||
115 | unsigned long pck_min, pck_max; | |
116 | ||
117 | /* outputs */ | |
118 | ||
119 | struct dsi_clock_info dsi_cinfo; | |
120 | struct dss_clock_info dss_cinfo; | |
121 | struct dispc_clock_info dispc_cinfo; | |
122 | }; | |
123 | ||
124 | static bool dpi_calc_dispc_cb(int lckd, int pckd, unsigned long lck, | |
125 | unsigned long pck, void *data) | |
126 | { | |
127 | struct dpi_clk_calc_ctx *ctx = data; | |
128 | ||
129 | /* | |
130 | * Odd dividers give us uneven duty cycle, causing problem when level | |
131 | * shifted. So skip all odd dividers when the pixel clock is on the | |
132 | * higher side. | |
133 | */ | |
134 | if (ctx->pck_min >= 1000000) { | |
135 | if (lckd > 1 && lckd % 2 != 0) | |
136 | return false; | |
137 | ||
138 | if (pckd > 1 && pckd % 2 != 0) | |
139 | return false; | |
140 | } | |
141 | ||
142 | ctx->dispc_cinfo.lck_div = lckd; | |
143 | ctx->dispc_cinfo.pck_div = pckd; | |
144 | ctx->dispc_cinfo.lck = lck; | |
145 | ctx->dispc_cinfo.pck = pck; | |
146 | ||
147 | return true; | |
148 | } | |
149 | ||
150 | ||
151 | static bool dpi_calc_hsdiv_cb(int regm_dispc, unsigned long dispc, | |
152 | void *data) | |
153 | { | |
154 | struct dpi_clk_calc_ctx *ctx = data; | |
155 | ||
156 | /* | |
157 | * Odd dividers give us uneven duty cycle, causing problem when level | |
158 | * shifted. So skip all odd dividers when the pixel clock is on the | |
159 | * higher side. | |
160 | */ | |
161 | if (regm_dispc > 1 && regm_dispc % 2 != 0 && ctx->pck_min >= 1000000) | |
162 | return false; | |
163 | ||
164 | ctx->dsi_cinfo.regm_dispc = regm_dispc; | |
165 | ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc; | |
166 | ||
167 | return dispc_div_calc(dispc, ctx->pck_min, ctx->pck_max, | |
168 | dpi_calc_dispc_cb, ctx); | |
169 | } | |
170 | ||
171 | ||
172 | static bool dpi_calc_pll_cb(int regn, int regm, unsigned long fint, | |
173 | unsigned long pll, | |
174 | void *data) | |
175 | { | |
176 | struct dpi_clk_calc_ctx *ctx = data; | |
177 | ||
178 | ctx->dsi_cinfo.regn = regn; | |
179 | ctx->dsi_cinfo.regm = regm; | |
180 | ctx->dsi_cinfo.fint = fint; | |
181 | ctx->dsi_cinfo.clkin4ddr = pll; | |
182 | ||
183 | return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->pck_min, | |
184 | dpi_calc_hsdiv_cb, ctx); | |
185 | } | |
186 | ||
187 | static bool dpi_calc_dss_cb(int fckd, unsigned long fck, void *data) | |
188 | { | |
189 | struct dpi_clk_calc_ctx *ctx = data; | |
190 | ||
191 | ctx->dss_cinfo.fck = fck; | |
192 | ctx->dss_cinfo.fck_div = fckd; | |
193 | ||
194 | return dispc_div_calc(fck, ctx->pck_min, ctx->pck_max, | |
195 | dpi_calc_dispc_cb, ctx); | |
196 | } | |
197 | ||
198 | static bool dpi_dsi_clk_calc(unsigned long pck, struct dpi_clk_calc_ctx *ctx) | |
199 | { | |
200 | unsigned long clkin; | |
201 | unsigned long pll_min, pll_max; | |
202 | ||
203 | clkin = dsi_get_pll_clkin(dpi.dsidev); | |
204 | ||
205 | memset(ctx, 0, sizeof(*ctx)); | |
206 | ctx->dsidev = dpi.dsidev; | |
207 | ctx->pck_min = pck - 1000; | |
208 | ctx->pck_max = pck + 1000; | |
209 | ctx->dsi_cinfo.clkin = clkin; | |
210 | ||
211 | pll_min = 0; | |
212 | pll_max = 0; | |
213 | ||
214 | return dsi_pll_calc(dpi.dsidev, clkin, | |
215 | pll_min, pll_max, | |
216 | dpi_calc_pll_cb, ctx); | |
217 | } | |
218 | ||
219 | static bool dpi_dss_clk_calc(unsigned long pck, struct dpi_clk_calc_ctx *ctx) | |
220 | { | |
221 | int i; | |
222 | ||
223 | /* | |
224 | * DSS fck gives us very few possibilities, so finding a good pixel | |
225 | * clock may not be possible. We try multiple times to find the clock, | |
226 | * each time widening the pixel clock range we look for, up to | |
2c6360fb | 227 | * +/- ~15MHz. |
100c8262 TV |
228 | */ |
229 | ||
2c6360fb | 230 | for (i = 0; i < 25; ++i) { |
100c8262 TV |
231 | bool ok; |
232 | ||
233 | memset(ctx, 0, sizeof(*ctx)); | |
234 | if (pck > 1000 * i * i * i) | |
235 | ctx->pck_min = max(pck - 1000 * i * i * i, 0lu); | |
236 | else | |
237 | ctx->pck_min = 0; | |
238 | ctx->pck_max = pck + 1000 * i * i * i; | |
239 | ||
240 | ok = dss_div_calc(ctx->pck_min, dpi_calc_dss_cb, ctx); | |
241 | if (ok) | |
242 | return ok; | |
243 | } | |
244 | ||
245 | return false; | |
246 | } | |
247 | ||
248 | ||
249 | ||
03a0d1e8 | 250 | static int dpi_set_dsi_clk(enum omap_channel channel, |
ff1b2cde SS |
251 | unsigned long pck_req, unsigned long *fck, int *lck_div, |
252 | int *pck_div) | |
553c48cf | 253 | { |
100c8262 | 254 | struct dpi_clk_calc_ctx ctx; |
553c48cf | 255 | int r; |
100c8262 | 256 | bool ok; |
553c48cf | 257 | |
100c8262 TV |
258 | ok = dpi_dsi_clk_calc(pck_req, &ctx); |
259 | if (!ok) | |
260 | return -EINVAL; | |
553c48cf | 261 | |
100c8262 | 262 | r = dsi_pll_set_clock_div(dpi.dsidev, &ctx.dsi_cinfo); |
553c48cf TV |
263 | if (r) |
264 | return r; | |
265 | ||
03a0d1e8 TV |
266 | dss_select_lcd_clk_source(channel, |
267 | dpi_get_alt_clk_src(channel)); | |
553c48cf | 268 | |
100c8262 | 269 | dpi.mgr_config.clock_info = ctx.dispc_cinfo; |
553c48cf | 270 | |
100c8262 TV |
271 | *fck = ctx.dsi_cinfo.dsi_pll_hsdiv_dispc_clk; |
272 | *lck_div = ctx.dispc_cinfo.lck_div; | |
273 | *pck_div = ctx.dispc_cinfo.pck_div; | |
553c48cf TV |
274 | |
275 | return 0; | |
276 | } | |
7636b3b4 | 277 | |
03a0d1e8 TV |
278 | static int dpi_set_dispc_clk(unsigned long pck_req, unsigned long *fck, |
279 | int *lck_div, int *pck_div) | |
553c48cf | 280 | { |
100c8262 | 281 | struct dpi_clk_calc_ctx ctx; |
553c48cf | 282 | int r; |
100c8262 | 283 | bool ok; |
553c48cf | 284 | |
100c8262 TV |
285 | ok = dpi_dss_clk_calc(pck_req, &ctx); |
286 | if (!ok) | |
287 | return -EINVAL; | |
553c48cf | 288 | |
100c8262 | 289 | r = dss_set_clock_div(&ctx.dss_cinfo); |
553c48cf TV |
290 | if (r) |
291 | return r; | |
292 | ||
100c8262 | 293 | dpi.mgr_config.clock_info = ctx.dispc_cinfo; |
553c48cf | 294 | |
100c8262 TV |
295 | *fck = ctx.dss_cinfo.fck; |
296 | *lck_div = ctx.dispc_cinfo.lck_div; | |
297 | *pck_div = ctx.dispc_cinfo.pck_div; | |
553c48cf TV |
298 | |
299 | return 0; | |
300 | } | |
553c48cf | 301 | |
03a0d1e8 | 302 | static int dpi_set_mode(struct omap_overlay_manager *mgr) |
553c48cf | 303 | { |
c499144c | 304 | struct omap_video_timings *t = &dpi.timings; |
7636b3b4 AT |
305 | int lck_div = 0, pck_div = 0; |
306 | unsigned long fck = 0; | |
553c48cf | 307 | unsigned long pck; |
553c48cf TV |
308 | int r = 0; |
309 | ||
8a3db406 | 310 | if (dpi.dsidev) |
03a0d1e8 | 311 | r = dpi_set_dsi_clk(mgr->id, t->pixel_clock * 1000, &fck, |
6d523e7b | 312 | &lck_div, &pck_div); |
7636b3b4 | 313 | else |
03a0d1e8 | 314 | r = dpi_set_dispc_clk(t->pixel_clock * 1000, &fck, |
6d523e7b | 315 | &lck_div, &pck_div); |
553c48cf | 316 | if (r) |
4fbafaf3 | 317 | return r; |
553c48cf TV |
318 | |
319 | pck = fck / lck_div / pck_div / 1000; | |
320 | ||
321 | if (pck != t->pixel_clock) { | |
322 | DSSWARN("Could not find exact pixel clock. " | |
323 | "Requested %d kHz, got %lu kHz\n", | |
324 | t->pixel_clock, pck); | |
325 | ||
326 | t->pixel_clock = pck; | |
327 | } | |
328 | ||
5d512fcd | 329 | dss_mgr_set_timings(mgr, t); |
553c48cf | 330 | |
4fbafaf3 | 331 | return 0; |
553c48cf TV |
332 | } |
333 | ||
03a0d1e8 | 334 | static void dpi_config_lcd_manager(struct omap_overlay_manager *mgr) |
553c48cf | 335 | { |
5cf9a264 | 336 | dpi.mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS; |
569969d6 | 337 | |
5cf9a264 AT |
338 | dpi.mgr_config.stallmode = false; |
339 | dpi.mgr_config.fifohandcheck = false; | |
340 | ||
c6b393d4 | 341 | dpi.mgr_config.video_port_width = dpi.data_lines; |
5cf9a264 AT |
342 | |
343 | dpi.mgr_config.lcden_sig_polarity = 0; | |
344 | ||
5d512fcd | 345 | dss_mgr_set_lcd_config(mgr, &dpi.mgr_config); |
553c48cf TV |
346 | } |
347 | ||
37ac60e4 | 348 | int omapdss_dpi_display_enable(struct omap_dss_device *dssdev) |
553c48cf | 349 | { |
1f68d9c4 | 350 | struct omap_dss_device *out = &dpi.output; |
553c48cf TV |
351 | int r; |
352 | ||
c8a5e4e8 AT |
353 | mutex_lock(&dpi.lock); |
354 | ||
195e672a | 355 | if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI) && !dpi.vdds_dsi_reg) { |
40410715 | 356 | DSSERR("no VDSS_DSI regulator\n"); |
c8a5e4e8 AT |
357 | r = -ENODEV; |
358 | goto err_no_reg; | |
40410715 RK |
359 | } |
360 | ||
5d512fcd AT |
361 | if (out == NULL || out->manager == NULL) { |
362 | DSSERR("failed to enable display: no output/manager\n"); | |
c8a5e4e8 | 363 | r = -ENODEV; |
5d512fcd | 364 | goto err_no_out_mgr; |
05e1d606 TV |
365 | } |
366 | ||
195e672a | 367 | if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) { |
8a2cfea8 TV |
368 | r = regulator_enable(dpi.vdds_dsi_reg); |
369 | if (r) | |
4fbafaf3 | 370 | goto err_reg_enable; |
8a2cfea8 TV |
371 | } |
372 | ||
4fbafaf3 | 373 | r = dispc_runtime_get(); |
553c48cf | 374 | if (r) |
4fbafaf3 TV |
375 | goto err_get_dispc; |
376 | ||
03a0d1e8 | 377 | r = dss_dpi_select_source(out->manager->id); |
de09e455 TV |
378 | if (r) |
379 | goto err_src_sel; | |
380 | ||
8a3db406 | 381 | if (dpi.dsidev) { |
4fbafaf3 TV |
382 | r = dsi_runtime_get(dpi.dsidev); |
383 | if (r) | |
384 | goto err_get_dsi; | |
385 | ||
a72b64b9 | 386 | r = dsi_pll_init(dpi.dsidev, 0, 1); |
7636b3b4 | 387 | if (r) |
4fbafaf3 | 388 | goto err_dsi_pll_init; |
7636b3b4 AT |
389 | } |
390 | ||
03a0d1e8 | 391 | r = dpi_set_mode(out->manager); |
553c48cf | 392 | if (r) |
4fbafaf3 | 393 | goto err_set_mode; |
553c48cf | 394 | |
03a0d1e8 | 395 | dpi_config_lcd_manager(out->manager); |
5cf9a264 | 396 | |
553c48cf TV |
397 | mdelay(2); |
398 | ||
5d512fcd | 399 | r = dss_mgr_enable(out->manager); |
33ca237f TV |
400 | if (r) |
401 | goto err_mgr_enable; | |
553c48cf | 402 | |
c8a5e4e8 AT |
403 | mutex_unlock(&dpi.lock); |
404 | ||
553c48cf TV |
405 | return 0; |
406 | ||
33ca237f | 407 | err_mgr_enable: |
4fbafaf3 | 408 | err_set_mode: |
8a3db406 | 409 | if (dpi.dsidev) |
19077a73 | 410 | dsi_pll_uninit(dpi.dsidev, true); |
4fbafaf3 | 411 | err_dsi_pll_init: |
8a3db406 | 412 | if (dpi.dsidev) |
4fbafaf3 TV |
413 | dsi_runtime_put(dpi.dsidev); |
414 | err_get_dsi: | |
de09e455 | 415 | err_src_sel: |
4fbafaf3 TV |
416 | dispc_runtime_put(); |
417 | err_get_dispc: | |
195e672a | 418 | if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) |
8a2cfea8 | 419 | regulator_disable(dpi.vdds_dsi_reg); |
4fbafaf3 | 420 | err_reg_enable: |
5d512fcd | 421 | err_no_out_mgr: |
c8a5e4e8 AT |
422 | err_no_reg: |
423 | mutex_unlock(&dpi.lock); | |
553c48cf TV |
424 | return r; |
425 | } | |
37ac60e4 | 426 | EXPORT_SYMBOL(omapdss_dpi_display_enable); |
553c48cf | 427 | |
37ac60e4 | 428 | void omapdss_dpi_display_disable(struct omap_dss_device *dssdev) |
553c48cf | 429 | { |
03a0d1e8 | 430 | struct omap_overlay_manager *mgr = dpi.output.manager; |
5d512fcd | 431 | |
c8a5e4e8 AT |
432 | mutex_lock(&dpi.lock); |
433 | ||
5d512fcd | 434 | dss_mgr_disable(mgr); |
553c48cf | 435 | |
8a3db406 | 436 | if (dpi.dsidev) { |
a5b8399f | 437 | dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK); |
a72b64b9 | 438 | dsi_pll_uninit(dpi.dsidev, true); |
4fbafaf3 | 439 | dsi_runtime_put(dpi.dsidev); |
7636b3b4 | 440 | } |
553c48cf | 441 | |
4fbafaf3 | 442 | dispc_runtime_put(); |
553c48cf | 443 | |
195e672a | 444 | if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) |
8a2cfea8 TV |
445 | regulator_disable(dpi.vdds_dsi_reg); |
446 | ||
c8a5e4e8 | 447 | mutex_unlock(&dpi.lock); |
553c48cf | 448 | } |
37ac60e4 | 449 | EXPORT_SYMBOL(omapdss_dpi_display_disable); |
553c48cf | 450 | |
c499144c AT |
451 | void omapdss_dpi_set_timings(struct omap_dss_device *dssdev, |
452 | struct omap_video_timings *timings) | |
553c48cf TV |
453 | { |
454 | DSSDBG("dpi_set_timings\n"); | |
c8a5e4e8 AT |
455 | |
456 | mutex_lock(&dpi.lock); | |
457 | ||
c499144c | 458 | dpi.timings = *timings; |
c499144c | 459 | |
c8a5e4e8 | 460 | mutex_unlock(&dpi.lock); |
553c48cf | 461 | } |
c499144c | 462 | EXPORT_SYMBOL(omapdss_dpi_set_timings); |
553c48cf | 463 | |
69b2048f | 464 | int dpi_check_timings(struct omap_dss_device *dssdev, |
553c48cf TV |
465 | struct omap_video_timings *timings) |
466 | { | |
03a0d1e8 | 467 | struct omap_overlay_manager *mgr = dpi.output.manager; |
553c48cf TV |
468 | int lck_div, pck_div; |
469 | unsigned long fck; | |
470 | unsigned long pck; | |
100c8262 TV |
471 | struct dpi_clk_calc_ctx ctx; |
472 | bool ok; | |
553c48cf | 473 | |
8b095513 | 474 | if (mgr && !dispc_mgr_timings_ok(mgr->id, timings)) |
553c48cf TV |
475 | return -EINVAL; |
476 | ||
477 | if (timings->pixel_clock == 0) | |
478 | return -EINVAL; | |
479 | ||
8a3db406 | 480 | if (dpi.dsidev) { |
100c8262 TV |
481 | ok = dpi_dsi_clk_calc(timings->pixel_clock * 1000, &ctx); |
482 | if (!ok) | |
483 | return -EINVAL; | |
553c48cf | 484 | |
100c8262 | 485 | fck = ctx.dsi_cinfo.dsi_pll_hsdiv_dispc_clk; |
7636b3b4 | 486 | } else { |
100c8262 TV |
487 | ok = dpi_dss_clk_calc(timings->pixel_clock * 1000, &ctx); |
488 | if (!ok) | |
489 | return -EINVAL; | |
553c48cf | 490 | |
100c8262 | 491 | fck = ctx.dss_cinfo.fck; |
553c48cf | 492 | } |
7636b3b4 | 493 | |
100c8262 TV |
494 | lck_div = ctx.dispc_cinfo.lck_div; |
495 | pck_div = ctx.dispc_cinfo.pck_div; | |
553c48cf TV |
496 | |
497 | pck = fck / lck_div / pck_div / 1000; | |
498 | ||
499 | timings->pixel_clock = pck; | |
500 | ||
501 | return 0; | |
502 | } | |
69b2048f | 503 | EXPORT_SYMBOL(dpi_check_timings); |
553c48cf | 504 | |
c6b393d4 AT |
505 | void omapdss_dpi_set_data_lines(struct omap_dss_device *dssdev, int data_lines) |
506 | { | |
507 | mutex_lock(&dpi.lock); | |
508 | ||
509 | dpi.data_lines = data_lines; | |
510 | ||
511 | mutex_unlock(&dpi.lock); | |
512 | } | |
513 | EXPORT_SYMBOL(omapdss_dpi_set_data_lines); | |
514 | ||
94cf394b | 515 | static int dpi_verify_dsi_pll(struct platform_device *dsidev) |
6061675b TV |
516 | { |
517 | int r; | |
518 | ||
519 | /* do initial setup with the PLL to see if it is operational */ | |
520 | ||
521 | r = dsi_runtime_get(dsidev); | |
522 | if (r) | |
523 | return r; | |
524 | ||
525 | r = dsi_pll_init(dsidev, 0, 1); | |
526 | if (r) { | |
527 | dsi_runtime_put(dsidev); | |
528 | return r; | |
529 | } | |
530 | ||
531 | dsi_pll_uninit(dsidev, true); | |
532 | dsi_runtime_put(dsidev); | |
533 | ||
534 | return 0; | |
535 | } | |
536 | ||
2795f646 TV |
537 | static int dpi_init_regulator(void) |
538 | { | |
539 | struct regulator *vdds_dsi; | |
540 | ||
541 | if (!dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) | |
542 | return 0; | |
543 | ||
544 | if (dpi.vdds_dsi_reg) | |
545 | return 0; | |
546 | ||
547 | vdds_dsi = dss_get_vdds_dsi(); | |
548 | ||
549 | if (IS_ERR(vdds_dsi)) { | |
00df43b8 TV |
550 | vdds_dsi = devm_regulator_get(&dpi.pdev->dev, "vdds_dsi"); |
551 | if (IS_ERR(vdds_dsi)) { | |
552 | DSSERR("can't get VDDS_DSI regulator\n"); | |
553 | return PTR_ERR(vdds_dsi); | |
554 | } | |
2795f646 TV |
555 | } |
556 | ||
557 | dpi.vdds_dsi_reg = vdds_dsi; | |
558 | ||
559 | return 0; | |
560 | } | |
561 | ||
562 | static void dpi_init_pll(void) | |
563 | { | |
564 | struct platform_device *dsidev; | |
565 | ||
566 | if (dpi.dsidev) | |
567 | return; | |
568 | ||
569 | dsidev = dpi_get_dsidev(dpi.output.dispc_channel); | |
570 | if (!dsidev) | |
571 | return; | |
572 | ||
573 | if (dpi_verify_dsi_pll(dsidev)) { | |
574 | DSSWARN("DSI PLL not operational\n"); | |
575 | return; | |
576 | } | |
577 | ||
578 | dpi.dsidev = dsidev; | |
579 | } | |
580 | ||
2eea5ae6 TV |
581 | /* |
582 | * Return a hardcoded channel for the DPI output. This should work for | |
583 | * current use cases, but this can be later expanded to either resolve | |
584 | * the channel in some more dynamic manner, or get the channel as a user | |
585 | * parameter. | |
586 | */ | |
587 | static enum omap_channel dpi_get_channel(void) | |
588 | { | |
589 | switch (omapdss_get_version()) { | |
590 | case OMAPDSS_VER_OMAP24xx: | |
591 | case OMAPDSS_VER_OMAP34xx_ES1: | |
592 | case OMAPDSS_VER_OMAP34xx_ES3: | |
593 | case OMAPDSS_VER_OMAP3630: | |
594 | case OMAPDSS_VER_AM35xx: | |
595 | return OMAP_DSS_CHANNEL_LCD; | |
596 | ||
597 | case OMAPDSS_VER_OMAP4430_ES1: | |
598 | case OMAPDSS_VER_OMAP4430_ES2: | |
599 | case OMAPDSS_VER_OMAP4: | |
600 | return OMAP_DSS_CHANNEL_LCD2; | |
601 | ||
602 | case OMAPDSS_VER_OMAP5: | |
603 | return OMAP_DSS_CHANNEL_LCD3; | |
604 | ||
605 | default: | |
606 | DSSWARN("unsupported DSS version\n"); | |
607 | return OMAP_DSS_CHANNEL_LCD; | |
608 | } | |
609 | } | |
610 | ||
94cf394b | 611 | static struct omap_dss_device *dpi_find_dssdev(struct platform_device *pdev) |
5f42f2ce | 612 | { |
35deca3d | 613 | struct omap_dss_board_info *pdata = pdev->dev.platform_data; |
2bbcce5e | 614 | const char *def_disp_name = omapdss_get_default_display_name(); |
1521653c TV |
615 | struct omap_dss_device *def_dssdev; |
616 | int i; | |
617 | ||
618 | def_dssdev = NULL; | |
35deca3d TV |
619 | |
620 | for (i = 0; i < pdata->num_devices; ++i) { | |
621 | struct omap_dss_device *dssdev = pdata->devices[i]; | |
622 | ||
623 | if (dssdev->type != OMAP_DISPLAY_TYPE_DPI) | |
624 | continue; | |
625 | ||
1521653c TV |
626 | if (def_dssdev == NULL) |
627 | def_dssdev = dssdev; | |
628 | ||
629 | if (def_disp_name != NULL && | |
630 | strcmp(dssdev->name, def_disp_name) == 0) { | |
631 | def_dssdev = dssdev; | |
632 | break; | |
9d8232a7 | 633 | } |
1521653c | 634 | } |
9d8232a7 | 635 | |
1521653c TV |
636 | return def_dssdev; |
637 | } | |
638 | ||
bcb734d2 | 639 | static int dpi_probe_pdata(struct platform_device *dpidev) |
1521653c | 640 | { |
5274484b | 641 | struct omap_dss_device *plat_dssdev; |
1521653c TV |
642 | struct omap_dss_device *dssdev; |
643 | int r; | |
644 | ||
5274484b | 645 | plat_dssdev = dpi_find_dssdev(dpidev); |
1521653c | 646 | |
5274484b | 647 | if (!plat_dssdev) |
bcb734d2 | 648 | return 0; |
5274484b | 649 | |
2795f646 TV |
650 | r = dpi_init_regulator(); |
651 | if (r) | |
652 | return r; | |
653 | ||
654 | dpi_init_pll(); | |
655 | ||
5274484b | 656 | dssdev = dss_alloc_and_init_device(&dpidev->dev); |
1521653c | 657 | if (!dssdev) |
bcb734d2 | 658 | return -ENOMEM; |
1521653c | 659 | |
5274484b TV |
660 | dss_copy_device_pdata(dssdev, plat_dssdev); |
661 | ||
486c0e17 TV |
662 | r = omapdss_output_set_device(&dpi.output, dssdev); |
663 | if (r) { | |
664 | DSSERR("failed to connect output to new device: %s\n", | |
665 | dssdev->name); | |
666 | dss_put_device(dssdev); | |
bcb734d2 | 667 | return r; |
486c0e17 TV |
668 | } |
669 | ||
5274484b | 670 | r = dss_add_device(dssdev); |
1521653c TV |
671 | if (r) { |
672 | DSSERR("device %s register failed: %d\n", dssdev->name, r); | |
486c0e17 | 673 | omapdss_output_unset_device(&dpi.output); |
5274484b | 674 | dss_put_device(dssdev); |
bcb734d2 | 675 | return r; |
35deca3d | 676 | } |
bcb734d2 TV |
677 | |
678 | return 0; | |
38f3daf6 TV |
679 | } |
680 | ||
94cf394b | 681 | static void dpi_init_output(struct platform_device *pdev) |
81b87f51 | 682 | { |
1f68d9c4 | 683 | struct omap_dss_device *out = &dpi.output; |
81b87f51 | 684 | |
1f68d9c4 | 685 | out->dev = &pdev->dev; |
81b87f51 | 686 | out->id = OMAP_DSS_OUTPUT_DPI; |
1f68d9c4 | 687 | out->output_type = OMAP_DISPLAY_TYPE_DPI; |
7286a08f | 688 | out->name = "dpi.0"; |
2eea5ae6 | 689 | out->dispc_channel = dpi_get_channel(); |
b7328e14 | 690 | out->owner = THIS_MODULE; |
81b87f51 | 691 | |
5d47dbc8 | 692 | omapdss_register_output(out); |
81b87f51 AT |
693 | } |
694 | ||
695 | static void __exit dpi_uninit_output(struct platform_device *pdev) | |
696 | { | |
1f68d9c4 | 697 | struct omap_dss_device *out = &dpi.output; |
81b87f51 | 698 | |
5d47dbc8 | 699 | omapdss_unregister_output(out); |
81b87f51 AT |
700 | } |
701 | ||
94cf394b | 702 | static int omap_dpi_probe(struct platform_device *pdev) |
38f3daf6 | 703 | { |
bcb734d2 TV |
704 | int r; |
705 | ||
00df43b8 TV |
706 | dpi.pdev = pdev; |
707 | ||
c8a5e4e8 AT |
708 | mutex_init(&dpi.lock); |
709 | ||
81b87f51 AT |
710 | dpi_init_output(pdev); |
711 | ||
c6ca5b22 TV |
712 | if (pdev->dev.platform_data) { |
713 | r = dpi_probe_pdata(pdev); | |
714 | if (r) | |
715 | goto err_probe; | |
bcb734d2 | 716 | } |
35deca3d | 717 | |
5f42f2ce | 718 | return 0; |
c6ca5b22 TV |
719 | |
720 | err_probe: | |
721 | dpi_uninit_output(pdev); | |
722 | return r; | |
5f42f2ce TV |
723 | } |
724 | ||
6e7e8f06 | 725 | static int __exit omap_dpi_remove(struct platform_device *pdev) |
553c48cf | 726 | { |
5274484b | 727 | dss_unregister_child_devices(&pdev->dev); |
35deca3d | 728 | |
81b87f51 AT |
729 | dpi_uninit_output(pdev); |
730 | ||
a57dd4fe | 731 | return 0; |
553c48cf TV |
732 | } |
733 | ||
a57dd4fe | 734 | static struct platform_driver omap_dpi_driver = { |
94cf394b | 735 | .probe = omap_dpi_probe, |
6e7e8f06 | 736 | .remove = __exit_p(omap_dpi_remove), |
a57dd4fe TV |
737 | .driver = { |
738 | .name = "omapdss_dpi", | |
739 | .owner = THIS_MODULE, | |
740 | }, | |
741 | }; | |
742 | ||
6e7e8f06 | 743 | int __init dpi_init_platform_driver(void) |
a57dd4fe | 744 | { |
94cf394b | 745 | return platform_driver_register(&omap_dpi_driver); |
a57dd4fe TV |
746 | } |
747 | ||
6e7e8f06 | 748 | void __exit dpi_uninit_platform_driver(void) |
a57dd4fe TV |
749 | { |
750 | platform_driver_unregister(&omap_dpi_driver); | |
751 | } |