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-nokia-dsi.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);
58 * struct panel_config - panel configuration
61 * @timings: panel resolution
62 * @sleep: various panel specific delays, passed to msleep() if non-zero
63 * @reset_sequence: reset sequence timings, passed to udelay() if non-zero
64 * @regulators: array of panel regulators
65 * @num_regulators: number of regulators in the array
71 struct omap_video_timings timings;
74 unsigned int sleep_in;
75 unsigned int sleep_out;
76 unsigned int hw_reset;
77 unsigned int enable_te;
91 static struct panel_config panel_configs[] = {
103 .enable_te = 100, /* possible panel bug */
115 struct backlight_device *bldev;
117 unsigned long hw_guard_end; /* next value of jiffies when we can
118 * issue the next sleep in/out command
120 unsigned long hw_guard_wait; /* max guard time in jiffies */
122 struct omap_dss_device *dssdev;
133 struct delayed_work te_timeout_work;
140 struct workqueue_struct *workqueue;
142 struct delayed_work esd_work;
143 unsigned esd_interval;
146 unsigned ulps_timeout;
147 struct delayed_work ulps_work;
149 struct panel_config *panel_config;
152 static inline struct nokia_dsi_panel_data
153 *get_panel_data(const struct omap_dss_device *dssdev)
155 return (struct nokia_dsi_panel_data *) dssdev->data;
158 static void taal_esd_work(struct work_struct *work);
159 static void taal_ulps_work(struct work_struct *work);
161 static void hw_guard_start(struct taal_data *td, int guard_msec)
163 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
164 td->hw_guard_end = jiffies + td->hw_guard_wait;
167 static void hw_guard_wait(struct taal_data *td)
169 unsigned long wait = td->hw_guard_end - jiffies;
171 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
172 set_current_state(TASK_UNINTERRUPTIBLE);
173 schedule_timeout(wait);
177 static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
182 r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1);
192 static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
194 return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1);
197 static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
202 return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2);
205 static int taal_sleep_in(struct taal_data *td)
213 cmd = MIPI_DCS_ENTER_SLEEP_MODE;
214 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1);
218 hw_guard_start(td, 120);
220 if (td->panel_config->sleep.sleep_in)
221 msleep(td->panel_config->sleep.sleep_in);
226 static int taal_sleep_out(struct taal_data *td)
232 r = taal_dcs_write_0(td, MIPI_DCS_EXIT_SLEEP_MODE);
236 hw_guard_start(td, 120);
238 if (td->panel_config->sleep.sleep_out)
239 msleep(td->panel_config->sleep.sleep_out);
244 static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
248 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
251 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
254 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
261 static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
267 r = taal_dcs_read_1(td, MIPI_DCS_GET_ADDRESS_MODE, &mode);
298 mode &= ~((1<<7) | (1<<6) | (1<<5));
299 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
301 return taal_dcs_write_1(td, MIPI_DCS_SET_ADDRESS_MODE, mode);
304 static int taal_set_update_window(struct taal_data *td,
305 u16 x, u16 y, u16 w, u16 h)
314 buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
315 buf[1] = (x1 >> 8) & 0xff;
316 buf[2] = (x1 >> 0) & 0xff;
317 buf[3] = (x2 >> 8) & 0xff;
318 buf[4] = (x2 >> 0) & 0xff;
320 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
324 buf[0] = MIPI_DCS_SET_PAGE_ADDRESS;
325 buf[1] = (y1 >> 8) & 0xff;
326 buf[2] = (y1 >> 0) & 0xff;
327 buf[3] = (y2 >> 8) & 0xff;
328 buf[4] = (y2 >> 0) & 0xff;
330 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
334 dsi_vc_send_bta_sync(td->dssdev, td->channel);
339 static void taal_queue_esd_work(struct omap_dss_device *dssdev)
341 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
343 if (td->esd_interval > 0)
344 queue_delayed_work(td->workqueue, &td->esd_work,
345 msecs_to_jiffies(td->esd_interval));
348 static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
350 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
352 cancel_delayed_work(&td->esd_work);
355 static void taal_queue_ulps_work(struct omap_dss_device *dssdev)
357 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
359 if (td->ulps_timeout > 0)
360 queue_delayed_work(td->workqueue, &td->ulps_work,
361 msecs_to_jiffies(td->ulps_timeout));
364 static void taal_cancel_ulps_work(struct omap_dss_device *dssdev)
366 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
368 cancel_delayed_work(&td->ulps_work);
371 static int taal_enter_ulps(struct omap_dss_device *dssdev)
373 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
374 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
377 if (td->ulps_enabled)
380 taal_cancel_ulps_work(dssdev);
382 r = _taal_enable_te(dssdev, false);
386 disable_irq(gpio_to_irq(panel_data->ext_te_gpio));
388 omapdss_dsi_display_disable(dssdev, false, true);
390 td->ulps_enabled = true;
395 dev_err(&dssdev->dev, "enter ULPS failed");
396 taal_panel_reset(dssdev);
398 td->ulps_enabled = false;
400 taal_queue_ulps_work(dssdev);
405 static int taal_exit_ulps(struct omap_dss_device *dssdev)
407 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
408 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
411 if (!td->ulps_enabled)
414 r = omapdss_dsi_display_enable(dssdev);
416 dev_err(&dssdev->dev, "failed to enable DSI\n");
420 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
422 r = _taal_enable_te(dssdev, true);
424 dev_err(&dssdev->dev, "failed to re-enable TE");
428 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
430 taal_queue_ulps_work(dssdev);
432 td->ulps_enabled = false;
437 dev_err(&dssdev->dev, "failed to exit ULPS");
439 r = taal_panel_reset(dssdev);
441 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
442 td->ulps_enabled = false;
445 taal_queue_ulps_work(dssdev);
450 static int taal_wake_up(struct omap_dss_device *dssdev)
452 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
454 if (td->ulps_enabled)
455 return taal_exit_ulps(dssdev);
457 taal_cancel_ulps_work(dssdev);
458 taal_queue_ulps_work(dssdev);
462 static int taal_bl_update_status(struct backlight_device *dev)
464 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
465 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
469 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
470 dev->props.power == FB_BLANK_UNBLANK)
471 level = dev->props.brightness;
475 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
477 mutex_lock(&td->lock);
480 dsi_bus_lock(dssdev);
482 r = taal_wake_up(dssdev);
484 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
486 dsi_bus_unlock(dssdev);
491 mutex_unlock(&td->lock);
496 static int taal_bl_get_intensity(struct backlight_device *dev)
498 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
499 dev->props.power == FB_BLANK_UNBLANK)
500 return dev->props.brightness;
505 static const struct backlight_ops taal_bl_ops = {
506 .get_brightness = taal_bl_get_intensity,
507 .update_status = taal_bl_update_status,
510 static void taal_get_resolution(struct omap_dss_device *dssdev,
511 u16 *xres, u16 *yres)
513 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
515 if (td->rotate == 0 || td->rotate == 2) {
516 *xres = dssdev->panel.timings.x_res;
517 *yres = dssdev->panel.timings.y_res;
519 *yres = dssdev->panel.timings.x_res;
520 *xres = dssdev->panel.timings.y_res;
524 static ssize_t taal_num_errors_show(struct device *dev,
525 struct device_attribute *attr, char *buf)
527 struct omap_dss_device *dssdev = to_dss_device(dev);
528 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
532 mutex_lock(&td->lock);
535 dsi_bus_lock(dssdev);
537 r = taal_wake_up(dssdev);
539 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
541 dsi_bus_unlock(dssdev);
546 mutex_unlock(&td->lock);
551 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
554 static ssize_t taal_hw_revision_show(struct device *dev,
555 struct device_attribute *attr, char *buf)
557 struct omap_dss_device *dssdev = to_dss_device(dev);
558 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
562 mutex_lock(&td->lock);
565 dsi_bus_lock(dssdev);
567 r = taal_wake_up(dssdev);
569 r = taal_get_id(td, &id1, &id2, &id3);
571 dsi_bus_unlock(dssdev);
576 mutex_unlock(&td->lock);
581 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
584 static const char *cabc_modes[] = {
585 "off", /* used also always when CABC is not supported */
591 static ssize_t show_cabc_mode(struct device *dev,
592 struct device_attribute *attr,
595 struct omap_dss_device *dssdev = to_dss_device(dev);
596 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
597 const char *mode_str;
601 mode = td->cabc_mode;
603 mode_str = "unknown";
604 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
605 mode_str = cabc_modes[mode];
606 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
608 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
611 static ssize_t store_cabc_mode(struct device *dev,
612 struct device_attribute *attr,
613 const char *buf, size_t count)
615 struct omap_dss_device *dssdev = to_dss_device(dev);
616 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
620 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
621 if (sysfs_streq(cabc_modes[i], buf))
625 if (i == ARRAY_SIZE(cabc_modes))
628 mutex_lock(&td->lock);
631 dsi_bus_lock(dssdev);
633 if (!td->cabc_broken) {
634 r = taal_wake_up(dssdev);
638 r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
643 dsi_bus_unlock(dssdev);
648 mutex_unlock(&td->lock);
652 dsi_bus_unlock(dssdev);
653 mutex_unlock(&td->lock);
657 static ssize_t show_cabc_available_modes(struct device *dev,
658 struct device_attribute *attr,
665 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
666 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
667 i ? " " : "", cabc_modes[i],
668 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
670 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
673 static ssize_t taal_store_esd_interval(struct device *dev,
674 struct device_attribute *attr,
675 const char *buf, size_t count)
677 struct omap_dss_device *dssdev = to_dss_device(dev);
678 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
683 r = strict_strtoul(buf, 10, &t);
687 mutex_lock(&td->lock);
688 taal_cancel_esd_work(dssdev);
689 td->esd_interval = t;
691 taal_queue_esd_work(dssdev);
692 mutex_unlock(&td->lock);
697 static ssize_t taal_show_esd_interval(struct device *dev,
698 struct device_attribute *attr,
701 struct omap_dss_device *dssdev = to_dss_device(dev);
702 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
705 mutex_lock(&td->lock);
706 t = td->esd_interval;
707 mutex_unlock(&td->lock);
709 return snprintf(buf, PAGE_SIZE, "%u\n", t);
712 static ssize_t taal_store_ulps(struct device *dev,
713 struct device_attribute *attr,
714 const char *buf, size_t count)
716 struct omap_dss_device *dssdev = to_dss_device(dev);
717 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
721 r = strict_strtoul(buf, 10, &t);
725 mutex_lock(&td->lock);
728 dsi_bus_lock(dssdev);
731 r = taal_enter_ulps(dssdev);
733 r = taal_wake_up(dssdev);
735 dsi_bus_unlock(dssdev);
738 mutex_unlock(&td->lock);
746 static ssize_t taal_show_ulps(struct device *dev,
747 struct device_attribute *attr,
750 struct omap_dss_device *dssdev = to_dss_device(dev);
751 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
754 mutex_lock(&td->lock);
755 t = td->ulps_enabled;
756 mutex_unlock(&td->lock);
758 return snprintf(buf, PAGE_SIZE, "%u\n", t);
761 static ssize_t taal_store_ulps_timeout(struct device *dev,
762 struct device_attribute *attr,
763 const char *buf, size_t count)
765 struct omap_dss_device *dssdev = to_dss_device(dev);
766 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
770 r = strict_strtoul(buf, 10, &t);
774 mutex_lock(&td->lock);
775 td->ulps_timeout = t;
778 /* taal_wake_up will restart the timer */
779 dsi_bus_lock(dssdev);
780 r = taal_wake_up(dssdev);
781 dsi_bus_unlock(dssdev);
784 mutex_unlock(&td->lock);
792 static ssize_t taal_show_ulps_timeout(struct device *dev,
793 struct device_attribute *attr,
796 struct omap_dss_device *dssdev = to_dss_device(dev);
797 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
800 mutex_lock(&td->lock);
801 t = td->ulps_timeout;
802 mutex_unlock(&td->lock);
804 return snprintf(buf, PAGE_SIZE, "%u\n", t);
807 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
808 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
809 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
810 show_cabc_mode, store_cabc_mode);
811 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
812 show_cabc_available_modes, NULL);
813 static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
814 taal_show_esd_interval, taal_store_esd_interval);
815 static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
816 taal_show_ulps, taal_store_ulps);
817 static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
818 taal_show_ulps_timeout, taal_store_ulps_timeout);
820 static struct attribute *taal_attrs[] = {
821 &dev_attr_num_dsi_errors.attr,
822 &dev_attr_hw_revision.attr,
823 &dev_attr_cabc_mode.attr,
824 &dev_attr_cabc_available_modes.attr,
825 &dev_attr_esd_interval.attr,
827 &dev_attr_ulps_timeout.attr,
831 static struct attribute_group taal_attr_group = {
835 static void taal_hw_reset(struct omap_dss_device *dssdev)
837 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
838 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
840 if (panel_data->reset_gpio == -1)
843 gpio_set_value(panel_data->reset_gpio, 1);
844 if (td->panel_config->reset_sequence.high)
845 udelay(td->panel_config->reset_sequence.high);
846 /* reset the panel */
847 gpio_set_value(panel_data->reset_gpio, 0);
849 if (td->panel_config->reset_sequence.low)
850 udelay(td->panel_config->reset_sequence.low);
851 gpio_set_value(panel_data->reset_gpio, 1);
852 /* wait after releasing reset */
853 if (td->panel_config->sleep.hw_reset)
854 msleep(td->panel_config->sleep.hw_reset);
857 static int taal_probe(struct omap_dss_device *dssdev)
859 struct backlight_properties props;
860 struct taal_data *td;
861 struct backlight_device *bldev = NULL;
862 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
863 struct panel_config *panel_config = NULL;
866 dev_dbg(&dssdev->dev, "probe\n");
868 if (!panel_data || !panel_data->name) {
873 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
874 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
875 panel_config = &panel_configs[i];
885 dssdev->panel.timings = panel_config->timings;
886 dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
888 td = kzalloc(sizeof(*td), GFP_KERNEL);
894 td->panel_config = panel_config;
895 td->esd_interval = panel_data->esd_interval;
896 td->ulps_enabled = false;
897 td->ulps_timeout = panel_data->ulps_timeout;
899 mutex_init(&td->lock);
901 atomic_set(&td->do_update, 0);
903 td->workqueue = create_singlethread_workqueue("taal_esd");
904 if (td->workqueue == NULL) {
905 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
909 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
910 INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
912 dev_set_drvdata(&dssdev->dev, td);
914 if (gpio_is_valid(panel_data->reset_gpio)) {
915 r = gpio_request_one(panel_data->reset_gpio, GPIOF_OUT_INIT_LOW,
918 dev_err(&dssdev->dev, "failed to request reset gpio\n");
923 taal_hw_reset(dssdev);
925 if (panel_data->use_dsi_backlight) {
926 memset(&props, 0, sizeof(struct backlight_properties));
927 props.max_brightness = 255;
929 props.type = BACKLIGHT_RAW;
930 bldev = backlight_device_register(dev_name(&dssdev->dev),
931 &dssdev->dev, dssdev, &taal_bl_ops, &props);
939 bldev->props.fb_blank = FB_BLANK_UNBLANK;
940 bldev->props.power = FB_BLANK_UNBLANK;
941 bldev->props.brightness = 255;
943 taal_bl_update_status(bldev);
946 if (panel_data->use_ext_te) {
947 int gpio = panel_data->ext_te_gpio;
949 r = gpio_request_one(gpio, GPIOF_IN, "taal irq");
951 dev_err(&dssdev->dev, "GPIO request failed\n");
955 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
957 "taal vsync", dssdev);
960 dev_err(&dssdev->dev, "IRQ request failed\n");
965 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
966 taal_te_timeout_work_callback);
968 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
971 r = omap_dsi_request_vc(dssdev, &td->channel);
973 dev_err(&dssdev->dev, "failed to get virtual channel\n");
977 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
979 dev_err(&dssdev->dev, "failed to set VC_ID\n");
983 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
985 dev_err(&dssdev->dev, "failed to create sysfs files\n");
992 omap_dsi_release_vc(dssdev, td->channel);
994 if (panel_data->use_ext_te)
995 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
997 if (panel_data->use_ext_te)
998 gpio_free(panel_data->ext_te_gpio);
1001 backlight_device_unregister(bldev);
1003 if (gpio_is_valid(panel_data->reset_gpio))
1004 gpio_free(panel_data->reset_gpio);
1006 destroy_workqueue(td->workqueue);
1013 static void __exit taal_remove(struct omap_dss_device *dssdev)
1015 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1016 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1017 struct backlight_device *bldev;
1019 dev_dbg(&dssdev->dev, "remove\n");
1021 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
1022 omap_dsi_release_vc(dssdev, td->channel);
1024 if (panel_data->use_ext_te) {
1025 int gpio = panel_data->ext_te_gpio;
1026 free_irq(gpio_to_irq(gpio), dssdev);
1031 if (bldev != NULL) {
1032 bldev->props.power = FB_BLANK_POWERDOWN;
1033 taal_bl_update_status(bldev);
1034 backlight_device_unregister(bldev);
1037 taal_cancel_ulps_work(dssdev);
1038 taal_cancel_esd_work(dssdev);
1039 destroy_workqueue(td->workqueue);
1041 /* reset, to be sure that the panel is in a valid state */
1042 taal_hw_reset(dssdev);
1044 if (gpio_is_valid(panel_data->reset_gpio))
1045 gpio_free(panel_data->reset_gpio);
1050 static int taal_power_on(struct omap_dss_device *dssdev)
1052 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1053 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1057 r = omapdss_dsi_configure_pins(dssdev, &panel_data->pin_config);
1059 dev_err(&dssdev->dev, "failed to configure DSI pins\n");
1063 omapdss_dsi_set_size(dssdev, dssdev->panel.timings.x_res,
1064 dssdev->panel.timings.y_res);
1066 r = omapdss_dsi_display_enable(dssdev);
1068 dev_err(&dssdev->dev, "failed to enable DSI\n");
1072 taal_hw_reset(dssdev);
1074 omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
1076 r = taal_sleep_out(td);
1080 r = taal_get_id(td, &id1, &id2, &id3);
1084 /* on early Taal revisions CABC is broken */
1085 if (td->panel_config->type == PANEL_TAAL &&
1086 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
1087 td->cabc_broken = true;
1089 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
1093 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
1094 (1<<2) | (1<<5)); /* BL | BCTRL */
1098 r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
1099 MIPI_DCS_PIXEL_FMT_24BIT);
1103 r = taal_set_addr_mode(td, td->rotate, td->mirror);
1107 if (!td->cabc_broken) {
1108 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
1113 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
1117 r = _taal_enable_te(dssdev, td->te_enabled);
1121 r = dsi_enable_video_output(dssdev, td->channel);
1127 if (!td->intro_printed) {
1128 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
1129 td->panel_config->name, id1, id2, id3);
1130 if (td->cabc_broken)
1131 dev_info(&dssdev->dev,
1132 "old Taal version, CABC disabled\n");
1133 td->intro_printed = true;
1136 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
1140 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
1142 taal_hw_reset(dssdev);
1144 omapdss_dsi_display_disable(dssdev, true, false);
1149 static void taal_power_off(struct omap_dss_device *dssdev)
1151 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1154 dsi_disable_video_output(dssdev, td->channel);
1156 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
1158 r = taal_sleep_in(td);
1161 dev_err(&dssdev->dev,
1162 "error disabling panel, issuing HW reset\n");
1163 taal_hw_reset(dssdev);
1166 omapdss_dsi_display_disable(dssdev, true, false);
1171 static int taal_panel_reset(struct omap_dss_device *dssdev)
1173 dev_err(&dssdev->dev, "performing LCD reset\n");
1175 taal_power_off(dssdev);
1176 taal_hw_reset(dssdev);
1177 return taal_power_on(dssdev);
1180 static int taal_enable(struct omap_dss_device *dssdev)
1182 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1185 dev_dbg(&dssdev->dev, "enable\n");
1187 mutex_lock(&td->lock);
1189 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
1194 dsi_bus_lock(dssdev);
1196 r = taal_power_on(dssdev);
1198 dsi_bus_unlock(dssdev);
1203 taal_queue_esd_work(dssdev);
1205 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1207 mutex_unlock(&td->lock);
1211 dev_dbg(&dssdev->dev, "enable failed\n");
1212 mutex_unlock(&td->lock);
1216 static void taal_disable(struct omap_dss_device *dssdev)
1218 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1220 dev_dbg(&dssdev->dev, "disable\n");
1222 mutex_lock(&td->lock);
1224 taal_cancel_ulps_work(dssdev);
1225 taal_cancel_esd_work(dssdev);
1227 dsi_bus_lock(dssdev);
1229 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
1232 r = taal_wake_up(dssdev);
1234 taal_power_off(dssdev);
1237 dsi_bus_unlock(dssdev);
1239 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1241 mutex_unlock(&td->lock);
1244 static int taal_suspend(struct omap_dss_device *dssdev)
1246 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1249 dev_dbg(&dssdev->dev, "suspend\n");
1251 mutex_lock(&td->lock);
1253 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1258 taal_cancel_ulps_work(dssdev);
1259 taal_cancel_esd_work(dssdev);
1261 dsi_bus_lock(dssdev);
1263 r = taal_wake_up(dssdev);
1265 taal_power_off(dssdev);
1267 dsi_bus_unlock(dssdev);
1269 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1271 mutex_unlock(&td->lock);
1275 mutex_unlock(&td->lock);
1279 static int taal_resume(struct omap_dss_device *dssdev)
1281 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1284 dev_dbg(&dssdev->dev, "resume\n");
1286 mutex_lock(&td->lock);
1288 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1293 dsi_bus_lock(dssdev);
1295 r = taal_power_on(dssdev);
1297 dsi_bus_unlock(dssdev);
1300 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1302 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1303 taal_queue_esd_work(dssdev);
1306 mutex_unlock(&td->lock);
1310 mutex_unlock(&td->lock);
1314 static void taal_framedone_cb(int err, void *data)
1316 struct omap_dss_device *dssdev = data;
1317 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1318 dsi_bus_unlock(dssdev);
1321 static irqreturn_t taal_te_isr(int irq, void *data)
1323 struct omap_dss_device *dssdev = data;
1324 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1328 old = atomic_cmpxchg(&td->do_update, 1, 0);
1331 cancel_delayed_work(&td->te_timeout_work);
1333 r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
1341 dev_err(&dssdev->dev, "start update failed\n");
1342 dsi_bus_unlock(dssdev);
1346 static void taal_te_timeout_work_callback(struct work_struct *work)
1348 struct taal_data *td = container_of(work, struct taal_data,
1349 te_timeout_work.work);
1350 struct omap_dss_device *dssdev = td->dssdev;
1352 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1354 atomic_set(&td->do_update, 0);
1355 dsi_bus_unlock(dssdev);
1358 static int taal_update(struct omap_dss_device *dssdev,
1359 u16 x, u16 y, u16 w, u16 h)
1361 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1362 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1365 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1367 mutex_lock(&td->lock);
1368 dsi_bus_lock(dssdev);
1370 r = taal_wake_up(dssdev);
1379 /* XXX no need to send this every frame, but dsi break if not done */
1380 r = taal_set_update_window(td, 0, 0,
1381 td->panel_config->timings.x_res,
1382 td->panel_config->timings.y_res);
1386 if (td->te_enabled && panel_data->use_ext_te) {
1387 schedule_delayed_work(&td->te_timeout_work,
1388 msecs_to_jiffies(250));
1389 atomic_set(&td->do_update, 1);
1391 r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
1397 /* note: no bus_unlock here. unlock is in framedone_cb */
1398 mutex_unlock(&td->lock);
1401 dsi_bus_unlock(dssdev);
1402 mutex_unlock(&td->lock);
1406 static int taal_sync(struct omap_dss_device *dssdev)
1408 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1410 dev_dbg(&dssdev->dev, "sync\n");
1412 mutex_lock(&td->lock);
1413 dsi_bus_lock(dssdev);
1414 dsi_bus_unlock(dssdev);
1415 mutex_unlock(&td->lock);
1417 dev_dbg(&dssdev->dev, "sync done\n");
1422 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1424 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1425 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1429 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1431 r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
1433 if (!panel_data->use_ext_te)
1434 omapdss_dsi_enable_te(dssdev, enable);
1436 if (td->panel_config->sleep.enable_te)
1437 msleep(td->panel_config->sleep.enable_te);
1442 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1444 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1447 mutex_lock(&td->lock);
1449 if (td->te_enabled == enable)
1452 dsi_bus_lock(dssdev);
1455 r = taal_wake_up(dssdev);
1459 r = _taal_enable_te(dssdev, enable);
1464 td->te_enabled = enable;
1466 dsi_bus_unlock(dssdev);
1468 mutex_unlock(&td->lock);
1472 dsi_bus_unlock(dssdev);
1473 mutex_unlock(&td->lock);
1478 static int taal_get_te(struct omap_dss_device *dssdev)
1480 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1483 mutex_lock(&td->lock);
1485 mutex_unlock(&td->lock);
1490 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1492 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1496 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1498 mutex_lock(&td->lock);
1500 if (td->rotate == rotate)
1503 dsi_bus_lock(dssdev);
1506 r = taal_wake_up(dssdev);
1510 r = taal_set_addr_mode(td, rotate, td->mirror);
1515 if (rotate == 0 || rotate == 2) {
1516 dw = dssdev->panel.timings.x_res;
1517 dh = dssdev->panel.timings.y_res;
1519 dw = dssdev->panel.timings.y_res;
1520 dh = dssdev->panel.timings.x_res;
1523 omapdss_dsi_set_size(dssdev, dw, dh);
1525 td->rotate = rotate;
1527 dsi_bus_unlock(dssdev);
1529 mutex_unlock(&td->lock);
1532 dsi_bus_unlock(dssdev);
1533 mutex_unlock(&td->lock);
1537 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1539 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1542 mutex_lock(&td->lock);
1544 mutex_unlock(&td->lock);
1549 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1551 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1554 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1556 mutex_lock(&td->lock);
1558 if (td->mirror == enable)
1561 dsi_bus_lock(dssdev);
1563 r = taal_wake_up(dssdev);
1567 r = taal_set_addr_mode(td, td->rotate, enable);
1572 td->mirror = enable;
1574 dsi_bus_unlock(dssdev);
1576 mutex_unlock(&td->lock);
1579 dsi_bus_unlock(dssdev);
1580 mutex_unlock(&td->lock);
1584 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1586 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1589 mutex_lock(&td->lock);
1591 mutex_unlock(&td->lock);
1596 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1598 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1602 mutex_lock(&td->lock);
1609 dsi_bus_lock(dssdev);
1611 r = taal_wake_up(dssdev);
1615 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1618 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1621 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1625 dsi_bus_unlock(dssdev);
1626 mutex_unlock(&td->lock);
1629 dsi_bus_unlock(dssdev);
1631 mutex_unlock(&td->lock);
1635 static int taal_memory_read(struct omap_dss_device *dssdev,
1636 void *buf, size_t size,
1637 u16 x, u16 y, u16 w, u16 h)
1642 unsigned buf_used = 0;
1643 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1645 if (size < w * h * 3)
1648 mutex_lock(&td->lock);
1655 size = min(w * h * 3,
1656 dssdev->panel.timings.x_res *
1657 dssdev->panel.timings.y_res * 3);
1659 dsi_bus_lock(dssdev);
1661 r = taal_wake_up(dssdev);
1665 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1666 * use short packets. plen 32 works, but bigger packets seem to cause
1673 taal_set_update_window(td, x, y, w, h);
1675 r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
1679 while (buf_used < size) {
1680 u8 dcs_cmd = first ? 0x2e : 0x3e;
1683 r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
1684 buf + buf_used, size - buf_used);
1687 dev_err(&dssdev->dev, "read error\n");
1694 dev_err(&dssdev->dev, "short read\n");
1698 if (signal_pending(current)) {
1699 dev_err(&dssdev->dev, "signal pending, "
1700 "aborting memory read\n");
1709 dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
1711 dsi_bus_unlock(dssdev);
1713 mutex_unlock(&td->lock);
1717 static void taal_ulps_work(struct work_struct *work)
1719 struct taal_data *td = container_of(work, struct taal_data,
1721 struct omap_dss_device *dssdev = td->dssdev;
1723 mutex_lock(&td->lock);
1725 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
1726 mutex_unlock(&td->lock);
1730 dsi_bus_lock(dssdev);
1732 taal_enter_ulps(dssdev);
1734 dsi_bus_unlock(dssdev);
1735 mutex_unlock(&td->lock);
1738 static void taal_esd_work(struct work_struct *work)
1740 struct taal_data *td = container_of(work, struct taal_data,
1742 struct omap_dss_device *dssdev = td->dssdev;
1743 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1747 mutex_lock(&td->lock);
1750 mutex_unlock(&td->lock);
1754 dsi_bus_lock(dssdev);
1756 r = taal_wake_up(dssdev);
1758 dev_err(&dssdev->dev, "failed to exit ULPS\n");
1762 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
1764 dev_err(&dssdev->dev, "failed to read Taal status\n");
1768 /* Run self diagnostics */
1769 r = taal_sleep_out(td);
1771 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1775 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
1777 dev_err(&dssdev->dev, "failed to read Taal status\n");
1781 /* Each sleep out command will trigger a self diagnostic and flip
1782 * Bit6 if the test passes.
1784 if (!((state1 ^ state2) & (1 << 6))) {
1785 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1788 /* Self-diagnostics result is also shown on TE GPIO line. We need
1789 * to re-enable TE after self diagnostics */
1790 if (td->te_enabled && panel_data->use_ext_te) {
1791 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1796 dsi_bus_unlock(dssdev);
1798 taal_queue_esd_work(dssdev);
1800 mutex_unlock(&td->lock);
1803 dev_err(&dssdev->dev, "performing LCD reset\n");
1805 taal_panel_reset(dssdev);
1807 dsi_bus_unlock(dssdev);
1809 taal_queue_esd_work(dssdev);
1811 mutex_unlock(&td->lock);
1814 static struct omap_dss_driver taal_driver = {
1815 .probe = taal_probe,
1816 .remove = __exit_p(taal_remove),
1818 .enable = taal_enable,
1819 .disable = taal_disable,
1820 .suspend = taal_suspend,
1821 .resume = taal_resume,
1823 .update = taal_update,
1826 .get_resolution = taal_get_resolution,
1827 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1829 .enable_te = taal_enable_te,
1830 .get_te = taal_get_te,
1832 .set_rotate = taal_rotate,
1833 .get_rotate = taal_get_rotate,
1834 .set_mirror = taal_mirror,
1835 .get_mirror = taal_get_mirror,
1836 .run_test = taal_run_test,
1837 .memory_read = taal_memory_read,
1841 .owner = THIS_MODULE,
1845 static int __init taal_init(void)
1847 omap_dss_register_driver(&taal_driver);
1852 static void __exit taal_exit(void)
1854 omap_dss_unregister_driver(&taal_driver);
1857 module_init(taal_init);
1858 module_exit(taal_exit);
1860 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1861 MODULE_DESCRIPTION("Taal Driver");
1862 MODULE_LICENSE("GPL");