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> | |
31 | #include <linux/completion.h> | |
32 | #include <linux/workqueue.h> | |
5a0e3ad6 | 33 | #include <linux/slab.h> |
a3201a0e | 34 | #include <linux/mutex.h> |
f133a9d7 TV |
35 | |
36 | #include <plat/display.h> | |
37 | ||
38 | /* DSI Virtual channel. Hardcoded for now. */ | |
39 | #define TCH 0 | |
40 | ||
41 | #define DCS_READ_NUM_ERRORS 0x05 | |
42 | #define DCS_READ_POWER_MODE 0x0a | |
43 | #define DCS_READ_MADCTL 0x0b | |
44 | #define DCS_READ_PIXEL_FORMAT 0x0c | |
45 | #define DCS_RDDSDR 0x0f | |
46 | #define DCS_SLEEP_IN 0x10 | |
47 | #define DCS_SLEEP_OUT 0x11 | |
48 | #define DCS_DISPLAY_OFF 0x28 | |
49 | #define DCS_DISPLAY_ON 0x29 | |
50 | #define DCS_COLUMN_ADDR 0x2a | |
51 | #define DCS_PAGE_ADDR 0x2b | |
52 | #define DCS_MEMORY_WRITE 0x2c | |
53 | #define DCS_TEAR_OFF 0x34 | |
54 | #define DCS_TEAR_ON 0x35 | |
55 | #define DCS_MEM_ACC_CTRL 0x36 | |
56 | #define DCS_PIXEL_FORMAT 0x3a | |
57 | #define DCS_BRIGHTNESS 0x51 | |
58 | #define DCS_CTRL_DISPLAY 0x53 | |
59 | #define DCS_WRITE_CABC 0x55 | |
60 | #define DCS_READ_CABC 0x56 | |
61 | #define DCS_GET_ID1 0xda | |
62 | #define DCS_GET_ID2 0xdb | |
63 | #define DCS_GET_ID3 0xdc | |
64 | ||
65 | /* #define TAAL_USE_ESD_CHECK */ | |
66 | #define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000) | |
67 | ||
21df20fc TV |
68 | static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable); |
69 | ||
f133a9d7 | 70 | struct taal_data { |
a3201a0e TV |
71 | struct mutex lock; |
72 | ||
f133a9d7 TV |
73 | struct backlight_device *bldev; |
74 | ||
75 | unsigned long hw_guard_end; /* next value of jiffies when we can | |
76 | * issue the next sleep in/out command | |
77 | */ | |
78 | unsigned long hw_guard_wait; /* max guard time in jiffies */ | |
79 | ||
80 | struct omap_dss_device *dssdev; | |
81 | ||
82 | bool enabled; | |
83 | u8 rotate; | |
84 | bool mirror; | |
85 | ||
86 | bool te_enabled; | |
87 | bool use_ext_te; | |
88 | struct completion te_completion; | |
89 | ||
90 | bool use_dsi_bl; | |
91 | ||
92 | bool cabc_broken; | |
93 | unsigned cabc_mode; | |
94 | ||
95 | bool intro_printed; | |
96 | ||
97 | struct workqueue_struct *esd_wq; | |
98 | struct delayed_work esd_work; | |
99 | }; | |
100 | ||
101 | static void taal_esd_work(struct work_struct *work); | |
102 | ||
103 | static void hw_guard_start(struct taal_data *td, int guard_msec) | |
104 | { | |
105 | td->hw_guard_wait = msecs_to_jiffies(guard_msec); | |
106 | td->hw_guard_end = jiffies + td->hw_guard_wait; | |
107 | } | |
108 | ||
109 | static void hw_guard_wait(struct taal_data *td) | |
110 | { | |
111 | unsigned long wait = td->hw_guard_end - jiffies; | |
112 | ||
113 | if ((long)wait > 0 && wait <= td->hw_guard_wait) { | |
114 | set_current_state(TASK_UNINTERRUPTIBLE); | |
115 | schedule_timeout(wait); | |
116 | } | |
117 | } | |
118 | ||
119 | static int taal_dcs_read_1(u8 dcs_cmd, u8 *data) | |
120 | { | |
121 | int r; | |
122 | u8 buf[1]; | |
123 | ||
124 | r = dsi_vc_dcs_read(TCH, dcs_cmd, buf, 1); | |
125 | ||
126 | if (r < 0) | |
127 | return r; | |
128 | ||
129 | *data = buf[0]; | |
130 | ||
131 | return 0; | |
132 | } | |
133 | ||
134 | static int taal_dcs_write_0(u8 dcs_cmd) | |
135 | { | |
136 | return dsi_vc_dcs_write(TCH, &dcs_cmd, 1); | |
137 | } | |
138 | ||
139 | static int taal_dcs_write_1(u8 dcs_cmd, u8 param) | |
140 | { | |
141 | u8 buf[2]; | |
142 | buf[0] = dcs_cmd; | |
143 | buf[1] = param; | |
144 | return dsi_vc_dcs_write(TCH, buf, 2); | |
145 | } | |
146 | ||
147 | static int taal_sleep_in(struct taal_data *td) | |
148 | ||
149 | { | |
150 | u8 cmd; | |
151 | int r; | |
152 | ||
153 | hw_guard_wait(td); | |
154 | ||
155 | cmd = DCS_SLEEP_IN; | |
156 | r = dsi_vc_dcs_write_nosync(TCH, &cmd, 1); | |
157 | if (r) | |
158 | return r; | |
159 | ||
160 | hw_guard_start(td, 120); | |
161 | ||
162 | msleep(5); | |
163 | ||
164 | return 0; | |
165 | } | |
166 | ||
167 | static int taal_sleep_out(struct taal_data *td) | |
168 | { | |
169 | int r; | |
170 | ||
171 | hw_guard_wait(td); | |
172 | ||
173 | r = taal_dcs_write_0(DCS_SLEEP_OUT); | |
174 | if (r) | |
175 | return r; | |
176 | ||
177 | hw_guard_start(td, 120); | |
178 | ||
179 | msleep(5); | |
180 | ||
181 | return 0; | |
182 | } | |
183 | ||
184 | static int taal_get_id(u8 *id1, u8 *id2, u8 *id3) | |
185 | { | |
186 | int r; | |
187 | ||
188 | r = taal_dcs_read_1(DCS_GET_ID1, id1); | |
189 | if (r) | |
190 | return r; | |
191 | r = taal_dcs_read_1(DCS_GET_ID2, id2); | |
192 | if (r) | |
193 | return r; | |
194 | r = taal_dcs_read_1(DCS_GET_ID3, id3); | |
195 | if (r) | |
196 | return r; | |
197 | ||
198 | return 0; | |
199 | } | |
200 | ||
201 | static int taal_set_addr_mode(u8 rotate, bool mirror) | |
202 | { | |
203 | int r; | |
204 | u8 mode; | |
205 | int b5, b6, b7; | |
206 | ||
207 | r = taal_dcs_read_1(DCS_READ_MADCTL, &mode); | |
208 | if (r) | |
209 | return r; | |
210 | ||
211 | switch (rotate) { | |
212 | default: | |
213 | case 0: | |
214 | b7 = 0; | |
215 | b6 = 0; | |
216 | b5 = 0; | |
217 | break; | |
218 | case 1: | |
219 | b7 = 0; | |
220 | b6 = 1; | |
221 | b5 = 1; | |
222 | break; | |
223 | case 2: | |
224 | b7 = 1; | |
225 | b6 = 1; | |
226 | b5 = 0; | |
227 | break; | |
228 | case 3: | |
229 | b7 = 1; | |
230 | b6 = 0; | |
231 | b5 = 1; | |
232 | break; | |
233 | } | |
234 | ||
235 | if (mirror) | |
236 | b6 = !b6; | |
237 | ||
238 | mode &= ~((1<<7) | (1<<6) | (1<<5)); | |
239 | mode |= (b7 << 7) | (b6 << 6) | (b5 << 5); | |
240 | ||
241 | return taal_dcs_write_1(DCS_MEM_ACC_CTRL, mode); | |
242 | } | |
243 | ||
244 | static int taal_set_update_window(u16 x, u16 y, u16 w, u16 h) | |
245 | { | |
246 | int r; | |
247 | u16 x1 = x; | |
248 | u16 x2 = x + w - 1; | |
249 | u16 y1 = y; | |
250 | u16 y2 = y + h - 1; | |
251 | ||
252 | u8 buf[5]; | |
253 | buf[0] = DCS_COLUMN_ADDR; | |
254 | buf[1] = (x1 >> 8) & 0xff; | |
255 | buf[2] = (x1 >> 0) & 0xff; | |
256 | buf[3] = (x2 >> 8) & 0xff; | |
257 | buf[4] = (x2 >> 0) & 0xff; | |
258 | ||
259 | r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf)); | |
260 | if (r) | |
261 | return r; | |
262 | ||
263 | buf[0] = DCS_PAGE_ADDR; | |
264 | buf[1] = (y1 >> 8) & 0xff; | |
265 | buf[2] = (y1 >> 0) & 0xff; | |
266 | buf[3] = (y2 >> 8) & 0xff; | |
267 | buf[4] = (y2 >> 0) & 0xff; | |
268 | ||
269 | r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf)); | |
270 | if (r) | |
271 | return r; | |
272 | ||
273 | dsi_vc_send_bta_sync(TCH); | |
274 | ||
275 | return r; | |
276 | } | |
277 | ||
278 | static int taal_bl_update_status(struct backlight_device *dev) | |
279 | { | |
280 | struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev); | |
281 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
282 | int r; | |
283 | int level; | |
284 | ||
285 | if (dev->props.fb_blank == FB_BLANK_UNBLANK && | |
286 | dev->props.power == FB_BLANK_UNBLANK) | |
287 | level = dev->props.brightness; | |
288 | else | |
289 | level = 0; | |
290 | ||
291 | dev_dbg(&dssdev->dev, "update brightness to %d\n", level); | |
292 | ||
1cbc8703 TV |
293 | mutex_lock(&td->lock); |
294 | ||
f133a9d7 TV |
295 | if (td->use_dsi_bl) { |
296 | if (td->enabled) { | |
297 | dsi_bus_lock(); | |
298 | r = taal_dcs_write_1(DCS_BRIGHTNESS, level); | |
299 | dsi_bus_unlock(); | |
1cbc8703 TV |
300 | } else { |
301 | r = 0; | |
f133a9d7 TV |
302 | } |
303 | } else { | |
304 | if (!dssdev->set_backlight) | |
1cbc8703 TV |
305 | r = -EINVAL; |
306 | else | |
307 | r = dssdev->set_backlight(dssdev, level); | |
f133a9d7 TV |
308 | } |
309 | ||
1cbc8703 TV |
310 | mutex_unlock(&td->lock); |
311 | ||
312 | return r; | |
f133a9d7 TV |
313 | } |
314 | ||
315 | static int taal_bl_get_intensity(struct backlight_device *dev) | |
316 | { | |
317 | if (dev->props.fb_blank == FB_BLANK_UNBLANK && | |
318 | dev->props.power == FB_BLANK_UNBLANK) | |
319 | return dev->props.brightness; | |
320 | ||
321 | return 0; | |
322 | } | |
323 | ||
324 | static struct backlight_ops taal_bl_ops = { | |
325 | .get_brightness = taal_bl_get_intensity, | |
326 | .update_status = taal_bl_update_status, | |
327 | }; | |
328 | ||
329 | static void taal_get_timings(struct omap_dss_device *dssdev, | |
330 | struct omap_video_timings *timings) | |
331 | { | |
332 | *timings = dssdev->panel.timings; | |
333 | } | |
334 | ||
335 | static void taal_get_resolution(struct omap_dss_device *dssdev, | |
336 | u16 *xres, u16 *yres) | |
337 | { | |
338 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
339 | ||
340 | if (td->rotate == 0 || td->rotate == 2) { | |
341 | *xres = dssdev->panel.timings.x_res; | |
342 | *yres = dssdev->panel.timings.y_res; | |
343 | } else { | |
344 | *yres = dssdev->panel.timings.x_res; | |
345 | *xres = dssdev->panel.timings.y_res; | |
346 | } | |
347 | } | |
348 | ||
349 | static irqreturn_t taal_te_isr(int irq, void *data) | |
350 | { | |
351 | struct omap_dss_device *dssdev = data; | |
352 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
353 | ||
354 | complete_all(&td->te_completion); | |
355 | ||
356 | return IRQ_HANDLED; | |
357 | } | |
358 | ||
359 | static ssize_t taal_num_errors_show(struct device *dev, | |
360 | struct device_attribute *attr, char *buf) | |
361 | { | |
362 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
363 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
364 | u8 errors; | |
365 | int r; | |
366 | ||
6b316715 JN |
367 | mutex_lock(&td->lock); |
368 | ||
f133a9d7 TV |
369 | if (td->enabled) { |
370 | dsi_bus_lock(); | |
371 | r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors); | |
372 | dsi_bus_unlock(); | |
373 | } else { | |
374 | r = -ENODEV; | |
375 | } | |
376 | ||
6b316715 JN |
377 | mutex_unlock(&td->lock); |
378 | ||
f133a9d7 TV |
379 | if (r) |
380 | return r; | |
381 | ||
382 | return snprintf(buf, PAGE_SIZE, "%d\n", errors); | |
383 | } | |
384 | ||
385 | static ssize_t taal_hw_revision_show(struct device *dev, | |
386 | struct device_attribute *attr, char *buf) | |
387 | { | |
388 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
389 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
390 | u8 id1, id2, id3; | |
391 | int r; | |
392 | ||
6b316715 JN |
393 | mutex_lock(&td->lock); |
394 | ||
f133a9d7 TV |
395 | if (td->enabled) { |
396 | dsi_bus_lock(); | |
397 | r = taal_get_id(&id1, &id2, &id3); | |
398 | dsi_bus_unlock(); | |
399 | } else { | |
400 | r = -ENODEV; | |
401 | } | |
402 | ||
6b316715 JN |
403 | mutex_unlock(&td->lock); |
404 | ||
f133a9d7 TV |
405 | if (r) |
406 | return r; | |
407 | ||
408 | return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3); | |
409 | } | |
410 | ||
411 | static const char *cabc_modes[] = { | |
412 | "off", /* used also always when CABC is not supported */ | |
413 | "ui", | |
414 | "still-image", | |
415 | "moving-image", | |
416 | }; | |
417 | ||
418 | static ssize_t show_cabc_mode(struct device *dev, | |
419 | struct device_attribute *attr, | |
420 | char *buf) | |
421 | { | |
422 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
423 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
424 | const char *mode_str; | |
425 | int mode; | |
426 | int len; | |
427 | ||
428 | mode = td->cabc_mode; | |
429 | ||
430 | mode_str = "unknown"; | |
431 | if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes)) | |
432 | mode_str = cabc_modes[mode]; | |
433 | len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str); | |
434 | ||
435 | return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1; | |
436 | } | |
437 | ||
438 | static ssize_t store_cabc_mode(struct device *dev, | |
439 | struct device_attribute *attr, | |
440 | const char *buf, size_t count) | |
441 | { | |
442 | struct omap_dss_device *dssdev = to_dss_device(dev); | |
443 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
444 | int i; | |
445 | ||
446 | for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) { | |
447 | if (sysfs_streq(cabc_modes[i], buf)) | |
448 | break; | |
449 | } | |
450 | ||
451 | if (i == ARRAY_SIZE(cabc_modes)) | |
452 | return -EINVAL; | |
453 | ||
6b316715 JN |
454 | mutex_lock(&td->lock); |
455 | ||
f133a9d7 TV |
456 | if (td->enabled) { |
457 | dsi_bus_lock(); | |
458 | if (!td->cabc_broken) | |
459 | taal_dcs_write_1(DCS_WRITE_CABC, i); | |
460 | dsi_bus_unlock(); | |
461 | } | |
462 | ||
463 | td->cabc_mode = i; | |
464 | ||
6b316715 JN |
465 | mutex_unlock(&td->lock); |
466 | ||
f133a9d7 TV |
467 | return count; |
468 | } | |
469 | ||
470 | static ssize_t show_cabc_available_modes(struct device *dev, | |
471 | struct device_attribute *attr, | |
472 | char *buf) | |
473 | { | |
474 | int len; | |
475 | int i; | |
476 | ||
477 | for (i = 0, len = 0; | |
478 | len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++) | |
479 | len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s", | |
480 | i ? " " : "", cabc_modes[i], | |
481 | i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : ""); | |
482 | ||
483 | return len < PAGE_SIZE ? len : PAGE_SIZE - 1; | |
484 | } | |
485 | ||
486 | static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL); | |
487 | static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL); | |
488 | static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR, | |
489 | show_cabc_mode, store_cabc_mode); | |
490 | static DEVICE_ATTR(cabc_available_modes, S_IRUGO, | |
491 | show_cabc_available_modes, NULL); | |
492 | ||
493 | static struct attribute *taal_attrs[] = { | |
494 | &dev_attr_num_dsi_errors.attr, | |
495 | &dev_attr_hw_revision.attr, | |
496 | &dev_attr_cabc_mode.attr, | |
497 | &dev_attr_cabc_available_modes.attr, | |
498 | NULL, | |
499 | }; | |
500 | ||
501 | static struct attribute_group taal_attr_group = { | |
502 | .attrs = taal_attrs, | |
503 | }; | |
504 | ||
006db7b4 JN |
505 | static void taal_hw_reset(struct omap_dss_device *dssdev) |
506 | { | |
507 | if (dssdev->reset_gpio == -1) | |
508 | return; | |
509 | ||
510 | gpio_set_value(dssdev->reset_gpio, 1); | |
511 | udelay(10); | |
512 | /* reset the panel */ | |
513 | gpio_set_value(dssdev->reset_gpio, 0); | |
514 | /* assert reset for at least 10us */ | |
515 | udelay(10); | |
516 | gpio_set_value(dssdev->reset_gpio, 1); | |
517 | /* wait 5ms after releasing reset */ | |
518 | msleep(5); | |
519 | } | |
520 | ||
f133a9d7 TV |
521 | static int taal_probe(struct omap_dss_device *dssdev) |
522 | { | |
a19a6ee6 | 523 | struct backlight_properties props; |
f133a9d7 TV |
524 | struct taal_data *td; |
525 | struct backlight_device *bldev; | |
526 | int r; | |
527 | ||
528 | const struct omap_video_timings taal_panel_timings = { | |
529 | .x_res = 864, | |
530 | .y_res = 480, | |
531 | }; | |
532 | ||
533 | dev_dbg(&dssdev->dev, "probe\n"); | |
534 | ||
535 | dssdev->panel.config = OMAP_DSS_LCD_TFT; | |
536 | dssdev->panel.timings = taal_panel_timings; | |
537 | dssdev->ctrl.pixel_size = 24; | |
538 | ||
539 | td = kzalloc(sizeof(*td), GFP_KERNEL); | |
540 | if (!td) { | |
541 | r = -ENOMEM; | |
542 | goto err0; | |
543 | } | |
544 | td->dssdev = dssdev; | |
545 | ||
a3201a0e TV |
546 | mutex_init(&td->lock); |
547 | ||
f133a9d7 TV |
548 | td->esd_wq = create_singlethread_workqueue("taal_esd"); |
549 | if (td->esd_wq == NULL) { | |
550 | dev_err(&dssdev->dev, "can't create ESD workqueue\n"); | |
551 | r = -ENOMEM; | |
92fe0ff1 | 552 | goto err1; |
f133a9d7 TV |
553 | } |
554 | INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work); | |
555 | ||
556 | dev_set_drvdata(&dssdev->dev, td); | |
557 | ||
006db7b4 JN |
558 | taal_hw_reset(dssdev); |
559 | ||
f133a9d7 TV |
560 | /* if no platform set_backlight() defined, presume DSI backlight |
561 | * control */ | |
a19a6ee6 | 562 | memset(&props, 0, sizeof(struct backlight_properties)); |
f133a9d7 TV |
563 | if (!dssdev->set_backlight) |
564 | td->use_dsi_bl = true; | |
565 | ||
a19a6ee6 MG |
566 | if (td->use_dsi_bl) |
567 | props.max_brightness = 255; | |
568 | else | |
569 | props.max_brightness = 127; | |
f133a9d7 | 570 | bldev = backlight_device_register("taal", &dssdev->dev, dssdev, |
a19a6ee6 | 571 | &taal_bl_ops, &props); |
f133a9d7 TV |
572 | if (IS_ERR(bldev)) { |
573 | r = PTR_ERR(bldev); | |
92fe0ff1 | 574 | goto err2; |
f133a9d7 TV |
575 | } |
576 | ||
577 | td->bldev = bldev; | |
578 | ||
579 | bldev->props.fb_blank = FB_BLANK_UNBLANK; | |
580 | bldev->props.power = FB_BLANK_UNBLANK; | |
a19a6ee6 | 581 | if (td->use_dsi_bl) |
f133a9d7 | 582 | bldev->props.brightness = 255; |
a19a6ee6 | 583 | else |
f133a9d7 | 584 | bldev->props.brightness = 127; |
f133a9d7 TV |
585 | |
586 | taal_bl_update_status(bldev); | |
587 | ||
588 | if (dssdev->phy.dsi.ext_te) { | |
589 | int gpio = dssdev->phy.dsi.ext_te_gpio; | |
590 | ||
591 | r = gpio_request(gpio, "taal irq"); | |
592 | if (r) { | |
593 | dev_err(&dssdev->dev, "GPIO request failed\n"); | |
594 | goto err3; | |
595 | } | |
596 | ||
597 | gpio_direction_input(gpio); | |
598 | ||
599 | r = request_irq(gpio_to_irq(gpio), taal_te_isr, | |
600 | IRQF_DISABLED | IRQF_TRIGGER_RISING, | |
601 | "taal vsync", dssdev); | |
602 | ||
603 | if (r) { | |
604 | dev_err(&dssdev->dev, "IRQ request failed\n"); | |
605 | gpio_free(gpio); | |
2f1e5f60 | 606 | goto err4; |
f133a9d7 TV |
607 | } |
608 | ||
609 | init_completion(&td->te_completion); | |
610 | ||
611 | td->use_ext_te = true; | |
612 | } | |
613 | ||
614 | r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group); | |
615 | if (r) { | |
616 | dev_err(&dssdev->dev, "failed to create sysfs files\n"); | |
2f1e5f60 | 617 | goto err5; |
f133a9d7 TV |
618 | } |
619 | ||
620 | return 0; | |
2f1e5f60 JN |
621 | err5: |
622 | if (td->use_ext_te) | |
623 | free_irq(gpio_to_irq(dssdev->phy.dsi.ext_te_gpio), dssdev); | |
f133a9d7 | 624 | err4: |
2f1e5f60 JN |
625 | if (td->use_ext_te) |
626 | gpio_free(dssdev->phy.dsi.ext_te_gpio); | |
f133a9d7 TV |
627 | err3: |
628 | backlight_device_unregister(bldev); | |
629 | err2: | |
f133a9d7 TV |
630 | destroy_workqueue(td->esd_wq); |
631 | err1: | |
632 | kfree(td); | |
633 | err0: | |
634 | return r; | |
635 | } | |
636 | ||
637 | static void taal_remove(struct omap_dss_device *dssdev) | |
638 | { | |
639 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
640 | struct backlight_device *bldev; | |
641 | ||
642 | dev_dbg(&dssdev->dev, "remove\n"); | |
643 | ||
644 | sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group); | |
645 | ||
646 | if (td->use_ext_te) { | |
647 | int gpio = dssdev->phy.dsi.ext_te_gpio; | |
648 | free_irq(gpio_to_irq(gpio), dssdev); | |
649 | gpio_free(gpio); | |
650 | } | |
651 | ||
652 | bldev = td->bldev; | |
653 | bldev->props.power = FB_BLANK_POWERDOWN; | |
654 | taal_bl_update_status(bldev); | |
655 | backlight_device_unregister(bldev); | |
656 | ||
4571a023 | 657 | cancel_delayed_work(&td->esd_work); |
f133a9d7 TV |
658 | destroy_workqueue(td->esd_wq); |
659 | ||
006db7b4 JN |
660 | /* reset, to be sure that the panel is in a valid state */ |
661 | taal_hw_reset(dssdev); | |
662 | ||
f133a9d7 TV |
663 | kfree(td); |
664 | } | |
665 | ||
37ac60e4 | 666 | static int taal_power_on(struct omap_dss_device *dssdev) |
f133a9d7 TV |
667 | { |
668 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
669 | u8 id1, id2, id3; | |
670 | int r; | |
671 | ||
f133a9d7 TV |
672 | /* it seems we have to wait a bit until taal is ready */ |
673 | msleep(5); | |
674 | ||
37ac60e4 TV |
675 | r = omapdss_dsi_display_enable(dssdev); |
676 | if (r) { | |
677 | dev_err(&dssdev->dev, "failed to enable DSI\n"); | |
678 | goto err0; | |
679 | } | |
680 | ||
006db7b4 JN |
681 | taal_hw_reset(dssdev); |
682 | ||
37ac60e4 TV |
683 | omapdss_dsi_vc_enable_hs(TCH, false); |
684 | ||
f133a9d7 TV |
685 | r = taal_sleep_out(td); |
686 | if (r) | |
687 | goto err; | |
688 | ||
689 | r = taal_get_id(&id1, &id2, &id3); | |
690 | if (r) | |
691 | goto err; | |
692 | ||
693 | /* on early revisions CABC is broken */ | |
694 | if (id2 == 0x00 || id2 == 0xff || id2 == 0x81) | |
695 | td->cabc_broken = true; | |
696 | ||
f2a8b75c JN |
697 | r = taal_dcs_write_1(DCS_BRIGHTNESS, 0xff); |
698 | if (r) | |
699 | goto err; | |
f133a9d7 | 700 | |
f2a8b75c JN |
701 | r = taal_dcs_write_1(DCS_CTRL_DISPLAY, |
702 | (1<<2) | (1<<5)); /* BL | BCTRL */ | |
703 | if (r) | |
704 | goto err; | |
f133a9d7 | 705 | |
f2a8b75c JN |
706 | r = taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */ |
707 | if (r) | |
708 | goto err; | |
f133a9d7 | 709 | |
f2a8b75c JN |
710 | r = taal_set_addr_mode(td->rotate, td->mirror); |
711 | if (r) | |
712 | goto err; | |
713 | ||
714 | if (!td->cabc_broken) { | |
715 | r = taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode); | |
716 | if (r) | |
717 | goto err; | |
718 | } | |
719 | ||
720 | r = taal_dcs_write_0(DCS_DISPLAY_ON); | |
721 | if (r) | |
722 | goto err; | |
f133a9d7 | 723 | |
21df20fc TV |
724 | r = _taal_enable_te(dssdev, td->te_enabled); |
725 | if (r) | |
726 | goto err; | |
727 | ||
f133a9d7 TV |
728 | td->enabled = 1; |
729 | ||
730 | if (!td->intro_printed) { | |
731 | dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n", | |
732 | id1, id2, id3); | |
733 | if (td->cabc_broken) | |
734 | dev_info(&dssdev->dev, | |
735 | "old Taal version, CABC disabled\n"); | |
736 | td->intro_printed = true; | |
737 | } | |
738 | ||
37ac60e4 TV |
739 | omapdss_dsi_vc_enable_hs(TCH, true); |
740 | ||
f133a9d7 TV |
741 | return 0; |
742 | err: | |
006db7b4 JN |
743 | dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n"); |
744 | ||
745 | taal_hw_reset(dssdev); | |
746 | ||
37ac60e4 TV |
747 | omapdss_dsi_display_disable(dssdev); |
748 | err0: | |
f133a9d7 TV |
749 | return r; |
750 | } | |
751 | ||
37ac60e4 | 752 | static void taal_power_off(struct omap_dss_device *dssdev) |
f133a9d7 TV |
753 | { |
754 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
006db7b4 | 755 | int r; |
f133a9d7 | 756 | |
006db7b4 JN |
757 | r = taal_dcs_write_0(DCS_DISPLAY_OFF); |
758 | if (!r) { | |
759 | r = taal_sleep_in(td); | |
760 | /* wait a bit so that the message goes through */ | |
761 | msleep(10); | |
762 | } | |
f133a9d7 | 763 | |
006db7b4 JN |
764 | if (r) { |
765 | dev_err(&dssdev->dev, | |
766 | "error disabling panel, issuing HW reset\n"); | |
767 | taal_hw_reset(dssdev); | |
768 | } | |
f133a9d7 | 769 | |
37ac60e4 TV |
770 | omapdss_dsi_display_disable(dssdev); |
771 | ||
f133a9d7 | 772 | td->enabled = 0; |
37ac60e4 TV |
773 | } |
774 | ||
775 | static int taal_enable(struct omap_dss_device *dssdev) | |
776 | { | |
a3201a0e | 777 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
37ac60e4 | 778 | int r; |
a3201a0e | 779 | |
37ac60e4 TV |
780 | dev_dbg(&dssdev->dev, "enable\n"); |
781 | ||
a3201a0e TV |
782 | mutex_lock(&td->lock); |
783 | ||
784 | if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) { | |
785 | r = -EINVAL; | |
786 | goto err; | |
787 | } | |
37ac60e4 | 788 | |
2c2fc151 JN |
789 | dsi_bus_lock(); |
790 | ||
37ac60e4 | 791 | r = taal_power_on(dssdev); |
2c2fc151 JN |
792 | |
793 | dsi_bus_unlock(); | |
794 | ||
37ac60e4 | 795 | if (r) |
a3201a0e | 796 | goto err; |
37ac60e4 | 797 | |
4571a023 JN |
798 | #ifdef TAAL_USE_ESD_CHECK |
799 | queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD); | |
800 | #endif | |
801 | ||
37ac60e4 TV |
802 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
803 | ||
a3201a0e TV |
804 | mutex_unlock(&td->lock); |
805 | ||
806 | return 0; | |
807 | err: | |
808 | dev_dbg(&dssdev->dev, "enable failed\n"); | |
809 | mutex_unlock(&td->lock); | |
37ac60e4 TV |
810 | return r; |
811 | } | |
812 | ||
813 | static void taal_disable(struct omap_dss_device *dssdev) | |
814 | { | |
a3201a0e TV |
815 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
816 | ||
37ac60e4 TV |
817 | dev_dbg(&dssdev->dev, "disable\n"); |
818 | ||
a3201a0e TV |
819 | mutex_lock(&td->lock); |
820 | ||
4571a023 JN |
821 | cancel_delayed_work(&td->esd_work); |
822 | ||
2c2fc151 JN |
823 | dsi_bus_lock(); |
824 | ||
37ac60e4 TV |
825 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) |
826 | taal_power_off(dssdev); | |
827 | ||
2c2fc151 JN |
828 | dsi_bus_unlock(); |
829 | ||
37ac60e4 | 830 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
a3201a0e TV |
831 | |
832 | mutex_unlock(&td->lock); | |
f133a9d7 TV |
833 | } |
834 | ||
835 | static int taal_suspend(struct omap_dss_device *dssdev) | |
836 | { | |
a3201a0e TV |
837 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
838 | int r; | |
839 | ||
37ac60e4 | 840 | dev_dbg(&dssdev->dev, "suspend\n"); |
f133a9d7 | 841 | |
a3201a0e TV |
842 | mutex_lock(&td->lock); |
843 | ||
844 | if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) { | |
845 | r = -EINVAL; | |
846 | goto err; | |
847 | } | |
37ac60e4 | 848 | |
4571a023 JN |
849 | cancel_delayed_work(&td->esd_work); |
850 | ||
2c2fc151 JN |
851 | dsi_bus_lock(); |
852 | ||
37ac60e4 | 853 | taal_power_off(dssdev); |
2c2fc151 JN |
854 | |
855 | dsi_bus_unlock(); | |
856 | ||
37ac60e4 | 857 | dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED; |
f133a9d7 | 858 | |
a3201a0e TV |
859 | mutex_unlock(&td->lock); |
860 | ||
f133a9d7 | 861 | return 0; |
a3201a0e TV |
862 | err: |
863 | mutex_unlock(&td->lock); | |
864 | return r; | |
f133a9d7 TV |
865 | } |
866 | ||
867 | static int taal_resume(struct omap_dss_device *dssdev) | |
868 | { | |
a3201a0e | 869 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
37ac60e4 | 870 | int r; |
a3201a0e | 871 | |
37ac60e4 | 872 | dev_dbg(&dssdev->dev, "resume\n"); |
f133a9d7 | 873 | |
a3201a0e TV |
874 | mutex_lock(&td->lock); |
875 | ||
876 | if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) { | |
877 | r = -EINVAL; | |
878 | goto err; | |
879 | } | |
f133a9d7 | 880 | |
2c2fc151 JN |
881 | dsi_bus_lock(); |
882 | ||
37ac60e4 | 883 | r = taal_power_on(dssdev); |
2c2fc151 JN |
884 | |
885 | dsi_bus_unlock(); | |
886 | ||
4571a023 | 887 | if (r) { |
fed44b7a | 888 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
4571a023 | 889 | } else { |
fed44b7a | 890 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
4571a023 JN |
891 | #ifdef TAAL_USE_ESD_CHECK |
892 | queue_delayed_work(td->esd_wq, &td->esd_work, | |
893 | TAAL_ESD_CHECK_PERIOD); | |
894 | #endif | |
895 | } | |
a3201a0e TV |
896 | |
897 | mutex_unlock(&td->lock); | |
898 | ||
899 | return r; | |
900 | err: | |
901 | mutex_unlock(&td->lock); | |
37ac60e4 | 902 | return r; |
f133a9d7 TV |
903 | } |
904 | ||
18946f62 TV |
905 | static void taal_framedone_cb(int err, void *data) |
906 | { | |
907 | struct omap_dss_device *dssdev = data; | |
908 | dev_dbg(&dssdev->dev, "framedone, err %d\n", err); | |
909 | dsi_bus_unlock(); | |
910 | } | |
911 | ||
912 | static int taal_update(struct omap_dss_device *dssdev, | |
f133a9d7 TV |
913 | u16 x, u16 y, u16 w, u16 h) |
914 | { | |
18946f62 TV |
915 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
916 | int r; | |
917 | ||
918 | dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h); | |
919 | ||
a3201a0e | 920 | mutex_lock(&td->lock); |
18946f62 TV |
921 | dsi_bus_lock(); |
922 | ||
923 | if (!td->enabled) { | |
924 | r = 0; | |
925 | goto err; | |
926 | } | |
927 | ||
928 | r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h); | |
929 | if (r) | |
930 | goto err; | |
931 | ||
932 | r = taal_set_update_window(x, y, w, h); | |
933 | if (r) | |
934 | goto err; | |
935 | ||
936 | r = omap_dsi_update(dssdev, TCH, x, y, w, h, | |
937 | taal_framedone_cb, dssdev); | |
938 | if (r) | |
939 | goto err; | |
940 | ||
941 | /* note: no bus_unlock here. unlock is in framedone_cb */ | |
a3201a0e | 942 | mutex_unlock(&td->lock); |
18946f62 TV |
943 | return 0; |
944 | err: | |
945 | dsi_bus_unlock(); | |
a3201a0e | 946 | mutex_unlock(&td->lock); |
18946f62 TV |
947 | return r; |
948 | } | |
949 | ||
950 | static int taal_sync(struct omap_dss_device *dssdev) | |
951 | { | |
a3201a0e TV |
952 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
953 | ||
18946f62 TV |
954 | dev_dbg(&dssdev->dev, "sync\n"); |
955 | ||
a3201a0e | 956 | mutex_lock(&td->lock); |
18946f62 TV |
957 | dsi_bus_lock(); |
958 | dsi_bus_unlock(); | |
a3201a0e | 959 | mutex_unlock(&td->lock); |
18946f62 TV |
960 | |
961 | dev_dbg(&dssdev->dev, "sync done\n"); | |
962 | ||
963 | return 0; | |
f133a9d7 TV |
964 | } |
965 | ||
21df20fc | 966 | static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable) |
f133a9d7 | 967 | { |
f133a9d7 TV |
968 | int r; |
969 | ||
f133a9d7 TV |
970 | if (enable) |
971 | r = taal_dcs_write_1(DCS_TEAR_ON, 0); | |
972 | else | |
973 | r = taal_dcs_write_0(DCS_TEAR_OFF); | |
974 | ||
225b650d TV |
975 | omapdss_dsi_enable_te(dssdev, enable); |
976 | ||
977 | /* XXX for some reason, DSI TE breaks if we don't wait here. | |
978 | * Panel bug? Needs more studying */ | |
979 | msleep(100); | |
980 | ||
21df20fc TV |
981 | return r; |
982 | } | |
983 | ||
984 | static int taal_enable_te(struct omap_dss_device *dssdev, bool enable) | |
985 | { | |
a3201a0e | 986 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
21df20fc TV |
987 | int r; |
988 | ||
a3201a0e | 989 | mutex_lock(&td->lock); |
21df20fc TV |
990 | dsi_bus_lock(); |
991 | ||
ee52c0ae JN |
992 | if (td->enabled) { |
993 | r = _taal_enable_te(dssdev, enable); | |
994 | if (r) | |
995 | goto err; | |
996 | } | |
997 | ||
998 | td->te_enabled = enable; | |
21df20fc | 999 | |
225b650d | 1000 | dsi_bus_unlock(); |
a3201a0e | 1001 | mutex_unlock(&td->lock); |
225b650d | 1002 | |
ee52c0ae JN |
1003 | return 0; |
1004 | err: | |
1005 | dsi_bus_unlock(); | |
1006 | mutex_unlock(&td->lock); | |
1007 | ||
f133a9d7 TV |
1008 | return r; |
1009 | } | |
1010 | ||
225b650d TV |
1011 | static int taal_get_te(struct omap_dss_device *dssdev) |
1012 | { | |
1013 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
a3201a0e TV |
1014 | int r; |
1015 | ||
1016 | mutex_lock(&td->lock); | |
1017 | r = td->te_enabled; | |
1018 | mutex_unlock(&td->lock); | |
1019 | ||
1020 | return r; | |
225b650d TV |
1021 | } |
1022 | ||
f133a9d7 TV |
1023 | static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate) |
1024 | { | |
1025 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
1026 | int r; | |
1027 | ||
1028 | dev_dbg(&dssdev->dev, "rotate %d\n", rotate); | |
1029 | ||
a3201a0e | 1030 | mutex_lock(&td->lock); |
87424e1b TV |
1031 | dsi_bus_lock(); |
1032 | ||
f133a9d7 TV |
1033 | if (td->enabled) { |
1034 | r = taal_set_addr_mode(rotate, td->mirror); | |
f133a9d7 | 1035 | if (r) |
87424e1b | 1036 | goto err; |
f133a9d7 TV |
1037 | } |
1038 | ||
1039 | td->rotate = rotate; | |
1040 | ||
87424e1b | 1041 | dsi_bus_unlock(); |
a3201a0e | 1042 | mutex_unlock(&td->lock); |
f133a9d7 | 1043 | return 0; |
87424e1b TV |
1044 | err: |
1045 | dsi_bus_unlock(); | |
a3201a0e | 1046 | mutex_unlock(&td->lock); |
87424e1b | 1047 | return r; |
f133a9d7 TV |
1048 | } |
1049 | ||
1050 | static u8 taal_get_rotate(struct omap_dss_device *dssdev) | |
1051 | { | |
1052 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
a3201a0e TV |
1053 | int r; |
1054 | ||
1055 | mutex_lock(&td->lock); | |
1056 | r = td->rotate; | |
1057 | mutex_unlock(&td->lock); | |
1058 | ||
1059 | return r; | |
f133a9d7 TV |
1060 | } |
1061 | ||
1062 | static int taal_mirror(struct omap_dss_device *dssdev, bool enable) | |
1063 | { | |
1064 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
1065 | int r; | |
1066 | ||
1067 | dev_dbg(&dssdev->dev, "mirror %d\n", enable); | |
1068 | ||
a3201a0e | 1069 | mutex_lock(&td->lock); |
8d8aa61d | 1070 | dsi_bus_lock(); |
f133a9d7 TV |
1071 | if (td->enabled) { |
1072 | r = taal_set_addr_mode(td->rotate, enable); | |
f133a9d7 | 1073 | if (r) |
8d8aa61d | 1074 | goto err; |
f133a9d7 TV |
1075 | } |
1076 | ||
1077 | td->mirror = enable; | |
1078 | ||
8d8aa61d | 1079 | dsi_bus_unlock(); |
a3201a0e | 1080 | mutex_unlock(&td->lock); |
f133a9d7 | 1081 | return 0; |
8d8aa61d TV |
1082 | err: |
1083 | dsi_bus_unlock(); | |
a3201a0e | 1084 | mutex_unlock(&td->lock); |
8d8aa61d | 1085 | return r; |
f133a9d7 TV |
1086 | } |
1087 | ||
1088 | static bool taal_get_mirror(struct omap_dss_device *dssdev) | |
1089 | { | |
1090 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); | |
a3201a0e TV |
1091 | int r; |
1092 | ||
1093 | mutex_lock(&td->lock); | |
1094 | r = td->mirror; | |
1095 | mutex_unlock(&td->lock); | |
1096 | ||
1097 | return r; | |
f133a9d7 TV |
1098 | } |
1099 | ||
1100 | static int taal_run_test(struct omap_dss_device *dssdev, int test_num) | |
1101 | { | |
a3201a0e | 1102 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
f133a9d7 TV |
1103 | u8 id1, id2, id3; |
1104 | int r; | |
1105 | ||
a3201a0e | 1106 | mutex_lock(&td->lock); |
ee52c0ae JN |
1107 | |
1108 | if (!td->enabled) { | |
1109 | r = -ENODEV; | |
1110 | goto err1; | |
1111 | } | |
1112 | ||
1a75ef42 TV |
1113 | dsi_bus_lock(); |
1114 | ||
f133a9d7 TV |
1115 | r = taal_dcs_read_1(DCS_GET_ID1, &id1); |
1116 | if (r) | |
ee52c0ae | 1117 | goto err2; |
f133a9d7 TV |
1118 | r = taal_dcs_read_1(DCS_GET_ID2, &id2); |
1119 | if (r) | |
ee52c0ae | 1120 | goto err2; |
f133a9d7 TV |
1121 | r = taal_dcs_read_1(DCS_GET_ID3, &id3); |
1122 | if (r) | |
ee52c0ae | 1123 | goto err2; |
f133a9d7 | 1124 | |
1a75ef42 | 1125 | dsi_bus_unlock(); |
a3201a0e | 1126 | mutex_unlock(&td->lock); |
f133a9d7 | 1127 | return 0; |
ee52c0ae | 1128 | err2: |
1a75ef42 | 1129 | dsi_bus_unlock(); |
ee52c0ae | 1130 | err1: |
a3201a0e | 1131 | mutex_unlock(&td->lock); |
1a75ef42 | 1132 | return r; |
f133a9d7 TV |
1133 | } |
1134 | ||
1135 | static int taal_memory_read(struct omap_dss_device *dssdev, | |
1136 | void *buf, size_t size, | |
1137 | u16 x, u16 y, u16 w, u16 h) | |
1138 | { | |
1139 | int r; | |
1140 | int first = 1; | |
1141 | int plen; | |
1142 | unsigned buf_used = 0; | |
c75d9464 TV |
1143 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
1144 | ||
f133a9d7 TV |
1145 | if (size < w * h * 3) |
1146 | return -ENOMEM; | |
1147 | ||
a3201a0e TV |
1148 | mutex_lock(&td->lock); |
1149 | ||
1150 | if (!td->enabled) { | |
1151 | r = -ENODEV; | |
1152 | goto err1; | |
1153 | } | |
1154 | ||
f133a9d7 TV |
1155 | size = min(w * h * 3, |
1156 | dssdev->panel.timings.x_res * | |
1157 | dssdev->panel.timings.y_res * 3); | |
1158 | ||
c75d9464 TV |
1159 | dsi_bus_lock(); |
1160 | ||
f133a9d7 TV |
1161 | /* plen 1 or 2 goes into short packet. until checksum error is fixed, |
1162 | * use short packets. plen 32 works, but bigger packets seem to cause | |
1163 | * an error. */ | |
1164 | if (size % 2) | |
1165 | plen = 1; | |
1166 | else | |
1167 | plen = 2; | |
1168 | ||
c75d9464 | 1169 | taal_set_update_window(x, y, w, h); |
f133a9d7 TV |
1170 | |
1171 | r = dsi_vc_set_max_rx_packet_size(TCH, plen); | |
1172 | if (r) | |
a3201a0e | 1173 | goto err2; |
f133a9d7 TV |
1174 | |
1175 | while (buf_used < size) { | |
1176 | u8 dcs_cmd = first ? 0x2e : 0x3e; | |
1177 | first = 0; | |
1178 | ||
1179 | r = dsi_vc_dcs_read(TCH, dcs_cmd, | |
1180 | buf + buf_used, size - buf_used); | |
1181 | ||
1182 | if (r < 0) { | |
1183 | dev_err(&dssdev->dev, "read error\n"); | |
a3201a0e | 1184 | goto err3; |
f133a9d7 TV |
1185 | } |
1186 | ||
1187 | buf_used += r; | |
1188 | ||
1189 | if (r < plen) { | |
1190 | dev_err(&dssdev->dev, "short read\n"); | |
1191 | break; | |
1192 | } | |
1193 | ||
1194 | if (signal_pending(current)) { | |
1195 | dev_err(&dssdev->dev, "signal pending, " | |
1196 | "aborting memory read\n"); | |
1197 | r = -ERESTARTSYS; | |
a3201a0e | 1198 | goto err3; |
f133a9d7 TV |
1199 | } |
1200 | } | |
1201 | ||
1202 | r = buf_used; | |
1203 | ||
a3201a0e | 1204 | err3: |
f133a9d7 | 1205 | dsi_vc_set_max_rx_packet_size(TCH, 1); |
a3201a0e | 1206 | err2: |
c75d9464 | 1207 | dsi_bus_unlock(); |
a3201a0e TV |
1208 | err1: |
1209 | mutex_unlock(&td->lock); | |
f133a9d7 TV |
1210 | return r; |
1211 | } | |
1212 | ||
1213 | static void taal_esd_work(struct work_struct *work) | |
1214 | { | |
1215 | struct taal_data *td = container_of(work, struct taal_data, | |
1216 | esd_work.work); | |
1217 | struct omap_dss_device *dssdev = td->dssdev; | |
1218 | u8 state1, state2; | |
1219 | int r; | |
1220 | ||
a3201a0e TV |
1221 | mutex_lock(&td->lock); |
1222 | ||
1223 | if (!td->enabled) { | |
1224 | mutex_unlock(&td->lock); | |
f133a9d7 | 1225 | return; |
a3201a0e | 1226 | } |
f133a9d7 TV |
1227 | |
1228 | dsi_bus_lock(); | |
1229 | ||
1230 | r = taal_dcs_read_1(DCS_RDDSDR, &state1); | |
1231 | if (r) { | |
1232 | dev_err(&dssdev->dev, "failed to read Taal status\n"); | |
1233 | goto err; | |
1234 | } | |
1235 | ||
1236 | /* Run self diagnostics */ | |
1237 | r = taal_sleep_out(td); | |
1238 | if (r) { | |
1239 | dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n"); | |
1240 | goto err; | |
1241 | } | |
1242 | ||
1243 | r = taal_dcs_read_1(DCS_RDDSDR, &state2); | |
1244 | if (r) { | |
1245 | dev_err(&dssdev->dev, "failed to read Taal status\n"); | |
1246 | goto err; | |
1247 | } | |
1248 | ||
1249 | /* Each sleep out command will trigger a self diagnostic and flip | |
1250 | * Bit6 if the test passes. | |
1251 | */ | |
1252 | if (!((state1 ^ state2) & (1 << 6))) { | |
1253 | dev_err(&dssdev->dev, "LCD self diagnostics failed\n"); | |
1254 | goto err; | |
1255 | } | |
1256 | /* Self-diagnostics result is also shown on TE GPIO line. We need | |
1257 | * to re-enable TE after self diagnostics */ | |
1189b7ff TV |
1258 | if (td->use_ext_te && td->te_enabled) { |
1259 | r = taal_dcs_write_1(DCS_TEAR_ON, 0); | |
1260 | if (r) | |
1261 | goto err; | |
1262 | } | |
f133a9d7 TV |
1263 | |
1264 | dsi_bus_unlock(); | |
1265 | ||
1266 | queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD); | |
1267 | ||
a3201a0e | 1268 | mutex_unlock(&td->lock); |
f133a9d7 TV |
1269 | return; |
1270 | err: | |
1271 | dev_err(&dssdev->dev, "performing LCD reset\n"); | |
1272 | ||
a3201a0e | 1273 | taal_power_off(dssdev); |
006db7b4 | 1274 | taal_hw_reset(dssdev); |
a3201a0e | 1275 | taal_power_on(dssdev); |
f133a9d7 TV |
1276 | |
1277 | dsi_bus_unlock(); | |
1278 | ||
1279 | queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD); | |
a3201a0e TV |
1280 | |
1281 | mutex_unlock(&td->lock); | |
f133a9d7 TV |
1282 | } |
1283 | ||
446f7bff TV |
1284 | static int taal_set_update_mode(struct omap_dss_device *dssdev, |
1285 | enum omap_dss_update_mode mode) | |
1286 | { | |
1287 | if (mode != OMAP_DSS_UPDATE_MANUAL) | |
1288 | return -EINVAL; | |
1289 | return 0; | |
1290 | } | |
1291 | ||
1292 | static enum omap_dss_update_mode taal_get_update_mode( | |
1293 | struct omap_dss_device *dssdev) | |
1294 | { | |
1295 | return OMAP_DSS_UPDATE_MANUAL; | |
1296 | } | |
1297 | ||
f133a9d7 TV |
1298 | static struct omap_dss_driver taal_driver = { |
1299 | .probe = taal_probe, | |
1300 | .remove = taal_remove, | |
1301 | ||
1302 | .enable = taal_enable, | |
1303 | .disable = taal_disable, | |
1304 | .suspend = taal_suspend, | |
1305 | .resume = taal_resume, | |
1306 | ||
446f7bff TV |
1307 | .set_update_mode = taal_set_update_mode, |
1308 | .get_update_mode = taal_get_update_mode, | |
18946f62 TV |
1309 | |
1310 | .update = taal_update, | |
1311 | .sync = taal_sync, | |
1312 | ||
96adcece | 1313 | .get_resolution = taal_get_resolution, |
a2699504 TV |
1314 | .get_recommended_bpp = omapdss_default_get_recommended_bpp, |
1315 | ||
f133a9d7 | 1316 | .enable_te = taal_enable_te, |
225b650d | 1317 | .get_te = taal_get_te, |
225b650d | 1318 | |
f133a9d7 TV |
1319 | .set_rotate = taal_rotate, |
1320 | .get_rotate = taal_get_rotate, | |
1321 | .set_mirror = taal_mirror, | |
1322 | .get_mirror = taal_get_mirror, | |
1323 | .run_test = taal_run_test, | |
1324 | .memory_read = taal_memory_read, | |
1325 | ||
69b2048f TV |
1326 | .get_timings = taal_get_timings, |
1327 | ||
f133a9d7 TV |
1328 | .driver = { |
1329 | .name = "taal", | |
1330 | .owner = THIS_MODULE, | |
1331 | }, | |
1332 | }; | |
1333 | ||
1334 | static int __init taal_init(void) | |
1335 | { | |
1336 | omap_dss_register_driver(&taal_driver); | |
1337 | ||
1338 | return 0; | |
1339 | } | |
1340 | ||
1341 | static void __exit taal_exit(void) | |
1342 | { | |
1343 | omap_dss_unregister_driver(&taal_driver); | |
1344 | } | |
1345 | ||
1346 | module_init(taal_init); | |
1347 | module_exit(taal_exit); | |
1348 | ||
1349 | MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>"); | |
1350 | MODULE_DESCRIPTION("Taal Driver"); | |
1351 | MODULE_LICENSE("GPL"); |