blob: 2b57776217796b3b9fa4e326b0316eea725e60fb [file] [log] [blame]
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001/*
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>
33
34#include <plat/display.h>
35
36/* DSI Virtual channel. Hardcoded for now. */
37#define TCH 0
38
39#define DCS_READ_NUM_ERRORS 0x05
40#define DCS_READ_POWER_MODE 0x0a
41#define DCS_READ_MADCTL 0x0b
42#define DCS_READ_PIXEL_FORMAT 0x0c
43#define DCS_RDDSDR 0x0f
44#define DCS_SLEEP_IN 0x10
45#define DCS_SLEEP_OUT 0x11
46#define DCS_DISPLAY_OFF 0x28
47#define DCS_DISPLAY_ON 0x29
48#define DCS_COLUMN_ADDR 0x2a
49#define DCS_PAGE_ADDR 0x2b
50#define DCS_MEMORY_WRITE 0x2c
51#define DCS_TEAR_OFF 0x34
52#define DCS_TEAR_ON 0x35
53#define DCS_MEM_ACC_CTRL 0x36
54#define DCS_PIXEL_FORMAT 0x3a
55#define DCS_BRIGHTNESS 0x51
56#define DCS_CTRL_DISPLAY 0x53
57#define DCS_WRITE_CABC 0x55
58#define DCS_READ_CABC 0x56
59#define DCS_GET_ID1 0xda
60#define DCS_GET_ID2 0xdb
61#define DCS_GET_ID3 0xdc
62
63/* #define TAAL_USE_ESD_CHECK */
64#define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000)
65
66struct taal_data {
67 struct backlight_device *bldev;
68
69 unsigned long hw_guard_end; /* next value of jiffies when we can
70 * issue the next sleep in/out command
71 */
72 unsigned long hw_guard_wait; /* max guard time in jiffies */
73
74 struct omap_dss_device *dssdev;
75
76 bool enabled;
77 u8 rotate;
78 bool mirror;
79
80 bool te_enabled;
81 bool use_ext_te;
82 struct completion te_completion;
83
84 bool use_dsi_bl;
85
86 bool cabc_broken;
87 unsigned cabc_mode;
88
89 bool intro_printed;
90
91 struct workqueue_struct *esd_wq;
92 struct delayed_work esd_work;
93};
94
95static void taal_esd_work(struct work_struct *work);
96
97static void hw_guard_start(struct taal_data *td, int guard_msec)
98{
99 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
100 td->hw_guard_end = jiffies + td->hw_guard_wait;
101}
102
103static void hw_guard_wait(struct taal_data *td)
104{
105 unsigned long wait = td->hw_guard_end - jiffies;
106
107 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
108 set_current_state(TASK_UNINTERRUPTIBLE);
109 schedule_timeout(wait);
110 }
111}
112
113static int taal_dcs_read_1(u8 dcs_cmd, u8 *data)
114{
115 int r;
116 u8 buf[1];
117
118 r = dsi_vc_dcs_read(TCH, dcs_cmd, buf, 1);
119
120 if (r < 0)
121 return r;
122
123 *data = buf[0];
124
125 return 0;
126}
127
128static int taal_dcs_write_0(u8 dcs_cmd)
129{
130 return dsi_vc_dcs_write(TCH, &dcs_cmd, 1);
131}
132
133static int taal_dcs_write_1(u8 dcs_cmd, u8 param)
134{
135 u8 buf[2];
136 buf[0] = dcs_cmd;
137 buf[1] = param;
138 return dsi_vc_dcs_write(TCH, buf, 2);
139}
140
141static int taal_sleep_in(struct taal_data *td)
142
143{
144 u8 cmd;
145 int r;
146
147 hw_guard_wait(td);
148
149 cmd = DCS_SLEEP_IN;
150 r = dsi_vc_dcs_write_nosync(TCH, &cmd, 1);
151 if (r)
152 return r;
153
154 hw_guard_start(td, 120);
155
156 msleep(5);
157
158 return 0;
159}
160
161static int taal_sleep_out(struct taal_data *td)
162{
163 int r;
164
165 hw_guard_wait(td);
166
167 r = taal_dcs_write_0(DCS_SLEEP_OUT);
168 if (r)
169 return r;
170
171 hw_guard_start(td, 120);
172
173 msleep(5);
174
175 return 0;
176}
177
178static int taal_get_id(u8 *id1, u8 *id2, u8 *id3)
179{
180 int r;
181
182 r = taal_dcs_read_1(DCS_GET_ID1, id1);
183 if (r)
184 return r;
185 r = taal_dcs_read_1(DCS_GET_ID2, id2);
186 if (r)
187 return r;
188 r = taal_dcs_read_1(DCS_GET_ID3, id3);
189 if (r)
190 return r;
191
192 return 0;
193}
194
195static int taal_set_addr_mode(u8 rotate, bool mirror)
196{
197 int r;
198 u8 mode;
199 int b5, b6, b7;
200
201 r = taal_dcs_read_1(DCS_READ_MADCTL, &mode);
202 if (r)
203 return r;
204
205 switch (rotate) {
206 default:
207 case 0:
208 b7 = 0;
209 b6 = 0;
210 b5 = 0;
211 break;
212 case 1:
213 b7 = 0;
214 b6 = 1;
215 b5 = 1;
216 break;
217 case 2:
218 b7 = 1;
219 b6 = 1;
220 b5 = 0;
221 break;
222 case 3:
223 b7 = 1;
224 b6 = 0;
225 b5 = 1;
226 break;
227 }
228
229 if (mirror)
230 b6 = !b6;
231
232 mode &= ~((1<<7) | (1<<6) | (1<<5));
233 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
234
235 return taal_dcs_write_1(DCS_MEM_ACC_CTRL, mode);
236}
237
238static int taal_set_update_window(u16 x, u16 y, u16 w, u16 h)
239{
240 int r;
241 u16 x1 = x;
242 u16 x2 = x + w - 1;
243 u16 y1 = y;
244 u16 y2 = y + h - 1;
245
246 u8 buf[5];
247 buf[0] = DCS_COLUMN_ADDR;
248 buf[1] = (x1 >> 8) & 0xff;
249 buf[2] = (x1 >> 0) & 0xff;
250 buf[3] = (x2 >> 8) & 0xff;
251 buf[4] = (x2 >> 0) & 0xff;
252
253 r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
254 if (r)
255 return r;
256
257 buf[0] = DCS_PAGE_ADDR;
258 buf[1] = (y1 >> 8) & 0xff;
259 buf[2] = (y1 >> 0) & 0xff;
260 buf[3] = (y2 >> 8) & 0xff;
261 buf[4] = (y2 >> 0) & 0xff;
262
263 r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
264 if (r)
265 return r;
266
267 dsi_vc_send_bta_sync(TCH);
268
269 return r;
270}
271
272static int taal_bl_update_status(struct backlight_device *dev)
273{
274 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
275 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
276 int r;
277 int level;
278
279 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
280 dev->props.power == FB_BLANK_UNBLANK)
281 level = dev->props.brightness;
282 else
283 level = 0;
284
285 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
286
287 if (td->use_dsi_bl) {
288 if (td->enabled) {
289 dsi_bus_lock();
290 r = taal_dcs_write_1(DCS_BRIGHTNESS, level);
291 dsi_bus_unlock();
292 if (r)
293 return r;
294 }
295 } else {
296 if (!dssdev->set_backlight)
297 return -EINVAL;
298
299 r = dssdev->set_backlight(dssdev, level);
300 if (r)
301 return r;
302 }
303
304 return 0;
305}
306
307static int taal_bl_get_intensity(struct backlight_device *dev)
308{
309 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
310 dev->props.power == FB_BLANK_UNBLANK)
311 return dev->props.brightness;
312
313 return 0;
314}
315
316static struct backlight_ops taal_bl_ops = {
317 .get_brightness = taal_bl_get_intensity,
318 .update_status = taal_bl_update_status,
319};
320
321static void taal_get_timings(struct omap_dss_device *dssdev,
322 struct omap_video_timings *timings)
323{
324 *timings = dssdev->panel.timings;
325}
326
327static void taal_get_resolution(struct omap_dss_device *dssdev,
328 u16 *xres, u16 *yres)
329{
330 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
331
332 if (td->rotate == 0 || td->rotate == 2) {
333 *xres = dssdev->panel.timings.x_res;
334 *yres = dssdev->panel.timings.y_res;
335 } else {
336 *yres = dssdev->panel.timings.x_res;
337 *xres = dssdev->panel.timings.y_res;
338 }
339}
340
341static irqreturn_t taal_te_isr(int irq, void *data)
342{
343 struct omap_dss_device *dssdev = data;
344 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
345
346 complete_all(&td->te_completion);
347
348 return IRQ_HANDLED;
349}
350
351static ssize_t taal_num_errors_show(struct device *dev,
352 struct device_attribute *attr, char *buf)
353{
354 struct omap_dss_device *dssdev = to_dss_device(dev);
355 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
356 u8 errors;
357 int r;
358
359 if (td->enabled) {
360 dsi_bus_lock();
361 r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors);
362 dsi_bus_unlock();
363 } else {
364 r = -ENODEV;
365 }
366
367 if (r)
368 return r;
369
370 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
371}
372
373static ssize_t taal_hw_revision_show(struct device *dev,
374 struct device_attribute *attr, char *buf)
375{
376 struct omap_dss_device *dssdev = to_dss_device(dev);
377 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
378 u8 id1, id2, id3;
379 int r;
380
381 if (td->enabled) {
382 dsi_bus_lock();
383 r = taal_get_id(&id1, &id2, &id3);
384 dsi_bus_unlock();
385 } else {
386 r = -ENODEV;
387 }
388
389 if (r)
390 return r;
391
392 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
393}
394
395static const char *cabc_modes[] = {
396 "off", /* used also always when CABC is not supported */
397 "ui",
398 "still-image",
399 "moving-image",
400};
401
402static ssize_t show_cabc_mode(struct device *dev,
403 struct device_attribute *attr,
404 char *buf)
405{
406 struct omap_dss_device *dssdev = to_dss_device(dev);
407 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
408 const char *mode_str;
409 int mode;
410 int len;
411
412 mode = td->cabc_mode;
413
414 mode_str = "unknown";
415 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
416 mode_str = cabc_modes[mode];
417 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
418
419 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
420}
421
422static ssize_t store_cabc_mode(struct device *dev,
423 struct device_attribute *attr,
424 const char *buf, size_t count)
425{
426 struct omap_dss_device *dssdev = to_dss_device(dev);
427 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
428 int i;
429
430 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
431 if (sysfs_streq(cabc_modes[i], buf))
432 break;
433 }
434
435 if (i == ARRAY_SIZE(cabc_modes))
436 return -EINVAL;
437
438 if (td->enabled) {
439 dsi_bus_lock();
440 if (!td->cabc_broken)
441 taal_dcs_write_1(DCS_WRITE_CABC, i);
442 dsi_bus_unlock();
443 }
444
445 td->cabc_mode = i;
446
447 return count;
448}
449
450static ssize_t show_cabc_available_modes(struct device *dev,
451 struct device_attribute *attr,
452 char *buf)
453{
454 int len;
455 int i;
456
457 for (i = 0, len = 0;
458 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
459 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
460 i ? " " : "", cabc_modes[i],
461 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
462
463 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
464}
465
466static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
467static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
468static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
469 show_cabc_mode, store_cabc_mode);
470static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
471 show_cabc_available_modes, NULL);
472
473static struct attribute *taal_attrs[] = {
474 &dev_attr_num_dsi_errors.attr,
475 &dev_attr_hw_revision.attr,
476 &dev_attr_cabc_mode.attr,
477 &dev_attr_cabc_available_modes.attr,
478 NULL,
479};
480
481static struct attribute_group taal_attr_group = {
482 .attrs = taal_attrs,
483};
484
485static int taal_probe(struct omap_dss_device *dssdev)
486{
487 struct taal_data *td;
488 struct backlight_device *bldev;
489 int r;
490
491 const struct omap_video_timings taal_panel_timings = {
492 .x_res = 864,
493 .y_res = 480,
494 };
495
496 dev_dbg(&dssdev->dev, "probe\n");
497
498 dssdev->panel.config = OMAP_DSS_LCD_TFT;
499 dssdev->panel.timings = taal_panel_timings;
500 dssdev->ctrl.pixel_size = 24;
501
502 td = kzalloc(sizeof(*td), GFP_KERNEL);
503 if (!td) {
504 r = -ENOMEM;
505 goto err0;
506 }
507 td->dssdev = dssdev;
508
509 td->esd_wq = create_singlethread_workqueue("taal_esd");
510 if (td->esd_wq == NULL) {
511 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
512 r = -ENOMEM;
Aaro Koskinen92fe0ff2009-12-09 17:26:25 +0100513 goto err1;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200514 }
515 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
516
517 dev_set_drvdata(&dssdev->dev, td);
518
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200519 /* if no platform set_backlight() defined, presume DSI backlight
520 * control */
521 if (!dssdev->set_backlight)
522 td->use_dsi_bl = true;
523
524 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
525 &taal_bl_ops);
526 if (IS_ERR(bldev)) {
527 r = PTR_ERR(bldev);
Aaro Koskinen92fe0ff2009-12-09 17:26:25 +0100528 goto err2;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200529 }
530
531 td->bldev = bldev;
532
533 bldev->props.fb_blank = FB_BLANK_UNBLANK;
534 bldev->props.power = FB_BLANK_UNBLANK;
535 if (td->use_dsi_bl) {
536 bldev->props.max_brightness = 255;
537 bldev->props.brightness = 255;
538 } else {
539 bldev->props.max_brightness = 127;
540 bldev->props.brightness = 127;
541 }
542
543 taal_bl_update_status(bldev);
544
545 if (dssdev->phy.dsi.ext_te) {
546 int gpio = dssdev->phy.dsi.ext_te_gpio;
547
548 r = gpio_request(gpio, "taal irq");
549 if (r) {
550 dev_err(&dssdev->dev, "GPIO request failed\n");
551 goto err3;
552 }
553
554 gpio_direction_input(gpio);
555
556 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
557 IRQF_DISABLED | IRQF_TRIGGER_RISING,
558 "taal vsync", dssdev);
559
560 if (r) {
561 dev_err(&dssdev->dev, "IRQ request failed\n");
562 gpio_free(gpio);
563 goto err3;
564 }
565
566 init_completion(&td->te_completion);
567
568 td->use_ext_te = true;
569 }
570
571 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
572 if (r) {
573 dev_err(&dssdev->dev, "failed to create sysfs files\n");
574 goto err4;
575 }
576
577 return 0;
578err4:
579 if (td->use_ext_te) {
580 int gpio = dssdev->phy.dsi.ext_te_gpio;
581 free_irq(gpio_to_irq(gpio), dssdev);
582 gpio_free(gpio);
583 }
584err3:
585 backlight_device_unregister(bldev);
586err2:
587 cancel_delayed_work_sync(&td->esd_work);
588 destroy_workqueue(td->esd_wq);
589err1:
590 kfree(td);
591err0:
592 return r;
593}
594
595static void taal_remove(struct omap_dss_device *dssdev)
596{
597 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
598 struct backlight_device *bldev;
599
600 dev_dbg(&dssdev->dev, "remove\n");
601
602 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
603
604 if (td->use_ext_te) {
605 int gpio = dssdev->phy.dsi.ext_te_gpio;
606 free_irq(gpio_to_irq(gpio), dssdev);
607 gpio_free(gpio);
608 }
609
610 bldev = td->bldev;
611 bldev->props.power = FB_BLANK_POWERDOWN;
612 taal_bl_update_status(bldev);
613 backlight_device_unregister(bldev);
614
615 cancel_delayed_work_sync(&td->esd_work);
616 destroy_workqueue(td->esd_wq);
617
618 kfree(td);
619}
620
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200621static int taal_power_on(struct omap_dss_device *dssdev)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200622{
623 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
624 u8 id1, id2, id3;
625 int r;
626
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200627 if (dssdev->platform_enable) {
628 r = dssdev->platform_enable(dssdev);
629 if (r)
630 return r;
631 }
632
633 /* it seems we have to wait a bit until taal is ready */
634 msleep(5);
635
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200636 dsi_bus_lock();
637
638 r = omapdss_dsi_display_enable(dssdev);
639 if (r) {
640 dev_err(&dssdev->dev, "failed to enable DSI\n");
641 goto err0;
642 }
643
644 omapdss_dsi_vc_enable_hs(TCH, false);
645
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200646 r = taal_sleep_out(td);
647 if (r)
648 goto err;
649
650 r = taal_get_id(&id1, &id2, &id3);
651 if (r)
652 goto err;
653
654 /* on early revisions CABC is broken */
655 if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
656 td->cabc_broken = true;
657
658 taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
659 taal_dcs_write_1(DCS_CTRL_DISPLAY, (1<<2) | (1<<5)); /* BL | BCTRL */
660
661 taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
662
663 taal_set_addr_mode(td->rotate, td->mirror);
664 if (!td->cabc_broken)
665 taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
666
667 taal_dcs_write_0(DCS_DISPLAY_ON);
668
669#ifdef TAAL_USE_ESD_CHECK
670 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
671#endif
672
673 td->enabled = 1;
674
675 if (!td->intro_printed) {
676 dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n",
677 id1, id2, id3);
678 if (td->cabc_broken)
679 dev_info(&dssdev->dev,
680 "old Taal version, CABC disabled\n");
681 td->intro_printed = true;
682 }
683
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200684 omapdss_dsi_vc_enable_hs(TCH, true);
685
686 dsi_bus_unlock();
687
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200688 return 0;
689err:
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200690 dsi_bus_unlock();
691
692 omapdss_dsi_display_disable(dssdev);
693err0:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200694 if (dssdev->platform_disable)
695 dssdev->platform_disable(dssdev);
696
697 return r;
698}
699
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200700static void taal_power_off(struct omap_dss_device *dssdev)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200701{
702 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
703
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200704 dsi_bus_lock();
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200705
706 cancel_delayed_work(&td->esd_work);
707
708 taal_dcs_write_0(DCS_DISPLAY_OFF);
709 taal_sleep_in(td);
710
711 /* wait a bit so that the message goes through */
712 msleep(10);
713
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200714 omapdss_dsi_display_disable(dssdev);
715
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200716 if (dssdev->platform_disable)
717 dssdev->platform_disable(dssdev);
718
719 td->enabled = 0;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200720
721 dsi_bus_unlock();
722}
723
724static int taal_enable(struct omap_dss_device *dssdev)
725{
726 int r;
727 dev_dbg(&dssdev->dev, "enable\n");
728
729 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
730 return -EINVAL;
731
732 r = taal_power_on(dssdev);
733 if (r)
734 return r;
735
736 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
737
738 return r;
739}
740
741static void taal_disable(struct omap_dss_device *dssdev)
742{
743 dev_dbg(&dssdev->dev, "disable\n");
744
745 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
746 taal_power_off(dssdev);
747
748 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200749}
750
751static int taal_suspend(struct omap_dss_device *dssdev)
752{
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200753 dev_dbg(&dssdev->dev, "suspend\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200754
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200755 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
756 return -EINVAL;
757
758 taal_power_off(dssdev);
759 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200760
761 return 0;
762}
763
764static int taal_resume(struct omap_dss_device *dssdev)
765{
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200766 int r;
767 dev_dbg(&dssdev->dev, "resume\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200768
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200769 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED)
770 return -EINVAL;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200771
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200772 r = taal_power_on(dssdev);
773 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
774 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200775}
776
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200777static void taal_framedone_cb(int err, void *data)
778{
779 struct omap_dss_device *dssdev = data;
780 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
781 dsi_bus_unlock();
782}
783
784static int taal_update(struct omap_dss_device *dssdev,
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200785 u16 x, u16 y, u16 w, u16 h)
786{
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200787 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
788 int r;
789
790 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
791
792 dsi_bus_lock();
793
794 if (!td->enabled) {
795 r = 0;
796 goto err;
797 }
798
799 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h);
800 if (r)
801 goto err;
802
803 r = taal_set_update_window(x, y, w, h);
804 if (r)
805 goto err;
806
807 r = omap_dsi_update(dssdev, TCH, x, y, w, h,
808 taal_framedone_cb, dssdev);
809 if (r)
810 goto err;
811
812 /* note: no bus_unlock here. unlock is in framedone_cb */
813 return 0;
814err:
815 dsi_bus_unlock();
816 return r;
817}
818
819static int taal_sync(struct omap_dss_device *dssdev)
820{
821 dev_dbg(&dssdev->dev, "sync\n");
822
823 dsi_bus_lock();
824 dsi_bus_unlock();
825
826 dev_dbg(&dssdev->dev, "sync done\n");
827
828 return 0;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200829}
830
831static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
832{
833 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
834 int r;
835
Tomi Valkeinen225b6502010-01-11 15:11:01 +0200836 dsi_bus_lock();
837
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200838 td->te_enabled = enable;
839
840 if (enable)
841 r = taal_dcs_write_1(DCS_TEAR_ON, 0);
842 else
843 r = taal_dcs_write_0(DCS_TEAR_OFF);
844
Tomi Valkeinen225b6502010-01-11 15:11:01 +0200845 omapdss_dsi_enable_te(dssdev, enable);
846
847 /* XXX for some reason, DSI TE breaks if we don't wait here.
848 * Panel bug? Needs more studying */
849 msleep(100);
850
851 dsi_bus_unlock();
852
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200853 return r;
854}
855
Tomi Valkeinen225b6502010-01-11 15:11:01 +0200856static int taal_get_te(struct omap_dss_device *dssdev)
857{
858 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
859 return td->te_enabled;
860}
861
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200862static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
863{
864 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
865 int r;
866
867 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
868
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200869 dsi_bus_lock();
870
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200871 if (td->enabled) {
872 r = taal_set_addr_mode(rotate, td->mirror);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200873 if (r)
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200874 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200875 }
876
877 td->rotate = rotate;
878
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200879 dsi_bus_unlock();
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200880 return 0;
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200881err:
882 dsi_bus_unlock();
883 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200884}
885
886static u8 taal_get_rotate(struct omap_dss_device *dssdev)
887{
888 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
889 return td->rotate;
890}
891
892static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
893{
894 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
895 int r;
896
897 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
898
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200899 dsi_bus_lock();
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200900 if (td->enabled) {
901 r = taal_set_addr_mode(td->rotate, enable);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200902 if (r)
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200903 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200904 }
905
906 td->mirror = enable;
907
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200908 dsi_bus_unlock();
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200909 return 0;
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200910err:
911 dsi_bus_unlock();
912 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200913}
914
915static bool taal_get_mirror(struct omap_dss_device *dssdev)
916{
917 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
918 return td->mirror;
919}
920
921static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
922{
923 u8 id1, id2, id3;
924 int r;
925
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200926 dsi_bus_lock();
927
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200928 r = taal_dcs_read_1(DCS_GET_ID1, &id1);
929 if (r)
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200930 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200931 r = taal_dcs_read_1(DCS_GET_ID2, &id2);
932 if (r)
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200933 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200934 r = taal_dcs_read_1(DCS_GET_ID3, &id3);
935 if (r)
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200936 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200937
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200938 dsi_bus_unlock();
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200939 return 0;
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200940err:
941 dsi_bus_unlock();
942 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200943}
944
945static int taal_memory_read(struct omap_dss_device *dssdev,
946 void *buf, size_t size,
947 u16 x, u16 y, u16 w, u16 h)
948{
949 int r;
950 int first = 1;
951 int plen;
952 unsigned buf_used = 0;
Tomi Valkeinenc75d9462010-01-08 16:56:44 +0200953 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
954
955 if (!td->enabled)
956 return -ENODEV;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200957
958 if (size < w * h * 3)
959 return -ENOMEM;
960
961 size = min(w * h * 3,
962 dssdev->panel.timings.x_res *
963 dssdev->panel.timings.y_res * 3);
964
Tomi Valkeinenc75d9462010-01-08 16:56:44 +0200965 dsi_bus_lock();
966
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200967 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
968 * use short packets. plen 32 works, but bigger packets seem to cause
969 * an error. */
970 if (size % 2)
971 plen = 1;
972 else
973 plen = 2;
974
Tomi Valkeinenc75d9462010-01-08 16:56:44 +0200975 taal_set_update_window(x, y, w, h);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200976
977 r = dsi_vc_set_max_rx_packet_size(TCH, plen);
978 if (r)
Tomi Valkeinenc75d9462010-01-08 16:56:44 +0200979 goto err0;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200980
981 while (buf_used < size) {
982 u8 dcs_cmd = first ? 0x2e : 0x3e;
983 first = 0;
984
985 r = dsi_vc_dcs_read(TCH, dcs_cmd,
986 buf + buf_used, size - buf_used);
987
988 if (r < 0) {
989 dev_err(&dssdev->dev, "read error\n");
990 goto err;
991 }
992
993 buf_used += r;
994
995 if (r < plen) {
996 dev_err(&dssdev->dev, "short read\n");
997 break;
998 }
999
1000 if (signal_pending(current)) {
1001 dev_err(&dssdev->dev, "signal pending, "
1002 "aborting memory read\n");
1003 r = -ERESTARTSYS;
1004 goto err;
1005 }
1006 }
1007
1008 r = buf_used;
1009
1010err:
1011 dsi_vc_set_max_rx_packet_size(TCH, 1);
Tomi Valkeinenc75d9462010-01-08 16:56:44 +02001012err0:
1013 dsi_bus_unlock();
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001014 return r;
1015}
1016
1017static void taal_esd_work(struct work_struct *work)
1018{
1019 struct taal_data *td = container_of(work, struct taal_data,
1020 esd_work.work);
1021 struct omap_dss_device *dssdev = td->dssdev;
1022 u8 state1, state2;
1023 int r;
1024
1025 if (!td->enabled)
1026 return;
1027
1028 dsi_bus_lock();
1029
1030 r = taal_dcs_read_1(DCS_RDDSDR, &state1);
1031 if (r) {
1032 dev_err(&dssdev->dev, "failed to read Taal status\n");
1033 goto err;
1034 }
1035
1036 /* Run self diagnostics */
1037 r = taal_sleep_out(td);
1038 if (r) {
1039 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1040 goto err;
1041 }
1042
1043 r = taal_dcs_read_1(DCS_RDDSDR, &state2);
1044 if (r) {
1045 dev_err(&dssdev->dev, "failed to read Taal status\n");
1046 goto err;
1047 }
1048
1049 /* Each sleep out command will trigger a self diagnostic and flip
1050 * Bit6 if the test passes.
1051 */
1052 if (!((state1 ^ state2) & (1 << 6))) {
1053 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1054 goto err;
1055 }
1056 /* Self-diagnostics result is also shown on TE GPIO line. We need
1057 * to re-enable TE after self diagnostics */
Tomi Valkeinen1189b7f2010-03-01 13:52:10 +02001058 if (td->use_ext_te && td->te_enabled) {
1059 r = taal_dcs_write_1(DCS_TEAR_ON, 0);
1060 if (r)
1061 goto err;
1062 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001063
1064 dsi_bus_unlock();
1065
1066 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1067
1068 return;
1069err:
1070 dev_err(&dssdev->dev, "performing LCD reset\n");
1071
1072 taal_disable(dssdev);
1073 taal_enable(dssdev);
1074
1075 dsi_bus_unlock();
1076
1077 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1078}
1079
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001080static int taal_set_update_mode(struct omap_dss_device *dssdev,
1081 enum omap_dss_update_mode mode)
1082{
1083 if (mode != OMAP_DSS_UPDATE_MANUAL)
1084 return -EINVAL;
1085 return 0;
1086}
1087
1088static enum omap_dss_update_mode taal_get_update_mode(
1089 struct omap_dss_device *dssdev)
1090{
1091 return OMAP_DSS_UPDATE_MANUAL;
1092}
1093
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001094static struct omap_dss_driver taal_driver = {
1095 .probe = taal_probe,
1096 .remove = taal_remove,
1097
1098 .enable = taal_enable,
1099 .disable = taal_disable,
1100 .suspend = taal_suspend,
1101 .resume = taal_resume,
1102
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001103 .set_update_mode = taal_set_update_mode,
1104 .get_update_mode = taal_get_update_mode,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001105
1106 .update = taal_update,
1107 .sync = taal_sync,
1108
Tomi Valkeinen96adcec2010-01-11 13:54:33 +02001109 .get_resolution = taal_get_resolution,
Tomi Valkeinena2699502010-01-11 14:33:40 +02001110 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1111
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001112 .enable_te = taal_enable_te,
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001113 .get_te = taal_get_te,
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001114
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001115 .set_rotate = taal_rotate,
1116 .get_rotate = taal_get_rotate,
1117 .set_mirror = taal_mirror,
1118 .get_mirror = taal_get_mirror,
1119 .run_test = taal_run_test,
1120 .memory_read = taal_memory_read,
1121
Tomi Valkeinen69b20482010-01-20 12:11:25 +02001122 .get_timings = taal_get_timings,
1123
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001124 .driver = {
1125 .name = "taal",
1126 .owner = THIS_MODULE,
1127 },
1128};
1129
1130static int __init taal_init(void)
1131{
1132 omap_dss_register_driver(&taal_driver);
1133
1134 return 0;
1135}
1136
1137static void __exit taal_exit(void)
1138{
1139 omap_dss_unregister_driver(&taal_driver);
1140}
1141
1142module_init(taal_init);
1143module_exit(taal_exit);
1144
1145MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1146MODULE_DESCRIPTION("Taal Driver");
1147MODULE_LICENSE("GPL");