blob: 44d73f779ebed5fa515852a827ca155bcad512ce [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
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030036#include <video/omapdss.h>
Tomi Valkeinen4e9f99d2011-05-11 14:10:07 +030037#include <video/omap-panel-nokia-dsi.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;
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700735
736 props.type = BACKLIGHT_RAW;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200737 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500738 &taal_bl_ops, &props);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200739 if (IS_ERR(bldev)) {
740 r = PTR_ERR(bldev);
Jani Nikulad2b65782010-04-15 12:24:36 +0300741 goto err_bl;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200742 }
743
744 td->bldev = bldev;
745
746 bldev->props.fb_blank = FB_BLANK_UNBLANK;
747 bldev->props.power = FB_BLANK_UNBLANK;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500748 if (td->use_dsi_bl)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200749 bldev->props.brightness = 255;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500750 else
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200751 bldev->props.brightness = 127;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200752
753 taal_bl_update_status(bldev);
754
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300755 if (panel_data->use_ext_te) {
756 int gpio = panel_data->ext_te_gpio;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200757
758 r = gpio_request(gpio, "taal irq");
759 if (r) {
760 dev_err(&dssdev->dev, "GPIO request failed\n");
Jani Nikulad2b65782010-04-15 12:24:36 +0300761 goto err_gpio;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200762 }
763
764 gpio_direction_input(gpio);
765
766 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
767 IRQF_DISABLED | IRQF_TRIGGER_RISING,
768 "taal vsync", dssdev);
769
770 if (r) {
771 dev_err(&dssdev->dev, "IRQ request failed\n");
772 gpio_free(gpio);
Jani Nikulad2b65782010-04-15 12:24:36 +0300773 goto err_irq;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200774 }
775
Jani Nikula7ae2fb12010-04-13 10:57:52 +0300776 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
777 taal_te_timeout_work_callback);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200778
Jani Nikula7ae2fb12010-04-13 10:57:52 +0300779 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200780 }
781
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530782 r = omap_dsi_request_vc(dssdev, &td->channel);
783 if (r) {
784 dev_err(&dssdev->dev, "failed to get virtual channel\n");
785 goto err_req_vc;
786 }
787
788 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
789 if (r) {
790 dev_err(&dssdev->dev, "failed to set VC_ID\n");
791 goto err_vc_id;
792 }
793
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200794 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
795 if (r) {
796 dev_err(&dssdev->dev, "failed to create sysfs files\n");
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530797 goto err_vc_id;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200798 }
799
800 return 0;
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530801
802err_vc_id:
803 omap_dsi_release_vc(dssdev, td->channel);
804err_req_vc:
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300805 if (panel_data->use_ext_te)
806 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
Jani Nikulad2b65782010-04-15 12:24:36 +0300807err_irq:
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300808 if (panel_data->use_ext_te)
809 gpio_free(panel_data->ext_te_gpio);
Jani Nikulad2b65782010-04-15 12:24:36 +0300810err_gpio:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200811 backlight_device_unregister(bldev);
Jani Nikulad2b65782010-04-15 12:24:36 +0300812err_bl:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200813 destroy_workqueue(td->esd_wq);
Jani Nikulad2b65782010-04-15 12:24:36 +0300814err_wq:
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +0300815 free_regulators(panel_config->regulators, panel_config->num_regulators);
816err_reg:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200817 kfree(td);
Jani Nikulad2b65782010-04-15 12:24:36 +0300818err:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200819 return r;
820}
821
Tomi Valkeinen14e4d782011-03-31 12:03:51 +0300822static void __exit taal_remove(struct omap_dss_device *dssdev)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200823{
824 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300825 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200826 struct backlight_device *bldev;
827
828 dev_dbg(&dssdev->dev, "remove\n");
829
830 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530831 omap_dsi_release_vc(dssdev, td->channel);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200832
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300833 if (panel_data->use_ext_te) {
834 int gpio = panel_data->ext_te_gpio;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200835 free_irq(gpio_to_irq(gpio), dssdev);
836 gpio_free(gpio);
837 }
838
839 bldev = td->bldev;
840 bldev->props.power = FB_BLANK_POWERDOWN;
841 taal_bl_update_status(bldev);
842 backlight_device_unregister(bldev);
843
Jani Nikula4571a022010-04-12 10:23:46 +0300844 cancel_delayed_work(&td->esd_work);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200845 destroy_workqueue(td->esd_wq);
846
Jani Nikula006db7b2010-04-09 12:25:59 +0300847 /* reset, to be sure that the panel is in a valid state */
848 taal_hw_reset(dssdev);
849
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +0300850 free_regulators(td->panel_config->regulators,
851 td->panel_config->num_regulators);
852
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200853 kfree(td);
854}
855
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200856static int taal_power_on(struct omap_dss_device *dssdev)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200857{
858 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
859 u8 id1, id2, id3;
860 int r;
861
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200862 r = omapdss_dsi_display_enable(dssdev);
863 if (r) {
864 dev_err(&dssdev->dev, "failed to enable DSI\n");
865 goto err0;
866 }
867
Jani Nikula006db7b2010-04-09 12:25:59 +0300868 taal_hw_reset(dssdev);
869
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530870 omapdss_dsi_vc_enable_hs(td->channel, false);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200871
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200872 r = taal_sleep_out(td);
873 if (r)
874 goto err;
875
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530876 r = taal_get_id(td, &id1, &id2, &id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200877 if (r)
878 goto err;
879
Jani Nikula1e8943d2010-04-15 17:07:39 +0300880 /* on early Taal revisions CABC is broken */
881 if (td->panel_config->type == PANEL_TAAL &&
882 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200883 td->cabc_broken = true;
884
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530885 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300886 if (r)
887 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200888
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530889 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300890 (1<<2) | (1<<5)); /* BL | BCTRL */
891 if (r)
892 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200893
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530894 r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300895 if (r)
896 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200897
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530898 r = taal_set_addr_mode(td, td->rotate, td->mirror);
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300899 if (r)
900 goto err;
901
902 if (!td->cabc_broken) {
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530903 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300904 if (r)
905 goto err;
906 }
907
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530908 r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
Jani Nikulaf2a8b752010-04-09 14:15:12 +0300909 if (r)
910 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200911
Tomi Valkeinen21df20f2010-03-02 12:13:55 +0200912 r = _taal_enable_te(dssdev, td->te_enabled);
913 if (r)
914 goto err;
915
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200916 td->enabled = 1;
917
918 if (!td->intro_printed) {
Jani Nikula0f45bdd2010-04-16 14:21:14 +0300919 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
920 td->panel_config->name, id1, id2, id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200921 if (td->cabc_broken)
922 dev_info(&dssdev->dev,
923 "old Taal version, CABC disabled\n");
924 td->intro_printed = true;
925 }
926
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530927 omapdss_dsi_vc_enable_hs(td->channel, true);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200928
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200929 return 0;
930err:
Jani Nikula006db7b2010-04-09 12:25:59 +0300931 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
932
933 taal_hw_reset(dssdev);
934
Tomi Valkeinen22d6d672010-10-11 11:33:30 +0300935 omapdss_dsi_display_disable(dssdev, true, false);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200936err0:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200937 return r;
938}
939
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200940static void taal_power_off(struct omap_dss_device *dssdev)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200941{
942 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Jani Nikula006db7b2010-04-09 12:25:59 +0300943 int r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200944
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530945 r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
Jani Nikula006db7b2010-04-09 12:25:59 +0300946 if (!r) {
947 r = taal_sleep_in(td);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300948 /* HACK: wait a bit so that the message goes through */
Jani Nikula006db7b2010-04-09 12:25:59 +0300949 msleep(10);
950 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200951
Jani Nikula006db7b2010-04-09 12:25:59 +0300952 if (r) {
953 dev_err(&dssdev->dev,
954 "error disabling panel, issuing HW reset\n");
955 taal_hw_reset(dssdev);
956 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200957
Tomi Valkeinen22d6d672010-10-11 11:33:30 +0300958 omapdss_dsi_display_disable(dssdev, true, false);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200959
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200960 td->enabled = 0;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200961}
962
963static int taal_enable(struct omap_dss_device *dssdev)
964{
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200965 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Jani Nikula448dfe92010-04-15 12:42:16 +0300966 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200967 int r;
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200968
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200969 dev_dbg(&dssdev->dev, "enable\n");
970
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200971 mutex_lock(&td->lock);
972
973 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
974 r = -EINVAL;
975 goto err;
976 }
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200977
Jani Nikula2c2fc152010-04-12 10:06:14 +0300978 dsi_bus_lock();
979
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200980 r = taal_power_on(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +0300981
982 dsi_bus_unlock();
983
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200984 if (r)
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200985 goto err;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200986
Jani Nikula448dfe92010-04-15 12:42:16 +0300987 if (panel_data->use_esd_check)
988 queue_delayed_work(td->esd_wq, &td->esd_work,
989 TAAL_ESD_CHECK_PERIOD);
Jani Nikula4571a022010-04-12 10:23:46 +0300990
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200991 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
992
Tomi Valkeinena3201a02010-03-03 14:31:45 +0200993 mutex_unlock(&td->lock);
994
995 return 0;
996err:
997 dev_dbg(&dssdev->dev, "enable failed\n");
998 mutex_unlock(&td->lock);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200999 return r;
1000}
1001
1002static void taal_disable(struct omap_dss_device *dssdev)
1003{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001004 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1005
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001006 dev_dbg(&dssdev->dev, "disable\n");
1007
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001008 mutex_lock(&td->lock);
1009
Jani Nikula4571a022010-04-12 10:23:46 +03001010 cancel_delayed_work(&td->esd_work);
1011
Jani Nikula2c2fc152010-04-12 10:06:14 +03001012 dsi_bus_lock();
1013
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001014 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
1015 taal_power_off(dssdev);
1016
Jani Nikula2c2fc152010-04-12 10:06:14 +03001017 dsi_bus_unlock();
1018
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001019 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001020
1021 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001022}
1023
1024static int taal_suspend(struct omap_dss_device *dssdev)
1025{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001026 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1027 int r;
1028
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001029 dev_dbg(&dssdev->dev, "suspend\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001030
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001031 mutex_lock(&td->lock);
1032
1033 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1034 r = -EINVAL;
1035 goto err;
1036 }
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001037
Jani Nikula4571a022010-04-12 10:23:46 +03001038 cancel_delayed_work(&td->esd_work);
1039
Jani Nikula2c2fc152010-04-12 10:06:14 +03001040 dsi_bus_lock();
1041
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001042 taal_power_off(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001043
1044 dsi_bus_unlock();
1045
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001046 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001047
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001048 mutex_unlock(&td->lock);
1049
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001050 return 0;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001051err:
1052 mutex_unlock(&td->lock);
1053 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001054}
1055
1056static int taal_resume(struct omap_dss_device *dssdev)
1057{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001058 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Jani Nikula448dfe92010-04-15 12:42:16 +03001059 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001060 int r;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001061
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001062 dev_dbg(&dssdev->dev, "resume\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001063
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001064 mutex_lock(&td->lock);
1065
1066 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1067 r = -EINVAL;
1068 goto err;
1069 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001070
Jani Nikula2c2fc152010-04-12 10:06:14 +03001071 dsi_bus_lock();
1072
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001073 r = taal_power_on(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001074
1075 dsi_bus_unlock();
1076
Jani Nikula4571a022010-04-12 10:23:46 +03001077 if (r) {
Jani Nikulafed44b72010-04-12 10:25:21 +03001078 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Jani Nikula4571a022010-04-12 10:23:46 +03001079 } else {
Jani Nikulafed44b72010-04-12 10:25:21 +03001080 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
Jani Nikula448dfe92010-04-15 12:42:16 +03001081 if (panel_data->use_esd_check)
1082 queue_delayed_work(td->esd_wq, &td->esd_work,
1083 TAAL_ESD_CHECK_PERIOD);
Jani Nikula4571a022010-04-12 10:23:46 +03001084 }
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001085
1086 mutex_unlock(&td->lock);
1087
1088 return r;
1089err:
1090 mutex_unlock(&td->lock);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001091 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001092}
1093
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001094static void taal_framedone_cb(int err, void *data)
1095{
1096 struct omap_dss_device *dssdev = data;
1097 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
1098 dsi_bus_unlock();
1099}
1100
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001101static irqreturn_t taal_te_isr(int irq, void *data)
1102{
1103 struct omap_dss_device *dssdev = data;
1104 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1105 int old;
1106 int r;
1107
1108 old = atomic_cmpxchg(&td->do_update, 1, 0);
1109
1110 if (old) {
1111 cancel_delayed_work(&td->te_timeout_work);
1112
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301113 r = omap_dsi_update(dssdev, td->channel,
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001114 td->update_region.x,
1115 td->update_region.y,
1116 td->update_region.w,
1117 td->update_region.h,
1118 taal_framedone_cb, dssdev);
1119 if (r)
1120 goto err;
1121 }
1122
1123 return IRQ_HANDLED;
1124err:
1125 dev_err(&dssdev->dev, "start update failed\n");
1126 dsi_bus_unlock();
1127 return IRQ_HANDLED;
1128}
1129
1130static void taal_te_timeout_work_callback(struct work_struct *work)
1131{
1132 struct taal_data *td = container_of(work, struct taal_data,
1133 te_timeout_work.work);
1134 struct omap_dss_device *dssdev = td->dssdev;
1135
1136 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1137
1138 atomic_set(&td->do_update, 0);
1139 dsi_bus_unlock();
1140}
1141
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001142static int taal_update(struct omap_dss_device *dssdev,
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001143 u16 x, u16 y, u16 w, u16 h)
1144{
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001145 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001146 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001147 int r;
1148
1149 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1150
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001151 mutex_lock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001152 dsi_bus_lock();
1153
1154 if (!td->enabled) {
1155 r = 0;
1156 goto err;
1157 }
1158
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03001159 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001160 if (r)
1161 goto err;
1162
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301163 r = taal_set_update_window(td, x, y, w, h);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001164 if (r)
1165 goto err;
1166
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001167 if (td->te_enabled && panel_data->use_ext_te) {
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001168 td->update_region.x = x;
1169 td->update_region.y = y;
1170 td->update_region.w = w;
1171 td->update_region.h = h;
1172 barrier();
1173 schedule_delayed_work(&td->te_timeout_work,
1174 msecs_to_jiffies(250));
1175 atomic_set(&td->do_update, 1);
1176 } else {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301177 r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001178 taal_framedone_cb, dssdev);
1179 if (r)
1180 goto err;
1181 }
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001182
1183 /* note: no bus_unlock here. unlock is in framedone_cb */
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001184 mutex_unlock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001185 return 0;
1186err:
1187 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001188 mutex_unlock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001189 return r;
1190}
1191
1192static int taal_sync(struct omap_dss_device *dssdev)
1193{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001194 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1195
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001196 dev_dbg(&dssdev->dev, "sync\n");
1197
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001198 mutex_lock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001199 dsi_bus_lock();
1200 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001201 mutex_unlock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001202
1203 dev_dbg(&dssdev->dev, "sync done\n");
1204
1205 return 0;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001206}
1207
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001208static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001209{
Jani Nikulae7f6c3f2010-04-15 12:55:38 +03001210 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001211 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001212 int r;
1213
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001214 if (enable)
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301215 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001216 else
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301217 r = taal_dcs_write_0(td, DCS_TEAR_OFF);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001218
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001219 if (!panel_data->use_ext_te)
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001220 omapdss_dsi_enable_te(dssdev, enable);
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001221
Jani Nikulae7f6c3f2010-04-15 12:55:38 +03001222 if (td->panel_config->sleep.enable_te)
1223 msleep(td->panel_config->sleep.enable_te);
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001224
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001225 return r;
1226}
1227
1228static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1229{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001230 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001231 int r;
1232
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001233 mutex_lock(&td->lock);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001234
1235 if (td->te_enabled == enable)
1236 goto end;
1237
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001238 dsi_bus_lock();
1239
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001240 if (td->enabled) {
1241 r = _taal_enable_te(dssdev, enable);
1242 if (r)
1243 goto err;
1244 }
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001245
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001246 td->te_enabled = enable;
1247
1248 dsi_bus_unlock();
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001249end:
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001250 mutex_unlock(&td->lock);
1251
1252 return 0;
1253err:
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001254 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001255 mutex_unlock(&td->lock);
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001256
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001257 return r;
1258}
1259
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001260static int taal_get_te(struct omap_dss_device *dssdev)
1261{
1262 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001263 int r;
1264
1265 mutex_lock(&td->lock);
1266 r = td->te_enabled;
1267 mutex_unlock(&td->lock);
1268
1269 return r;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001270}
1271
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001272static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1273{
1274 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1275 int r;
1276
1277 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1278
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001279 mutex_lock(&td->lock);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001280
1281 if (td->rotate == rotate)
1282 goto end;
1283
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001284 dsi_bus_lock();
1285
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001286 if (td->enabled) {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301287 r = taal_set_addr_mode(td, rotate, td->mirror);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001288 if (r)
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001289 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001290 }
1291
1292 td->rotate = rotate;
1293
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001294 dsi_bus_unlock();
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001295end:
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001296 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001297 return 0;
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001298err:
1299 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001300 mutex_unlock(&td->lock);
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001301 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001302}
1303
1304static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1305{
1306 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001307 int r;
1308
1309 mutex_lock(&td->lock);
1310 r = td->rotate;
1311 mutex_unlock(&td->lock);
1312
1313 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001314}
1315
1316static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1317{
1318 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1319 int r;
1320
1321 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1322
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001323 mutex_lock(&td->lock);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001324
1325 if (td->mirror == enable)
1326 goto end;
1327
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001328 dsi_bus_lock();
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001329 if (td->enabled) {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301330 r = taal_set_addr_mode(td, td->rotate, enable);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001331 if (r)
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001332 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001333 }
1334
1335 td->mirror = enable;
1336
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001337 dsi_bus_unlock();
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001338end:
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001339 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001340 return 0;
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001341err:
1342 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001343 mutex_unlock(&td->lock);
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001344 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001345}
1346
1347static bool taal_get_mirror(struct omap_dss_device *dssdev)
1348{
1349 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001350 int r;
1351
1352 mutex_lock(&td->lock);
1353 r = td->mirror;
1354 mutex_unlock(&td->lock);
1355
1356 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001357}
1358
1359static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1360{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001361 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001362 u8 id1, id2, id3;
1363 int r;
1364
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001365 mutex_lock(&td->lock);
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001366
1367 if (!td->enabled) {
1368 r = -ENODEV;
1369 goto err1;
1370 }
1371
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +02001372 dsi_bus_lock();
1373
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301374 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001375 if (r)
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001376 goto err2;
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301377 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001378 if (r)
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001379 goto err2;
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301380 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001381 if (r)
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001382 goto err2;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001383
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +02001384 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001385 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001386 return 0;
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001387err2:
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +02001388 dsi_bus_unlock();
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001389err1:
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001390 mutex_unlock(&td->lock);
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +02001391 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001392}
1393
1394static int taal_memory_read(struct omap_dss_device *dssdev,
1395 void *buf, size_t size,
1396 u16 x, u16 y, u16 w, u16 h)
1397{
1398 int r;
1399 int first = 1;
1400 int plen;
1401 unsigned buf_used = 0;
Tomi Valkeinenc75d9462010-01-08 16:56:44 +02001402 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1403
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001404 if (size < w * h * 3)
1405 return -ENOMEM;
1406
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001407 mutex_lock(&td->lock);
1408
1409 if (!td->enabled) {
1410 r = -ENODEV;
1411 goto err1;
1412 }
1413
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001414 size = min(w * h * 3,
1415 dssdev->panel.timings.x_res *
1416 dssdev->panel.timings.y_res * 3);
1417
Tomi Valkeinenc75d9462010-01-08 16:56:44 +02001418 dsi_bus_lock();
1419
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001420 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1421 * use short packets. plen 32 works, but bigger packets seem to cause
1422 * an error. */
1423 if (size % 2)
1424 plen = 1;
1425 else
1426 plen = 2;
1427
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301428 taal_set_update_window(td, x, y, w, h);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001429
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301430 r = dsi_vc_set_max_rx_packet_size(td->channel, plen);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001431 if (r)
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001432 goto err2;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001433
1434 while (buf_used < size) {
1435 u8 dcs_cmd = first ? 0x2e : 0x3e;
1436 first = 0;
1437
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301438 r = dsi_vc_dcs_read(td->channel, dcs_cmd,
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001439 buf + buf_used, size - buf_used);
1440
1441 if (r < 0) {
1442 dev_err(&dssdev->dev, "read error\n");
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001443 goto err3;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001444 }
1445
1446 buf_used += r;
1447
1448 if (r < plen) {
1449 dev_err(&dssdev->dev, "short read\n");
1450 break;
1451 }
1452
1453 if (signal_pending(current)) {
1454 dev_err(&dssdev->dev, "signal pending, "
1455 "aborting memory read\n");
1456 r = -ERESTARTSYS;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001457 goto err3;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001458 }
1459 }
1460
1461 r = buf_used;
1462
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001463err3:
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301464 dsi_vc_set_max_rx_packet_size(td->channel, 1);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001465err2:
Tomi Valkeinenc75d9462010-01-08 16:56:44 +02001466 dsi_bus_unlock();
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001467err1:
1468 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001469 return r;
1470}
1471
1472static void taal_esd_work(struct work_struct *work)
1473{
1474 struct taal_data *td = container_of(work, struct taal_data,
1475 esd_work.work);
1476 struct omap_dss_device *dssdev = td->dssdev;
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001477 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001478 u8 state1, state2;
1479 int r;
1480
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001481 mutex_lock(&td->lock);
1482
1483 if (!td->enabled) {
1484 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001485 return;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001486 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001487
1488 dsi_bus_lock();
1489
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301490 r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001491 if (r) {
1492 dev_err(&dssdev->dev, "failed to read Taal status\n");
1493 goto err;
1494 }
1495
1496 /* Run self diagnostics */
1497 r = taal_sleep_out(td);
1498 if (r) {
1499 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1500 goto err;
1501 }
1502
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301503 r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001504 if (r) {
1505 dev_err(&dssdev->dev, "failed to read Taal status\n");
1506 goto err;
1507 }
1508
1509 /* Each sleep out command will trigger a self diagnostic and flip
1510 * Bit6 if the test passes.
1511 */
1512 if (!((state1 ^ state2) & (1 << 6))) {
1513 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1514 goto err;
1515 }
1516 /* Self-diagnostics result is also shown on TE GPIO line. We need
1517 * to re-enable TE after self diagnostics */
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001518 if (td->te_enabled && panel_data->use_ext_te) {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301519 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
Tomi Valkeinen1189b7f2010-03-01 13:52:10 +02001520 if (r)
1521 goto err;
1522 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001523
1524 dsi_bus_unlock();
1525
1526 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
1527
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001528 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001529 return;
1530err:
1531 dev_err(&dssdev->dev, "performing LCD reset\n");
1532
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001533 taal_power_off(dssdev);
Jani Nikula006db7b2010-04-09 12:25:59 +03001534 taal_hw_reset(dssdev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001535 taal_power_on(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001536
1537 dsi_bus_unlock();
1538
1539 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001540
1541 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001542}
1543
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001544static int taal_set_update_mode(struct omap_dss_device *dssdev,
1545 enum omap_dss_update_mode mode)
1546{
1547 if (mode != OMAP_DSS_UPDATE_MANUAL)
1548 return -EINVAL;
1549 return 0;
1550}
1551
1552static enum omap_dss_update_mode taal_get_update_mode(
1553 struct omap_dss_device *dssdev)
1554{
1555 return OMAP_DSS_UPDATE_MANUAL;
1556}
1557
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001558static struct omap_dss_driver taal_driver = {
1559 .probe = taal_probe,
Tomi Valkeinen14e4d782011-03-31 12:03:51 +03001560 .remove = __exit_p(taal_remove),
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001561
1562 .enable = taal_enable,
1563 .disable = taal_disable,
1564 .suspend = taal_suspend,
1565 .resume = taal_resume,
1566
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001567 .set_update_mode = taal_set_update_mode,
1568 .get_update_mode = taal_get_update_mode,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001569
1570 .update = taal_update,
1571 .sync = taal_sync,
1572
Tomi Valkeinen96adcec2010-01-11 13:54:33 +02001573 .get_resolution = taal_get_resolution,
Tomi Valkeinena2699502010-01-11 14:33:40 +02001574 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1575
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001576 .enable_te = taal_enable_te,
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001577 .get_te = taal_get_te,
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001578
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001579 .set_rotate = taal_rotate,
1580 .get_rotate = taal_get_rotate,
1581 .set_mirror = taal_mirror,
1582 .get_mirror = taal_get_mirror,
1583 .run_test = taal_run_test,
1584 .memory_read = taal_memory_read,
1585
Tomi Valkeinen69b20482010-01-20 12:11:25 +02001586 .get_timings = taal_get_timings,
1587
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001588 .driver = {
1589 .name = "taal",
1590 .owner = THIS_MODULE,
1591 },
1592};
1593
1594static int __init taal_init(void)
1595{
1596 omap_dss_register_driver(&taal_driver);
1597
1598 return 0;
1599}
1600
1601static void __exit taal_exit(void)
1602{
1603 omap_dss_unregister_driver(&taal_driver);
1604}
1605
1606module_init(taal_init);
1607module_exit(taal_exit);
1608
1609MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1610MODULE_DESCRIPTION("Taal Driver");
1611MODULE_LICENSE("GPL");