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