blob: abdfdd81001fda87120cc2e45ecf981a6981a116 [file] [log] [blame]
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001/*
2 * Taal DSI command mode panel
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
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.
10 *
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.
15 *
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/>.
18 */
19
20/*#define DEBUG*/
21
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>
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +020031#include <linux/workqueue.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +030033#include <linux/regulator/consumer.h>
Tomi Valkeinena3201a02010-03-03 14:31:45 +020034#include <linux/mutex.h>
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +020035
36#include <plat/display.h>
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +030037#include <plat/nokia-dsi-panel.h>
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +020038
39/* DSI Virtual channel. Hardcoded for now. */
40#define TCH 0
41
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
65
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +020066#define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000)
67
Jani Nikula7ae2fb12010-04-13 10:57:52 +030068static irqreturn_t taal_te_isr(int irq, void *data);
69static void taal_te_timeout_work_callback(struct work_struct *work);
Tomi Valkeinen21df20f2010-03-02 12:13:55 +020070static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
71
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +030072struct panel_regulator {
73 struct regulator *regulator;
74 const char *name;
75 int min_uV;
76 int max_uV;
77};
78
79static void free_regulators(struct panel_regulator *regulators, int n)
80{
81 int i;
82
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);
87 }
88}
89
90static int init_regulators(struct omap_dss_device *dssdev,
91 struct panel_regulator *regulators, int n)
92{
93 int r, i, v;
94
95 for (i = 0; i < n; i++) {
96 struct regulator *reg;
97
98 reg = regulator_get(&dssdev->dev, regulators[i].name);
99 if (IS_ERR(reg)) {
100 dev_err(&dssdev->dev, "failed to get regulator %s\n",
101 regulators[i].name);
102 r = PTR_ERR(reg);
103 goto err;
104 }
105
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);
111 if (r) {
112 dev_err(&dssdev->dev,
113 "failed to set regulator %s voltage\n",
114 regulators[i].name);
115 regulator_put(reg);
116 goto err;
117 }
118 }
119
120 r = regulator_enable(reg);
121 if (r) {
122 dev_err(&dssdev->dev, "failed to enable regulator %s\n",
123 regulators[i].name);
124 regulator_put(reg);
125 goto err;
126 }
127
128 regulators[i].regulator = reg;
129 }
130
131 return 0;
132
133err:
134 free_regulators(regulators, i);
135
136 return r;
137}
138
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300139/**
140 * struct panel_config - panel configuration
141 * @name: panel name
142 * @type: panel type
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
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +0300146 * @regulators: array of panel regulators
147 * @num_regulators: number of regulators in the array
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300148 */
149struct panel_config {
150 const char *name;
151 int type;
152
153 struct omap_video_timings timings;
154
155 struct {
156 unsigned int sleep_in;
157 unsigned int sleep_out;
158 unsigned int hw_reset;
159 unsigned int enable_te;
160 } sleep;
161
162 struct {
163 unsigned int high;
164 unsigned int low;
165 } reset_sequence;
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +0300166
167 struct panel_regulator *regulators;
168 int num_regulators;
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300169};
170
171enum {
172 PANEL_TAAL,
173};
174
175static struct panel_config panel_configs[] = {
176 {
177 .name = "taal",
178 .type = PANEL_TAAL,
179 .timings = {
180 .x_res = 864,
181 .y_res = 480,
182 },
183 .sleep = {
184 .sleep_in = 5,
185 .sleep_out = 5,
186 .hw_reset = 5,
187 .enable_te = 100, /* possible panel bug */
188 },
189 .reset_sequence = {
190 .high = 10,
191 .low = 10,
192 },
193 },
194};
195
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200196struct taal_data {
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200197 struct mutex lock;
198
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200199 struct backlight_device *bldev;
200
201 unsigned long hw_guard_end; /* next value of jiffies when we can
202 * issue the next sleep in/out command
203 */
204 unsigned long hw_guard_wait; /* max guard time in jiffies */
205
206 struct omap_dss_device *dssdev;
207
208 bool enabled;
209 u8 rotate;
210 bool mirror;
211
212 bool te_enabled;
Jani Nikula7ae2fb12010-04-13 10:57:52 +0300213
214 atomic_t do_update;
215 struct {
216 u16 x;
217 u16 y;
218 u16 w;
219 u16 h;
220 } update_region;
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530221 int channel;
222
Jani Nikula7ae2fb12010-04-13 10:57:52 +0300223 struct delayed_work te_timeout_work;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200224
225 bool use_dsi_bl;
226
227 bool cabc_broken;
228 unsigned cabc_mode;
229
230 bool intro_printed;
231
232 struct workqueue_struct *esd_wq;
233 struct delayed_work esd_work;
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300234
235 struct panel_config *panel_config;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200236};
237
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300238static inline struct nokia_dsi_panel_data
239*get_panel_data(const struct omap_dss_device *dssdev)
240{
241 return (struct nokia_dsi_panel_data *) dssdev->data;
242}
243
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200244static void taal_esd_work(struct work_struct *work);
245
246static void hw_guard_start(struct taal_data *td, int guard_msec)
247{
248 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
249 td->hw_guard_end = jiffies + td->hw_guard_wait;
250}
251
252static void hw_guard_wait(struct taal_data *td)
253{
254 unsigned long wait = td->hw_guard_end - jiffies;
255
256 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
257 set_current_state(TASK_UNINTERRUPTIBLE);
258 schedule_timeout(wait);
259 }
260}
261
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530262static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200263{
264 int r;
265 u8 buf[1];
266
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530267 r = dsi_vc_dcs_read(td->channel, dcs_cmd, buf, 1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200268
269 if (r < 0)
270 return r;
271
272 *data = buf[0];
273
274 return 0;
275}
276
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530277static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200278{
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530279 return dsi_vc_dcs_write(td->channel, &dcs_cmd, 1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200280}
281
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530282static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200283{
284 u8 buf[2];
285 buf[0] = dcs_cmd;
286 buf[1] = param;
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530287 return dsi_vc_dcs_write(td->channel, buf, 2);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200288}
289
290static int taal_sleep_in(struct taal_data *td)
291
292{
293 u8 cmd;
294 int r;
295
296 hw_guard_wait(td);
297
298 cmd = DCS_SLEEP_IN;
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530299 r = dsi_vc_dcs_write_nosync(td->channel, &cmd, 1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200300 if (r)
301 return r;
302
303 hw_guard_start(td, 120);
304
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300305 if (td->panel_config->sleep.sleep_in)
306 msleep(td->panel_config->sleep.sleep_in);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200307
308 return 0;
309}
310
311static int taal_sleep_out(struct taal_data *td)
312{
313 int r;
314
315 hw_guard_wait(td);
316
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530317 r = taal_dcs_write_0(td, DCS_SLEEP_OUT);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200318 if (r)
319 return r;
320
321 hw_guard_start(td, 120);
322
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300323 if (td->panel_config->sleep.sleep_out)
324 msleep(td->panel_config->sleep.sleep_out);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200325
326 return 0;
327}
328
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530329static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200330{
331 int r;
332
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530333 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200334 if (r)
335 return r;
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530336 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200337 if (r)
338 return r;
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530339 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200340 if (r)
341 return r;
342
343 return 0;
344}
345
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530346static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200347{
348 int r;
349 u8 mode;
350 int b5, b6, b7;
351
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530352 r = taal_dcs_read_1(td, DCS_READ_MADCTL, &mode);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200353 if (r)
354 return r;
355
356 switch (rotate) {
357 default:
358 case 0:
359 b7 = 0;
360 b6 = 0;
361 b5 = 0;
362 break;
363 case 1:
364 b7 = 0;
365 b6 = 1;
366 b5 = 1;
367 break;
368 case 2:
369 b7 = 1;
370 b6 = 1;
371 b5 = 0;
372 break;
373 case 3:
374 b7 = 1;
375 b6 = 0;
376 b5 = 1;
377 break;
378 }
379
380 if (mirror)
381 b6 = !b6;
382
383 mode &= ~((1<<7) | (1<<6) | (1<<5));
384 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
385
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530386 return taal_dcs_write_1(td, DCS_MEM_ACC_CTRL, mode);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200387}
388
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530389static int taal_set_update_window(struct taal_data *td,
390 u16 x, u16 y, u16 w, u16 h)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200391{
392 int r;
393 u16 x1 = x;
394 u16 x2 = x + w - 1;
395 u16 y1 = y;
396 u16 y2 = y + h - 1;
397
398 u8 buf[5];
399 buf[0] = DCS_COLUMN_ADDR;
400 buf[1] = (x1 >> 8) & 0xff;
401 buf[2] = (x1 >> 0) & 0xff;
402 buf[3] = (x2 >> 8) & 0xff;
403 buf[4] = (x2 >> 0) & 0xff;
404
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530405 r = dsi_vc_dcs_write_nosync(td->channel, buf, sizeof(buf));
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200406 if (r)
407 return r;
408
409 buf[0] = DCS_PAGE_ADDR;
410 buf[1] = (y1 >> 8) & 0xff;
411 buf[2] = (y1 >> 0) & 0xff;
412 buf[3] = (y2 >> 8) & 0xff;
413 buf[4] = (y2 >> 0) & 0xff;
414
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530415 r = dsi_vc_dcs_write_nosync(td->channel, buf, sizeof(buf));
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200416 if (r)
417 return r;
418
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530419 dsi_vc_send_bta_sync(td->channel);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200420
421 return r;
422}
423
424static int taal_bl_update_status(struct backlight_device *dev)
425{
426 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
427 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300428 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200429 int r;
430 int level;
431
432 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
433 dev->props.power == FB_BLANK_UNBLANK)
434 level = dev->props.brightness;
435 else
436 level = 0;
437
438 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
439
Tomi Valkeinen1cbc8702010-04-15 16:41:07 +0300440 mutex_lock(&td->lock);
441
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200442 if (td->use_dsi_bl) {
443 if (td->enabled) {
444 dsi_bus_lock();
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530445 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200446 dsi_bus_unlock();
Tomi Valkeinen1cbc8702010-04-15 16:41:07 +0300447 } else {
448 r = 0;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200449 }
450 } else {
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300451 if (!panel_data->set_backlight)
Tomi Valkeinen1cbc8702010-04-15 16:41:07 +0300452 r = -EINVAL;
453 else
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300454 r = panel_data->set_backlight(dssdev, level);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200455 }
456
Tomi Valkeinen1cbc8702010-04-15 16:41:07 +0300457 mutex_unlock(&td->lock);
458
459 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200460}
461
462static int taal_bl_get_intensity(struct backlight_device *dev)
463{
464 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
465 dev->props.power == FB_BLANK_UNBLANK)
466 return dev->props.brightness;
467
468 return 0;
469}
470
Lionel Debrouxacc24722010-11-16 14:14:02 +0100471static const struct backlight_ops taal_bl_ops = {
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200472 .get_brightness = taal_bl_get_intensity,
473 .update_status = taal_bl_update_status,
474};
475
476static void taal_get_timings(struct omap_dss_device *dssdev,
477 struct omap_video_timings *timings)
478{
479 *timings = dssdev->panel.timings;
480}
481
482static void taal_get_resolution(struct omap_dss_device *dssdev,
483 u16 *xres, u16 *yres)
484{
485 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
486
487 if (td->rotate == 0 || td->rotate == 2) {
488 *xres = dssdev->panel.timings.x_res;
489 *yres = dssdev->panel.timings.y_res;
490 } else {
491 *yres = dssdev->panel.timings.x_res;
492 *xres = dssdev->panel.timings.y_res;
493 }
494}
495
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200496static ssize_t taal_num_errors_show(struct device *dev,
497 struct device_attribute *attr, char *buf)
498{
499 struct omap_dss_device *dssdev = to_dss_device(dev);
500 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
501 u8 errors;
502 int r;
503
Jani Nikula6b316712010-04-28 11:15:18 +0300504 mutex_lock(&td->lock);
505
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200506 if (td->enabled) {
507 dsi_bus_lock();
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530508 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200509 dsi_bus_unlock();
510 } else {
511 r = -ENODEV;
512 }
513
Jani Nikula6b316712010-04-28 11:15:18 +0300514 mutex_unlock(&td->lock);
515
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200516 if (r)
517 return r;
518
519 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
520}
521
522static ssize_t taal_hw_revision_show(struct device *dev,
523 struct device_attribute *attr, char *buf)
524{
525 struct omap_dss_device *dssdev = to_dss_device(dev);
526 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
527 u8 id1, id2, id3;
528 int r;
529
Jani Nikula6b316712010-04-28 11:15:18 +0300530 mutex_lock(&td->lock);
531
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200532 if (td->enabled) {
533 dsi_bus_lock();
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530534 r = taal_get_id(td, &id1, &id2, &id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200535 dsi_bus_unlock();
536 } else {
537 r = -ENODEV;
538 }
539
Jani Nikula6b316712010-04-28 11:15:18 +0300540 mutex_unlock(&td->lock);
541
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200542 if (r)
543 return r;
544
545 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
546}
547
548static const char *cabc_modes[] = {
549 "off", /* used also always when CABC is not supported */
550 "ui",
551 "still-image",
552 "moving-image",
553};
554
555static ssize_t show_cabc_mode(struct device *dev,
556 struct device_attribute *attr,
557 char *buf)
558{
559 struct omap_dss_device *dssdev = to_dss_device(dev);
560 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
561 const char *mode_str;
562 int mode;
563 int len;
564
565 mode = td->cabc_mode;
566
567 mode_str = "unknown";
568 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
569 mode_str = cabc_modes[mode];
570 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
571
572 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
573}
574
575static ssize_t store_cabc_mode(struct device *dev,
576 struct device_attribute *attr,
577 const char *buf, size_t count)
578{
579 struct omap_dss_device *dssdev = to_dss_device(dev);
580 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
581 int i;
582
583 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
584 if (sysfs_streq(cabc_modes[i], buf))
585 break;
586 }
587
588 if (i == ARRAY_SIZE(cabc_modes))
589 return -EINVAL;
590
Jani Nikula6b316712010-04-28 11:15:18 +0300591 mutex_lock(&td->lock);
592
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200593 if (td->enabled) {
594 dsi_bus_lock();
595 if (!td->cabc_broken)
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530596 taal_dcs_write_1(td, DCS_WRITE_CABC, i);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200597 dsi_bus_unlock();
598 }
599
600 td->cabc_mode = i;
601
Jani Nikula6b316712010-04-28 11:15:18 +0300602 mutex_unlock(&td->lock);
603
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200604 return count;
605}
606
607static ssize_t show_cabc_available_modes(struct device *dev,
608 struct device_attribute *attr,
609 char *buf)
610{
611 int len;
612 int i;
613
614 for (i = 0, len = 0;
615 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
616 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
617 i ? " " : "", cabc_modes[i],
618 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
619
620 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
621}
622
623static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
624static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
625static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
626 show_cabc_mode, store_cabc_mode);
627static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
628 show_cabc_available_modes, NULL);
629
630static struct attribute *taal_attrs[] = {
631 &dev_attr_num_dsi_errors.attr,
632 &dev_attr_hw_revision.attr,
633 &dev_attr_cabc_mode.attr,
634 &dev_attr_cabc_available_modes.attr,
635 NULL,
636};
637
638static struct attribute_group taal_attr_group = {
639 .attrs = taal_attrs,
640};
641
Jani Nikula006db7b2010-04-09 12:25:59 +0300642static void taal_hw_reset(struct omap_dss_device *dssdev)
643{
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300644 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300645 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
646
647 if (panel_data->reset_gpio == -1)
Jani Nikula006db7b2010-04-09 12:25:59 +0300648 return;
649
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300650 gpio_set_value(panel_data->reset_gpio, 1);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300651 if (td->panel_config->reset_sequence.high)
652 udelay(td->panel_config->reset_sequence.high);
Jani Nikula006db7b2010-04-09 12:25:59 +0300653 /* reset the panel */
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300654 gpio_set_value(panel_data->reset_gpio, 0);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300655 /* assert reset */
656 if (td->panel_config->reset_sequence.low)
657 udelay(td->panel_config->reset_sequence.low);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300658 gpio_set_value(panel_data->reset_gpio, 1);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300659 /* wait after releasing reset */
660 if (td->panel_config->sleep.hw_reset)
661 msleep(td->panel_config->sleep.hw_reset);
Jani Nikula006db7b2010-04-09 12:25:59 +0300662}
663
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200664static int taal_probe(struct omap_dss_device *dssdev)
665{
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500666 struct backlight_properties props;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200667 struct taal_data *td;
668 struct backlight_device *bldev;
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300669 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300670 struct panel_config *panel_config = NULL;
671 int r, i;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200672
673 dev_dbg(&dssdev->dev, "probe\n");
674
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300675 if (!panel_data || !panel_data->name) {
676 r = -EINVAL;
677 goto err;
678 }
679
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300680 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
681 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
682 panel_config = &panel_configs[i];
683 break;
684 }
685 }
686
687 if (!panel_config) {
688 r = -EINVAL;
689 goto err;
690 }
691
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200692 dssdev->panel.config = OMAP_DSS_LCD_TFT;
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300693 dssdev->panel.timings = panel_config->timings;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200694 dssdev->ctrl.pixel_size = 24;
695
696 td = kzalloc(sizeof(*td), GFP_KERNEL);
697 if (!td) {
698 r = -ENOMEM;
Jani Nikulad2b65782010-04-15 12:24:36 +0300699 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200700 }
701 td->dssdev = dssdev;
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300702 td->panel_config = panel_config;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200703
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200704 mutex_init(&td->lock);
705
Jani Nikula7ae2fb12010-04-13 10:57:52 +0300706 atomic_set(&td->do_update, 0);
707
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +0300708 r = init_regulators(dssdev, panel_config->regulators,
709 panel_config->num_regulators);
710 if (r)
711 goto err_reg;
712
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200713 td->esd_wq = create_singlethread_workqueue("taal_esd");
714 if (td->esd_wq == NULL) {
715 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
716 r = -ENOMEM;
Jani Nikulad2b65782010-04-15 12:24:36 +0300717 goto err_wq;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200718 }
719 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
720
721 dev_set_drvdata(&dssdev->dev, td);
722
Jani Nikula006db7b2010-04-09 12:25:59 +0300723 taal_hw_reset(dssdev);
724
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200725 /* if no platform set_backlight() defined, presume DSI backlight
726 * control */
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500727 memset(&props, 0, sizeof(struct backlight_properties));
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300728 if (!panel_data->set_backlight)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200729 td->use_dsi_bl = true;
730
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500731 if (td->use_dsi_bl)
732 props.max_brightness = 255;
733 else
734 props.max_brightness = 127;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200735 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500736 &taal_bl_ops, &props);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200737 if (IS_ERR(bldev)) {
738 r = PTR_ERR(bldev);
Jani Nikulad2b65782010-04-15 12:24:36 +0300739 goto err_bl;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200740 }
741
742 td->bldev = bldev;
743
744 bldev->props.fb_blank = FB_BLANK_UNBLANK;
745 bldev->props.power = FB_BLANK_UNBLANK;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500746 if (td->use_dsi_bl)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200747 bldev->props.brightness = 255;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500748 else
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200749 bldev->props.brightness = 127;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200750
751 taal_bl_update_status(bldev);
752
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300753 if (panel_data->use_ext_te) {
754 int gpio = panel_data->ext_te_gpio;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200755
756 r = gpio_request(gpio, "taal irq");
757 if (r) {
758 dev_err(&dssdev->dev, "GPIO request failed\n");
Jani Nikulad2b65782010-04-15 12:24:36 +0300759 goto err_gpio;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200760 }
761
762 gpio_direction_input(gpio);
763
764 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
765 IRQF_DISABLED | IRQF_TRIGGER_RISING,
766 "taal vsync", dssdev);
767
768 if (r) {
769 dev_err(&dssdev->dev, "IRQ request failed\n");
770 gpio_free(gpio);
Jani Nikulad2b65782010-04-15 12:24:36 +0300771 goto err_irq;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200772 }
773
Jani Nikula7ae2fb12010-04-13 10:57:52 +0300774 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
775 taal_te_timeout_work_callback);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200776
Jani Nikula7ae2fb12010-04-13 10:57:52 +0300777 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200778 }
779
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530780 r = omap_dsi_request_vc(dssdev, &td->channel);
781 if (r) {
782 dev_err(&dssdev->dev, "failed to get virtual channel\n");
783 goto err_req_vc;
784 }
785
786 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
787 if (r) {
788 dev_err(&dssdev->dev, "failed to set VC_ID\n");
789 goto err_vc_id;
790 }
791
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200792 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
793 if (r) {
794 dev_err(&dssdev->dev, "failed to create sysfs files\n");
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530795 goto err_vc_id;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200796 }
797
798 return 0;
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530799
800err_vc_id:
801 omap_dsi_release_vc(dssdev, td->channel);
802err_req_vc:
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300803 if (panel_data->use_ext_te)
804 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
Jani Nikulad2b65782010-04-15 12:24:36 +0300805err_irq:
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300806 if (panel_data->use_ext_te)
807 gpio_free(panel_data->ext_te_gpio);
Jani Nikulad2b65782010-04-15 12:24:36 +0300808err_gpio:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200809 backlight_device_unregister(bldev);
Jani Nikulad2b65782010-04-15 12:24:36 +0300810err_bl:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200811 destroy_workqueue(td->esd_wq);
Jani Nikulad2b65782010-04-15 12:24:36 +0300812err_wq:
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +0300813 free_regulators(panel_config->regulators, panel_config->num_regulators);
814err_reg:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200815 kfree(td);
Jani Nikulad2b65782010-04-15 12:24:36 +0300816err:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200817 return r;
818}
819
820static void taal_remove(struct omap_dss_device *dssdev)
821{
822 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300823 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200824 struct backlight_device *bldev;
825
826 dev_dbg(&dssdev->dev, "remove\n");
827
828 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530829 omap_dsi_release_vc(dssdev, td->channel);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200830
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300831 if (panel_data->use_ext_te) {
832 int gpio = panel_data->ext_te_gpio;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200833 free_irq(gpio_to_irq(gpio), dssdev);
834 gpio_free(gpio);
835 }
836
837 bldev = td->bldev;
838 bldev->props.power = FB_BLANK_POWERDOWN;
839 taal_bl_update_status(bldev);
840 backlight_device_unregister(bldev);
841
Jani Nikula4571a022010-04-12 10:23:46 +0300842 cancel_delayed_work(&td->esd_work);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200843 destroy_workqueue(td->esd_wq);
844
Jani Nikula006db7b2010-04-09 12:25:59 +0300845 /* reset, to be sure that the panel is in a valid state */
846 taal_hw_reset(dssdev);
847
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +0300848 free_regulators(td->panel_config->regulators,
849 td->panel_config->num_regulators);
850
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200851 kfree(td);
852}
853
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200854static int taal_power_on(struct omap_dss_device *dssdev)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200855{
856 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
857 u8 id1, id2, id3;
858 int r;
859
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200860 r = omapdss_dsi_display_enable(dssdev);
861 if (r) {
862 dev_err(&dssdev->dev, "failed to enable DSI\n");
863 goto err0;
864 }
865
Jani Nikula006db7b2010-04-09 12:25:59 +0300866 taal_hw_reset(dssdev);
867
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530868 omapdss_dsi_vc_enable_hs(td->channel, false);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200869
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200870 r = taal_sleep_out(td);
871 if (r)
872 goto err;
873
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530874 r = taal_get_id(td, &id1, &id2, &id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200875 if (r)
876 goto err;
877
Jani Nikula1e8943d2010-04-15 17:07:39 +0300878 /* on early Taal revisions CABC is broken */
879 if (td->panel_config->type == PANEL_TAAL &&
880 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200881 td->cabc_broken = true;
882
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530883 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300884 if (r)
885 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200886
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530887 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300888 (1<<2) | (1<<5)); /* BL | BCTRL */
889 if (r)
890 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200891
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530892 r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300893 if (r)
894 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200895
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530896 r = taal_set_addr_mode(td, td->rotate, td->mirror);
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300897 if (r)
898 goto err;
899
900 if (!td->cabc_broken) {
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530901 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300902 if (r)
903 goto err;
904 }
905
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530906 r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300907 if (r)
908 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200909
Tomi Valkeinen21df20f2010-03-02 12:13:55 +0200910 r = _taal_enable_te(dssdev, td->te_enabled);
911 if (r)
912 goto err;
913
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200914 td->enabled = 1;
915
916 if (!td->intro_printed) {
Jani Nikula0f45bdd2010-04-16 14:21:14 +0300917 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
918 td->panel_config->name, id1, id2, id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200919 if (td->cabc_broken)
920 dev_info(&dssdev->dev,
921 "old Taal version, CABC disabled\n");
922 td->intro_printed = true;
923 }
924
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530925 omapdss_dsi_vc_enable_hs(td->channel, true);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200926
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200927 return 0;
928err:
Jani Nikula006db7b2010-04-09 12:25:59 +0300929 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
930
931 taal_hw_reset(dssdev);
932
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200933 omapdss_dsi_display_disable(dssdev);
934err0:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200935 return r;
936}
937
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200938static void taal_power_off(struct omap_dss_device *dssdev)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200939{
940 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Jani Nikula006db7b2010-04-09 12:25:59 +0300941 int r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200942
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530943 r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
Jani Nikula006db7b2010-04-09 12:25:59 +0300944 if (!r) {
945 r = taal_sleep_in(td);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300946 /* HACK: wait a bit so that the message goes through */
Jani Nikula006db7b2010-04-09 12:25:59 +0300947 msleep(10);
948 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200949
Jani Nikula006db7b2010-04-09 12:25:59 +0300950 if (r) {
951 dev_err(&dssdev->dev,
952 "error disabling panel, issuing HW reset\n");
953 taal_hw_reset(dssdev);
954 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200955
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200956 omapdss_dsi_display_disable(dssdev);
957
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200958 td->enabled = 0;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200959}
960
961static int taal_enable(struct omap_dss_device *dssdev)
962{
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200963 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Jani Nikula448dfe92010-04-15 12:42:16 +0300964 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200965 int r;
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200966
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200967 dev_dbg(&dssdev->dev, "enable\n");
968
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200969 mutex_lock(&td->lock);
970
971 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
972 r = -EINVAL;
973 goto err;
974 }
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200975
Jani Nikula2c2fc152010-04-12 10:06:14 +0300976 dsi_bus_lock();
977
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200978 r = taal_power_on(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +0300979
980 dsi_bus_unlock();
981
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200982 if (r)
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200983 goto err;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200984
Jani Nikula448dfe92010-04-15 12:42:16 +0300985 if (panel_data->use_esd_check)
986 queue_delayed_work(td->esd_wq, &td->esd_work,
987 TAAL_ESD_CHECK_PERIOD);
Jani Nikula4571a022010-04-12 10:23:46 +0300988
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200989 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
990
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200991 mutex_unlock(&td->lock);
992
993 return 0;
994err:
995 dev_dbg(&dssdev->dev, "enable failed\n");
996 mutex_unlock(&td->lock);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200997 return r;
998}
999
1000static void taal_disable(struct omap_dss_device *dssdev)
1001{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001002 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1003
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001004 dev_dbg(&dssdev->dev, "disable\n");
1005
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001006 mutex_lock(&td->lock);
1007
Jani Nikula4571a022010-04-12 10:23:46 +03001008 cancel_delayed_work(&td->esd_work);
1009
Jani Nikula2c2fc152010-04-12 10:06:14 +03001010 dsi_bus_lock();
1011
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001012 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
1013 taal_power_off(dssdev);
1014
Jani Nikula2c2fc152010-04-12 10:06:14 +03001015 dsi_bus_unlock();
1016
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001017 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001018
1019 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001020}
1021
1022static int taal_suspend(struct omap_dss_device *dssdev)
1023{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001024 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1025 int r;
1026
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001027 dev_dbg(&dssdev->dev, "suspend\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001028
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001029 mutex_lock(&td->lock);
1030
1031 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1032 r = -EINVAL;
1033 goto err;
1034 }
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001035
Jani Nikula4571a022010-04-12 10:23:46 +03001036 cancel_delayed_work(&td->esd_work);
1037
Jani Nikula2c2fc152010-04-12 10:06:14 +03001038 dsi_bus_lock();
1039
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001040 taal_power_off(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001041
1042 dsi_bus_unlock();
1043
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001044 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001045
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001046 mutex_unlock(&td->lock);
1047
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001048 return 0;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001049err:
1050 mutex_unlock(&td->lock);
1051 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001052}
1053
1054static int taal_resume(struct omap_dss_device *dssdev)
1055{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001056 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Jani Nikula448dfe92010-04-15 12:42:16 +03001057 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001058 int r;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001059
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001060 dev_dbg(&dssdev->dev, "resume\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001061
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001062 mutex_lock(&td->lock);
1063
1064 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1065 r = -EINVAL;
1066 goto err;
1067 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001068
Jani Nikula2c2fc152010-04-12 10:06:14 +03001069 dsi_bus_lock();
1070
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001071 r = taal_power_on(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001072
1073 dsi_bus_unlock();
1074
Jani Nikula4571a022010-04-12 10:23:46 +03001075 if (r) {
Jani Nikulafed44b72010-04-12 10:25:21 +03001076 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Jani Nikula4571a022010-04-12 10:23:46 +03001077 } else {
Jani Nikulafed44b72010-04-12 10:25:21 +03001078 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
Jani Nikula448dfe92010-04-15 12:42:16 +03001079 if (panel_data->use_esd_check)
1080 queue_delayed_work(td->esd_wq, &td->esd_work,
1081 TAAL_ESD_CHECK_PERIOD);
Jani Nikula4571a022010-04-12 10:23:46 +03001082 }
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001083
1084 mutex_unlock(&td->lock);
1085
1086 return r;
1087err:
1088 mutex_unlock(&td->lock);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001089 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001090}
1091
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001092static void taal_framedone_cb(int err, void *data)
1093{
1094 struct omap_dss_device *dssdev = data;
1095 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1096 dsi_bus_unlock();
1097}
1098
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001099static irqreturn_t taal_te_isr(int irq, void *data)
1100{
1101 struct omap_dss_device *dssdev = data;
1102 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1103 int old;
1104 int r;
1105
1106 old = atomic_cmpxchg(&td->do_update, 1, 0);
1107
1108 if (old) {
1109 cancel_delayed_work(&td->te_timeout_work);
1110
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301111 r = omap_dsi_update(dssdev, td->channel,
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001112 td->update_region.x,
1113 td->update_region.y,
1114 td->update_region.w,
1115 td->update_region.h,
1116 taal_framedone_cb, dssdev);
1117 if (r)
1118 goto err;
1119 }
1120
1121 return IRQ_HANDLED;
1122err:
1123 dev_err(&dssdev->dev, "start update failed\n");
1124 dsi_bus_unlock();
1125 return IRQ_HANDLED;
1126}
1127
1128static void taal_te_timeout_work_callback(struct work_struct *work)
1129{
1130 struct taal_data *td = container_of(work, struct taal_data,
1131 te_timeout_work.work);
1132 struct omap_dss_device *dssdev = td->dssdev;
1133
1134 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1135
1136 atomic_set(&td->do_update, 0);
1137 dsi_bus_unlock();
1138}
1139
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001140static int taal_update(struct omap_dss_device *dssdev,
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001141 u16 x, u16 y, u16 w, u16 h)
1142{
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001143 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001144 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001145 int r;
1146
1147 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1148
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001149 mutex_lock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001150 dsi_bus_lock();
1151
1152 if (!td->enabled) {
1153 r = 0;
1154 goto err;
1155 }
1156
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03001157 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001158 if (r)
1159 goto err;
1160
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301161 r = taal_set_update_window(td, x, y, w, h);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001162 if (r)
1163 goto err;
1164
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001165 if (td->te_enabled && panel_data->use_ext_te) {
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001166 td->update_region.x = x;
1167 td->update_region.y = y;
1168 td->update_region.w = w;
1169 td->update_region.h = h;
1170 barrier();
1171 schedule_delayed_work(&td->te_timeout_work,
1172 msecs_to_jiffies(250));
1173 atomic_set(&td->do_update, 1);
1174 } else {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301175 r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001176 taal_framedone_cb, dssdev);
1177 if (r)
1178 goto err;
1179 }
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001180
1181 /* note: no bus_unlock here. unlock is in framedone_cb */
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001182 mutex_unlock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001183 return 0;
1184err:
1185 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001186 mutex_unlock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001187 return r;
1188}
1189
1190static int taal_sync(struct omap_dss_device *dssdev)
1191{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001192 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1193
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001194 dev_dbg(&dssdev->dev, "sync\n");
1195
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001196 mutex_lock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001197 dsi_bus_lock();
1198 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001199 mutex_unlock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001200
1201 dev_dbg(&dssdev->dev, "sync done\n");
1202
1203 return 0;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001204}
1205
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001206static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001207{
Jani Nikulae7f6c3f2010-04-15 12:55:38 +03001208 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001209 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001210 int r;
1211
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001212 if (enable)
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301213 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001214 else
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301215 r = taal_dcs_write_0(td, DCS_TEAR_OFF);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001216
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001217 if (!panel_data->use_ext_te)
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001218 omapdss_dsi_enable_te(dssdev, enable);
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001219
Jani Nikulae7f6c3f2010-04-15 12:55:38 +03001220 if (td->panel_config->sleep.enable_te)
1221 msleep(td->panel_config->sleep.enable_te);
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001222
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001223 return r;
1224}
1225
1226static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1227{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001228 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001229 int r;
1230
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001231 mutex_lock(&td->lock);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001232
1233 if (td->te_enabled == enable)
1234 goto end;
1235
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001236 dsi_bus_lock();
1237
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001238 if (td->enabled) {
1239 r = _taal_enable_te(dssdev, enable);
1240 if (r)
1241 goto err;
1242 }
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001243
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001244 td->te_enabled = enable;
1245
1246 dsi_bus_unlock();
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001247end:
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001248 mutex_unlock(&td->lock);
1249
1250 return 0;
1251err:
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001252 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001253 mutex_unlock(&td->lock);
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001254
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001255 return r;
1256}
1257
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001258static int taal_get_te(struct omap_dss_device *dssdev)
1259{
1260 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001261 int r;
1262
1263 mutex_lock(&td->lock);
1264 r = td->te_enabled;
1265 mutex_unlock(&td->lock);
1266
1267 return r;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001268}
1269
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001270static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1271{
1272 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1273 int r;
1274
1275 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1276
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001277 mutex_lock(&td->lock);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001278
1279 if (td->rotate == rotate)
1280 goto end;
1281
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001282 dsi_bus_lock();
1283
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001284 if (td->enabled) {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301285 r = taal_set_addr_mode(td, rotate, td->mirror);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001286 if (r)
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001287 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001288 }
1289
1290 td->rotate = rotate;
1291
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001292 dsi_bus_unlock();
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001293end:
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001294 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001295 return 0;
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001296err:
1297 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001298 mutex_unlock(&td->lock);
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001299 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001300}
1301
1302static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1303{
1304 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001305 int r;
1306
1307 mutex_lock(&td->lock);
1308 r = td->rotate;
1309 mutex_unlock(&td->lock);
1310
1311 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001312}
1313
1314static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1315{
1316 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1317 int r;
1318
1319 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1320
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001321 mutex_lock(&td->lock);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001322
1323 if (td->mirror == enable)
1324 goto end;
1325
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001326 dsi_bus_lock();
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001327 if (td->enabled) {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301328 r = taal_set_addr_mode(td, td->rotate, enable);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001329 if (r)
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001330 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001331 }
1332
1333 td->mirror = enable;
1334
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001335 dsi_bus_unlock();
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001336end:
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001337 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001338 return 0;
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001339err:
1340 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001341 mutex_unlock(&td->lock);
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001342 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001343}
1344
1345static bool taal_get_mirror(struct omap_dss_device *dssdev)
1346{
1347 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001348 int r;
1349
1350 mutex_lock(&td->lock);
1351 r = td->mirror;
1352 mutex_unlock(&td->lock);
1353
1354 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001355}
1356
1357static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1358{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001359 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001360 u8 id1, id2, id3;
1361 int r;
1362
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001363 mutex_lock(&td->lock);
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001364
1365 if (!td->enabled) {
1366 r = -ENODEV;
1367 goto err1;
1368 }
1369
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +02001370 dsi_bus_lock();
1371
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301372 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001373 if (r)
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001374 goto err2;
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301375 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001376 if (r)
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001377 goto err2;
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301378 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001379 if (r)
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001380 goto err2;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001381
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +02001382 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001383 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001384 return 0;
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001385err2:
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +02001386 dsi_bus_unlock();
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001387err1:
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001388 mutex_unlock(&td->lock);
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +02001389 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001390}
1391
1392static int taal_memory_read(struct omap_dss_device *dssdev,
1393 void *buf, size_t size,
1394 u16 x, u16 y, u16 w, u16 h)
1395{
1396 int r;
1397 int first = 1;
1398 int plen;
1399 unsigned buf_used = 0;
Tomi Valkeinenc75d9462010-01-08 16:56:44 +02001400 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1401
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001402 if (size < w * h * 3)
1403 return -ENOMEM;
1404
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001405 mutex_lock(&td->lock);
1406
1407 if (!td->enabled) {
1408 r = -ENODEV;
1409 goto err1;
1410 }
1411
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001412 size = min(w * h * 3,
1413 dssdev->panel.timings.x_res *
1414 dssdev->panel.timings.y_res * 3);
1415
Tomi Valkeinenc75d9462010-01-08 16:56:44 +02001416 dsi_bus_lock();
1417
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001418 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1419 * use short packets. plen 32 works, but bigger packets seem to cause
1420 * an error. */
1421 if (size % 2)
1422 plen = 1;
1423 else
1424 plen = 2;
1425
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301426 taal_set_update_window(td, x, y, w, h);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001427
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301428 r = dsi_vc_set_max_rx_packet_size(td->channel, plen);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001429 if (r)
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001430 goto err2;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001431
1432 while (buf_used < size) {
1433 u8 dcs_cmd = first ? 0x2e : 0x3e;
1434 first = 0;
1435
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301436 r = dsi_vc_dcs_read(td->channel, dcs_cmd,
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001437 buf + buf_used, size - buf_used);
1438
1439 if (r < 0) {
1440 dev_err(&dssdev->dev, "read error\n");
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001441 goto err3;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001442 }
1443
1444 buf_used += r;
1445
1446 if (r < plen) {
1447 dev_err(&dssdev->dev, "short read\n");
1448 break;
1449 }
1450
1451 if (signal_pending(current)) {
1452 dev_err(&dssdev->dev, "signal pending, "
1453 "aborting memory read\n");
1454 r = -ERESTARTSYS;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001455 goto err3;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001456 }
1457 }
1458
1459 r = buf_used;
1460
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001461err3:
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301462 dsi_vc_set_max_rx_packet_size(td->channel, 1);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001463err2:
Tomi Valkeinenc75d9462010-01-08 16:56:44 +02001464 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001465err1:
1466 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001467 return r;
1468}
1469
1470static void taal_esd_work(struct work_struct *work)
1471{
1472 struct taal_data *td = container_of(work, struct taal_data,
1473 esd_work.work);
1474 struct omap_dss_device *dssdev = td->dssdev;
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001475 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001476 u8 state1, state2;
1477 int r;
1478
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001479 mutex_lock(&td->lock);
1480
1481 if (!td->enabled) {
1482 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001483 return;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001484 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001485
1486 dsi_bus_lock();
1487
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301488 r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001489 if (r) {
1490 dev_err(&dssdev->dev, "failed to read Taal status\n");
1491 goto err;
1492 }
1493
1494 /* Run self diagnostics */
1495 r = taal_sleep_out(td);
1496 if (r) {
1497 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1498 goto err;
1499 }
1500
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301501 r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001502 if (r) {
1503 dev_err(&dssdev->dev, "failed to read Taal status\n");
1504 goto err;
1505 }
1506
1507 /* Each sleep out command will trigger a self diagnostic and flip
1508 * Bit6 if the test passes.
1509 */
1510 if (!((state1 ^ state2) & (1 << 6))) {
1511 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1512 goto err;
1513 }
1514 /* Self-diagnostics result is also shown on TE GPIO line. We need
1515 * to re-enable TE after self diagnostics */
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001516 if (td->te_enabled && panel_data->use_ext_te) {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301517 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
Tomi Valkeinen1189b7f2010-03-01 13:52:10 +02001518 if (r)
1519 goto err;
1520 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001521
1522 dsi_bus_unlock();
1523
1524 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1525
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001526 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001527 return;
1528err:
1529 dev_err(&dssdev->dev, "performing LCD reset\n");
1530
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001531 taal_power_off(dssdev);
Jani Nikula006db7b2010-04-09 12:25:59 +03001532 taal_hw_reset(dssdev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001533 taal_power_on(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001534
1535 dsi_bus_unlock();
1536
1537 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001538
1539 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001540}
1541
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001542static int taal_set_update_mode(struct omap_dss_device *dssdev,
1543 enum omap_dss_update_mode mode)
1544{
1545 if (mode != OMAP_DSS_UPDATE_MANUAL)
1546 return -EINVAL;
1547 return 0;
1548}
1549
1550static enum omap_dss_update_mode taal_get_update_mode(
1551 struct omap_dss_device *dssdev)
1552{
1553 return OMAP_DSS_UPDATE_MANUAL;
1554}
1555
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001556static struct omap_dss_driver taal_driver = {
1557 .probe = taal_probe,
1558 .remove = taal_remove,
1559
1560 .enable = taal_enable,
1561 .disable = taal_disable,
1562 .suspend = taal_suspend,
1563 .resume = taal_resume,
1564
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001565 .set_update_mode = taal_set_update_mode,
1566 .get_update_mode = taal_get_update_mode,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001567
1568 .update = taal_update,
1569 .sync = taal_sync,
1570
Tomi Valkeinen96adcec2010-01-11 13:54:33 +02001571 .get_resolution = taal_get_resolution,
Tomi Valkeinena2699502010-01-11 14:33:40 +02001572 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1573
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001574 .enable_te = taal_enable_te,
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001575 .get_te = taal_get_te,
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001576
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001577 .set_rotate = taal_rotate,
1578 .get_rotate = taal_get_rotate,
1579 .set_mirror = taal_mirror,
1580 .get_mirror = taal_get_mirror,
1581 .run_test = taal_run_test,
1582 .memory_read = taal_memory_read,
1583
Tomi Valkeinen69b20482010-01-20 12:11:25 +02001584 .get_timings = taal_get_timings,
1585
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001586 .driver = {
1587 .name = "taal",
1588 .owner = THIS_MODULE,
1589 },
1590};
1591
1592static int __init taal_init(void)
1593{
1594 omap_dss_register_driver(&taal_driver);
1595
1596 return 0;
1597}
1598
1599static void __exit taal_exit(void)
1600{
1601 omap_dss_unregister_driver(&taal_driver);
1602}
1603
1604module_init(taal_init);
1605module_exit(taal_exit);
1606
1607MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1608MODULE_DESCRIPTION("Taal Driver");
1609MODULE_LICENSE("GPL");