2 * Taal DSI command mode panel
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <linux/module.h>
23 #include <linux/delay.h>
24 #include <linux/err.h>
25 #include <linux/jiffies.h>
26 #include <linux/sched.h>
27 #include <linux/backlight.h>
29 #include <linux/interrupt.h>
30 #include <linux/gpio.h>
31 #include <linux/workqueue.h>
32 #include <linux/slab.h>
33 #include <linux/regulator/consumer.h>
34 #include <linux/mutex.h>
36 #include <video/omapdss.h>
37 #include <video/omap-panel-nokia-dsi.h>
39 /* DSI Virtual channel. Hardcoded for now. */
42 #define DCS_READ_NUM_ERRORS 0x05
43 #define DCS_READ_POWER_MODE 0x0a
44 #define DCS_READ_MADCTL 0x0b
45 #define DCS_READ_PIXEL_FORMAT 0x0c
46 #define DCS_RDDSDR 0x0f
47 #define DCS_SLEEP_IN 0x10
48 #define DCS_SLEEP_OUT 0x11
49 #define DCS_DISPLAY_OFF 0x28
50 #define DCS_DISPLAY_ON 0x29
51 #define DCS_COLUMN_ADDR 0x2a
52 #define DCS_PAGE_ADDR 0x2b
53 #define DCS_MEMORY_WRITE 0x2c
54 #define DCS_TEAR_OFF 0x34
55 #define DCS_TEAR_ON 0x35
56 #define DCS_MEM_ACC_CTRL 0x36
57 #define DCS_PIXEL_FORMAT 0x3a
58 #define DCS_BRIGHTNESS 0x51
59 #define DCS_CTRL_DISPLAY 0x53
60 #define DCS_WRITE_CABC 0x55
61 #define DCS_READ_CABC 0x56
62 #define DCS_GET_ID1 0xda
63 #define DCS_GET_ID2 0xdb
64 #define DCS_GET_ID3 0xdc
66 static irqreturn_t taal_te_isr(int irq, void *data);
67 static void taal_te_timeout_work_callback(struct work_struct *work);
68 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
70 static int taal_panel_reset(struct omap_dss_device *dssdev);
72 struct panel_regulator {
73 struct regulator *regulator;
79 static void free_regulators(struct panel_regulator *regulators, int n)
83 for (i = 0; i < n; i++) {
84 /* disable/put in reverse order */
85 regulator_disable(regulators[n - i - 1].regulator);
86 regulator_put(regulators[n - i - 1].regulator);
90 static int init_regulators(struct omap_dss_device *dssdev,
91 struct panel_regulator *regulators, int n)
95 for (i = 0; i < n; i++) {
96 struct regulator *reg;
98 reg = regulator_get(&dssdev->dev, regulators[i].name);
100 dev_err(&dssdev->dev, "failed to get regulator %s\n",
106 /* FIXME: better handling of fixed vs. variable regulators */
107 v = regulator_get_voltage(reg);
108 if (v < regulators[i].min_uV || v > regulators[i].max_uV) {
109 r = regulator_set_voltage(reg, regulators[i].min_uV,
110 regulators[i].max_uV);
112 dev_err(&dssdev->dev,
113 "failed to set regulator %s voltage\n",
120 r = regulator_enable(reg);
122 dev_err(&dssdev->dev, "failed to enable regulator %s\n",
128 regulators[i].regulator = reg;
134 free_regulators(regulators, i);
140 * struct panel_config - panel configuration
143 * @timings: panel resolution
144 * @sleep: various panel specific delays, passed to msleep() if non-zero
145 * @reset_sequence: reset sequence timings, passed to udelay() if non-zero
146 * @regulators: array of panel regulators
147 * @num_regulators: number of regulators in the array
149 struct panel_config {
153 struct omap_video_timings timings;
156 unsigned int sleep_in;
157 unsigned int sleep_out;
158 unsigned int hw_reset;
159 unsigned int enable_te;
167 struct panel_regulator *regulators;
175 static struct panel_config panel_configs[] = {
187 .enable_te = 100, /* possible panel bug */
199 struct backlight_device *bldev;
201 unsigned long hw_guard_end; /* next value of jiffies when we can
202 * issue the next sleep in/out command
204 unsigned long hw_guard_wait; /* max guard time in jiffies */
206 struct omap_dss_device *dssdev;
223 struct delayed_work te_timeout_work;
232 struct workqueue_struct *workqueue;
234 struct delayed_work esd_work;
235 unsigned esd_interval;
238 unsigned ulps_timeout;
239 struct delayed_work ulps_work;
241 struct panel_config *panel_config;
244 static inline struct nokia_dsi_panel_data
245 *get_panel_data(const struct omap_dss_device *dssdev)
247 return (struct nokia_dsi_panel_data *) dssdev->data;
250 static void taal_esd_work(struct work_struct *work);
251 static void taal_ulps_work(struct work_struct *work);
253 static void hw_guard_start(struct taal_data *td, int guard_msec)
255 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
256 td->hw_guard_end = jiffies + td->hw_guard_wait;
259 static void hw_guard_wait(struct taal_data *td)
261 unsigned long wait = td->hw_guard_end - jiffies;
263 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
264 set_current_state(TASK_UNINTERRUPTIBLE);
265 schedule_timeout(wait);
269 static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
274 r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1);
284 static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
286 return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1);
289 static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
294 return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2);
297 static int taal_sleep_in(struct taal_data *td)
306 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1);
310 hw_guard_start(td, 120);
312 if (td->panel_config->sleep.sleep_in)
313 msleep(td->panel_config->sleep.sleep_in);
318 static int taal_sleep_out(struct taal_data *td)
324 r = taal_dcs_write_0(td, DCS_SLEEP_OUT);
328 hw_guard_start(td, 120);
330 if (td->panel_config->sleep.sleep_out)
331 msleep(td->panel_config->sleep.sleep_out);
336 static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
340 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
343 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
346 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
353 static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
359 r = taal_dcs_read_1(td, DCS_READ_MADCTL, &mode);
390 mode &= ~((1<<7) | (1<<6) | (1<<5));
391 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
393 return taal_dcs_write_1(td, DCS_MEM_ACC_CTRL, mode);
396 static int taal_set_update_window(struct taal_data *td,
397 u16 x, u16 y, u16 w, u16 h)
406 buf[0] = DCS_COLUMN_ADDR;
407 buf[1] = (x1 >> 8) & 0xff;
408 buf[2] = (x1 >> 0) & 0xff;
409 buf[3] = (x2 >> 8) & 0xff;
410 buf[4] = (x2 >> 0) & 0xff;
412 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
416 buf[0] = DCS_PAGE_ADDR;
417 buf[1] = (y1 >> 8) & 0xff;
418 buf[2] = (y1 >> 0) & 0xff;
419 buf[3] = (y2 >> 8) & 0xff;
420 buf[4] = (y2 >> 0) & 0xff;
422 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
426 dsi_vc_send_bta_sync(td->dssdev, td->channel);
431 static void taal_queue_esd_work(struct omap_dss_device *dssdev)
433 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
435 if (td->esd_interval > 0)
436 queue_delayed_work(td->workqueue, &td->esd_work,
437 msecs_to_jiffies(td->esd_interval));
440 static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
442 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
444 cancel_delayed_work(&td->esd_work);
447 static void taal_queue_ulps_work(struct omap_dss_device *dssdev)
449 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
451 if (td->ulps_timeout > 0)
452 queue_delayed_work(td->workqueue, &td->ulps_work,
453 msecs_to_jiffies(td->ulps_timeout));
456 static void taal_cancel_ulps_work(struct omap_dss_device *dssdev)
458 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
460 cancel_delayed_work(&td->ulps_work);
463 static int taal_enter_ulps(struct omap_dss_device *dssdev)
465 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
466 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
469 if (td->ulps_enabled)
472 taal_cancel_ulps_work(dssdev);
474 r = _taal_enable_te(dssdev, false);
478 disable_irq(gpio_to_irq(panel_data->ext_te_gpio));
480 omapdss_dsi_display_disable(dssdev, false, true);
482 td->ulps_enabled = true;
487 dev_err(&dssdev->dev, "enter ULPS failed");
488 taal_panel_reset(dssdev);
490 td->ulps_enabled = false;
492 taal_queue_ulps_work(dssdev);
497 static int taal_exit_ulps(struct omap_dss_device *dssdev)
499 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
500 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
503 if (!td->ulps_enabled)
506 r = omapdss_dsi_display_enable(dssdev);
510 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
512 r = _taal_enable_te(dssdev, true);
516 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
518 taal_queue_ulps_work(dssdev);
520 td->ulps_enabled = false;
525 dev_err(&dssdev->dev, "exit ULPS failed");
526 r = taal_panel_reset(dssdev);
528 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
529 td->ulps_enabled = false;
531 taal_queue_ulps_work(dssdev);
536 static int taal_wake_up(struct omap_dss_device *dssdev)
538 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
540 if (td->ulps_enabled)
541 return taal_exit_ulps(dssdev);
543 taal_cancel_ulps_work(dssdev);
544 taal_queue_ulps_work(dssdev);
548 static int taal_bl_update_status(struct backlight_device *dev)
550 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
551 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
552 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
556 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
557 dev->props.power == FB_BLANK_UNBLANK)
558 level = dev->props.brightness;
562 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
564 mutex_lock(&td->lock);
566 if (td->use_dsi_bl) {
568 dsi_bus_lock(dssdev);
570 r = taal_wake_up(dssdev);
572 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
574 dsi_bus_unlock(dssdev);
579 if (!panel_data->set_backlight)
582 r = panel_data->set_backlight(dssdev, level);
585 mutex_unlock(&td->lock);
590 static int taal_bl_get_intensity(struct backlight_device *dev)
592 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
593 dev->props.power == FB_BLANK_UNBLANK)
594 return dev->props.brightness;
599 static const struct backlight_ops taal_bl_ops = {
600 .get_brightness = taal_bl_get_intensity,
601 .update_status = taal_bl_update_status,
604 static void taal_get_timings(struct omap_dss_device *dssdev,
605 struct omap_video_timings *timings)
607 *timings = dssdev->panel.timings;
610 static void taal_get_resolution(struct omap_dss_device *dssdev,
611 u16 *xres, u16 *yres)
613 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
615 if (td->rotate == 0 || td->rotate == 2) {
616 *xres = dssdev->panel.timings.x_res;
617 *yres = dssdev->panel.timings.y_res;
619 *yres = dssdev->panel.timings.x_res;
620 *xres = dssdev->panel.timings.y_res;
624 static ssize_t taal_num_errors_show(struct device *dev,
625 struct device_attribute *attr, char *buf)
627 struct omap_dss_device *dssdev = to_dss_device(dev);
628 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
632 mutex_lock(&td->lock);
635 dsi_bus_lock(dssdev);
637 r = taal_wake_up(dssdev);
639 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
641 dsi_bus_unlock(dssdev);
646 mutex_unlock(&td->lock);
651 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
654 static ssize_t taal_hw_revision_show(struct device *dev,
655 struct device_attribute *attr, char *buf)
657 struct omap_dss_device *dssdev = to_dss_device(dev);
658 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
662 mutex_lock(&td->lock);
665 dsi_bus_lock(dssdev);
667 r = taal_wake_up(dssdev);
669 r = taal_get_id(td, &id1, &id2, &id3);
671 dsi_bus_unlock(dssdev);
676 mutex_unlock(&td->lock);
681 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
684 static const char *cabc_modes[] = {
685 "off", /* used also always when CABC is not supported */
691 static ssize_t show_cabc_mode(struct device *dev,
692 struct device_attribute *attr,
695 struct omap_dss_device *dssdev = to_dss_device(dev);
696 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
697 const char *mode_str;
701 mode = td->cabc_mode;
703 mode_str = "unknown";
704 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
705 mode_str = cabc_modes[mode];
706 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
708 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
711 static ssize_t store_cabc_mode(struct device *dev,
712 struct device_attribute *attr,
713 const char *buf, size_t count)
715 struct omap_dss_device *dssdev = to_dss_device(dev);
716 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
720 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
721 if (sysfs_streq(cabc_modes[i], buf))
725 if (i == ARRAY_SIZE(cabc_modes))
728 mutex_lock(&td->lock);
731 dsi_bus_lock(dssdev);
733 if (!td->cabc_broken) {
734 r = taal_wake_up(dssdev);
738 r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
743 dsi_bus_unlock(dssdev);
748 mutex_unlock(&td->lock);
752 dsi_bus_unlock(dssdev);
753 mutex_unlock(&td->lock);
757 static ssize_t show_cabc_available_modes(struct device *dev,
758 struct device_attribute *attr,
765 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
766 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
767 i ? " " : "", cabc_modes[i],
768 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
770 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
773 static ssize_t taal_store_esd_interval(struct device *dev,
774 struct device_attribute *attr,
775 const char *buf, size_t count)
777 struct omap_dss_device *dssdev = to_dss_device(dev);
778 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
783 r = strict_strtoul(buf, 10, &t);
787 mutex_lock(&td->lock);
788 taal_cancel_esd_work(dssdev);
789 td->esd_interval = t;
791 taal_queue_esd_work(dssdev);
792 mutex_unlock(&td->lock);
797 static ssize_t taal_show_esd_interval(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->esd_interval;
807 mutex_unlock(&td->lock);
809 return snprintf(buf, PAGE_SIZE, "%u\n", t);
812 static ssize_t taal_store_ulps(struct device *dev,
813 struct device_attribute *attr,
814 const char *buf, size_t count)
816 struct omap_dss_device *dssdev = to_dss_device(dev);
817 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
821 r = strict_strtoul(buf, 10, &t);
825 mutex_lock(&td->lock);
828 dsi_bus_lock(dssdev);
831 r = taal_enter_ulps(dssdev);
833 r = taal_wake_up(dssdev);
835 dsi_bus_unlock(dssdev);
838 mutex_unlock(&td->lock);
846 static ssize_t taal_show_ulps(struct device *dev,
847 struct device_attribute *attr,
850 struct omap_dss_device *dssdev = to_dss_device(dev);
851 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
854 mutex_lock(&td->lock);
855 t = td->ulps_enabled;
856 mutex_unlock(&td->lock);
858 return snprintf(buf, PAGE_SIZE, "%u\n", t);
861 static ssize_t taal_store_ulps_timeout(struct device *dev,
862 struct device_attribute *attr,
863 const char *buf, size_t count)
865 struct omap_dss_device *dssdev = to_dss_device(dev);
866 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
870 r = strict_strtoul(buf, 10, &t);
874 mutex_lock(&td->lock);
875 td->ulps_timeout = t;
878 /* taal_wake_up will restart the timer */
879 dsi_bus_lock(dssdev);
880 r = taal_wake_up(dssdev);
881 dsi_bus_unlock(dssdev);
884 mutex_unlock(&td->lock);
892 static ssize_t taal_show_ulps_timeout(struct device *dev,
893 struct device_attribute *attr,
896 struct omap_dss_device *dssdev = to_dss_device(dev);
897 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
900 mutex_lock(&td->lock);
901 t = td->ulps_timeout;
902 mutex_unlock(&td->lock);
904 return snprintf(buf, PAGE_SIZE, "%u\n", t);
907 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
908 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
909 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
910 show_cabc_mode, store_cabc_mode);
911 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
912 show_cabc_available_modes, NULL);
913 static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
914 taal_show_esd_interval, taal_store_esd_interval);
915 static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
916 taal_show_ulps, taal_store_ulps);
917 static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
918 taal_show_ulps_timeout, taal_store_ulps_timeout);
920 static struct attribute *taal_attrs[] = {
921 &dev_attr_num_dsi_errors.attr,
922 &dev_attr_hw_revision.attr,
923 &dev_attr_cabc_mode.attr,
924 &dev_attr_cabc_available_modes.attr,
925 &dev_attr_esd_interval.attr,
927 &dev_attr_ulps_timeout.attr,
931 static struct attribute_group taal_attr_group = {
935 static void taal_hw_reset(struct omap_dss_device *dssdev)
937 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
938 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
940 if (panel_data->reset_gpio == -1)
943 gpio_set_value(panel_data->reset_gpio, 1);
944 if (td->panel_config->reset_sequence.high)
945 udelay(td->panel_config->reset_sequence.high);
946 /* reset the panel */
947 gpio_set_value(panel_data->reset_gpio, 0);
949 if (td->panel_config->reset_sequence.low)
950 udelay(td->panel_config->reset_sequence.low);
951 gpio_set_value(panel_data->reset_gpio, 1);
952 /* wait after releasing reset */
953 if (td->panel_config->sleep.hw_reset)
954 msleep(td->panel_config->sleep.hw_reset);
957 static int taal_probe(struct omap_dss_device *dssdev)
959 struct backlight_properties props;
960 struct taal_data *td;
961 struct backlight_device *bldev;
962 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
963 struct panel_config *panel_config = NULL;
966 dev_dbg(&dssdev->dev, "probe\n");
968 if (!panel_data || !panel_data->name) {
973 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
974 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
975 panel_config = &panel_configs[i];
985 dssdev->panel.config = OMAP_DSS_LCD_TFT;
986 dssdev->panel.timings = panel_config->timings;
987 dssdev->ctrl.pixel_size = 24;
989 td = kzalloc(sizeof(*td), GFP_KERNEL);
995 td->panel_config = panel_config;
996 td->esd_interval = panel_data->esd_interval;
997 td->ulps_enabled = false;
998 td->ulps_timeout = panel_data->ulps_timeout;
1000 mutex_init(&td->lock);
1002 atomic_set(&td->do_update, 0);
1004 r = init_regulators(dssdev, panel_config->regulators,
1005 panel_config->num_regulators);
1009 td->workqueue = create_singlethread_workqueue("taal_esd");
1010 if (td->workqueue == NULL) {
1011 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
1015 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
1016 INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
1018 dev_set_drvdata(&dssdev->dev, td);
1020 taal_hw_reset(dssdev);
1022 /* if no platform set_backlight() defined, presume DSI backlight
1024 memset(&props, 0, sizeof(struct backlight_properties));
1025 if (!panel_data->set_backlight)
1026 td->use_dsi_bl = true;
1029 props.max_brightness = 255;
1031 props.max_brightness = 127;
1033 props.type = BACKLIGHT_RAW;
1034 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
1035 &taal_bl_ops, &props);
1036 if (IS_ERR(bldev)) {
1043 bldev->props.fb_blank = FB_BLANK_UNBLANK;
1044 bldev->props.power = FB_BLANK_UNBLANK;
1046 bldev->props.brightness = 255;
1048 bldev->props.brightness = 127;
1050 taal_bl_update_status(bldev);
1052 if (panel_data->use_ext_te) {
1053 int gpio = panel_data->ext_te_gpio;
1055 r = gpio_request(gpio, "taal irq");
1057 dev_err(&dssdev->dev, "GPIO request failed\n");
1061 gpio_direction_input(gpio);
1063 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
1064 IRQF_DISABLED | IRQF_TRIGGER_RISING,
1065 "taal vsync", dssdev);
1068 dev_err(&dssdev->dev, "IRQ request failed\n");
1073 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
1074 taal_te_timeout_work_callback);
1076 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
1079 r = omap_dsi_request_vc(dssdev, &td->channel);
1081 dev_err(&dssdev->dev, "failed to get virtual channel\n");
1085 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
1087 dev_err(&dssdev->dev, "failed to set VC_ID\n");
1091 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
1093 dev_err(&dssdev->dev, "failed to create sysfs files\n");
1100 omap_dsi_release_vc(dssdev, td->channel);
1102 if (panel_data->use_ext_te)
1103 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
1105 if (panel_data->use_ext_te)
1106 gpio_free(panel_data->ext_te_gpio);
1108 backlight_device_unregister(bldev);
1110 destroy_workqueue(td->workqueue);
1112 free_regulators(panel_config->regulators, panel_config->num_regulators);
1119 static void __exit taal_remove(struct omap_dss_device *dssdev)
1121 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1122 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1123 struct backlight_device *bldev;
1125 dev_dbg(&dssdev->dev, "remove\n");
1127 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
1128 omap_dsi_release_vc(dssdev, td->channel);
1130 if (panel_data->use_ext_te) {
1131 int gpio = panel_data->ext_te_gpio;
1132 free_irq(gpio_to_irq(gpio), dssdev);
1137 bldev->props.power = FB_BLANK_POWERDOWN;
1138 taal_bl_update_status(bldev);
1139 backlight_device_unregister(bldev);
1141 taal_cancel_ulps_work(dssdev);
1142 taal_cancel_esd_work(dssdev);
1143 destroy_workqueue(td->workqueue);
1145 /* reset, to be sure that the panel is in a valid state */
1146 taal_hw_reset(dssdev);
1148 free_regulators(td->panel_config->regulators,
1149 td->panel_config->num_regulators);
1154 static int taal_power_on(struct omap_dss_device *dssdev)
1156 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1160 r = omapdss_dsi_display_enable(dssdev);
1162 dev_err(&dssdev->dev, "failed to enable DSI\n");
1166 taal_hw_reset(dssdev);
1168 omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
1170 r = taal_sleep_out(td);
1174 r = taal_get_id(td, &id1, &id2, &id3);
1178 /* on early Taal revisions CABC is broken */
1179 if (td->panel_config->type == PANEL_TAAL &&
1180 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
1181 td->cabc_broken = true;
1183 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
1187 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
1188 (1<<2) | (1<<5)); /* BL | BCTRL */
1192 r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
1196 r = taal_set_addr_mode(td, td->rotate, td->mirror);
1200 if (!td->cabc_broken) {
1201 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
1206 r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
1210 r = _taal_enable_te(dssdev, td->te_enabled);
1216 if (!td->intro_printed) {
1217 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
1218 td->panel_config->name, id1, id2, id3);
1219 if (td->cabc_broken)
1220 dev_info(&dssdev->dev,
1221 "old Taal version, CABC disabled\n");
1222 td->intro_printed = true;
1225 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
1229 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
1231 taal_hw_reset(dssdev);
1233 omapdss_dsi_display_disable(dssdev, true, false);
1238 static void taal_power_off(struct omap_dss_device *dssdev)
1240 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1243 r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
1245 r = taal_sleep_in(td);
1246 /* HACK: wait a bit so that the message goes through */
1251 dev_err(&dssdev->dev,
1252 "error disabling panel, issuing HW reset\n");
1253 taal_hw_reset(dssdev);
1256 omapdss_dsi_display_disable(dssdev, true, false);
1261 static int taal_panel_reset(struct omap_dss_device *dssdev)
1263 dev_err(&dssdev->dev, "performing LCD reset\n");
1265 taal_power_off(dssdev);
1266 taal_hw_reset(dssdev);
1267 return taal_power_on(dssdev);
1270 static int taal_enable(struct omap_dss_device *dssdev)
1272 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1275 dev_dbg(&dssdev->dev, "enable\n");
1277 mutex_lock(&td->lock);
1279 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
1284 dsi_bus_lock(dssdev);
1286 r = taal_power_on(dssdev);
1288 dsi_bus_unlock(dssdev);
1293 taal_queue_esd_work(dssdev);
1295 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1297 mutex_unlock(&td->lock);
1301 dev_dbg(&dssdev->dev, "enable failed\n");
1302 mutex_unlock(&td->lock);
1306 static void taal_disable(struct omap_dss_device *dssdev)
1308 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1310 dev_dbg(&dssdev->dev, "disable\n");
1312 mutex_lock(&td->lock);
1314 taal_cancel_ulps_work(dssdev);
1315 taal_cancel_esd_work(dssdev);
1317 dsi_bus_lock(dssdev);
1319 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
1320 taal_wake_up(dssdev);
1321 taal_power_off(dssdev);
1324 dsi_bus_unlock(dssdev);
1326 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1328 mutex_unlock(&td->lock);
1331 static int taal_suspend(struct omap_dss_device *dssdev)
1333 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1336 dev_dbg(&dssdev->dev, "suspend\n");
1338 mutex_lock(&td->lock);
1340 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1345 taal_cancel_ulps_work(dssdev);
1346 taal_cancel_esd_work(dssdev);
1348 dsi_bus_lock(dssdev);
1350 r = taal_wake_up(dssdev);
1352 taal_power_off(dssdev);
1354 dsi_bus_unlock(dssdev);
1356 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1358 mutex_unlock(&td->lock);
1362 mutex_unlock(&td->lock);
1366 static int taal_resume(struct omap_dss_device *dssdev)
1368 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1371 dev_dbg(&dssdev->dev, "resume\n");
1373 mutex_lock(&td->lock);
1375 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1380 dsi_bus_lock(dssdev);
1382 r = taal_power_on(dssdev);
1384 dsi_bus_unlock(dssdev);
1387 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1389 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1390 taal_queue_esd_work(dssdev);
1393 mutex_unlock(&td->lock);
1397 mutex_unlock(&td->lock);
1401 static void taal_framedone_cb(int err, void *data)
1403 struct omap_dss_device *dssdev = data;
1404 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1405 dsi_bus_unlock(dssdev);
1408 static irqreturn_t taal_te_isr(int irq, void *data)
1410 struct omap_dss_device *dssdev = data;
1411 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1415 old = atomic_cmpxchg(&td->do_update, 1, 0);
1418 cancel_delayed_work(&td->te_timeout_work);
1420 r = omap_dsi_update(dssdev, td->channel,
1421 td->update_region.x,
1422 td->update_region.y,
1423 td->update_region.w,
1424 td->update_region.h,
1425 taal_framedone_cb, dssdev);
1432 dev_err(&dssdev->dev, "start update failed\n");
1433 dsi_bus_unlock(dssdev);
1437 static void taal_te_timeout_work_callback(struct work_struct *work)
1439 struct taal_data *td = container_of(work, struct taal_data,
1440 te_timeout_work.work);
1441 struct omap_dss_device *dssdev = td->dssdev;
1443 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1445 atomic_set(&td->do_update, 0);
1446 dsi_bus_unlock(dssdev);
1449 static int taal_update(struct omap_dss_device *dssdev,
1450 u16 x, u16 y, u16 w, u16 h)
1452 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1453 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1456 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1458 mutex_lock(&td->lock);
1459 dsi_bus_lock(dssdev);
1461 r = taal_wake_up(dssdev);
1470 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
1474 r = taal_set_update_window(td, x, y, w, h);
1478 if (td->te_enabled && panel_data->use_ext_te) {
1479 td->update_region.x = x;
1480 td->update_region.y = y;
1481 td->update_region.w = w;
1482 td->update_region.h = h;
1484 schedule_delayed_work(&td->te_timeout_work,
1485 msecs_to_jiffies(250));
1486 atomic_set(&td->do_update, 1);
1488 r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
1489 taal_framedone_cb, dssdev);
1494 /* note: no bus_unlock here. unlock is in framedone_cb */
1495 mutex_unlock(&td->lock);
1498 dsi_bus_unlock(dssdev);
1499 mutex_unlock(&td->lock);
1503 static int taal_sync(struct omap_dss_device *dssdev)
1505 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1507 dev_dbg(&dssdev->dev, "sync\n");
1509 mutex_lock(&td->lock);
1510 dsi_bus_lock(dssdev);
1511 dsi_bus_unlock(dssdev);
1512 mutex_unlock(&td->lock);
1514 dev_dbg(&dssdev->dev, "sync done\n");
1519 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1521 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1522 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1526 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1528 r = taal_dcs_write_0(td, DCS_TEAR_OFF);
1530 if (!panel_data->use_ext_te)
1531 omapdss_dsi_enable_te(dssdev, enable);
1533 if (td->panel_config->sleep.enable_te)
1534 msleep(td->panel_config->sleep.enable_te);
1539 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1541 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1544 mutex_lock(&td->lock);
1546 if (td->te_enabled == enable)
1549 dsi_bus_lock(dssdev);
1552 r = taal_wake_up(dssdev);
1556 r = _taal_enable_te(dssdev, enable);
1561 td->te_enabled = enable;
1563 dsi_bus_unlock(dssdev);
1565 mutex_unlock(&td->lock);
1569 dsi_bus_unlock(dssdev);
1570 mutex_unlock(&td->lock);
1575 static int taal_get_te(struct omap_dss_device *dssdev)
1577 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1580 mutex_lock(&td->lock);
1582 mutex_unlock(&td->lock);
1587 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1589 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1592 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1594 mutex_lock(&td->lock);
1596 if (td->rotate == rotate)
1599 dsi_bus_lock(dssdev);
1602 r = taal_wake_up(dssdev);
1606 r = taal_set_addr_mode(td, rotate, td->mirror);
1611 td->rotate = rotate;
1613 dsi_bus_unlock(dssdev);
1615 mutex_unlock(&td->lock);
1618 dsi_bus_unlock(dssdev);
1619 mutex_unlock(&td->lock);
1623 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1625 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1628 mutex_lock(&td->lock);
1630 mutex_unlock(&td->lock);
1635 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1637 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1640 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1642 mutex_lock(&td->lock);
1644 if (td->mirror == enable)
1647 dsi_bus_lock(dssdev);
1649 r = taal_wake_up(dssdev);
1653 r = taal_set_addr_mode(td, td->rotate, enable);
1658 td->mirror = enable;
1660 dsi_bus_unlock(dssdev);
1662 mutex_unlock(&td->lock);
1665 dsi_bus_unlock(dssdev);
1666 mutex_unlock(&td->lock);
1670 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1672 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1675 mutex_lock(&td->lock);
1677 mutex_unlock(&td->lock);
1682 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1684 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1688 mutex_lock(&td->lock);
1695 dsi_bus_lock(dssdev);
1697 r = taal_wake_up(dssdev);
1701 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1704 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1707 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1711 dsi_bus_unlock(dssdev);
1712 mutex_unlock(&td->lock);
1715 dsi_bus_unlock(dssdev);
1717 mutex_unlock(&td->lock);
1721 static int taal_memory_read(struct omap_dss_device *dssdev,
1722 void *buf, size_t size,
1723 u16 x, u16 y, u16 w, u16 h)
1728 unsigned buf_used = 0;
1729 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1731 if (size < w * h * 3)
1734 mutex_lock(&td->lock);
1741 size = min(w * h * 3,
1742 dssdev->panel.timings.x_res *
1743 dssdev->panel.timings.y_res * 3);
1745 dsi_bus_lock(dssdev);
1747 r = taal_wake_up(dssdev);
1751 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1752 * use short packets. plen 32 works, but bigger packets seem to cause
1759 taal_set_update_window(td, x, y, w, h);
1761 r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
1765 while (buf_used < size) {
1766 u8 dcs_cmd = first ? 0x2e : 0x3e;
1769 r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
1770 buf + buf_used, size - buf_used);
1773 dev_err(&dssdev->dev, "read error\n");
1780 dev_err(&dssdev->dev, "short read\n");
1784 if (signal_pending(current)) {
1785 dev_err(&dssdev->dev, "signal pending, "
1786 "aborting memory read\n");
1795 dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
1797 dsi_bus_unlock(dssdev);
1799 mutex_unlock(&td->lock);
1803 static void taal_ulps_work(struct work_struct *work)
1805 struct taal_data *td = container_of(work, struct taal_data,
1807 struct omap_dss_device *dssdev = td->dssdev;
1809 mutex_lock(&td->lock);
1811 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
1812 mutex_unlock(&td->lock);
1816 dsi_bus_lock(dssdev);
1818 taal_enter_ulps(dssdev);
1820 dsi_bus_unlock(dssdev);
1821 mutex_unlock(&td->lock);
1824 static void taal_esd_work(struct work_struct *work)
1826 struct taal_data *td = container_of(work, struct taal_data,
1828 struct omap_dss_device *dssdev = td->dssdev;
1829 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1833 mutex_lock(&td->lock);
1836 mutex_unlock(&td->lock);
1840 dsi_bus_lock(dssdev);
1842 r = taal_wake_up(dssdev);
1844 dev_err(&dssdev->dev, "failed to exit ULPS\n");
1848 r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
1850 dev_err(&dssdev->dev, "failed to read Taal status\n");
1854 /* Run self diagnostics */
1855 r = taal_sleep_out(td);
1857 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1861 r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
1863 dev_err(&dssdev->dev, "failed to read Taal status\n");
1867 /* Each sleep out command will trigger a self diagnostic and flip
1868 * Bit6 if the test passes.
1870 if (!((state1 ^ state2) & (1 << 6))) {
1871 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1874 /* Self-diagnostics result is also shown on TE GPIO line. We need
1875 * to re-enable TE after self diagnostics */
1876 if (td->te_enabled && panel_data->use_ext_te) {
1877 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1882 dsi_bus_unlock(dssdev);
1884 taal_queue_esd_work(dssdev);
1886 mutex_unlock(&td->lock);
1889 dev_err(&dssdev->dev, "performing LCD reset\n");
1891 taal_panel_reset(dssdev);
1893 dsi_bus_unlock(dssdev);
1895 taal_queue_esd_work(dssdev);
1897 mutex_unlock(&td->lock);
1900 static int taal_set_update_mode(struct omap_dss_device *dssdev,
1901 enum omap_dss_update_mode mode)
1903 if (mode != OMAP_DSS_UPDATE_MANUAL)
1908 static enum omap_dss_update_mode taal_get_update_mode(
1909 struct omap_dss_device *dssdev)
1911 return OMAP_DSS_UPDATE_MANUAL;
1914 static struct omap_dss_driver taal_driver = {
1915 .probe = taal_probe,
1916 .remove = __exit_p(taal_remove),
1918 .enable = taal_enable,
1919 .disable = taal_disable,
1920 .suspend = taal_suspend,
1921 .resume = taal_resume,
1923 .set_update_mode = taal_set_update_mode,
1924 .get_update_mode = taal_get_update_mode,
1926 .update = taal_update,
1929 .get_resolution = taal_get_resolution,
1930 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1932 .enable_te = taal_enable_te,
1933 .get_te = taal_get_te,
1935 .set_rotate = taal_rotate,
1936 .get_rotate = taal_get_rotate,
1937 .set_mirror = taal_mirror,
1938 .get_mirror = taal_get_mirror,
1939 .run_test = taal_run_test,
1940 .memory_read = taal_memory_read,
1942 .get_timings = taal_get_timings,
1946 .owner = THIS_MODULE,
1950 static int __init taal_init(void)
1952 omap_dss_register_driver(&taal_driver);
1957 static void __exit taal_exit(void)
1959 omap_dss_unregister_driver(&taal_driver);
1962 module_init(taal_init);
1963 module_exit(taal_exit);
1965 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1966 MODULE_DESCRIPTION("Taal Driver");
1967 MODULE_LICENSE("GPL");