2 * Taal DSI command mode panel
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <linux/module.h>
23 #include <linux/delay.h>
24 #include <linux/err.h>
25 #include <linux/jiffies.h>
26 #include <linux/sched.h>
27 #include <linux/backlight.h>
29 #include <linux/interrupt.h>
30 #include <linux/gpio.h>
31 #include <linux/workqueue.h>
32 #include <linux/slab.h>
33 #include <linux/regulator/consumer.h>
34 #include <linux/mutex.h>
36 #include <video/omapdss.h>
37 #include <video/omap-panel-nokia-dsi.h>
38 #include <video/mipi_display.h>
40 /* DSI Virtual channel. Hardcoded for now. */
43 #define DCS_READ_NUM_ERRORS 0x05
44 #define DCS_BRIGHTNESS 0x51
45 #define DCS_CTRL_DISPLAY 0x53
46 #define DCS_WRITE_CABC 0x55
47 #define DCS_READ_CABC 0x56
48 #define DCS_GET_ID1 0xda
49 #define DCS_GET_ID2 0xdb
50 #define DCS_GET_ID3 0xdc
52 static irqreturn_t taal_te_isr(int irq, void *data);
53 static void taal_te_timeout_work_callback(struct work_struct *work);
54 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
56 static int taal_panel_reset(struct omap_dss_device *dssdev);
58 struct panel_regulator {
59 struct regulator *regulator;
65 static void free_regulators(struct panel_regulator *regulators, int n)
69 for (i = 0; i < n; i++) {
70 /* disable/put in reverse order */
71 regulator_disable(regulators[n - i - 1].regulator);
72 regulator_put(regulators[n - i - 1].regulator);
76 static int init_regulators(struct omap_dss_device *dssdev,
77 struct panel_regulator *regulators, int n)
81 for (i = 0; i < n; i++) {
82 struct regulator *reg;
84 reg = regulator_get(&dssdev->dev, regulators[i].name);
86 dev_err(&dssdev->dev, "failed to get regulator %s\n",
92 /* FIXME: better handling of fixed vs. variable regulators */
93 v = regulator_get_voltage(reg);
94 if (v < regulators[i].min_uV || v > regulators[i].max_uV) {
95 r = regulator_set_voltage(reg, regulators[i].min_uV,
96 regulators[i].max_uV);
99 "failed to set regulator %s voltage\n",
106 r = regulator_enable(reg);
108 dev_err(&dssdev->dev, "failed to enable regulator %s\n",
114 regulators[i].regulator = reg;
120 free_regulators(regulators, i);
126 * struct panel_config - panel configuration
129 * @timings: panel resolution
130 * @sleep: various panel specific delays, passed to msleep() if non-zero
131 * @reset_sequence: reset sequence timings, passed to udelay() if non-zero
132 * @regulators: array of panel regulators
133 * @num_regulators: number of regulators in the array
135 struct panel_config {
139 struct omap_video_timings timings;
142 unsigned int sleep_in;
143 unsigned int sleep_out;
144 unsigned int hw_reset;
145 unsigned int enable_te;
153 struct panel_regulator *regulators;
161 static struct panel_config panel_configs[] = {
173 .enable_te = 100, /* possible panel bug */
185 struct backlight_device *bldev;
187 unsigned long hw_guard_end; /* next value of jiffies when we can
188 * issue the next sleep in/out command
190 unsigned long hw_guard_wait; /* max guard time in jiffies */
192 struct omap_dss_device *dssdev;
203 struct delayed_work te_timeout_work;
210 struct workqueue_struct *workqueue;
212 struct delayed_work esd_work;
213 unsigned esd_interval;
216 unsigned ulps_timeout;
217 struct delayed_work ulps_work;
219 struct panel_config *panel_config;
222 static inline struct nokia_dsi_panel_data
223 *get_panel_data(const struct omap_dss_device *dssdev)
225 return (struct nokia_dsi_panel_data *) dssdev->data;
228 static void taal_esd_work(struct work_struct *work);
229 static void taal_ulps_work(struct work_struct *work);
231 static void hw_guard_start(struct taal_data *td, int guard_msec)
233 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
234 td->hw_guard_end = jiffies + td->hw_guard_wait;
237 static void hw_guard_wait(struct taal_data *td)
239 unsigned long wait = td->hw_guard_end - jiffies;
241 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
242 set_current_state(TASK_UNINTERRUPTIBLE);
243 schedule_timeout(wait);
247 static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
252 r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1);
262 static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
264 return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1);
267 static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
272 return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2);
275 static int taal_sleep_in(struct taal_data *td)
283 cmd = MIPI_DCS_ENTER_SLEEP_MODE;
284 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1);
288 hw_guard_start(td, 120);
290 if (td->panel_config->sleep.sleep_in)
291 msleep(td->panel_config->sleep.sleep_in);
296 static int taal_sleep_out(struct taal_data *td)
302 r = taal_dcs_write_0(td, MIPI_DCS_EXIT_SLEEP_MODE);
306 hw_guard_start(td, 120);
308 if (td->panel_config->sleep.sleep_out)
309 msleep(td->panel_config->sleep.sleep_out);
314 static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
318 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
321 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
324 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
331 static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
337 r = taal_dcs_read_1(td, MIPI_DCS_GET_ADDRESS_MODE, &mode);
368 mode &= ~((1<<7) | (1<<6) | (1<<5));
369 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
371 return taal_dcs_write_1(td, MIPI_DCS_SET_ADDRESS_MODE, mode);
374 static int taal_set_update_window(struct taal_data *td,
375 u16 x, u16 y, u16 w, u16 h)
384 buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
385 buf[1] = (x1 >> 8) & 0xff;
386 buf[2] = (x1 >> 0) & 0xff;
387 buf[3] = (x2 >> 8) & 0xff;
388 buf[4] = (x2 >> 0) & 0xff;
390 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
394 buf[0] = MIPI_DCS_SET_PAGE_ADDRESS;
395 buf[1] = (y1 >> 8) & 0xff;
396 buf[2] = (y1 >> 0) & 0xff;
397 buf[3] = (y2 >> 8) & 0xff;
398 buf[4] = (y2 >> 0) & 0xff;
400 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
404 dsi_vc_send_bta_sync(td->dssdev, td->channel);
409 static void taal_queue_esd_work(struct omap_dss_device *dssdev)
411 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
413 if (td->esd_interval > 0)
414 queue_delayed_work(td->workqueue, &td->esd_work,
415 msecs_to_jiffies(td->esd_interval));
418 static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
420 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
422 cancel_delayed_work(&td->esd_work);
425 static void taal_queue_ulps_work(struct omap_dss_device *dssdev)
427 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
429 if (td->ulps_timeout > 0)
430 queue_delayed_work(td->workqueue, &td->ulps_work,
431 msecs_to_jiffies(td->ulps_timeout));
434 static void taal_cancel_ulps_work(struct omap_dss_device *dssdev)
436 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
438 cancel_delayed_work(&td->ulps_work);
441 static int taal_enter_ulps(struct omap_dss_device *dssdev)
443 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
444 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
447 if (td->ulps_enabled)
450 taal_cancel_ulps_work(dssdev);
452 r = _taal_enable_te(dssdev, false);
456 disable_irq(gpio_to_irq(panel_data->ext_te_gpio));
458 omapdss_dsi_display_disable(dssdev, false, true);
460 td->ulps_enabled = true;
465 dev_err(&dssdev->dev, "enter ULPS failed");
466 taal_panel_reset(dssdev);
468 td->ulps_enabled = false;
470 taal_queue_ulps_work(dssdev);
475 static int taal_exit_ulps(struct omap_dss_device *dssdev)
477 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
478 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
481 if (!td->ulps_enabled)
484 r = omapdss_dsi_display_enable(dssdev);
486 dev_err(&dssdev->dev, "failed to enable DSI\n");
490 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
492 r = _taal_enable_te(dssdev, true);
494 dev_err(&dssdev->dev, "failed to re-enable TE");
498 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
500 taal_queue_ulps_work(dssdev);
502 td->ulps_enabled = false;
507 dev_err(&dssdev->dev, "failed to exit ULPS");
509 r = taal_panel_reset(dssdev);
511 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
512 td->ulps_enabled = false;
515 taal_queue_ulps_work(dssdev);
520 static int taal_wake_up(struct omap_dss_device *dssdev)
522 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
524 if (td->ulps_enabled)
525 return taal_exit_ulps(dssdev);
527 taal_cancel_ulps_work(dssdev);
528 taal_queue_ulps_work(dssdev);
532 static int taal_bl_update_status(struct backlight_device *dev)
534 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
535 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
539 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
540 dev->props.power == FB_BLANK_UNBLANK)
541 level = dev->props.brightness;
545 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
547 mutex_lock(&td->lock);
550 dsi_bus_lock(dssdev);
552 r = taal_wake_up(dssdev);
554 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
556 dsi_bus_unlock(dssdev);
561 mutex_unlock(&td->lock);
566 static int taal_bl_get_intensity(struct backlight_device *dev)
568 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
569 dev->props.power == FB_BLANK_UNBLANK)
570 return dev->props.brightness;
575 static const struct backlight_ops taal_bl_ops = {
576 .get_brightness = taal_bl_get_intensity,
577 .update_status = taal_bl_update_status,
580 static void taal_get_timings(struct omap_dss_device *dssdev,
581 struct omap_video_timings *timings)
583 *timings = dssdev->panel.timings;
586 static void taal_get_resolution(struct omap_dss_device *dssdev,
587 u16 *xres, u16 *yres)
589 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
591 if (td->rotate == 0 || td->rotate == 2) {
592 *xres = dssdev->panel.timings.x_res;
593 *yres = dssdev->panel.timings.y_res;
595 *yres = dssdev->panel.timings.x_res;
596 *xres = dssdev->panel.timings.y_res;
600 static ssize_t taal_num_errors_show(struct device *dev,
601 struct device_attribute *attr, char *buf)
603 struct omap_dss_device *dssdev = to_dss_device(dev);
604 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
608 mutex_lock(&td->lock);
611 dsi_bus_lock(dssdev);
613 r = taal_wake_up(dssdev);
615 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
617 dsi_bus_unlock(dssdev);
622 mutex_unlock(&td->lock);
627 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
630 static ssize_t taal_hw_revision_show(struct device *dev,
631 struct device_attribute *attr, char *buf)
633 struct omap_dss_device *dssdev = to_dss_device(dev);
634 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
638 mutex_lock(&td->lock);
641 dsi_bus_lock(dssdev);
643 r = taal_wake_up(dssdev);
645 r = taal_get_id(td, &id1, &id2, &id3);
647 dsi_bus_unlock(dssdev);
652 mutex_unlock(&td->lock);
657 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
660 static const char *cabc_modes[] = {
661 "off", /* used also always when CABC is not supported */
667 static ssize_t show_cabc_mode(struct device *dev,
668 struct device_attribute *attr,
671 struct omap_dss_device *dssdev = to_dss_device(dev);
672 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
673 const char *mode_str;
677 mode = td->cabc_mode;
679 mode_str = "unknown";
680 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
681 mode_str = cabc_modes[mode];
682 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
684 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
687 static ssize_t store_cabc_mode(struct device *dev,
688 struct device_attribute *attr,
689 const char *buf, size_t count)
691 struct omap_dss_device *dssdev = to_dss_device(dev);
692 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
696 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
697 if (sysfs_streq(cabc_modes[i], buf))
701 if (i == ARRAY_SIZE(cabc_modes))
704 mutex_lock(&td->lock);
707 dsi_bus_lock(dssdev);
709 if (!td->cabc_broken) {
710 r = taal_wake_up(dssdev);
714 r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
719 dsi_bus_unlock(dssdev);
724 mutex_unlock(&td->lock);
728 dsi_bus_unlock(dssdev);
729 mutex_unlock(&td->lock);
733 static ssize_t show_cabc_available_modes(struct device *dev,
734 struct device_attribute *attr,
741 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
742 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
743 i ? " " : "", cabc_modes[i],
744 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
746 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
749 static ssize_t taal_store_esd_interval(struct device *dev,
750 struct device_attribute *attr,
751 const char *buf, size_t count)
753 struct omap_dss_device *dssdev = to_dss_device(dev);
754 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
759 r = strict_strtoul(buf, 10, &t);
763 mutex_lock(&td->lock);
764 taal_cancel_esd_work(dssdev);
765 td->esd_interval = t;
767 taal_queue_esd_work(dssdev);
768 mutex_unlock(&td->lock);
773 static ssize_t taal_show_esd_interval(struct device *dev,
774 struct device_attribute *attr,
777 struct omap_dss_device *dssdev = to_dss_device(dev);
778 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
781 mutex_lock(&td->lock);
782 t = td->esd_interval;
783 mutex_unlock(&td->lock);
785 return snprintf(buf, PAGE_SIZE, "%u\n", t);
788 static ssize_t taal_store_ulps(struct device *dev,
789 struct device_attribute *attr,
790 const char *buf, size_t count)
792 struct omap_dss_device *dssdev = to_dss_device(dev);
793 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
797 r = strict_strtoul(buf, 10, &t);
801 mutex_lock(&td->lock);
804 dsi_bus_lock(dssdev);
807 r = taal_enter_ulps(dssdev);
809 r = taal_wake_up(dssdev);
811 dsi_bus_unlock(dssdev);
814 mutex_unlock(&td->lock);
822 static ssize_t taal_show_ulps(struct device *dev,
823 struct device_attribute *attr,
826 struct omap_dss_device *dssdev = to_dss_device(dev);
827 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
830 mutex_lock(&td->lock);
831 t = td->ulps_enabled;
832 mutex_unlock(&td->lock);
834 return snprintf(buf, PAGE_SIZE, "%u\n", t);
837 static ssize_t taal_store_ulps_timeout(struct device *dev,
838 struct device_attribute *attr,
839 const char *buf, size_t count)
841 struct omap_dss_device *dssdev = to_dss_device(dev);
842 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
846 r = strict_strtoul(buf, 10, &t);
850 mutex_lock(&td->lock);
851 td->ulps_timeout = t;
854 /* taal_wake_up will restart the timer */
855 dsi_bus_lock(dssdev);
856 r = taal_wake_up(dssdev);
857 dsi_bus_unlock(dssdev);
860 mutex_unlock(&td->lock);
868 static ssize_t taal_show_ulps_timeout(struct device *dev,
869 struct device_attribute *attr,
872 struct omap_dss_device *dssdev = to_dss_device(dev);
873 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
876 mutex_lock(&td->lock);
877 t = td->ulps_timeout;
878 mutex_unlock(&td->lock);
880 return snprintf(buf, PAGE_SIZE, "%u\n", t);
883 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
884 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
885 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
886 show_cabc_mode, store_cabc_mode);
887 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
888 show_cabc_available_modes, NULL);
889 static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
890 taal_show_esd_interval, taal_store_esd_interval);
891 static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
892 taal_show_ulps, taal_store_ulps);
893 static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
894 taal_show_ulps_timeout, taal_store_ulps_timeout);
896 static struct attribute *taal_attrs[] = {
897 &dev_attr_num_dsi_errors.attr,
898 &dev_attr_hw_revision.attr,
899 &dev_attr_cabc_mode.attr,
900 &dev_attr_cabc_available_modes.attr,
901 &dev_attr_esd_interval.attr,
903 &dev_attr_ulps_timeout.attr,
907 static struct attribute_group taal_attr_group = {
911 static void taal_hw_reset(struct omap_dss_device *dssdev)
913 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
914 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
916 if (panel_data->reset_gpio == -1)
919 gpio_set_value(panel_data->reset_gpio, 1);
920 if (td->panel_config->reset_sequence.high)
921 udelay(td->panel_config->reset_sequence.high);
922 /* reset the panel */
923 gpio_set_value(panel_data->reset_gpio, 0);
925 if (td->panel_config->reset_sequence.low)
926 udelay(td->panel_config->reset_sequence.low);
927 gpio_set_value(panel_data->reset_gpio, 1);
928 /* wait after releasing reset */
929 if (td->panel_config->sleep.hw_reset)
930 msleep(td->panel_config->sleep.hw_reset);
933 static int taal_probe(struct omap_dss_device *dssdev)
935 struct backlight_properties props;
936 struct taal_data *td;
937 struct backlight_device *bldev = NULL;
938 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
939 struct panel_config *panel_config = NULL;
942 dev_dbg(&dssdev->dev, "probe\n");
944 if (!panel_data || !panel_data->name) {
949 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
950 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
951 panel_config = &panel_configs[i];
961 dssdev->panel.config = OMAP_DSS_LCD_TFT;
962 dssdev->panel.timings = panel_config->timings;
963 dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
965 td = kzalloc(sizeof(*td), GFP_KERNEL);
971 td->panel_config = panel_config;
972 td->esd_interval = panel_data->esd_interval;
973 td->ulps_enabled = false;
974 td->ulps_timeout = panel_data->ulps_timeout;
976 mutex_init(&td->lock);
978 atomic_set(&td->do_update, 0);
980 r = init_regulators(dssdev, panel_config->regulators,
981 panel_config->num_regulators);
985 td->workqueue = create_singlethread_workqueue("taal_esd");
986 if (td->workqueue == NULL) {
987 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
991 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
992 INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
994 dev_set_drvdata(&dssdev->dev, td);
996 if (gpio_is_valid(panel_data->reset_gpio)) {
997 r = gpio_request_one(panel_data->reset_gpio, GPIOF_OUT_INIT_LOW,
1000 dev_err(&dssdev->dev, "failed to request reset gpio\n");
1005 taal_hw_reset(dssdev);
1007 if (panel_data->use_dsi_backlight) {
1008 memset(&props, 0, sizeof(struct backlight_properties));
1009 props.max_brightness = 255;
1011 props.type = BACKLIGHT_RAW;
1012 bldev = backlight_device_register(dev_name(&dssdev->dev),
1013 &dssdev->dev, dssdev, &taal_bl_ops, &props);
1014 if (IS_ERR(bldev)) {
1021 bldev->props.fb_blank = FB_BLANK_UNBLANK;
1022 bldev->props.power = FB_BLANK_UNBLANK;
1023 bldev->props.brightness = 255;
1025 taal_bl_update_status(bldev);
1028 if (panel_data->use_ext_te) {
1029 int gpio = panel_data->ext_te_gpio;
1031 r = gpio_request_one(gpio, GPIOF_IN, "taal irq");
1033 dev_err(&dssdev->dev, "GPIO request failed\n");
1037 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
1038 IRQF_TRIGGER_RISING,
1039 "taal vsync", dssdev);
1042 dev_err(&dssdev->dev, "IRQ request failed\n");
1047 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
1048 taal_te_timeout_work_callback);
1050 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
1053 r = omap_dsi_request_vc(dssdev, &td->channel);
1055 dev_err(&dssdev->dev, "failed to get virtual channel\n");
1059 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
1061 dev_err(&dssdev->dev, "failed to set VC_ID\n");
1065 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
1067 dev_err(&dssdev->dev, "failed to create sysfs files\n");
1074 omap_dsi_release_vc(dssdev, td->channel);
1076 if (panel_data->use_ext_te)
1077 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
1079 if (panel_data->use_ext_te)
1080 gpio_free(panel_data->ext_te_gpio);
1083 backlight_device_unregister(bldev);
1085 if (gpio_is_valid(panel_data->reset_gpio))
1086 gpio_free(panel_data->reset_gpio);
1088 destroy_workqueue(td->workqueue);
1090 free_regulators(panel_config->regulators, panel_config->num_regulators);
1097 static void __exit taal_remove(struct omap_dss_device *dssdev)
1099 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1100 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1101 struct backlight_device *bldev;
1103 dev_dbg(&dssdev->dev, "remove\n");
1105 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
1106 omap_dsi_release_vc(dssdev, td->channel);
1108 if (panel_data->use_ext_te) {
1109 int gpio = panel_data->ext_te_gpio;
1110 free_irq(gpio_to_irq(gpio), dssdev);
1115 if (bldev != NULL) {
1116 bldev->props.power = FB_BLANK_POWERDOWN;
1117 taal_bl_update_status(bldev);
1118 backlight_device_unregister(bldev);
1121 taal_cancel_ulps_work(dssdev);
1122 taal_cancel_esd_work(dssdev);
1123 destroy_workqueue(td->workqueue);
1125 /* reset, to be sure that the panel is in a valid state */
1126 taal_hw_reset(dssdev);
1128 free_regulators(td->panel_config->regulators,
1129 td->panel_config->num_regulators);
1131 if (gpio_is_valid(panel_data->reset_gpio))
1132 gpio_free(panel_data->reset_gpio);
1137 static int taal_power_on(struct omap_dss_device *dssdev)
1139 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1140 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1144 r = omapdss_dsi_configure_pins(dssdev, &panel_data->pin_config);
1146 dev_err(&dssdev->dev, "failed to configure DSI pins\n");
1150 r = omapdss_dsi_display_enable(dssdev);
1152 dev_err(&dssdev->dev, "failed to enable DSI\n");
1156 taal_hw_reset(dssdev);
1158 omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
1160 r = taal_sleep_out(td);
1164 r = taal_get_id(td, &id1, &id2, &id3);
1168 /* on early Taal revisions CABC is broken */
1169 if (td->panel_config->type == PANEL_TAAL &&
1170 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
1171 td->cabc_broken = true;
1173 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
1177 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
1178 (1<<2) | (1<<5)); /* BL | BCTRL */
1182 r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
1183 MIPI_DCS_PIXEL_FMT_24BIT);
1187 r = taal_set_addr_mode(td, td->rotate, td->mirror);
1191 if (!td->cabc_broken) {
1192 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
1197 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
1201 r = _taal_enable_te(dssdev, td->te_enabled);
1205 r = dsi_enable_video_output(dssdev, td->channel);
1211 if (!td->intro_printed) {
1212 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
1213 td->panel_config->name, id1, id2, id3);
1214 if (td->cabc_broken)
1215 dev_info(&dssdev->dev,
1216 "old Taal version, CABC disabled\n");
1217 td->intro_printed = true;
1220 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
1224 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
1226 taal_hw_reset(dssdev);
1228 omapdss_dsi_display_disable(dssdev, true, false);
1233 static void taal_power_off(struct omap_dss_device *dssdev)
1235 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1238 dsi_disable_video_output(dssdev, td->channel);
1240 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
1242 r = taal_sleep_in(td);
1245 dev_err(&dssdev->dev,
1246 "error disabling panel, issuing HW reset\n");
1247 taal_hw_reset(dssdev);
1250 omapdss_dsi_display_disable(dssdev, true, false);
1255 static int taal_panel_reset(struct omap_dss_device *dssdev)
1257 dev_err(&dssdev->dev, "performing LCD reset\n");
1259 taal_power_off(dssdev);
1260 taal_hw_reset(dssdev);
1261 return taal_power_on(dssdev);
1264 static int taal_enable(struct omap_dss_device *dssdev)
1266 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1269 dev_dbg(&dssdev->dev, "enable\n");
1271 mutex_lock(&td->lock);
1273 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
1278 dsi_bus_lock(dssdev);
1280 r = taal_power_on(dssdev);
1282 dsi_bus_unlock(dssdev);
1287 taal_queue_esd_work(dssdev);
1289 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1291 mutex_unlock(&td->lock);
1295 dev_dbg(&dssdev->dev, "enable failed\n");
1296 mutex_unlock(&td->lock);
1300 static void taal_disable(struct omap_dss_device *dssdev)
1302 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1304 dev_dbg(&dssdev->dev, "disable\n");
1306 mutex_lock(&td->lock);
1308 taal_cancel_ulps_work(dssdev);
1309 taal_cancel_esd_work(dssdev);
1311 dsi_bus_lock(dssdev);
1313 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
1316 r = taal_wake_up(dssdev);
1318 taal_power_off(dssdev);
1321 dsi_bus_unlock(dssdev);
1323 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1325 mutex_unlock(&td->lock);
1328 static int taal_suspend(struct omap_dss_device *dssdev)
1330 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1333 dev_dbg(&dssdev->dev, "suspend\n");
1335 mutex_lock(&td->lock);
1337 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1342 taal_cancel_ulps_work(dssdev);
1343 taal_cancel_esd_work(dssdev);
1345 dsi_bus_lock(dssdev);
1347 r = taal_wake_up(dssdev);
1349 taal_power_off(dssdev);
1351 dsi_bus_unlock(dssdev);
1353 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1355 mutex_unlock(&td->lock);
1359 mutex_unlock(&td->lock);
1363 static int taal_resume(struct omap_dss_device *dssdev)
1365 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1368 dev_dbg(&dssdev->dev, "resume\n");
1370 mutex_lock(&td->lock);
1372 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1377 dsi_bus_lock(dssdev);
1379 r = taal_power_on(dssdev);
1381 dsi_bus_unlock(dssdev);
1384 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1386 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1387 taal_queue_esd_work(dssdev);
1390 mutex_unlock(&td->lock);
1394 mutex_unlock(&td->lock);
1398 static void taal_framedone_cb(int err, void *data)
1400 struct omap_dss_device *dssdev = data;
1401 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1402 dsi_bus_unlock(dssdev);
1405 static irqreturn_t taal_te_isr(int irq, void *data)
1407 struct omap_dss_device *dssdev = data;
1408 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1412 old = atomic_cmpxchg(&td->do_update, 1, 0);
1415 cancel_delayed_work(&td->te_timeout_work);
1417 r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
1425 dev_err(&dssdev->dev, "start update failed\n");
1426 dsi_bus_unlock(dssdev);
1430 static void taal_te_timeout_work_callback(struct work_struct *work)
1432 struct taal_data *td = container_of(work, struct taal_data,
1433 te_timeout_work.work);
1434 struct omap_dss_device *dssdev = td->dssdev;
1436 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1438 atomic_set(&td->do_update, 0);
1439 dsi_bus_unlock(dssdev);
1442 static int taal_update(struct omap_dss_device *dssdev,
1443 u16 x, u16 y, u16 w, u16 h)
1445 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1446 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1449 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1451 mutex_lock(&td->lock);
1452 dsi_bus_lock(dssdev);
1454 r = taal_wake_up(dssdev);
1463 /* XXX no need to send this every frame, but dsi break if not done */
1464 r = taal_set_update_window(td, 0, 0,
1465 td->panel_config->timings.x_res,
1466 td->panel_config->timings.y_res);
1470 if (td->te_enabled && panel_data->use_ext_te) {
1471 schedule_delayed_work(&td->te_timeout_work,
1472 msecs_to_jiffies(250));
1473 atomic_set(&td->do_update, 1);
1475 r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
1481 /* note: no bus_unlock here. unlock is in framedone_cb */
1482 mutex_unlock(&td->lock);
1485 dsi_bus_unlock(dssdev);
1486 mutex_unlock(&td->lock);
1490 static int taal_sync(struct omap_dss_device *dssdev)
1492 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1494 dev_dbg(&dssdev->dev, "sync\n");
1496 mutex_lock(&td->lock);
1497 dsi_bus_lock(dssdev);
1498 dsi_bus_unlock(dssdev);
1499 mutex_unlock(&td->lock);
1501 dev_dbg(&dssdev->dev, "sync done\n");
1506 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1508 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1509 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1513 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1515 r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
1517 if (!panel_data->use_ext_te)
1518 omapdss_dsi_enable_te(dssdev, enable);
1520 if (td->panel_config->sleep.enable_te)
1521 msleep(td->panel_config->sleep.enable_te);
1526 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1528 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1531 mutex_lock(&td->lock);
1533 if (td->te_enabled == enable)
1536 dsi_bus_lock(dssdev);
1539 r = taal_wake_up(dssdev);
1543 r = _taal_enable_te(dssdev, enable);
1548 td->te_enabled = enable;
1550 dsi_bus_unlock(dssdev);
1552 mutex_unlock(&td->lock);
1556 dsi_bus_unlock(dssdev);
1557 mutex_unlock(&td->lock);
1562 static int taal_get_te(struct omap_dss_device *dssdev)
1564 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1567 mutex_lock(&td->lock);
1569 mutex_unlock(&td->lock);
1574 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1576 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1579 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1581 mutex_lock(&td->lock);
1583 if (td->rotate == rotate)
1586 dsi_bus_lock(dssdev);
1589 r = taal_wake_up(dssdev);
1593 r = taal_set_addr_mode(td, rotate, td->mirror);
1598 td->rotate = rotate;
1600 dsi_bus_unlock(dssdev);
1602 mutex_unlock(&td->lock);
1605 dsi_bus_unlock(dssdev);
1606 mutex_unlock(&td->lock);
1610 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1612 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1615 mutex_lock(&td->lock);
1617 mutex_unlock(&td->lock);
1622 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1624 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1627 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1629 mutex_lock(&td->lock);
1631 if (td->mirror == enable)
1634 dsi_bus_lock(dssdev);
1636 r = taal_wake_up(dssdev);
1640 r = taal_set_addr_mode(td, td->rotate, enable);
1645 td->mirror = enable;
1647 dsi_bus_unlock(dssdev);
1649 mutex_unlock(&td->lock);
1652 dsi_bus_unlock(dssdev);
1653 mutex_unlock(&td->lock);
1657 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1659 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1662 mutex_lock(&td->lock);
1664 mutex_unlock(&td->lock);
1669 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1671 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1675 mutex_lock(&td->lock);
1682 dsi_bus_lock(dssdev);
1684 r = taal_wake_up(dssdev);
1688 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1691 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1694 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1698 dsi_bus_unlock(dssdev);
1699 mutex_unlock(&td->lock);
1702 dsi_bus_unlock(dssdev);
1704 mutex_unlock(&td->lock);
1708 static int taal_memory_read(struct omap_dss_device *dssdev,
1709 void *buf, size_t size,
1710 u16 x, u16 y, u16 w, u16 h)
1715 unsigned buf_used = 0;
1716 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1718 if (size < w * h * 3)
1721 mutex_lock(&td->lock);
1728 size = min(w * h * 3,
1729 dssdev->panel.timings.x_res *
1730 dssdev->panel.timings.y_res * 3);
1732 dsi_bus_lock(dssdev);
1734 r = taal_wake_up(dssdev);
1738 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1739 * use short packets. plen 32 works, but bigger packets seem to cause
1746 taal_set_update_window(td, x, y, w, h);
1748 r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
1752 while (buf_used < size) {
1753 u8 dcs_cmd = first ? 0x2e : 0x3e;
1756 r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
1757 buf + buf_used, size - buf_used);
1760 dev_err(&dssdev->dev, "read error\n");
1767 dev_err(&dssdev->dev, "short read\n");
1771 if (signal_pending(current)) {
1772 dev_err(&dssdev->dev, "signal pending, "
1773 "aborting memory read\n");
1782 dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
1784 dsi_bus_unlock(dssdev);
1786 mutex_unlock(&td->lock);
1790 static void taal_ulps_work(struct work_struct *work)
1792 struct taal_data *td = container_of(work, struct taal_data,
1794 struct omap_dss_device *dssdev = td->dssdev;
1796 mutex_lock(&td->lock);
1798 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
1799 mutex_unlock(&td->lock);
1803 dsi_bus_lock(dssdev);
1805 taal_enter_ulps(dssdev);
1807 dsi_bus_unlock(dssdev);
1808 mutex_unlock(&td->lock);
1811 static void taal_esd_work(struct work_struct *work)
1813 struct taal_data *td = container_of(work, struct taal_data,
1815 struct omap_dss_device *dssdev = td->dssdev;
1816 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1820 mutex_lock(&td->lock);
1823 mutex_unlock(&td->lock);
1827 dsi_bus_lock(dssdev);
1829 r = taal_wake_up(dssdev);
1831 dev_err(&dssdev->dev, "failed to exit ULPS\n");
1835 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
1837 dev_err(&dssdev->dev, "failed to read Taal status\n");
1841 /* Run self diagnostics */
1842 r = taal_sleep_out(td);
1844 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1848 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
1850 dev_err(&dssdev->dev, "failed to read Taal status\n");
1854 /* Each sleep out command will trigger a self diagnostic and flip
1855 * Bit6 if the test passes.
1857 if (!((state1 ^ state2) & (1 << 6))) {
1858 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1861 /* Self-diagnostics result is also shown on TE GPIO line. We need
1862 * to re-enable TE after self diagnostics */
1863 if (td->te_enabled && panel_data->use_ext_te) {
1864 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1869 dsi_bus_unlock(dssdev);
1871 taal_queue_esd_work(dssdev);
1873 mutex_unlock(&td->lock);
1876 dev_err(&dssdev->dev, "performing LCD reset\n");
1878 taal_panel_reset(dssdev);
1880 dsi_bus_unlock(dssdev);
1882 taal_queue_esd_work(dssdev);
1884 mutex_unlock(&td->lock);
1887 static struct omap_dss_driver taal_driver = {
1888 .probe = taal_probe,
1889 .remove = __exit_p(taal_remove),
1891 .enable = taal_enable,
1892 .disable = taal_disable,
1893 .suspend = taal_suspend,
1894 .resume = taal_resume,
1896 .update = taal_update,
1899 .get_resolution = taal_get_resolution,
1900 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1902 .enable_te = taal_enable_te,
1903 .get_te = taal_get_te,
1905 .set_rotate = taal_rotate,
1906 .get_rotate = taal_get_rotate,
1907 .set_mirror = taal_mirror,
1908 .get_mirror = taal_get_mirror,
1909 .run_test = taal_run_test,
1910 .memory_read = taal_memory_read,
1912 .get_timings = taal_get_timings,
1916 .owner = THIS_MODULE,
1920 static int __init taal_init(void)
1922 omap_dss_register_driver(&taal_driver);
1927 static void __exit taal_exit(void)
1929 omap_dss_unregister_driver(&taal_driver);
1932 module_init(taal_init);
1933 module_exit(taal_exit);
1935 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1936 MODULE_DESCRIPTION("Taal Driver");
1937 MODULE_LICENSE("GPL");