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
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/>.
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>
29 #include <linux/interrupt.h>
30 #include <linux/gpio.h>
31 #include <linux/completion.h>
32 #include <linux/workqueue.h>
33 #include <linux/slab.h>
34 #include <linux/mutex.h>
36 #include <plat/display.h>
38 /* DSI Virtual channel. Hardcoded for now. */
41 #define DCS_READ_NUM_ERRORS 0x05
42 #define DCS_READ_POWER_MODE 0x0a
43 #define DCS_READ_MADCTL 0x0b
44 #define DCS_READ_PIXEL_FORMAT 0x0c
45 #define DCS_RDDSDR 0x0f
46 #define DCS_SLEEP_IN 0x10
47 #define DCS_SLEEP_OUT 0x11
48 #define DCS_DISPLAY_OFF 0x28
49 #define DCS_DISPLAY_ON 0x29
50 #define DCS_COLUMN_ADDR 0x2a
51 #define DCS_PAGE_ADDR 0x2b
52 #define DCS_MEMORY_WRITE 0x2c
53 #define DCS_TEAR_OFF 0x34
54 #define DCS_TEAR_ON 0x35
55 #define DCS_MEM_ACC_CTRL 0x36
56 #define DCS_PIXEL_FORMAT 0x3a
57 #define DCS_BRIGHTNESS 0x51
58 #define DCS_CTRL_DISPLAY 0x53
59 #define DCS_WRITE_CABC 0x55
60 #define DCS_READ_CABC 0x56
61 #define DCS_GET_ID1 0xda
62 #define DCS_GET_ID2 0xdb
63 #define DCS_GET_ID3 0xdc
65 /* #define TAAL_USE_ESD_CHECK */
66 #define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000)
68 static int _taal_enable_te(struct omap_dss_device
*dssdev
, bool enable
);
73 struct backlight_device
*bldev
;
75 unsigned long hw_guard_end
; /* next value of jiffies when we can
76 * issue the next sleep in/out command
78 unsigned long hw_guard_wait
; /* max guard time in jiffies */
80 struct omap_dss_device
*dssdev
;
88 struct completion te_completion
;
97 struct workqueue_struct
*esd_wq
;
98 struct delayed_work esd_work
;
101 static void taal_esd_work(struct work_struct
*work
);
103 static void hw_guard_start(struct taal_data
*td
, int guard_msec
)
105 td
->hw_guard_wait
= msecs_to_jiffies(guard_msec
);
106 td
->hw_guard_end
= jiffies
+ td
->hw_guard_wait
;
109 static void hw_guard_wait(struct taal_data
*td
)
111 unsigned long wait
= td
->hw_guard_end
- jiffies
;
113 if ((long)wait
> 0 && wait
<= td
->hw_guard_wait
) {
114 set_current_state(TASK_UNINTERRUPTIBLE
);
115 schedule_timeout(wait
);
119 static int taal_dcs_read_1(u8 dcs_cmd
, u8
*data
)
124 r
= dsi_vc_dcs_read(TCH
, dcs_cmd
, buf
, 1);
134 static int taal_dcs_write_0(u8 dcs_cmd
)
136 return dsi_vc_dcs_write(TCH
, &dcs_cmd
, 1);
139 static int taal_dcs_write_1(u8 dcs_cmd
, u8 param
)
144 return dsi_vc_dcs_write(TCH
, buf
, 2);
147 static int taal_sleep_in(struct taal_data
*td
)
156 r
= dsi_vc_dcs_write_nosync(TCH
, &cmd
, 1);
160 hw_guard_start(td
, 120);
167 static int taal_sleep_out(struct taal_data
*td
)
173 r
= taal_dcs_write_0(DCS_SLEEP_OUT
);
177 hw_guard_start(td
, 120);
184 static int taal_get_id(u8
*id1
, u8
*id2
, u8
*id3
)
188 r
= taal_dcs_read_1(DCS_GET_ID1
, id1
);
191 r
= taal_dcs_read_1(DCS_GET_ID2
, id2
);
194 r
= taal_dcs_read_1(DCS_GET_ID3
, id3
);
201 static int taal_set_addr_mode(u8 rotate
, bool mirror
)
207 r
= taal_dcs_read_1(DCS_READ_MADCTL
, &mode
);
238 mode
&= ~((1<<7) | (1<<6) | (1<<5));
239 mode
|= (b7
<< 7) | (b6
<< 6) | (b5
<< 5);
241 return taal_dcs_write_1(DCS_MEM_ACC_CTRL
, mode
);
244 static int taal_set_update_window(u16 x
, u16 y
, u16 w
, u16 h
)
253 buf
[0] = DCS_COLUMN_ADDR
;
254 buf
[1] = (x1
>> 8) & 0xff;
255 buf
[2] = (x1
>> 0) & 0xff;
256 buf
[3] = (x2
>> 8) & 0xff;
257 buf
[4] = (x2
>> 0) & 0xff;
259 r
= dsi_vc_dcs_write_nosync(TCH
, buf
, sizeof(buf
));
263 buf
[0] = DCS_PAGE_ADDR
;
264 buf
[1] = (y1
>> 8) & 0xff;
265 buf
[2] = (y1
>> 0) & 0xff;
266 buf
[3] = (y2
>> 8) & 0xff;
267 buf
[4] = (y2
>> 0) & 0xff;
269 r
= dsi_vc_dcs_write_nosync(TCH
, buf
, sizeof(buf
));
273 dsi_vc_send_bta_sync(TCH
);
278 static int taal_bl_update_status(struct backlight_device
*dev
)
280 struct omap_dss_device
*dssdev
= dev_get_drvdata(&dev
->dev
);
281 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
285 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
286 dev
->props
.power
== FB_BLANK_UNBLANK
)
287 level
= dev
->props
.brightness
;
291 dev_dbg(&dssdev
->dev
, "update brightness to %d\n", level
);
293 mutex_lock(&td
->lock
);
295 if (td
->use_dsi_bl
) {
298 r
= taal_dcs_write_1(DCS_BRIGHTNESS
, level
);
304 if (!dssdev
->set_backlight
)
307 r
= dssdev
->set_backlight(dssdev
, level
);
310 mutex_unlock(&td
->lock
);
315 static int taal_bl_get_intensity(struct backlight_device
*dev
)
317 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
318 dev
->props
.power
== FB_BLANK_UNBLANK
)
319 return dev
->props
.brightness
;
324 static struct backlight_ops taal_bl_ops
= {
325 .get_brightness
= taal_bl_get_intensity
,
326 .update_status
= taal_bl_update_status
,
329 static void taal_get_timings(struct omap_dss_device
*dssdev
,
330 struct omap_video_timings
*timings
)
332 *timings
= dssdev
->panel
.timings
;
335 static void taal_get_resolution(struct omap_dss_device
*dssdev
,
336 u16
*xres
, u16
*yres
)
338 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
340 if (td
->rotate
== 0 || td
->rotate
== 2) {
341 *xres
= dssdev
->panel
.timings
.x_res
;
342 *yres
= dssdev
->panel
.timings
.y_res
;
344 *yres
= dssdev
->panel
.timings
.x_res
;
345 *xres
= dssdev
->panel
.timings
.y_res
;
349 static irqreturn_t
taal_te_isr(int irq
, void *data
)
351 struct omap_dss_device
*dssdev
= data
;
352 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
354 complete_all(&td
->te_completion
);
359 static ssize_t
taal_num_errors_show(struct device
*dev
,
360 struct device_attribute
*attr
, char *buf
)
362 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
363 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
367 mutex_lock(&td
->lock
);
371 r
= taal_dcs_read_1(DCS_READ_NUM_ERRORS
, &errors
);
377 mutex_unlock(&td
->lock
);
382 return snprintf(buf
, PAGE_SIZE
, "%d\n", errors
);
385 static ssize_t
taal_hw_revision_show(struct device
*dev
,
386 struct device_attribute
*attr
, char *buf
)
388 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
389 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
393 mutex_lock(&td
->lock
);
397 r
= taal_get_id(&id1
, &id2
, &id3
);
403 mutex_unlock(&td
->lock
);
408 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x\n", id1
, id2
, id3
);
411 static const char *cabc_modes
[] = {
412 "off", /* used also always when CABC is not supported */
418 static ssize_t
show_cabc_mode(struct device
*dev
,
419 struct device_attribute
*attr
,
422 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
423 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
424 const char *mode_str
;
428 mode
= td
->cabc_mode
;
430 mode_str
= "unknown";
431 if (mode
>= 0 && mode
< ARRAY_SIZE(cabc_modes
))
432 mode_str
= cabc_modes
[mode
];
433 len
= snprintf(buf
, PAGE_SIZE
, "%s\n", mode_str
);
435 return len
< PAGE_SIZE
- 1 ? len
: PAGE_SIZE
- 1;
438 static ssize_t
store_cabc_mode(struct device
*dev
,
439 struct device_attribute
*attr
,
440 const char *buf
, size_t count
)
442 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
443 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
446 for (i
= 0; i
< ARRAY_SIZE(cabc_modes
); i
++) {
447 if (sysfs_streq(cabc_modes
[i
], buf
))
451 if (i
== ARRAY_SIZE(cabc_modes
))
454 mutex_lock(&td
->lock
);
458 if (!td
->cabc_broken
)
459 taal_dcs_write_1(DCS_WRITE_CABC
, i
);
465 mutex_unlock(&td
->lock
);
470 static ssize_t
show_cabc_available_modes(struct device
*dev
,
471 struct device_attribute
*attr
,
478 len
< PAGE_SIZE
&& i
< ARRAY_SIZE(cabc_modes
); i
++)
479 len
+= snprintf(&buf
[len
], PAGE_SIZE
- len
, "%s%s%s",
480 i
? " " : "", cabc_modes
[i
],
481 i
== ARRAY_SIZE(cabc_modes
) - 1 ? "\n" : "");
483 return len
< PAGE_SIZE
? len
: PAGE_SIZE
- 1;
486 static DEVICE_ATTR(num_dsi_errors
, S_IRUGO
, taal_num_errors_show
, NULL
);
487 static DEVICE_ATTR(hw_revision
, S_IRUGO
, taal_hw_revision_show
, NULL
);
488 static DEVICE_ATTR(cabc_mode
, S_IRUGO
| S_IWUSR
,
489 show_cabc_mode
, store_cabc_mode
);
490 static DEVICE_ATTR(cabc_available_modes
, S_IRUGO
,
491 show_cabc_available_modes
, NULL
);
493 static struct attribute
*taal_attrs
[] = {
494 &dev_attr_num_dsi_errors
.attr
,
495 &dev_attr_hw_revision
.attr
,
496 &dev_attr_cabc_mode
.attr
,
497 &dev_attr_cabc_available_modes
.attr
,
501 static struct attribute_group taal_attr_group
= {
505 static void taal_hw_reset(struct omap_dss_device
*dssdev
)
507 if (dssdev
->reset_gpio
== -1)
510 gpio_set_value(dssdev
->reset_gpio
, 1);
512 /* reset the panel */
513 gpio_set_value(dssdev
->reset_gpio
, 0);
514 /* assert reset for at least 10us */
516 gpio_set_value(dssdev
->reset_gpio
, 1);
517 /* wait 5ms after releasing reset */
521 static int taal_probe(struct omap_dss_device
*dssdev
)
523 struct backlight_properties props
;
524 struct taal_data
*td
;
525 struct backlight_device
*bldev
;
528 const struct omap_video_timings taal_panel_timings
= {
533 dev_dbg(&dssdev
->dev
, "probe\n");
535 dssdev
->panel
.config
= OMAP_DSS_LCD_TFT
;
536 dssdev
->panel
.timings
= taal_panel_timings
;
537 dssdev
->ctrl
.pixel_size
= 24;
539 td
= kzalloc(sizeof(*td
), GFP_KERNEL
);
546 mutex_init(&td
->lock
);
548 td
->esd_wq
= create_singlethread_workqueue("taal_esd");
549 if (td
->esd_wq
== NULL
) {
550 dev_err(&dssdev
->dev
, "can't create ESD workqueue\n");
554 INIT_DELAYED_WORK_DEFERRABLE(&td
->esd_work
, taal_esd_work
);
556 dev_set_drvdata(&dssdev
->dev
, td
);
558 taal_hw_reset(dssdev
);
560 /* if no platform set_backlight() defined, presume DSI backlight
562 memset(&props
, 0, sizeof(struct backlight_properties
));
563 if (!dssdev
->set_backlight
)
564 td
->use_dsi_bl
= true;
567 props
.max_brightness
= 255;
569 props
.max_brightness
= 127;
570 bldev
= backlight_device_register("taal", &dssdev
->dev
, dssdev
,
571 &taal_bl_ops
, &props
);
579 bldev
->props
.fb_blank
= FB_BLANK_UNBLANK
;
580 bldev
->props
.power
= FB_BLANK_UNBLANK
;
582 bldev
->props
.brightness
= 255;
584 bldev
->props
.brightness
= 127;
586 taal_bl_update_status(bldev
);
588 if (dssdev
->phy
.dsi
.ext_te
) {
589 int gpio
= dssdev
->phy
.dsi
.ext_te_gpio
;
591 r
= gpio_request(gpio
, "taal irq");
593 dev_err(&dssdev
->dev
, "GPIO request failed\n");
597 gpio_direction_input(gpio
);
599 r
= request_irq(gpio_to_irq(gpio
), taal_te_isr
,
600 IRQF_DISABLED
| IRQF_TRIGGER_RISING
,
601 "taal vsync", dssdev
);
604 dev_err(&dssdev
->dev
, "IRQ request failed\n");
609 init_completion(&td
->te_completion
);
611 td
->use_ext_te
= true;
614 r
= sysfs_create_group(&dssdev
->dev
.kobj
, &taal_attr_group
);
616 dev_err(&dssdev
->dev
, "failed to create sysfs files\n");
623 free_irq(gpio_to_irq(dssdev
->phy
.dsi
.ext_te_gpio
), dssdev
);
626 gpio_free(dssdev
->phy
.dsi
.ext_te_gpio
);
628 backlight_device_unregister(bldev
);
630 destroy_workqueue(td
->esd_wq
);
637 static void taal_remove(struct omap_dss_device
*dssdev
)
639 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
640 struct backlight_device
*bldev
;
642 dev_dbg(&dssdev
->dev
, "remove\n");
644 sysfs_remove_group(&dssdev
->dev
.kobj
, &taal_attr_group
);
646 if (td
->use_ext_te
) {
647 int gpio
= dssdev
->phy
.dsi
.ext_te_gpio
;
648 free_irq(gpio_to_irq(gpio
), dssdev
);
653 bldev
->props
.power
= FB_BLANK_POWERDOWN
;
654 taal_bl_update_status(bldev
);
655 backlight_device_unregister(bldev
);
657 cancel_delayed_work(&td
->esd_work
);
658 destroy_workqueue(td
->esd_wq
);
660 /* reset, to be sure that the panel is in a valid state */
661 taal_hw_reset(dssdev
);
666 static int taal_power_on(struct omap_dss_device
*dssdev
)
668 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
672 /* it seems we have to wait a bit until taal is ready */
675 r
= omapdss_dsi_display_enable(dssdev
);
677 dev_err(&dssdev
->dev
, "failed to enable DSI\n");
681 taal_hw_reset(dssdev
);
683 omapdss_dsi_vc_enable_hs(TCH
, false);
685 r
= taal_sleep_out(td
);
689 r
= taal_get_id(&id1
, &id2
, &id3
);
693 /* on early revisions CABC is broken */
694 if (id2
== 0x00 || id2
== 0xff || id2
== 0x81)
695 td
->cabc_broken
= true;
697 r
= taal_dcs_write_1(DCS_BRIGHTNESS
, 0xff);
701 r
= taal_dcs_write_1(DCS_CTRL_DISPLAY
,
702 (1<<2) | (1<<5)); /* BL | BCTRL */
706 r
= taal_dcs_write_1(DCS_PIXEL_FORMAT
, 0x7); /* 24bit/pixel */
710 r
= taal_set_addr_mode(td
->rotate
, td
->mirror
);
714 if (!td
->cabc_broken
) {
715 r
= taal_dcs_write_1(DCS_WRITE_CABC
, td
->cabc_mode
);
720 r
= taal_dcs_write_0(DCS_DISPLAY_ON
);
724 r
= _taal_enable_te(dssdev
, td
->te_enabled
);
730 if (!td
->intro_printed
) {
731 dev_info(&dssdev
->dev
, "revision %02x.%02x.%02x\n",
734 dev_info(&dssdev
->dev
,
735 "old Taal version, CABC disabled\n");
736 td
->intro_printed
= true;
739 omapdss_dsi_vc_enable_hs(TCH
, true);
743 dev_err(&dssdev
->dev
, "error while enabling panel, issuing HW reset\n");
745 taal_hw_reset(dssdev
);
747 omapdss_dsi_display_disable(dssdev
);
752 static void taal_power_off(struct omap_dss_device
*dssdev
)
754 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
757 r
= taal_dcs_write_0(DCS_DISPLAY_OFF
);
759 r
= taal_sleep_in(td
);
760 /* wait a bit so that the message goes through */
765 dev_err(&dssdev
->dev
,
766 "error disabling panel, issuing HW reset\n");
767 taal_hw_reset(dssdev
);
770 omapdss_dsi_display_disable(dssdev
);
775 static int taal_enable(struct omap_dss_device
*dssdev
)
777 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
780 dev_dbg(&dssdev
->dev
, "enable\n");
782 mutex_lock(&td
->lock
);
784 if (dssdev
->state
!= OMAP_DSS_DISPLAY_DISABLED
) {
791 r
= taal_power_on(dssdev
);
798 #ifdef TAAL_USE_ESD_CHECK
799 queue_delayed_work(td
->esd_wq
, &td
->esd_work
, TAAL_ESD_CHECK_PERIOD
);
802 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
804 mutex_unlock(&td
->lock
);
808 dev_dbg(&dssdev
->dev
, "enable failed\n");
809 mutex_unlock(&td
->lock
);
813 static void taal_disable(struct omap_dss_device
*dssdev
)
815 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
817 dev_dbg(&dssdev
->dev
, "disable\n");
819 mutex_lock(&td
->lock
);
821 cancel_delayed_work(&td
->esd_work
);
825 if (dssdev
->state
== OMAP_DSS_DISPLAY_ACTIVE
)
826 taal_power_off(dssdev
);
830 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
832 mutex_unlock(&td
->lock
);
835 static int taal_suspend(struct omap_dss_device
*dssdev
)
837 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
840 dev_dbg(&dssdev
->dev
, "suspend\n");
842 mutex_lock(&td
->lock
);
844 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
) {
849 cancel_delayed_work(&td
->esd_work
);
853 taal_power_off(dssdev
);
857 dssdev
->state
= OMAP_DSS_DISPLAY_SUSPENDED
;
859 mutex_unlock(&td
->lock
);
863 mutex_unlock(&td
->lock
);
867 static int taal_resume(struct omap_dss_device
*dssdev
)
869 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
872 dev_dbg(&dssdev
->dev
, "resume\n");
874 mutex_lock(&td
->lock
);
876 if (dssdev
->state
!= OMAP_DSS_DISPLAY_SUSPENDED
) {
883 r
= taal_power_on(dssdev
);
888 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
890 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
891 #ifdef TAAL_USE_ESD_CHECK
892 queue_delayed_work(td
->esd_wq
, &td
->esd_work
,
893 TAAL_ESD_CHECK_PERIOD
);
897 mutex_unlock(&td
->lock
);
901 mutex_unlock(&td
->lock
);
905 static void taal_framedone_cb(int err
, void *data
)
907 struct omap_dss_device
*dssdev
= data
;
908 dev_dbg(&dssdev
->dev
, "framedone, err %d\n", err
);
912 static int taal_update(struct omap_dss_device
*dssdev
,
913 u16 x
, u16 y
, u16 w
, u16 h
)
915 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
918 dev_dbg(&dssdev
->dev
, "update %d, %d, %d x %d\n", x
, y
, w
, h
);
920 mutex_lock(&td
->lock
);
928 r
= omap_dsi_prepare_update(dssdev
, &x
, &y
, &w
, &h
);
932 r
= taal_set_update_window(x
, y
, w
, h
);
936 r
= omap_dsi_update(dssdev
, TCH
, x
, y
, w
, h
,
937 taal_framedone_cb
, dssdev
);
941 /* note: no bus_unlock here. unlock is in framedone_cb */
942 mutex_unlock(&td
->lock
);
946 mutex_unlock(&td
->lock
);
950 static int taal_sync(struct omap_dss_device
*dssdev
)
952 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
954 dev_dbg(&dssdev
->dev
, "sync\n");
956 mutex_lock(&td
->lock
);
959 mutex_unlock(&td
->lock
);
961 dev_dbg(&dssdev
->dev
, "sync done\n");
966 static int _taal_enable_te(struct omap_dss_device
*dssdev
, bool enable
)
971 r
= taal_dcs_write_1(DCS_TEAR_ON
, 0);
973 r
= taal_dcs_write_0(DCS_TEAR_OFF
);
975 omapdss_dsi_enable_te(dssdev
, enable
);
977 /* XXX for some reason, DSI TE breaks if we don't wait here.
978 * Panel bug? Needs more studying */
984 static int taal_enable_te(struct omap_dss_device
*dssdev
, bool enable
)
986 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
989 mutex_lock(&td
->lock
);
993 r
= _taal_enable_te(dssdev
, enable
);
998 td
->te_enabled
= enable
;
1001 mutex_unlock(&td
->lock
);
1006 mutex_unlock(&td
->lock
);
1011 static int taal_get_te(struct omap_dss_device
*dssdev
)
1013 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
1016 mutex_lock(&td
->lock
);
1018 mutex_unlock(&td
->lock
);
1023 static int taal_rotate(struct omap_dss_device
*dssdev
, u8 rotate
)
1025 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
1028 dev_dbg(&dssdev
->dev
, "rotate %d\n", rotate
);
1030 mutex_lock(&td
->lock
);
1034 r
= taal_set_addr_mode(rotate
, td
->mirror
);
1039 td
->rotate
= rotate
;
1042 mutex_unlock(&td
->lock
);
1046 mutex_unlock(&td
->lock
);
1050 static u8
taal_get_rotate(struct omap_dss_device
*dssdev
)
1052 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
1055 mutex_lock(&td
->lock
);
1057 mutex_unlock(&td
->lock
);
1062 static int taal_mirror(struct omap_dss_device
*dssdev
, bool enable
)
1064 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
1067 dev_dbg(&dssdev
->dev
, "mirror %d\n", enable
);
1069 mutex_lock(&td
->lock
);
1072 r
= taal_set_addr_mode(td
->rotate
, enable
);
1077 td
->mirror
= enable
;
1080 mutex_unlock(&td
->lock
);
1084 mutex_unlock(&td
->lock
);
1088 static bool taal_get_mirror(struct omap_dss_device
*dssdev
)
1090 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
1093 mutex_lock(&td
->lock
);
1095 mutex_unlock(&td
->lock
);
1100 static int taal_run_test(struct omap_dss_device
*dssdev
, int test_num
)
1102 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
1106 mutex_lock(&td
->lock
);
1115 r
= taal_dcs_read_1(DCS_GET_ID1
, &id1
);
1118 r
= taal_dcs_read_1(DCS_GET_ID2
, &id2
);
1121 r
= taal_dcs_read_1(DCS_GET_ID3
, &id3
);
1126 mutex_unlock(&td
->lock
);
1131 mutex_unlock(&td
->lock
);
1135 static int taal_memory_read(struct omap_dss_device
*dssdev
,
1136 void *buf
, size_t size
,
1137 u16 x
, u16 y
, u16 w
, u16 h
)
1142 unsigned buf_used
= 0;
1143 struct taal_data
*td
= dev_get_drvdata(&dssdev
->dev
);
1145 if (size
< w
* h
* 3)
1148 mutex_lock(&td
->lock
);
1155 size
= min(w
* h
* 3,
1156 dssdev
->panel
.timings
.x_res
*
1157 dssdev
->panel
.timings
.y_res
* 3);
1161 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1162 * use short packets. plen 32 works, but bigger packets seem to cause
1169 taal_set_update_window(x
, y
, w
, h
);
1171 r
= dsi_vc_set_max_rx_packet_size(TCH
, plen
);
1175 while (buf_used
< size
) {
1176 u8 dcs_cmd
= first
? 0x2e : 0x3e;
1179 r
= dsi_vc_dcs_read(TCH
, dcs_cmd
,
1180 buf
+ buf_used
, size
- buf_used
);
1183 dev_err(&dssdev
->dev
, "read error\n");
1190 dev_err(&dssdev
->dev
, "short read\n");
1194 if (signal_pending(current
)) {
1195 dev_err(&dssdev
->dev
, "signal pending, "
1196 "aborting memory read\n");
1205 dsi_vc_set_max_rx_packet_size(TCH
, 1);
1209 mutex_unlock(&td
->lock
);
1213 static void taal_esd_work(struct work_struct
*work
)
1215 struct taal_data
*td
= container_of(work
, struct taal_data
,
1217 struct omap_dss_device
*dssdev
= td
->dssdev
;
1221 mutex_lock(&td
->lock
);
1224 mutex_unlock(&td
->lock
);
1230 r
= taal_dcs_read_1(DCS_RDDSDR
, &state1
);
1232 dev_err(&dssdev
->dev
, "failed to read Taal status\n");
1236 /* Run self diagnostics */
1237 r
= taal_sleep_out(td
);
1239 dev_err(&dssdev
->dev
, "failed to run Taal self-diagnostics\n");
1243 r
= taal_dcs_read_1(DCS_RDDSDR
, &state2
);
1245 dev_err(&dssdev
->dev
, "failed to read Taal status\n");
1249 /* Each sleep out command will trigger a self diagnostic and flip
1250 * Bit6 if the test passes.
1252 if (!((state1
^ state2
) & (1 << 6))) {
1253 dev_err(&dssdev
->dev
, "LCD self diagnostics failed\n");
1256 /* Self-diagnostics result is also shown on TE GPIO line. We need
1257 * to re-enable TE after self diagnostics */
1258 if (td
->use_ext_te
&& td
->te_enabled
) {
1259 r
= taal_dcs_write_1(DCS_TEAR_ON
, 0);
1266 queue_delayed_work(td
->esd_wq
, &td
->esd_work
, TAAL_ESD_CHECK_PERIOD
);
1268 mutex_unlock(&td
->lock
);
1271 dev_err(&dssdev
->dev
, "performing LCD reset\n");
1273 taal_power_off(dssdev
);
1274 taal_hw_reset(dssdev
);
1275 taal_power_on(dssdev
);
1279 queue_delayed_work(td
->esd_wq
, &td
->esd_work
, TAAL_ESD_CHECK_PERIOD
);
1281 mutex_unlock(&td
->lock
);
1284 static int taal_set_update_mode(struct omap_dss_device
*dssdev
,
1285 enum omap_dss_update_mode mode
)
1287 if (mode
!= OMAP_DSS_UPDATE_MANUAL
)
1292 static enum omap_dss_update_mode
taal_get_update_mode(
1293 struct omap_dss_device
*dssdev
)
1295 return OMAP_DSS_UPDATE_MANUAL
;
1298 static struct omap_dss_driver taal_driver
= {
1299 .probe
= taal_probe
,
1300 .remove
= taal_remove
,
1302 .enable
= taal_enable
,
1303 .disable
= taal_disable
,
1304 .suspend
= taal_suspend
,
1305 .resume
= taal_resume
,
1307 .set_update_mode
= taal_set_update_mode
,
1308 .get_update_mode
= taal_get_update_mode
,
1310 .update
= taal_update
,
1313 .get_resolution
= taal_get_resolution
,
1314 .get_recommended_bpp
= omapdss_default_get_recommended_bpp
,
1316 .enable_te
= taal_enable_te
,
1317 .get_te
= taal_get_te
,
1319 .set_rotate
= taal_rotate
,
1320 .get_rotate
= taal_get_rotate
,
1321 .set_mirror
= taal_mirror
,
1322 .get_mirror
= taal_get_mirror
,
1323 .run_test
= taal_run_test
,
1324 .memory_read
= taal_memory_read
,
1326 .get_timings
= taal_get_timings
,
1330 .owner
= THIS_MODULE
,
1334 static int __init
taal_init(void)
1336 omap_dss_register_driver(&taal_driver
);
1341 static void __exit
taal_exit(void)
1343 omap_dss_unregister_driver(&taal_driver
);
1346 module_init(taal_init
);
1347 module_exit(taal_exit
);
1349 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1350 MODULE_DESCRIPTION("Taal Driver");
1351 MODULE_LICENSE("GPL");