Commit | Line | Data |
---|---|---|
f133a9d7 TV |
1 | /* |
2 | * Taal DSI command mode panel | |
3 | * | |
4 | * Copyright (C) 2009 Nokia Corporation | |
5 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License version 2 as published by | |
9 | * the Free Software Foundation. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 | * more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along with | |
17 | * this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | /*#define DEBUG*/ | |
21 | ||
22 | #include <linux/module.h> | |
23 | #include <linux/delay.h> | |
24 | #include <linux/err.h> | |
25 | #include <linux/jiffies.h> | |
26 | #include <linux/sched.h> | |
27 | #include <linux/backlight.h> | |
28 | #include <linux/fb.h> | |
29 | #include <linux/interrupt.h> | |
30 | #include <linux/gpio.h> | |
f133a9d7 | 31 | #include <linux/workqueue.h> |
5a0e3ad6 | 32 | #include <linux/slab.h> |
a3201a0e | 33 | #include <linux/mutex.h> |
f133a9d7 | 34 | |
a0b38cc4 | 35 | #include <video/omapdss.h> |
4e9f99d7 | 36 | #include <video/omap-panel-nokia-dsi.h> |
7a7c48f9 | 37 | #include <video/mipi_display.h> |
f133a9d7 TV |
38 | |
39 | /* DSI Virtual channel. Hardcoded for now. */ | |
40 | #define TCH 0 | |
41 | ||
42 | #define DCS_READ_NUM_ERRORS 0x05 | |
f133a9d7 TV |
43 | #define DCS_BRIGHTNESS 0x51 |
44 | #define DCS_CTRL_DISPLAY 0x53 | |
45 | #define DCS_WRITE_CABC 0x55 | |
46 | #define DCS_READ_CABC 0x56 | |
47 | #define DCS_GET_ID1 0xda | |
48 | #define DCS_GET_ID2 0xdb | |
49 | #define DCS_GET_ID3 0xdc | |
50 | ||
7ae2fb11 JN |
51 | static irqreturn_t taal_te_isr(int irq, void *data); |
52 | static void taal_te_timeout_work_callback(struct work_struct *work); | |
21df20fc TV |
53 | static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable); |
54 | ||
1abf7814 TV |
55 | static int taal_panel_reset(struct omap_dss_device *dssdev); |
56 | ||
e7f6c3f2 JN |
57 | /** |
58 | * struct panel_config - panel configuration | |
59 | * @name: panel name | |
60 | * @type: panel type | |
61 | * @timings: panel resolution | |
62 | * @sleep: various panel specific delays, passed to msleep() if non-zero | |
63 | * @reset_sequence: reset sequence timings, passed to udelay() if non-zero | |
c8cd4547 TV |
64 | * @regulators: array of panel regulators |
65 | * @num_regulators: number of regulators in the array | |
e7f6c3f2 JN |
66 | */ |
67 | struct panel_config { | |
68 | const char *name; | |
69 | int type; | |
70 | ||
71 | struct omap_video_timings timings; | |
72 | ||
73 | struct { | |
74 | unsigned int sleep_in; | |
75 | unsigned int sleep_out; | |
76 | unsigned int hw_reset; | |
77 | unsigned int enable_te; | |
78 | } sleep; | |
79 | ||
80 | struct { | |
81 | unsigned int high; | |
82 | unsigned int low; | |
83 | } reset_sequence; | |
c8cd4547 | 84 | |
e7f6c3f2 JN |
85 | }; |
86 | ||
87 | enum { | |
88 | PANEL_TAAL, | |
89 | }; | |
90 | ||
91 | static struct panel_config panel_configs[] = { | |
92 | { | |
93 | .name = "taal", | |
94 | .type = PANEL_TAAL, | |
95 | .timings = { | |
96 | .x_res = 864, | |
97 | .y_res = 480, | |
98 | }, | |
99 | .sleep = { | |
100 | .sleep_in = 5, | |
101 | .sleep_out = 5, | |
102 | .hw_reset = 5, | |
103 | .enable_te = 100, /* possible panel bug */ | |
104 | }, | |
105 | .reset_sequence = { | |
106 | .high = 10, | |
107 | .low = 10, | |
108 | }, | |
109 | }, | |
110 | }; | |
111 | ||
f133a9d7 | 112 | struct taal_data { |
a3201a0e TV |
113 | struct mutex lock; |
114 | ||
f133a9d7 TV |
115 | struct backlight_device *bldev; |
116 | ||
117 | unsigned long hw_guard_end; /* next value of jiffies when we can | |
118 | * issue the next sleep in/out command | |
119 | */ | |
120 | unsigned long hw_guard_wait; /* max guard time in jiffies */ | |
121 | ||
122 | struct omap_dss_device *dssdev; | |
123 | ||
124 | bool enabled; | |
125 | u8 rotate; | |
126 | bool mirror; | |
127 | ||
128 | bool te_enabled; | |
7ae2fb11 JN |
129 | |
130 | atomic_t do_update; | |
bc6d4b1d AT |
131 | int channel; |
132 | ||
7ae2fb11 | 133 | struct delayed_work te_timeout_work; |
f133a9d7 | 134 | |
f133a9d7 TV |
135 | bool cabc_broken; |
136 | unsigned cabc_mode; | |
137 | ||
138 | bool intro_printed; | |
139 | ||
883b9ac9 TV |
140 | struct workqueue_struct *workqueue; |
141 | ||
f133a9d7 | 142 | struct delayed_work esd_work; |
33a410be | 143 | unsigned esd_interval; |
e7f6c3f2 | 144 | |
1abf7814 TV |
145 | bool ulps_enabled; |
146 | unsigned ulps_timeout; | |
147 | struct delayed_work ulps_work; | |
148 | ||
e7f6c3f2 | 149 | struct panel_config *panel_config; |
f133a9d7 TV |
150 | }; |
151 | ||
8d3573c8 TV |
152 | static inline struct nokia_dsi_panel_data |
153 | *get_panel_data(const struct omap_dss_device *dssdev) | |
154 | { | |
155 | return (struct nokia_dsi_panel_data *) dssdev->data; | |
156 | } | |
157 | ||
f133a9d7 | 158 | static void taal_esd_work(struct work_struct *work); |
1abf7814 | 159 | static void taal_ulps_work(struct work_struct *work); |
f133a9d7 TV |
160 | |
161 | static void hw_guard_start(struct taal_data *td, int guard_msec) | |
162 | { | |
163 | td->hw_guard_wait = msecs_to_jiffies(guard_msec); | |
164 | td->hw_guard_end = jiffies + td->hw_guard_wait; | |
165 | } | |
166 | ||
167 | static void hw_guard_wait(struct taal_data *td) | |
168 | { | |
169 | unsigned long wait = td->hw_guard_end - jiffies; | |
170 | ||
171 | if ((long)wait > 0 && wait <= td->hw_guard_wait) { | |
172 | set_current_state(TASK_UNINTERRUPTIBLE); | |
173 | schedule_timeout(wait); | |
174 | } | |
175 | } | |
176 | ||
bc6d4b1d | 177 | static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data) |
f133a9d7 TV |
178 | { |
179 | int r; | |
180 | u8 buf[1]; | |
181 | ||
1ffefe75 | 182 | r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1); |
f133a9d7 TV |
183 | |
184 | if (r < 0) | |
185 | return r; | |
186 | ||
187 | *data = buf[0]; | |
188 | ||
189 | return 0; | |
190 | } | |
191 | ||
bc6d4b1d | 192 | static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd) |
f133a9d7 | 193 | { |
1ffefe75 | 194 | return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1); |
f133a9d7 TV |
195 | } |
196 | ||
bc6d4b1d | 197 | static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param) |
f133a9d7 TV |
198 | { |
199 | u8 buf[2]; | |
200 | buf[0] = dcs_cmd; | |
201 | buf[1] = param; | |
1ffefe75 | 202 | return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2); |
f133a9d7 TV |
203 | } |
204 | ||
205 | static int taal_sleep_in(struct taal_data *td) | |
206 | ||
207 | { | |
208 | u8 cmd; | |
209 | int r; | |
210 | ||
211 | hw_guard_wait(td); | |
212 | ||
7a7c48f9 | 213 | cmd = MIPI_DCS_ENTER_SLEEP_MODE; |
1ffefe75 | 214 | r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1); |
f133a9d7 TV |
215 | if (r) |
216 | return r; | |
217 | ||
218 | hw_guard_start(td, 120); | |
219 | ||
e7f6c3f2 JN |
220 | if (td->panel_config->sleep.sleep_in) |
221 | msleep(td->panel_config->sleep.sleep_in); | |
f133a9d7 TV |
222 | |
223 | return 0; | |
224 | } | |
225 | ||
226 | static int taal_sleep_out(struct taal_data *td) | |
227 | { | |
228 | int r; | |
229 | ||
230 | hw_guard_wait(td); | |
231 | ||
7a7c48f9 | 232 | r = taal_dcs_write_0(td, MIPI_DCS_EXIT_SLEEP_MODE); |
f133a9d7 TV |
233 | if (r) |
234 | return r; | |
235 | ||
236 | hw_guard_start(td, 120); | |
237 | ||
e7f6c3f2 JN |
238 | if (td->panel_config->sleep.sleep_out) |
239 | msleep(td->panel_config->sleep.sleep_out); | |
f133a9d7 TV |
240 | |
241 | return 0; | |
242 | } | |
243 | ||
bc6d4b1d | 244 | static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3) |
f133a9d7 TV |
245 | { |
246 | int r; | |
247 | ||
bc6d4b1d | 248 | r = taal_dcs_read_1(td, DCS_GET_ID1, id1); |
f133a9d7 TV |
249 | if (r) |
250 | return r; | |
bc6d4b1d | 251 | r = taal_dcs_read_1(td, DCS_GET_ID2, id2); |
f133a9d7 TV |
252 | if (r) |
253 | return r; | |
bc6d4b1d | 254 | r = taal_dcs_read_1(td, DCS_GET_ID3, id3); |
f133a9d7 TV |
255 | if (r) |
256 | return r; | |
257 | ||
258 | return 0; | |
259 | } | |
260 | ||
bc6d4b1d | 261 | static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror) |
f133a9d7 TV |
262 | { |
263 | int r; | |
264 | u8 mode; | |
265 | int b5, b6, b7; | |
266 | ||
7a7c48f9 | 267 | r = taal_dcs_read_1(td, MIPI_DCS_GET_ADDRESS_MODE, &mode); |
f133a9d7 TV |
268 | if (r) |
269 | return r; | |
270 | ||
271 | switch (rotate) { | |
272 | default: | |
273 | case 0: | |
274 | b7 = 0; | |
275 | b6 = 0; | |
276 | b5 = 0; | |
277 | break; | |
278 | case 1: | |
279 | b7 = 0; | |
280 | b6 = 1; | |
281 | b5 = 1; | |
282 | break; | |
283 | case 2: | |
284 | b7 = 1; | |
285 | b6 = 1; | |
286 | b5 = 0; | |
287 | break; | |
288 | case 3: | |
289 | b7 = 1; | |
290 | b6 = 0; | |
291 | b5 = 1; | |
292 | break; | |
293 | } | |
294 | ||
295 | if (mirror) | |
296 | b6 = !b6; | |
297 | ||
298 | mode &= ~((1<<7) | (1<<6) | (1<<5)); | |
299 | mode |= (b7 << 7) | (b6 << 6) | (b5 << 5); | |
300 | ||
7a7c48f9 | 301 | return taal_dcs_write_1(td, MIPI_DCS_SET_ADDRESS_MODE, mode); |
f133a9d7 TV |
302 | } |
303 | ||
bc6d4b1d AT |
304 | static int taal_set_update_window(struct taal_data *td, |
305 | u16 x, u16 y, u16 w, u16 h) | |
f133a9d7 TV |
306 | { |
307 | int r; | |
308 | u16 x1 = x; | |
309 | u16 x2 = x + w - 1; | |
310 | u16 y1 = y; | |
311 | u16 y2 = y + h - 1; | |
312 | ||
313 | u8 buf[5]; | |
7a7c48f9 | 314 | buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS; |
f133a9d7 TV |
315 | buf[1] = (x1 >> 8) & 0xff; |
316 | buf[2] = (x1 >> 0) & 0xff; | |
317 | buf[3] = (x2 >> 8) & 0xff; | |
318 | buf[4] = (x2 >> 0) & 0xff; | |
319 | ||
1ffefe75 | 320 | r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf)); |
f133a9d7 TV |
321 | if (r) |
322 | return r; | |
323 | ||
7a7c48f9 | 324 | buf[0] = MIPI_DCS_SET_PAGE_ADDRESS; |
f133a9d7 TV |
325 | buf[1] = (y1 >> 8) & 0xff; |
326 | buf[2] = (y1 >> 0) & 0xff; | |
327 | buf[3] = (y2 >> 8) & 0xff; | |
328 | buf[4] = (y2 >> 0) & 0xff; | |
329 | ||
1ffefe75 | 330 | r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf)); |
f133a9d7 TV |
331 | if (r) |
332 | return r; | |
333 | ||
1ffefe75 | 334 | dsi_vc_send_bta_sync(td->dssdev, td->channel); |
f133a9d7 TV |
335 | |
336 | return r; | |
337 | } | |
338 | ||
1663d2f7 TV |
339 | static void taal_queue_esd_work(struct omap_dss_device *dssdev) |
340 | { | |
341 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
342 | ||
343 | if (td->esd_interval > 0) | |
883b9ac9 | 344 | queue_delayed_work(td->workqueue, &td->esd_work, |
1663d2f7 TV |
345 | msecs_to_jiffies(td->esd_interval)); |
346 | } | |
347 | ||
348 | static void taal_cancel_esd_work(struct omap_dss_device *dssdev) | |
349 | { | |
350 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
351 | ||
352 | cancel_delayed_work(&td->esd_work); | |
353 | } | |
354 | ||
1abf7814 TV |
355 | static void taal_queue_ulps_work(struct omap_dss_device *dssdev) |
356 | { | |
357 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
358 | ||
359 | if (td->ulps_timeout > 0) | |
360 | queue_delayed_work(td->workqueue, &td->ulps_work, | |
361 | msecs_to_jiffies(td->ulps_timeout)); | |
362 | } | |
363 | ||
364 | static void taal_cancel_ulps_work(struct omap_dss_device *dssdev) | |
365 | { | |
366 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
367 | ||
368 | cancel_delayed_work(&td->ulps_work); | |
369 | } | |
370 | ||
371 | static int taal_enter_ulps(struct omap_dss_device *dssdev) | |
372 | { | |
373 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
374 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); | |
375 | int r; | |
376 | ||
377 | if (td->ulps_enabled) | |
378 | return 0; | |
379 | ||
380 | taal_cancel_ulps_work(dssdev); | |
381 | ||
382 | r = _taal_enable_te(dssdev, false); | |
383 | if (r) | |
384 | goto err; | |
385 | ||
386 | disable_irq(gpio_to_irq(panel_data->ext_te_gpio)); | |
387 | ||
388 | omapdss_dsi_display_disable(dssdev, false, true); | |
389 | ||
390 | td->ulps_enabled = true; | |
391 | ||
392 | return 0; | |
393 | ||
394 | err: | |
395 | dev_err(&dssdev->dev, "enter ULPS failed"); | |
396 | taal_panel_reset(dssdev); | |
397 | ||
398 | td->ulps_enabled = false; | |
399 | ||
400 | taal_queue_ulps_work(dssdev); | |
401 | ||
402 | return r; | |
403 | } | |
404 | ||
405 | static int taal_exit_ulps(struct omap_dss_device *dssdev) | |
406 | { | |
407 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
408 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); | |
409 | int r; | |
410 | ||
411 | if (!td->ulps_enabled) | |
412 | return 0; | |
413 | ||
414 | r = omapdss_dsi_display_enable(dssdev); | |
e8945677 TV |
415 | if (r) { |
416 | dev_err(&dssdev->dev, "failed to enable DSI\n"); | |
417 | goto err1; | |
418 | } | |
1abf7814 | 419 | |
1ffefe75 | 420 | omapdss_dsi_vc_enable_hs(dssdev, td->channel, true); |
1abf7814 TV |
421 | |
422 | r = _taal_enable_te(dssdev, true); | |
e8945677 TV |
423 | if (r) { |
424 | dev_err(&dssdev->dev, "failed to re-enable TE"); | |
425 | goto err2; | |
426 | } | |
1abf7814 TV |
427 | |
428 | enable_irq(gpio_to_irq(panel_data->ext_te_gpio)); | |
429 | ||
430 | taal_queue_ulps_work(dssdev); | |
431 | ||
432 | td->ulps_enabled = false; | |
433 | ||
434 | return 0; | |
435 | ||
e8945677 TV |
436 | err2: |
437 | dev_err(&dssdev->dev, "failed to exit ULPS"); | |
1abf7814 | 438 | |
e8945677 TV |
439 | r = taal_panel_reset(dssdev); |
440 | if (!r) { | |
441 | enable_irq(gpio_to_irq(panel_data->ext_te_gpio)); | |
442 | td->ulps_enabled = false; | |
443 | } | |
444 | err1: | |
1abf7814 TV |
445 | taal_queue_ulps_work(dssdev); |
446 | ||
447 | return r; | |
448 | } | |
449 | ||
450 | static int taal_wake_up(struct omap_dss_device *dssdev) | |
451 | { | |
452 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
453 | ||
454 | if (td->ulps_enabled) | |
455 | return taal_exit_ulps(dssdev); | |
456 | ||
457 | taal_cancel_ulps_work(dssdev); | |
458 | taal_queue_ulps_work(dssdev); | |
459 | return 0; | |
460 | } | |
461 | ||
f133a9d7 TV |
462 | static int taal_bl_update_status(struct backlight_device *dev) |
463 | { | |
464 | struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev); | |
465 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
466 | int r; | |
467 | int level; | |
468 | ||
469 | if (dev->props.fb_blank == FB_BLANK_UNBLANK && | |
470 | dev->props.power == FB_BLANK_UNBLANK) | |
471 | level = dev->props.brightness; | |
472 | else | |
473 | level = 0; | |
474 | ||
475 | dev_dbg(&dssdev->dev, "update brightness to %d\n", level); | |
476 | ||
1cbc8703 TV |
477 | mutex_lock(&td->lock); |
478 | ||
bb36dbfd TV |
479 | if (td->enabled) { |
480 | dsi_bus_lock(dssdev); | |
1abf7814 | 481 | |
bb36dbfd TV |
482 | r = taal_wake_up(dssdev); |
483 | if (!r) | |
484 | r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level); | |
1abf7814 | 485 | |
bb36dbfd | 486 | dsi_bus_unlock(dssdev); |
f133a9d7 | 487 | } else { |
bb36dbfd | 488 | r = 0; |
f133a9d7 TV |
489 | } |
490 | ||
1cbc8703 TV |
491 | mutex_unlock(&td->lock); |
492 | ||
493 | return r; | |
f133a9d7 TV |
494 | } |
495 | ||
496 | static int taal_bl_get_intensity(struct backlight_device *dev) | |
497 | { | |
498 | if (dev->props.fb_blank == FB_BLANK_UNBLANK && | |
499 | dev->props.power == FB_BLANK_UNBLANK) | |
500 | return dev->props.brightness; | |
501 | ||
502 | return 0; | |
503 | } | |
504 | ||
acc2472e | 505 | static const struct backlight_ops taal_bl_ops = { |
f133a9d7 TV |
506 | .get_brightness = taal_bl_get_intensity, |
507 | .update_status = taal_bl_update_status, | |
508 | }; | |
509 | ||
f133a9d7 TV |
510 | static void taal_get_resolution(struct omap_dss_device *dssdev, |
511 | u16 *xres, u16 *yres) | |
512 | { | |
513 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
514 | ||
515 | if (td->rotate == 0 || td->rotate == 2) { | |
516 | *xres = dssdev->panel.timings.x_res; | |
517 | *yres = dssdev->panel.timings.y_res; | |
518 | } else { | |
519 | *yres = dssdev->panel.timings.x_res; | |
520 | *xres = dssdev->panel.timings.y_res; | |
521 | } | |
522 | } | |
523 | ||
f133a9d7 TV |
524 | static ssize_t taal_num_errors_show(struct device *dev, |
525 | struct device_attribute *attr, char *buf) | |
526 | { | |
527 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
528 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
d1700f92 | 529 | u8 errors = 0; |
f133a9d7 TV |
530 | int r; |
531 | ||
6b316715 JN |
532 | mutex_lock(&td->lock); |
533 | ||
f133a9d7 | 534 | if (td->enabled) { |
1ffefe75 | 535 | dsi_bus_lock(dssdev); |
1abf7814 TV |
536 | |
537 | r = taal_wake_up(dssdev); | |
538 | if (!r) | |
539 | r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors); | |
540 | ||
1ffefe75 | 541 | dsi_bus_unlock(dssdev); |
f133a9d7 TV |
542 | } else { |
543 | r = -ENODEV; | |
544 | } | |
545 | ||
6b316715 JN |
546 | mutex_unlock(&td->lock); |
547 | ||
f133a9d7 TV |
548 | if (r) |
549 | return r; | |
550 | ||
551 | return snprintf(buf, PAGE_SIZE, "%d\n", errors); | |
552 | } | |
553 | ||
554 | static ssize_t taal_hw_revision_show(struct device *dev, | |
555 | struct device_attribute *attr, char *buf) | |
556 | { | |
557 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
558 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
559 | u8 id1, id2, id3; | |
560 | int r; | |
561 | ||
6b316715 JN |
562 | mutex_lock(&td->lock); |
563 | ||
f133a9d7 | 564 | if (td->enabled) { |
1ffefe75 | 565 | dsi_bus_lock(dssdev); |
1abf7814 TV |
566 | |
567 | r = taal_wake_up(dssdev); | |
568 | if (!r) | |
569 | r = taal_get_id(td, &id1, &id2, &id3); | |
570 | ||
1ffefe75 | 571 | dsi_bus_unlock(dssdev); |
f133a9d7 TV |
572 | } else { |
573 | r = -ENODEV; | |
574 | } | |
575 | ||
6b316715 JN |
576 | mutex_unlock(&td->lock); |
577 | ||
f133a9d7 TV |
578 | if (r) |
579 | return r; | |
580 | ||
581 | return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3); | |
582 | } | |
583 | ||
584 | static const char *cabc_modes[] = { | |
585 | "off", /* used also always when CABC is not supported */ | |
586 | "ui", | |
587 | "still-image", | |
588 | "moving-image", | |
589 | }; | |
590 | ||
591 | static ssize_t show_cabc_mode(struct device *dev, | |
592 | struct device_attribute *attr, | |
593 | char *buf) | |
594 | { | |
595 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
596 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
597 | const char *mode_str; | |
598 | int mode; | |
599 | int len; | |
600 | ||
601 | mode = td->cabc_mode; | |
602 | ||
603 | mode_str = "unknown"; | |
604 | if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes)) | |
605 | mode_str = cabc_modes[mode]; | |
606 | len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str); | |
607 | ||
608 | return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1; | |
609 | } | |
610 | ||
611 | static ssize_t store_cabc_mode(struct device *dev, | |
612 | struct device_attribute *attr, | |
613 | const char *buf, size_t count) | |
614 | { | |
615 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
616 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
617 | int i; | |
1abf7814 | 618 | int r; |
f133a9d7 TV |
619 | |
620 | for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) { | |
621 | if (sysfs_streq(cabc_modes[i], buf)) | |
622 | break; | |
623 | } | |
624 | ||
625 | if (i == ARRAY_SIZE(cabc_modes)) | |
626 | return -EINVAL; | |
627 | ||
6b316715 JN |
628 | mutex_lock(&td->lock); |
629 | ||
f133a9d7 | 630 | if (td->enabled) { |
1ffefe75 | 631 | dsi_bus_lock(dssdev); |
1abf7814 TV |
632 | |
633 | if (!td->cabc_broken) { | |
634 | r = taal_wake_up(dssdev); | |
635 | if (r) | |
636 | goto err; | |
637 | ||
638 | r = taal_dcs_write_1(td, DCS_WRITE_CABC, i); | |
639 | if (r) | |
640 | goto err; | |
641 | } | |
642 | ||
1ffefe75 | 643 | dsi_bus_unlock(dssdev); |
f133a9d7 TV |
644 | } |
645 | ||
646 | td->cabc_mode = i; | |
647 | ||
6b316715 JN |
648 | mutex_unlock(&td->lock); |
649 | ||
f133a9d7 | 650 | return count; |
1abf7814 | 651 | err: |
1ffefe75 | 652 | dsi_bus_unlock(dssdev); |
1abf7814 TV |
653 | mutex_unlock(&td->lock); |
654 | return r; | |
f133a9d7 TV |
655 | } |
656 | ||
657 | static ssize_t show_cabc_available_modes(struct device *dev, | |
658 | struct device_attribute *attr, | |
659 | char *buf) | |
660 | { | |
661 | int len; | |
662 | int i; | |
663 | ||
664 | for (i = 0, len = 0; | |
665 | len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++) | |
666 | len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s", | |
667 | i ? " " : "", cabc_modes[i], | |
668 | i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : ""); | |
669 | ||
670 | return len < PAGE_SIZE ? len : PAGE_SIZE - 1; | |
671 | } | |
672 | ||
1f8fa452 TV |
673 | static ssize_t taal_store_esd_interval(struct device *dev, |
674 | struct device_attribute *attr, | |
675 | const char *buf, size_t count) | |
676 | { | |
677 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
678 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
679 | ||
680 | unsigned long t; | |
681 | int r; | |
682 | ||
683 | r = strict_strtoul(buf, 10, &t); | |
684 | if (r) | |
685 | return r; | |
686 | ||
687 | mutex_lock(&td->lock); | |
688 | taal_cancel_esd_work(dssdev); | |
689 | td->esd_interval = t; | |
690 | if (td->enabled) | |
691 | taal_queue_esd_work(dssdev); | |
692 | mutex_unlock(&td->lock); | |
693 | ||
694 | return count; | |
695 | } | |
696 | ||
697 | static ssize_t taal_show_esd_interval(struct device *dev, | |
698 | struct device_attribute *attr, | |
699 | char *buf) | |
700 | { | |
701 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
702 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
703 | unsigned t; | |
704 | ||
705 | mutex_lock(&td->lock); | |
706 | t = td->esd_interval; | |
707 | mutex_unlock(&td->lock); | |
708 | ||
709 | return snprintf(buf, PAGE_SIZE, "%u\n", t); | |
710 | } | |
711 | ||
1abf7814 TV |
712 | static ssize_t taal_store_ulps(struct device *dev, |
713 | struct device_attribute *attr, | |
714 | const char *buf, size_t count) | |
715 | { | |
716 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
717 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
718 | unsigned long t; | |
719 | int r; | |
720 | ||
721 | r = strict_strtoul(buf, 10, &t); | |
722 | if (r) | |
723 | return r; | |
724 | ||
725 | mutex_lock(&td->lock); | |
726 | ||
727 | if (td->enabled) { | |
1ffefe75 | 728 | dsi_bus_lock(dssdev); |
1abf7814 TV |
729 | |
730 | if (t) | |
731 | r = taal_enter_ulps(dssdev); | |
732 | else | |
733 | r = taal_wake_up(dssdev); | |
734 | ||
1ffefe75 | 735 | dsi_bus_unlock(dssdev); |
1abf7814 TV |
736 | } |
737 | ||
738 | mutex_unlock(&td->lock); | |
739 | ||
740 | if (r) | |
741 | return r; | |
742 | ||
743 | return count; | |
744 | } | |
745 | ||
746 | static ssize_t taal_show_ulps(struct device *dev, | |
747 | struct device_attribute *attr, | |
748 | char *buf) | |
749 | { | |
750 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
751 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
752 | unsigned t; | |
753 | ||
754 | mutex_lock(&td->lock); | |
755 | t = td->ulps_enabled; | |
756 | mutex_unlock(&td->lock); | |
757 | ||
758 | return snprintf(buf, PAGE_SIZE, "%u\n", t); | |
759 | } | |
760 | ||
761 | static ssize_t taal_store_ulps_timeout(struct device *dev, | |
762 | struct device_attribute *attr, | |
763 | const char *buf, size_t count) | |
764 | { | |
765 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
766 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
767 | unsigned long t; | |
768 | int r; | |
769 | ||
770 | r = strict_strtoul(buf, 10, &t); | |
771 | if (r) | |
772 | return r; | |
773 | ||
774 | mutex_lock(&td->lock); | |
775 | td->ulps_timeout = t; | |
776 | ||
777 | if (td->enabled) { | |
778 | /* taal_wake_up will restart the timer */ | |
1ffefe75 | 779 | dsi_bus_lock(dssdev); |
1abf7814 | 780 | r = taal_wake_up(dssdev); |
1ffefe75 | 781 | dsi_bus_unlock(dssdev); |
1abf7814 TV |
782 | } |
783 | ||
784 | mutex_unlock(&td->lock); | |
785 | ||
786 | if (r) | |
787 | return r; | |
788 | ||
789 | return count; | |
790 | } | |
791 | ||
792 | static ssize_t taal_show_ulps_timeout(struct device *dev, | |
793 | struct device_attribute *attr, | |
794 | char *buf) | |
795 | { | |
796 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
797 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
798 | unsigned t; | |
799 | ||
800 | mutex_lock(&td->lock); | |
801 | t = td->ulps_timeout; | |
802 | mutex_unlock(&td->lock); | |
803 | ||
804 | return snprintf(buf, PAGE_SIZE, "%u\n", t); | |
805 | } | |
806 | ||
f133a9d7 TV |
807 | static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL); |
808 | static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL); | |
809 | static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR, | |
810 | show_cabc_mode, store_cabc_mode); | |
811 | static DEVICE_ATTR(cabc_available_modes, S_IRUGO, | |
812 | show_cabc_available_modes, NULL); | |
1f8fa452 TV |
813 | static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR, |
814 | taal_show_esd_interval, taal_store_esd_interval); | |
1abf7814 TV |
815 | static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR, |
816 | taal_show_ulps, taal_store_ulps); | |
817 | static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR, | |
818 | taal_show_ulps_timeout, taal_store_ulps_timeout); | |
f133a9d7 TV |
819 | |
820 | static struct attribute *taal_attrs[] = { | |
821 | &dev_attr_num_dsi_errors.attr, | |
822 | &dev_attr_hw_revision.attr, | |
823 | &dev_attr_cabc_mode.attr, | |
824 | &dev_attr_cabc_available_modes.attr, | |
1f8fa452 | 825 | &dev_attr_esd_interval.attr, |
1abf7814 TV |
826 | &dev_attr_ulps.attr, |
827 | &dev_attr_ulps_timeout.attr, | |
f133a9d7 TV |
828 | NULL, |
829 | }; | |
830 | ||
831 | static struct attribute_group taal_attr_group = { | |
832 | .attrs = taal_attrs, | |
833 | }; | |
834 | ||
006db7b4 JN |
835 | static void taal_hw_reset(struct omap_dss_device *dssdev) |
836 | { | |
e7f6c3f2 | 837 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
8d3573c8 TV |
838 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
839 | ||
840 | if (panel_data->reset_gpio == -1) | |
006db7b4 JN |
841 | return; |
842 | ||
8d3573c8 | 843 | gpio_set_value(panel_data->reset_gpio, 1); |
e7f6c3f2 JN |
844 | if (td->panel_config->reset_sequence.high) |
845 | udelay(td->panel_config->reset_sequence.high); | |
006db7b4 | 846 | /* reset the panel */ |
8d3573c8 | 847 | gpio_set_value(panel_data->reset_gpio, 0); |
e7f6c3f2 JN |
848 | /* assert reset */ |
849 | if (td->panel_config->reset_sequence.low) | |
850 | udelay(td->panel_config->reset_sequence.low); | |
8d3573c8 | 851 | gpio_set_value(panel_data->reset_gpio, 1); |
e7f6c3f2 JN |
852 | /* wait after releasing reset */ |
853 | if (td->panel_config->sleep.hw_reset) | |
854 | msleep(td->panel_config->sleep.hw_reset); | |
006db7b4 JN |
855 | } |
856 | ||
f133a9d7 TV |
857 | static int taal_probe(struct omap_dss_device *dssdev) |
858 | { | |
a19a6ee6 | 859 | struct backlight_properties props; |
f133a9d7 | 860 | struct taal_data *td; |
bb36dbfd | 861 | struct backlight_device *bldev = NULL; |
8d3573c8 | 862 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
e7f6c3f2 JN |
863 | struct panel_config *panel_config = NULL; |
864 | int r, i; | |
f133a9d7 TV |
865 | |
866 | dev_dbg(&dssdev->dev, "probe\n"); | |
867 | ||
8d3573c8 TV |
868 | if (!panel_data || !panel_data->name) { |
869 | r = -EINVAL; | |
870 | goto err; | |
871 | } | |
872 | ||
e7f6c3f2 JN |
873 | for (i = 0; i < ARRAY_SIZE(panel_configs); i++) { |
874 | if (strcmp(panel_data->name, panel_configs[i].name) == 0) { | |
875 | panel_config = &panel_configs[i]; | |
876 | break; | |
877 | } | |
878 | } | |
879 | ||
880 | if (!panel_config) { | |
881 | r = -EINVAL; | |
882 | goto err; | |
883 | } | |
884 | ||
e7f6c3f2 | 885 | dssdev->panel.timings = panel_config->timings; |
a3b3cc2b | 886 | dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888; |
f133a9d7 TV |
887 | |
888 | td = kzalloc(sizeof(*td), GFP_KERNEL); | |
889 | if (!td) { | |
890 | r = -ENOMEM; | |
d2b65787 | 891 | goto err; |
f133a9d7 TV |
892 | } |
893 | td->dssdev = dssdev; | |
e7f6c3f2 | 894 | td->panel_config = panel_config; |
33a410be | 895 | td->esd_interval = panel_data->esd_interval; |
1abf7814 TV |
896 | td->ulps_enabled = false; |
897 | td->ulps_timeout = panel_data->ulps_timeout; | |
f133a9d7 | 898 | |
a3201a0e TV |
899 | mutex_init(&td->lock); |
900 | ||
7ae2fb11 JN |
901 | atomic_set(&td->do_update, 0); |
902 | ||
883b9ac9 TV |
903 | td->workqueue = create_singlethread_workqueue("taal_esd"); |
904 | if (td->workqueue == NULL) { | |
f133a9d7 TV |
905 | dev_err(&dssdev->dev, "can't create ESD workqueue\n"); |
906 | r = -ENOMEM; | |
d2b65787 | 907 | goto err_wq; |
f133a9d7 | 908 | } |
203b42f7 | 909 | INIT_DEFERRABLE_WORK(&td->esd_work, taal_esd_work); |
1abf7814 | 910 | INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work); |
f133a9d7 TV |
911 | |
912 | dev_set_drvdata(&dssdev->dev, td); | |
913 | ||
3acc797c TV |
914 | if (gpio_is_valid(panel_data->reset_gpio)) { |
915 | r = gpio_request_one(panel_data->reset_gpio, GPIOF_OUT_INIT_LOW, | |
916 | "taal rst"); | |
917 | if (r) { | |
918 | dev_err(&dssdev->dev, "failed to request reset gpio\n"); | |
919 | goto err_rst_gpio; | |
920 | } | |
921 | } | |
922 | ||
006db7b4 JN |
923 | taal_hw_reset(dssdev); |
924 | ||
bb36dbfd TV |
925 | if (panel_data->use_dsi_backlight) { |
926 | memset(&props, 0, sizeof(struct backlight_properties)); | |
a19a6ee6 | 927 | props.max_brightness = 255; |
f133a9d7 | 928 | |
bb36dbfd TV |
929 | props.type = BACKLIGHT_RAW; |
930 | bldev = backlight_device_register(dev_name(&dssdev->dev), | |
931 | &dssdev->dev, dssdev, &taal_bl_ops, &props); | |
932 | if (IS_ERR(bldev)) { | |
933 | r = PTR_ERR(bldev); | |
934 | goto err_bl; | |
935 | } | |
f133a9d7 | 936 | |
bb36dbfd | 937 | td->bldev = bldev; |
f133a9d7 | 938 | |
bb36dbfd TV |
939 | bldev->props.fb_blank = FB_BLANK_UNBLANK; |
940 | bldev->props.power = FB_BLANK_UNBLANK; | |
f133a9d7 | 941 | bldev->props.brightness = 255; |
f133a9d7 | 942 | |
bb36dbfd TV |
943 | taal_bl_update_status(bldev); |
944 | } | |
f133a9d7 | 945 | |
8d3573c8 TV |
946 | if (panel_data->use_ext_te) { |
947 | int gpio = panel_data->ext_te_gpio; | |
f133a9d7 | 948 | |
f8bd4934 | 949 | r = gpio_request_one(gpio, GPIOF_IN, "taal irq"); |
f133a9d7 TV |
950 | if (r) { |
951 | dev_err(&dssdev->dev, "GPIO request failed\n"); | |
d2b65787 | 952 | goto err_gpio; |
f133a9d7 TV |
953 | } |
954 | ||
f133a9d7 | 955 | r = request_irq(gpio_to_irq(gpio), taal_te_isr, |
f8798ccb | 956 | IRQF_TRIGGER_RISING, |
f133a9d7 TV |
957 | "taal vsync", dssdev); |
958 | ||
959 | if (r) { | |
960 | dev_err(&dssdev->dev, "IRQ request failed\n"); | |
961 | gpio_free(gpio); | |
d2b65787 | 962 | goto err_irq; |
f133a9d7 TV |
963 | } |
964 | ||
203b42f7 TH |
965 | INIT_DEFERRABLE_WORK(&td->te_timeout_work, |
966 | taal_te_timeout_work_callback); | |
f133a9d7 | 967 | |
7ae2fb11 | 968 | dev_dbg(&dssdev->dev, "Using GPIO TE\n"); |
f133a9d7 TV |
969 | } |
970 | ||
bc6d4b1d AT |
971 | r = omap_dsi_request_vc(dssdev, &td->channel); |
972 | if (r) { | |
973 | dev_err(&dssdev->dev, "failed to get virtual channel\n"); | |
974 | goto err_req_vc; | |
975 | } | |
976 | ||
977 | r = omap_dsi_set_vc_id(dssdev, td->channel, TCH); | |
978 | if (r) { | |
979 | dev_err(&dssdev->dev, "failed to set VC_ID\n"); | |
980 | goto err_vc_id; | |
981 | } | |
982 | ||
f133a9d7 TV |
983 | r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group); |
984 | if (r) { | |
985 | dev_err(&dssdev->dev, "failed to create sysfs files\n"); | |
bc6d4b1d | 986 | goto err_vc_id; |
f133a9d7 TV |
987 | } |
988 | ||
989 | return 0; | |
bc6d4b1d AT |
990 | |
991 | err_vc_id: | |
992 | omap_dsi_release_vc(dssdev, td->channel); | |
993 | err_req_vc: | |
8d3573c8 TV |
994 | if (panel_data->use_ext_te) |
995 | free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev); | |
d2b65787 | 996 | err_irq: |
8d3573c8 TV |
997 | if (panel_data->use_ext_te) |
998 | gpio_free(panel_data->ext_te_gpio); | |
d2b65787 | 999 | err_gpio: |
bb36dbfd TV |
1000 | if (bldev != NULL) |
1001 | backlight_device_unregister(bldev); | |
d2b65787 | 1002 | err_bl: |
3acc797c TV |
1003 | if (gpio_is_valid(panel_data->reset_gpio)) |
1004 | gpio_free(panel_data->reset_gpio); | |
1005 | err_rst_gpio: | |
883b9ac9 | 1006 | destroy_workqueue(td->workqueue); |
d2b65787 | 1007 | err_wq: |
f133a9d7 | 1008 | kfree(td); |
d2b65787 | 1009 | err: |
f133a9d7 TV |
1010 | return r; |
1011 | } | |
1012 | ||
14e4d784 | 1013 | static void __exit taal_remove(struct omap_dss_device *dssdev) |
f133a9d7 TV |
1014 | { |
1015 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
8d3573c8 | 1016 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
f133a9d7 TV |
1017 | struct backlight_device *bldev; |
1018 | ||
1019 | dev_dbg(&dssdev->dev, "remove\n"); | |
1020 | ||
1021 | sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group); | |
bc6d4b1d | 1022 | omap_dsi_release_vc(dssdev, td->channel); |
f133a9d7 | 1023 | |
8d3573c8 TV |
1024 | if (panel_data->use_ext_te) { |
1025 | int gpio = panel_data->ext_te_gpio; | |
f133a9d7 TV |
1026 | free_irq(gpio_to_irq(gpio), dssdev); |
1027 | gpio_free(gpio); | |
1028 | } | |
1029 | ||
1030 | bldev = td->bldev; | |
bb36dbfd TV |
1031 | if (bldev != NULL) { |
1032 | bldev->props.power = FB_BLANK_POWERDOWN; | |
1033 | taal_bl_update_status(bldev); | |
1034 | backlight_device_unregister(bldev); | |
1035 | } | |
f133a9d7 | 1036 | |
1abf7814 | 1037 | taal_cancel_ulps_work(dssdev); |
1663d2f7 | 1038 | taal_cancel_esd_work(dssdev); |
883b9ac9 | 1039 | destroy_workqueue(td->workqueue); |
f133a9d7 | 1040 | |
006db7b4 JN |
1041 | /* reset, to be sure that the panel is in a valid state */ |
1042 | taal_hw_reset(dssdev); | |
1043 | ||
3acc797c TV |
1044 | if (gpio_is_valid(panel_data->reset_gpio)) |
1045 | gpio_free(panel_data->reset_gpio); | |
1046 | ||
f133a9d7 TV |
1047 | kfree(td); |
1048 | } | |
1049 | ||
37ac60e4 | 1050 | static int taal_power_on(struct omap_dss_device *dssdev) |
f133a9d7 TV |
1051 | { |
1052 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
e4a9e94c | 1053 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
f133a9d7 TV |
1054 | u8 id1, id2, id3; |
1055 | int r; | |
1056 | ||
e4a9e94c TV |
1057 | r = omapdss_dsi_configure_pins(dssdev, &panel_data->pin_config); |
1058 | if (r) { | |
1059 | dev_err(&dssdev->dev, "failed to configure DSI pins\n"); | |
1060 | goto err0; | |
1061 | }; | |
1062 | ||
37ac60e4 TV |
1063 | r = omapdss_dsi_display_enable(dssdev); |
1064 | if (r) { | |
1065 | dev_err(&dssdev->dev, "failed to enable DSI\n"); | |
1066 | goto err0; | |
1067 | } | |
1068 | ||
006db7b4 JN |
1069 | taal_hw_reset(dssdev); |
1070 | ||
1ffefe75 | 1071 | omapdss_dsi_vc_enable_hs(dssdev, td->channel, false); |
37ac60e4 | 1072 | |
f133a9d7 TV |
1073 | r = taal_sleep_out(td); |
1074 | if (r) | |
1075 | goto err; | |
1076 | ||
bc6d4b1d | 1077 | r = taal_get_id(td, &id1, &id2, &id3); |
f133a9d7 TV |
1078 | if (r) |
1079 | goto err; | |
1080 | ||
1e8943db JN |
1081 | /* on early Taal revisions CABC is broken */ |
1082 | if (td->panel_config->type == PANEL_TAAL && | |
1083 | (id2 == 0x00 || id2 == 0xff || id2 == 0x81)) | |
f133a9d7 TV |
1084 | td->cabc_broken = true; |
1085 | ||
bc6d4b1d | 1086 | r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff); |
f2a8b75c JN |
1087 | if (r) |
1088 | goto err; | |
f133a9d7 | 1089 | |
bc6d4b1d | 1090 | r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY, |
f2a8b75c JN |
1091 | (1<<2) | (1<<5)); /* BL | BCTRL */ |
1092 | if (r) | |
1093 | goto err; | |
f133a9d7 | 1094 | |
7a7c48f9 AT |
1095 | r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT, |
1096 | MIPI_DCS_PIXEL_FMT_24BIT); | |
f2a8b75c JN |
1097 | if (r) |
1098 | goto err; | |
f133a9d7 | 1099 | |
bc6d4b1d | 1100 | r = taal_set_addr_mode(td, td->rotate, td->mirror); |
f2a8b75c JN |
1101 | if (r) |
1102 | goto err; | |
1103 | ||
1104 | if (!td->cabc_broken) { | |
bc6d4b1d | 1105 | r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode); |
f2a8b75c JN |
1106 | if (r) |
1107 | goto err; | |
1108 | } | |
1109 | ||
7a7c48f9 | 1110 | r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON); |
f2a8b75c JN |
1111 | if (r) |
1112 | goto err; | |
f133a9d7 | 1113 | |
21df20fc TV |
1114 | r = _taal_enable_te(dssdev, td->te_enabled); |
1115 | if (r) | |
1116 | goto err; | |
1117 | ||
9a147a65 TV |
1118 | r = dsi_enable_video_output(dssdev, td->channel); |
1119 | if (r) | |
1120 | goto err; | |
1121 | ||
f133a9d7 TV |
1122 | td->enabled = 1; |
1123 | ||
1124 | if (!td->intro_printed) { | |
0f45bddf JN |
1125 | dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n", |
1126 | td->panel_config->name, id1, id2, id3); | |
f133a9d7 TV |
1127 | if (td->cabc_broken) |
1128 | dev_info(&dssdev->dev, | |
1129 | "old Taal version, CABC disabled\n"); | |
1130 | td->intro_printed = true; | |
1131 | } | |
1132 | ||
1ffefe75 | 1133 | omapdss_dsi_vc_enable_hs(dssdev, td->channel, true); |
37ac60e4 | 1134 | |
f133a9d7 TV |
1135 | return 0; |
1136 | err: | |
006db7b4 JN |
1137 | dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n"); |
1138 | ||
1139 | taal_hw_reset(dssdev); | |
1140 | ||
22d6d676 | 1141 | omapdss_dsi_display_disable(dssdev, true, false); |
37ac60e4 | 1142 | err0: |
f133a9d7 TV |
1143 | return r; |
1144 | } | |
1145 | ||
37ac60e4 | 1146 | static void taal_power_off(struct omap_dss_device *dssdev) |
f133a9d7 TV |
1147 | { |
1148 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
006db7b4 | 1149 | int r; |
f133a9d7 | 1150 | |
9a147a65 TV |
1151 | dsi_disable_video_output(dssdev, td->channel); |
1152 | ||
7a7c48f9 | 1153 | r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF); |
15ffa1da | 1154 | if (!r) |
006db7b4 | 1155 | r = taal_sleep_in(td); |
f133a9d7 | 1156 | |
006db7b4 JN |
1157 | if (r) { |
1158 | dev_err(&dssdev->dev, | |
1159 | "error disabling panel, issuing HW reset\n"); | |
1160 | taal_hw_reset(dssdev); | |
1161 | } | |
f133a9d7 | 1162 | |
22d6d676 | 1163 | omapdss_dsi_display_disable(dssdev, true, false); |
37ac60e4 | 1164 | |
f133a9d7 | 1165 | td->enabled = 0; |
37ac60e4 TV |
1166 | } |
1167 | ||
bb5476c7 TV |
1168 | static int taal_panel_reset(struct omap_dss_device *dssdev) |
1169 | { | |
1170 | dev_err(&dssdev->dev, "performing LCD reset\n"); | |
1171 | ||
1172 | taal_power_off(dssdev); | |
1173 | taal_hw_reset(dssdev); | |
1174 | return taal_power_on(dssdev); | |
1175 | } | |
1176 | ||
37ac60e4 TV |
1177 | static int taal_enable(struct omap_dss_device *dssdev) |
1178 | { | |
a3201a0e | 1179 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
37ac60e4 | 1180 | int r; |
a3201a0e | 1181 | |
37ac60e4 TV |
1182 | dev_dbg(&dssdev->dev, "enable\n"); |
1183 | ||
a3201a0e TV |
1184 | mutex_lock(&td->lock); |
1185 | ||
1186 | if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) { | |
1187 | r = -EINVAL; | |
1188 | goto err; | |
1189 | } | |
37ac60e4 | 1190 | |
1ffefe75 | 1191 | dsi_bus_lock(dssdev); |
2c2fc151 | 1192 | |
37ac60e4 | 1193 | r = taal_power_on(dssdev); |
2c2fc151 | 1194 | |
1ffefe75 | 1195 | dsi_bus_unlock(dssdev); |
2c2fc151 | 1196 | |
37ac60e4 | 1197 | if (r) |
a3201a0e | 1198 | goto err; |
37ac60e4 | 1199 | |
1663d2f7 | 1200 | taal_queue_esd_work(dssdev); |
4571a023 | 1201 | |
37ac60e4 TV |
1202 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
1203 | ||
a3201a0e TV |
1204 | mutex_unlock(&td->lock); |
1205 | ||
1206 | return 0; | |
1207 | err: | |
1208 | dev_dbg(&dssdev->dev, "enable failed\n"); | |
1209 | mutex_unlock(&td->lock); | |
37ac60e4 TV |
1210 | return r; |
1211 | } | |
1212 | ||
1213 | static void taal_disable(struct omap_dss_device *dssdev) | |
1214 | { | |
a3201a0e TV |
1215 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
1216 | ||
37ac60e4 TV |
1217 | dev_dbg(&dssdev->dev, "disable\n"); |
1218 | ||
a3201a0e TV |
1219 | mutex_lock(&td->lock); |
1220 | ||
1abf7814 | 1221 | taal_cancel_ulps_work(dssdev); |
1663d2f7 | 1222 | taal_cancel_esd_work(dssdev); |
4571a023 | 1223 | |
1ffefe75 | 1224 | dsi_bus_lock(dssdev); |
2c2fc151 | 1225 | |
1abf7814 | 1226 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { |
e8945677 TV |
1227 | int r; |
1228 | ||
1229 | r = taal_wake_up(dssdev); | |
1230 | if (!r) | |
1231 | taal_power_off(dssdev); | |
1abf7814 | 1232 | } |
37ac60e4 | 1233 | |
1ffefe75 | 1234 | dsi_bus_unlock(dssdev); |
2c2fc151 | 1235 | |
37ac60e4 | 1236 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
a3201a0e TV |
1237 | |
1238 | mutex_unlock(&td->lock); | |
f133a9d7 TV |
1239 | } |
1240 | ||
1241 | static int taal_suspend(struct omap_dss_device *dssdev) | |
1242 | { | |
a3201a0e TV |
1243 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
1244 | int r; | |
1245 | ||
37ac60e4 | 1246 | dev_dbg(&dssdev->dev, "suspend\n"); |
f133a9d7 | 1247 | |
a3201a0e TV |
1248 | mutex_lock(&td->lock); |
1249 | ||
1250 | if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) { | |
1251 | r = -EINVAL; | |
1252 | goto err; | |
1253 | } | |
37ac60e4 | 1254 | |
1abf7814 | 1255 | taal_cancel_ulps_work(dssdev); |
1663d2f7 | 1256 | taal_cancel_esd_work(dssdev); |
4571a023 | 1257 | |
1ffefe75 | 1258 | dsi_bus_lock(dssdev); |
2c2fc151 | 1259 | |
1abf7814 TV |
1260 | r = taal_wake_up(dssdev); |
1261 | if (!r) | |
1262 | taal_power_off(dssdev); | |
2c2fc151 | 1263 | |
1ffefe75 | 1264 | dsi_bus_unlock(dssdev); |
2c2fc151 | 1265 | |
37ac60e4 | 1266 | dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED; |
f133a9d7 | 1267 | |
a3201a0e TV |
1268 | mutex_unlock(&td->lock); |
1269 | ||
f133a9d7 | 1270 | return 0; |
a3201a0e TV |
1271 | err: |
1272 | mutex_unlock(&td->lock); | |
1273 | return r; | |
f133a9d7 TV |
1274 | } |
1275 | ||
1276 | static int taal_resume(struct omap_dss_device *dssdev) | |
1277 | { | |
a3201a0e | 1278 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
37ac60e4 | 1279 | int r; |
a3201a0e | 1280 | |
37ac60e4 | 1281 | dev_dbg(&dssdev->dev, "resume\n"); |
f133a9d7 | 1282 | |
a3201a0e TV |
1283 | mutex_lock(&td->lock); |
1284 | ||
1285 | if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) { | |
1286 | r = -EINVAL; | |
1287 | goto err; | |
1288 | } | |
f133a9d7 | 1289 | |
1ffefe75 | 1290 | dsi_bus_lock(dssdev); |
2c2fc151 | 1291 | |
37ac60e4 | 1292 | r = taal_power_on(dssdev); |
2c2fc151 | 1293 | |
1ffefe75 | 1294 | dsi_bus_unlock(dssdev); |
2c2fc151 | 1295 | |
4571a023 | 1296 | if (r) { |
fed44b7a | 1297 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
4571a023 | 1298 | } else { |
fed44b7a | 1299 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
1663d2f7 | 1300 | taal_queue_esd_work(dssdev); |
4571a023 | 1301 | } |
a3201a0e TV |
1302 | |
1303 | mutex_unlock(&td->lock); | |
1304 | ||
1305 | return r; | |
1306 | err: | |
1307 | mutex_unlock(&td->lock); | |
37ac60e4 | 1308 | return r; |
f133a9d7 TV |
1309 | } |
1310 | ||
18946f62 TV |
1311 | static void taal_framedone_cb(int err, void *data) |
1312 | { | |
1313 | struct omap_dss_device *dssdev = data; | |
1314 | dev_dbg(&dssdev->dev, "framedone, err %d\n", err); | |
1ffefe75 | 1315 | dsi_bus_unlock(dssdev); |
18946f62 TV |
1316 | } |
1317 | ||
7ae2fb11 JN |
1318 | static irqreturn_t taal_te_isr(int irq, void *data) |
1319 | { | |
1320 | struct omap_dss_device *dssdev = data; | |
1321 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
1322 | int old; | |
1323 | int r; | |
1324 | ||
1325 | old = atomic_cmpxchg(&td->do_update, 1, 0); | |
1326 | ||
1327 | if (old) { | |
1328 | cancel_delayed_work(&td->te_timeout_work); | |
1329 | ||
5476e74a TV |
1330 | r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb, |
1331 | dssdev); | |
7ae2fb11 JN |
1332 | if (r) |
1333 | goto err; | |
1334 | } | |
1335 | ||
1336 | return IRQ_HANDLED; | |
1337 | err: | |
1338 | dev_err(&dssdev->dev, "start update failed\n"); | |
1ffefe75 | 1339 | dsi_bus_unlock(dssdev); |
7ae2fb11 JN |
1340 | return IRQ_HANDLED; |
1341 | } | |
1342 | ||
1343 | static void taal_te_timeout_work_callback(struct work_struct *work) | |
1344 | { | |
1345 | struct taal_data *td = container_of(work, struct taal_data, | |
1346 | te_timeout_work.work); | |
1347 | struct omap_dss_device *dssdev = td->dssdev; | |
1348 | ||
1349 | dev_err(&dssdev->dev, "TE not received for 250ms!\n"); | |
1350 | ||
1351 | atomic_set(&td->do_update, 0); | |
1ffefe75 | 1352 | dsi_bus_unlock(dssdev); |
7ae2fb11 JN |
1353 | } |
1354 | ||
18946f62 | 1355 | static int taal_update(struct omap_dss_device *dssdev, |
f133a9d7 TV |
1356 | u16 x, u16 y, u16 w, u16 h) |
1357 | { | |
18946f62 | 1358 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
8d3573c8 | 1359 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
18946f62 TV |
1360 | int r; |
1361 | ||
1362 | dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h); | |
1363 | ||
a3201a0e | 1364 | mutex_lock(&td->lock); |
1ffefe75 | 1365 | dsi_bus_lock(dssdev); |
18946f62 | 1366 | |
1abf7814 TV |
1367 | r = taal_wake_up(dssdev); |
1368 | if (r) | |
1369 | goto err; | |
1370 | ||
18946f62 TV |
1371 | if (!td->enabled) { |
1372 | r = 0; | |
1373 | goto err; | |
1374 | } | |
1375 | ||
6331709b TV |
1376 | /* XXX no need to send this every frame, but dsi break if not done */ |
1377 | r = taal_set_update_window(td, 0, 0, | |
1378 | td->panel_config->timings.x_res, | |
1379 | td->panel_config->timings.y_res); | |
18946f62 TV |
1380 | if (r) |
1381 | goto err; | |
1382 | ||
8d3573c8 | 1383 | if (td->te_enabled && panel_data->use_ext_te) { |
7ae2fb11 JN |
1384 | schedule_delayed_work(&td->te_timeout_work, |
1385 | msecs_to_jiffies(250)); | |
1386 | atomic_set(&td->do_update, 1); | |
1387 | } else { | |
5476e74a TV |
1388 | r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb, |
1389 | dssdev); | |
7ae2fb11 JN |
1390 | if (r) |
1391 | goto err; | |
1392 | } | |
18946f62 TV |
1393 | |
1394 | /* note: no bus_unlock here. unlock is in framedone_cb */ | |
a3201a0e | 1395 | mutex_unlock(&td->lock); |
18946f62 TV |
1396 | return 0; |
1397 | err: | |
1ffefe75 | 1398 | dsi_bus_unlock(dssdev); |
a3201a0e | 1399 | mutex_unlock(&td->lock); |
18946f62 TV |
1400 | return r; |
1401 | } | |
1402 | ||
1403 | static int taal_sync(struct omap_dss_device *dssdev) | |
1404 | { | |
a3201a0e TV |
1405 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
1406 | ||
18946f62 TV |
1407 | dev_dbg(&dssdev->dev, "sync\n"); |
1408 | ||
a3201a0e | 1409 | mutex_lock(&td->lock); |
1ffefe75 AT |
1410 | dsi_bus_lock(dssdev); |
1411 | dsi_bus_unlock(dssdev); | |
a3201a0e | 1412 | mutex_unlock(&td->lock); |
18946f62 TV |
1413 | |
1414 | dev_dbg(&dssdev->dev, "sync done\n"); | |
1415 | ||
1416 | return 0; | |
f133a9d7 TV |
1417 | } |
1418 | ||
21df20fc | 1419 | static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable) |
f133a9d7 | 1420 | { |
e7f6c3f2 | 1421 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
8d3573c8 | 1422 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
f133a9d7 TV |
1423 | int r; |
1424 | ||
f133a9d7 | 1425 | if (enable) |
7a7c48f9 | 1426 | r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0); |
f133a9d7 | 1427 | else |
7a7c48f9 | 1428 | r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF); |
f133a9d7 | 1429 | |
8d3573c8 | 1430 | if (!panel_data->use_ext_te) |
7ae2fb11 | 1431 | omapdss_dsi_enable_te(dssdev, enable); |
225b650d | 1432 | |
e7f6c3f2 JN |
1433 | if (td->panel_config->sleep.enable_te) |
1434 | msleep(td->panel_config->sleep.enable_te); | |
225b650d | 1435 | |
21df20fc TV |
1436 | return r; |
1437 | } | |
1438 | ||
1439 | static int taal_enable_te(struct omap_dss_device *dssdev, bool enable) | |
1440 | { | |
a3201a0e | 1441 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
21df20fc TV |
1442 | int r; |
1443 | ||
a3201a0e | 1444 | mutex_lock(&td->lock); |
ffb63c95 TV |
1445 | |
1446 | if (td->te_enabled == enable) | |
1447 | goto end; | |
1448 | ||
1ffefe75 | 1449 | dsi_bus_lock(dssdev); |
21df20fc | 1450 | |
ee52c0ae | 1451 | if (td->enabled) { |
1abf7814 TV |
1452 | r = taal_wake_up(dssdev); |
1453 | if (r) | |
1454 | goto err; | |
1455 | ||
ee52c0ae JN |
1456 | r = _taal_enable_te(dssdev, enable); |
1457 | if (r) | |
1458 | goto err; | |
1459 | } | |
1460 | ||
1461 | td->te_enabled = enable; | |
21df20fc | 1462 | |
1ffefe75 | 1463 | dsi_bus_unlock(dssdev); |
ffb63c95 | 1464 | end: |
a3201a0e | 1465 | mutex_unlock(&td->lock); |
225b650d | 1466 | |
ee52c0ae JN |
1467 | return 0; |
1468 | err: | |
1ffefe75 | 1469 | dsi_bus_unlock(dssdev); |
ee52c0ae JN |
1470 | mutex_unlock(&td->lock); |
1471 | ||
f133a9d7 TV |
1472 | return r; |
1473 | } | |
1474 | ||
225b650d TV |
1475 | static int taal_get_te(struct omap_dss_device *dssdev) |
1476 | { | |
1477 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
a3201a0e TV |
1478 | int r; |
1479 | ||
1480 | mutex_lock(&td->lock); | |
1481 | r = td->te_enabled; | |
1482 | mutex_unlock(&td->lock); | |
1483 | ||
1484 | return r; | |
225b650d TV |
1485 | } |
1486 | ||
f133a9d7 TV |
1487 | static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate) |
1488 | { | |
1489 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
1490 | int r; | |
1491 | ||
1492 | dev_dbg(&dssdev->dev, "rotate %d\n", rotate); | |
1493 | ||
a3201a0e | 1494 | mutex_lock(&td->lock); |
ffb63c95 TV |
1495 | |
1496 | if (td->rotate == rotate) | |
1497 | goto end; | |
1498 | ||
1ffefe75 | 1499 | dsi_bus_lock(dssdev); |
87424e1b | 1500 | |
f133a9d7 | 1501 | if (td->enabled) { |
1abf7814 TV |
1502 | r = taal_wake_up(dssdev); |
1503 | if (r) | |
1504 | goto err; | |
1505 | ||
bc6d4b1d | 1506 | r = taal_set_addr_mode(td, rotate, td->mirror); |
f133a9d7 | 1507 | if (r) |
87424e1b | 1508 | goto err; |
f133a9d7 TV |
1509 | } |
1510 | ||
1511 | td->rotate = rotate; | |
1512 | ||
1ffefe75 | 1513 | dsi_bus_unlock(dssdev); |
ffb63c95 | 1514 | end: |
a3201a0e | 1515 | mutex_unlock(&td->lock); |
f133a9d7 | 1516 | return 0; |
87424e1b | 1517 | err: |
1ffefe75 | 1518 | dsi_bus_unlock(dssdev); |
a3201a0e | 1519 | mutex_unlock(&td->lock); |
87424e1b | 1520 | return r; |
f133a9d7 TV |
1521 | } |
1522 | ||
1523 | static u8 taal_get_rotate(struct omap_dss_device *dssdev) | |
1524 | { | |
1525 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
a3201a0e TV |
1526 | int r; |
1527 | ||
1528 | mutex_lock(&td->lock); | |
1529 | r = td->rotate; | |
1530 | mutex_unlock(&td->lock); | |
1531 | ||
1532 | return r; | |
f133a9d7 TV |
1533 | } |
1534 | ||
1535 | static int taal_mirror(struct omap_dss_device *dssdev, bool enable) | |
1536 | { | |
1537 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
1538 | int r; | |
1539 | ||
1540 | dev_dbg(&dssdev->dev, "mirror %d\n", enable); | |
1541 | ||
a3201a0e | 1542 | mutex_lock(&td->lock); |
ffb63c95 TV |
1543 | |
1544 | if (td->mirror == enable) | |
1545 | goto end; | |
1546 | ||
1ffefe75 | 1547 | dsi_bus_lock(dssdev); |
f133a9d7 | 1548 | if (td->enabled) { |
1abf7814 TV |
1549 | r = taal_wake_up(dssdev); |
1550 | if (r) | |
1551 | goto err; | |
1552 | ||
bc6d4b1d | 1553 | r = taal_set_addr_mode(td, td->rotate, enable); |
f133a9d7 | 1554 | if (r) |
8d8aa61d | 1555 | goto err; |
f133a9d7 TV |
1556 | } |
1557 | ||
1558 | td->mirror = enable; | |
1559 | ||
1ffefe75 | 1560 | dsi_bus_unlock(dssdev); |
ffb63c95 | 1561 | end: |
a3201a0e | 1562 | mutex_unlock(&td->lock); |
f133a9d7 | 1563 | return 0; |
8d8aa61d | 1564 | err: |
1ffefe75 | 1565 | dsi_bus_unlock(dssdev); |
a3201a0e | 1566 | mutex_unlock(&td->lock); |
8d8aa61d | 1567 | return r; |
f133a9d7 TV |
1568 | } |
1569 | ||
1570 | static bool taal_get_mirror(struct omap_dss_device *dssdev) | |
1571 | { | |
1572 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
a3201a0e TV |
1573 | int r; |
1574 | ||
1575 | mutex_lock(&td->lock); | |
1576 | r = td->mirror; | |
1577 | mutex_unlock(&td->lock); | |
1578 | ||
1579 | return r; | |
f133a9d7 TV |
1580 | } |
1581 | ||
1582 | static int taal_run_test(struct omap_dss_device *dssdev, int test_num) | |
1583 | { | |
a3201a0e | 1584 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
f133a9d7 TV |
1585 | u8 id1, id2, id3; |
1586 | int r; | |
1587 | ||
a3201a0e | 1588 | mutex_lock(&td->lock); |
ee52c0ae JN |
1589 | |
1590 | if (!td->enabled) { | |
1591 | r = -ENODEV; | |
1592 | goto err1; | |
1593 | } | |
1594 | ||
1ffefe75 | 1595 | dsi_bus_lock(dssdev); |
1a75ef42 | 1596 | |
1abf7814 TV |
1597 | r = taal_wake_up(dssdev); |
1598 | if (r) | |
1599 | goto err2; | |
1600 | ||
bc6d4b1d | 1601 | r = taal_dcs_read_1(td, DCS_GET_ID1, &id1); |
f133a9d7 | 1602 | if (r) |
ee52c0ae | 1603 | goto err2; |
bc6d4b1d | 1604 | r = taal_dcs_read_1(td, DCS_GET_ID2, &id2); |
f133a9d7 | 1605 | if (r) |
ee52c0ae | 1606 | goto err2; |
bc6d4b1d | 1607 | r = taal_dcs_read_1(td, DCS_GET_ID3, &id3); |
f133a9d7 | 1608 | if (r) |
ee52c0ae | 1609 | goto err2; |
f133a9d7 | 1610 | |
1ffefe75 | 1611 | dsi_bus_unlock(dssdev); |
a3201a0e | 1612 | mutex_unlock(&td->lock); |
f133a9d7 | 1613 | return 0; |
ee52c0ae | 1614 | err2: |
1ffefe75 | 1615 | dsi_bus_unlock(dssdev); |
ee52c0ae | 1616 | err1: |
a3201a0e | 1617 | mutex_unlock(&td->lock); |
1a75ef42 | 1618 | return r; |
f133a9d7 TV |
1619 | } |
1620 | ||
1621 | static int taal_memory_read(struct omap_dss_device *dssdev, | |
1622 | void *buf, size_t size, | |
1623 | u16 x, u16 y, u16 w, u16 h) | |
1624 | { | |
1625 | int r; | |
1626 | int first = 1; | |
1627 | int plen; | |
1628 | unsigned buf_used = 0; | |
c75d9464 TV |
1629 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
1630 | ||
f133a9d7 TV |
1631 | if (size < w * h * 3) |
1632 | return -ENOMEM; | |
1633 | ||
a3201a0e TV |
1634 | mutex_lock(&td->lock); |
1635 | ||
1636 | if (!td->enabled) { | |
1637 | r = -ENODEV; | |
1638 | goto err1; | |
1639 | } | |
1640 | ||
f133a9d7 TV |
1641 | size = min(w * h * 3, |
1642 | dssdev->panel.timings.x_res * | |
1643 | dssdev->panel.timings.y_res * 3); | |
1644 | ||
1ffefe75 | 1645 | dsi_bus_lock(dssdev); |
c75d9464 | 1646 | |
1abf7814 TV |
1647 | r = taal_wake_up(dssdev); |
1648 | if (r) | |
1649 | goto err2; | |
1650 | ||
f133a9d7 TV |
1651 | /* plen 1 or 2 goes into short packet. until checksum error is fixed, |
1652 | * use short packets. plen 32 works, but bigger packets seem to cause | |
1653 | * an error. */ | |
1654 | if (size % 2) | |
1655 | plen = 1; | |
1656 | else | |
1657 | plen = 2; | |
1658 | ||
bc6d4b1d | 1659 | taal_set_update_window(td, x, y, w, h); |
f133a9d7 | 1660 | |
1ffefe75 | 1661 | r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen); |
f133a9d7 | 1662 | if (r) |
a3201a0e | 1663 | goto err2; |
f133a9d7 TV |
1664 | |
1665 | while (buf_used < size) { | |
1666 | u8 dcs_cmd = first ? 0x2e : 0x3e; | |
1667 | first = 0; | |
1668 | ||
1ffefe75 | 1669 | r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd, |
f133a9d7 TV |
1670 | buf + buf_used, size - buf_used); |
1671 | ||
1672 | if (r < 0) { | |
1673 | dev_err(&dssdev->dev, "read error\n"); | |
a3201a0e | 1674 | goto err3; |
f133a9d7 TV |
1675 | } |
1676 | ||
1677 | buf_used += r; | |
1678 | ||
1679 | if (r < plen) { | |
1680 | dev_err(&dssdev->dev, "short read\n"); | |
1681 | break; | |
1682 | } | |
1683 | ||
1684 | if (signal_pending(current)) { | |
1685 | dev_err(&dssdev->dev, "signal pending, " | |
1686 | "aborting memory read\n"); | |
1687 | r = -ERESTARTSYS; | |
a3201a0e | 1688 | goto err3; |
f133a9d7 TV |
1689 | } |
1690 | } | |
1691 | ||
1692 | r = buf_used; | |
1693 | ||
a3201a0e | 1694 | err3: |
1ffefe75 | 1695 | dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1); |
a3201a0e | 1696 | err2: |
1ffefe75 | 1697 | dsi_bus_unlock(dssdev); |
a3201a0e TV |
1698 | err1: |
1699 | mutex_unlock(&td->lock); | |
f133a9d7 TV |
1700 | return r; |
1701 | } | |
1702 | ||
1abf7814 TV |
1703 | static void taal_ulps_work(struct work_struct *work) |
1704 | { | |
1705 | struct taal_data *td = container_of(work, struct taal_data, | |
1706 | ulps_work.work); | |
1707 | struct omap_dss_device *dssdev = td->dssdev; | |
1708 | ||
1709 | mutex_lock(&td->lock); | |
1710 | ||
1711 | if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) { | |
1712 | mutex_unlock(&td->lock); | |
1713 | return; | |
1714 | } | |
1715 | ||
1ffefe75 | 1716 | dsi_bus_lock(dssdev); |
1abf7814 TV |
1717 | |
1718 | taal_enter_ulps(dssdev); | |
1719 | ||
1ffefe75 | 1720 | dsi_bus_unlock(dssdev); |
1abf7814 TV |
1721 | mutex_unlock(&td->lock); |
1722 | } | |
1723 | ||
f133a9d7 TV |
1724 | static void taal_esd_work(struct work_struct *work) |
1725 | { | |
1726 | struct taal_data *td = container_of(work, struct taal_data, | |
1727 | esd_work.work); | |
1728 | struct omap_dss_device *dssdev = td->dssdev; | |
8d3573c8 | 1729 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
f133a9d7 TV |
1730 | u8 state1, state2; |
1731 | int r; | |
1732 | ||
a3201a0e TV |
1733 | mutex_lock(&td->lock); |
1734 | ||
1735 | if (!td->enabled) { | |
1736 | mutex_unlock(&td->lock); | |
f133a9d7 | 1737 | return; |
a3201a0e | 1738 | } |
f133a9d7 | 1739 | |
1ffefe75 | 1740 | dsi_bus_lock(dssdev); |
f133a9d7 | 1741 | |
1abf7814 TV |
1742 | r = taal_wake_up(dssdev); |
1743 | if (r) { | |
1744 | dev_err(&dssdev->dev, "failed to exit ULPS\n"); | |
1745 | goto err; | |
1746 | } | |
1747 | ||
7a7c48f9 | 1748 | r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1); |
f133a9d7 TV |
1749 | if (r) { |
1750 | dev_err(&dssdev->dev, "failed to read Taal status\n"); | |
1751 | goto err; | |
1752 | } | |
1753 | ||
1754 | /* Run self diagnostics */ | |
1755 | r = taal_sleep_out(td); | |
1756 | if (r) { | |
1757 | dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n"); | |
1758 | goto err; | |
1759 | } | |
1760 | ||
7a7c48f9 | 1761 | r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2); |
f133a9d7 TV |
1762 | if (r) { |
1763 | dev_err(&dssdev->dev, "failed to read Taal status\n"); | |
1764 | goto err; | |
1765 | } | |
1766 | ||
1767 | /* Each sleep out command will trigger a self diagnostic and flip | |
1768 | * Bit6 if the test passes. | |
1769 | */ | |
1770 | if (!((state1 ^ state2) & (1 << 6))) { | |
1771 | dev_err(&dssdev->dev, "LCD self diagnostics failed\n"); | |
1772 | goto err; | |
1773 | } | |
1774 | /* Self-diagnostics result is also shown on TE GPIO line. We need | |
1775 | * to re-enable TE after self diagnostics */ | |
8d3573c8 | 1776 | if (td->te_enabled && panel_data->use_ext_te) { |
7a7c48f9 | 1777 | r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0); |
1189b7ff TV |
1778 | if (r) |
1779 | goto err; | |
1780 | } | |
f133a9d7 | 1781 | |
1ffefe75 | 1782 | dsi_bus_unlock(dssdev); |
f133a9d7 | 1783 | |
1663d2f7 | 1784 | taal_queue_esd_work(dssdev); |
f133a9d7 | 1785 | |
a3201a0e | 1786 | mutex_unlock(&td->lock); |
f133a9d7 TV |
1787 | return; |
1788 | err: | |
1789 | dev_err(&dssdev->dev, "performing LCD reset\n"); | |
1790 | ||
bb5476c7 | 1791 | taal_panel_reset(dssdev); |
f133a9d7 | 1792 | |
1ffefe75 | 1793 | dsi_bus_unlock(dssdev); |
f133a9d7 | 1794 | |
1663d2f7 | 1795 | taal_queue_esd_work(dssdev); |
a3201a0e TV |
1796 | |
1797 | mutex_unlock(&td->lock); | |
f133a9d7 TV |
1798 | } |
1799 | ||
1800 | static struct omap_dss_driver taal_driver = { | |
1801 | .probe = taal_probe, | |
14e4d784 | 1802 | .remove = __exit_p(taal_remove), |
f133a9d7 TV |
1803 | |
1804 | .enable = taal_enable, | |
1805 | .disable = taal_disable, | |
1806 | .suspend = taal_suspend, | |
1807 | .resume = taal_resume, | |
1808 | ||
18946f62 TV |
1809 | .update = taal_update, |
1810 | .sync = taal_sync, | |
1811 | ||
96adcece | 1812 | .get_resolution = taal_get_resolution, |
a2699504 TV |
1813 | .get_recommended_bpp = omapdss_default_get_recommended_bpp, |
1814 | ||
f133a9d7 | 1815 | .enable_te = taal_enable_te, |
225b650d | 1816 | .get_te = taal_get_te, |
225b650d | 1817 | |
f133a9d7 TV |
1818 | .set_rotate = taal_rotate, |
1819 | .get_rotate = taal_get_rotate, | |
1820 | .set_mirror = taal_mirror, | |
1821 | .get_mirror = taal_get_mirror, | |
1822 | .run_test = taal_run_test, | |
1823 | .memory_read = taal_memory_read, | |
1824 | ||
1825 | .driver = { | |
1826 | .name = "taal", | |
1827 | .owner = THIS_MODULE, | |
1828 | }, | |
1829 | }; | |
1830 | ||
1831 | static int __init taal_init(void) | |
1832 | { | |
1833 | omap_dss_register_driver(&taal_driver); | |
1834 | ||
1835 | return 0; | |
1836 | } | |
1837 | ||
1838 | static void __exit taal_exit(void) | |
1839 | { | |
1840 | omap_dss_unregister_driver(&taal_driver); | |
1841 | } | |
1842 | ||
1843 | module_init(taal_init); | |
1844 | module_exit(taal_exit); | |
1845 | ||
1846 | MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>"); | |
1847 | MODULE_DESCRIPTION("Taal Driver"); | |
1848 | MODULE_LICENSE("GPL"); |