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;
209 struct delayed_work te_timeout_work;
218 struct workqueue_struct *workqueue;
220 struct delayed_work esd_work;
221 unsigned esd_interval;
224 unsigned ulps_timeout;
225 struct delayed_work ulps_work;
227 struct panel_config *panel_config;
230 static inline struct nokia_dsi_panel_data
231 *get_panel_data(const struct omap_dss_device *dssdev)
233 return (struct nokia_dsi_panel_data *) dssdev->data;
236 static void taal_esd_work(struct work_struct *work);
237 static void taal_ulps_work(struct work_struct *work);
239 static void hw_guard_start(struct taal_data *td, int guard_msec)
241 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
242 td->hw_guard_end = jiffies + td->hw_guard_wait;
245 static void hw_guard_wait(struct taal_data *td)
247 unsigned long wait = td->hw_guard_end - jiffies;
249 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
250 set_current_state(TASK_UNINTERRUPTIBLE);
251 schedule_timeout(wait);
255 static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
260 r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1);
270 static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
272 return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1);
275 static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
280 return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2);
283 static int taal_sleep_in(struct taal_data *td)
291 cmd = MIPI_DCS_ENTER_SLEEP_MODE;
292 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1);
296 hw_guard_start(td, 120);
298 if (td->panel_config->sleep.sleep_in)
299 msleep(td->panel_config->sleep.sleep_in);
304 static int taal_sleep_out(struct taal_data *td)
310 r = taal_dcs_write_0(td, MIPI_DCS_EXIT_SLEEP_MODE);
314 hw_guard_start(td, 120);
316 if (td->panel_config->sleep.sleep_out)
317 msleep(td->panel_config->sleep.sleep_out);
322 static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
326 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
329 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
332 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
339 static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
345 r = taal_dcs_read_1(td, MIPI_DCS_GET_ADDRESS_MODE, &mode);
376 mode &= ~((1<<7) | (1<<6) | (1<<5));
377 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
379 return taal_dcs_write_1(td, MIPI_DCS_SET_ADDRESS_MODE, mode);
382 static int taal_set_update_window(struct taal_data *td,
383 u16 x, u16 y, u16 w, u16 h)
392 buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
393 buf[1] = (x1 >> 8) & 0xff;
394 buf[2] = (x1 >> 0) & 0xff;
395 buf[3] = (x2 >> 8) & 0xff;
396 buf[4] = (x2 >> 0) & 0xff;
398 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
402 buf[0] = MIPI_DCS_SET_PAGE_ADDRESS;
403 buf[1] = (y1 >> 8) & 0xff;
404 buf[2] = (y1 >> 0) & 0xff;
405 buf[3] = (y2 >> 8) & 0xff;
406 buf[4] = (y2 >> 0) & 0xff;
408 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
412 dsi_vc_send_bta_sync(td->dssdev, td->channel);
417 static void taal_queue_esd_work(struct omap_dss_device *dssdev)
419 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
421 if (td->esd_interval > 0)
422 queue_delayed_work(td->workqueue, &td->esd_work,
423 msecs_to_jiffies(td->esd_interval));
426 static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
428 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
430 cancel_delayed_work(&td->esd_work);
433 static void taal_queue_ulps_work(struct omap_dss_device *dssdev)
435 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
437 if (td->ulps_timeout > 0)
438 queue_delayed_work(td->workqueue, &td->ulps_work,
439 msecs_to_jiffies(td->ulps_timeout));
442 static void taal_cancel_ulps_work(struct omap_dss_device *dssdev)
444 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
446 cancel_delayed_work(&td->ulps_work);
449 static int taal_enter_ulps(struct omap_dss_device *dssdev)
451 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
452 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
455 if (td->ulps_enabled)
458 taal_cancel_ulps_work(dssdev);
460 r = _taal_enable_te(dssdev, false);
464 disable_irq(gpio_to_irq(panel_data->ext_te_gpio));
466 omapdss_dsi_display_disable(dssdev, false, true);
468 td->ulps_enabled = true;
473 dev_err(&dssdev->dev, "enter ULPS failed");
474 taal_panel_reset(dssdev);
476 td->ulps_enabled = false;
478 taal_queue_ulps_work(dssdev);
483 static int taal_exit_ulps(struct omap_dss_device *dssdev)
485 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
486 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
489 if (!td->ulps_enabled)
492 r = omapdss_dsi_display_enable(dssdev);
494 dev_err(&dssdev->dev, "failed to enable DSI\n");
498 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
500 r = _taal_enable_te(dssdev, true);
502 dev_err(&dssdev->dev, "failed to re-enable TE");
506 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
508 taal_queue_ulps_work(dssdev);
510 td->ulps_enabled = false;
515 dev_err(&dssdev->dev, "failed to exit ULPS");
517 r = taal_panel_reset(dssdev);
519 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
520 td->ulps_enabled = false;
523 taal_queue_ulps_work(dssdev);
528 static int taal_wake_up(struct omap_dss_device *dssdev)
530 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
532 if (td->ulps_enabled)
533 return taal_exit_ulps(dssdev);
535 taal_cancel_ulps_work(dssdev);
536 taal_queue_ulps_work(dssdev);
540 static int taal_bl_update_status(struct backlight_device *dev)
542 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
543 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
544 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
548 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
549 dev->props.power == FB_BLANK_UNBLANK)
550 level = dev->props.brightness;
554 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
556 mutex_lock(&td->lock);
558 if (td->use_dsi_bl) {
560 dsi_bus_lock(dssdev);
562 r = taal_wake_up(dssdev);
564 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
566 dsi_bus_unlock(dssdev);
571 if (!panel_data->set_backlight)
574 r = panel_data->set_backlight(dssdev, level);
577 mutex_unlock(&td->lock);
582 static int taal_bl_get_intensity(struct backlight_device *dev)
584 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
585 dev->props.power == FB_BLANK_UNBLANK)
586 return dev->props.brightness;
591 static const struct backlight_ops taal_bl_ops = {
592 .get_brightness = taal_bl_get_intensity,
593 .update_status = taal_bl_update_status,
596 static void taal_get_timings(struct omap_dss_device *dssdev,
597 struct omap_video_timings *timings)
599 *timings = dssdev->panel.timings;
602 static void taal_get_resolution(struct omap_dss_device *dssdev,
603 u16 *xres, u16 *yres)
605 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
607 if (td->rotate == 0 || td->rotate == 2) {
608 *xres = dssdev->panel.timings.x_res;
609 *yres = dssdev->panel.timings.y_res;
611 *yres = dssdev->panel.timings.x_res;
612 *xres = dssdev->panel.timings.y_res;
616 static ssize_t taal_num_errors_show(struct device *dev,
617 struct device_attribute *attr, char *buf)
619 struct omap_dss_device *dssdev = to_dss_device(dev);
620 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
624 mutex_lock(&td->lock);
627 dsi_bus_lock(dssdev);
629 r = taal_wake_up(dssdev);
631 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
633 dsi_bus_unlock(dssdev);
638 mutex_unlock(&td->lock);
643 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
646 static ssize_t taal_hw_revision_show(struct device *dev,
647 struct device_attribute *attr, char *buf)
649 struct omap_dss_device *dssdev = to_dss_device(dev);
650 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
654 mutex_lock(&td->lock);
657 dsi_bus_lock(dssdev);
659 r = taal_wake_up(dssdev);
661 r = taal_get_id(td, &id1, &id2, &id3);
663 dsi_bus_unlock(dssdev);
668 mutex_unlock(&td->lock);
673 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
676 static const char *cabc_modes[] = {
677 "off", /* used also always when CABC is not supported */
683 static ssize_t show_cabc_mode(struct device *dev,
684 struct device_attribute *attr,
687 struct omap_dss_device *dssdev = to_dss_device(dev);
688 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
689 const char *mode_str;
693 mode = td->cabc_mode;
695 mode_str = "unknown";
696 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
697 mode_str = cabc_modes[mode];
698 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
700 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
703 static ssize_t store_cabc_mode(struct device *dev,
704 struct device_attribute *attr,
705 const char *buf, size_t count)
707 struct omap_dss_device *dssdev = to_dss_device(dev);
708 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
712 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
713 if (sysfs_streq(cabc_modes[i], buf))
717 if (i == ARRAY_SIZE(cabc_modes))
720 mutex_lock(&td->lock);
723 dsi_bus_lock(dssdev);
725 if (!td->cabc_broken) {
726 r = taal_wake_up(dssdev);
730 r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
735 dsi_bus_unlock(dssdev);
740 mutex_unlock(&td->lock);
744 dsi_bus_unlock(dssdev);
745 mutex_unlock(&td->lock);
749 static ssize_t show_cabc_available_modes(struct device *dev,
750 struct device_attribute *attr,
757 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
758 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
759 i ? " " : "", cabc_modes[i],
760 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
762 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
765 static ssize_t taal_store_esd_interval(struct device *dev,
766 struct device_attribute *attr,
767 const char *buf, size_t count)
769 struct omap_dss_device *dssdev = to_dss_device(dev);
770 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
775 r = strict_strtoul(buf, 10, &t);
779 mutex_lock(&td->lock);
780 taal_cancel_esd_work(dssdev);
781 td->esd_interval = t;
783 taal_queue_esd_work(dssdev);
784 mutex_unlock(&td->lock);
789 static ssize_t taal_show_esd_interval(struct device *dev,
790 struct device_attribute *attr,
793 struct omap_dss_device *dssdev = to_dss_device(dev);
794 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
797 mutex_lock(&td->lock);
798 t = td->esd_interval;
799 mutex_unlock(&td->lock);
801 return snprintf(buf, PAGE_SIZE, "%u\n", t);
804 static ssize_t taal_store_ulps(struct device *dev,
805 struct device_attribute *attr,
806 const char *buf, size_t count)
808 struct omap_dss_device *dssdev = to_dss_device(dev);
809 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
813 r = strict_strtoul(buf, 10, &t);
817 mutex_lock(&td->lock);
820 dsi_bus_lock(dssdev);
823 r = taal_enter_ulps(dssdev);
825 r = taal_wake_up(dssdev);
827 dsi_bus_unlock(dssdev);
830 mutex_unlock(&td->lock);
838 static ssize_t taal_show_ulps(struct device *dev,
839 struct device_attribute *attr,
842 struct omap_dss_device *dssdev = to_dss_device(dev);
843 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
846 mutex_lock(&td->lock);
847 t = td->ulps_enabled;
848 mutex_unlock(&td->lock);
850 return snprintf(buf, PAGE_SIZE, "%u\n", t);
853 static ssize_t taal_store_ulps_timeout(struct device *dev,
854 struct device_attribute *attr,
855 const char *buf, size_t count)
857 struct omap_dss_device *dssdev = to_dss_device(dev);
858 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
862 r = strict_strtoul(buf, 10, &t);
866 mutex_lock(&td->lock);
867 td->ulps_timeout = t;
870 /* taal_wake_up will restart the timer */
871 dsi_bus_lock(dssdev);
872 r = taal_wake_up(dssdev);
873 dsi_bus_unlock(dssdev);
876 mutex_unlock(&td->lock);
884 static ssize_t taal_show_ulps_timeout(struct device *dev,
885 struct device_attribute *attr,
888 struct omap_dss_device *dssdev = to_dss_device(dev);
889 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
892 mutex_lock(&td->lock);
893 t = td->ulps_timeout;
894 mutex_unlock(&td->lock);
896 return snprintf(buf, PAGE_SIZE, "%u\n", t);
899 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
900 static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
901 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
902 show_cabc_mode, store_cabc_mode);
903 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
904 show_cabc_available_modes, NULL);
905 static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
906 taal_show_esd_interval, taal_store_esd_interval);
907 static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
908 taal_show_ulps, taal_store_ulps);
909 static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
910 taal_show_ulps_timeout, taal_store_ulps_timeout);
912 static struct attribute *taal_attrs[] = {
913 &dev_attr_num_dsi_errors.attr,
914 &dev_attr_hw_revision.attr,
915 &dev_attr_cabc_mode.attr,
916 &dev_attr_cabc_available_modes.attr,
917 &dev_attr_esd_interval.attr,
919 &dev_attr_ulps_timeout.attr,
923 static struct attribute_group taal_attr_group = {
927 static void taal_hw_reset(struct omap_dss_device *dssdev)
929 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
930 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
932 if (panel_data->reset_gpio == -1)
935 gpio_set_value(panel_data->reset_gpio, 1);
936 if (td->panel_config->reset_sequence.high)
937 udelay(td->panel_config->reset_sequence.high);
938 /* reset the panel */
939 gpio_set_value(panel_data->reset_gpio, 0);
941 if (td->panel_config->reset_sequence.low)
942 udelay(td->panel_config->reset_sequence.low);
943 gpio_set_value(panel_data->reset_gpio, 1);
944 /* wait after releasing reset */
945 if (td->panel_config->sleep.hw_reset)
946 msleep(td->panel_config->sleep.hw_reset);
949 static int taal_probe(struct omap_dss_device *dssdev)
951 struct backlight_properties props;
952 struct taal_data *td;
953 struct backlight_device *bldev;
954 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
955 struct panel_config *panel_config = NULL;
958 dev_dbg(&dssdev->dev, "probe\n");
960 if (!panel_data || !panel_data->name) {
965 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
966 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
967 panel_config = &panel_configs[i];
977 dssdev->panel.config = OMAP_DSS_LCD_TFT;
978 dssdev->panel.timings = panel_config->timings;
979 dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
981 td = kzalloc(sizeof(*td), GFP_KERNEL);
987 td->panel_config = panel_config;
988 td->esd_interval = panel_data->esd_interval;
989 td->ulps_enabled = false;
990 td->ulps_timeout = panel_data->ulps_timeout;
992 mutex_init(&td->lock);
994 atomic_set(&td->do_update, 0);
996 r = init_regulators(dssdev, panel_config->regulators,
997 panel_config->num_regulators);
1001 td->workqueue = create_singlethread_workqueue("taal_esd");
1002 if (td->workqueue == NULL) {
1003 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
1007 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
1008 INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
1010 dev_set_drvdata(&dssdev->dev, td);
1012 taal_hw_reset(dssdev);
1014 /* if no platform set_backlight() defined, presume DSI backlight
1016 memset(&props, 0, sizeof(struct backlight_properties));
1017 if (!panel_data->set_backlight)
1018 td->use_dsi_bl = true;
1021 props.max_brightness = 255;
1023 props.max_brightness = 127;
1025 props.type = BACKLIGHT_RAW;
1026 bldev = backlight_device_register(dev_name(&dssdev->dev), &dssdev->dev,
1027 dssdev, &taal_bl_ops, &props);
1028 if (IS_ERR(bldev)) {
1035 bldev->props.fb_blank = FB_BLANK_UNBLANK;
1036 bldev->props.power = FB_BLANK_UNBLANK;
1038 bldev->props.brightness = 255;
1040 bldev->props.brightness = 127;
1042 taal_bl_update_status(bldev);
1044 if (panel_data->use_ext_te) {
1045 int gpio = panel_data->ext_te_gpio;
1047 r = gpio_request(gpio, "taal irq");
1049 dev_err(&dssdev->dev, "GPIO request failed\n");
1053 gpio_direction_input(gpio);
1055 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
1056 IRQF_DISABLED | IRQF_TRIGGER_RISING,
1057 "taal vsync", dssdev);
1060 dev_err(&dssdev->dev, "IRQ request failed\n");
1065 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
1066 taal_te_timeout_work_callback);
1068 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
1071 r = omap_dsi_request_vc(dssdev, &td->channel);
1073 dev_err(&dssdev->dev, "failed to get virtual channel\n");
1077 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
1079 dev_err(&dssdev->dev, "failed to set VC_ID\n");
1083 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
1085 dev_err(&dssdev->dev, "failed to create sysfs files\n");
1092 omap_dsi_release_vc(dssdev, td->channel);
1094 if (panel_data->use_ext_te)
1095 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
1097 if (panel_data->use_ext_te)
1098 gpio_free(panel_data->ext_te_gpio);
1100 backlight_device_unregister(bldev);
1102 destroy_workqueue(td->workqueue);
1104 free_regulators(panel_config->regulators, panel_config->num_regulators);
1111 static void __exit taal_remove(struct omap_dss_device *dssdev)
1113 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1114 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1115 struct backlight_device *bldev;
1117 dev_dbg(&dssdev->dev, "remove\n");
1119 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
1120 omap_dsi_release_vc(dssdev, td->channel);
1122 if (panel_data->use_ext_te) {
1123 int gpio = panel_data->ext_te_gpio;
1124 free_irq(gpio_to_irq(gpio), dssdev);
1129 bldev->props.power = FB_BLANK_POWERDOWN;
1130 taal_bl_update_status(bldev);
1131 backlight_device_unregister(bldev);
1133 taal_cancel_ulps_work(dssdev);
1134 taal_cancel_esd_work(dssdev);
1135 destroy_workqueue(td->workqueue);
1137 /* reset, to be sure that the panel is in a valid state */
1138 taal_hw_reset(dssdev);
1140 free_regulators(td->panel_config->regulators,
1141 td->panel_config->num_regulators);
1146 static int taal_power_on(struct omap_dss_device *dssdev)
1148 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1152 r = omapdss_dsi_display_enable(dssdev);
1154 dev_err(&dssdev->dev, "failed to enable DSI\n");
1158 taal_hw_reset(dssdev);
1160 omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
1162 r = taal_sleep_out(td);
1166 r = taal_get_id(td, &id1, &id2, &id3);
1170 /* on early Taal revisions CABC is broken */
1171 if (td->panel_config->type == PANEL_TAAL &&
1172 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
1173 td->cabc_broken = true;
1175 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
1179 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
1180 (1<<2) | (1<<5)); /* BL | BCTRL */
1184 r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
1185 MIPI_DCS_PIXEL_FMT_24BIT);
1189 r = taal_set_addr_mode(td, td->rotate, td->mirror);
1193 if (!td->cabc_broken) {
1194 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
1199 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
1203 r = _taal_enable_te(dssdev, td->te_enabled);
1209 if (!td->intro_printed) {
1210 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
1211 td->panel_config->name, id1, id2, id3);
1212 if (td->cabc_broken)
1213 dev_info(&dssdev->dev,
1214 "old Taal version, CABC disabled\n");
1215 td->intro_printed = true;
1218 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
1222 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
1224 taal_hw_reset(dssdev);
1226 omapdss_dsi_display_disable(dssdev, true, false);
1231 static void taal_power_off(struct omap_dss_device *dssdev)
1233 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1236 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
1238 r = taal_sleep_in(td);
1241 dev_err(&dssdev->dev,
1242 "error disabling panel, issuing HW reset\n");
1243 taal_hw_reset(dssdev);
1246 omapdss_dsi_display_disable(dssdev, true, false);
1251 static int taal_panel_reset(struct omap_dss_device *dssdev)
1253 dev_err(&dssdev->dev, "performing LCD reset\n");
1255 taal_power_off(dssdev);
1256 taal_hw_reset(dssdev);
1257 return taal_power_on(dssdev);
1260 static int taal_enable(struct omap_dss_device *dssdev)
1262 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1265 dev_dbg(&dssdev->dev, "enable\n");
1267 mutex_lock(&td->lock);
1269 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
1274 dsi_bus_lock(dssdev);
1276 r = taal_power_on(dssdev);
1278 dsi_bus_unlock(dssdev);
1283 taal_queue_esd_work(dssdev);
1285 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1287 mutex_unlock(&td->lock);
1291 dev_dbg(&dssdev->dev, "enable failed\n");
1292 mutex_unlock(&td->lock);
1296 static void taal_disable(struct omap_dss_device *dssdev)
1298 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1300 dev_dbg(&dssdev->dev, "disable\n");
1302 mutex_lock(&td->lock);
1304 taal_cancel_ulps_work(dssdev);
1305 taal_cancel_esd_work(dssdev);
1307 dsi_bus_lock(dssdev);
1309 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
1312 r = taal_wake_up(dssdev);
1314 taal_power_off(dssdev);
1317 dsi_bus_unlock(dssdev);
1319 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1321 mutex_unlock(&td->lock);
1324 static int taal_suspend(struct omap_dss_device *dssdev)
1326 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1329 dev_dbg(&dssdev->dev, "suspend\n");
1331 mutex_lock(&td->lock);
1333 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1338 taal_cancel_ulps_work(dssdev);
1339 taal_cancel_esd_work(dssdev);
1341 dsi_bus_lock(dssdev);
1343 r = taal_wake_up(dssdev);
1345 taal_power_off(dssdev);
1347 dsi_bus_unlock(dssdev);
1349 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1351 mutex_unlock(&td->lock);
1355 mutex_unlock(&td->lock);
1359 static int taal_resume(struct omap_dss_device *dssdev)
1361 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1364 dev_dbg(&dssdev->dev, "resume\n");
1366 mutex_lock(&td->lock);
1368 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1373 dsi_bus_lock(dssdev);
1375 r = taal_power_on(dssdev);
1377 dsi_bus_unlock(dssdev);
1380 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1382 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1383 taal_queue_esd_work(dssdev);
1386 mutex_unlock(&td->lock);
1390 mutex_unlock(&td->lock);
1394 static void taal_framedone_cb(int err, void *data)
1396 struct omap_dss_device *dssdev = data;
1397 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1398 dsi_bus_unlock(dssdev);
1401 static irqreturn_t taal_te_isr(int irq, void *data)
1403 struct omap_dss_device *dssdev = data;
1404 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1408 old = atomic_cmpxchg(&td->do_update, 1, 0);
1411 cancel_delayed_work(&td->te_timeout_work);
1413 r = omap_dsi_update(dssdev, td->channel,
1414 td->update_region.x,
1415 td->update_region.y,
1416 td->update_region.w,
1417 td->update_region.h,
1418 taal_framedone_cb, dssdev);
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 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
1467 r = taal_set_update_window(td, x, y, w, h);
1471 if (td->te_enabled && panel_data->use_ext_te) {
1472 td->update_region.x = x;
1473 td->update_region.y = y;
1474 td->update_region.w = w;
1475 td->update_region.h = h;
1477 schedule_delayed_work(&td->te_timeout_work,
1478 msecs_to_jiffies(250));
1479 atomic_set(&td->do_update, 1);
1481 r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
1482 taal_framedone_cb, dssdev);
1487 /* note: no bus_unlock here. unlock is in framedone_cb */
1488 mutex_unlock(&td->lock);
1491 dsi_bus_unlock(dssdev);
1492 mutex_unlock(&td->lock);
1496 static int taal_sync(struct omap_dss_device *dssdev)
1498 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1500 dev_dbg(&dssdev->dev, "sync\n");
1502 mutex_lock(&td->lock);
1503 dsi_bus_lock(dssdev);
1504 dsi_bus_unlock(dssdev);
1505 mutex_unlock(&td->lock);
1507 dev_dbg(&dssdev->dev, "sync done\n");
1512 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1514 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1515 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1519 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1521 r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
1523 if (!panel_data->use_ext_te)
1524 omapdss_dsi_enable_te(dssdev, enable);
1526 if (td->panel_config->sleep.enable_te)
1527 msleep(td->panel_config->sleep.enable_te);
1532 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1534 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1537 mutex_lock(&td->lock);
1539 if (td->te_enabled == enable)
1542 dsi_bus_lock(dssdev);
1545 r = taal_wake_up(dssdev);
1549 r = _taal_enable_te(dssdev, enable);
1554 td->te_enabled = enable;
1556 dsi_bus_unlock(dssdev);
1558 mutex_unlock(&td->lock);
1562 dsi_bus_unlock(dssdev);
1563 mutex_unlock(&td->lock);
1568 static int taal_get_te(struct omap_dss_device *dssdev)
1570 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1573 mutex_lock(&td->lock);
1575 mutex_unlock(&td->lock);
1580 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1582 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1585 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1587 mutex_lock(&td->lock);
1589 if (td->rotate == rotate)
1592 dsi_bus_lock(dssdev);
1595 r = taal_wake_up(dssdev);
1599 r = taal_set_addr_mode(td, rotate, td->mirror);
1604 td->rotate = rotate;
1606 dsi_bus_unlock(dssdev);
1608 mutex_unlock(&td->lock);
1611 dsi_bus_unlock(dssdev);
1612 mutex_unlock(&td->lock);
1616 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1618 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1621 mutex_lock(&td->lock);
1623 mutex_unlock(&td->lock);
1628 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1630 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1633 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1635 mutex_lock(&td->lock);
1637 if (td->mirror == enable)
1640 dsi_bus_lock(dssdev);
1642 r = taal_wake_up(dssdev);
1646 r = taal_set_addr_mode(td, td->rotate, enable);
1651 td->mirror = enable;
1653 dsi_bus_unlock(dssdev);
1655 mutex_unlock(&td->lock);
1658 dsi_bus_unlock(dssdev);
1659 mutex_unlock(&td->lock);
1663 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1665 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1668 mutex_lock(&td->lock);
1670 mutex_unlock(&td->lock);
1675 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1677 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1681 mutex_lock(&td->lock);
1688 dsi_bus_lock(dssdev);
1690 r = taal_wake_up(dssdev);
1694 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1697 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1700 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1704 dsi_bus_unlock(dssdev);
1705 mutex_unlock(&td->lock);
1708 dsi_bus_unlock(dssdev);
1710 mutex_unlock(&td->lock);
1714 static int taal_memory_read(struct omap_dss_device *dssdev,
1715 void *buf, size_t size,
1716 u16 x, u16 y, u16 w, u16 h)
1721 unsigned buf_used = 0;
1722 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1724 if (size < w * h * 3)
1727 mutex_lock(&td->lock);
1734 size = min(w * h * 3,
1735 dssdev->panel.timings.x_res *
1736 dssdev->panel.timings.y_res * 3);
1738 dsi_bus_lock(dssdev);
1740 r = taal_wake_up(dssdev);
1744 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1745 * use short packets. plen 32 works, but bigger packets seem to cause
1752 taal_set_update_window(td, x, y, w, h);
1754 r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
1758 while (buf_used < size) {
1759 u8 dcs_cmd = first ? 0x2e : 0x3e;
1762 r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
1763 buf + buf_used, size - buf_used);
1766 dev_err(&dssdev->dev, "read error\n");
1773 dev_err(&dssdev->dev, "short read\n");
1777 if (signal_pending(current)) {
1778 dev_err(&dssdev->dev, "signal pending, "
1779 "aborting memory read\n");
1788 dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
1790 dsi_bus_unlock(dssdev);
1792 mutex_unlock(&td->lock);
1796 static void taal_ulps_work(struct work_struct *work)
1798 struct taal_data *td = container_of(work, struct taal_data,
1800 struct omap_dss_device *dssdev = td->dssdev;
1802 mutex_lock(&td->lock);
1804 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
1805 mutex_unlock(&td->lock);
1809 dsi_bus_lock(dssdev);
1811 taal_enter_ulps(dssdev);
1813 dsi_bus_unlock(dssdev);
1814 mutex_unlock(&td->lock);
1817 static void taal_esd_work(struct work_struct *work)
1819 struct taal_data *td = container_of(work, struct taal_data,
1821 struct omap_dss_device *dssdev = td->dssdev;
1822 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1826 mutex_lock(&td->lock);
1829 mutex_unlock(&td->lock);
1833 dsi_bus_lock(dssdev);
1835 r = taal_wake_up(dssdev);
1837 dev_err(&dssdev->dev, "failed to exit ULPS\n");
1841 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
1843 dev_err(&dssdev->dev, "failed to read Taal status\n");
1847 /* Run self diagnostics */
1848 r = taal_sleep_out(td);
1850 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1854 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
1856 dev_err(&dssdev->dev, "failed to read Taal status\n");
1860 /* Each sleep out command will trigger a self diagnostic and flip
1861 * Bit6 if the test passes.
1863 if (!((state1 ^ state2) & (1 << 6))) {
1864 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1867 /* Self-diagnostics result is also shown on TE GPIO line. We need
1868 * to re-enable TE after self diagnostics */
1869 if (td->te_enabled && panel_data->use_ext_te) {
1870 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1875 dsi_bus_unlock(dssdev);
1877 taal_queue_esd_work(dssdev);
1879 mutex_unlock(&td->lock);
1882 dev_err(&dssdev->dev, "performing LCD reset\n");
1884 taal_panel_reset(dssdev);
1886 dsi_bus_unlock(dssdev);
1888 taal_queue_esd_work(dssdev);
1890 mutex_unlock(&td->lock);
1893 static struct omap_dss_driver taal_driver = {
1894 .probe = taal_probe,
1895 .remove = __exit_p(taal_remove),
1897 .enable = taal_enable,
1898 .disable = taal_disable,
1899 .suspend = taal_suspend,
1900 .resume = taal_resume,
1902 .update = taal_update,
1905 .get_resolution = taal_get_resolution,
1906 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1908 .enable_te = taal_enable_te,
1909 .get_te = taal_get_te,
1911 .set_rotate = taal_rotate,
1912 .get_rotate = taal_get_rotate,
1913 .set_mirror = taal_mirror,
1914 .get_mirror = taal_get_mirror,
1915 .run_test = taal_run_test,
1916 .memory_read = taal_memory_read,
1918 .get_timings = taal_get_timings,
1922 .owner = THIS_MODULE,
1926 static int __init taal_init(void)
1928 omap_dss_register_driver(&taal_driver);
1933 static void __exit taal_exit(void)
1935 omap_dss_unregister_driver(&taal_driver);
1938 module_init(taal_init);
1939 module_exit(taal_exit);
1941 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1942 MODULE_DESCRIPTION("Taal Driver");
1943 MODULE_LICENSE("GPL");