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;
223 struct delayed_work te_timeout_work;
232 struct workqueue_struct *esd_wq;
233 struct delayed_work esd_work;
235 struct panel_config *panel_config;
238 static inline struct nokia_dsi_panel_data
239 *get_panel_data(const struct omap_dss_device *dssdev)
241 return (struct nokia_dsi_panel_data *) dssdev->data;
244 static void taal_esd_work(struct work_struct *work);
246 static void hw_guard_start(struct taal_data *td, int guard_msec)
248 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
249 td->hw_guard_end = jiffies + td->hw_guard_wait;
252 static void hw_guard_wait(struct taal_data *td)
254 unsigned long wait = td->hw_guard_end - jiffies;
256 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
257 set_current_state(TASK_UNINTERRUPTIBLE);
258 schedule_timeout(wait);
262 static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
267 r = dsi_vc_dcs_read(td->channel, dcs_cmd, buf, 1);
277 static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
279 return dsi_vc_dcs_write(td->channel, &dcs_cmd, 1);
282 static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
287 return dsi_vc_dcs_write(td->channel, buf, 2);
290 static int taal_sleep_in(struct taal_data *td)
299 r = dsi_vc_dcs_write_nosync(td->channel, &cmd, 1);
303 hw_guard_start(td, 120);
305 if (td->panel_config->sleep.sleep_in)
306 msleep(td->panel_config->sleep.sleep_in);
311 static int taal_sleep_out(struct taal_data *td)
317 r = taal_dcs_write_0(td, DCS_SLEEP_OUT);
321 hw_guard_start(td, 120);
323 if (td->panel_config->sleep.sleep_out)
324 msleep(td->panel_config->sleep.sleep_out);
329 static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
333 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
336 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
339 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
346 static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
352 r = taal_dcs_read_1(td, DCS_READ_MADCTL, &mode);
383 mode &= ~((1<<7) | (1<<6) | (1<<5));
384 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
386 return taal_dcs_write_1(td, DCS_MEM_ACC_CTRL, mode);
389 static int taal_set_update_window(struct taal_data *td,
390 u16 x, u16 y, u16 w, u16 h)
399 buf[0] = DCS_COLUMN_ADDR;
400 buf[1] = (x1 >> 8) & 0xff;
401 buf[2] = (x1 >> 0) & 0xff;
402 buf[3] = (x2 >> 8) & 0xff;
403 buf[4] = (x2 >> 0) & 0xff;
405 r = dsi_vc_dcs_write_nosync(td->channel, buf, sizeof(buf));
409 buf[0] = DCS_PAGE_ADDR;
410 buf[1] = (y1 >> 8) & 0xff;
411 buf[2] = (y1 >> 0) & 0xff;
412 buf[3] = (y2 >> 8) & 0xff;
413 buf[4] = (y2 >> 0) & 0xff;
415 r = dsi_vc_dcs_write_nosync(td->channel, buf, sizeof(buf));
419 dsi_vc_send_bta_sync(td->channel);
424 static int taal_bl_update_status(struct backlight_device *dev)
426 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
427 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
428 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
432 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
433 dev->props.power == FB_BLANK_UNBLANK)
434 level = dev->props.brightness;
438 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
440 mutex_lock(&td->lock);
442 if (td->use_dsi_bl) {
445 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
451 if (!panel_data->set_backlight)
454 r = panel_data->set_backlight(dssdev, level);
457 mutex_unlock(&td->lock);
462 static int taal_bl_get_intensity(struct backlight_device *dev)
464 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
465 dev->props.power == FB_BLANK_UNBLANK)
466 return dev->props.brightness;
471 static const struct backlight_ops taal_bl_ops = {
472 .get_brightness = taal_bl_get_intensity,
473 .update_status = taal_bl_update_status,
476 static void taal_get_timings(struct omap_dss_device *dssdev,
477 struct omap_video_timings *timings)
479 *timings = dssdev->panel.timings;
482 static void taal_get_resolution(struct omap_dss_device *dssdev,
483 u16 *xres, u16 *yres)
485 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
487 if (td->rotate == 0 || td->rotate == 2) {
488 *xres = dssdev->panel.timings.x_res;
489 *yres = dssdev->panel.timings.y_res;
491 *yres = dssdev->panel.timings.x_res;
492 *xres = dssdev->panel.timings.y_res;
496 static ssize_t taal_num_errors_show(struct device *dev,
497 struct device_attribute *attr, char *buf)
499 struct omap_dss_device *dssdev = to_dss_device(dev);
500 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
504 mutex_lock(&td->lock);
508 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
514 mutex_unlock(&td->lock);
519 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
522 static ssize_t taal_hw_revision_show(struct device *dev,
523 struct device_attribute *attr, char *buf)
525 struct omap_dss_device *dssdev = to_dss_device(dev);
526 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
530 mutex_lock(&td->lock);
534 r = taal_get_id(td, &id1, &id2, &id3);
540 mutex_unlock(&td->lock);
545 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
548 static const char *cabc_modes[] = {
549 "off", /* used also always when CABC is not supported */
555 static ssize_t show_cabc_mode(struct device *dev,
556 struct device_attribute *attr,
559 struct omap_dss_device *dssdev = to_dss_device(dev);
560 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
561 const char *mode_str;
565 mode = td->cabc_mode;
567 mode_str = "unknown";
568 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
569 mode_str = cabc_modes[mode];
570 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
572 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
575 static ssize_t store_cabc_mode(struct device *dev,
576 struct device_attribute *attr,
577 const char *buf, size_t count)
579 struct omap_dss_device *dssdev = to_dss_device(dev);
580 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
583 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
584 if (sysfs_streq(cabc_modes[i], buf))
588 if (i == ARRAY_SIZE(cabc_modes))
591 mutex_lock(&td->lock);
595 if (!td->cabc_broken)
596 taal_dcs_write_1(td, DCS_WRITE_CABC, i);
602 mutex_unlock(&td->lock);
607 static ssize_t show_cabc_available_modes(struct device *dev,
608 struct device_attribute *attr,
615 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
616 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
617 i ? " " : "", cabc_modes[i],
618 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
620 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
623 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
624 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
625 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
626 show_cabc_mode, store_cabc_mode);
627 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
628 show_cabc_available_modes, NULL);
630 static struct attribute *taal_attrs[] = {
631 &dev_attr_num_dsi_errors.attr,
632 &dev_attr_hw_revision.attr,
633 &dev_attr_cabc_mode.attr,
634 &dev_attr_cabc_available_modes.attr,
638 static struct attribute_group taal_attr_group = {
642 static void taal_hw_reset(struct omap_dss_device *dssdev)
644 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
645 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
647 if (panel_data->reset_gpio == -1)
650 gpio_set_value(panel_data->reset_gpio, 1);
651 if (td->panel_config->reset_sequence.high)
652 udelay(td->panel_config->reset_sequence.high);
653 /* reset the panel */
654 gpio_set_value(panel_data->reset_gpio, 0);
656 if (td->panel_config->reset_sequence.low)
657 udelay(td->panel_config->reset_sequence.low);
658 gpio_set_value(panel_data->reset_gpio, 1);
659 /* wait after releasing reset */
660 if (td->panel_config->sleep.hw_reset)
661 msleep(td->panel_config->sleep.hw_reset);
664 static int taal_probe(struct omap_dss_device *dssdev)
666 struct backlight_properties props;
667 struct taal_data *td;
668 struct backlight_device *bldev;
669 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
670 struct panel_config *panel_config = NULL;
673 dev_dbg(&dssdev->dev, "probe\n");
675 if (!panel_data || !panel_data->name) {
680 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
681 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
682 panel_config = &panel_configs[i];
692 dssdev->panel.config = OMAP_DSS_LCD_TFT;
693 dssdev->panel.timings = panel_config->timings;
694 dssdev->ctrl.pixel_size = 24;
696 td = kzalloc(sizeof(*td), GFP_KERNEL);
702 td->panel_config = panel_config;
704 mutex_init(&td->lock);
706 atomic_set(&td->do_update, 0);
708 r = init_regulators(dssdev, panel_config->regulators,
709 panel_config->num_regulators);
713 td->esd_wq = create_singlethread_workqueue("taal_esd");
714 if (td->esd_wq == NULL) {
715 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
719 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
721 dev_set_drvdata(&dssdev->dev, td);
723 taal_hw_reset(dssdev);
725 /* if no platform set_backlight() defined, presume DSI backlight
727 memset(&props, 0, sizeof(struct backlight_properties));
728 if (!panel_data->set_backlight)
729 td->use_dsi_bl = true;
732 props.max_brightness = 255;
734 props.max_brightness = 127;
736 props.type = BACKLIGHT_RAW;
737 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
738 &taal_bl_ops, &props);
746 bldev->props.fb_blank = FB_BLANK_UNBLANK;
747 bldev->props.power = FB_BLANK_UNBLANK;
749 bldev->props.brightness = 255;
751 bldev->props.brightness = 127;
753 taal_bl_update_status(bldev);
755 if (panel_data->use_ext_te) {
756 int gpio = panel_data->ext_te_gpio;
758 r = gpio_request(gpio, "taal irq");
760 dev_err(&dssdev->dev, "GPIO request failed\n");
764 gpio_direction_input(gpio);
766 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
767 IRQF_DISABLED | IRQF_TRIGGER_RISING,
768 "taal vsync", dssdev);
771 dev_err(&dssdev->dev, "IRQ request failed\n");
776 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
777 taal_te_timeout_work_callback);
779 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
782 r = omap_dsi_request_vc(dssdev, &td->channel);
784 dev_err(&dssdev->dev, "failed to get virtual channel\n");
788 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
790 dev_err(&dssdev->dev, "failed to set VC_ID\n");
794 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
796 dev_err(&dssdev->dev, "failed to create sysfs files\n");
803 omap_dsi_release_vc(dssdev, td->channel);
805 if (panel_data->use_ext_te)
806 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
808 if (panel_data->use_ext_te)
809 gpio_free(panel_data->ext_te_gpio);
811 backlight_device_unregister(bldev);
813 destroy_workqueue(td->esd_wq);
815 free_regulators(panel_config->regulators, panel_config->num_regulators);
822 static void taal_remove(struct omap_dss_device *dssdev)
824 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
825 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
826 struct backlight_device *bldev;
828 dev_dbg(&dssdev->dev, "remove\n");
830 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
831 omap_dsi_release_vc(dssdev, td->channel);
833 if (panel_data->use_ext_te) {
834 int gpio = panel_data->ext_te_gpio;
835 free_irq(gpio_to_irq(gpio), dssdev);
840 bldev->props.power = FB_BLANK_POWERDOWN;
841 taal_bl_update_status(bldev);
842 backlight_device_unregister(bldev);
844 cancel_delayed_work(&td->esd_work);
845 destroy_workqueue(td->esd_wq);
847 /* reset, to be sure that the panel is in a valid state */
848 taal_hw_reset(dssdev);
850 free_regulators(td->panel_config->regulators,
851 td->panel_config->num_regulators);
856 static int taal_power_on(struct omap_dss_device *dssdev)
858 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
862 r = omapdss_dsi_display_enable(dssdev);
864 dev_err(&dssdev->dev, "failed to enable DSI\n");
868 taal_hw_reset(dssdev);
870 omapdss_dsi_vc_enable_hs(td->channel, false);
872 r = taal_sleep_out(td);
876 r = taal_get_id(td, &id1, &id2, &id3);
880 /* on early Taal revisions CABC is broken */
881 if (td->panel_config->type == PANEL_TAAL &&
882 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
883 td->cabc_broken = true;
885 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
889 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
890 (1<<2) | (1<<5)); /* BL | BCTRL */
894 r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
898 r = taal_set_addr_mode(td, td->rotate, td->mirror);
902 if (!td->cabc_broken) {
903 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
908 r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
912 r = _taal_enable_te(dssdev, td->te_enabled);
918 if (!td->intro_printed) {
919 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
920 td->panel_config->name, id1, id2, id3);
922 dev_info(&dssdev->dev,
923 "old Taal version, CABC disabled\n");
924 td->intro_printed = true;
927 omapdss_dsi_vc_enable_hs(td->channel, true);
931 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
933 taal_hw_reset(dssdev);
935 omapdss_dsi_display_disable(dssdev);
940 static void taal_power_off(struct omap_dss_device *dssdev)
942 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
945 r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
947 r = taal_sleep_in(td);
948 /* HACK: wait a bit so that the message goes through */
953 dev_err(&dssdev->dev,
954 "error disabling panel, issuing HW reset\n");
955 taal_hw_reset(dssdev);
958 omapdss_dsi_display_disable(dssdev);
963 static int taal_enable(struct omap_dss_device *dssdev)
965 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
966 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
969 dev_dbg(&dssdev->dev, "enable\n");
971 mutex_lock(&td->lock);
973 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
980 r = taal_power_on(dssdev);
987 if (panel_data->use_esd_check)
988 queue_delayed_work(td->esd_wq, &td->esd_work,
989 TAAL_ESD_CHECK_PERIOD);
991 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
993 mutex_unlock(&td->lock);
997 dev_dbg(&dssdev->dev, "enable failed\n");
998 mutex_unlock(&td->lock);
1002 static void taal_disable(struct omap_dss_device *dssdev)
1004 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1006 dev_dbg(&dssdev->dev, "disable\n");
1008 mutex_lock(&td->lock);
1010 cancel_delayed_work(&td->esd_work);
1014 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
1015 taal_power_off(dssdev);
1019 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1021 mutex_unlock(&td->lock);
1024 static int taal_suspend(struct omap_dss_device *dssdev)
1026 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1029 dev_dbg(&dssdev->dev, "suspend\n");
1031 mutex_lock(&td->lock);
1033 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1038 cancel_delayed_work(&td->esd_work);
1042 taal_power_off(dssdev);
1046 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1048 mutex_unlock(&td->lock);
1052 mutex_unlock(&td->lock);
1056 static int taal_resume(struct omap_dss_device *dssdev)
1058 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1059 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1062 dev_dbg(&dssdev->dev, "resume\n");
1064 mutex_lock(&td->lock);
1066 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1073 r = taal_power_on(dssdev);
1078 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1080 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1081 if (panel_data->use_esd_check)
1082 queue_delayed_work(td->esd_wq, &td->esd_work,
1083 TAAL_ESD_CHECK_PERIOD);
1086 mutex_unlock(&td->lock);
1090 mutex_unlock(&td->lock);
1094 static void taal_framedone_cb(int err, void *data)
1096 struct omap_dss_device *dssdev = data;
1097 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1101 static irqreturn_t taal_te_isr(int irq, void *data)
1103 struct omap_dss_device *dssdev = data;
1104 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1108 old = atomic_cmpxchg(&td->do_update, 1, 0);
1111 cancel_delayed_work(&td->te_timeout_work);
1113 r = omap_dsi_update(dssdev, td->channel,
1114 td->update_region.x,
1115 td->update_region.y,
1116 td->update_region.w,
1117 td->update_region.h,
1118 taal_framedone_cb, dssdev);
1125 dev_err(&dssdev->dev, "start update failed\n");
1130 static void taal_te_timeout_work_callback(struct work_struct *work)
1132 struct taal_data *td = container_of(work, struct taal_data,
1133 te_timeout_work.work);
1134 struct omap_dss_device *dssdev = td->dssdev;
1136 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1138 atomic_set(&td->do_update, 0);
1142 static int taal_update(struct omap_dss_device *dssdev,
1143 u16 x, u16 y, u16 w, u16 h)
1145 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1146 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1149 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1151 mutex_lock(&td->lock);
1159 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
1163 r = taal_set_update_window(td, x, y, w, h);
1167 if (td->te_enabled && panel_data->use_ext_te) {
1168 td->update_region.x = x;
1169 td->update_region.y = y;
1170 td->update_region.w = w;
1171 td->update_region.h = h;
1173 schedule_delayed_work(&td->te_timeout_work,
1174 msecs_to_jiffies(250));
1175 atomic_set(&td->do_update, 1);
1177 r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
1178 taal_framedone_cb, dssdev);
1183 /* note: no bus_unlock here. unlock is in framedone_cb */
1184 mutex_unlock(&td->lock);
1188 mutex_unlock(&td->lock);
1192 static int taal_sync(struct omap_dss_device *dssdev)
1194 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1196 dev_dbg(&dssdev->dev, "sync\n");
1198 mutex_lock(&td->lock);
1201 mutex_unlock(&td->lock);
1203 dev_dbg(&dssdev->dev, "sync done\n");
1208 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1210 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1211 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1215 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1217 r = taal_dcs_write_0(td, DCS_TEAR_OFF);
1219 if (!panel_data->use_ext_te)
1220 omapdss_dsi_enable_te(dssdev, enable);
1222 if (td->panel_config->sleep.enable_te)
1223 msleep(td->panel_config->sleep.enable_te);
1228 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1230 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1233 mutex_lock(&td->lock);
1235 if (td->te_enabled == enable)
1241 r = _taal_enable_te(dssdev, enable);
1246 td->te_enabled = enable;
1250 mutex_unlock(&td->lock);
1255 mutex_unlock(&td->lock);
1260 static int taal_get_te(struct omap_dss_device *dssdev)
1262 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1265 mutex_lock(&td->lock);
1267 mutex_unlock(&td->lock);
1272 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1274 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1277 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1279 mutex_lock(&td->lock);
1281 if (td->rotate == rotate)
1287 r = taal_set_addr_mode(td, rotate, td->mirror);
1292 td->rotate = rotate;
1296 mutex_unlock(&td->lock);
1300 mutex_unlock(&td->lock);
1304 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1306 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1309 mutex_lock(&td->lock);
1311 mutex_unlock(&td->lock);
1316 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1318 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1321 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1323 mutex_lock(&td->lock);
1325 if (td->mirror == enable)
1330 r = taal_set_addr_mode(td, td->rotate, enable);
1335 td->mirror = enable;
1339 mutex_unlock(&td->lock);
1343 mutex_unlock(&td->lock);
1347 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1349 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1352 mutex_lock(&td->lock);
1354 mutex_unlock(&td->lock);
1359 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1361 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1365 mutex_lock(&td->lock);
1374 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1377 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1380 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1385 mutex_unlock(&td->lock);
1390 mutex_unlock(&td->lock);
1394 static int taal_memory_read(struct omap_dss_device *dssdev,
1395 void *buf, size_t size,
1396 u16 x, u16 y, u16 w, u16 h)
1401 unsigned buf_used = 0;
1402 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1404 if (size < w * h * 3)
1407 mutex_lock(&td->lock);
1414 size = min(w * h * 3,
1415 dssdev->panel.timings.x_res *
1416 dssdev->panel.timings.y_res * 3);
1420 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1421 * use short packets. plen 32 works, but bigger packets seem to cause
1428 taal_set_update_window(td, x, y, w, h);
1430 r = dsi_vc_set_max_rx_packet_size(td->channel, plen);
1434 while (buf_used < size) {
1435 u8 dcs_cmd = first ? 0x2e : 0x3e;
1438 r = dsi_vc_dcs_read(td->channel, dcs_cmd,
1439 buf + buf_used, size - buf_used);
1442 dev_err(&dssdev->dev, "read error\n");
1449 dev_err(&dssdev->dev, "short read\n");
1453 if (signal_pending(current)) {
1454 dev_err(&dssdev->dev, "signal pending, "
1455 "aborting memory read\n");
1464 dsi_vc_set_max_rx_packet_size(td->channel, 1);
1468 mutex_unlock(&td->lock);
1472 static void taal_esd_work(struct work_struct *work)
1474 struct taal_data *td = container_of(work, struct taal_data,
1476 struct omap_dss_device *dssdev = td->dssdev;
1477 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1481 mutex_lock(&td->lock);
1484 mutex_unlock(&td->lock);
1490 r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
1492 dev_err(&dssdev->dev, "failed to read Taal status\n");
1496 /* Run self diagnostics */
1497 r = taal_sleep_out(td);
1499 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1503 r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
1505 dev_err(&dssdev->dev, "failed to read Taal status\n");
1509 /* Each sleep out command will trigger a self diagnostic and flip
1510 * Bit6 if the test passes.
1512 if (!((state1 ^ state2) & (1 << 6))) {
1513 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1516 /* Self-diagnostics result is also shown on TE GPIO line. We need
1517 * to re-enable TE after self diagnostics */
1518 if (td->te_enabled && panel_data->use_ext_te) {
1519 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1526 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1528 mutex_unlock(&td->lock);
1531 dev_err(&dssdev->dev, "performing LCD reset\n");
1533 taal_power_off(dssdev);
1534 taal_hw_reset(dssdev);
1535 taal_power_on(dssdev);
1539 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1541 mutex_unlock(&td->lock);
1544 static int taal_set_update_mode(struct omap_dss_device *dssdev,
1545 enum omap_dss_update_mode mode)
1547 if (mode != OMAP_DSS_UPDATE_MANUAL)
1552 static enum omap_dss_update_mode taal_get_update_mode(
1553 struct omap_dss_device *dssdev)
1555 return OMAP_DSS_UPDATE_MANUAL;
1558 static struct omap_dss_driver taal_driver = {
1559 .probe = taal_probe,
1560 .remove = taal_remove,
1562 .enable = taal_enable,
1563 .disable = taal_disable,
1564 .suspend = taal_suspend,
1565 .resume = taal_resume,
1567 .set_update_mode = taal_set_update_mode,
1568 .get_update_mode = taal_get_update_mode,
1570 .update = taal_update,
1573 .get_resolution = taal_get_resolution,
1574 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1576 .enable_te = taal_enable_te,
1577 .get_te = taal_get_te,
1579 .set_rotate = taal_rotate,
1580 .get_rotate = taal_get_rotate,
1581 .set_mirror = taal_mirror,
1582 .get_mirror = taal_get_mirror,
1583 .run_test = taal_run_test,
1584 .memory_read = taal_memory_read,
1586 .get_timings = taal_get_timings,
1590 .owner = THIS_MODULE,
1594 static int __init taal_init(void)
1596 omap_dss_register_driver(&taal_driver);
1601 static void __exit taal_exit(void)
1603 omap_dss_unregister_driver(&taal_driver);
1606 module_init(taal_init);
1607 module_exit(taal_exit);
1609 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1610 MODULE_DESCRIPTION("Taal Driver");
1611 MODULE_LICENSE("GPL");