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 <video/omapdss.h>
37 #include <video/omap-panel-nokia-dsi.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 static irqreturn_t taal_te_isr(int irq, void *data);
67 static void taal_te_timeout_work_callback(struct work_struct *work);
68 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
70 struct panel_regulator {
71 struct regulator *regulator;
77 static void free_regulators(struct panel_regulator *regulators, int n)
81 for (i = 0; i < n; i++) {
82 /* disable/put in reverse order */
83 regulator_disable(regulators[n - i - 1].regulator);
84 regulator_put(regulators[n - i - 1].regulator);
88 static int init_regulators(struct omap_dss_device *dssdev,
89 struct panel_regulator *regulators, int n)
93 for (i = 0; i < n; i++) {
94 struct regulator *reg;
96 reg = regulator_get(&dssdev->dev, regulators[i].name);
98 dev_err(&dssdev->dev, "failed to get regulator %s\n",
104 /* FIXME: better handling of fixed vs. variable regulators */
105 v = regulator_get_voltage(reg);
106 if (v < regulators[i].min_uV || v > regulators[i].max_uV) {
107 r = regulator_set_voltage(reg, regulators[i].min_uV,
108 regulators[i].max_uV);
110 dev_err(&dssdev->dev,
111 "failed to set regulator %s voltage\n",
118 r = regulator_enable(reg);
120 dev_err(&dssdev->dev, "failed to enable regulator %s\n",
126 regulators[i].regulator = reg;
132 free_regulators(regulators, i);
138 * struct panel_config - panel configuration
141 * @timings: panel resolution
142 * @sleep: various panel specific delays, passed to msleep() if non-zero
143 * @reset_sequence: reset sequence timings, passed to udelay() if non-zero
144 * @regulators: array of panel regulators
145 * @num_regulators: number of regulators in the array
147 struct panel_config {
151 struct omap_video_timings timings;
154 unsigned int sleep_in;
155 unsigned int sleep_out;
156 unsigned int hw_reset;
157 unsigned int enable_te;
165 struct panel_regulator *regulators;
173 static struct panel_config panel_configs[] = {
185 .enable_te = 100, /* possible panel bug */
197 struct backlight_device *bldev;
199 unsigned long hw_guard_end; /* next value of jiffies when we can
200 * issue the next sleep in/out command
202 unsigned long hw_guard_wait; /* max guard time in jiffies */
204 struct omap_dss_device *dssdev;
221 struct delayed_work te_timeout_work;
230 struct workqueue_struct *workqueue;
232 struct delayed_work esd_work;
233 unsigned esd_interval;
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 void taal_queue_esd_work(struct omap_dss_device *dssdev)
426 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
428 if (td->esd_interval > 0)
429 queue_delayed_work(td->workqueue, &td->esd_work,
430 msecs_to_jiffies(td->esd_interval));
433 static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
435 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
437 cancel_delayed_work(&td->esd_work);
440 static int taal_bl_update_status(struct backlight_device *dev)
442 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
443 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
444 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
448 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
449 dev->props.power == FB_BLANK_UNBLANK)
450 level = dev->props.brightness;
454 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
456 mutex_lock(&td->lock);
458 if (td->use_dsi_bl) {
461 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
467 if (!panel_data->set_backlight)
470 r = panel_data->set_backlight(dssdev, level);
473 mutex_unlock(&td->lock);
478 static int taal_bl_get_intensity(struct backlight_device *dev)
480 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
481 dev->props.power == FB_BLANK_UNBLANK)
482 return dev->props.brightness;
487 static const struct backlight_ops taal_bl_ops = {
488 .get_brightness = taal_bl_get_intensity,
489 .update_status = taal_bl_update_status,
492 static void taal_get_timings(struct omap_dss_device *dssdev,
493 struct omap_video_timings *timings)
495 *timings = dssdev->panel.timings;
498 static void taal_get_resolution(struct omap_dss_device *dssdev,
499 u16 *xres, u16 *yres)
501 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
503 if (td->rotate == 0 || td->rotate == 2) {
504 *xres = dssdev->panel.timings.x_res;
505 *yres = dssdev->panel.timings.y_res;
507 *yres = dssdev->panel.timings.x_res;
508 *xres = dssdev->panel.timings.y_res;
512 static ssize_t taal_num_errors_show(struct device *dev,
513 struct device_attribute *attr, char *buf)
515 struct omap_dss_device *dssdev = to_dss_device(dev);
516 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
520 mutex_lock(&td->lock);
524 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
530 mutex_unlock(&td->lock);
535 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
538 static ssize_t taal_hw_revision_show(struct device *dev,
539 struct device_attribute *attr, char *buf)
541 struct omap_dss_device *dssdev = to_dss_device(dev);
542 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
546 mutex_lock(&td->lock);
550 r = taal_get_id(td, &id1, &id2, &id3);
556 mutex_unlock(&td->lock);
561 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
564 static const char *cabc_modes[] = {
565 "off", /* used also always when CABC is not supported */
571 static ssize_t show_cabc_mode(struct device *dev,
572 struct device_attribute *attr,
575 struct omap_dss_device *dssdev = to_dss_device(dev);
576 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
577 const char *mode_str;
581 mode = td->cabc_mode;
583 mode_str = "unknown";
584 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
585 mode_str = cabc_modes[mode];
586 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
588 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
591 static ssize_t store_cabc_mode(struct device *dev,
592 struct device_attribute *attr,
593 const char *buf, size_t count)
595 struct omap_dss_device *dssdev = to_dss_device(dev);
596 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
599 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
600 if (sysfs_streq(cabc_modes[i], buf))
604 if (i == ARRAY_SIZE(cabc_modes))
607 mutex_lock(&td->lock);
611 if (!td->cabc_broken)
612 taal_dcs_write_1(td, DCS_WRITE_CABC, i);
618 mutex_unlock(&td->lock);
623 static ssize_t show_cabc_available_modes(struct device *dev,
624 struct device_attribute *attr,
631 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
632 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
633 i ? " " : "", cabc_modes[i],
634 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
636 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
639 static ssize_t taal_store_esd_interval(struct device *dev,
640 struct device_attribute *attr,
641 const char *buf, size_t count)
643 struct omap_dss_device *dssdev = to_dss_device(dev);
644 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
649 r = strict_strtoul(buf, 10, &t);
653 mutex_lock(&td->lock);
654 taal_cancel_esd_work(dssdev);
655 td->esd_interval = t;
657 taal_queue_esd_work(dssdev);
658 mutex_unlock(&td->lock);
663 static ssize_t taal_show_esd_interval(struct device *dev,
664 struct device_attribute *attr,
667 struct omap_dss_device *dssdev = to_dss_device(dev);
668 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
671 mutex_lock(&td->lock);
672 t = td->esd_interval;
673 mutex_unlock(&td->lock);
675 return snprintf(buf, PAGE_SIZE, "%u\n", t);
678 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
679 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
680 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
681 show_cabc_mode, store_cabc_mode);
682 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
683 show_cabc_available_modes, NULL);
684 static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
685 taal_show_esd_interval, taal_store_esd_interval);
687 static struct attribute *taal_attrs[] = {
688 &dev_attr_num_dsi_errors.attr,
689 &dev_attr_hw_revision.attr,
690 &dev_attr_cabc_mode.attr,
691 &dev_attr_cabc_available_modes.attr,
692 &dev_attr_esd_interval.attr,
696 static struct attribute_group taal_attr_group = {
700 static void taal_hw_reset(struct omap_dss_device *dssdev)
702 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
703 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
705 if (panel_data->reset_gpio == -1)
708 gpio_set_value(panel_data->reset_gpio, 1);
709 if (td->panel_config->reset_sequence.high)
710 udelay(td->panel_config->reset_sequence.high);
711 /* reset the panel */
712 gpio_set_value(panel_data->reset_gpio, 0);
714 if (td->panel_config->reset_sequence.low)
715 udelay(td->panel_config->reset_sequence.low);
716 gpio_set_value(panel_data->reset_gpio, 1);
717 /* wait after releasing reset */
718 if (td->panel_config->sleep.hw_reset)
719 msleep(td->panel_config->sleep.hw_reset);
722 static int taal_probe(struct omap_dss_device *dssdev)
724 struct backlight_properties props;
725 struct taal_data *td;
726 struct backlight_device *bldev;
727 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
728 struct panel_config *panel_config = NULL;
731 dev_dbg(&dssdev->dev, "probe\n");
733 if (!panel_data || !panel_data->name) {
738 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
739 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
740 panel_config = &panel_configs[i];
750 dssdev->panel.config = OMAP_DSS_LCD_TFT;
751 dssdev->panel.timings = panel_config->timings;
752 dssdev->ctrl.pixel_size = 24;
754 td = kzalloc(sizeof(*td), GFP_KERNEL);
760 td->panel_config = panel_config;
761 td->esd_interval = panel_data->esd_interval;
763 mutex_init(&td->lock);
765 atomic_set(&td->do_update, 0);
767 r = init_regulators(dssdev, panel_config->regulators,
768 panel_config->num_regulators);
772 td->workqueue = create_singlethread_workqueue("taal_esd");
773 if (td->workqueue == NULL) {
774 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
778 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
780 dev_set_drvdata(&dssdev->dev, td);
782 taal_hw_reset(dssdev);
784 /* if no platform set_backlight() defined, presume DSI backlight
786 memset(&props, 0, sizeof(struct backlight_properties));
787 if (!panel_data->set_backlight)
788 td->use_dsi_bl = true;
791 props.max_brightness = 255;
793 props.max_brightness = 127;
795 props.type = BACKLIGHT_RAW;
796 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
797 &taal_bl_ops, &props);
805 bldev->props.fb_blank = FB_BLANK_UNBLANK;
806 bldev->props.power = FB_BLANK_UNBLANK;
808 bldev->props.brightness = 255;
810 bldev->props.brightness = 127;
812 taal_bl_update_status(bldev);
814 if (panel_data->use_ext_te) {
815 int gpio = panel_data->ext_te_gpio;
817 r = gpio_request(gpio, "taal irq");
819 dev_err(&dssdev->dev, "GPIO request failed\n");
823 gpio_direction_input(gpio);
825 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
826 IRQF_DISABLED | IRQF_TRIGGER_RISING,
827 "taal vsync", dssdev);
830 dev_err(&dssdev->dev, "IRQ request failed\n");
835 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
836 taal_te_timeout_work_callback);
838 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
841 r = omap_dsi_request_vc(dssdev, &td->channel);
843 dev_err(&dssdev->dev, "failed to get virtual channel\n");
847 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
849 dev_err(&dssdev->dev, "failed to set VC_ID\n");
853 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
855 dev_err(&dssdev->dev, "failed to create sysfs files\n");
862 omap_dsi_release_vc(dssdev, td->channel);
864 if (panel_data->use_ext_te)
865 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
867 if (panel_data->use_ext_te)
868 gpio_free(panel_data->ext_te_gpio);
870 backlight_device_unregister(bldev);
872 destroy_workqueue(td->workqueue);
874 free_regulators(panel_config->regulators, panel_config->num_regulators);
881 static void __exit taal_remove(struct omap_dss_device *dssdev)
883 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
884 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
885 struct backlight_device *bldev;
887 dev_dbg(&dssdev->dev, "remove\n");
889 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
890 omap_dsi_release_vc(dssdev, td->channel);
892 if (panel_data->use_ext_te) {
893 int gpio = panel_data->ext_te_gpio;
894 free_irq(gpio_to_irq(gpio), dssdev);
899 bldev->props.power = FB_BLANK_POWERDOWN;
900 taal_bl_update_status(bldev);
901 backlight_device_unregister(bldev);
903 taal_cancel_esd_work(dssdev);
904 destroy_workqueue(td->workqueue);
906 /* reset, to be sure that the panel is in a valid state */
907 taal_hw_reset(dssdev);
909 free_regulators(td->panel_config->regulators,
910 td->panel_config->num_regulators);
915 static int taal_power_on(struct omap_dss_device *dssdev)
917 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
921 r = omapdss_dsi_display_enable(dssdev);
923 dev_err(&dssdev->dev, "failed to enable DSI\n");
927 taal_hw_reset(dssdev);
929 omapdss_dsi_vc_enable_hs(td->channel, false);
931 r = taal_sleep_out(td);
935 r = taal_get_id(td, &id1, &id2, &id3);
939 /* on early Taal revisions CABC is broken */
940 if (td->panel_config->type == PANEL_TAAL &&
941 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
942 td->cabc_broken = true;
944 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
948 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
949 (1<<2) | (1<<5)); /* BL | BCTRL */
953 r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
957 r = taal_set_addr_mode(td, td->rotate, td->mirror);
961 if (!td->cabc_broken) {
962 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
967 r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
971 r = _taal_enable_te(dssdev, td->te_enabled);
977 if (!td->intro_printed) {
978 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
979 td->panel_config->name, id1, id2, id3);
981 dev_info(&dssdev->dev,
982 "old Taal version, CABC disabled\n");
983 td->intro_printed = true;
986 omapdss_dsi_vc_enable_hs(td->channel, true);
990 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
992 taal_hw_reset(dssdev);
994 omapdss_dsi_display_disable(dssdev, true, false);
999 static void taal_power_off(struct omap_dss_device *dssdev)
1001 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1004 r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
1006 r = taal_sleep_in(td);
1007 /* HACK: wait a bit so that the message goes through */
1012 dev_err(&dssdev->dev,
1013 "error disabling panel, issuing HW reset\n");
1014 taal_hw_reset(dssdev);
1017 omapdss_dsi_display_disable(dssdev, true, false);
1022 static int taal_panel_reset(struct omap_dss_device *dssdev)
1024 dev_err(&dssdev->dev, "performing LCD reset\n");
1026 taal_power_off(dssdev);
1027 taal_hw_reset(dssdev);
1028 return taal_power_on(dssdev);
1031 static int taal_enable(struct omap_dss_device *dssdev)
1033 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1036 dev_dbg(&dssdev->dev, "enable\n");
1038 mutex_lock(&td->lock);
1040 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
1047 r = taal_power_on(dssdev);
1054 taal_queue_esd_work(dssdev);
1056 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1058 mutex_unlock(&td->lock);
1062 dev_dbg(&dssdev->dev, "enable failed\n");
1063 mutex_unlock(&td->lock);
1067 static void taal_disable(struct omap_dss_device *dssdev)
1069 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1071 dev_dbg(&dssdev->dev, "disable\n");
1073 mutex_lock(&td->lock);
1075 taal_cancel_esd_work(dssdev);
1079 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
1080 taal_power_off(dssdev);
1084 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1086 mutex_unlock(&td->lock);
1089 static int taal_suspend(struct omap_dss_device *dssdev)
1091 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1094 dev_dbg(&dssdev->dev, "suspend\n");
1096 mutex_lock(&td->lock);
1098 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1103 taal_cancel_esd_work(dssdev);
1107 taal_power_off(dssdev);
1111 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1113 mutex_unlock(&td->lock);
1117 mutex_unlock(&td->lock);
1121 static int taal_resume(struct omap_dss_device *dssdev)
1123 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1126 dev_dbg(&dssdev->dev, "resume\n");
1128 mutex_lock(&td->lock);
1130 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1137 r = taal_power_on(dssdev);
1142 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1144 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1145 taal_queue_esd_work(dssdev);
1148 mutex_unlock(&td->lock);
1152 mutex_unlock(&td->lock);
1156 static void taal_framedone_cb(int err, void *data)
1158 struct omap_dss_device *dssdev = data;
1159 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1163 static irqreturn_t taal_te_isr(int irq, void *data)
1165 struct omap_dss_device *dssdev = data;
1166 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1170 old = atomic_cmpxchg(&td->do_update, 1, 0);
1173 cancel_delayed_work(&td->te_timeout_work);
1175 r = omap_dsi_update(dssdev, td->channel,
1176 td->update_region.x,
1177 td->update_region.y,
1178 td->update_region.w,
1179 td->update_region.h,
1180 taal_framedone_cb, dssdev);
1187 dev_err(&dssdev->dev, "start update failed\n");
1192 static void taal_te_timeout_work_callback(struct work_struct *work)
1194 struct taal_data *td = container_of(work, struct taal_data,
1195 te_timeout_work.work);
1196 struct omap_dss_device *dssdev = td->dssdev;
1198 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1200 atomic_set(&td->do_update, 0);
1204 static int taal_update(struct omap_dss_device *dssdev,
1205 u16 x, u16 y, u16 w, u16 h)
1207 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1208 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1211 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1213 mutex_lock(&td->lock);
1221 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
1225 r = taal_set_update_window(td, x, y, w, h);
1229 if (td->te_enabled && panel_data->use_ext_te) {
1230 td->update_region.x = x;
1231 td->update_region.y = y;
1232 td->update_region.w = w;
1233 td->update_region.h = h;
1235 schedule_delayed_work(&td->te_timeout_work,
1236 msecs_to_jiffies(250));
1237 atomic_set(&td->do_update, 1);
1239 r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
1240 taal_framedone_cb, dssdev);
1245 /* note: no bus_unlock here. unlock is in framedone_cb */
1246 mutex_unlock(&td->lock);
1250 mutex_unlock(&td->lock);
1254 static int taal_sync(struct omap_dss_device *dssdev)
1256 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1258 dev_dbg(&dssdev->dev, "sync\n");
1260 mutex_lock(&td->lock);
1263 mutex_unlock(&td->lock);
1265 dev_dbg(&dssdev->dev, "sync done\n");
1270 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1272 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1273 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1277 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1279 r = taal_dcs_write_0(td, DCS_TEAR_OFF);
1281 if (!panel_data->use_ext_te)
1282 omapdss_dsi_enable_te(dssdev, enable);
1284 if (td->panel_config->sleep.enable_te)
1285 msleep(td->panel_config->sleep.enable_te);
1290 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1292 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1295 mutex_lock(&td->lock);
1297 if (td->te_enabled == enable)
1303 r = _taal_enable_te(dssdev, enable);
1308 td->te_enabled = enable;
1312 mutex_unlock(&td->lock);
1317 mutex_unlock(&td->lock);
1322 static int taal_get_te(struct omap_dss_device *dssdev)
1324 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1327 mutex_lock(&td->lock);
1329 mutex_unlock(&td->lock);
1334 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1336 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1339 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1341 mutex_lock(&td->lock);
1343 if (td->rotate == rotate)
1349 r = taal_set_addr_mode(td, rotate, td->mirror);
1354 td->rotate = rotate;
1358 mutex_unlock(&td->lock);
1362 mutex_unlock(&td->lock);
1366 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1368 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1371 mutex_lock(&td->lock);
1373 mutex_unlock(&td->lock);
1378 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1380 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1383 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1385 mutex_lock(&td->lock);
1387 if (td->mirror == enable)
1392 r = taal_set_addr_mode(td, td->rotate, enable);
1397 td->mirror = enable;
1401 mutex_unlock(&td->lock);
1405 mutex_unlock(&td->lock);
1409 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1411 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1414 mutex_lock(&td->lock);
1416 mutex_unlock(&td->lock);
1421 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1423 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1427 mutex_lock(&td->lock);
1436 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1439 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1442 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1447 mutex_unlock(&td->lock);
1452 mutex_unlock(&td->lock);
1456 static int taal_memory_read(struct omap_dss_device *dssdev,
1457 void *buf, size_t size,
1458 u16 x, u16 y, u16 w, u16 h)
1463 unsigned buf_used = 0;
1464 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1466 if (size < w * h * 3)
1469 mutex_lock(&td->lock);
1476 size = min(w * h * 3,
1477 dssdev->panel.timings.x_res *
1478 dssdev->panel.timings.y_res * 3);
1482 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1483 * use short packets. plen 32 works, but bigger packets seem to cause
1490 taal_set_update_window(td, x, y, w, h);
1492 r = dsi_vc_set_max_rx_packet_size(td->channel, plen);
1496 while (buf_used < size) {
1497 u8 dcs_cmd = first ? 0x2e : 0x3e;
1500 r = dsi_vc_dcs_read(td->channel, dcs_cmd,
1501 buf + buf_used, size - buf_used);
1504 dev_err(&dssdev->dev, "read error\n");
1511 dev_err(&dssdev->dev, "short read\n");
1515 if (signal_pending(current)) {
1516 dev_err(&dssdev->dev, "signal pending, "
1517 "aborting memory read\n");
1526 dsi_vc_set_max_rx_packet_size(td->channel, 1);
1530 mutex_unlock(&td->lock);
1534 static void taal_esd_work(struct work_struct *work)
1536 struct taal_data *td = container_of(work, struct taal_data,
1538 struct omap_dss_device *dssdev = td->dssdev;
1539 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1543 mutex_lock(&td->lock);
1546 mutex_unlock(&td->lock);
1552 r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
1554 dev_err(&dssdev->dev, "failed to read Taal status\n");
1558 /* Run self diagnostics */
1559 r = taal_sleep_out(td);
1561 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1565 r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
1567 dev_err(&dssdev->dev, "failed to read Taal status\n");
1571 /* Each sleep out command will trigger a self diagnostic and flip
1572 * Bit6 if the test passes.
1574 if (!((state1 ^ state2) & (1 << 6))) {
1575 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1578 /* Self-diagnostics result is also shown on TE GPIO line. We need
1579 * to re-enable TE after self diagnostics */
1580 if (td->te_enabled && panel_data->use_ext_te) {
1581 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1588 taal_queue_esd_work(dssdev);
1590 mutex_unlock(&td->lock);
1593 dev_err(&dssdev->dev, "performing LCD reset\n");
1595 taal_panel_reset(dssdev);
1599 taal_queue_esd_work(dssdev);
1601 mutex_unlock(&td->lock);
1604 static int taal_set_update_mode(struct omap_dss_device *dssdev,
1605 enum omap_dss_update_mode mode)
1607 if (mode != OMAP_DSS_UPDATE_MANUAL)
1612 static enum omap_dss_update_mode taal_get_update_mode(
1613 struct omap_dss_device *dssdev)
1615 return OMAP_DSS_UPDATE_MANUAL;
1618 static struct omap_dss_driver taal_driver = {
1619 .probe = taal_probe,
1620 .remove = __exit_p(taal_remove),
1622 .enable = taal_enable,
1623 .disable = taal_disable,
1624 .suspend = taal_suspend,
1625 .resume = taal_resume,
1627 .set_update_mode = taal_set_update_mode,
1628 .get_update_mode = taal_get_update_mode,
1630 .update = taal_update,
1633 .get_resolution = taal_get_resolution,
1634 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1636 .enable_te = taal_enable_te,
1637 .get_te = taal_get_te,
1639 .set_rotate = taal_rotate,
1640 .get_rotate = taal_get_rotate,
1641 .set_mirror = taal_mirror,
1642 .get_mirror = taal_get_mirror,
1643 .run_test = taal_run_test,
1644 .memory_read = taal_memory_read,
1646 .get_timings = taal_get_timings,
1650 .owner = THIS_MODULE,
1654 static int __init taal_init(void)
1656 omap_dss_register_driver(&taal_driver);
1661 static void __exit taal_exit(void)
1663 omap_dss_unregister_driver(&taal_driver);
1666 module_init(taal_init);
1667 module_exit(taal_exit);
1669 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1670 MODULE_DESCRIPTION("Taal Driver");
1671 MODULE_LICENSE("GPL");