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/workqueue.h>
32 #include <linux/slab.h>
33 #include <linux/mutex.h>
35 #include <plat/display.h>
36 #include <plat/nokia-dsi-panel.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_ESD_CHECK_PERIOD msecs_to_jiffies(5000)
67 static irqreturn_t taal_te_isr(int irq, void *data);
68 static void taal_te_timeout_work_callback(struct work_struct *work);
69 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
74 struct backlight_device *bldev;
76 unsigned long hw_guard_end; /* next value of jiffies when we can
77 * issue the next sleep in/out command
79 unsigned long hw_guard_wait; /* max guard time in jiffies */
81 struct omap_dss_device *dssdev;
96 struct delayed_work te_timeout_work;
105 struct workqueue_struct *esd_wq;
106 struct delayed_work esd_work;
109 static inline struct nokia_dsi_panel_data
110 *get_panel_data(const struct omap_dss_device *dssdev)
112 return (struct nokia_dsi_panel_data *) dssdev->data;
115 static void taal_esd_work(struct work_struct *work);
117 static void hw_guard_start(struct taal_data *td, int guard_msec)
119 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
120 td->hw_guard_end = jiffies + td->hw_guard_wait;
123 static void hw_guard_wait(struct taal_data *td)
125 unsigned long wait = td->hw_guard_end - jiffies;
127 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
128 set_current_state(TASK_UNINTERRUPTIBLE);
129 schedule_timeout(wait);
133 static int taal_dcs_read_1(u8 dcs_cmd, u8 *data)
138 r = dsi_vc_dcs_read(TCH, dcs_cmd, buf, 1);
148 static int taal_dcs_write_0(u8 dcs_cmd)
150 return dsi_vc_dcs_write(TCH, &dcs_cmd, 1);
153 static int taal_dcs_write_1(u8 dcs_cmd, u8 param)
158 return dsi_vc_dcs_write(TCH, buf, 2);
161 static int taal_sleep_in(struct taal_data *td)
170 r = dsi_vc_dcs_write_nosync(TCH, &cmd, 1);
174 hw_guard_start(td, 120);
181 static int taal_sleep_out(struct taal_data *td)
187 r = taal_dcs_write_0(DCS_SLEEP_OUT);
191 hw_guard_start(td, 120);
198 static int taal_get_id(u8 *id1, u8 *id2, u8 *id3)
202 r = taal_dcs_read_1(DCS_GET_ID1, id1);
205 r = taal_dcs_read_1(DCS_GET_ID2, id2);
208 r = taal_dcs_read_1(DCS_GET_ID3, id3);
215 static int taal_set_addr_mode(u8 rotate, bool mirror)
221 r = taal_dcs_read_1(DCS_READ_MADCTL, &mode);
252 mode &= ~((1<<7) | (1<<6) | (1<<5));
253 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
255 return taal_dcs_write_1(DCS_MEM_ACC_CTRL, mode);
258 static int taal_set_update_window(u16 x, u16 y, u16 w, u16 h)
267 buf[0] = DCS_COLUMN_ADDR;
268 buf[1] = (x1 >> 8) & 0xff;
269 buf[2] = (x1 >> 0) & 0xff;
270 buf[3] = (x2 >> 8) & 0xff;
271 buf[4] = (x2 >> 0) & 0xff;
273 r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
277 buf[0] = DCS_PAGE_ADDR;
278 buf[1] = (y1 >> 8) & 0xff;
279 buf[2] = (y1 >> 0) & 0xff;
280 buf[3] = (y2 >> 8) & 0xff;
281 buf[4] = (y2 >> 0) & 0xff;
283 r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
287 dsi_vc_send_bta_sync(TCH);
292 static int taal_bl_update_status(struct backlight_device *dev)
294 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
295 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
296 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
300 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
301 dev->props.power == FB_BLANK_UNBLANK)
302 level = dev->props.brightness;
306 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
308 mutex_lock(&td->lock);
310 if (td->use_dsi_bl) {
313 r = taal_dcs_write_1(DCS_BRIGHTNESS, level);
319 if (!panel_data->set_backlight)
322 r = panel_data->set_backlight(dssdev, level);
325 mutex_unlock(&td->lock);
330 static int taal_bl_get_intensity(struct backlight_device *dev)
332 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
333 dev->props.power == FB_BLANK_UNBLANK)
334 return dev->props.brightness;
339 static struct backlight_ops taal_bl_ops = {
340 .get_brightness = taal_bl_get_intensity,
341 .update_status = taal_bl_update_status,
344 static void taal_get_timings(struct omap_dss_device *dssdev,
345 struct omap_video_timings *timings)
347 *timings = dssdev->panel.timings;
350 static void taal_get_resolution(struct omap_dss_device *dssdev,
351 u16 *xres, u16 *yres)
353 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
355 if (td->rotate == 0 || td->rotate == 2) {
356 *xres = dssdev->panel.timings.x_res;
357 *yres = dssdev->panel.timings.y_res;
359 *yres = dssdev->panel.timings.x_res;
360 *xres = dssdev->panel.timings.y_res;
364 static ssize_t taal_num_errors_show(struct device *dev,
365 struct device_attribute *attr, char *buf)
367 struct omap_dss_device *dssdev = to_dss_device(dev);
368 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
372 mutex_lock(&td->lock);
376 r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors);
382 mutex_unlock(&td->lock);
387 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
390 static ssize_t taal_hw_revision_show(struct device *dev,
391 struct device_attribute *attr, char *buf)
393 struct omap_dss_device *dssdev = to_dss_device(dev);
394 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
398 mutex_lock(&td->lock);
402 r = taal_get_id(&id1, &id2, &id3);
408 mutex_unlock(&td->lock);
413 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
416 static const char *cabc_modes[] = {
417 "off", /* used also always when CABC is not supported */
423 static ssize_t show_cabc_mode(struct device *dev,
424 struct device_attribute *attr,
427 struct omap_dss_device *dssdev = to_dss_device(dev);
428 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
429 const char *mode_str;
433 mode = td->cabc_mode;
435 mode_str = "unknown";
436 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
437 mode_str = cabc_modes[mode];
438 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
440 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
443 static ssize_t store_cabc_mode(struct device *dev,
444 struct device_attribute *attr,
445 const char *buf, size_t count)
447 struct omap_dss_device *dssdev = to_dss_device(dev);
448 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
451 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
452 if (sysfs_streq(cabc_modes[i], buf))
456 if (i == ARRAY_SIZE(cabc_modes))
459 mutex_lock(&td->lock);
463 if (!td->cabc_broken)
464 taal_dcs_write_1(DCS_WRITE_CABC, i);
470 mutex_unlock(&td->lock);
475 static ssize_t show_cabc_available_modes(struct device *dev,
476 struct device_attribute *attr,
483 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
484 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
485 i ? " " : "", cabc_modes[i],
486 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
488 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
491 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
492 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
493 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
494 show_cabc_mode, store_cabc_mode);
495 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
496 show_cabc_available_modes, NULL);
498 static struct attribute *taal_attrs[] = {
499 &dev_attr_num_dsi_errors.attr,
500 &dev_attr_hw_revision.attr,
501 &dev_attr_cabc_mode.attr,
502 &dev_attr_cabc_available_modes.attr,
506 static struct attribute_group taal_attr_group = {
510 static void taal_hw_reset(struct omap_dss_device *dssdev)
512 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
514 if (panel_data->reset_gpio == -1)
517 gpio_set_value(panel_data->reset_gpio, 1);
519 /* reset the panel */
520 gpio_set_value(panel_data->reset_gpio, 0);
521 /* assert reset for at least 10us */
523 gpio_set_value(panel_data->reset_gpio, 1);
524 /* wait 5ms after releasing reset */
528 static int taal_probe(struct omap_dss_device *dssdev)
530 struct backlight_properties props;
531 struct taal_data *td;
532 struct backlight_device *bldev;
533 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
536 const struct omap_video_timings taal_panel_timings = {
541 dev_dbg(&dssdev->dev, "probe\n");
543 if (!panel_data || !panel_data->name) {
548 dssdev->panel.config = OMAP_DSS_LCD_TFT;
549 dssdev->panel.timings = taal_panel_timings;
550 dssdev->ctrl.pixel_size = 24;
552 td = kzalloc(sizeof(*td), GFP_KERNEL);
559 mutex_init(&td->lock);
561 atomic_set(&td->do_update, 0);
563 td->esd_wq = create_singlethread_workqueue("taal_esd");
564 if (td->esd_wq == NULL) {
565 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
569 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
571 dev_set_drvdata(&dssdev->dev, td);
573 taal_hw_reset(dssdev);
575 /* if no platform set_backlight() defined, presume DSI backlight
577 memset(&props, 0, sizeof(struct backlight_properties));
578 if (!panel_data->set_backlight)
579 td->use_dsi_bl = true;
582 props.max_brightness = 255;
584 props.max_brightness = 127;
585 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
586 &taal_bl_ops, &props);
594 bldev->props.fb_blank = FB_BLANK_UNBLANK;
595 bldev->props.power = FB_BLANK_UNBLANK;
597 bldev->props.brightness = 255;
599 bldev->props.brightness = 127;
601 taal_bl_update_status(bldev);
603 if (panel_data->use_ext_te) {
604 int gpio = panel_data->ext_te_gpio;
606 r = gpio_request(gpio, "taal irq");
608 dev_err(&dssdev->dev, "GPIO request failed\n");
612 gpio_direction_input(gpio);
614 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
615 IRQF_DISABLED | IRQF_TRIGGER_RISING,
616 "taal vsync", dssdev);
619 dev_err(&dssdev->dev, "IRQ request failed\n");
624 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
625 taal_te_timeout_work_callback);
627 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
630 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
632 dev_err(&dssdev->dev, "failed to create sysfs files\n");
638 if (panel_data->use_ext_te)
639 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
641 if (panel_data->use_ext_te)
642 gpio_free(panel_data->ext_te_gpio);
644 backlight_device_unregister(bldev);
646 destroy_workqueue(td->esd_wq);
653 static void taal_remove(struct omap_dss_device *dssdev)
655 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
656 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
657 struct backlight_device *bldev;
659 dev_dbg(&dssdev->dev, "remove\n");
661 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
663 if (panel_data->use_ext_te) {
664 int gpio = panel_data->ext_te_gpio;
665 free_irq(gpio_to_irq(gpio), dssdev);
670 bldev->props.power = FB_BLANK_POWERDOWN;
671 taal_bl_update_status(bldev);
672 backlight_device_unregister(bldev);
674 cancel_delayed_work(&td->esd_work);
675 destroy_workqueue(td->esd_wq);
677 /* reset, to be sure that the panel is in a valid state */
678 taal_hw_reset(dssdev);
683 static int taal_power_on(struct omap_dss_device *dssdev)
685 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
689 /* it seems we have to wait a bit until taal is ready */
692 r = omapdss_dsi_display_enable(dssdev);
694 dev_err(&dssdev->dev, "failed to enable DSI\n");
698 taal_hw_reset(dssdev);
700 omapdss_dsi_vc_enable_hs(TCH, false);
702 r = taal_sleep_out(td);
706 r = taal_get_id(&id1, &id2, &id3);
710 /* on early revisions CABC is broken */
711 if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
712 td->cabc_broken = true;
714 r = taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
718 r = taal_dcs_write_1(DCS_CTRL_DISPLAY,
719 (1<<2) | (1<<5)); /* BL | BCTRL */
723 r = taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
727 r = taal_set_addr_mode(td->rotate, td->mirror);
731 if (!td->cabc_broken) {
732 r = taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
737 r = taal_dcs_write_0(DCS_DISPLAY_ON);
741 r = _taal_enable_te(dssdev, td->te_enabled);
747 if (!td->intro_printed) {
748 dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n",
751 dev_info(&dssdev->dev,
752 "old Taal version, CABC disabled\n");
753 td->intro_printed = true;
756 omapdss_dsi_vc_enable_hs(TCH, true);
760 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
762 taal_hw_reset(dssdev);
764 omapdss_dsi_display_disable(dssdev);
769 static void taal_power_off(struct omap_dss_device *dssdev)
771 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
774 r = taal_dcs_write_0(DCS_DISPLAY_OFF);
776 r = taal_sleep_in(td);
777 /* wait a bit so that the message goes through */
782 dev_err(&dssdev->dev,
783 "error disabling panel, issuing HW reset\n");
784 taal_hw_reset(dssdev);
787 omapdss_dsi_display_disable(dssdev);
792 static int taal_enable(struct omap_dss_device *dssdev)
794 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
795 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
798 dev_dbg(&dssdev->dev, "enable\n");
800 mutex_lock(&td->lock);
802 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
809 r = taal_power_on(dssdev);
816 if (panel_data->use_esd_check)
817 queue_delayed_work(td->esd_wq, &td->esd_work,
818 TAAL_ESD_CHECK_PERIOD);
820 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
822 mutex_unlock(&td->lock);
826 dev_dbg(&dssdev->dev, "enable failed\n");
827 mutex_unlock(&td->lock);
831 static void taal_disable(struct omap_dss_device *dssdev)
833 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
835 dev_dbg(&dssdev->dev, "disable\n");
837 mutex_lock(&td->lock);
839 cancel_delayed_work(&td->esd_work);
843 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
844 taal_power_off(dssdev);
848 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
850 mutex_unlock(&td->lock);
853 static int taal_suspend(struct omap_dss_device *dssdev)
855 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
858 dev_dbg(&dssdev->dev, "suspend\n");
860 mutex_lock(&td->lock);
862 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
867 cancel_delayed_work(&td->esd_work);
871 taal_power_off(dssdev);
875 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
877 mutex_unlock(&td->lock);
881 mutex_unlock(&td->lock);
885 static int taal_resume(struct omap_dss_device *dssdev)
887 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
888 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
891 dev_dbg(&dssdev->dev, "resume\n");
893 mutex_lock(&td->lock);
895 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
902 r = taal_power_on(dssdev);
907 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
909 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
910 if (panel_data->use_esd_check)
911 queue_delayed_work(td->esd_wq, &td->esd_work,
912 TAAL_ESD_CHECK_PERIOD);
915 mutex_unlock(&td->lock);
919 mutex_unlock(&td->lock);
923 static void taal_framedone_cb(int err, void *data)
925 struct omap_dss_device *dssdev = data;
926 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
930 static irqreturn_t taal_te_isr(int irq, void *data)
932 struct omap_dss_device *dssdev = data;
933 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
937 old = atomic_cmpxchg(&td->do_update, 1, 0);
940 cancel_delayed_work(&td->te_timeout_work);
942 r = omap_dsi_update(dssdev, TCH,
947 taal_framedone_cb, dssdev);
954 dev_err(&dssdev->dev, "start update failed\n");
959 static void taal_te_timeout_work_callback(struct work_struct *work)
961 struct taal_data *td = container_of(work, struct taal_data,
962 te_timeout_work.work);
963 struct omap_dss_device *dssdev = td->dssdev;
965 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
967 atomic_set(&td->do_update, 0);
971 static int taal_update(struct omap_dss_device *dssdev,
972 u16 x, u16 y, u16 w, u16 h)
974 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
975 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
978 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
980 mutex_lock(&td->lock);
988 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h);
992 r = taal_set_update_window(x, y, w, h);
996 if (td->te_enabled && panel_data->use_ext_te) {
997 td->update_region.x = x;
998 td->update_region.y = y;
999 td->update_region.w = w;
1000 td->update_region.h = h;
1002 schedule_delayed_work(&td->te_timeout_work,
1003 msecs_to_jiffies(250));
1004 atomic_set(&td->do_update, 1);
1006 r = omap_dsi_update(dssdev, TCH, x, y, w, h,
1007 taal_framedone_cb, dssdev);
1012 /* note: no bus_unlock here. unlock is in framedone_cb */
1013 mutex_unlock(&td->lock);
1017 mutex_unlock(&td->lock);
1021 static int taal_sync(struct omap_dss_device *dssdev)
1023 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1025 dev_dbg(&dssdev->dev, "sync\n");
1027 mutex_lock(&td->lock);
1030 mutex_unlock(&td->lock);
1032 dev_dbg(&dssdev->dev, "sync done\n");
1037 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1039 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1043 r = taal_dcs_write_1(DCS_TEAR_ON, 0);
1045 r = taal_dcs_write_0(DCS_TEAR_OFF);
1047 if (!panel_data->use_ext_te)
1048 omapdss_dsi_enable_te(dssdev, enable);
1050 /* XXX for some reason, DSI TE breaks if we don't wait here.
1051 * Panel bug? Needs more studying */
1057 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1059 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1062 mutex_lock(&td->lock);
1066 r = _taal_enable_te(dssdev, enable);
1071 td->te_enabled = enable;
1074 mutex_unlock(&td->lock);
1079 mutex_unlock(&td->lock);
1084 static int taal_get_te(struct omap_dss_device *dssdev)
1086 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1089 mutex_lock(&td->lock);
1091 mutex_unlock(&td->lock);
1096 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1098 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1101 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1103 mutex_lock(&td->lock);
1107 r = taal_set_addr_mode(rotate, td->mirror);
1112 td->rotate = rotate;
1115 mutex_unlock(&td->lock);
1119 mutex_unlock(&td->lock);
1123 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1125 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1128 mutex_lock(&td->lock);
1130 mutex_unlock(&td->lock);
1135 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1137 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1140 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1142 mutex_lock(&td->lock);
1145 r = taal_set_addr_mode(td->rotate, enable);
1150 td->mirror = enable;
1153 mutex_unlock(&td->lock);
1157 mutex_unlock(&td->lock);
1161 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1163 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1166 mutex_lock(&td->lock);
1168 mutex_unlock(&td->lock);
1173 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1175 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1179 mutex_lock(&td->lock);
1188 r = taal_dcs_read_1(DCS_GET_ID1, &id1);
1191 r = taal_dcs_read_1(DCS_GET_ID2, &id2);
1194 r = taal_dcs_read_1(DCS_GET_ID3, &id3);
1199 mutex_unlock(&td->lock);
1204 mutex_unlock(&td->lock);
1208 static int taal_memory_read(struct omap_dss_device *dssdev,
1209 void *buf, size_t size,
1210 u16 x, u16 y, u16 w, u16 h)
1215 unsigned buf_used = 0;
1216 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1218 if (size < w * h * 3)
1221 mutex_lock(&td->lock);
1228 size = min(w * h * 3,
1229 dssdev->panel.timings.x_res *
1230 dssdev->panel.timings.y_res * 3);
1234 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1235 * use short packets. plen 32 works, but bigger packets seem to cause
1242 taal_set_update_window(x, y, w, h);
1244 r = dsi_vc_set_max_rx_packet_size(TCH, plen);
1248 while (buf_used < size) {
1249 u8 dcs_cmd = first ? 0x2e : 0x3e;
1252 r = dsi_vc_dcs_read(TCH, dcs_cmd,
1253 buf + buf_used, size - buf_used);
1256 dev_err(&dssdev->dev, "read error\n");
1263 dev_err(&dssdev->dev, "short read\n");
1267 if (signal_pending(current)) {
1268 dev_err(&dssdev->dev, "signal pending, "
1269 "aborting memory read\n");
1278 dsi_vc_set_max_rx_packet_size(TCH, 1);
1282 mutex_unlock(&td->lock);
1286 static void taal_esd_work(struct work_struct *work)
1288 struct taal_data *td = container_of(work, struct taal_data,
1290 struct omap_dss_device *dssdev = td->dssdev;
1291 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1295 mutex_lock(&td->lock);
1298 mutex_unlock(&td->lock);
1304 r = taal_dcs_read_1(DCS_RDDSDR, &state1);
1306 dev_err(&dssdev->dev, "failed to read Taal status\n");
1310 /* Run self diagnostics */
1311 r = taal_sleep_out(td);
1313 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1317 r = taal_dcs_read_1(DCS_RDDSDR, &state2);
1319 dev_err(&dssdev->dev, "failed to read Taal status\n");
1323 /* Each sleep out command will trigger a self diagnostic and flip
1324 * Bit6 if the test passes.
1326 if (!((state1 ^ state2) & (1 << 6))) {
1327 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1330 /* Self-diagnostics result is also shown on TE GPIO line. We need
1331 * to re-enable TE after self diagnostics */
1332 if (td->te_enabled && panel_data->use_ext_te) {
1333 r = taal_dcs_write_1(DCS_TEAR_ON, 0);
1340 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1342 mutex_unlock(&td->lock);
1345 dev_err(&dssdev->dev, "performing LCD reset\n");
1347 taal_power_off(dssdev);
1348 taal_hw_reset(dssdev);
1349 taal_power_on(dssdev);
1353 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1355 mutex_unlock(&td->lock);
1358 static int taal_set_update_mode(struct omap_dss_device *dssdev,
1359 enum omap_dss_update_mode mode)
1361 if (mode != OMAP_DSS_UPDATE_MANUAL)
1366 static enum omap_dss_update_mode taal_get_update_mode(
1367 struct omap_dss_device *dssdev)
1369 return OMAP_DSS_UPDATE_MANUAL;
1372 static struct omap_dss_driver taal_driver = {
1373 .probe = taal_probe,
1374 .remove = taal_remove,
1376 .enable = taal_enable,
1377 .disable = taal_disable,
1378 .suspend = taal_suspend,
1379 .resume = taal_resume,
1381 .set_update_mode = taal_set_update_mode,
1382 .get_update_mode = taal_get_update_mode,
1384 .update = taal_update,
1387 .get_resolution = taal_get_resolution,
1388 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1390 .enable_te = taal_enable_te,
1391 .get_te = taal_get_te,
1393 .set_rotate = taal_rotate,
1394 .get_rotate = taal_get_rotate,
1395 .set_mirror = taal_mirror,
1396 .get_mirror = taal_get_mirror,
1397 .run_test = taal_run_test,
1398 .memory_read = taal_memory_read,
1400 .get_timings = taal_get_timings,
1404 .owner = THIS_MODULE,
1408 static int __init taal_init(void)
1410 omap_dss_register_driver(&taal_driver);
1415 static void __exit taal_exit(void)
1417 omap_dss_unregister_driver(&taal_driver);
1420 module_init(taal_init);
1421 module_exit(taal_exit);
1423 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1424 MODULE_DESCRIPTION("Taal Driver");
1425 MODULE_LICENSE("GPL");