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/mutex.h>
35 #include <video/omapdss.h>
36 #include <video/omap-panel-data.h>
37 #include <video/mipi_display.h>
39 /* DSI Virtual channel. Hardcoded for now. */
42 #define DCS_READ_NUM_ERRORS 0x05
43 #define DCS_BRIGHTNESS 0x51
44 #define DCS_CTRL_DISPLAY 0x53
45 #define DCS_WRITE_CABC 0x55
46 #define DCS_READ_CABC 0x56
47 #define DCS_GET_ID1 0xda
48 #define DCS_GET_ID2 0xdb
49 #define DCS_GET_ID3 0xdc
51 static irqreturn_t taal_te_isr(int irq, void *data);
52 static void taal_te_timeout_work_callback(struct work_struct *work);
53 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
55 static int taal_panel_reset(struct omap_dss_device *dssdev);
60 struct backlight_device *bldev;
62 unsigned long hw_guard_end; /* next value of jiffies when we can
63 * issue the next sleep in/out command
65 unsigned long hw_guard_wait; /* max guard time in jiffies */
67 struct omap_dss_device *dssdev;
69 /* panel HW configuration from DT or platform data */
73 bool use_dsi_backlight;
75 struct omap_dsi_pin_config pin_config;
77 /* runtime variables */
85 struct delayed_work te_timeout_work;
92 struct workqueue_struct *workqueue;
94 struct delayed_work esd_work;
95 unsigned esd_interval;
98 unsigned ulps_timeout;
99 struct delayed_work ulps_work;
102 static void taal_esd_work(struct work_struct *work);
103 static void taal_ulps_work(struct work_struct *work);
105 static void hw_guard_start(struct taal_data *td, int guard_msec)
107 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
108 td->hw_guard_end = jiffies + td->hw_guard_wait;
111 static void hw_guard_wait(struct taal_data *td)
113 unsigned long wait = td->hw_guard_end - jiffies;
115 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
116 set_current_state(TASK_UNINTERRUPTIBLE);
117 schedule_timeout(wait);
121 static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
126 r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1);
136 static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
138 return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1);
141 static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
146 return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2);
149 static int taal_sleep_in(struct taal_data *td)
157 cmd = MIPI_DCS_ENTER_SLEEP_MODE;
158 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1);
162 hw_guard_start(td, 120);
169 static int taal_sleep_out(struct taal_data *td)
175 r = taal_dcs_write_0(td, MIPI_DCS_EXIT_SLEEP_MODE);
179 hw_guard_start(td, 120);
186 static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
190 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
193 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
196 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
203 static int taal_set_update_window(struct taal_data *td,
204 u16 x, u16 y, u16 w, u16 h)
213 buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
214 buf[1] = (x1 >> 8) & 0xff;
215 buf[2] = (x1 >> 0) & 0xff;
216 buf[3] = (x2 >> 8) & 0xff;
217 buf[4] = (x2 >> 0) & 0xff;
219 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
223 buf[0] = MIPI_DCS_SET_PAGE_ADDRESS;
224 buf[1] = (y1 >> 8) & 0xff;
225 buf[2] = (y1 >> 0) & 0xff;
226 buf[3] = (y2 >> 8) & 0xff;
227 buf[4] = (y2 >> 0) & 0xff;
229 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
233 dsi_vc_send_bta_sync(td->dssdev, td->channel);
238 static void taal_queue_esd_work(struct omap_dss_device *dssdev)
240 struct taal_data *td = dev_get_drvdata(dssdev->dev);
242 if (td->esd_interval > 0)
243 queue_delayed_work(td->workqueue, &td->esd_work,
244 msecs_to_jiffies(td->esd_interval));
247 static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
249 struct taal_data *td = dev_get_drvdata(dssdev->dev);
251 cancel_delayed_work(&td->esd_work);
254 static void taal_queue_ulps_work(struct omap_dss_device *dssdev)
256 struct taal_data *td = dev_get_drvdata(dssdev->dev);
258 if (td->ulps_timeout > 0)
259 queue_delayed_work(td->workqueue, &td->ulps_work,
260 msecs_to_jiffies(td->ulps_timeout));
263 static void taal_cancel_ulps_work(struct omap_dss_device *dssdev)
265 struct taal_data *td = dev_get_drvdata(dssdev->dev);
267 cancel_delayed_work(&td->ulps_work);
270 static int taal_enter_ulps(struct omap_dss_device *dssdev)
272 struct taal_data *td = dev_get_drvdata(dssdev->dev);
275 if (td->ulps_enabled)
278 taal_cancel_ulps_work(dssdev);
280 r = _taal_enable_te(dssdev, false);
284 if (gpio_is_valid(td->ext_te_gpio))
285 disable_irq(gpio_to_irq(td->ext_te_gpio));
287 omapdss_dsi_display_disable(dssdev, false, true);
289 td->ulps_enabled = true;
294 dev_err(dssdev->dev, "enter ULPS failed");
295 taal_panel_reset(dssdev);
297 td->ulps_enabled = false;
299 taal_queue_ulps_work(dssdev);
304 static int taal_exit_ulps(struct omap_dss_device *dssdev)
306 struct taal_data *td = dev_get_drvdata(dssdev->dev);
309 if (!td->ulps_enabled)
312 r = omapdss_dsi_display_enable(dssdev);
314 dev_err(dssdev->dev, "failed to enable DSI\n");
318 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
320 r = _taal_enable_te(dssdev, true);
322 dev_err(dssdev->dev, "failed to re-enable TE");
326 if (gpio_is_valid(td->ext_te_gpio))
327 enable_irq(gpio_to_irq(td->ext_te_gpio));
329 taal_queue_ulps_work(dssdev);
331 td->ulps_enabled = false;
336 dev_err(dssdev->dev, "failed to exit ULPS");
338 r = taal_panel_reset(dssdev);
340 if (gpio_is_valid(td->ext_te_gpio))
341 enable_irq(gpio_to_irq(td->ext_te_gpio));
342 td->ulps_enabled = false;
345 taal_queue_ulps_work(dssdev);
350 static int taal_wake_up(struct omap_dss_device *dssdev)
352 struct taal_data *td = dev_get_drvdata(dssdev->dev);
354 if (td->ulps_enabled)
355 return taal_exit_ulps(dssdev);
357 taal_cancel_ulps_work(dssdev);
358 taal_queue_ulps_work(dssdev);
362 static int taal_bl_update_status(struct backlight_device *dev)
364 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
365 struct taal_data *td = dev_get_drvdata(dssdev->dev);
369 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
370 dev->props.power == FB_BLANK_UNBLANK)
371 level = dev->props.brightness;
375 dev_dbg(dssdev->dev, "update brightness to %d\n", level);
377 mutex_lock(&td->lock);
380 dsi_bus_lock(dssdev);
382 r = taal_wake_up(dssdev);
384 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
386 dsi_bus_unlock(dssdev);
391 mutex_unlock(&td->lock);
396 static int taal_bl_get_intensity(struct backlight_device *dev)
398 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
399 dev->props.power == FB_BLANK_UNBLANK)
400 return dev->props.brightness;
405 static const struct backlight_ops taal_bl_ops = {
406 .get_brightness = taal_bl_get_intensity,
407 .update_status = taal_bl_update_status,
410 static void taal_get_resolution(struct omap_dss_device *dssdev,
411 u16 *xres, u16 *yres)
413 *xres = dssdev->panel.timings.x_res;
414 *yres = dssdev->panel.timings.y_res;
417 static ssize_t taal_num_errors_show(struct device *dev,
418 struct device_attribute *attr, char *buf)
420 struct omap_dss_device *dssdev = to_dss_device(dev);
421 struct taal_data *td = dev_get_drvdata(dssdev->dev);
425 mutex_lock(&td->lock);
428 dsi_bus_lock(dssdev);
430 r = taal_wake_up(dssdev);
432 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
434 dsi_bus_unlock(dssdev);
439 mutex_unlock(&td->lock);
444 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
447 static ssize_t taal_hw_revision_show(struct device *dev,
448 struct device_attribute *attr, char *buf)
450 struct omap_dss_device *dssdev = to_dss_device(dev);
451 struct taal_data *td = dev_get_drvdata(dssdev->dev);
455 mutex_lock(&td->lock);
458 dsi_bus_lock(dssdev);
460 r = taal_wake_up(dssdev);
462 r = taal_get_id(td, &id1, &id2, &id3);
464 dsi_bus_unlock(dssdev);
469 mutex_unlock(&td->lock);
474 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
477 static const char *cabc_modes[] = {
478 "off", /* used also always when CABC is not supported */
484 static ssize_t show_cabc_mode(struct device *dev,
485 struct device_attribute *attr,
488 struct omap_dss_device *dssdev = to_dss_device(dev);
489 struct taal_data *td = dev_get_drvdata(dssdev->dev);
490 const char *mode_str;
494 mode = td->cabc_mode;
496 mode_str = "unknown";
497 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
498 mode_str = cabc_modes[mode];
499 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
501 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
504 static ssize_t store_cabc_mode(struct device *dev,
505 struct device_attribute *attr,
506 const char *buf, size_t count)
508 struct omap_dss_device *dssdev = to_dss_device(dev);
509 struct taal_data *td = dev_get_drvdata(dssdev->dev);
513 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
514 if (sysfs_streq(cabc_modes[i], buf))
518 if (i == ARRAY_SIZE(cabc_modes))
521 mutex_lock(&td->lock);
524 dsi_bus_lock(dssdev);
526 if (!td->cabc_broken) {
527 r = taal_wake_up(dssdev);
531 r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
536 dsi_bus_unlock(dssdev);
541 mutex_unlock(&td->lock);
545 dsi_bus_unlock(dssdev);
546 mutex_unlock(&td->lock);
550 static ssize_t show_cabc_available_modes(struct device *dev,
551 struct device_attribute *attr,
558 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
559 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
560 i ? " " : "", cabc_modes[i],
561 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
563 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
566 static ssize_t taal_store_esd_interval(struct device *dev,
567 struct device_attribute *attr,
568 const char *buf, size_t count)
570 struct omap_dss_device *dssdev = to_dss_device(dev);
571 struct taal_data *td = dev_get_drvdata(dssdev->dev);
576 r = kstrtoul(buf, 10, &t);
580 mutex_lock(&td->lock);
581 taal_cancel_esd_work(dssdev);
582 td->esd_interval = t;
584 taal_queue_esd_work(dssdev);
585 mutex_unlock(&td->lock);
590 static ssize_t taal_show_esd_interval(struct device *dev,
591 struct device_attribute *attr,
594 struct omap_dss_device *dssdev = to_dss_device(dev);
595 struct taal_data *td = dev_get_drvdata(dssdev->dev);
598 mutex_lock(&td->lock);
599 t = td->esd_interval;
600 mutex_unlock(&td->lock);
602 return snprintf(buf, PAGE_SIZE, "%u\n", t);
605 static ssize_t taal_store_ulps(struct device *dev,
606 struct device_attribute *attr,
607 const char *buf, size_t count)
609 struct omap_dss_device *dssdev = to_dss_device(dev);
610 struct taal_data *td = dev_get_drvdata(dssdev->dev);
614 r = kstrtoul(buf, 10, &t);
618 mutex_lock(&td->lock);
621 dsi_bus_lock(dssdev);
624 r = taal_enter_ulps(dssdev);
626 r = taal_wake_up(dssdev);
628 dsi_bus_unlock(dssdev);
631 mutex_unlock(&td->lock);
639 static ssize_t taal_show_ulps(struct device *dev,
640 struct device_attribute *attr,
643 struct omap_dss_device *dssdev = to_dss_device(dev);
644 struct taal_data *td = dev_get_drvdata(dssdev->dev);
647 mutex_lock(&td->lock);
648 t = td->ulps_enabled;
649 mutex_unlock(&td->lock);
651 return snprintf(buf, PAGE_SIZE, "%u\n", t);
654 static ssize_t taal_store_ulps_timeout(struct device *dev,
655 struct device_attribute *attr,
656 const char *buf, size_t count)
658 struct omap_dss_device *dssdev = to_dss_device(dev);
659 struct taal_data *td = dev_get_drvdata(dssdev->dev);
663 r = kstrtoul(buf, 10, &t);
667 mutex_lock(&td->lock);
668 td->ulps_timeout = t;
671 /* taal_wake_up will restart the timer */
672 dsi_bus_lock(dssdev);
673 r = taal_wake_up(dssdev);
674 dsi_bus_unlock(dssdev);
677 mutex_unlock(&td->lock);
685 static ssize_t taal_show_ulps_timeout(struct device *dev,
686 struct device_attribute *attr,
689 struct omap_dss_device *dssdev = to_dss_device(dev);
690 struct taal_data *td = dev_get_drvdata(dssdev->dev);
693 mutex_lock(&td->lock);
694 t = td->ulps_timeout;
695 mutex_unlock(&td->lock);
697 return snprintf(buf, PAGE_SIZE, "%u\n", t);
700 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
701 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
702 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
703 show_cabc_mode, store_cabc_mode);
704 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
705 show_cabc_available_modes, NULL);
706 static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
707 taal_show_esd_interval, taal_store_esd_interval);
708 static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
709 taal_show_ulps, taal_store_ulps);
710 static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
711 taal_show_ulps_timeout, taal_store_ulps_timeout);
713 static struct attribute *taal_attrs[] = {
714 &dev_attr_num_dsi_errors.attr,
715 &dev_attr_hw_revision.attr,
716 &dev_attr_cabc_mode.attr,
717 &dev_attr_cabc_available_modes.attr,
718 &dev_attr_esd_interval.attr,
720 &dev_attr_ulps_timeout.attr,
724 static struct attribute_group taal_attr_group = {
728 static void taal_hw_reset(struct omap_dss_device *dssdev)
730 struct taal_data *td = dev_get_drvdata(dssdev->dev);
732 if (!gpio_is_valid(td->reset_gpio))
735 gpio_set_value(td->reset_gpio, 1);
737 /* reset the panel */
738 gpio_set_value(td->reset_gpio, 0);
741 gpio_set_value(td->reset_gpio, 1);
742 /* wait after releasing reset */
746 static void taal_probe_pdata(struct taal_data *td,
747 const struct nokia_dsi_panel_data *pdata)
749 td->reset_gpio = pdata->reset_gpio;
751 if (pdata->use_ext_te)
752 td->ext_te_gpio = pdata->ext_te_gpio;
754 td->ext_te_gpio = -1;
756 td->esd_interval = pdata->esd_interval;
757 td->ulps_timeout = pdata->ulps_timeout;
759 td->use_dsi_backlight = pdata->use_dsi_backlight;
761 td->pin_config = pdata->pin_config;
764 static int taal_probe(struct omap_dss_device *dssdev)
766 struct backlight_properties props;
767 struct taal_data *td;
768 struct backlight_device *bldev = NULL;
771 dev_dbg(dssdev->dev, "probe\n");
773 td = devm_kzalloc(dssdev->dev, sizeof(*td), GFP_KERNEL);
777 dev_set_drvdata(dssdev->dev, td);
781 const struct nokia_dsi_panel_data *pdata = dssdev->data;
783 taal_probe_pdata(td, pdata);
788 dssdev->panel.timings.x_res = 864;
789 dssdev->panel.timings.y_res = 480;
790 dssdev->panel.timings.pixel_clock = DIV_ROUND_UP(864 * 480 * 60, 1000);
791 dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
792 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
793 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
795 mutex_init(&td->lock);
797 atomic_set(&td->do_update, 0);
799 if (gpio_is_valid(td->reset_gpio)) {
800 r = devm_gpio_request_one(dssdev->dev, td->reset_gpio,
801 GPIOF_OUT_INIT_LOW, "taal rst");
803 dev_err(dssdev->dev, "failed to request reset gpio\n");
808 if (gpio_is_valid(td->ext_te_gpio)) {
809 r = devm_gpio_request_one(dssdev->dev, td->ext_te_gpio,
810 GPIOF_IN, "taal irq");
812 dev_err(dssdev->dev, "GPIO request failed\n");
816 r = devm_request_irq(dssdev->dev, gpio_to_irq(td->ext_te_gpio),
819 "taal vsync", dssdev);
822 dev_err(dssdev->dev, "IRQ request failed\n");
826 INIT_DEFERRABLE_WORK(&td->te_timeout_work,
827 taal_te_timeout_work_callback);
829 dev_dbg(dssdev->dev, "Using GPIO TE\n");
832 td->workqueue = create_singlethread_workqueue("taal_esd");
833 if (td->workqueue == NULL) {
834 dev_err(dssdev->dev, "can't create ESD workqueue\n");
837 INIT_DEFERRABLE_WORK(&td->esd_work, taal_esd_work);
838 INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
840 taal_hw_reset(dssdev);
842 if (td->use_dsi_backlight) {
843 memset(&props, 0, sizeof(struct backlight_properties));
844 props.max_brightness = 255;
846 props.type = BACKLIGHT_RAW;
847 bldev = backlight_device_register(dev_name(dssdev->dev),
848 dssdev->dev, dssdev, &taal_bl_ops, &props);
856 bldev->props.fb_blank = FB_BLANK_UNBLANK;
857 bldev->props.power = FB_BLANK_UNBLANK;
858 bldev->props.brightness = 255;
860 taal_bl_update_status(bldev);
863 r = omap_dsi_request_vc(dssdev, &td->channel);
865 dev_err(dssdev->dev, "failed to get virtual channel\n");
869 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
871 dev_err(dssdev->dev, "failed to set VC_ID\n");
875 r = sysfs_create_group(&dssdev->dev->kobj, &taal_attr_group);
877 dev_err(dssdev->dev, "failed to create sysfs files\n");
884 omap_dsi_release_vc(dssdev, td->channel);
887 backlight_device_unregister(bldev);
889 destroy_workqueue(td->workqueue);
893 static void __exit taal_remove(struct omap_dss_device *dssdev)
895 struct taal_data *td = dev_get_drvdata(dssdev->dev);
896 struct backlight_device *bldev;
898 dev_dbg(dssdev->dev, "remove\n");
900 sysfs_remove_group(&dssdev->dev->kobj, &taal_attr_group);
901 omap_dsi_release_vc(dssdev, td->channel);
905 bldev->props.power = FB_BLANK_POWERDOWN;
906 taal_bl_update_status(bldev);
907 backlight_device_unregister(bldev);
910 taal_cancel_ulps_work(dssdev);
911 taal_cancel_esd_work(dssdev);
912 destroy_workqueue(td->workqueue);
914 /* reset, to be sure that the panel is in a valid state */
915 taal_hw_reset(dssdev);
918 static int taal_power_on(struct omap_dss_device *dssdev)
920 struct taal_data *td = dev_get_drvdata(dssdev->dev);
923 struct omap_dss_dsi_config dsi_config = {
924 .mode = OMAP_DSS_DSI_CMD_MODE,
925 .pixel_format = OMAP_DSS_DSI_FMT_RGB888,
926 .timings = &dssdev->panel.timings,
927 .hs_clk_min = 150000000,
928 .hs_clk_max = 300000000,
929 .lp_clk_min = 7000000,
930 .lp_clk_max = 10000000,
933 r = omapdss_dsi_configure_pins(dssdev, &td->pin_config);
935 dev_err(dssdev->dev, "failed to configure DSI pins\n");
939 r = omapdss_dsi_set_config(dssdev, &dsi_config);
941 dev_err(dssdev->dev, "failed to configure DSI\n");
945 r = omapdss_dsi_display_enable(dssdev);
947 dev_err(dssdev->dev, "failed to enable DSI\n");
951 taal_hw_reset(dssdev);
953 omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
955 r = taal_sleep_out(td);
959 r = taal_get_id(td, &id1, &id2, &id3);
963 /* on early Taal revisions CABC is broken */
964 if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
965 td->cabc_broken = true;
967 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
971 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
972 (1<<2) | (1<<5)); /* BL | BCTRL */
976 r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
977 MIPI_DCS_PIXEL_FMT_24BIT);
981 if (!td->cabc_broken) {
982 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
987 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
991 r = _taal_enable_te(dssdev, td->te_enabled);
995 r = dsi_enable_video_output(dssdev, td->channel);
1001 if (!td->intro_printed) {
1002 dev_info(dssdev->dev, "panel revision %02x.%02x.%02x\n",
1004 if (td->cabc_broken)
1005 dev_info(dssdev->dev,
1006 "old Taal version, CABC disabled\n");
1007 td->intro_printed = true;
1010 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
1014 dev_err(dssdev->dev, "error while enabling panel, issuing HW reset\n");
1016 taal_hw_reset(dssdev);
1018 omapdss_dsi_display_disable(dssdev, true, false);
1023 static void taal_power_off(struct omap_dss_device *dssdev)
1025 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1028 dsi_disable_video_output(dssdev, td->channel);
1030 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
1032 r = taal_sleep_in(td);
1035 dev_err(dssdev->dev,
1036 "error disabling panel, issuing HW reset\n");
1037 taal_hw_reset(dssdev);
1040 omapdss_dsi_display_disable(dssdev, true, false);
1045 static int taal_panel_reset(struct omap_dss_device *dssdev)
1047 dev_err(dssdev->dev, "performing LCD reset\n");
1049 taal_power_off(dssdev);
1050 taal_hw_reset(dssdev);
1051 return taal_power_on(dssdev);
1054 static int taal_enable(struct omap_dss_device *dssdev)
1056 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1059 dev_dbg(dssdev->dev, "enable\n");
1061 mutex_lock(&td->lock);
1063 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
1068 dsi_bus_lock(dssdev);
1070 r = taal_power_on(dssdev);
1072 dsi_bus_unlock(dssdev);
1077 taal_queue_esd_work(dssdev);
1079 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1081 mutex_unlock(&td->lock);
1085 dev_dbg(dssdev->dev, "enable failed\n");
1086 mutex_unlock(&td->lock);
1090 static void taal_disable(struct omap_dss_device *dssdev)
1092 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1094 dev_dbg(dssdev->dev, "disable\n");
1096 mutex_lock(&td->lock);
1098 taal_cancel_ulps_work(dssdev);
1099 taal_cancel_esd_work(dssdev);
1101 dsi_bus_lock(dssdev);
1103 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
1106 r = taal_wake_up(dssdev);
1108 taal_power_off(dssdev);
1111 dsi_bus_unlock(dssdev);
1113 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1115 mutex_unlock(&td->lock);
1118 static void taal_framedone_cb(int err, void *data)
1120 struct omap_dss_device *dssdev = data;
1121 dev_dbg(dssdev->dev, "framedone, err %d\n", err);
1122 dsi_bus_unlock(dssdev);
1125 static irqreturn_t taal_te_isr(int irq, void *data)
1127 struct omap_dss_device *dssdev = data;
1128 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1132 old = atomic_cmpxchg(&td->do_update, 1, 0);
1135 cancel_delayed_work(&td->te_timeout_work);
1137 r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
1145 dev_err(dssdev->dev, "start update failed\n");
1146 dsi_bus_unlock(dssdev);
1150 static void taal_te_timeout_work_callback(struct work_struct *work)
1152 struct taal_data *td = container_of(work, struct taal_data,
1153 te_timeout_work.work);
1154 struct omap_dss_device *dssdev = td->dssdev;
1156 dev_err(dssdev->dev, "TE not received for 250ms!\n");
1158 atomic_set(&td->do_update, 0);
1159 dsi_bus_unlock(dssdev);
1162 static int taal_update(struct omap_dss_device *dssdev,
1163 u16 x, u16 y, u16 w, u16 h)
1165 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1168 dev_dbg(dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1170 mutex_lock(&td->lock);
1171 dsi_bus_lock(dssdev);
1173 r = taal_wake_up(dssdev);
1182 /* XXX no need to send this every frame, but dsi break if not done */
1183 r = taal_set_update_window(td, 0, 0,
1184 dssdev->panel.timings.x_res,
1185 dssdev->panel.timings.y_res);
1189 if (td->te_enabled && gpio_is_valid(td->ext_te_gpio)) {
1190 schedule_delayed_work(&td->te_timeout_work,
1191 msecs_to_jiffies(250));
1192 atomic_set(&td->do_update, 1);
1194 r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
1200 /* note: no bus_unlock here. unlock is in framedone_cb */
1201 mutex_unlock(&td->lock);
1204 dsi_bus_unlock(dssdev);
1205 mutex_unlock(&td->lock);
1209 static int taal_sync(struct omap_dss_device *dssdev)
1211 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1213 dev_dbg(dssdev->dev, "sync\n");
1215 mutex_lock(&td->lock);
1216 dsi_bus_lock(dssdev);
1217 dsi_bus_unlock(dssdev);
1218 mutex_unlock(&td->lock);
1220 dev_dbg(dssdev->dev, "sync done\n");
1225 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1227 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1231 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1233 r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
1235 if (!gpio_is_valid(td->ext_te_gpio))
1236 omapdss_dsi_enable_te(dssdev, enable);
1238 /* possible panel bug */
1244 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1246 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1249 mutex_lock(&td->lock);
1251 if (td->te_enabled == enable)
1254 dsi_bus_lock(dssdev);
1257 r = taal_wake_up(dssdev);
1261 r = _taal_enable_te(dssdev, enable);
1266 td->te_enabled = enable;
1268 dsi_bus_unlock(dssdev);
1270 mutex_unlock(&td->lock);
1274 dsi_bus_unlock(dssdev);
1275 mutex_unlock(&td->lock);
1280 static int taal_get_te(struct omap_dss_device *dssdev)
1282 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1285 mutex_lock(&td->lock);
1287 mutex_unlock(&td->lock);
1292 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1294 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1298 mutex_lock(&td->lock);
1305 dsi_bus_lock(dssdev);
1307 r = taal_wake_up(dssdev);
1311 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1314 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1317 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1321 dsi_bus_unlock(dssdev);
1322 mutex_unlock(&td->lock);
1325 dsi_bus_unlock(dssdev);
1327 mutex_unlock(&td->lock);
1331 static int taal_memory_read(struct omap_dss_device *dssdev,
1332 void *buf, size_t size,
1333 u16 x, u16 y, u16 w, u16 h)
1338 unsigned buf_used = 0;
1339 struct taal_data *td = dev_get_drvdata(dssdev->dev);
1341 if (size < w * h * 3)
1344 mutex_lock(&td->lock);
1351 size = min(w * h * 3,
1352 dssdev->panel.timings.x_res *
1353 dssdev->panel.timings.y_res * 3);
1355 dsi_bus_lock(dssdev);
1357 r = taal_wake_up(dssdev);
1361 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1362 * use short packets. plen 32 works, but bigger packets seem to cause
1369 taal_set_update_window(td, x, y, w, h);
1371 r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
1375 while (buf_used < size) {
1376 u8 dcs_cmd = first ? 0x2e : 0x3e;
1379 r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
1380 buf + buf_used, size - buf_used);
1383 dev_err(dssdev->dev, "read error\n");
1390 dev_err(dssdev->dev, "short read\n");
1394 if (signal_pending(current)) {
1395 dev_err(dssdev->dev, "signal pending, "
1396 "aborting memory read\n");
1405 dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
1407 dsi_bus_unlock(dssdev);
1409 mutex_unlock(&td->lock);
1413 static void taal_ulps_work(struct work_struct *work)
1415 struct taal_data *td = container_of(work, struct taal_data,
1417 struct omap_dss_device *dssdev = td->dssdev;
1419 mutex_lock(&td->lock);
1421 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
1422 mutex_unlock(&td->lock);
1426 dsi_bus_lock(dssdev);
1428 taal_enter_ulps(dssdev);
1430 dsi_bus_unlock(dssdev);
1431 mutex_unlock(&td->lock);
1434 static void taal_esd_work(struct work_struct *work)
1436 struct taal_data *td = container_of(work, struct taal_data,
1438 struct omap_dss_device *dssdev = td->dssdev;
1442 mutex_lock(&td->lock);
1445 mutex_unlock(&td->lock);
1449 dsi_bus_lock(dssdev);
1451 r = taal_wake_up(dssdev);
1453 dev_err(dssdev->dev, "failed to exit ULPS\n");
1457 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
1459 dev_err(dssdev->dev, "failed to read Taal status\n");
1463 /* Run self diagnostics */
1464 r = taal_sleep_out(td);
1466 dev_err(dssdev->dev, "failed to run Taal self-diagnostics\n");
1470 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
1472 dev_err(dssdev->dev, "failed to read Taal status\n");
1476 /* Each sleep out command will trigger a self diagnostic and flip
1477 * Bit6 if the test passes.
1479 if (!((state1 ^ state2) & (1 << 6))) {
1480 dev_err(dssdev->dev, "LCD self diagnostics failed\n");
1483 /* Self-diagnostics result is also shown on TE GPIO line. We need
1484 * to re-enable TE after self diagnostics */
1485 if (td->te_enabled && gpio_is_valid(td->ext_te_gpio)) {
1486 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1491 dsi_bus_unlock(dssdev);
1493 taal_queue_esd_work(dssdev);
1495 mutex_unlock(&td->lock);
1498 dev_err(dssdev->dev, "performing LCD reset\n");
1500 taal_panel_reset(dssdev);
1502 dsi_bus_unlock(dssdev);
1504 taal_queue_esd_work(dssdev);
1506 mutex_unlock(&td->lock);
1509 static struct omap_dss_driver taal_driver = {
1510 .probe = taal_probe,
1511 .remove = __exit_p(taal_remove),
1513 .enable = taal_enable,
1514 .disable = taal_disable,
1516 .update = taal_update,
1519 .get_resolution = taal_get_resolution,
1520 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1522 .enable_te = taal_enable_te,
1523 .get_te = taal_get_te,
1525 .run_test = taal_run_test,
1526 .memory_read = taal_memory_read,
1530 .owner = THIS_MODULE,
1534 static int __init taal_init(void)
1536 omap_dss_register_driver(&taal_driver);
1541 static void __exit taal_exit(void)
1543 omap_dss_unregister_driver(&taal_driver);
1546 module_init(taal_init);
1547 module_exit(taal_exit);
1549 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1550 MODULE_DESCRIPTION("Taal Driver");
1551 MODULE_LICENSE("GPL");