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;
733 props.type = BACKLIGHT_RAW;
734 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
735 &taal_bl_ops, &props);
743 bldev->props.fb_blank = FB_BLANK_UNBLANK;
744 bldev->props.power = FB_BLANK_UNBLANK;
746 bldev->props.brightness = 255;
748 bldev->props.brightness = 127;
750 taal_bl_update_status(bldev);
752 if (panel_data->use_ext_te) {
753 int gpio = panel_data->ext_te_gpio;
755 r = gpio_request(gpio, "taal irq");
757 dev_err(&dssdev->dev, "GPIO request failed\n");
761 gpio_direction_input(gpio);
763 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
764 IRQF_DISABLED | IRQF_TRIGGER_RISING,
765 "taal vsync", dssdev);
768 dev_err(&dssdev->dev, "IRQ request failed\n");
773 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
774 taal_te_timeout_work_callback);
776 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
779 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
781 dev_err(&dssdev->dev, "failed to create sysfs files\n");
787 if (panel_data->use_ext_te)
788 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
790 if (panel_data->use_ext_te)
791 gpio_free(panel_data->ext_te_gpio);
793 backlight_device_unregister(bldev);
795 destroy_workqueue(td->esd_wq);
797 free_regulators(panel_config->regulators, panel_config->num_regulators);
804 static void taal_remove(struct omap_dss_device *dssdev)
806 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
807 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
808 struct backlight_device *bldev;
810 dev_dbg(&dssdev->dev, "remove\n");
812 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
814 if (panel_data->use_ext_te) {
815 int gpio = panel_data->ext_te_gpio;
816 free_irq(gpio_to_irq(gpio), dssdev);
821 bldev->props.power = FB_BLANK_POWERDOWN;
822 taal_bl_update_status(bldev);
823 backlight_device_unregister(bldev);
825 cancel_delayed_work(&td->esd_work);
826 destroy_workqueue(td->esd_wq);
828 /* reset, to be sure that the panel is in a valid state */
829 taal_hw_reset(dssdev);
831 free_regulators(td->panel_config->regulators,
832 td->panel_config->num_regulators);
837 static int taal_power_on(struct omap_dss_device *dssdev)
839 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
843 r = omapdss_dsi_display_enable(dssdev);
845 dev_err(&dssdev->dev, "failed to enable DSI\n");
849 taal_hw_reset(dssdev);
851 omapdss_dsi_vc_enable_hs(TCH, false);
853 r = taal_sleep_out(td);
857 r = taal_get_id(&id1, &id2, &id3);
861 /* on early Taal revisions CABC is broken */
862 if (td->panel_config->type == PANEL_TAAL &&
863 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
864 td->cabc_broken = true;
866 r = taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
870 r = taal_dcs_write_1(DCS_CTRL_DISPLAY,
871 (1<<2) | (1<<5)); /* BL | BCTRL */
875 r = taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
879 r = taal_set_addr_mode(td->rotate, td->mirror);
883 if (!td->cabc_broken) {
884 r = taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
889 r = taal_dcs_write_0(DCS_DISPLAY_ON);
893 r = _taal_enable_te(dssdev, td->te_enabled);
899 if (!td->intro_printed) {
900 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
901 td->panel_config->name, id1, id2, id3);
903 dev_info(&dssdev->dev,
904 "old Taal version, CABC disabled\n");
905 td->intro_printed = true;
908 omapdss_dsi_vc_enable_hs(TCH, true);
912 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
914 taal_hw_reset(dssdev);
916 omapdss_dsi_display_disable(dssdev);
921 static void taal_power_off(struct omap_dss_device *dssdev)
923 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
926 r = taal_dcs_write_0(DCS_DISPLAY_OFF);
928 r = taal_sleep_in(td);
929 /* HACK: wait a bit so that the message goes through */
934 dev_err(&dssdev->dev,
935 "error disabling panel, issuing HW reset\n");
936 taal_hw_reset(dssdev);
939 omapdss_dsi_display_disable(dssdev);
944 static int taal_enable(struct omap_dss_device *dssdev)
946 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
947 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
950 dev_dbg(&dssdev->dev, "enable\n");
952 mutex_lock(&td->lock);
954 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
961 r = taal_power_on(dssdev);
968 if (panel_data->use_esd_check)
969 queue_delayed_work(td->esd_wq, &td->esd_work,
970 TAAL_ESD_CHECK_PERIOD);
972 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
974 mutex_unlock(&td->lock);
978 dev_dbg(&dssdev->dev, "enable failed\n");
979 mutex_unlock(&td->lock);
983 static void taal_disable(struct omap_dss_device *dssdev)
985 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
987 dev_dbg(&dssdev->dev, "disable\n");
989 mutex_lock(&td->lock);
991 cancel_delayed_work(&td->esd_work);
995 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
996 taal_power_off(dssdev);
1000 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1002 mutex_unlock(&td->lock);
1005 static int taal_suspend(struct omap_dss_device *dssdev)
1007 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1010 dev_dbg(&dssdev->dev, "suspend\n");
1012 mutex_lock(&td->lock);
1014 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1019 cancel_delayed_work(&td->esd_work);
1023 taal_power_off(dssdev);
1027 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1029 mutex_unlock(&td->lock);
1033 mutex_unlock(&td->lock);
1037 static int taal_resume(struct omap_dss_device *dssdev)
1039 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1040 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1043 dev_dbg(&dssdev->dev, "resume\n");
1045 mutex_lock(&td->lock);
1047 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1054 r = taal_power_on(dssdev);
1059 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1061 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1062 if (panel_data->use_esd_check)
1063 queue_delayed_work(td->esd_wq, &td->esd_work,
1064 TAAL_ESD_CHECK_PERIOD);
1067 mutex_unlock(&td->lock);
1071 mutex_unlock(&td->lock);
1075 static void taal_framedone_cb(int err, void *data)
1077 struct omap_dss_device *dssdev = data;
1078 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1082 static irqreturn_t taal_te_isr(int irq, void *data)
1084 struct omap_dss_device *dssdev = data;
1085 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1089 old = atomic_cmpxchg(&td->do_update, 1, 0);
1092 cancel_delayed_work(&td->te_timeout_work);
1094 r = omap_dsi_update(dssdev, TCH,
1095 td->update_region.x,
1096 td->update_region.y,
1097 td->update_region.w,
1098 td->update_region.h,
1099 taal_framedone_cb, dssdev);
1106 dev_err(&dssdev->dev, "start update failed\n");
1111 static void taal_te_timeout_work_callback(struct work_struct *work)
1113 struct taal_data *td = container_of(work, struct taal_data,
1114 te_timeout_work.work);
1115 struct omap_dss_device *dssdev = td->dssdev;
1117 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1119 atomic_set(&td->do_update, 0);
1123 static int taal_update(struct omap_dss_device *dssdev,
1124 u16 x, u16 y, u16 w, u16 h)
1126 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1127 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1130 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1132 mutex_lock(&td->lock);
1140 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
1144 r = taal_set_update_window(x, y, w, h);
1148 if (td->te_enabled && panel_data->use_ext_te) {
1149 td->update_region.x = x;
1150 td->update_region.y = y;
1151 td->update_region.w = w;
1152 td->update_region.h = h;
1154 schedule_delayed_work(&td->te_timeout_work,
1155 msecs_to_jiffies(250));
1156 atomic_set(&td->do_update, 1);
1158 r = omap_dsi_update(dssdev, TCH, x, y, w, h,
1159 taal_framedone_cb, dssdev);
1164 /* note: no bus_unlock here. unlock is in framedone_cb */
1165 mutex_unlock(&td->lock);
1169 mutex_unlock(&td->lock);
1173 static int taal_sync(struct omap_dss_device *dssdev)
1175 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1177 dev_dbg(&dssdev->dev, "sync\n");
1179 mutex_lock(&td->lock);
1182 mutex_unlock(&td->lock);
1184 dev_dbg(&dssdev->dev, "sync done\n");
1189 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1191 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1192 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1196 r = taal_dcs_write_1(DCS_TEAR_ON, 0);
1198 r = taal_dcs_write_0(DCS_TEAR_OFF);
1200 if (!panel_data->use_ext_te)
1201 omapdss_dsi_enable_te(dssdev, enable);
1203 if (td->panel_config->sleep.enable_te)
1204 msleep(td->panel_config->sleep.enable_te);
1209 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1211 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1214 mutex_lock(&td->lock);
1216 if (td->te_enabled == enable)
1222 r = _taal_enable_te(dssdev, enable);
1227 td->te_enabled = enable;
1231 mutex_unlock(&td->lock);
1236 mutex_unlock(&td->lock);
1241 static int taal_get_te(struct omap_dss_device *dssdev)
1243 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1246 mutex_lock(&td->lock);
1248 mutex_unlock(&td->lock);
1253 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1255 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1258 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1260 mutex_lock(&td->lock);
1262 if (td->rotate == rotate)
1268 r = taal_set_addr_mode(rotate, td->mirror);
1273 td->rotate = rotate;
1277 mutex_unlock(&td->lock);
1281 mutex_unlock(&td->lock);
1285 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1287 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1290 mutex_lock(&td->lock);
1292 mutex_unlock(&td->lock);
1297 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1299 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1302 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1304 mutex_lock(&td->lock);
1306 if (td->mirror == enable)
1311 r = taal_set_addr_mode(td->rotate, enable);
1316 td->mirror = enable;
1320 mutex_unlock(&td->lock);
1324 mutex_unlock(&td->lock);
1328 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1330 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1333 mutex_lock(&td->lock);
1335 mutex_unlock(&td->lock);
1340 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1342 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1346 mutex_lock(&td->lock);
1355 r = taal_dcs_read_1(DCS_GET_ID1, &id1);
1358 r = taal_dcs_read_1(DCS_GET_ID2, &id2);
1361 r = taal_dcs_read_1(DCS_GET_ID3, &id3);
1366 mutex_unlock(&td->lock);
1371 mutex_unlock(&td->lock);
1375 static int taal_memory_read(struct omap_dss_device *dssdev,
1376 void *buf, size_t size,
1377 u16 x, u16 y, u16 w, u16 h)
1382 unsigned buf_used = 0;
1383 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1385 if (size < w * h * 3)
1388 mutex_lock(&td->lock);
1395 size = min(w * h * 3,
1396 dssdev->panel.timings.x_res *
1397 dssdev->panel.timings.y_res * 3);
1401 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1402 * use short packets. plen 32 works, but bigger packets seem to cause
1409 taal_set_update_window(x, y, w, h);
1411 r = dsi_vc_set_max_rx_packet_size(TCH, plen);
1415 while (buf_used < size) {
1416 u8 dcs_cmd = first ? 0x2e : 0x3e;
1419 r = dsi_vc_dcs_read(TCH, dcs_cmd,
1420 buf + buf_used, size - buf_used);
1423 dev_err(&dssdev->dev, "read error\n");
1430 dev_err(&dssdev->dev, "short read\n");
1434 if (signal_pending(current)) {
1435 dev_err(&dssdev->dev, "signal pending, "
1436 "aborting memory read\n");
1445 dsi_vc_set_max_rx_packet_size(TCH, 1);
1449 mutex_unlock(&td->lock);
1453 static void taal_esd_work(struct work_struct *work)
1455 struct taal_data *td = container_of(work, struct taal_data,
1457 struct omap_dss_device *dssdev = td->dssdev;
1458 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1462 mutex_lock(&td->lock);
1465 mutex_unlock(&td->lock);
1471 r = taal_dcs_read_1(DCS_RDDSDR, &state1);
1473 dev_err(&dssdev->dev, "failed to read Taal status\n");
1477 /* Run self diagnostics */
1478 r = taal_sleep_out(td);
1480 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1484 r = taal_dcs_read_1(DCS_RDDSDR, &state2);
1486 dev_err(&dssdev->dev, "failed to read Taal status\n");
1490 /* Each sleep out command will trigger a self diagnostic and flip
1491 * Bit6 if the test passes.
1493 if (!((state1 ^ state2) & (1 << 6))) {
1494 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1497 /* Self-diagnostics result is also shown on TE GPIO line. We need
1498 * to re-enable TE after self diagnostics */
1499 if (td->te_enabled && panel_data->use_ext_te) {
1500 r = taal_dcs_write_1(DCS_TEAR_ON, 0);
1507 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1509 mutex_unlock(&td->lock);
1512 dev_err(&dssdev->dev, "performing LCD reset\n");
1514 taal_power_off(dssdev);
1515 taal_hw_reset(dssdev);
1516 taal_power_on(dssdev);
1520 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1522 mutex_unlock(&td->lock);
1525 static int taal_set_update_mode(struct omap_dss_device *dssdev,
1526 enum omap_dss_update_mode mode)
1528 if (mode != OMAP_DSS_UPDATE_MANUAL)
1533 static enum omap_dss_update_mode taal_get_update_mode(
1534 struct omap_dss_device *dssdev)
1536 return OMAP_DSS_UPDATE_MANUAL;
1539 static struct omap_dss_driver taal_driver = {
1540 .probe = taal_probe,
1541 .remove = taal_remove,
1543 .enable = taal_enable,
1544 .disable = taal_disable,
1545 .suspend = taal_suspend,
1546 .resume = taal_resume,
1548 .set_update_mode = taal_set_update_mode,
1549 .get_update_mode = taal_get_update_mode,
1551 .update = taal_update,
1554 .get_resolution = taal_get_resolution,
1555 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1557 .enable_te = taal_enable_te,
1558 .get_te = taal_get_te,
1560 .set_rotate = taal_rotate,
1561 .get_rotate = taal_get_rotate,
1562 .set_mirror = taal_mirror,
1563 .get_mirror = taal_get_mirror,
1564 .run_test = taal_run_test,
1565 .memory_read = taal_memory_read,
1567 .get_timings = taal_get_timings,
1571 .owner = THIS_MODULE,
1575 static int __init taal_init(void)
1577 omap_dss_register_driver(&taal_driver);
1582 static void __exit taal_exit(void)
1584 omap_dss_unregister_driver(&taal_driver);
1587 module_init(taal_init);
1588 module_exit(taal_exit);
1590 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1591 MODULE_DESCRIPTION("Taal Driver");
1592 MODULE_LICENSE("GPL");