Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / drivers / video / omap2 / displays / panel-taal.c
blob4e888ac09b3f4a79de6b263d275684affca45ba0
1 /*
2 * Taal DSI command mode panel
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
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.
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.
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/>.
20 /*#define DEBUG*/
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>
36 #include <video/omapdss.h>
37 #include <video/omap-panel-nokia-dsi.h>
39 /* DSI Virtual channel. Hardcoded for now. */
40 #define TCH 0
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
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);
70 static int taal_panel_reset(struct omap_dss_device *dssdev);
72 struct panel_regulator {
73 struct regulator *regulator;
74 const char *name;
75 int min_uV;
76 int max_uV;
79 static void free_regulators(struct panel_regulator *regulators, int n)
81 int i;
83 for (i = 0; i < n; i++) {
84 /* disable/put in reverse order */
85 regulator_disable(regulators[n - i - 1].regulator);
86 regulator_put(regulators[n - i - 1].regulator);
90 static int init_regulators(struct omap_dss_device *dssdev,
91 struct panel_regulator *regulators, int n)
93 int r, i, v;
95 for (i = 0; i < n; i++) {
96 struct regulator *reg;
98 reg = regulator_get(&dssdev->dev, regulators[i].name);
99 if (IS_ERR(reg)) {
100 dev_err(&dssdev->dev, "failed to get regulator %s\n",
101 regulators[i].name);
102 r = PTR_ERR(reg);
103 goto err;
106 /* FIXME: better handling of fixed vs. variable regulators */
107 v = regulator_get_voltage(reg);
108 if (v < regulators[i].min_uV || v > regulators[i].max_uV) {
109 r = regulator_set_voltage(reg, regulators[i].min_uV,
110 regulators[i].max_uV);
111 if (r) {
112 dev_err(&dssdev->dev,
113 "failed to set regulator %s voltage\n",
114 regulators[i].name);
115 regulator_put(reg);
116 goto err;
120 r = regulator_enable(reg);
121 if (r) {
122 dev_err(&dssdev->dev, "failed to enable regulator %s\n",
123 regulators[i].name);
124 regulator_put(reg);
125 goto err;
128 regulators[i].regulator = reg;
131 return 0;
133 err:
134 free_regulators(regulators, i);
136 return r;
140 * struct panel_config - panel configuration
141 * @name: panel name
142 * @type: panel type
143 * @timings: panel resolution
144 * @sleep: various panel specific delays, passed to msleep() if non-zero
145 * @reset_sequence: reset sequence timings, passed to udelay() if non-zero
146 * @regulators: array of panel regulators
147 * @num_regulators: number of regulators in the array
149 struct panel_config {
150 const char *name;
151 int type;
153 struct omap_video_timings timings;
155 struct {
156 unsigned int sleep_in;
157 unsigned int sleep_out;
158 unsigned int hw_reset;
159 unsigned int enable_te;
160 } sleep;
162 struct {
163 unsigned int high;
164 unsigned int low;
165 } reset_sequence;
167 struct panel_regulator *regulators;
168 int num_regulators;
171 enum {
172 PANEL_TAAL,
175 static struct panel_config panel_configs[] = {
177 .name = "taal",
178 .type = PANEL_TAAL,
179 .timings = {
180 .x_res = 864,
181 .y_res = 480,
183 .sleep = {
184 .sleep_in = 5,
185 .sleep_out = 5,
186 .hw_reset = 5,
187 .enable_te = 100, /* possible panel bug */
189 .reset_sequence = {
190 .high = 10,
191 .low = 10,
196 struct taal_data {
197 struct mutex lock;
199 struct backlight_device *bldev;
201 unsigned long hw_guard_end; /* next value of jiffies when we can
202 * issue the next sleep in/out command
204 unsigned long hw_guard_wait; /* max guard time in jiffies */
206 struct omap_dss_device *dssdev;
208 bool enabled;
209 u8 rotate;
210 bool mirror;
212 bool te_enabled;
214 atomic_t do_update;
215 struct {
216 u16 x;
217 u16 y;
218 u16 w;
219 u16 h;
220 } update_region;
221 int channel;
223 struct delayed_work te_timeout_work;
225 bool use_dsi_bl;
227 bool cabc_broken;
228 unsigned cabc_mode;
230 bool intro_printed;
232 struct workqueue_struct *workqueue;
234 struct delayed_work esd_work;
235 unsigned esd_interval;
237 bool ulps_enabled;
238 unsigned ulps_timeout;
239 struct delayed_work ulps_work;
241 struct panel_config *panel_config;
244 static inline struct nokia_dsi_panel_data
245 *get_panel_data(const struct omap_dss_device *dssdev)
247 return (struct nokia_dsi_panel_data *) dssdev->data;
250 static void taal_esd_work(struct work_struct *work);
251 static void taal_ulps_work(struct work_struct *work);
253 static void hw_guard_start(struct taal_data *td, int guard_msec)
255 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
256 td->hw_guard_end = jiffies + td->hw_guard_wait;
259 static void hw_guard_wait(struct taal_data *td)
261 unsigned long wait = td->hw_guard_end - jiffies;
263 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
264 set_current_state(TASK_UNINTERRUPTIBLE);
265 schedule_timeout(wait);
269 static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
271 int r;
272 u8 buf[1];
274 r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1);
276 if (r < 0)
277 return r;
279 *data = buf[0];
281 return 0;
284 static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
286 return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1);
289 static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
291 u8 buf[2];
292 buf[0] = dcs_cmd;
293 buf[1] = param;
294 return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2);
297 static int taal_sleep_in(struct taal_data *td)
300 u8 cmd;
301 int r;
303 hw_guard_wait(td);
305 cmd = DCS_SLEEP_IN;
306 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1);
307 if (r)
308 return r;
310 hw_guard_start(td, 120);
312 if (td->panel_config->sleep.sleep_in)
313 msleep(td->panel_config->sleep.sleep_in);
315 return 0;
318 static int taal_sleep_out(struct taal_data *td)
320 int r;
322 hw_guard_wait(td);
324 r = taal_dcs_write_0(td, DCS_SLEEP_OUT);
325 if (r)
326 return r;
328 hw_guard_start(td, 120);
330 if (td->panel_config->sleep.sleep_out)
331 msleep(td->panel_config->sleep.sleep_out);
333 return 0;
336 static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
338 int r;
340 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
341 if (r)
342 return r;
343 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
344 if (r)
345 return r;
346 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
347 if (r)
348 return r;
350 return 0;
353 static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
355 int r;
356 u8 mode;
357 int b5, b6, b7;
359 r = taal_dcs_read_1(td, DCS_READ_MADCTL, &mode);
360 if (r)
361 return r;
363 switch (rotate) {
364 default:
365 case 0:
366 b7 = 0;
367 b6 = 0;
368 b5 = 0;
369 break;
370 case 1:
371 b7 = 0;
372 b6 = 1;
373 b5 = 1;
374 break;
375 case 2:
376 b7 = 1;
377 b6 = 1;
378 b5 = 0;
379 break;
380 case 3:
381 b7 = 1;
382 b6 = 0;
383 b5 = 1;
384 break;
387 if (mirror)
388 b6 = !b6;
390 mode &= ~((1<<7) | (1<<6) | (1<<5));
391 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
393 return taal_dcs_write_1(td, DCS_MEM_ACC_CTRL, mode);
396 static int taal_set_update_window(struct taal_data *td,
397 u16 x, u16 y, u16 w, u16 h)
399 int r;
400 u16 x1 = x;
401 u16 x2 = x + w - 1;
402 u16 y1 = y;
403 u16 y2 = y + h - 1;
405 u8 buf[5];
406 buf[0] = DCS_COLUMN_ADDR;
407 buf[1] = (x1 >> 8) & 0xff;
408 buf[2] = (x1 >> 0) & 0xff;
409 buf[3] = (x2 >> 8) & 0xff;
410 buf[4] = (x2 >> 0) & 0xff;
412 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
413 if (r)
414 return r;
416 buf[0] = DCS_PAGE_ADDR;
417 buf[1] = (y1 >> 8) & 0xff;
418 buf[2] = (y1 >> 0) & 0xff;
419 buf[3] = (y2 >> 8) & 0xff;
420 buf[4] = (y2 >> 0) & 0xff;
422 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
423 if (r)
424 return r;
426 dsi_vc_send_bta_sync(td->dssdev, td->channel);
428 return r;
431 static void taal_queue_esd_work(struct omap_dss_device *dssdev)
433 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
435 if (td->esd_interval > 0)
436 queue_delayed_work(td->workqueue, &td->esd_work,
437 msecs_to_jiffies(td->esd_interval));
440 static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
442 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
444 cancel_delayed_work(&td->esd_work);
447 static void taal_queue_ulps_work(struct omap_dss_device *dssdev)
449 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
451 if (td->ulps_timeout > 0)
452 queue_delayed_work(td->workqueue, &td->ulps_work,
453 msecs_to_jiffies(td->ulps_timeout));
456 static void taal_cancel_ulps_work(struct omap_dss_device *dssdev)
458 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
460 cancel_delayed_work(&td->ulps_work);
463 static int taal_enter_ulps(struct omap_dss_device *dssdev)
465 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
466 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
467 int r;
469 if (td->ulps_enabled)
470 return 0;
472 taal_cancel_ulps_work(dssdev);
474 r = _taal_enable_te(dssdev, false);
475 if (r)
476 goto err;
478 disable_irq(gpio_to_irq(panel_data->ext_te_gpio));
480 omapdss_dsi_display_disable(dssdev, false, true);
482 td->ulps_enabled = true;
484 return 0;
486 err:
487 dev_err(&dssdev->dev, "enter ULPS failed");
488 taal_panel_reset(dssdev);
490 td->ulps_enabled = false;
492 taal_queue_ulps_work(dssdev);
494 return r;
497 static int taal_exit_ulps(struct omap_dss_device *dssdev)
499 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
500 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
501 int r;
503 if (!td->ulps_enabled)
504 return 0;
506 r = omapdss_dsi_display_enable(dssdev);
507 if (r) {
508 dev_err(&dssdev->dev, "failed to enable DSI\n");
509 goto err1;
512 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
514 r = _taal_enable_te(dssdev, true);
515 if (r) {
516 dev_err(&dssdev->dev, "failed to re-enable TE");
517 goto err2;
520 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
522 taal_queue_ulps_work(dssdev);
524 td->ulps_enabled = false;
526 return 0;
528 err2:
529 dev_err(&dssdev->dev, "failed to exit ULPS");
531 r = taal_panel_reset(dssdev);
532 if (!r) {
533 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
534 td->ulps_enabled = false;
536 err1:
537 taal_queue_ulps_work(dssdev);
539 return r;
542 static int taal_wake_up(struct omap_dss_device *dssdev)
544 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
546 if (td->ulps_enabled)
547 return taal_exit_ulps(dssdev);
549 taal_cancel_ulps_work(dssdev);
550 taal_queue_ulps_work(dssdev);
551 return 0;
554 static int taal_bl_update_status(struct backlight_device *dev)
556 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
557 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
558 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
559 int r;
560 int level;
562 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
563 dev->props.power == FB_BLANK_UNBLANK)
564 level = dev->props.brightness;
565 else
566 level = 0;
568 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
570 mutex_lock(&td->lock);
572 if (td->use_dsi_bl) {
573 if (td->enabled) {
574 dsi_bus_lock(dssdev);
576 r = taal_wake_up(dssdev);
577 if (!r)
578 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
580 dsi_bus_unlock(dssdev);
581 } else {
582 r = 0;
584 } else {
585 if (!panel_data->set_backlight)
586 r = -EINVAL;
587 else
588 r = panel_data->set_backlight(dssdev, level);
591 mutex_unlock(&td->lock);
593 return r;
596 static int taal_bl_get_intensity(struct backlight_device *dev)
598 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
599 dev->props.power == FB_BLANK_UNBLANK)
600 return dev->props.brightness;
602 return 0;
605 static const struct backlight_ops taal_bl_ops = {
606 .get_brightness = taal_bl_get_intensity,
607 .update_status = taal_bl_update_status,
610 static void taal_get_timings(struct omap_dss_device *dssdev,
611 struct omap_video_timings *timings)
613 *timings = dssdev->panel.timings;
616 static void taal_get_resolution(struct omap_dss_device *dssdev,
617 u16 *xres, u16 *yres)
619 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
621 if (td->rotate == 0 || td->rotate == 2) {
622 *xres = dssdev->panel.timings.x_res;
623 *yres = dssdev->panel.timings.y_res;
624 } else {
625 *yres = dssdev->panel.timings.x_res;
626 *xres = dssdev->panel.timings.y_res;
630 static ssize_t taal_num_errors_show(struct device *dev,
631 struct device_attribute *attr, char *buf)
633 struct omap_dss_device *dssdev = to_dss_device(dev);
634 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
635 u8 errors;
636 int r;
638 mutex_lock(&td->lock);
640 if (td->enabled) {
641 dsi_bus_lock(dssdev);
643 r = taal_wake_up(dssdev);
644 if (!r)
645 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
647 dsi_bus_unlock(dssdev);
648 } else {
649 r = -ENODEV;
652 mutex_unlock(&td->lock);
654 if (r)
655 return r;
657 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
660 static ssize_t taal_hw_revision_show(struct device *dev,
661 struct device_attribute *attr, char *buf)
663 struct omap_dss_device *dssdev = to_dss_device(dev);
664 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
665 u8 id1, id2, id3;
666 int r;
668 mutex_lock(&td->lock);
670 if (td->enabled) {
671 dsi_bus_lock(dssdev);
673 r = taal_wake_up(dssdev);
674 if (!r)
675 r = taal_get_id(td, &id1, &id2, &id3);
677 dsi_bus_unlock(dssdev);
678 } else {
679 r = -ENODEV;
682 mutex_unlock(&td->lock);
684 if (r)
685 return r;
687 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
690 static const char *cabc_modes[] = {
691 "off", /* used also always when CABC is not supported */
692 "ui",
693 "still-image",
694 "moving-image",
697 static ssize_t show_cabc_mode(struct device *dev,
698 struct device_attribute *attr,
699 char *buf)
701 struct omap_dss_device *dssdev = to_dss_device(dev);
702 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
703 const char *mode_str;
704 int mode;
705 int len;
707 mode = td->cabc_mode;
709 mode_str = "unknown";
710 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
711 mode_str = cabc_modes[mode];
712 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
714 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
717 static ssize_t store_cabc_mode(struct device *dev,
718 struct device_attribute *attr,
719 const char *buf, size_t count)
721 struct omap_dss_device *dssdev = to_dss_device(dev);
722 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
723 int i;
724 int r;
726 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
727 if (sysfs_streq(cabc_modes[i], buf))
728 break;
731 if (i == ARRAY_SIZE(cabc_modes))
732 return -EINVAL;
734 mutex_lock(&td->lock);
736 if (td->enabled) {
737 dsi_bus_lock(dssdev);
739 if (!td->cabc_broken) {
740 r = taal_wake_up(dssdev);
741 if (r)
742 goto err;
744 r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
745 if (r)
746 goto err;
749 dsi_bus_unlock(dssdev);
752 td->cabc_mode = i;
754 mutex_unlock(&td->lock);
756 return count;
757 err:
758 dsi_bus_unlock(dssdev);
759 mutex_unlock(&td->lock);
760 return r;
763 static ssize_t show_cabc_available_modes(struct device *dev,
764 struct device_attribute *attr,
765 char *buf)
767 int len;
768 int i;
770 for (i = 0, len = 0;
771 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
772 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
773 i ? " " : "", cabc_modes[i],
774 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
776 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
779 static ssize_t taal_store_esd_interval(struct device *dev,
780 struct device_attribute *attr,
781 const char *buf, size_t count)
783 struct omap_dss_device *dssdev = to_dss_device(dev);
784 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
786 unsigned long t;
787 int r;
789 r = strict_strtoul(buf, 10, &t);
790 if (r)
791 return r;
793 mutex_lock(&td->lock);
794 taal_cancel_esd_work(dssdev);
795 td->esd_interval = t;
796 if (td->enabled)
797 taal_queue_esd_work(dssdev);
798 mutex_unlock(&td->lock);
800 return count;
803 static ssize_t taal_show_esd_interval(struct device *dev,
804 struct device_attribute *attr,
805 char *buf)
807 struct omap_dss_device *dssdev = to_dss_device(dev);
808 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
809 unsigned t;
811 mutex_lock(&td->lock);
812 t = td->esd_interval;
813 mutex_unlock(&td->lock);
815 return snprintf(buf, PAGE_SIZE, "%u\n", t);
818 static ssize_t taal_store_ulps(struct device *dev,
819 struct device_attribute *attr,
820 const char *buf, size_t count)
822 struct omap_dss_device *dssdev = to_dss_device(dev);
823 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
824 unsigned long t;
825 int r;
827 r = strict_strtoul(buf, 10, &t);
828 if (r)
829 return r;
831 mutex_lock(&td->lock);
833 if (td->enabled) {
834 dsi_bus_lock(dssdev);
836 if (t)
837 r = taal_enter_ulps(dssdev);
838 else
839 r = taal_wake_up(dssdev);
841 dsi_bus_unlock(dssdev);
844 mutex_unlock(&td->lock);
846 if (r)
847 return r;
849 return count;
852 static ssize_t taal_show_ulps(struct device *dev,
853 struct device_attribute *attr,
854 char *buf)
856 struct omap_dss_device *dssdev = to_dss_device(dev);
857 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
858 unsigned t;
860 mutex_lock(&td->lock);
861 t = td->ulps_enabled;
862 mutex_unlock(&td->lock);
864 return snprintf(buf, PAGE_SIZE, "%u\n", t);
867 static ssize_t taal_store_ulps_timeout(struct device *dev,
868 struct device_attribute *attr,
869 const char *buf, size_t count)
871 struct omap_dss_device *dssdev = to_dss_device(dev);
872 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
873 unsigned long t;
874 int r;
876 r = strict_strtoul(buf, 10, &t);
877 if (r)
878 return r;
880 mutex_lock(&td->lock);
881 td->ulps_timeout = t;
883 if (td->enabled) {
884 /* taal_wake_up will restart the timer */
885 dsi_bus_lock(dssdev);
886 r = taal_wake_up(dssdev);
887 dsi_bus_unlock(dssdev);
890 mutex_unlock(&td->lock);
892 if (r)
893 return r;
895 return count;
898 static ssize_t taal_show_ulps_timeout(struct device *dev,
899 struct device_attribute *attr,
900 char *buf)
902 struct omap_dss_device *dssdev = to_dss_device(dev);
903 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
904 unsigned t;
906 mutex_lock(&td->lock);
907 t = td->ulps_timeout;
908 mutex_unlock(&td->lock);
910 return snprintf(buf, PAGE_SIZE, "%u\n", t);
913 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
914 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
915 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
916 show_cabc_mode, store_cabc_mode);
917 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
918 show_cabc_available_modes, NULL);
919 static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
920 taal_show_esd_interval, taal_store_esd_interval);
921 static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
922 taal_show_ulps, taal_store_ulps);
923 static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
924 taal_show_ulps_timeout, taal_store_ulps_timeout);
926 static struct attribute *taal_attrs[] = {
927 &dev_attr_num_dsi_errors.attr,
928 &dev_attr_hw_revision.attr,
929 &dev_attr_cabc_mode.attr,
930 &dev_attr_cabc_available_modes.attr,
931 &dev_attr_esd_interval.attr,
932 &dev_attr_ulps.attr,
933 &dev_attr_ulps_timeout.attr,
934 NULL,
937 static struct attribute_group taal_attr_group = {
938 .attrs = taal_attrs,
941 static void taal_hw_reset(struct omap_dss_device *dssdev)
943 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
944 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
946 if (panel_data->reset_gpio == -1)
947 return;
949 gpio_set_value(panel_data->reset_gpio, 1);
950 if (td->panel_config->reset_sequence.high)
951 udelay(td->panel_config->reset_sequence.high);
952 /* reset the panel */
953 gpio_set_value(panel_data->reset_gpio, 0);
954 /* assert reset */
955 if (td->panel_config->reset_sequence.low)
956 udelay(td->panel_config->reset_sequence.low);
957 gpio_set_value(panel_data->reset_gpio, 1);
958 /* wait after releasing reset */
959 if (td->panel_config->sleep.hw_reset)
960 msleep(td->panel_config->sleep.hw_reset);
963 static int taal_probe(struct omap_dss_device *dssdev)
965 struct backlight_properties props;
966 struct taal_data *td;
967 struct backlight_device *bldev;
968 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
969 struct panel_config *panel_config = NULL;
970 int r, i;
972 dev_dbg(&dssdev->dev, "probe\n");
974 if (!panel_data || !panel_data->name) {
975 r = -EINVAL;
976 goto err;
979 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
980 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
981 panel_config = &panel_configs[i];
982 break;
986 if (!panel_config) {
987 r = -EINVAL;
988 goto err;
991 dssdev->panel.config = OMAP_DSS_LCD_TFT;
992 dssdev->panel.timings = panel_config->timings;
993 dssdev->ctrl.pixel_size = 24;
995 td = kzalloc(sizeof(*td), GFP_KERNEL);
996 if (!td) {
997 r = -ENOMEM;
998 goto err;
1000 td->dssdev = dssdev;
1001 td->panel_config = panel_config;
1002 td->esd_interval = panel_data->esd_interval;
1003 td->ulps_enabled = false;
1004 td->ulps_timeout = panel_data->ulps_timeout;
1006 mutex_init(&td->lock);
1008 atomic_set(&td->do_update, 0);
1010 r = init_regulators(dssdev, panel_config->regulators,
1011 panel_config->num_regulators);
1012 if (r)
1013 goto err_reg;
1015 td->workqueue = create_singlethread_workqueue("taal_esd");
1016 if (td->workqueue == NULL) {
1017 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
1018 r = -ENOMEM;
1019 goto err_wq;
1021 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
1022 INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
1024 dev_set_drvdata(&dssdev->dev, td);
1026 taal_hw_reset(dssdev);
1028 /* if no platform set_backlight() defined, presume DSI backlight
1029 * control */
1030 memset(&props, 0, sizeof(struct backlight_properties));
1031 if (!panel_data->set_backlight)
1032 td->use_dsi_bl = true;
1034 if (td->use_dsi_bl)
1035 props.max_brightness = 255;
1036 else
1037 props.max_brightness = 127;
1039 props.type = BACKLIGHT_RAW;
1040 bldev = backlight_device_register(dev_name(&dssdev->dev), &dssdev->dev,
1041 dssdev, &taal_bl_ops, &props);
1042 if (IS_ERR(bldev)) {
1043 r = PTR_ERR(bldev);
1044 goto err_bl;
1047 td->bldev = bldev;
1049 bldev->props.fb_blank = FB_BLANK_UNBLANK;
1050 bldev->props.power = FB_BLANK_UNBLANK;
1051 if (td->use_dsi_bl)
1052 bldev->props.brightness = 255;
1053 else
1054 bldev->props.brightness = 127;
1056 taal_bl_update_status(bldev);
1058 if (panel_data->use_ext_te) {
1059 int gpio = panel_data->ext_te_gpio;
1061 r = gpio_request(gpio, "taal irq");
1062 if (r) {
1063 dev_err(&dssdev->dev, "GPIO request failed\n");
1064 goto err_gpio;
1067 gpio_direction_input(gpio);
1069 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
1070 IRQF_DISABLED | IRQF_TRIGGER_RISING,
1071 "taal vsync", dssdev);
1073 if (r) {
1074 dev_err(&dssdev->dev, "IRQ request failed\n");
1075 gpio_free(gpio);
1076 goto err_irq;
1079 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
1080 taal_te_timeout_work_callback);
1082 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
1085 r = omap_dsi_request_vc(dssdev, &td->channel);
1086 if (r) {
1087 dev_err(&dssdev->dev, "failed to get virtual channel\n");
1088 goto err_req_vc;
1091 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
1092 if (r) {
1093 dev_err(&dssdev->dev, "failed to set VC_ID\n");
1094 goto err_vc_id;
1097 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
1098 if (r) {
1099 dev_err(&dssdev->dev, "failed to create sysfs files\n");
1100 goto err_vc_id;
1103 return 0;
1105 err_vc_id:
1106 omap_dsi_release_vc(dssdev, td->channel);
1107 err_req_vc:
1108 if (panel_data->use_ext_te)
1109 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
1110 err_irq:
1111 if (panel_data->use_ext_te)
1112 gpio_free(panel_data->ext_te_gpio);
1113 err_gpio:
1114 backlight_device_unregister(bldev);
1115 err_bl:
1116 destroy_workqueue(td->workqueue);
1117 err_wq:
1118 free_regulators(panel_config->regulators, panel_config->num_regulators);
1119 err_reg:
1120 kfree(td);
1121 err:
1122 return r;
1125 static void __exit taal_remove(struct omap_dss_device *dssdev)
1127 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1128 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1129 struct backlight_device *bldev;
1131 dev_dbg(&dssdev->dev, "remove\n");
1133 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
1134 omap_dsi_release_vc(dssdev, td->channel);
1136 if (panel_data->use_ext_te) {
1137 int gpio = panel_data->ext_te_gpio;
1138 free_irq(gpio_to_irq(gpio), dssdev);
1139 gpio_free(gpio);
1142 bldev = td->bldev;
1143 bldev->props.power = FB_BLANK_POWERDOWN;
1144 taal_bl_update_status(bldev);
1145 backlight_device_unregister(bldev);
1147 taal_cancel_ulps_work(dssdev);
1148 taal_cancel_esd_work(dssdev);
1149 destroy_workqueue(td->workqueue);
1151 /* reset, to be sure that the panel is in a valid state */
1152 taal_hw_reset(dssdev);
1154 free_regulators(td->panel_config->regulators,
1155 td->panel_config->num_regulators);
1157 kfree(td);
1160 static int taal_power_on(struct omap_dss_device *dssdev)
1162 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1163 u8 id1, id2, id3;
1164 int r;
1166 r = omapdss_dsi_display_enable(dssdev);
1167 if (r) {
1168 dev_err(&dssdev->dev, "failed to enable DSI\n");
1169 goto err0;
1172 taal_hw_reset(dssdev);
1174 omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
1176 r = taal_sleep_out(td);
1177 if (r)
1178 goto err;
1180 r = taal_get_id(td, &id1, &id2, &id3);
1181 if (r)
1182 goto err;
1184 /* on early Taal revisions CABC is broken */
1185 if (td->panel_config->type == PANEL_TAAL &&
1186 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
1187 td->cabc_broken = true;
1189 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
1190 if (r)
1191 goto err;
1193 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
1194 (1<<2) | (1<<5)); /* BL | BCTRL */
1195 if (r)
1196 goto err;
1198 r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
1199 if (r)
1200 goto err;
1202 r = taal_set_addr_mode(td, td->rotate, td->mirror);
1203 if (r)
1204 goto err;
1206 if (!td->cabc_broken) {
1207 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
1208 if (r)
1209 goto err;
1212 r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
1213 if (r)
1214 goto err;
1216 r = _taal_enable_te(dssdev, td->te_enabled);
1217 if (r)
1218 goto err;
1220 td->enabled = 1;
1222 if (!td->intro_printed) {
1223 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
1224 td->panel_config->name, id1, id2, id3);
1225 if (td->cabc_broken)
1226 dev_info(&dssdev->dev,
1227 "old Taal version, CABC disabled\n");
1228 td->intro_printed = true;
1231 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
1233 return 0;
1234 err:
1235 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
1237 taal_hw_reset(dssdev);
1239 omapdss_dsi_display_disable(dssdev, true, false);
1240 err0:
1241 return r;
1244 static void taal_power_off(struct omap_dss_device *dssdev)
1246 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1247 int r;
1249 r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
1250 if (!r)
1251 r = taal_sleep_in(td);
1253 if (r) {
1254 dev_err(&dssdev->dev,
1255 "error disabling panel, issuing HW reset\n");
1256 taal_hw_reset(dssdev);
1259 omapdss_dsi_display_disable(dssdev, true, false);
1261 td->enabled = 0;
1264 static int taal_panel_reset(struct omap_dss_device *dssdev)
1266 dev_err(&dssdev->dev, "performing LCD reset\n");
1268 taal_power_off(dssdev);
1269 taal_hw_reset(dssdev);
1270 return taal_power_on(dssdev);
1273 static int taal_enable(struct omap_dss_device *dssdev)
1275 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1276 int r;
1278 dev_dbg(&dssdev->dev, "enable\n");
1280 mutex_lock(&td->lock);
1282 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
1283 r = -EINVAL;
1284 goto err;
1287 dsi_bus_lock(dssdev);
1289 r = taal_power_on(dssdev);
1291 dsi_bus_unlock(dssdev);
1293 if (r)
1294 goto err;
1296 taal_queue_esd_work(dssdev);
1298 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1300 mutex_unlock(&td->lock);
1302 return 0;
1303 err:
1304 dev_dbg(&dssdev->dev, "enable failed\n");
1305 mutex_unlock(&td->lock);
1306 return r;
1309 static void taal_disable(struct omap_dss_device *dssdev)
1311 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1313 dev_dbg(&dssdev->dev, "disable\n");
1315 mutex_lock(&td->lock);
1317 taal_cancel_ulps_work(dssdev);
1318 taal_cancel_esd_work(dssdev);
1320 dsi_bus_lock(dssdev);
1322 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
1323 int r;
1325 r = taal_wake_up(dssdev);
1326 if (!r)
1327 taal_power_off(dssdev);
1330 dsi_bus_unlock(dssdev);
1332 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1334 mutex_unlock(&td->lock);
1337 static int taal_suspend(struct omap_dss_device *dssdev)
1339 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1340 int r;
1342 dev_dbg(&dssdev->dev, "suspend\n");
1344 mutex_lock(&td->lock);
1346 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1347 r = -EINVAL;
1348 goto err;
1351 taal_cancel_ulps_work(dssdev);
1352 taal_cancel_esd_work(dssdev);
1354 dsi_bus_lock(dssdev);
1356 r = taal_wake_up(dssdev);
1357 if (!r)
1358 taal_power_off(dssdev);
1360 dsi_bus_unlock(dssdev);
1362 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1364 mutex_unlock(&td->lock);
1366 return 0;
1367 err:
1368 mutex_unlock(&td->lock);
1369 return r;
1372 static int taal_resume(struct omap_dss_device *dssdev)
1374 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1375 int r;
1377 dev_dbg(&dssdev->dev, "resume\n");
1379 mutex_lock(&td->lock);
1381 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1382 r = -EINVAL;
1383 goto err;
1386 dsi_bus_lock(dssdev);
1388 r = taal_power_on(dssdev);
1390 dsi_bus_unlock(dssdev);
1392 if (r) {
1393 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1394 } else {
1395 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1396 taal_queue_esd_work(dssdev);
1399 mutex_unlock(&td->lock);
1401 return r;
1402 err:
1403 mutex_unlock(&td->lock);
1404 return r;
1407 static void taal_framedone_cb(int err, void *data)
1409 struct omap_dss_device *dssdev = data;
1410 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1411 dsi_bus_unlock(dssdev);
1414 static irqreturn_t taal_te_isr(int irq, void *data)
1416 struct omap_dss_device *dssdev = data;
1417 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1418 int old;
1419 int r;
1421 old = atomic_cmpxchg(&td->do_update, 1, 0);
1423 if (old) {
1424 cancel_delayed_work(&td->te_timeout_work);
1426 r = omap_dsi_update(dssdev, td->channel,
1427 td->update_region.x,
1428 td->update_region.y,
1429 td->update_region.w,
1430 td->update_region.h,
1431 taal_framedone_cb, dssdev);
1432 if (r)
1433 goto err;
1436 return IRQ_HANDLED;
1437 err:
1438 dev_err(&dssdev->dev, "start update failed\n");
1439 dsi_bus_unlock(dssdev);
1440 return IRQ_HANDLED;
1443 static void taal_te_timeout_work_callback(struct work_struct *work)
1445 struct taal_data *td = container_of(work, struct taal_data,
1446 te_timeout_work.work);
1447 struct omap_dss_device *dssdev = td->dssdev;
1449 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1451 atomic_set(&td->do_update, 0);
1452 dsi_bus_unlock(dssdev);
1455 static int taal_update(struct omap_dss_device *dssdev,
1456 u16 x, u16 y, u16 w, u16 h)
1458 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1459 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1460 int r;
1462 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1464 mutex_lock(&td->lock);
1465 dsi_bus_lock(dssdev);
1467 r = taal_wake_up(dssdev);
1468 if (r)
1469 goto err;
1471 if (!td->enabled) {
1472 r = 0;
1473 goto err;
1476 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
1477 if (r)
1478 goto err;
1480 r = taal_set_update_window(td, x, y, w, h);
1481 if (r)
1482 goto err;
1484 if (td->te_enabled && panel_data->use_ext_te) {
1485 td->update_region.x = x;
1486 td->update_region.y = y;
1487 td->update_region.w = w;
1488 td->update_region.h = h;
1489 barrier();
1490 schedule_delayed_work(&td->te_timeout_work,
1491 msecs_to_jiffies(250));
1492 atomic_set(&td->do_update, 1);
1493 } else {
1494 r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
1495 taal_framedone_cb, dssdev);
1496 if (r)
1497 goto err;
1500 /* note: no bus_unlock here. unlock is in framedone_cb */
1501 mutex_unlock(&td->lock);
1502 return 0;
1503 err:
1504 dsi_bus_unlock(dssdev);
1505 mutex_unlock(&td->lock);
1506 return r;
1509 static int taal_sync(struct omap_dss_device *dssdev)
1511 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1513 dev_dbg(&dssdev->dev, "sync\n");
1515 mutex_lock(&td->lock);
1516 dsi_bus_lock(dssdev);
1517 dsi_bus_unlock(dssdev);
1518 mutex_unlock(&td->lock);
1520 dev_dbg(&dssdev->dev, "sync done\n");
1522 return 0;
1525 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1527 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1528 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1529 int r;
1531 if (enable)
1532 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1533 else
1534 r = taal_dcs_write_0(td, DCS_TEAR_OFF);
1536 if (!panel_data->use_ext_te)
1537 omapdss_dsi_enable_te(dssdev, enable);
1539 if (td->panel_config->sleep.enable_te)
1540 msleep(td->panel_config->sleep.enable_te);
1542 return r;
1545 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1547 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1548 int r;
1550 mutex_lock(&td->lock);
1552 if (td->te_enabled == enable)
1553 goto end;
1555 dsi_bus_lock(dssdev);
1557 if (td->enabled) {
1558 r = taal_wake_up(dssdev);
1559 if (r)
1560 goto err;
1562 r = _taal_enable_te(dssdev, enable);
1563 if (r)
1564 goto err;
1567 td->te_enabled = enable;
1569 dsi_bus_unlock(dssdev);
1570 end:
1571 mutex_unlock(&td->lock);
1573 return 0;
1574 err:
1575 dsi_bus_unlock(dssdev);
1576 mutex_unlock(&td->lock);
1578 return r;
1581 static int taal_get_te(struct omap_dss_device *dssdev)
1583 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1584 int r;
1586 mutex_lock(&td->lock);
1587 r = td->te_enabled;
1588 mutex_unlock(&td->lock);
1590 return r;
1593 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1595 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1596 int r;
1598 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1600 mutex_lock(&td->lock);
1602 if (td->rotate == rotate)
1603 goto end;
1605 dsi_bus_lock(dssdev);
1607 if (td->enabled) {
1608 r = taal_wake_up(dssdev);
1609 if (r)
1610 goto err;
1612 r = taal_set_addr_mode(td, rotate, td->mirror);
1613 if (r)
1614 goto err;
1617 td->rotate = rotate;
1619 dsi_bus_unlock(dssdev);
1620 end:
1621 mutex_unlock(&td->lock);
1622 return 0;
1623 err:
1624 dsi_bus_unlock(dssdev);
1625 mutex_unlock(&td->lock);
1626 return r;
1629 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1631 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1632 int r;
1634 mutex_lock(&td->lock);
1635 r = td->rotate;
1636 mutex_unlock(&td->lock);
1638 return r;
1641 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1643 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1644 int r;
1646 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1648 mutex_lock(&td->lock);
1650 if (td->mirror == enable)
1651 goto end;
1653 dsi_bus_lock(dssdev);
1654 if (td->enabled) {
1655 r = taal_wake_up(dssdev);
1656 if (r)
1657 goto err;
1659 r = taal_set_addr_mode(td, td->rotate, enable);
1660 if (r)
1661 goto err;
1664 td->mirror = enable;
1666 dsi_bus_unlock(dssdev);
1667 end:
1668 mutex_unlock(&td->lock);
1669 return 0;
1670 err:
1671 dsi_bus_unlock(dssdev);
1672 mutex_unlock(&td->lock);
1673 return r;
1676 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1678 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1679 int r;
1681 mutex_lock(&td->lock);
1682 r = td->mirror;
1683 mutex_unlock(&td->lock);
1685 return r;
1688 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1690 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1691 u8 id1, id2, id3;
1692 int r;
1694 mutex_lock(&td->lock);
1696 if (!td->enabled) {
1697 r = -ENODEV;
1698 goto err1;
1701 dsi_bus_lock(dssdev);
1703 r = taal_wake_up(dssdev);
1704 if (r)
1705 goto err2;
1707 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1708 if (r)
1709 goto err2;
1710 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1711 if (r)
1712 goto err2;
1713 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1714 if (r)
1715 goto err2;
1717 dsi_bus_unlock(dssdev);
1718 mutex_unlock(&td->lock);
1719 return 0;
1720 err2:
1721 dsi_bus_unlock(dssdev);
1722 err1:
1723 mutex_unlock(&td->lock);
1724 return r;
1727 static int taal_memory_read(struct omap_dss_device *dssdev,
1728 void *buf, size_t size,
1729 u16 x, u16 y, u16 w, u16 h)
1731 int r;
1732 int first = 1;
1733 int plen;
1734 unsigned buf_used = 0;
1735 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1737 if (size < w * h * 3)
1738 return -ENOMEM;
1740 mutex_lock(&td->lock);
1742 if (!td->enabled) {
1743 r = -ENODEV;
1744 goto err1;
1747 size = min(w * h * 3,
1748 dssdev->panel.timings.x_res *
1749 dssdev->panel.timings.y_res * 3);
1751 dsi_bus_lock(dssdev);
1753 r = taal_wake_up(dssdev);
1754 if (r)
1755 goto err2;
1757 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1758 * use short packets. plen 32 works, but bigger packets seem to cause
1759 * an error. */
1760 if (size % 2)
1761 plen = 1;
1762 else
1763 plen = 2;
1765 taal_set_update_window(td, x, y, w, h);
1767 r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
1768 if (r)
1769 goto err2;
1771 while (buf_used < size) {
1772 u8 dcs_cmd = first ? 0x2e : 0x3e;
1773 first = 0;
1775 r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
1776 buf + buf_used, size - buf_used);
1778 if (r < 0) {
1779 dev_err(&dssdev->dev, "read error\n");
1780 goto err3;
1783 buf_used += r;
1785 if (r < plen) {
1786 dev_err(&dssdev->dev, "short read\n");
1787 break;
1790 if (signal_pending(current)) {
1791 dev_err(&dssdev->dev, "signal pending, "
1792 "aborting memory read\n");
1793 r = -ERESTARTSYS;
1794 goto err3;
1798 r = buf_used;
1800 err3:
1801 dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
1802 err2:
1803 dsi_bus_unlock(dssdev);
1804 err1:
1805 mutex_unlock(&td->lock);
1806 return r;
1809 static void taal_ulps_work(struct work_struct *work)
1811 struct taal_data *td = container_of(work, struct taal_data,
1812 ulps_work.work);
1813 struct omap_dss_device *dssdev = td->dssdev;
1815 mutex_lock(&td->lock);
1817 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
1818 mutex_unlock(&td->lock);
1819 return;
1822 dsi_bus_lock(dssdev);
1824 taal_enter_ulps(dssdev);
1826 dsi_bus_unlock(dssdev);
1827 mutex_unlock(&td->lock);
1830 static void taal_esd_work(struct work_struct *work)
1832 struct taal_data *td = container_of(work, struct taal_data,
1833 esd_work.work);
1834 struct omap_dss_device *dssdev = td->dssdev;
1835 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1836 u8 state1, state2;
1837 int r;
1839 mutex_lock(&td->lock);
1841 if (!td->enabled) {
1842 mutex_unlock(&td->lock);
1843 return;
1846 dsi_bus_lock(dssdev);
1848 r = taal_wake_up(dssdev);
1849 if (r) {
1850 dev_err(&dssdev->dev, "failed to exit ULPS\n");
1851 goto err;
1854 r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
1855 if (r) {
1856 dev_err(&dssdev->dev, "failed to read Taal status\n");
1857 goto err;
1860 /* Run self diagnostics */
1861 r = taal_sleep_out(td);
1862 if (r) {
1863 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1864 goto err;
1867 r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
1868 if (r) {
1869 dev_err(&dssdev->dev, "failed to read Taal status\n");
1870 goto err;
1873 /* Each sleep out command will trigger a self diagnostic and flip
1874 * Bit6 if the test passes.
1876 if (!((state1 ^ state2) & (1 << 6))) {
1877 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1878 goto err;
1880 /* Self-diagnostics result is also shown on TE GPIO line. We need
1881 * to re-enable TE after self diagnostics */
1882 if (td->te_enabled && panel_data->use_ext_te) {
1883 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1884 if (r)
1885 goto err;
1888 dsi_bus_unlock(dssdev);
1890 taal_queue_esd_work(dssdev);
1892 mutex_unlock(&td->lock);
1893 return;
1894 err:
1895 dev_err(&dssdev->dev, "performing LCD reset\n");
1897 taal_panel_reset(dssdev);
1899 dsi_bus_unlock(dssdev);
1901 taal_queue_esd_work(dssdev);
1903 mutex_unlock(&td->lock);
1906 static struct omap_dss_driver taal_driver = {
1907 .probe = taal_probe,
1908 .remove = __exit_p(taal_remove),
1910 .enable = taal_enable,
1911 .disable = taal_disable,
1912 .suspend = taal_suspend,
1913 .resume = taal_resume,
1915 .update = taal_update,
1916 .sync = taal_sync,
1918 .get_resolution = taal_get_resolution,
1919 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1921 .enable_te = taal_enable_te,
1922 .get_te = taal_get_te,
1924 .set_rotate = taal_rotate,
1925 .get_rotate = taal_get_rotate,
1926 .set_mirror = taal_mirror,
1927 .get_mirror = taal_get_mirror,
1928 .run_test = taal_run_test,
1929 .memory_read = taal_memory_read,
1931 .get_timings = taal_get_timings,
1933 .driver = {
1934 .name = "taal",
1935 .owner = THIS_MODULE,
1939 static int __init taal_init(void)
1941 omap_dss_register_driver(&taal_driver);
1943 return 0;
1946 static void __exit taal_exit(void)
1948 omap_dss_unregister_driver(&taal_driver);
1951 module_init(taal_init);
1952 module_exit(taal_exit);
1954 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1955 MODULE_DESCRIPTION("Taal Driver");
1956 MODULE_LICENSE("GPL");