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 *esd_wq;
231 struct delayed_work esd_work;
232 unsigned esd_interval;
234 struct panel_config *panel_config;
237 static inline struct nokia_dsi_panel_data
238 *get_panel_data(const struct omap_dss_device *dssdev)
240 return (struct nokia_dsi_panel_data *) dssdev->data;
243 static void taal_esd_work(struct work_struct *work);
245 static void hw_guard_start(struct taal_data *td, int guard_msec)
247 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
248 td->hw_guard_end = jiffies + td->hw_guard_wait;
251 static void hw_guard_wait(struct taal_data *td)
253 unsigned long wait = td->hw_guard_end - jiffies;
255 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
256 set_current_state(TASK_UNINTERRUPTIBLE);
257 schedule_timeout(wait);
261 static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
266 r = dsi_vc_dcs_read(td->channel, dcs_cmd, buf, 1);
276 static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
278 return dsi_vc_dcs_write(td->channel, &dcs_cmd, 1);
281 static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
286 return dsi_vc_dcs_write(td->channel, buf, 2);
289 static int taal_sleep_in(struct taal_data *td)
298 r = dsi_vc_dcs_write_nosync(td->channel, &cmd, 1);
302 hw_guard_start(td, 120);
304 if (td->panel_config->sleep.sleep_in)
305 msleep(td->panel_config->sleep.sleep_in);
310 static int taal_sleep_out(struct taal_data *td)
316 r = taal_dcs_write_0(td, DCS_SLEEP_OUT);
320 hw_guard_start(td, 120);
322 if (td->panel_config->sleep.sleep_out)
323 msleep(td->panel_config->sleep.sleep_out);
328 static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
332 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
335 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
338 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
345 static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
351 r = taal_dcs_read_1(td, DCS_READ_MADCTL, &mode);
382 mode &= ~((1<<7) | (1<<6) | (1<<5));
383 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
385 return taal_dcs_write_1(td, DCS_MEM_ACC_CTRL, mode);
388 static int taal_set_update_window(struct taal_data *td,
389 u16 x, u16 y, u16 w, u16 h)
398 buf[0] = DCS_COLUMN_ADDR;
399 buf[1] = (x1 >> 8) & 0xff;
400 buf[2] = (x1 >> 0) & 0xff;
401 buf[3] = (x2 >> 8) & 0xff;
402 buf[4] = (x2 >> 0) & 0xff;
404 r = dsi_vc_dcs_write_nosync(td->channel, buf, sizeof(buf));
408 buf[0] = DCS_PAGE_ADDR;
409 buf[1] = (y1 >> 8) & 0xff;
410 buf[2] = (y1 >> 0) & 0xff;
411 buf[3] = (y2 >> 8) & 0xff;
412 buf[4] = (y2 >> 0) & 0xff;
414 r = dsi_vc_dcs_write_nosync(td->channel, buf, sizeof(buf));
418 dsi_vc_send_bta_sync(td->channel);
423 static void taal_queue_esd_work(struct omap_dss_device *dssdev)
425 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
427 if (td->esd_interval > 0)
428 queue_delayed_work(td->esd_wq, &td->esd_work,
429 msecs_to_jiffies(td->esd_interval));
432 static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
434 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
436 cancel_delayed_work(&td->esd_work);
439 static int taal_bl_update_status(struct backlight_device *dev)
441 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
442 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
443 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
447 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
448 dev->props.power == FB_BLANK_UNBLANK)
449 level = dev->props.brightness;
453 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
455 mutex_lock(&td->lock);
457 if (td->use_dsi_bl) {
460 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
466 if (!panel_data->set_backlight)
469 r = panel_data->set_backlight(dssdev, level);
472 mutex_unlock(&td->lock);
477 static int taal_bl_get_intensity(struct backlight_device *dev)
479 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
480 dev->props.power == FB_BLANK_UNBLANK)
481 return dev->props.brightness;
486 static const struct backlight_ops taal_bl_ops = {
487 .get_brightness = taal_bl_get_intensity,
488 .update_status = taal_bl_update_status,
491 static void taal_get_timings(struct omap_dss_device *dssdev,
492 struct omap_video_timings *timings)
494 *timings = dssdev->panel.timings;
497 static void taal_get_resolution(struct omap_dss_device *dssdev,
498 u16 *xres, u16 *yres)
500 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
502 if (td->rotate == 0 || td->rotate == 2) {
503 *xres = dssdev->panel.timings.x_res;
504 *yres = dssdev->panel.timings.y_res;
506 *yres = dssdev->panel.timings.x_res;
507 *xres = dssdev->panel.timings.y_res;
511 static ssize_t taal_num_errors_show(struct device *dev,
512 struct device_attribute *attr, char *buf)
514 struct omap_dss_device *dssdev = to_dss_device(dev);
515 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
519 mutex_lock(&td->lock);
523 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
529 mutex_unlock(&td->lock);
534 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
537 static ssize_t taal_hw_revision_show(struct device *dev,
538 struct device_attribute *attr, char *buf)
540 struct omap_dss_device *dssdev = to_dss_device(dev);
541 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
545 mutex_lock(&td->lock);
549 r = taal_get_id(td, &id1, &id2, &id3);
555 mutex_unlock(&td->lock);
560 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
563 static const char *cabc_modes[] = {
564 "off", /* used also always when CABC is not supported */
570 static ssize_t show_cabc_mode(struct device *dev,
571 struct device_attribute *attr,
574 struct omap_dss_device *dssdev = to_dss_device(dev);
575 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
576 const char *mode_str;
580 mode = td->cabc_mode;
582 mode_str = "unknown";
583 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
584 mode_str = cabc_modes[mode];
585 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
587 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
590 static ssize_t store_cabc_mode(struct device *dev,
591 struct device_attribute *attr,
592 const char *buf, size_t count)
594 struct omap_dss_device *dssdev = to_dss_device(dev);
595 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
598 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
599 if (sysfs_streq(cabc_modes[i], buf))
603 if (i == ARRAY_SIZE(cabc_modes))
606 mutex_lock(&td->lock);
610 if (!td->cabc_broken)
611 taal_dcs_write_1(td, DCS_WRITE_CABC, i);
617 mutex_unlock(&td->lock);
622 static ssize_t show_cabc_available_modes(struct device *dev,
623 struct device_attribute *attr,
630 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
631 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
632 i ? " " : "", cabc_modes[i],
633 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
635 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
638 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
639 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
640 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
641 show_cabc_mode, store_cabc_mode);
642 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
643 show_cabc_available_modes, NULL);
645 static struct attribute *taal_attrs[] = {
646 &dev_attr_num_dsi_errors.attr,
647 &dev_attr_hw_revision.attr,
648 &dev_attr_cabc_mode.attr,
649 &dev_attr_cabc_available_modes.attr,
653 static struct attribute_group taal_attr_group = {
657 static void taal_hw_reset(struct omap_dss_device *dssdev)
659 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
660 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
662 if (panel_data->reset_gpio == -1)
665 gpio_set_value(panel_data->reset_gpio, 1);
666 if (td->panel_config->reset_sequence.high)
667 udelay(td->panel_config->reset_sequence.high);
668 /* reset the panel */
669 gpio_set_value(panel_data->reset_gpio, 0);
671 if (td->panel_config->reset_sequence.low)
672 udelay(td->panel_config->reset_sequence.low);
673 gpio_set_value(panel_data->reset_gpio, 1);
674 /* wait after releasing reset */
675 if (td->panel_config->sleep.hw_reset)
676 msleep(td->panel_config->sleep.hw_reset);
679 static int taal_probe(struct omap_dss_device *dssdev)
681 struct backlight_properties props;
682 struct taal_data *td;
683 struct backlight_device *bldev;
684 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
685 struct panel_config *panel_config = NULL;
688 dev_dbg(&dssdev->dev, "probe\n");
690 if (!panel_data || !panel_data->name) {
695 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
696 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
697 panel_config = &panel_configs[i];
707 dssdev->panel.config = OMAP_DSS_LCD_TFT;
708 dssdev->panel.timings = panel_config->timings;
709 dssdev->ctrl.pixel_size = 24;
711 td = kzalloc(sizeof(*td), GFP_KERNEL);
717 td->panel_config = panel_config;
718 td->esd_interval = panel_data->esd_interval;
720 mutex_init(&td->lock);
722 atomic_set(&td->do_update, 0);
724 r = init_regulators(dssdev, panel_config->regulators,
725 panel_config->num_regulators);
729 td->esd_wq = create_singlethread_workqueue("taal_esd");
730 if (td->esd_wq == NULL) {
731 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
735 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
737 dev_set_drvdata(&dssdev->dev, td);
739 taal_hw_reset(dssdev);
741 /* if no platform set_backlight() defined, presume DSI backlight
743 memset(&props, 0, sizeof(struct backlight_properties));
744 if (!panel_data->set_backlight)
745 td->use_dsi_bl = true;
748 props.max_brightness = 255;
750 props.max_brightness = 127;
752 props.type = BACKLIGHT_RAW;
753 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
754 &taal_bl_ops, &props);
762 bldev->props.fb_blank = FB_BLANK_UNBLANK;
763 bldev->props.power = FB_BLANK_UNBLANK;
765 bldev->props.brightness = 255;
767 bldev->props.brightness = 127;
769 taal_bl_update_status(bldev);
771 if (panel_data->use_ext_te) {
772 int gpio = panel_data->ext_te_gpio;
774 r = gpio_request(gpio, "taal irq");
776 dev_err(&dssdev->dev, "GPIO request failed\n");
780 gpio_direction_input(gpio);
782 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
783 IRQF_DISABLED | IRQF_TRIGGER_RISING,
784 "taal vsync", dssdev);
787 dev_err(&dssdev->dev, "IRQ request failed\n");
792 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
793 taal_te_timeout_work_callback);
795 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
798 r = omap_dsi_request_vc(dssdev, &td->channel);
800 dev_err(&dssdev->dev, "failed to get virtual channel\n");
804 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
806 dev_err(&dssdev->dev, "failed to set VC_ID\n");
810 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
812 dev_err(&dssdev->dev, "failed to create sysfs files\n");
819 omap_dsi_release_vc(dssdev, td->channel);
821 if (panel_data->use_ext_te)
822 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
824 if (panel_data->use_ext_te)
825 gpio_free(panel_data->ext_te_gpio);
827 backlight_device_unregister(bldev);
829 destroy_workqueue(td->esd_wq);
831 free_regulators(panel_config->regulators, panel_config->num_regulators);
838 static void __exit taal_remove(struct omap_dss_device *dssdev)
840 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
841 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
842 struct backlight_device *bldev;
844 dev_dbg(&dssdev->dev, "remove\n");
846 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
847 omap_dsi_release_vc(dssdev, td->channel);
849 if (panel_data->use_ext_te) {
850 int gpio = panel_data->ext_te_gpio;
851 free_irq(gpio_to_irq(gpio), dssdev);
856 bldev->props.power = FB_BLANK_POWERDOWN;
857 taal_bl_update_status(bldev);
858 backlight_device_unregister(bldev);
860 taal_cancel_esd_work(dssdev);
861 destroy_workqueue(td->esd_wq);
863 /* reset, to be sure that the panel is in a valid state */
864 taal_hw_reset(dssdev);
866 free_regulators(td->panel_config->regulators,
867 td->panel_config->num_regulators);
872 static int taal_power_on(struct omap_dss_device *dssdev)
874 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
878 r = omapdss_dsi_display_enable(dssdev);
880 dev_err(&dssdev->dev, "failed to enable DSI\n");
884 taal_hw_reset(dssdev);
886 omapdss_dsi_vc_enable_hs(td->channel, false);
888 r = taal_sleep_out(td);
892 r = taal_get_id(td, &id1, &id2, &id3);
896 /* on early Taal revisions CABC is broken */
897 if (td->panel_config->type == PANEL_TAAL &&
898 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
899 td->cabc_broken = true;
901 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
905 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
906 (1<<2) | (1<<5)); /* BL | BCTRL */
910 r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
914 r = taal_set_addr_mode(td, td->rotate, td->mirror);
918 if (!td->cabc_broken) {
919 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
924 r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
928 r = _taal_enable_te(dssdev, td->te_enabled);
934 if (!td->intro_printed) {
935 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
936 td->panel_config->name, id1, id2, id3);
938 dev_info(&dssdev->dev,
939 "old Taal version, CABC disabled\n");
940 td->intro_printed = true;
943 omapdss_dsi_vc_enable_hs(td->channel, true);
947 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
949 taal_hw_reset(dssdev);
951 omapdss_dsi_display_disable(dssdev, true, false);
956 static void taal_power_off(struct omap_dss_device *dssdev)
958 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
961 r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
963 r = taal_sleep_in(td);
964 /* HACK: wait a bit so that the message goes through */
969 dev_err(&dssdev->dev,
970 "error disabling panel, issuing HW reset\n");
971 taal_hw_reset(dssdev);
974 omapdss_dsi_display_disable(dssdev, true, false);
979 static int taal_enable(struct omap_dss_device *dssdev)
981 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
984 dev_dbg(&dssdev->dev, "enable\n");
986 mutex_lock(&td->lock);
988 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
995 r = taal_power_on(dssdev);
1002 taal_queue_esd_work(dssdev);
1004 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1006 mutex_unlock(&td->lock);
1010 dev_dbg(&dssdev->dev, "enable failed\n");
1011 mutex_unlock(&td->lock);
1015 static void taal_disable(struct omap_dss_device *dssdev)
1017 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1019 dev_dbg(&dssdev->dev, "disable\n");
1021 mutex_lock(&td->lock);
1023 taal_cancel_esd_work(dssdev);
1027 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
1028 taal_power_off(dssdev);
1032 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1034 mutex_unlock(&td->lock);
1037 static int taal_suspend(struct omap_dss_device *dssdev)
1039 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1042 dev_dbg(&dssdev->dev, "suspend\n");
1044 mutex_lock(&td->lock);
1046 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1051 taal_cancel_esd_work(dssdev);
1055 taal_power_off(dssdev);
1059 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1061 mutex_unlock(&td->lock);
1065 mutex_unlock(&td->lock);
1069 static int taal_resume(struct omap_dss_device *dssdev)
1071 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1074 dev_dbg(&dssdev->dev, "resume\n");
1076 mutex_lock(&td->lock);
1078 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1085 r = taal_power_on(dssdev);
1090 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1092 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1093 taal_queue_esd_work(dssdev);
1096 mutex_unlock(&td->lock);
1100 mutex_unlock(&td->lock);
1104 static void taal_framedone_cb(int err, void *data)
1106 struct omap_dss_device *dssdev = data;
1107 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1111 static irqreturn_t taal_te_isr(int irq, void *data)
1113 struct omap_dss_device *dssdev = data;
1114 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1118 old = atomic_cmpxchg(&td->do_update, 1, 0);
1121 cancel_delayed_work(&td->te_timeout_work);
1123 r = omap_dsi_update(dssdev, td->channel,
1124 td->update_region.x,
1125 td->update_region.y,
1126 td->update_region.w,
1127 td->update_region.h,
1128 taal_framedone_cb, dssdev);
1135 dev_err(&dssdev->dev, "start update failed\n");
1140 static void taal_te_timeout_work_callback(struct work_struct *work)
1142 struct taal_data *td = container_of(work, struct taal_data,
1143 te_timeout_work.work);
1144 struct omap_dss_device *dssdev = td->dssdev;
1146 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1148 atomic_set(&td->do_update, 0);
1152 static int taal_update(struct omap_dss_device *dssdev,
1153 u16 x, u16 y, u16 w, u16 h)
1155 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1156 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1159 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1161 mutex_lock(&td->lock);
1169 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
1173 r = taal_set_update_window(td, x, y, w, h);
1177 if (td->te_enabled && panel_data->use_ext_te) {
1178 td->update_region.x = x;
1179 td->update_region.y = y;
1180 td->update_region.w = w;
1181 td->update_region.h = h;
1183 schedule_delayed_work(&td->te_timeout_work,
1184 msecs_to_jiffies(250));
1185 atomic_set(&td->do_update, 1);
1187 r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
1188 taal_framedone_cb, dssdev);
1193 /* note: no bus_unlock here. unlock is in framedone_cb */
1194 mutex_unlock(&td->lock);
1198 mutex_unlock(&td->lock);
1202 static int taal_sync(struct omap_dss_device *dssdev)
1204 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1206 dev_dbg(&dssdev->dev, "sync\n");
1208 mutex_lock(&td->lock);
1211 mutex_unlock(&td->lock);
1213 dev_dbg(&dssdev->dev, "sync done\n");
1218 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1220 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1221 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1225 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1227 r = taal_dcs_write_0(td, DCS_TEAR_OFF);
1229 if (!panel_data->use_ext_te)
1230 omapdss_dsi_enable_te(dssdev, enable);
1232 if (td->panel_config->sleep.enable_te)
1233 msleep(td->panel_config->sleep.enable_te);
1238 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1240 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1243 mutex_lock(&td->lock);
1245 if (td->te_enabled == enable)
1251 r = _taal_enable_te(dssdev, enable);
1256 td->te_enabled = enable;
1260 mutex_unlock(&td->lock);
1265 mutex_unlock(&td->lock);
1270 static int taal_get_te(struct omap_dss_device *dssdev)
1272 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1275 mutex_lock(&td->lock);
1277 mutex_unlock(&td->lock);
1282 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1284 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1287 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1289 mutex_lock(&td->lock);
1291 if (td->rotate == rotate)
1297 r = taal_set_addr_mode(td, rotate, td->mirror);
1302 td->rotate = rotate;
1306 mutex_unlock(&td->lock);
1310 mutex_unlock(&td->lock);
1314 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1316 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1319 mutex_lock(&td->lock);
1321 mutex_unlock(&td->lock);
1326 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1328 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1331 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1333 mutex_lock(&td->lock);
1335 if (td->mirror == enable)
1340 r = taal_set_addr_mode(td, td->rotate, enable);
1345 td->mirror = enable;
1349 mutex_unlock(&td->lock);
1353 mutex_unlock(&td->lock);
1357 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1359 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1362 mutex_lock(&td->lock);
1364 mutex_unlock(&td->lock);
1369 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1371 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1375 mutex_lock(&td->lock);
1384 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1387 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1390 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1395 mutex_unlock(&td->lock);
1400 mutex_unlock(&td->lock);
1404 static int taal_memory_read(struct omap_dss_device *dssdev,
1405 void *buf, size_t size,
1406 u16 x, u16 y, u16 w, u16 h)
1411 unsigned buf_used = 0;
1412 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1414 if (size < w * h * 3)
1417 mutex_lock(&td->lock);
1424 size = min(w * h * 3,
1425 dssdev->panel.timings.x_res *
1426 dssdev->panel.timings.y_res * 3);
1430 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1431 * use short packets. plen 32 works, but bigger packets seem to cause
1438 taal_set_update_window(td, x, y, w, h);
1440 r = dsi_vc_set_max_rx_packet_size(td->channel, plen);
1444 while (buf_used < size) {
1445 u8 dcs_cmd = first ? 0x2e : 0x3e;
1448 r = dsi_vc_dcs_read(td->channel, dcs_cmd,
1449 buf + buf_used, size - buf_used);
1452 dev_err(&dssdev->dev, "read error\n");
1459 dev_err(&dssdev->dev, "short read\n");
1463 if (signal_pending(current)) {
1464 dev_err(&dssdev->dev, "signal pending, "
1465 "aborting memory read\n");
1474 dsi_vc_set_max_rx_packet_size(td->channel, 1);
1478 mutex_unlock(&td->lock);
1482 static void taal_esd_work(struct work_struct *work)
1484 struct taal_data *td = container_of(work, struct taal_data,
1486 struct omap_dss_device *dssdev = td->dssdev;
1487 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1491 mutex_lock(&td->lock);
1494 mutex_unlock(&td->lock);
1500 r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
1502 dev_err(&dssdev->dev, "failed to read Taal status\n");
1506 /* Run self diagnostics */
1507 r = taal_sleep_out(td);
1509 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1513 r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
1515 dev_err(&dssdev->dev, "failed to read Taal status\n");
1519 /* Each sleep out command will trigger a self diagnostic and flip
1520 * Bit6 if the test passes.
1522 if (!((state1 ^ state2) & (1 << 6))) {
1523 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1526 /* Self-diagnostics result is also shown on TE GPIO line. We need
1527 * to re-enable TE after self diagnostics */
1528 if (td->te_enabled && panel_data->use_ext_te) {
1529 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1536 taal_queue_esd_work(dssdev);
1538 mutex_unlock(&td->lock);
1541 dev_err(&dssdev->dev, "performing LCD reset\n");
1543 taal_power_off(dssdev);
1544 taal_hw_reset(dssdev);
1545 taal_power_on(dssdev);
1549 taal_queue_esd_work(dssdev);
1551 mutex_unlock(&td->lock);
1554 static int taal_set_update_mode(struct omap_dss_device *dssdev,
1555 enum omap_dss_update_mode mode)
1557 if (mode != OMAP_DSS_UPDATE_MANUAL)
1562 static enum omap_dss_update_mode taal_get_update_mode(
1563 struct omap_dss_device *dssdev)
1565 return OMAP_DSS_UPDATE_MANUAL;
1568 static struct omap_dss_driver taal_driver = {
1569 .probe = taal_probe,
1570 .remove = __exit_p(taal_remove),
1572 .enable = taal_enable,
1573 .disable = taal_disable,
1574 .suspend = taal_suspend,
1575 .resume = taal_resume,
1577 .set_update_mode = taal_set_update_mode,
1578 .get_update_mode = taal_get_update_mode,
1580 .update = taal_update,
1583 .get_resolution = taal_get_resolution,
1584 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1586 .enable_te = taal_enable_te,
1587 .get_te = taal_get_te,
1589 .set_rotate = taal_rotate,
1590 .get_rotate = taal_get_rotate,
1591 .set_mirror = taal_mirror,
1592 .get_mirror = taal_get_mirror,
1593 .run_test = taal_run_test,
1594 .memory_read = taal_memory_read,
1596 .get_timings = taal_get_timings,
1600 .owner = THIS_MODULE,
1604 static int __init taal_init(void)
1606 omap_dss_register_driver(&taal_driver);
1611 static void __exit taal_exit(void)
1613 omap_dss_unregister_driver(&taal_driver);
1616 module_init(taal_init);
1617 module_exit(taal_exit);
1619 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1620 MODULE_DESCRIPTION("Taal Driver");
1621 MODULE_LICENSE("GPL");