OMAPDSS: VENC: fix NULL pointer dereference in DSS2 VENC sysfs debug attr on OMAP4
[zen-stable.git] / drivers / video / omap2 / displays / panel-taal.c
blob00c5c615585f91d3216df25a28fb64fbc42611b4
1 /*
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
14 * more details.
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/>.
20 /*#define DEBUG*/
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>
28 #include <linux/fb.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. */
41 #define TCH 0
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;
60 const char *name;
61 int min_uV;
62 int max_uV;
65 static void free_regulators(struct panel_regulator *regulators, int n)
67 int i;
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)
79 int r, i, v;
81 for (i = 0; i < n; i++) {
82 struct regulator *reg;
84 reg = regulator_get(&dssdev->dev, regulators[i].name);
85 if (IS_ERR(reg)) {
86 dev_err(&dssdev->dev, "failed to get regulator %s\n",
87 regulators[i].name);
88 r = PTR_ERR(reg);
89 goto err;
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);
97 if (r) {
98 dev_err(&dssdev->dev,
99 "failed to set regulator %s voltage\n",
100 regulators[i].name);
101 regulator_put(reg);
102 goto err;
106 r = regulator_enable(reg);
107 if (r) {
108 dev_err(&dssdev->dev, "failed to enable regulator %s\n",
109 regulators[i].name);
110 regulator_put(reg);
111 goto err;
114 regulators[i].regulator = reg;
117 return 0;
119 err:
120 free_regulators(regulators, i);
122 return r;
126 * struct panel_config - panel configuration
127 * @name: panel name
128 * @type: panel type
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 {
136 const char *name;
137 int type;
139 struct omap_video_timings timings;
141 struct {
142 unsigned int sleep_in;
143 unsigned int sleep_out;
144 unsigned int hw_reset;
145 unsigned int enable_te;
146 } sleep;
148 struct {
149 unsigned int high;
150 unsigned int low;
151 } reset_sequence;
153 struct panel_regulator *regulators;
154 int num_regulators;
157 enum {
158 PANEL_TAAL,
161 static struct panel_config panel_configs[] = {
163 .name = "taal",
164 .type = PANEL_TAAL,
165 .timings = {
166 .x_res = 864,
167 .y_res = 480,
169 .sleep = {
170 .sleep_in = 5,
171 .sleep_out = 5,
172 .hw_reset = 5,
173 .enable_te = 100, /* possible panel bug */
175 .reset_sequence = {
176 .high = 10,
177 .low = 10,
182 struct taal_data {
183 struct mutex lock;
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;
194 bool enabled;
195 u8 rotate;
196 bool mirror;
198 bool te_enabled;
200 atomic_t do_update;
201 int channel;
203 struct delayed_work te_timeout_work;
205 bool cabc_broken;
206 unsigned cabc_mode;
208 bool intro_printed;
210 struct workqueue_struct *workqueue;
212 struct delayed_work esd_work;
213 unsigned esd_interval;
215 bool ulps_enabled;
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)
249 int r;
250 u8 buf[1];
252 r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1);
254 if (r < 0)
255 return r;
257 *data = buf[0];
259 return 0;
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)
269 u8 buf[2];
270 buf[0] = dcs_cmd;
271 buf[1] = param;
272 return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2);
275 static int taal_sleep_in(struct taal_data *td)
278 u8 cmd;
279 int r;
281 hw_guard_wait(td);
283 cmd = MIPI_DCS_ENTER_SLEEP_MODE;
284 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1);
285 if (r)
286 return r;
288 hw_guard_start(td, 120);
290 if (td->panel_config->sleep.sleep_in)
291 msleep(td->panel_config->sleep.sleep_in);
293 return 0;
296 static int taal_sleep_out(struct taal_data *td)
298 int r;
300 hw_guard_wait(td);
302 r = taal_dcs_write_0(td, MIPI_DCS_EXIT_SLEEP_MODE);
303 if (r)
304 return r;
306 hw_guard_start(td, 120);
308 if (td->panel_config->sleep.sleep_out)
309 msleep(td->panel_config->sleep.sleep_out);
311 return 0;
314 static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
316 int r;
318 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
319 if (r)
320 return r;
321 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
322 if (r)
323 return r;
324 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
325 if (r)
326 return r;
328 return 0;
331 static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
333 int r;
334 u8 mode;
335 int b5, b6, b7;
337 r = taal_dcs_read_1(td, MIPI_DCS_GET_ADDRESS_MODE, &mode);
338 if (r)
339 return r;
341 switch (rotate) {
342 default:
343 case 0:
344 b7 = 0;
345 b6 = 0;
346 b5 = 0;
347 break;
348 case 1:
349 b7 = 0;
350 b6 = 1;
351 b5 = 1;
352 break;
353 case 2:
354 b7 = 1;
355 b6 = 1;
356 b5 = 0;
357 break;
358 case 3:
359 b7 = 1;
360 b6 = 0;
361 b5 = 1;
362 break;
365 if (mirror)
366 b6 = !b6;
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)
377 int r;
378 u16 x1 = x;
379 u16 x2 = x + w - 1;
380 u16 y1 = y;
381 u16 y2 = y + h - 1;
383 u8 buf[5];
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));
391 if (r)
392 return r;
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));
401 if (r)
402 return r;
404 dsi_vc_send_bta_sync(td->dssdev, td->channel);
406 return r;
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);
445 int r;
447 if (td->ulps_enabled)
448 return 0;
450 taal_cancel_ulps_work(dssdev);
452 r = _taal_enable_te(dssdev, false);
453 if (r)
454 goto err;
456 disable_irq(gpio_to_irq(panel_data->ext_te_gpio));
458 omapdss_dsi_display_disable(dssdev, false, true);
460 td->ulps_enabled = true;
462 return 0;
464 err:
465 dev_err(&dssdev->dev, "enter ULPS failed");
466 taal_panel_reset(dssdev);
468 td->ulps_enabled = false;
470 taal_queue_ulps_work(dssdev);
472 return r;
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);
479 int r;
481 if (!td->ulps_enabled)
482 return 0;
484 r = omapdss_dsi_display_enable(dssdev);
485 if (r) {
486 dev_err(&dssdev->dev, "failed to enable DSI\n");
487 goto err1;
490 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
492 r = _taal_enable_te(dssdev, true);
493 if (r) {
494 dev_err(&dssdev->dev, "failed to re-enable TE");
495 goto err2;
498 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
500 taal_queue_ulps_work(dssdev);
502 td->ulps_enabled = false;
504 return 0;
506 err2:
507 dev_err(&dssdev->dev, "failed to exit ULPS");
509 r = taal_panel_reset(dssdev);
510 if (!r) {
511 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
512 td->ulps_enabled = false;
514 err1:
515 taal_queue_ulps_work(dssdev);
517 return r;
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);
529 return 0;
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);
536 int r;
537 int level;
539 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
540 dev->props.power == FB_BLANK_UNBLANK)
541 level = dev->props.brightness;
542 else
543 level = 0;
545 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
547 mutex_lock(&td->lock);
549 if (td->enabled) {
550 dsi_bus_lock(dssdev);
552 r = taal_wake_up(dssdev);
553 if (!r)
554 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
556 dsi_bus_unlock(dssdev);
557 } else {
558 r = 0;
561 mutex_unlock(&td->lock);
563 return r;
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;
572 return 0;
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;
594 } else {
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);
605 u8 errors;
606 int r;
608 mutex_lock(&td->lock);
610 if (td->enabled) {
611 dsi_bus_lock(dssdev);
613 r = taal_wake_up(dssdev);
614 if (!r)
615 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
617 dsi_bus_unlock(dssdev);
618 } else {
619 r = -ENODEV;
622 mutex_unlock(&td->lock);
624 if (r)
625 return r;
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);
635 u8 id1, id2, id3;
636 int r;
638 mutex_lock(&td->lock);
640 if (td->enabled) {
641 dsi_bus_lock(dssdev);
643 r = taal_wake_up(dssdev);
644 if (!r)
645 r = taal_get_id(td, &id1, &id2, &id3);
647 dsi_bus_unlock(dssdev);
648 } else {
649 r = -ENODEV;
652 mutex_unlock(&td->lock);
654 if (r)
655 return r;
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 */
662 "ui",
663 "still-image",
664 "moving-image",
667 static ssize_t show_cabc_mode(struct device *dev,
668 struct device_attribute *attr,
669 char *buf)
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;
674 int mode;
675 int len;
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);
693 int i;
694 int r;
696 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
697 if (sysfs_streq(cabc_modes[i], buf))
698 break;
701 if (i == ARRAY_SIZE(cabc_modes))
702 return -EINVAL;
704 mutex_lock(&td->lock);
706 if (td->enabled) {
707 dsi_bus_lock(dssdev);
709 if (!td->cabc_broken) {
710 r = taal_wake_up(dssdev);
711 if (r)
712 goto err;
714 r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
715 if (r)
716 goto err;
719 dsi_bus_unlock(dssdev);
722 td->cabc_mode = i;
724 mutex_unlock(&td->lock);
726 return count;
727 err:
728 dsi_bus_unlock(dssdev);
729 mutex_unlock(&td->lock);
730 return r;
733 static ssize_t show_cabc_available_modes(struct device *dev,
734 struct device_attribute *attr,
735 char *buf)
737 int len;
738 int i;
740 for (i = 0, len = 0;
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);
756 unsigned long t;
757 int r;
759 r = strict_strtoul(buf, 10, &t);
760 if (r)
761 return r;
763 mutex_lock(&td->lock);
764 taal_cancel_esd_work(dssdev);
765 td->esd_interval = t;
766 if (td->enabled)
767 taal_queue_esd_work(dssdev);
768 mutex_unlock(&td->lock);
770 return count;
773 static ssize_t taal_show_esd_interval(struct device *dev,
774 struct device_attribute *attr,
775 char *buf)
777 struct omap_dss_device *dssdev = to_dss_device(dev);
778 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
779 unsigned t;
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);
794 unsigned long t;
795 int r;
797 r = strict_strtoul(buf, 10, &t);
798 if (r)
799 return r;
801 mutex_lock(&td->lock);
803 if (td->enabled) {
804 dsi_bus_lock(dssdev);
806 if (t)
807 r = taal_enter_ulps(dssdev);
808 else
809 r = taal_wake_up(dssdev);
811 dsi_bus_unlock(dssdev);
814 mutex_unlock(&td->lock);
816 if (r)
817 return r;
819 return count;
822 static ssize_t taal_show_ulps(struct device *dev,
823 struct device_attribute *attr,
824 char *buf)
826 struct omap_dss_device *dssdev = to_dss_device(dev);
827 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
828 unsigned t;
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);
843 unsigned long t;
844 int r;
846 r = strict_strtoul(buf, 10, &t);
847 if (r)
848 return r;
850 mutex_lock(&td->lock);
851 td->ulps_timeout = t;
853 if (td->enabled) {
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);
862 if (r)
863 return r;
865 return count;
868 static ssize_t taal_show_ulps_timeout(struct device *dev,
869 struct device_attribute *attr,
870 char *buf)
872 struct omap_dss_device *dssdev = to_dss_device(dev);
873 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
874 unsigned t;
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,
902 &dev_attr_ulps.attr,
903 &dev_attr_ulps_timeout.attr,
904 NULL,
907 static struct attribute_group taal_attr_group = {
908 .attrs = taal_attrs,
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)
917 return;
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);
924 /* assert reset */
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;
940 int r, i;
942 dev_dbg(&dssdev->dev, "probe\n");
944 if (!panel_data || !panel_data->name) {
945 r = -EINVAL;
946 goto err;
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];
952 break;
956 if (!panel_config) {
957 r = -EINVAL;
958 goto err;
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);
966 if (!td) {
967 r = -ENOMEM;
968 goto err;
970 td->dssdev = dssdev;
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);
982 if (r)
983 goto err_reg;
985 td->workqueue = create_singlethread_workqueue("taal_esd");
986 if (td->workqueue == NULL) {
987 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
988 r = -ENOMEM;
989 goto err_wq;
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 taal_hw_reset(dssdev);
998 if (panel_data->use_dsi_backlight) {
999 memset(&props, 0, sizeof(struct backlight_properties));
1000 props.max_brightness = 255;
1002 props.type = BACKLIGHT_RAW;
1003 bldev = backlight_device_register(dev_name(&dssdev->dev),
1004 &dssdev->dev, dssdev, &taal_bl_ops, &props);
1005 if (IS_ERR(bldev)) {
1006 r = PTR_ERR(bldev);
1007 goto err_bl;
1010 td->bldev = bldev;
1012 bldev->props.fb_blank = FB_BLANK_UNBLANK;
1013 bldev->props.power = FB_BLANK_UNBLANK;
1014 bldev->props.brightness = 255;
1016 taal_bl_update_status(bldev);
1019 if (panel_data->use_ext_te) {
1020 int gpio = panel_data->ext_te_gpio;
1022 r = gpio_request(gpio, "taal irq");
1023 if (r) {
1024 dev_err(&dssdev->dev, "GPIO request failed\n");
1025 goto err_gpio;
1028 gpio_direction_input(gpio);
1030 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
1031 IRQF_TRIGGER_RISING,
1032 "taal vsync", dssdev);
1034 if (r) {
1035 dev_err(&dssdev->dev, "IRQ request failed\n");
1036 gpio_free(gpio);
1037 goto err_irq;
1040 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
1041 taal_te_timeout_work_callback);
1043 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
1046 r = omap_dsi_request_vc(dssdev, &td->channel);
1047 if (r) {
1048 dev_err(&dssdev->dev, "failed to get virtual channel\n");
1049 goto err_req_vc;
1052 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
1053 if (r) {
1054 dev_err(&dssdev->dev, "failed to set VC_ID\n");
1055 goto err_vc_id;
1058 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
1059 if (r) {
1060 dev_err(&dssdev->dev, "failed to create sysfs files\n");
1061 goto err_vc_id;
1064 return 0;
1066 err_vc_id:
1067 omap_dsi_release_vc(dssdev, td->channel);
1068 err_req_vc:
1069 if (panel_data->use_ext_te)
1070 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
1071 err_irq:
1072 if (panel_data->use_ext_te)
1073 gpio_free(panel_data->ext_te_gpio);
1074 err_gpio:
1075 if (bldev != NULL)
1076 backlight_device_unregister(bldev);
1077 err_bl:
1078 destroy_workqueue(td->workqueue);
1079 err_wq:
1080 free_regulators(panel_config->regulators, panel_config->num_regulators);
1081 err_reg:
1082 kfree(td);
1083 err:
1084 return r;
1087 static void __exit taal_remove(struct omap_dss_device *dssdev)
1089 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1090 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1091 struct backlight_device *bldev;
1093 dev_dbg(&dssdev->dev, "remove\n");
1095 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
1096 omap_dsi_release_vc(dssdev, td->channel);
1098 if (panel_data->use_ext_te) {
1099 int gpio = panel_data->ext_te_gpio;
1100 free_irq(gpio_to_irq(gpio), dssdev);
1101 gpio_free(gpio);
1104 bldev = td->bldev;
1105 if (bldev != NULL) {
1106 bldev->props.power = FB_BLANK_POWERDOWN;
1107 taal_bl_update_status(bldev);
1108 backlight_device_unregister(bldev);
1111 taal_cancel_ulps_work(dssdev);
1112 taal_cancel_esd_work(dssdev);
1113 destroy_workqueue(td->workqueue);
1115 /* reset, to be sure that the panel is in a valid state */
1116 taal_hw_reset(dssdev);
1118 free_regulators(td->panel_config->regulators,
1119 td->panel_config->num_regulators);
1121 kfree(td);
1124 static int taal_power_on(struct omap_dss_device *dssdev)
1126 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1127 u8 id1, id2, id3;
1128 int r;
1130 r = omapdss_dsi_display_enable(dssdev);
1131 if (r) {
1132 dev_err(&dssdev->dev, "failed to enable DSI\n");
1133 goto err0;
1136 taal_hw_reset(dssdev);
1138 omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
1140 r = taal_sleep_out(td);
1141 if (r)
1142 goto err;
1144 r = taal_get_id(td, &id1, &id2, &id3);
1145 if (r)
1146 goto err;
1148 /* on early Taal revisions CABC is broken */
1149 if (td->panel_config->type == PANEL_TAAL &&
1150 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
1151 td->cabc_broken = true;
1153 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
1154 if (r)
1155 goto err;
1157 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
1158 (1<<2) | (1<<5)); /* BL | BCTRL */
1159 if (r)
1160 goto err;
1162 r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
1163 MIPI_DCS_PIXEL_FMT_24BIT);
1164 if (r)
1165 goto err;
1167 r = taal_set_addr_mode(td, td->rotate, td->mirror);
1168 if (r)
1169 goto err;
1171 if (!td->cabc_broken) {
1172 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
1173 if (r)
1174 goto err;
1177 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
1178 if (r)
1179 goto err;
1181 r = _taal_enable_te(dssdev, td->te_enabled);
1182 if (r)
1183 goto err;
1185 r = dsi_enable_video_output(dssdev, td->channel);
1186 if (r)
1187 goto err;
1189 td->enabled = 1;
1191 if (!td->intro_printed) {
1192 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
1193 td->panel_config->name, id1, id2, id3);
1194 if (td->cabc_broken)
1195 dev_info(&dssdev->dev,
1196 "old Taal version, CABC disabled\n");
1197 td->intro_printed = true;
1200 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
1202 return 0;
1203 err:
1204 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
1206 taal_hw_reset(dssdev);
1208 omapdss_dsi_display_disable(dssdev, true, false);
1209 err0:
1210 return r;
1213 static void taal_power_off(struct omap_dss_device *dssdev)
1215 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1216 int r;
1218 dsi_disable_video_output(dssdev, td->channel);
1220 r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
1221 if (!r)
1222 r = taal_sleep_in(td);
1224 if (r) {
1225 dev_err(&dssdev->dev,
1226 "error disabling panel, issuing HW reset\n");
1227 taal_hw_reset(dssdev);
1230 omapdss_dsi_display_disable(dssdev, true, false);
1232 td->enabled = 0;
1235 static int taal_panel_reset(struct omap_dss_device *dssdev)
1237 dev_err(&dssdev->dev, "performing LCD reset\n");
1239 taal_power_off(dssdev);
1240 taal_hw_reset(dssdev);
1241 return taal_power_on(dssdev);
1244 static int taal_enable(struct omap_dss_device *dssdev)
1246 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1247 int r;
1249 dev_dbg(&dssdev->dev, "enable\n");
1251 mutex_lock(&td->lock);
1253 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
1254 r = -EINVAL;
1255 goto err;
1258 dsi_bus_lock(dssdev);
1260 r = taal_power_on(dssdev);
1262 dsi_bus_unlock(dssdev);
1264 if (r)
1265 goto err;
1267 taal_queue_esd_work(dssdev);
1269 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1271 mutex_unlock(&td->lock);
1273 return 0;
1274 err:
1275 dev_dbg(&dssdev->dev, "enable failed\n");
1276 mutex_unlock(&td->lock);
1277 return r;
1280 static void taal_disable(struct omap_dss_device *dssdev)
1282 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1284 dev_dbg(&dssdev->dev, "disable\n");
1286 mutex_lock(&td->lock);
1288 taal_cancel_ulps_work(dssdev);
1289 taal_cancel_esd_work(dssdev);
1291 dsi_bus_lock(dssdev);
1293 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
1294 int r;
1296 r = taal_wake_up(dssdev);
1297 if (!r)
1298 taal_power_off(dssdev);
1301 dsi_bus_unlock(dssdev);
1303 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1305 mutex_unlock(&td->lock);
1308 static int taal_suspend(struct omap_dss_device *dssdev)
1310 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1311 int r;
1313 dev_dbg(&dssdev->dev, "suspend\n");
1315 mutex_lock(&td->lock);
1317 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1318 r = -EINVAL;
1319 goto err;
1322 taal_cancel_ulps_work(dssdev);
1323 taal_cancel_esd_work(dssdev);
1325 dsi_bus_lock(dssdev);
1327 r = taal_wake_up(dssdev);
1328 if (!r)
1329 taal_power_off(dssdev);
1331 dsi_bus_unlock(dssdev);
1333 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1335 mutex_unlock(&td->lock);
1337 return 0;
1338 err:
1339 mutex_unlock(&td->lock);
1340 return r;
1343 static int taal_resume(struct omap_dss_device *dssdev)
1345 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1346 int r;
1348 dev_dbg(&dssdev->dev, "resume\n");
1350 mutex_lock(&td->lock);
1352 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1353 r = -EINVAL;
1354 goto err;
1357 dsi_bus_lock(dssdev);
1359 r = taal_power_on(dssdev);
1361 dsi_bus_unlock(dssdev);
1363 if (r) {
1364 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1365 } else {
1366 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1367 taal_queue_esd_work(dssdev);
1370 mutex_unlock(&td->lock);
1372 return r;
1373 err:
1374 mutex_unlock(&td->lock);
1375 return r;
1378 static void taal_framedone_cb(int err, void *data)
1380 struct omap_dss_device *dssdev = data;
1381 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1382 dsi_bus_unlock(dssdev);
1385 static irqreturn_t taal_te_isr(int irq, void *data)
1387 struct omap_dss_device *dssdev = data;
1388 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1389 int old;
1390 int r;
1392 old = atomic_cmpxchg(&td->do_update, 1, 0);
1394 if (old) {
1395 cancel_delayed_work(&td->te_timeout_work);
1397 r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
1398 dssdev);
1399 if (r)
1400 goto err;
1403 return IRQ_HANDLED;
1404 err:
1405 dev_err(&dssdev->dev, "start update failed\n");
1406 dsi_bus_unlock(dssdev);
1407 return IRQ_HANDLED;
1410 static void taal_te_timeout_work_callback(struct work_struct *work)
1412 struct taal_data *td = container_of(work, struct taal_data,
1413 te_timeout_work.work);
1414 struct omap_dss_device *dssdev = td->dssdev;
1416 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1418 atomic_set(&td->do_update, 0);
1419 dsi_bus_unlock(dssdev);
1422 static int taal_update(struct omap_dss_device *dssdev,
1423 u16 x, u16 y, u16 w, u16 h)
1425 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1426 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1427 int r;
1429 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1431 mutex_lock(&td->lock);
1432 dsi_bus_lock(dssdev);
1434 r = taal_wake_up(dssdev);
1435 if (r)
1436 goto err;
1438 if (!td->enabled) {
1439 r = 0;
1440 goto err;
1443 /* XXX no need to send this every frame, but dsi break if not done */
1444 r = taal_set_update_window(td, 0, 0,
1445 td->panel_config->timings.x_res,
1446 td->panel_config->timings.y_res);
1447 if (r)
1448 goto err;
1450 if (td->te_enabled && panel_data->use_ext_te) {
1451 schedule_delayed_work(&td->te_timeout_work,
1452 msecs_to_jiffies(250));
1453 atomic_set(&td->do_update, 1);
1454 } else {
1455 r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
1456 dssdev);
1457 if (r)
1458 goto err;
1461 /* note: no bus_unlock here. unlock is in framedone_cb */
1462 mutex_unlock(&td->lock);
1463 return 0;
1464 err:
1465 dsi_bus_unlock(dssdev);
1466 mutex_unlock(&td->lock);
1467 return r;
1470 static int taal_sync(struct omap_dss_device *dssdev)
1472 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1474 dev_dbg(&dssdev->dev, "sync\n");
1476 mutex_lock(&td->lock);
1477 dsi_bus_lock(dssdev);
1478 dsi_bus_unlock(dssdev);
1479 mutex_unlock(&td->lock);
1481 dev_dbg(&dssdev->dev, "sync done\n");
1483 return 0;
1486 static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1488 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1489 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1490 int r;
1492 if (enable)
1493 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1494 else
1495 r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
1497 if (!panel_data->use_ext_te)
1498 omapdss_dsi_enable_te(dssdev, enable);
1500 if (td->panel_config->sleep.enable_te)
1501 msleep(td->panel_config->sleep.enable_te);
1503 return r;
1506 static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1508 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1509 int r;
1511 mutex_lock(&td->lock);
1513 if (td->te_enabled == enable)
1514 goto end;
1516 dsi_bus_lock(dssdev);
1518 if (td->enabled) {
1519 r = taal_wake_up(dssdev);
1520 if (r)
1521 goto err;
1523 r = _taal_enable_te(dssdev, enable);
1524 if (r)
1525 goto err;
1528 td->te_enabled = enable;
1530 dsi_bus_unlock(dssdev);
1531 end:
1532 mutex_unlock(&td->lock);
1534 return 0;
1535 err:
1536 dsi_bus_unlock(dssdev);
1537 mutex_unlock(&td->lock);
1539 return r;
1542 static int taal_get_te(struct omap_dss_device *dssdev)
1544 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1545 int r;
1547 mutex_lock(&td->lock);
1548 r = td->te_enabled;
1549 mutex_unlock(&td->lock);
1551 return r;
1554 static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1556 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1557 int r;
1559 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1561 mutex_lock(&td->lock);
1563 if (td->rotate == rotate)
1564 goto end;
1566 dsi_bus_lock(dssdev);
1568 if (td->enabled) {
1569 r = taal_wake_up(dssdev);
1570 if (r)
1571 goto err;
1573 r = taal_set_addr_mode(td, rotate, td->mirror);
1574 if (r)
1575 goto err;
1578 td->rotate = rotate;
1580 dsi_bus_unlock(dssdev);
1581 end:
1582 mutex_unlock(&td->lock);
1583 return 0;
1584 err:
1585 dsi_bus_unlock(dssdev);
1586 mutex_unlock(&td->lock);
1587 return r;
1590 static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1592 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1593 int r;
1595 mutex_lock(&td->lock);
1596 r = td->rotate;
1597 mutex_unlock(&td->lock);
1599 return r;
1602 static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1604 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1605 int r;
1607 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1609 mutex_lock(&td->lock);
1611 if (td->mirror == enable)
1612 goto end;
1614 dsi_bus_lock(dssdev);
1615 if (td->enabled) {
1616 r = taal_wake_up(dssdev);
1617 if (r)
1618 goto err;
1620 r = taal_set_addr_mode(td, td->rotate, enable);
1621 if (r)
1622 goto err;
1625 td->mirror = enable;
1627 dsi_bus_unlock(dssdev);
1628 end:
1629 mutex_unlock(&td->lock);
1630 return 0;
1631 err:
1632 dsi_bus_unlock(dssdev);
1633 mutex_unlock(&td->lock);
1634 return r;
1637 static bool taal_get_mirror(struct omap_dss_device *dssdev)
1639 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1640 int r;
1642 mutex_lock(&td->lock);
1643 r = td->mirror;
1644 mutex_unlock(&td->lock);
1646 return r;
1649 static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1651 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1652 u8 id1, id2, id3;
1653 int r;
1655 mutex_lock(&td->lock);
1657 if (!td->enabled) {
1658 r = -ENODEV;
1659 goto err1;
1662 dsi_bus_lock(dssdev);
1664 r = taal_wake_up(dssdev);
1665 if (r)
1666 goto err2;
1668 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1669 if (r)
1670 goto err2;
1671 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1672 if (r)
1673 goto err2;
1674 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1675 if (r)
1676 goto err2;
1678 dsi_bus_unlock(dssdev);
1679 mutex_unlock(&td->lock);
1680 return 0;
1681 err2:
1682 dsi_bus_unlock(dssdev);
1683 err1:
1684 mutex_unlock(&td->lock);
1685 return r;
1688 static int taal_memory_read(struct omap_dss_device *dssdev,
1689 void *buf, size_t size,
1690 u16 x, u16 y, u16 w, u16 h)
1692 int r;
1693 int first = 1;
1694 int plen;
1695 unsigned buf_used = 0;
1696 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1698 if (size < w * h * 3)
1699 return -ENOMEM;
1701 mutex_lock(&td->lock);
1703 if (!td->enabled) {
1704 r = -ENODEV;
1705 goto err1;
1708 size = min(w * h * 3,
1709 dssdev->panel.timings.x_res *
1710 dssdev->panel.timings.y_res * 3);
1712 dsi_bus_lock(dssdev);
1714 r = taal_wake_up(dssdev);
1715 if (r)
1716 goto err2;
1718 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1719 * use short packets. plen 32 works, but bigger packets seem to cause
1720 * an error. */
1721 if (size % 2)
1722 plen = 1;
1723 else
1724 plen = 2;
1726 taal_set_update_window(td, x, y, w, h);
1728 r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
1729 if (r)
1730 goto err2;
1732 while (buf_used < size) {
1733 u8 dcs_cmd = first ? 0x2e : 0x3e;
1734 first = 0;
1736 r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
1737 buf + buf_used, size - buf_used);
1739 if (r < 0) {
1740 dev_err(&dssdev->dev, "read error\n");
1741 goto err3;
1744 buf_used += r;
1746 if (r < plen) {
1747 dev_err(&dssdev->dev, "short read\n");
1748 break;
1751 if (signal_pending(current)) {
1752 dev_err(&dssdev->dev, "signal pending, "
1753 "aborting memory read\n");
1754 r = -ERESTARTSYS;
1755 goto err3;
1759 r = buf_used;
1761 err3:
1762 dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
1763 err2:
1764 dsi_bus_unlock(dssdev);
1765 err1:
1766 mutex_unlock(&td->lock);
1767 return r;
1770 static void taal_ulps_work(struct work_struct *work)
1772 struct taal_data *td = container_of(work, struct taal_data,
1773 ulps_work.work);
1774 struct omap_dss_device *dssdev = td->dssdev;
1776 mutex_lock(&td->lock);
1778 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
1779 mutex_unlock(&td->lock);
1780 return;
1783 dsi_bus_lock(dssdev);
1785 taal_enter_ulps(dssdev);
1787 dsi_bus_unlock(dssdev);
1788 mutex_unlock(&td->lock);
1791 static void taal_esd_work(struct work_struct *work)
1793 struct taal_data *td = container_of(work, struct taal_data,
1794 esd_work.work);
1795 struct omap_dss_device *dssdev = td->dssdev;
1796 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1797 u8 state1, state2;
1798 int r;
1800 mutex_lock(&td->lock);
1802 if (!td->enabled) {
1803 mutex_unlock(&td->lock);
1804 return;
1807 dsi_bus_lock(dssdev);
1809 r = taal_wake_up(dssdev);
1810 if (r) {
1811 dev_err(&dssdev->dev, "failed to exit ULPS\n");
1812 goto err;
1815 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
1816 if (r) {
1817 dev_err(&dssdev->dev, "failed to read Taal status\n");
1818 goto err;
1821 /* Run self diagnostics */
1822 r = taal_sleep_out(td);
1823 if (r) {
1824 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1825 goto err;
1828 r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
1829 if (r) {
1830 dev_err(&dssdev->dev, "failed to read Taal status\n");
1831 goto err;
1834 /* Each sleep out command will trigger a self diagnostic and flip
1835 * Bit6 if the test passes.
1837 if (!((state1 ^ state2) & (1 << 6))) {
1838 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1839 goto err;
1841 /* Self-diagnostics result is also shown on TE GPIO line. We need
1842 * to re-enable TE after self diagnostics */
1843 if (td->te_enabled && panel_data->use_ext_te) {
1844 r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
1845 if (r)
1846 goto err;
1849 dsi_bus_unlock(dssdev);
1851 taal_queue_esd_work(dssdev);
1853 mutex_unlock(&td->lock);
1854 return;
1855 err:
1856 dev_err(&dssdev->dev, "performing LCD reset\n");
1858 taal_panel_reset(dssdev);
1860 dsi_bus_unlock(dssdev);
1862 taal_queue_esd_work(dssdev);
1864 mutex_unlock(&td->lock);
1867 static struct omap_dss_driver taal_driver = {
1868 .probe = taal_probe,
1869 .remove = __exit_p(taal_remove),
1871 .enable = taal_enable,
1872 .disable = taal_disable,
1873 .suspend = taal_suspend,
1874 .resume = taal_resume,
1876 .update = taal_update,
1877 .sync = taal_sync,
1879 .get_resolution = taal_get_resolution,
1880 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1882 .enable_te = taal_enable_te,
1883 .get_te = taal_get_te,
1885 .set_rotate = taal_rotate,
1886 .get_rotate = taal_get_rotate,
1887 .set_mirror = taal_mirror,
1888 .get_mirror = taal_get_mirror,
1889 .run_test = taal_run_test,
1890 .memory_read = taal_memory_read,
1892 .get_timings = taal_get_timings,
1894 .driver = {
1895 .name = "taal",
1896 .owner = THIS_MODULE,
1900 static int __init taal_init(void)
1902 omap_dss_register_driver(&taal_driver);
1904 return 0;
1907 static void __exit taal_exit(void)
1909 omap_dss_unregister_driver(&taal_driver);
1912 module_init(taal_init);
1913 module_exit(taal_exit);
1915 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1916 MODULE_DESCRIPTION("Taal Driver");
1917 MODULE_LICENSE("GPL");