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/regulator/consumer.h>
34 #include <linux/mutex.h>
36 #include <plat/display.h>
37 #include <plat/nokia-dsi-panel.h>
39 /* DSI Virtual channel. Hardcoded for now. */
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 #define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000)
68 static irqreturn_t taal_te_isr(int irq, void *data);
69 static void taal_te_timeout_work_callback(struct work_struct *work);
70 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
72 struct panel_regulator {
73 struct regulator *regulator;
79 static void free_regulators(struct panel_regulator *regulators, int n)
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)
95 for (i = 0; i < n; i++) {
96 struct regulator *reg;
98 reg = regulator_get(&dssdev->dev, regulators[i].name);
100 dev_err(&dssdev->dev, "failed to get regulator %s\n",
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);
112 dev_err(&dssdev->dev,
113 "failed to set regulator %s voltage\n",
120 r = regulator_enable(reg);
122 dev_err(&dssdev->dev, "failed to enable regulator %s\n",
128 regulators[i].regulator = reg;
134 free_regulators(regulators, i);
140 * struct panel_config - panel configuration
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 {
153 struct omap_video_timings timings;
156 unsigned int sleep_in;
157 unsigned int sleep_out;
158 unsigned int hw_reset;
159 unsigned int enable_te;
167 struct panel_regulator *regulators;
175 static struct panel_config panel_configs[] = {
187 .enable_te = 100, /* possible panel bug */
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;
221 struct delayed_work te_timeout_work;
230 struct workqueue_struct *esd_wq;
231 struct delayed_work esd_work;
233 struct panel_config *panel_config;
236 static inline struct nokia_dsi_panel_data
237 *get_panel_data(const struct omap_dss_device *dssdev)
239 return (struct nokia_dsi_panel_data *) dssdev->data;
242 static void taal_esd_work(struct work_struct *work);
244 static void hw_guard_start(struct taal_data *td, int guard_msec)
246 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
247 td->hw_guard_end = jiffies + td->hw_guard_wait;
250 static void hw_guard_wait(struct taal_data *td)
252 unsigned long wait = td->hw_guard_end - jiffies;
254 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
255 set_current_state(TASK_UNINTERRUPTIBLE);
256 schedule_timeout(wait);
260 static int taal_dcs_read_1(u8 dcs_cmd, u8 *data)
265 r = dsi_vc_dcs_read(TCH, dcs_cmd, buf, 1);
275 static int taal_dcs_write_0(u8 dcs_cmd)
277 return dsi_vc_dcs_write(TCH, &dcs_cmd, 1);
280 static int taal_dcs_write_1(u8 dcs_cmd, u8 param)
285 return dsi_vc_dcs_write(TCH, buf, 2);
288 static int taal_sleep_in(struct taal_data *td)
297 r = dsi_vc_dcs_write_nosync(TCH, &cmd, 1);
301 hw_guard_start(td, 120);
303 if (td->panel_config->sleep.sleep_in)
304 msleep(td->panel_config->sleep.sleep_in);
309 static int taal_sleep_out(struct taal_data *td)
315 r = taal_dcs_write_0(DCS_SLEEP_OUT);
319 hw_guard_start(td, 120);
321 if (td->panel_config->sleep.sleep_out)
322 msleep(td->panel_config->sleep.sleep_out);
327 static int taal_get_id(u8 *id1, u8 *id2, u8 *id3)
331 r = taal_dcs_read_1(DCS_GET_ID1, id1);
334 r = taal_dcs_read_1(DCS_GET_ID2, id2);
337 r = taal_dcs_read_1(DCS_GET_ID3, id3);
344 static int taal_set_addr_mode(u8 rotate, bool mirror)
350 r = taal_dcs_read_1(DCS_READ_MADCTL, &mode);
381 mode &= ~((1<<7) | (1<<6) | (1<<5));
382 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
384 return taal_dcs_write_1(DCS_MEM_ACC_CTRL, mode);
387 static int taal_set_update_window(u16 x, u16 y, u16 w, u16 h)
396 buf[0] = DCS_COLUMN_ADDR;
397 buf[1] = (x1 >> 8) & 0xff;
398 buf[2] = (x1 >> 0) & 0xff;
399 buf[3] = (x2 >> 8) & 0xff;
400 buf[4] = (x2 >> 0) & 0xff;
402 r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
406 buf[0] = DCS_PAGE_ADDR;
407 buf[1] = (y1 >> 8) & 0xff;
408 buf[2] = (y1 >> 0) & 0xff;
409 buf[3] = (y2 >> 8) & 0xff;
410 buf[4] = (y2 >> 0) & 0xff;
412 r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
416 dsi_vc_send_bta_sync(TCH);
421 static int taal_bl_update_status(struct backlight_device *dev)
423 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
424 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
425 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
429 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
430 dev->props.power == FB_BLANK_UNBLANK)
431 level = dev->props.brightness;
435 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
437 mutex_lock(&td->lock);
439 if (td->use_dsi_bl) {
442 r = taal_dcs_write_1(DCS_BRIGHTNESS, level);
448 if (!panel_data->set_backlight)
451 r = panel_data->set_backlight(dssdev, level);
454 mutex_unlock(&td->lock);
459 static int taal_bl_get_intensity(struct backlight_device *dev)
461 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
462 dev->props.power == FB_BLANK_UNBLANK)
463 return dev->props.brightness;
468 static const struct backlight_ops taal_bl_ops = {
469 .get_brightness = taal_bl_get_intensity,
470 .update_status = taal_bl_update_status,
473 static void taal_get_timings(struct omap_dss_device *dssdev,
474 struct omap_video_timings *timings)
476 *timings = dssdev->panel.timings;
479 static void taal_get_resolution(struct omap_dss_device *dssdev,
480 u16 *xres, u16 *yres)
482 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
484 if (td->rotate == 0 || td->rotate == 2) {
485 *xres = dssdev->panel.timings.x_res;
486 *yres = dssdev->panel.timings.y_res;
488 *yres = dssdev->panel.timings.x_res;
489 *xres = dssdev->panel.timings.y_res;
493 static ssize_t taal_num_errors_show(struct device *dev,
494 struct device_attribute *attr, char *buf)
496 struct omap_dss_device *dssdev = to_dss_device(dev);
497 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
501 mutex_lock(&td->lock);
505 r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors);
511 mutex_unlock(&td->lock);
516 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
519 static ssize_t taal_hw_revision_show(struct device *dev,
520 struct device_attribute *attr, char *buf)
522 struct omap_dss_device *dssdev = to_dss_device(dev);
523 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
527 mutex_lock(&td->lock);
531 r = taal_get_id(&id1, &id2, &id3);
537 mutex_unlock(&td->lock);
542 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
545 static const char *cabc_modes[] = {
546 "off", /* used also always when CABC is not supported */
552 static ssize_t show_cabc_mode(struct device *dev,
553 struct device_attribute *attr,
556 struct omap_dss_device *dssdev = to_dss_device(dev);
557 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
558 const char *mode_str;
562 mode = td->cabc_mode;
564 mode_str = "unknown";
565 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
566 mode_str = cabc_modes[mode];
567 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
569 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
572 static ssize_t store_cabc_mode(struct device *dev,
573 struct device_attribute *attr,
574 const char *buf, size_t count)
576 struct omap_dss_device *dssdev = to_dss_device(dev);
577 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
580 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
581 if (sysfs_streq(cabc_modes[i], buf))
585 if (i == ARRAY_SIZE(cabc_modes))
588 mutex_lock(&td->lock);
592 if (!td->cabc_broken)
593 taal_dcs_write_1(DCS_WRITE_CABC, i);
599 mutex_unlock(&td->lock);
604 static ssize_t show_cabc_available_modes(struct device *dev,
605 struct device_attribute *attr,
612 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
613 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
614 i ? " " : "", cabc_modes[i],
615 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
617 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
620 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
621 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
622 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
623 show_cabc_mode, store_cabc_mode);
624 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
625 show_cabc_available_modes, NULL);
627 static struct attribute *taal_attrs[] = {
628 &dev_attr_num_dsi_errors.attr,
629 &dev_attr_hw_revision.attr,
630 &dev_attr_cabc_mode.attr,
631 &dev_attr_cabc_available_modes.attr,
635 static struct attribute_group taal_attr_group = {
639 static void taal_hw_reset(struct omap_dss_device *dssdev)
641 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
642 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
644 if (panel_data->reset_gpio == -1)
647 gpio_set_value(panel_data->reset_gpio, 1);
648 if (td->panel_config->reset_sequence.high)
649 udelay(td->panel_config->reset_sequence.high);
650 /* reset the panel */
651 gpio_set_value(panel_data->reset_gpio, 0);
653 if (td->panel_config->reset_sequence.low)
654 udelay(td->panel_config->reset_sequence.low);
655 gpio_set_value(panel_data->reset_gpio, 1);
656 /* wait after releasing reset */
657 if (td->panel_config->sleep.hw_reset)
658 msleep(td->panel_config->sleep.hw_reset);
661 static int taal_probe(struct omap_dss_device *dssdev)
663 struct backlight_properties props;
664 struct taal_data *td;
665 struct backlight_device *bldev;
666 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
667 struct panel_config *panel_config = NULL;
670 dev_dbg(&dssdev->dev, "probe\n");
672 if (!panel_data || !panel_data->name) {
677 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
678 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
679 panel_config = &panel_configs[i];
689 dssdev->panel.config = OMAP_DSS_LCD_TFT;
690 dssdev->panel.timings = panel_config->timings;
691 dssdev->ctrl.pixel_size = 24;
693 td = kzalloc(sizeof(*td), GFP_KERNEL);
699 td->panel_config = panel_config;
701 mutex_init(&td->lock);
703 atomic_set(&td->do_update, 0);
705 r = init_regulators(dssdev, panel_config->regulators,
706 panel_config->num_regulators);
710 td->esd_wq = create_singlethread_workqueue("taal_esd");
711 if (td->esd_wq == NULL) {
712 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
716 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
718 dev_set_drvdata(&dssdev->dev, td);
720 taal_hw_reset(dssdev);
722 /* if no platform set_backlight() defined, presume DSI backlight
724 memset(&props, 0, sizeof(struct backlight_properties));
725 if (!panel_data->set_backlight)
726 td->use_dsi_bl = true;
729 props.max_brightness = 255;
731 props.max_brightness = 127;
732 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
733 &taal_bl_ops, &props);
741 bldev->props.fb_blank = FB_BLANK_UNBLANK;
742 bldev->props.power = FB_BLANK_UNBLANK;
744 bldev->props.brightness = 255;
746 bldev->props.brightness = 127;
748 taal_bl_update_status(bldev);
750 if (panel_data->use_ext_te) {
751 int gpio = panel_data->ext_te_gpio;
753 r = gpio_request(gpio, "taal irq");
755 dev_err(&dssdev->dev, "GPIO request failed\n");
759 gpio_direction_input(gpio);
761 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
762 IRQF_DISABLED | IRQF_TRIGGER_RISING,
763 "taal vsync", dssdev);
766 dev_err(&dssdev->dev, "IRQ request failed\n");
771 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
772 taal_te_timeout_work_callback);
774 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
777 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
779 dev_err(&dssdev->dev, "failed to create sysfs files\n");
785 if (panel_data->use_ext_te)
786 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
788 if (panel_data->use_ext_te)
789 gpio_free(panel_data->ext_te_gpio);
791 backlight_device_unregister(bldev);
793 destroy_workqueue(td->esd_wq);
795 free_regulators(panel_config->regulators, panel_config->num_regulators);
802 static void taal_remove(struct omap_dss_device *dssdev)
804 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
805 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
806 struct backlight_device *bldev;
808 dev_dbg(&dssdev->dev, "remove\n");
810 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
812 if (panel_data->use_ext_te) {
813 int gpio = panel_data->ext_te_gpio;
814 free_irq(gpio_to_irq(gpio), dssdev);
819 bldev->props.power = FB_BLANK_POWERDOWN;
820 taal_bl_update_status(bldev);
821 backlight_device_unregister(bldev);
823 cancel_delayed_work(&td->esd_work);
824 destroy_workqueue(td->esd_wq);
826 /* reset, to be sure that the panel is in a valid state */
827 taal_hw_reset(dssdev);
829 free_regulators(td->panel_config->regulators,
830 td->panel_config->num_regulators);
835 static int taal_power_on(struct omap_dss_device *dssdev)
837 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
841 r = omapdss_dsi_display_enable(dssdev);
843 dev_err(&dssdev->dev, "failed to enable DSI\n");
847 taal_hw_reset(dssdev);
849 omapdss_dsi_vc_enable_hs(TCH, false);
851 r = taal_sleep_out(td);
855 r = taal_get_id(&id1, &id2, &id3);
859 /* on early Taal revisions CABC is broken */
860 if (td->panel_config->type == PANEL_TAAL &&
861 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
862 td->cabc_broken = true;
864 r = taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
868 r = taal_dcs_write_1(DCS_CTRL_DISPLAY,
869 (1<<2) | (1<<5)); /* BL | BCTRL */
873 r = taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
877 r = taal_set_addr_mode(td->rotate, td->mirror);
881 if (!td->cabc_broken) {
882 r = taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
887 r = taal_dcs_write_0(DCS_DISPLAY_ON);
891 r = _taal_enable_te(dssdev, td->te_enabled);
897 if (!td->intro_printed) {
898 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
899 td->panel_config->name, id1, id2, id3);
901 dev_info(&dssdev->dev,
902 "old Taal version, CABC disabled\n");
903 td->intro_printed = true;
906 omapdss_dsi_vc_enable_hs(TCH, true);
910 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
912 taal_hw_reset(dssdev);
914 omapdss_dsi_display_disable(dssdev);
919 static void taal_power_off(struct omap_dss_device *dssdev)
921 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
924 r = taal_dcs_write_0(DCS_DISPLAY_OFF);
926 r = taal_sleep_in(td);
927 /* HACK: wait a bit so that the message goes through */
932 dev_err(&dssdev->dev,
933 "error disabling panel, issuing HW reset\n");
934 taal_hw_reset(dssdev);
937 omapdss_dsi_display_disable(dssdev);
942 static int taal_enable(struct omap_dss_device *dssdev)
944 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
945 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
948 dev_dbg(&dssdev->dev, "enable\n");
950 mutex_lock(&td->lock);
952 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
959 r = taal_power_on(dssdev);
966 if (panel_data->use_esd_check)
967 queue_delayed_work(td->esd_wq, &td->esd_work,
968 TAAL_ESD_CHECK_PERIOD);
970 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
972 mutex_unlock(&td->lock);
976 dev_dbg(&dssdev->dev, "enable failed\n");
977 mutex_unlock(&td->lock);
981 static void taal_disable(struct omap_dss_device *dssdev)
983 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
985 dev_dbg(&dssdev->dev, "disable\n");
987 mutex_lock(&td->lock);
989 cancel_delayed_work(&td->esd_work);
993 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
994 taal_power_off(dssdev);
998 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1000 mutex_unlock(&td->lock);
1003 static int taal_suspend(struct omap_dss_device *dssdev)
1005 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1008 dev_dbg(&dssdev->dev, "suspend\n");
1010 mutex_lock(&td->lock);
1012 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1017 cancel_delayed_work(&td->esd_work);
1021 taal_power_off(dssdev);
1025 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1027 mutex_unlock(&td->lock);
1031 mutex_unlock(&td->lock);
1035 static int taal_resume(struct omap_dss_device *dssdev)
1037 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1038 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1041 dev_dbg(&dssdev->dev, "resume\n");
1043 mutex_lock(&td->lock);
1045 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1052 r = taal_power_on(dssdev);
1057 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1059 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1060 if (panel_data->use_esd_check)
1061 queue_delayed_work(td->esd_wq, &td->esd_work,
1062 TAAL_ESD_CHECK_PERIOD);
1065 mutex_unlock(&td->lock);
1069 mutex_unlock(&td->lock);
1073 static void taal_framedone_cb(int err, void *data)
1075 struct omap_dss_device *dssdev = data;
1076 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1080 static irqreturn_t taal_te_isr(int irq, void *data)
1082 struct omap_dss_device *dssdev = data;
1083 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1087 old = atomic_cmpxchg(&td->do_update, 1, 0);
1090 cancel_delayed_work(&td->te_timeout_work);
1092 r = omap_dsi_update(dssdev, TCH,
1093 td->update_region.x,
1094 td->update_region.y,
1095 td->update_region.w,
1096 td->update_region.h,
1097 taal_framedone_cb, dssdev);
1104 dev_err(&dssdev->dev, "start update failed\n");
1109 static void taal_te_timeout_work_callback(struct work_struct *work)
1111 struct taal_data *td = container_of(work, struct taal_data,
1112 te_timeout_work.work);
1113 struct omap_dss_device *dssdev = td->dssdev;
1115 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1117 atomic_set(&td->do_update, 0);
1121 static int taal_update(struct omap_dss_device *dssdev,
1122 u16 x, u16 y, u16 w, u16 h)
1124 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1125 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1128 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1130 mutex_lock(&td->lock);
1138 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
1142 r = taal_set_update_window(x, y, w, h);
1146 if (td->te_enabled && panel_data->use_ext_te) {
1147 td->update_region.x = x;
1148 td->update_region.y = y;
1149 td->update_region.w = w;
1150 td->update_region.h = h;
1152 schedule_delayed_work(&td->te_timeout_work,
1153 msecs_to_jiffies(250));
1154 atomic_set(&td->do_update, 1);
1156 r = omap_dsi_update(dssdev, TCH, x, y, w, h,
1157 taal_framedone_cb, dssdev);
1162 /* note: no bus_unlock here. unlock is in framedone_cb */
1163 mutex_unlock(&td->lock);
1167 mutex_unlock(&td->lock);
1171 static int taal_sync(struct omap_dss_device *dssdev)
1173 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1175 dev_dbg(&dssdev->dev, "sync\n");
1177 mutex_lock(&td->lock);
1180 mutex_unlock(&td->lock);
1182 dev_dbg(&dssdev->dev, "sync done\n");
1187 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1189 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1190 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1194 r = taal_dcs_write_1(DCS_TEAR_ON, 0);
1196 r = taal_dcs_write_0(DCS_TEAR_OFF);
1198 if (!panel_data->use_ext_te)
1199 omapdss_dsi_enable_te(dssdev, enable);
1201 if (td->panel_config->sleep.enable_te)
1202 msleep(td->panel_config->sleep.enable_te);
1207 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1209 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1212 mutex_lock(&td->lock);
1214 if (td->te_enabled == enable)
1220 r = _taal_enable_te(dssdev, enable);
1225 td->te_enabled = enable;
1229 mutex_unlock(&td->lock);
1234 mutex_unlock(&td->lock);
1239 static int taal_get_te(struct omap_dss_device *dssdev)
1241 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1244 mutex_lock(&td->lock);
1246 mutex_unlock(&td->lock);
1251 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1253 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1256 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1258 mutex_lock(&td->lock);
1260 if (td->rotate == rotate)
1266 r = taal_set_addr_mode(rotate, td->mirror);
1271 td->rotate = rotate;
1275 mutex_unlock(&td->lock);
1279 mutex_unlock(&td->lock);
1283 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1285 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1288 mutex_lock(&td->lock);
1290 mutex_unlock(&td->lock);
1295 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1297 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1300 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1302 mutex_lock(&td->lock);
1304 if (td->mirror == enable)
1309 r = taal_set_addr_mode(td->rotate, enable);
1314 td->mirror = enable;
1318 mutex_unlock(&td->lock);
1322 mutex_unlock(&td->lock);
1326 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1328 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1331 mutex_lock(&td->lock);
1333 mutex_unlock(&td->lock);
1338 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1340 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1344 mutex_lock(&td->lock);
1353 r = taal_dcs_read_1(DCS_GET_ID1, &id1);
1356 r = taal_dcs_read_1(DCS_GET_ID2, &id2);
1359 r = taal_dcs_read_1(DCS_GET_ID3, &id3);
1364 mutex_unlock(&td->lock);
1369 mutex_unlock(&td->lock);
1373 static int taal_memory_read(struct omap_dss_device *dssdev,
1374 void *buf, size_t size,
1375 u16 x, u16 y, u16 w, u16 h)
1380 unsigned buf_used = 0;
1381 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1383 if (size < w * h * 3)
1386 mutex_lock(&td->lock);
1393 size = min(w * h * 3,
1394 dssdev->panel.timings.x_res *
1395 dssdev->panel.timings.y_res * 3);
1399 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1400 * use short packets. plen 32 works, but bigger packets seem to cause
1407 taal_set_update_window(x, y, w, h);
1409 r = dsi_vc_set_max_rx_packet_size(TCH, plen);
1413 while (buf_used < size) {
1414 u8 dcs_cmd = first ? 0x2e : 0x3e;
1417 r = dsi_vc_dcs_read(TCH, dcs_cmd,
1418 buf + buf_used, size - buf_used);
1421 dev_err(&dssdev->dev, "read error\n");
1428 dev_err(&dssdev->dev, "short read\n");
1432 if (signal_pending(current)) {
1433 dev_err(&dssdev->dev, "signal pending, "
1434 "aborting memory read\n");
1443 dsi_vc_set_max_rx_packet_size(TCH, 1);
1447 mutex_unlock(&td->lock);
1451 static void taal_esd_work(struct work_struct *work)
1453 struct taal_data *td = container_of(work, struct taal_data,
1455 struct omap_dss_device *dssdev = td->dssdev;
1456 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1460 mutex_lock(&td->lock);
1463 mutex_unlock(&td->lock);
1469 r = taal_dcs_read_1(DCS_RDDSDR, &state1);
1471 dev_err(&dssdev->dev, "failed to read Taal status\n");
1475 /* Run self diagnostics */
1476 r = taal_sleep_out(td);
1478 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1482 r = taal_dcs_read_1(DCS_RDDSDR, &state2);
1484 dev_err(&dssdev->dev, "failed to read Taal status\n");
1488 /* Each sleep out command will trigger a self diagnostic and flip
1489 * Bit6 if the test passes.
1491 if (!((state1 ^ state2) & (1 << 6))) {
1492 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1495 /* Self-diagnostics result is also shown on TE GPIO line. We need
1496 * to re-enable TE after self diagnostics */
1497 if (td->te_enabled && panel_data->use_ext_te) {
1498 r = taal_dcs_write_1(DCS_TEAR_ON, 0);
1505 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1507 mutex_unlock(&td->lock);
1510 dev_err(&dssdev->dev, "performing LCD reset\n");
1512 taal_power_off(dssdev);
1513 taal_hw_reset(dssdev);
1514 taal_power_on(dssdev);
1518 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1520 mutex_unlock(&td->lock);
1523 static int taal_set_update_mode(struct omap_dss_device *dssdev,
1524 enum omap_dss_update_mode mode)
1526 if (mode != OMAP_DSS_UPDATE_MANUAL)
1531 static enum omap_dss_update_mode taal_get_update_mode(
1532 struct omap_dss_device *dssdev)
1534 return OMAP_DSS_UPDATE_MANUAL;
1537 static struct omap_dss_driver taal_driver = {
1538 .probe = taal_probe,
1539 .remove = taal_remove,
1541 .enable = taal_enable,
1542 .disable = taal_disable,
1543 .suspend = taal_suspend,
1544 .resume = taal_resume,
1546 .set_update_mode = taal_set_update_mode,
1547 .get_update_mode = taal_get_update_mode,
1549 .update = taal_update,
1552 .get_resolution = taal_get_resolution,
1553 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1555 .enable_te = taal_enable_te,
1556 .get_te = taal_get_te,
1558 .set_rotate = taal_rotate,
1559 .get_rotate = taal_get_rotate,
1560 .set_mirror = taal_mirror,
1561 .get_mirror = taal_get_mirror,
1562 .run_test = taal_run_test,
1563 .memory_read = taal_memory_read,
1565 .get_timings = taal_get_timings,
1569 .owner = THIS_MODULE,
1573 static int __init taal_init(void)
1575 omap_dss_register_driver(&taal_driver);
1580 static void __exit taal_exit(void)
1582 omap_dss_unregister_driver(&taal_driver);
1585 module_init(taal_init);
1586 module_exit(taal_exit);
1588 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1589 MODULE_DESCRIPTION("Taal Driver");
1590 MODULE_LICENSE("GPL");