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