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;
124 /* panel specific HW info */
125 struct panel_config *panel_config;
127 /* panel HW configuration from DT or platform data */
131 bool use_dsi_backlight;
133 struct omap_dsi_pin_config pin_config;
135 /* runtime variables */
145 struct delayed_work te_timeout_work;
152 struct workqueue_struct *workqueue;
154 struct delayed_work esd_work;
155 unsigned esd_interval;
158 unsigned ulps_timeout;
159 struct delayed_work ulps_work;
162 static void taal_esd_work(struct work_struct *work);
163 static void taal_ulps_work(struct work_struct *work);
165 static void hw_guard_start(struct taal_data *td, int guard_msec)
167 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
168 td->hw_guard_end = jiffies + td->hw_guard_wait;
171 static void hw_guard_wait(struct taal_data *td)
173 unsigned long wait = td->hw_guard_end - jiffies;
175 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
176 set_current_state(TASK_UNINTERRUPTIBLE);
177 schedule_timeout(wait);
181 static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
186 r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1);
196 static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
198 return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1);
201 static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
206 return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2);
209 static int taal_sleep_in(struct taal_data *td)
217 cmd = MIPI_DCS_ENTER_SLEEP_MODE;
218 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1);
222 hw_guard_start(td, 120);
224 if (td->panel_config->sleep.sleep_in)
225 msleep(td->panel_config->sleep.sleep_in);
230 static int taal_sleep_out(struct taal_data *td)
236 r = taal_dcs_write_0(td, MIPI_DCS_EXIT_SLEEP_MODE);
240 hw_guard_start(td, 120);
242 if (td->panel_config->sleep.sleep_out)
243 msleep(td->panel_config->sleep.sleep_out);
248 static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
252 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
255 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
258 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
265 static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
271 r = taal_dcs_read_1(td, MIPI_DCS_GET_ADDRESS_MODE, &mode);
302 mode &= ~((1<<7) | (1<<6) | (1<<5));
303 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
305 return taal_dcs_write_1(td, MIPI_DCS_SET_ADDRESS_MODE, mode);
308 static int taal_set_update_window(struct taal_data *td,
309 u16 x, u16 y, u16 w, u16 h)
318 buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
319 buf[1] = (x1 >> 8) & 0xff;
320 buf[2] = (x1 >> 0) & 0xff;
321 buf[3] = (x2 >> 8) & 0xff;
322 buf[4] = (x2 >> 0) & 0xff;
324 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
328 buf[0] = MIPI_DCS_SET_PAGE_ADDRESS;
329 buf[1] = (y1 >> 8) & 0xff;
330 buf[2] = (y1 >> 0) & 0xff;
331 buf[3] = (y2 >> 8) & 0xff;
332 buf[4] = (y2 >> 0) & 0xff;
334 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
338 dsi_vc_send_bta_sync(td->dssdev, td->channel);
343 static void taal_queue_esd_work(struct omap_dss_device *dssdev)
345 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
347 if (td->esd_interval > 0)
348 queue_delayed_work(td->workqueue, &td->esd_work,
349 msecs_to_jiffies(td->esd_interval));
352 static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
354 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
356 cancel_delayed_work(&td->esd_work);
359 static void taal_queue_ulps_work(struct omap_dss_device *dssdev)
361 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
363 if (td->ulps_timeout > 0)
364 queue_delayed_work(td->workqueue, &td->ulps_work,
365 msecs_to_jiffies(td->ulps_timeout));
368 static void taal_cancel_ulps_work(struct omap_dss_device *dssdev)
370 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
372 cancel_delayed_work(&td->ulps_work);
375 static int taal_enter_ulps(struct omap_dss_device *dssdev)
377 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
380 if (td->ulps_enabled)
383 taal_cancel_ulps_work(dssdev);
385 r = _taal_enable_te(dssdev, false);
389 if (gpio_is_valid(td->ext_te_gpio))
390 disable_irq(gpio_to_irq(td->ext_te_gpio));
392 omapdss_dsi_display_disable(dssdev, false, true);
394 td->ulps_enabled = true;
399 dev_err(&dssdev->dev, "enter ULPS failed");
400 taal_panel_reset(dssdev);
402 td->ulps_enabled = false;
404 taal_queue_ulps_work(dssdev);
409 static int taal_exit_ulps(struct omap_dss_device *dssdev)
411 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
414 if (!td->ulps_enabled)
417 r = omapdss_dsi_display_enable(dssdev);
419 dev_err(&dssdev->dev, "failed to enable DSI\n");
423 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
425 r = _taal_enable_te(dssdev, true);
427 dev_err(&dssdev->dev, "failed to re-enable TE");
431 if (gpio_is_valid(td->ext_te_gpio))
432 enable_irq(gpio_to_irq(td->ext_te_gpio));
434 taal_queue_ulps_work(dssdev);
436 td->ulps_enabled = false;
441 dev_err(&dssdev->dev, "failed to exit ULPS");
443 r = taal_panel_reset(dssdev);
445 if (gpio_is_valid(td->ext_te_gpio))
446 enable_irq(gpio_to_irq(td->ext_te_gpio));
447 td->ulps_enabled = false;
450 taal_queue_ulps_work(dssdev);
455 static int taal_wake_up(struct omap_dss_device *dssdev)
457 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
459 if (td->ulps_enabled)
460 return taal_exit_ulps(dssdev);
462 taal_cancel_ulps_work(dssdev);
463 taal_queue_ulps_work(dssdev);
467 static int taal_bl_update_status(struct backlight_device *dev)
469 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
470 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
474 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
475 dev->props.power == FB_BLANK_UNBLANK)
476 level = dev->props.brightness;
480 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
482 mutex_lock(&td->lock);
485 dsi_bus_lock(dssdev);
487 r = taal_wake_up(dssdev);
489 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
491 dsi_bus_unlock(dssdev);
496 mutex_unlock(&td->lock);
501 static int taal_bl_get_intensity(struct backlight_device *dev)
503 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
504 dev->props.power == FB_BLANK_UNBLANK)
505 return dev->props.brightness;
510 static const struct backlight_ops taal_bl_ops = {
511 .get_brightness = taal_bl_get_intensity,
512 .update_status = taal_bl_update_status,
515 static void taal_get_resolution(struct omap_dss_device *dssdev,
516 u16 *xres, u16 *yres)
518 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
520 if (td->rotate == 0 || td->rotate == 2) {
521 *xres = dssdev->panel.timings.x_res;
522 *yres = dssdev->panel.timings.y_res;
524 *yres = dssdev->panel.timings.x_res;
525 *xres = dssdev->panel.timings.y_res;
529 static ssize_t taal_num_errors_show(struct device *dev,
530 struct device_attribute *attr, char *buf)
532 struct omap_dss_device *dssdev = to_dss_device(dev);
533 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
537 mutex_lock(&td->lock);
540 dsi_bus_lock(dssdev);
542 r = taal_wake_up(dssdev);
544 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
546 dsi_bus_unlock(dssdev);
551 mutex_unlock(&td->lock);
556 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
559 static ssize_t taal_hw_revision_show(struct device *dev,
560 struct device_attribute *attr, char *buf)
562 struct omap_dss_device *dssdev = to_dss_device(dev);
563 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
567 mutex_lock(&td->lock);
570 dsi_bus_lock(dssdev);
572 r = taal_wake_up(dssdev);
574 r = taal_get_id(td, &id1, &id2, &id3);
576 dsi_bus_unlock(dssdev);
581 mutex_unlock(&td->lock);
586 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
589 static const char *cabc_modes[] = {
590 "off", /* used also always when CABC is not supported */
596 static ssize_t show_cabc_mode(struct device *dev,
597 struct device_attribute *attr,
600 struct omap_dss_device *dssdev = to_dss_device(dev);
601 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
602 const char *mode_str;
606 mode = td->cabc_mode;
608 mode_str = "unknown";
609 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
610 mode_str = cabc_modes[mode];
611 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
613 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
616 static ssize_t store_cabc_mode(struct device *dev,
617 struct device_attribute *attr,
618 const char *buf, size_t count)
620 struct omap_dss_device *dssdev = to_dss_device(dev);
621 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
625 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
626 if (sysfs_streq(cabc_modes[i], buf))
630 if (i == ARRAY_SIZE(cabc_modes))
633 mutex_lock(&td->lock);
636 dsi_bus_lock(dssdev);
638 if (!td->cabc_broken) {
639 r = taal_wake_up(dssdev);
643 r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
648 dsi_bus_unlock(dssdev);
653 mutex_unlock(&td->lock);
657 dsi_bus_unlock(dssdev);
658 mutex_unlock(&td->lock);
662 static ssize_t show_cabc_available_modes(struct device *dev,
663 struct device_attribute *attr,
670 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
671 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
672 i ? " " : "", cabc_modes[i],
673 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
675 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
678 static ssize_t taal_store_esd_interval(struct device *dev,
679 struct device_attribute *attr,
680 const char *buf, size_t count)
682 struct omap_dss_device *dssdev = to_dss_device(dev);
683 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
688 r = strict_strtoul(buf, 10, &t);
692 mutex_lock(&td->lock);
693 taal_cancel_esd_work(dssdev);
694 td->esd_interval = t;
696 taal_queue_esd_work(dssdev);
697 mutex_unlock(&td->lock);
702 static ssize_t taal_show_esd_interval(struct device *dev,
703 struct device_attribute *attr,
706 struct omap_dss_device *dssdev = to_dss_device(dev);
707 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
710 mutex_lock(&td->lock);
711 t = td->esd_interval;
712 mutex_unlock(&td->lock);
714 return snprintf(buf, PAGE_SIZE, "%u\n", t);
717 static ssize_t taal_store_ulps(struct device *dev,
718 struct device_attribute *attr,
719 const char *buf, size_t count)
721 struct omap_dss_device *dssdev = to_dss_device(dev);
722 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
726 r = strict_strtoul(buf, 10, &t);
730 mutex_lock(&td->lock);
733 dsi_bus_lock(dssdev);
736 r = taal_enter_ulps(dssdev);
738 r = taal_wake_up(dssdev);
740 dsi_bus_unlock(dssdev);
743 mutex_unlock(&td->lock);
751 static ssize_t taal_show_ulps(struct device *dev,
752 struct device_attribute *attr,
755 struct omap_dss_device *dssdev = to_dss_device(dev);
756 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
759 mutex_lock(&td->lock);
760 t = td->ulps_enabled;
761 mutex_unlock(&td->lock);
763 return snprintf(buf, PAGE_SIZE, "%u\n", t);
766 static ssize_t taal_store_ulps_timeout(struct device *dev,
767 struct device_attribute *attr,
768 const char *buf, size_t count)
770 struct omap_dss_device *dssdev = to_dss_device(dev);
771 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
775 r = strict_strtoul(buf, 10, &t);
779 mutex_lock(&td->lock);
780 td->ulps_timeout = t;
783 /* taal_wake_up will restart the timer */
784 dsi_bus_lock(dssdev);
785 r = taal_wake_up(dssdev);
786 dsi_bus_unlock(dssdev);
789 mutex_unlock(&td->lock);
797 static ssize_t taal_show_ulps_timeout(struct device *dev,
798 struct device_attribute *attr,
801 struct omap_dss_device *dssdev = to_dss_device(dev);
802 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
805 mutex_lock(&td->lock);
806 t = td->ulps_timeout;
807 mutex_unlock(&td->lock);
809 return snprintf(buf, PAGE_SIZE, "%u\n", t);
812 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
813 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
814 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
815 show_cabc_mode, store_cabc_mode);
816 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
817 show_cabc_available_modes, NULL);
818 static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
819 taal_show_esd_interval, taal_store_esd_interval);
820 static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
821 taal_show_ulps, taal_store_ulps);
822 static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
823 taal_show_ulps_timeout, taal_store_ulps_timeout);
825 static struct attribute *taal_attrs[] = {
826 &dev_attr_num_dsi_errors.attr,
827 &dev_attr_hw_revision.attr,
828 &dev_attr_cabc_mode.attr,
829 &dev_attr_cabc_available_modes.attr,
830 &dev_attr_esd_interval.attr,
832 &dev_attr_ulps_timeout.attr,
836 static struct attribute_group taal_attr_group = {
840 static void taal_hw_reset(struct omap_dss_device *dssdev)
842 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
844 if (!gpio_is_valid(td->reset_gpio))
847 gpio_set_value(td->reset_gpio, 1);
848 if (td->panel_config->reset_sequence.high)
849 udelay(td->panel_config->reset_sequence.high);
850 /* reset the panel */
851 gpio_set_value(td->reset_gpio, 0);
853 if (td->panel_config->reset_sequence.low)
854 udelay(td->panel_config->reset_sequence.low);
855 gpio_set_value(td->reset_gpio, 1);
856 /* wait after releasing reset */
857 if (td->panel_config->sleep.hw_reset)
858 msleep(td->panel_config->sleep.hw_reset);
861 static void taal_probe_pdata(struct taal_data *td,
862 const struct nokia_dsi_panel_data *pdata)
864 td->reset_gpio = pdata->reset_gpio;
866 if (pdata->use_ext_te)
867 td->ext_te_gpio = pdata->ext_te_gpio;
869 td->ext_te_gpio = -1;
871 td->esd_interval = pdata->esd_interval;
872 td->ulps_timeout = pdata->ulps_timeout;
874 td->use_dsi_backlight = pdata->use_dsi_backlight;
876 td->pin_config = pdata->pin_config;
879 static int taal_probe(struct omap_dss_device *dssdev)
881 struct backlight_properties props;
882 struct taal_data *td;
883 struct backlight_device *bldev = NULL;
885 const char *panel_name;
887 dev_dbg(&dssdev->dev, "probe\n");
889 td = devm_kzalloc(&dssdev->dev, sizeof(*td), GFP_KERNEL);
893 dev_set_drvdata(&dssdev->dev, td);
897 const struct nokia_dsi_panel_data *pdata = dssdev->data;
899 taal_probe_pdata(td, pdata);
901 panel_name = pdata->name;
906 if (panel_name == NULL)
909 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
910 if (strcmp(panel_name, panel_configs[i].name) == 0) {
911 td->panel_config = &panel_configs[i];
916 if (!td->panel_config)
919 dssdev->panel.timings = td->panel_config->timings;
920 dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
921 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
922 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
924 mutex_init(&td->lock);
926 atomic_set(&td->do_update, 0);
928 if (gpio_is_valid(td->reset_gpio)) {
929 r = devm_gpio_request_one(&dssdev->dev, td->reset_gpio,
930 GPIOF_OUT_INIT_LOW, "taal rst");
932 dev_err(&dssdev->dev, "failed to request reset gpio\n");
937 if (gpio_is_valid(td->ext_te_gpio)) {
938 r = devm_gpio_request_one(&dssdev->dev, td->ext_te_gpio,
939 GPIOF_IN, "taal irq");
941 dev_err(&dssdev->dev, "GPIO request failed\n");
945 r = devm_request_irq(&dssdev->dev, gpio_to_irq(td->ext_te_gpio),
948 "taal vsync", dssdev);
951 dev_err(&dssdev->dev, "IRQ request failed\n");
955 INIT_DEFERRABLE_WORK(&td->te_timeout_work,
956 taal_te_timeout_work_callback);
958 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
961 td->workqueue = create_singlethread_workqueue("taal_esd");
962 if (td->workqueue == NULL) {
963 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
966 INIT_DEFERRABLE_WORK(&td->esd_work, taal_esd_work);
967 INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
969 taal_hw_reset(dssdev);
971 if (td->use_dsi_backlight) {
972 memset(&props, 0, sizeof(struct backlight_properties));
973 props.max_brightness = 255;
975 props.type = BACKLIGHT_RAW;
976 bldev = backlight_device_register(dev_name(&dssdev->dev),
977 &dssdev->dev, dssdev, &taal_bl_ops, &props);
985 bldev->props.fb_blank = FB_BLANK_UNBLANK;
986 bldev->props.power = FB_BLANK_UNBLANK;
987 bldev->props.brightness = 255;
989 taal_bl_update_status(bldev);
992 r = omap_dsi_request_vc(dssdev, &td->channel);
994 dev_err(&dssdev->dev, "failed to get virtual channel\n");
998 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
1000 dev_err(&dssdev->dev, "failed to set VC_ID\n");
1004 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
1006 dev_err(&dssdev->dev, "failed to create sysfs files\n");
1013 omap_dsi_release_vc(dssdev, td->channel);
1016 backlight_device_unregister(bldev);
1018 destroy_workqueue(td->workqueue);
1022 static void __exit taal_remove(struct omap_dss_device *dssdev)
1024 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1025 struct backlight_device *bldev;
1027 dev_dbg(&dssdev->dev, "remove\n");
1029 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
1030 omap_dsi_release_vc(dssdev, td->channel);
1033 if (bldev != NULL) {
1034 bldev->props.power = FB_BLANK_POWERDOWN;
1035 taal_bl_update_status(bldev);
1036 backlight_device_unregister(bldev);
1039 taal_cancel_ulps_work(dssdev);
1040 taal_cancel_esd_work(dssdev);
1041 destroy_workqueue(td->workqueue);
1043 /* reset, to be sure that the panel is in a valid state */
1044 taal_hw_reset(dssdev);
1047 static int taal_power_on(struct omap_dss_device *dssdev)
1049 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1053 r = omapdss_dsi_configure_pins(dssdev, &td->pin_config);
1055 dev_err(&dssdev->dev, "failed to configure DSI pins\n");
1059 omapdss_dsi_set_size(dssdev, dssdev->panel.timings.x_res,
1060 dssdev->panel.timings.y_res);
1061 omapdss_dsi_set_pixel_format(dssdev, OMAP_DSS_DSI_FMT_RGB888);
1062 omapdss_dsi_set_operation_mode(dssdev, OMAP_DSS_DSI_CMD_MODE);
1064 r = omapdss_dsi_set_clocks(dssdev, 216000000, 10000000);
1066 dev_err(&dssdev->dev, "failed to set HS and LP clocks\n");
1070 r = omapdss_dsi_display_enable(dssdev);
1072 dev_err(&dssdev->dev, "failed to enable DSI\n");
1076 taal_hw_reset(dssdev);
1078 omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
1080 r = taal_sleep_out(td);
1084 r = taal_get_id(td, &id1, &id2, &id3);
1088 /* on early Taal revisions CABC is broken */
1089 if (td->panel_config->type == PANEL_TAAL &&
1090 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
1091 td->cabc_broken = true;
1093 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
1097 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
1098 (1<<2) | (1<<5)); /* BL | BCTRL */
1102 r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
1103 MIPI_DCS_PIXEL_FMT_24BIT);
1107 r = taal_set_addr_mode(td, td->rotate, td->mirror);
1111 if (!td->cabc_broken) {
1112 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
1117 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
1121 r = _taal_enable_te(dssdev, td->te_enabled);
1125 r = dsi_enable_video_output(dssdev, td->channel);
1131 if (!td->intro_printed) {
1132 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
1133 td->panel_config->name, id1, id2, id3);
1134 if (td->cabc_broken)
1135 dev_info(&dssdev->dev,
1136 "old Taal version, CABC disabled\n");
1137 td->intro_printed = true;
1140 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
1144 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
1146 taal_hw_reset(dssdev);
1148 omapdss_dsi_display_disable(dssdev, true, false);
1153 static void taal_power_off(struct omap_dss_device *dssdev)
1155 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1158 dsi_disable_video_output(dssdev, td->channel);
1160 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
1162 r = taal_sleep_in(td);
1165 dev_err(&dssdev->dev,
1166 "error disabling panel, issuing HW reset\n");
1167 taal_hw_reset(dssdev);
1170 omapdss_dsi_display_disable(dssdev, true, false);
1175 static int taal_panel_reset(struct omap_dss_device *dssdev)
1177 dev_err(&dssdev->dev, "performing LCD reset\n");
1179 taal_power_off(dssdev);
1180 taal_hw_reset(dssdev);
1181 return taal_power_on(dssdev);
1184 static int taal_enable(struct omap_dss_device *dssdev)
1186 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1189 dev_dbg(&dssdev->dev, "enable\n");
1191 mutex_lock(&td->lock);
1193 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
1198 dsi_bus_lock(dssdev);
1200 r = taal_power_on(dssdev);
1202 dsi_bus_unlock(dssdev);
1207 taal_queue_esd_work(dssdev);
1209 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1211 mutex_unlock(&td->lock);
1215 dev_dbg(&dssdev->dev, "enable failed\n");
1216 mutex_unlock(&td->lock);
1220 static void taal_disable(struct omap_dss_device *dssdev)
1222 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1224 dev_dbg(&dssdev->dev, "disable\n");
1226 mutex_lock(&td->lock);
1228 taal_cancel_ulps_work(dssdev);
1229 taal_cancel_esd_work(dssdev);
1231 dsi_bus_lock(dssdev);
1233 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
1236 r = taal_wake_up(dssdev);
1238 taal_power_off(dssdev);
1241 dsi_bus_unlock(dssdev);
1243 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1245 mutex_unlock(&td->lock);
1248 static void taal_framedone_cb(int err, void *data)
1250 struct omap_dss_device *dssdev = data;
1251 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1252 dsi_bus_unlock(dssdev);
1255 static irqreturn_t taal_te_isr(int irq, void *data)
1257 struct omap_dss_device *dssdev = data;
1258 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1262 old = atomic_cmpxchg(&td->do_update, 1, 0);
1265 cancel_delayed_work(&td->te_timeout_work);
1267 r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
1275 dev_err(&dssdev->dev, "start update failed\n");
1276 dsi_bus_unlock(dssdev);
1280 static void taal_te_timeout_work_callback(struct work_struct *work)
1282 struct taal_data *td = container_of(work, struct taal_data,
1283 te_timeout_work.work);
1284 struct omap_dss_device *dssdev = td->dssdev;
1286 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1288 atomic_set(&td->do_update, 0);
1289 dsi_bus_unlock(dssdev);
1292 static int taal_update(struct omap_dss_device *dssdev,
1293 u16 x, u16 y, u16 w, u16 h)
1295 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1298 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1300 mutex_lock(&td->lock);
1301 dsi_bus_lock(dssdev);
1303 r = taal_wake_up(dssdev);
1312 /* XXX no need to send this every frame, but dsi break if not done */
1313 r = taal_set_update_window(td, 0, 0,
1314 td->panel_config->timings.x_res,
1315 td->panel_config->timings.y_res);
1319 if (td->te_enabled && gpio_is_valid(td->ext_te_gpio)) {
1320 schedule_delayed_work(&td->te_timeout_work,
1321 msecs_to_jiffies(250));
1322 atomic_set(&td->do_update, 1);
1324 r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
1330 /* note: no bus_unlock here. unlock is in framedone_cb */
1331 mutex_unlock(&td->lock);
1334 dsi_bus_unlock(dssdev);
1335 mutex_unlock(&td->lock);
1339 static int taal_sync(struct omap_dss_device *dssdev)
1341 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1343 dev_dbg(&dssdev->dev, "sync\n");
1345 mutex_lock(&td->lock);
1346 dsi_bus_lock(dssdev);
1347 dsi_bus_unlock(dssdev);
1348 mutex_unlock(&td->lock);
1350 dev_dbg(&dssdev->dev, "sync done\n");
1355 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1357 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1361 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1363 r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
1365 if (!gpio_is_valid(td->ext_te_gpio))
1366 omapdss_dsi_enable_te(dssdev, enable);
1368 if (td->panel_config->sleep.enable_te)
1369 msleep(td->panel_config->sleep.enable_te);
1374 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1376 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1379 mutex_lock(&td->lock);
1381 if (td->te_enabled == enable)
1384 dsi_bus_lock(dssdev);
1387 r = taal_wake_up(dssdev);
1391 r = _taal_enable_te(dssdev, enable);
1396 td->te_enabled = enable;
1398 dsi_bus_unlock(dssdev);
1400 mutex_unlock(&td->lock);
1404 dsi_bus_unlock(dssdev);
1405 mutex_unlock(&td->lock);
1410 static int taal_get_te(struct omap_dss_device *dssdev)
1412 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1415 mutex_lock(&td->lock);
1417 mutex_unlock(&td->lock);
1422 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1424 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1428 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1430 mutex_lock(&td->lock);
1432 if (td->rotate == rotate)
1435 dsi_bus_lock(dssdev);
1438 r = taal_wake_up(dssdev);
1442 r = taal_set_addr_mode(td, rotate, td->mirror);
1447 if (rotate == 0 || rotate == 2) {
1448 dw = dssdev->panel.timings.x_res;
1449 dh = dssdev->panel.timings.y_res;
1451 dw = dssdev->panel.timings.y_res;
1452 dh = dssdev->panel.timings.x_res;
1455 omapdss_dsi_set_size(dssdev, dw, dh);
1457 td->rotate = rotate;
1459 dsi_bus_unlock(dssdev);
1461 mutex_unlock(&td->lock);
1464 dsi_bus_unlock(dssdev);
1465 mutex_unlock(&td->lock);
1469 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1471 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1474 mutex_lock(&td->lock);
1476 mutex_unlock(&td->lock);
1481 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1483 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1486 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1488 mutex_lock(&td->lock);
1490 if (td->mirror == enable)
1493 dsi_bus_lock(dssdev);
1495 r = taal_wake_up(dssdev);
1499 r = taal_set_addr_mode(td, td->rotate, enable);
1504 td->mirror = enable;
1506 dsi_bus_unlock(dssdev);
1508 mutex_unlock(&td->lock);
1511 dsi_bus_unlock(dssdev);
1512 mutex_unlock(&td->lock);
1516 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1518 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1521 mutex_lock(&td->lock);
1523 mutex_unlock(&td->lock);
1528 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1530 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1534 mutex_lock(&td->lock);
1541 dsi_bus_lock(dssdev);
1543 r = taal_wake_up(dssdev);
1547 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1550 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1553 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1557 dsi_bus_unlock(dssdev);
1558 mutex_unlock(&td->lock);
1561 dsi_bus_unlock(dssdev);
1563 mutex_unlock(&td->lock);
1567 static int taal_memory_read(struct omap_dss_device *dssdev,
1568 void *buf, size_t size,
1569 u16 x, u16 y, u16 w, u16 h)
1574 unsigned buf_used = 0;
1575 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1577 if (size < w * h * 3)
1580 mutex_lock(&td->lock);
1587 size = min(w * h * 3,
1588 dssdev->panel.timings.x_res *
1589 dssdev->panel.timings.y_res * 3);
1591 dsi_bus_lock(dssdev);
1593 r = taal_wake_up(dssdev);
1597 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1598 * use short packets. plen 32 works, but bigger packets seem to cause
1605 taal_set_update_window(td, x, y, w, h);
1607 r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
1611 while (buf_used < size) {
1612 u8 dcs_cmd = first ? 0x2e : 0x3e;
1615 r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
1616 buf + buf_used, size - buf_used);
1619 dev_err(&dssdev->dev, "read error\n");
1626 dev_err(&dssdev->dev, "short read\n");
1630 if (signal_pending(current)) {
1631 dev_err(&dssdev->dev, "signal pending, "
1632 "aborting memory read\n");
1641 dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
1643 dsi_bus_unlock(dssdev);
1645 mutex_unlock(&td->lock);
1649 static void taal_ulps_work(struct work_struct *work)
1651 struct taal_data *td = container_of(work, struct taal_data,
1653 struct omap_dss_device *dssdev = td->dssdev;
1655 mutex_lock(&td->lock);
1657 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
1658 mutex_unlock(&td->lock);
1662 dsi_bus_lock(dssdev);
1664 taal_enter_ulps(dssdev);
1666 dsi_bus_unlock(dssdev);
1667 mutex_unlock(&td->lock);
1670 static void taal_esd_work(struct work_struct *work)
1672 struct taal_data *td = container_of(work, struct taal_data,
1674 struct omap_dss_device *dssdev = td->dssdev;
1678 mutex_lock(&td->lock);
1681 mutex_unlock(&td->lock);
1685 dsi_bus_lock(dssdev);
1687 r = taal_wake_up(dssdev);
1689 dev_err(&dssdev->dev, "failed to exit ULPS\n");
1693 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
1695 dev_err(&dssdev->dev, "failed to read Taal status\n");
1699 /* Run self diagnostics */
1700 r = taal_sleep_out(td);
1702 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1706 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
1708 dev_err(&dssdev->dev, "failed to read Taal status\n");
1712 /* Each sleep out command will trigger a self diagnostic and flip
1713 * Bit6 if the test passes.
1715 if (!((state1 ^ state2) & (1 << 6))) {
1716 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1719 /* Self-diagnostics result is also shown on TE GPIO line. We need
1720 * to re-enable TE after self diagnostics */
1721 if (td->te_enabled && gpio_is_valid(td->ext_te_gpio)) {
1722 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1727 dsi_bus_unlock(dssdev);
1729 taal_queue_esd_work(dssdev);
1731 mutex_unlock(&td->lock);
1734 dev_err(&dssdev->dev, "performing LCD reset\n");
1736 taal_panel_reset(dssdev);
1738 dsi_bus_unlock(dssdev);
1740 taal_queue_esd_work(dssdev);
1742 mutex_unlock(&td->lock);
1745 static struct omap_dss_driver taal_driver = {
1746 .probe = taal_probe,
1747 .remove = __exit_p(taal_remove),
1749 .enable = taal_enable,
1750 .disable = taal_disable,
1752 .update = taal_update,
1755 .get_resolution = taal_get_resolution,
1756 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1758 .enable_te = taal_enable_te,
1759 .get_te = taal_get_te,
1761 .set_rotate = taal_rotate,
1762 .get_rotate = taal_get_rotate,
1763 .set_mirror = taal_mirror,
1764 .get_mirror = taal_get_mirror,
1765 .run_test = taal_run_test,
1766 .memory_read = taal_memory_read,
1770 .owner = THIS_MODULE,
1774 static int __init taal_init(void)
1776 omap_dss_register_driver(&taal_driver);
1781 static void __exit taal_exit(void)
1783 omap_dss_unregister_driver(&taal_driver);
1786 module_init(taal_init);
1787 module_exit(taal_exit);
1789 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1790 MODULE_DESCRIPTION("Taal Driver");
1791 MODULE_LICENSE("GPL");