blob: 90d79c0bc9f43793853d9c51f3875cf57b40dad0 [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
Jani Nikula7ae2fb12010-04-13 10:57:52 +030066static irqreturn_t taal_te_isr(int irq, void *data);
67static void taal_te_timeout_work_callback(struct work_struct *work);
Tomi Valkeinen21df20f2010-03-02 12:13:55 +020068static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
69
Tomi Valkeinen1abf7812011-03-24 14:53:27 +020070static int taal_panel_reset(struct omap_dss_device *dssdev);
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
Tomi Valkeinen883b9ac2011-03-24 15:01:30 +0200232 struct workqueue_struct *workqueue;
233
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200234 struct delayed_work esd_work;
Tomi Valkeinen33a410b2011-03-24 13:58:01 +0200235 unsigned esd_interval;
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300236
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200237 bool ulps_enabled;
238 unsigned ulps_timeout;
239 struct delayed_work ulps_work;
240
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300241 struct panel_config *panel_config;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200242};
243
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300244static inline struct nokia_dsi_panel_data
245*get_panel_data(const struct omap_dss_device *dssdev)
246{
247 return (struct nokia_dsi_panel_data *) dssdev->data;
248}
249
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200250static void taal_esd_work(struct work_struct *work);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200251static void taal_ulps_work(struct work_struct *work);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200252
253static void hw_guard_start(struct taal_data *td, int guard_msec)
254{
255 td->hw_guard_wait = msecs_to_jiffies(guard_msec);
256 td->hw_guard_end = jiffies + td->hw_guard_wait;
257}
258
259static void hw_guard_wait(struct taal_data *td)
260{
261 unsigned long wait = td->hw_guard_end - jiffies;
262
263 if ((long)wait > 0 && wait <= td->hw_guard_wait) {
264 set_current_state(TASK_UNINTERRUPTIBLE);
265 schedule_timeout(wait);
266 }
267}
268
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530269static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200270{
271 int r;
272 u8 buf[1];
273
Archit Taneja1ffefe72011-05-12 17:26:24 +0530274 r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200275
276 if (r < 0)
277 return r;
278
279 *data = buf[0];
280
281 return 0;
282}
283
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530284static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200285{
Archit Taneja1ffefe72011-05-12 17:26:24 +0530286 return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200287}
288
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530289static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200290{
291 u8 buf[2];
292 buf[0] = dcs_cmd;
293 buf[1] = param;
Archit Taneja1ffefe72011-05-12 17:26:24 +0530294 return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200295}
296
297static int taal_sleep_in(struct taal_data *td)
298
299{
300 u8 cmd;
301 int r;
302
303 hw_guard_wait(td);
304
305 cmd = DCS_SLEEP_IN;
Archit Taneja1ffefe72011-05-12 17:26:24 +0530306 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200307 if (r)
308 return r;
309
310 hw_guard_start(td, 120);
311
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300312 if (td->panel_config->sleep.sleep_in)
313 msleep(td->panel_config->sleep.sleep_in);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200314
315 return 0;
316}
317
318static int taal_sleep_out(struct taal_data *td)
319{
320 int r;
321
322 hw_guard_wait(td);
323
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530324 r = taal_dcs_write_0(td, DCS_SLEEP_OUT);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200325 if (r)
326 return r;
327
328 hw_guard_start(td, 120);
329
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300330 if (td->panel_config->sleep.sleep_out)
331 msleep(td->panel_config->sleep.sleep_out);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200332
333 return 0;
334}
335
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530336static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200337{
338 int r;
339
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530340 r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200341 if (r)
342 return r;
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530343 r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200344 if (r)
345 return r;
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530346 r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200347 if (r)
348 return r;
349
350 return 0;
351}
352
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530353static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200354{
355 int r;
356 u8 mode;
357 int b5, b6, b7;
358
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530359 r = taal_dcs_read_1(td, DCS_READ_MADCTL, &mode);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200360 if (r)
361 return r;
362
363 switch (rotate) {
364 default:
365 case 0:
366 b7 = 0;
367 b6 = 0;
368 b5 = 0;
369 break;
370 case 1:
371 b7 = 0;
372 b6 = 1;
373 b5 = 1;
374 break;
375 case 2:
376 b7 = 1;
377 b6 = 1;
378 b5 = 0;
379 break;
380 case 3:
381 b7 = 1;
382 b6 = 0;
383 b5 = 1;
384 break;
385 }
386
387 if (mirror)
388 b6 = !b6;
389
390 mode &= ~((1<<7) | (1<<6) | (1<<5));
391 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
392
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530393 return taal_dcs_write_1(td, DCS_MEM_ACC_CTRL, mode);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200394}
395
Archit Tanejabc6d4b12011-03-01 13:59:46 +0530396static int taal_set_update_window(struct taal_data *td,
397 u16 x, u16 y, u16 w, u16 h)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200398{
399 int r;
400 u16 x1 = x;
401 u16 x2 = x + w - 1;
402 u16 y1 = y;
403 u16 y2 = y + h - 1;
404
405 u8 buf[5];
406 buf[0] = DCS_COLUMN_ADDR;
407 buf[1] = (x1 >> 8) & 0xff;
408 buf[2] = (x1 >> 0) & 0xff;
409 buf[3] = (x2 >> 8) & 0xff;
410 buf[4] = (x2 >> 0) & 0xff;
411
Archit Taneja1ffefe72011-05-12 17:26:24 +0530412 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200413 if (r)
414 return r;
415
416 buf[0] = DCS_PAGE_ADDR;
417 buf[1] = (y1 >> 8) & 0xff;
418 buf[2] = (y1 >> 0) & 0xff;
419 buf[3] = (y2 >> 8) & 0xff;
420 buf[4] = (y2 >> 0) & 0xff;
421
Archit Taneja1ffefe72011-05-12 17:26:24 +0530422 r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200423 if (r)
424 return r;
425
Archit Taneja1ffefe72011-05-12 17:26:24 +0530426 dsi_vc_send_bta_sync(td->dssdev, td->channel);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200427
428 return r;
429}
430
Tomi Valkeinen1663d2f2011-03-24 14:01:49 +0200431static void taal_queue_esd_work(struct omap_dss_device *dssdev)
432{
433 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
434
435 if (td->esd_interval > 0)
Tomi Valkeinen883b9ac2011-03-24 15:01:30 +0200436 queue_delayed_work(td->workqueue, &td->esd_work,
Tomi Valkeinen1663d2f2011-03-24 14:01:49 +0200437 msecs_to_jiffies(td->esd_interval));
438}
439
440static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
441{
442 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
443
444 cancel_delayed_work(&td->esd_work);
445}
446
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200447static void taal_queue_ulps_work(struct omap_dss_device *dssdev)
448{
449 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
450
451 if (td->ulps_timeout > 0)
452 queue_delayed_work(td->workqueue, &td->ulps_work,
453 msecs_to_jiffies(td->ulps_timeout));
454}
455
456static void taal_cancel_ulps_work(struct omap_dss_device *dssdev)
457{
458 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
459
460 cancel_delayed_work(&td->ulps_work);
461}
462
463static int taal_enter_ulps(struct omap_dss_device *dssdev)
464{
465 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
466 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
467 int r;
468
469 if (td->ulps_enabled)
470 return 0;
471
472 taal_cancel_ulps_work(dssdev);
473
474 r = _taal_enable_te(dssdev, false);
475 if (r)
476 goto err;
477
478 disable_irq(gpio_to_irq(panel_data->ext_te_gpio));
479
480 omapdss_dsi_display_disable(dssdev, false, true);
481
482 td->ulps_enabled = true;
483
484 return 0;
485
486err:
487 dev_err(&dssdev->dev, "enter ULPS failed");
488 taal_panel_reset(dssdev);
489
490 td->ulps_enabled = false;
491
492 taal_queue_ulps_work(dssdev);
493
494 return r;
495}
496
497static int taal_exit_ulps(struct omap_dss_device *dssdev)
498{
499 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
500 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
501 int r;
502
503 if (!td->ulps_enabled)
504 return 0;
505
506 r = omapdss_dsi_display_enable(dssdev);
507 if (r)
508 goto err;
509
Archit Taneja1ffefe72011-05-12 17:26:24 +0530510 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200511
512 r = _taal_enable_te(dssdev, true);
513 if (r)
514 goto err;
515
516 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
517
518 taal_queue_ulps_work(dssdev);
519
520 td->ulps_enabled = false;
521
522 return 0;
523
524err:
525 dev_err(&dssdev->dev, "exit ULPS failed");
526 r = taal_panel_reset(dssdev);
527
528 enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
529 td->ulps_enabled = false;
530
531 taal_queue_ulps_work(dssdev);
532
533 return r;
534}
535
536static int taal_wake_up(struct omap_dss_device *dssdev)
537{
538 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
539
540 if (td->ulps_enabled)
541 return taal_exit_ulps(dssdev);
542
543 taal_cancel_ulps_work(dssdev);
544 taal_queue_ulps_work(dssdev);
545 return 0;
546}
547
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200548static int taal_bl_update_status(struct backlight_device *dev)
549{
550 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
551 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300552 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200553 int r;
554 int level;
555
556 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
557 dev->props.power == FB_BLANK_UNBLANK)
558 level = dev->props.brightness;
559 else
560 level = 0;
561
562 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
563
Tomi Valkeinen1cbc8702010-04-15 16:41:07 +0300564 mutex_lock(&td->lock);
565
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200566 if (td->use_dsi_bl) {
567 if (td->enabled) {
Archit Taneja1ffefe72011-05-12 17:26:24 +0530568 dsi_bus_lock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200569
570 r = taal_wake_up(dssdev);
571 if (!r)
572 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
573
Archit Taneja1ffefe72011-05-12 17:26:24 +0530574 dsi_bus_unlock(dssdev);
Tomi Valkeinen1cbc8702010-04-15 16:41:07 +0300575 } else {
576 r = 0;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200577 }
578 } else {
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300579 if (!panel_data->set_backlight)
Tomi Valkeinen1cbc8702010-04-15 16:41:07 +0300580 r = -EINVAL;
581 else
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300582 r = panel_data->set_backlight(dssdev, level);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200583 }
584
Tomi Valkeinen1cbc8702010-04-15 16:41:07 +0300585 mutex_unlock(&td->lock);
586
587 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200588}
589
590static int taal_bl_get_intensity(struct backlight_device *dev)
591{
592 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
593 dev->props.power == FB_BLANK_UNBLANK)
594 return dev->props.brightness;
595
596 return 0;
597}
598
Lionel Debrouxacc24722010-11-16 14:14:02 +0100599static const struct backlight_ops taal_bl_ops = {
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200600 .get_brightness = taal_bl_get_intensity,
601 .update_status = taal_bl_update_status,
602};
603
604static void taal_get_timings(struct omap_dss_device *dssdev,
605 struct omap_video_timings *timings)
606{
607 *timings = dssdev->panel.timings;
608}
609
610static void taal_get_resolution(struct omap_dss_device *dssdev,
611 u16 *xres, u16 *yres)
612{
613 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
614
615 if (td->rotate == 0 || td->rotate == 2) {
616 *xres = dssdev->panel.timings.x_res;
617 *yres = dssdev->panel.timings.y_res;
618 } else {
619 *yres = dssdev->panel.timings.x_res;
620 *xres = dssdev->panel.timings.y_res;
621 }
622}
623
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200624static ssize_t taal_num_errors_show(struct device *dev,
625 struct device_attribute *attr, char *buf)
626{
627 struct omap_dss_device *dssdev = to_dss_device(dev);
628 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
629 u8 errors;
630 int r;
631
Jani Nikula6b316712010-04-28 11:15:18 +0300632 mutex_lock(&td->lock);
633
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200634 if (td->enabled) {
Archit Taneja1ffefe72011-05-12 17:26:24 +0530635 dsi_bus_lock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200636
637 r = taal_wake_up(dssdev);
638 if (!r)
639 r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
640
Archit Taneja1ffefe72011-05-12 17:26:24 +0530641 dsi_bus_unlock(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200642 } else {
643 r = -ENODEV;
644 }
645
Jani Nikula6b316712010-04-28 11:15:18 +0300646 mutex_unlock(&td->lock);
647
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200648 if (r)
649 return r;
650
651 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
652}
653
654static ssize_t taal_hw_revision_show(struct device *dev,
655 struct device_attribute *attr, char *buf)
656{
657 struct omap_dss_device *dssdev = to_dss_device(dev);
658 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
659 u8 id1, id2, id3;
660 int r;
661
Jani Nikula6b316712010-04-28 11:15:18 +0300662 mutex_lock(&td->lock);
663
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200664 if (td->enabled) {
Archit Taneja1ffefe72011-05-12 17:26:24 +0530665 dsi_bus_lock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200666
667 r = taal_wake_up(dssdev);
668 if (!r)
669 r = taal_get_id(td, &id1, &id2, &id3);
670
Archit Taneja1ffefe72011-05-12 17:26:24 +0530671 dsi_bus_unlock(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200672 } else {
673 r = -ENODEV;
674 }
675
Jani Nikula6b316712010-04-28 11:15:18 +0300676 mutex_unlock(&td->lock);
677
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200678 if (r)
679 return r;
680
681 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
682}
683
684static const char *cabc_modes[] = {
685 "off", /* used also always when CABC is not supported */
686 "ui",
687 "still-image",
688 "moving-image",
689};
690
691static ssize_t show_cabc_mode(struct device *dev,
692 struct device_attribute *attr,
693 char *buf)
694{
695 struct omap_dss_device *dssdev = to_dss_device(dev);
696 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
697 const char *mode_str;
698 int mode;
699 int len;
700
701 mode = td->cabc_mode;
702
703 mode_str = "unknown";
704 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
705 mode_str = cabc_modes[mode];
706 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
707
708 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
709}
710
711static ssize_t store_cabc_mode(struct device *dev,
712 struct device_attribute *attr,
713 const char *buf, size_t count)
714{
715 struct omap_dss_device *dssdev = to_dss_device(dev);
716 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
717 int i;
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200718 int r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200719
720 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
721 if (sysfs_streq(cabc_modes[i], buf))
722 break;
723 }
724
725 if (i == ARRAY_SIZE(cabc_modes))
726 return -EINVAL;
727
Jani Nikula6b316712010-04-28 11:15:18 +0300728 mutex_lock(&td->lock);
729
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200730 if (td->enabled) {
Archit Taneja1ffefe72011-05-12 17:26:24 +0530731 dsi_bus_lock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200732
733 if (!td->cabc_broken) {
734 r = taal_wake_up(dssdev);
735 if (r)
736 goto err;
737
738 r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
739 if (r)
740 goto err;
741 }
742
Archit Taneja1ffefe72011-05-12 17:26:24 +0530743 dsi_bus_unlock(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200744 }
745
746 td->cabc_mode = i;
747
Jani Nikula6b316712010-04-28 11:15:18 +0300748 mutex_unlock(&td->lock);
749
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200750 return count;
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200751err:
Archit Taneja1ffefe72011-05-12 17:26:24 +0530752 dsi_bus_unlock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200753 mutex_unlock(&td->lock);
754 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200755}
756
757static ssize_t show_cabc_available_modes(struct device *dev,
758 struct device_attribute *attr,
759 char *buf)
760{
761 int len;
762 int i;
763
764 for (i = 0, len = 0;
765 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
766 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
767 i ? " " : "", cabc_modes[i],
768 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
769
770 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
771}
772
Tomi Valkeinen1f8fa452011-03-24 14:06:51 +0200773static ssize_t taal_store_esd_interval(struct device *dev,
774 struct device_attribute *attr,
775 const char *buf, size_t count)
776{
777 struct omap_dss_device *dssdev = to_dss_device(dev);
778 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
779
780 unsigned long t;
781 int r;
782
783 r = strict_strtoul(buf, 10, &t);
784 if (r)
785 return r;
786
787 mutex_lock(&td->lock);
788 taal_cancel_esd_work(dssdev);
789 td->esd_interval = t;
790 if (td->enabled)
791 taal_queue_esd_work(dssdev);
792 mutex_unlock(&td->lock);
793
794 return count;
795}
796
797static ssize_t taal_show_esd_interval(struct device *dev,
798 struct device_attribute *attr,
799 char *buf)
800{
801 struct omap_dss_device *dssdev = to_dss_device(dev);
802 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
803 unsigned t;
804
805 mutex_lock(&td->lock);
806 t = td->esd_interval;
807 mutex_unlock(&td->lock);
808
809 return snprintf(buf, PAGE_SIZE, "%u\n", t);
810}
811
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200812static ssize_t taal_store_ulps(struct device *dev,
813 struct device_attribute *attr,
814 const char *buf, size_t count)
815{
816 struct omap_dss_device *dssdev = to_dss_device(dev);
817 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
818 unsigned long t;
819 int r;
820
821 r = strict_strtoul(buf, 10, &t);
822 if (r)
823 return r;
824
825 mutex_lock(&td->lock);
826
827 if (td->enabled) {
Archit Taneja1ffefe72011-05-12 17:26:24 +0530828 dsi_bus_lock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200829
830 if (t)
831 r = taal_enter_ulps(dssdev);
832 else
833 r = taal_wake_up(dssdev);
834
Archit Taneja1ffefe72011-05-12 17:26:24 +0530835 dsi_bus_unlock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200836 }
837
838 mutex_unlock(&td->lock);
839
840 if (r)
841 return r;
842
843 return count;
844}
845
846static ssize_t taal_show_ulps(struct device *dev,
847 struct device_attribute *attr,
848 char *buf)
849{
850 struct omap_dss_device *dssdev = to_dss_device(dev);
851 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
852 unsigned t;
853
854 mutex_lock(&td->lock);
855 t = td->ulps_enabled;
856 mutex_unlock(&td->lock);
857
858 return snprintf(buf, PAGE_SIZE, "%u\n", t);
859}
860
861static ssize_t taal_store_ulps_timeout(struct device *dev,
862 struct device_attribute *attr,
863 const char *buf, size_t count)
864{
865 struct omap_dss_device *dssdev = to_dss_device(dev);
866 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
867 unsigned long t;
868 int r;
869
870 r = strict_strtoul(buf, 10, &t);
871 if (r)
872 return r;
873
874 mutex_lock(&td->lock);
875 td->ulps_timeout = t;
876
877 if (td->enabled) {
878 /* taal_wake_up will restart the timer */
Archit Taneja1ffefe72011-05-12 17:26:24 +0530879 dsi_bus_lock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200880 r = taal_wake_up(dssdev);
Archit Taneja1ffefe72011-05-12 17:26:24 +0530881 dsi_bus_unlock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200882 }
883
884 mutex_unlock(&td->lock);
885
886 if (r)
887 return r;
888
889 return count;
890}
891
892static ssize_t taal_show_ulps_timeout(struct device *dev,
893 struct device_attribute *attr,
894 char *buf)
895{
896 struct omap_dss_device *dssdev = to_dss_device(dev);
897 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
898 unsigned t;
899
900 mutex_lock(&td->lock);
901 t = td->ulps_timeout;
902 mutex_unlock(&td->lock);
903
904 return snprintf(buf, PAGE_SIZE, "%u\n", t);
905}
906
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200907static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
908static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
909static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
910 show_cabc_mode, store_cabc_mode);
911static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
912 show_cabc_available_modes, NULL);
Tomi Valkeinen1f8fa452011-03-24 14:06:51 +0200913static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
914 taal_show_esd_interval, taal_store_esd_interval);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200915static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
916 taal_show_ulps, taal_store_ulps);
917static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
918 taal_show_ulps_timeout, taal_store_ulps_timeout);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200919
920static struct attribute *taal_attrs[] = {
921 &dev_attr_num_dsi_errors.attr,
922 &dev_attr_hw_revision.attr,
923 &dev_attr_cabc_mode.attr,
924 &dev_attr_cabc_available_modes.attr,
Tomi Valkeinen1f8fa452011-03-24 14:06:51 +0200925 &dev_attr_esd_interval.attr,
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200926 &dev_attr_ulps.attr,
927 &dev_attr_ulps_timeout.attr,
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200928 NULL,
929};
930
931static struct attribute_group taal_attr_group = {
932 .attrs = taal_attrs,
933};
934
Jani Nikula006db7b2010-04-09 12:25:59 +0300935static void taal_hw_reset(struct omap_dss_device *dssdev)
936{
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300937 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300938 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
939
940 if (panel_data->reset_gpio == -1)
Jani Nikula006db7b2010-04-09 12:25:59 +0300941 return;
942
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300943 gpio_set_value(panel_data->reset_gpio, 1);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300944 if (td->panel_config->reset_sequence.high)
945 udelay(td->panel_config->reset_sequence.high);
Jani Nikula006db7b2010-04-09 12:25:59 +0300946 /* reset the panel */
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300947 gpio_set_value(panel_data->reset_gpio, 0);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300948 /* assert reset */
949 if (td->panel_config->reset_sequence.low)
950 udelay(td->panel_config->reset_sequence.low);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300951 gpio_set_value(panel_data->reset_gpio, 1);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300952 /* wait after releasing reset */
953 if (td->panel_config->sleep.hw_reset)
954 msleep(td->panel_config->sleep.hw_reset);
Jani Nikula006db7b2010-04-09 12:25:59 +0300955}
956
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200957static int taal_probe(struct omap_dss_device *dssdev)
958{
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500959 struct backlight_properties props;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200960 struct taal_data *td;
961 struct backlight_device *bldev;
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300962 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300963 struct panel_config *panel_config = NULL;
964 int r, i;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200965
966 dev_dbg(&dssdev->dev, "probe\n");
967
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +0300968 if (!panel_data || !panel_data->name) {
969 r = -EINVAL;
970 goto err;
971 }
972
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300973 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
974 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
975 panel_config = &panel_configs[i];
976 break;
977 }
978 }
979
980 if (!panel_config) {
981 r = -EINVAL;
982 goto err;
983 }
984
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200985 dssdev->panel.config = OMAP_DSS_LCD_TFT;
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300986 dssdev->panel.timings = panel_config->timings;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200987 dssdev->ctrl.pixel_size = 24;
988
989 td = kzalloc(sizeof(*td), GFP_KERNEL);
990 if (!td) {
991 r = -ENOMEM;
Jani Nikulad2b65782010-04-15 12:24:36 +0300992 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200993 }
994 td->dssdev = dssdev;
Jani Nikulae7f6c3f2010-04-15 12:55:38 +0300995 td->panel_config = panel_config;
Tomi Valkeinen33a410b2011-03-24 13:58:01 +0200996 td->esd_interval = panel_data->esd_interval;
Tomi Valkeinen1abf7812011-03-24 14:53:27 +0200997 td->ulps_enabled = false;
998 td->ulps_timeout = panel_data->ulps_timeout;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +0200999
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001000 mutex_init(&td->lock);
1001
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001002 atomic_set(&td->do_update, 0);
1003
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +03001004 r = init_regulators(dssdev, panel_config->regulators,
1005 panel_config->num_regulators);
1006 if (r)
1007 goto err_reg;
1008
Tomi Valkeinen883b9ac2011-03-24 15:01:30 +02001009 td->workqueue = create_singlethread_workqueue("taal_esd");
1010 if (td->workqueue == NULL) {
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001011 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
1012 r = -ENOMEM;
Jani Nikulad2b65782010-04-15 12:24:36 +03001013 goto err_wq;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001014 }
1015 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001016 INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001017
1018 dev_set_drvdata(&dssdev->dev, td);
1019
Jani Nikula006db7b2010-04-09 12:25:59 +03001020 taal_hw_reset(dssdev);
1021
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001022 /* if no platform set_backlight() defined, presume DSI backlight
1023 * control */
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001024 memset(&props, 0, sizeof(struct backlight_properties));
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001025 if (!panel_data->set_backlight)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001026 td->use_dsi_bl = true;
1027
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001028 if (td->use_dsi_bl)
1029 props.max_brightness = 255;
1030 else
1031 props.max_brightness = 127;
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001032
1033 props.type = BACKLIGHT_RAW;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001034 bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001035 &taal_bl_ops, &props);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001036 if (IS_ERR(bldev)) {
1037 r = PTR_ERR(bldev);
Jani Nikulad2b65782010-04-15 12:24:36 +03001038 goto err_bl;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001039 }
1040
1041 td->bldev = bldev;
1042
1043 bldev->props.fb_blank = FB_BLANK_UNBLANK;
1044 bldev->props.power = FB_BLANK_UNBLANK;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001045 if (td->use_dsi_bl)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001046 bldev->props.brightness = 255;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001047 else
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001048 bldev->props.brightness = 127;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001049
1050 taal_bl_update_status(bldev);
1051
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001052 if (panel_data->use_ext_te) {
1053 int gpio = panel_data->ext_te_gpio;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001054
1055 r = gpio_request(gpio, "taal irq");
1056 if (r) {
1057 dev_err(&dssdev->dev, "GPIO request failed\n");
Jani Nikulad2b65782010-04-15 12:24:36 +03001058 goto err_gpio;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001059 }
1060
1061 gpio_direction_input(gpio);
1062
1063 r = request_irq(gpio_to_irq(gpio), taal_te_isr,
1064 IRQF_DISABLED | IRQF_TRIGGER_RISING,
1065 "taal vsync", dssdev);
1066
1067 if (r) {
1068 dev_err(&dssdev->dev, "IRQ request failed\n");
1069 gpio_free(gpio);
Jani Nikulad2b65782010-04-15 12:24:36 +03001070 goto err_irq;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001071 }
1072
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001073 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
1074 taal_te_timeout_work_callback);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001075
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001076 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001077 }
1078
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301079 r = omap_dsi_request_vc(dssdev, &td->channel);
1080 if (r) {
1081 dev_err(&dssdev->dev, "failed to get virtual channel\n");
1082 goto err_req_vc;
1083 }
1084
1085 r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
1086 if (r) {
1087 dev_err(&dssdev->dev, "failed to set VC_ID\n");
1088 goto err_vc_id;
1089 }
1090
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001091 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
1092 if (r) {
1093 dev_err(&dssdev->dev, "failed to create sysfs files\n");
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301094 goto err_vc_id;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001095 }
1096
1097 return 0;
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301098
1099err_vc_id:
1100 omap_dsi_release_vc(dssdev, td->channel);
1101err_req_vc:
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001102 if (panel_data->use_ext_te)
1103 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
Jani Nikulad2b65782010-04-15 12:24:36 +03001104err_irq:
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001105 if (panel_data->use_ext_te)
1106 gpio_free(panel_data->ext_te_gpio);
Jani Nikulad2b65782010-04-15 12:24:36 +03001107err_gpio:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001108 backlight_device_unregister(bldev);
Jani Nikulad2b65782010-04-15 12:24:36 +03001109err_bl:
Tomi Valkeinen883b9ac2011-03-24 15:01:30 +02001110 destroy_workqueue(td->workqueue);
Jani Nikulad2b65782010-04-15 12:24:36 +03001111err_wq:
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +03001112 free_regulators(panel_config->regulators, panel_config->num_regulators);
1113err_reg:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001114 kfree(td);
Jani Nikulad2b65782010-04-15 12:24:36 +03001115err:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001116 return r;
1117}
1118
Tomi Valkeinen14e4d782011-03-31 12:03:51 +03001119static void __exit taal_remove(struct omap_dss_device *dssdev)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001120{
1121 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001122 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001123 struct backlight_device *bldev;
1124
1125 dev_dbg(&dssdev->dev, "remove\n");
1126
1127 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301128 omap_dsi_release_vc(dssdev, td->channel);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001129
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001130 if (panel_data->use_ext_te) {
1131 int gpio = panel_data->ext_te_gpio;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001132 free_irq(gpio_to_irq(gpio), dssdev);
1133 gpio_free(gpio);
1134 }
1135
1136 bldev = td->bldev;
1137 bldev->props.power = FB_BLANK_POWERDOWN;
1138 taal_bl_update_status(bldev);
1139 backlight_device_unregister(bldev);
1140
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001141 taal_cancel_ulps_work(dssdev);
Tomi Valkeinen1663d2f2011-03-24 14:01:49 +02001142 taal_cancel_esd_work(dssdev);
Tomi Valkeinen883b9ac2011-03-24 15:01:30 +02001143 destroy_workqueue(td->workqueue);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001144
Jani Nikula006db7b2010-04-09 12:25:59 +03001145 /* reset, to be sure that the panel is in a valid state */
1146 taal_hw_reset(dssdev);
1147
Tomi Valkeinenc8cd4542010-06-09 15:24:46 +03001148 free_regulators(td->panel_config->regulators,
1149 td->panel_config->num_regulators);
1150
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001151 kfree(td);
1152}
1153
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001154static int taal_power_on(struct omap_dss_device *dssdev)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001155{
1156 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1157 u8 id1, id2, id3;
1158 int r;
1159
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001160 r = omapdss_dsi_display_enable(dssdev);
1161 if (r) {
1162 dev_err(&dssdev->dev, "failed to enable DSI\n");
1163 goto err0;
1164 }
1165
Jani Nikula006db7b2010-04-09 12:25:59 +03001166 taal_hw_reset(dssdev);
1167
Archit Taneja1ffefe72011-05-12 17:26:24 +05301168 omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001169
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001170 r = taal_sleep_out(td);
1171 if (r)
1172 goto err;
1173
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301174 r = taal_get_id(td, &id1, &id2, &id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001175 if (r)
1176 goto err;
1177
Jani Nikula1e8943d2010-04-15 17:07:39 +03001178 /* on early Taal revisions CABC is broken */
1179 if (td->panel_config->type == PANEL_TAAL &&
1180 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001181 td->cabc_broken = true;
1182
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301183 r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
Jani Nikulaf2a8b752010-04-09 14:15:12 +03001184 if (r)
1185 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001186
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301187 r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
Jani Nikulaf2a8b752010-04-09 14:15:12 +03001188 (1<<2) | (1<<5)); /* BL | BCTRL */
1189 if (r)
1190 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001191
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301192 r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
Jani Nikulaf2a8b752010-04-09 14:15:12 +03001193 if (r)
1194 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001195
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301196 r = taal_set_addr_mode(td, td->rotate, td->mirror);
Jani Nikulaf2a8b752010-04-09 14:15:12 +03001197 if (r)
1198 goto err;
1199
1200 if (!td->cabc_broken) {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301201 r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
Jani Nikulaf2a8b752010-04-09 14:15:12 +03001202 if (r)
1203 goto err;
1204 }
1205
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301206 r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
Jani Nikulaf2a8b752010-04-09 14:15:12 +03001207 if (r)
1208 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001209
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001210 r = _taal_enable_te(dssdev, td->te_enabled);
1211 if (r)
1212 goto err;
1213
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001214 td->enabled = 1;
1215
1216 if (!td->intro_printed) {
Jani Nikula0f45bdd2010-04-16 14:21:14 +03001217 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
1218 td->panel_config->name, id1, id2, id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001219 if (td->cabc_broken)
1220 dev_info(&dssdev->dev,
1221 "old Taal version, CABC disabled\n");
1222 td->intro_printed = true;
1223 }
1224
Archit Taneja1ffefe72011-05-12 17:26:24 +05301225 omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001226
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001227 return 0;
1228err:
Jani Nikula006db7b2010-04-09 12:25:59 +03001229 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
1230
1231 taal_hw_reset(dssdev);
1232
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03001233 omapdss_dsi_display_disable(dssdev, true, false);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001234err0:
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001235 return r;
1236}
1237
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001238static void taal_power_off(struct omap_dss_device *dssdev)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001239{
1240 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Jani Nikula006db7b2010-04-09 12:25:59 +03001241 int r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001242
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301243 r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
Jani Nikula006db7b2010-04-09 12:25:59 +03001244 if (!r) {
1245 r = taal_sleep_in(td);
Jani Nikulae7f6c3f2010-04-15 12:55:38 +03001246 /* HACK: wait a bit so that the message goes through */
Jani Nikula006db7b2010-04-09 12:25:59 +03001247 msleep(10);
1248 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001249
Jani Nikula006db7b2010-04-09 12:25:59 +03001250 if (r) {
1251 dev_err(&dssdev->dev,
1252 "error disabling panel, issuing HW reset\n");
1253 taal_hw_reset(dssdev);
1254 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001255
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03001256 omapdss_dsi_display_disable(dssdev, true, false);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001257
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001258 td->enabled = 0;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001259}
1260
Tomi Valkeinenbb5476c72011-03-24 15:00:06 +02001261static int taal_panel_reset(struct omap_dss_device *dssdev)
1262{
1263 dev_err(&dssdev->dev, "performing LCD reset\n");
1264
1265 taal_power_off(dssdev);
1266 taal_hw_reset(dssdev);
1267 return taal_power_on(dssdev);
1268}
1269
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001270static int taal_enable(struct omap_dss_device *dssdev)
1271{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001272 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001273 int r;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001274
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001275 dev_dbg(&dssdev->dev, "enable\n");
1276
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001277 mutex_lock(&td->lock);
1278
1279 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
1280 r = -EINVAL;
1281 goto err;
1282 }
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001283
Archit Taneja1ffefe72011-05-12 17:26:24 +05301284 dsi_bus_lock(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001285
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001286 r = taal_power_on(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001287
Archit Taneja1ffefe72011-05-12 17:26:24 +05301288 dsi_bus_unlock(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001289
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001290 if (r)
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001291 goto err;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001292
Tomi Valkeinen1663d2f2011-03-24 14:01:49 +02001293 taal_queue_esd_work(dssdev);
Jani Nikula4571a022010-04-12 10:23:46 +03001294
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001295 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1296
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001297 mutex_unlock(&td->lock);
1298
1299 return 0;
1300err:
1301 dev_dbg(&dssdev->dev, "enable failed\n");
1302 mutex_unlock(&td->lock);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001303 return r;
1304}
1305
1306static void taal_disable(struct omap_dss_device *dssdev)
1307{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001308 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1309
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001310 dev_dbg(&dssdev->dev, "disable\n");
1311
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001312 mutex_lock(&td->lock);
1313
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001314 taal_cancel_ulps_work(dssdev);
Tomi Valkeinen1663d2f2011-03-24 14:01:49 +02001315 taal_cancel_esd_work(dssdev);
Jani Nikula4571a022010-04-12 10:23:46 +03001316
Archit Taneja1ffefe72011-05-12 17:26:24 +05301317 dsi_bus_lock(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001318
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001319 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
1320 taal_wake_up(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001321 taal_power_off(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001322 }
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001323
Archit Taneja1ffefe72011-05-12 17:26:24 +05301324 dsi_bus_unlock(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001325
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001326 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001327
1328 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001329}
1330
1331static int taal_suspend(struct omap_dss_device *dssdev)
1332{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001333 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1334 int r;
1335
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001336 dev_dbg(&dssdev->dev, "suspend\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001337
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001338 mutex_lock(&td->lock);
1339
1340 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
1341 r = -EINVAL;
1342 goto err;
1343 }
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001344
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001345 taal_cancel_ulps_work(dssdev);
Tomi Valkeinen1663d2f2011-03-24 14:01:49 +02001346 taal_cancel_esd_work(dssdev);
Jani Nikula4571a022010-04-12 10:23:46 +03001347
Archit Taneja1ffefe72011-05-12 17:26:24 +05301348 dsi_bus_lock(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001349
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001350 r = taal_wake_up(dssdev);
1351 if (!r)
1352 taal_power_off(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001353
Archit Taneja1ffefe72011-05-12 17:26:24 +05301354 dsi_bus_unlock(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001355
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001356 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001357
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001358 mutex_unlock(&td->lock);
1359
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001360 return 0;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001361err:
1362 mutex_unlock(&td->lock);
1363 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001364}
1365
1366static int taal_resume(struct omap_dss_device *dssdev)
1367{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001368 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001369 int r;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001370
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001371 dev_dbg(&dssdev->dev, "resume\n");
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001372
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001373 mutex_lock(&td->lock);
1374
1375 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
1376 r = -EINVAL;
1377 goto err;
1378 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001379
Archit Taneja1ffefe72011-05-12 17:26:24 +05301380 dsi_bus_lock(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001381
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001382 r = taal_power_on(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001383
Archit Taneja1ffefe72011-05-12 17:26:24 +05301384 dsi_bus_unlock(dssdev);
Jani Nikula2c2fc152010-04-12 10:06:14 +03001385
Jani Nikula4571a022010-04-12 10:23:46 +03001386 if (r) {
Jani Nikulafed44b72010-04-12 10:25:21 +03001387 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Jani Nikula4571a022010-04-12 10:23:46 +03001388 } else {
Jani Nikulafed44b72010-04-12 10:25:21 +03001389 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
Tomi Valkeinen1663d2f2011-03-24 14:01:49 +02001390 taal_queue_esd_work(dssdev);
Jani Nikula4571a022010-04-12 10:23:46 +03001391 }
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001392
1393 mutex_unlock(&td->lock);
1394
1395 return r;
1396err:
1397 mutex_unlock(&td->lock);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02001398 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001399}
1400
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001401static void taal_framedone_cb(int err, void *data)
1402{
1403 struct omap_dss_device *dssdev = data;
1404 dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
Archit Taneja1ffefe72011-05-12 17:26:24 +05301405 dsi_bus_unlock(dssdev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001406}
1407
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001408static irqreturn_t taal_te_isr(int irq, void *data)
1409{
1410 struct omap_dss_device *dssdev = data;
1411 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1412 int old;
1413 int r;
1414
1415 old = atomic_cmpxchg(&td->do_update, 1, 0);
1416
1417 if (old) {
1418 cancel_delayed_work(&td->te_timeout_work);
1419
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301420 r = omap_dsi_update(dssdev, td->channel,
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001421 td->update_region.x,
1422 td->update_region.y,
1423 td->update_region.w,
1424 td->update_region.h,
1425 taal_framedone_cb, dssdev);
1426 if (r)
1427 goto err;
1428 }
1429
1430 return IRQ_HANDLED;
1431err:
1432 dev_err(&dssdev->dev, "start update failed\n");
Archit Taneja1ffefe72011-05-12 17:26:24 +05301433 dsi_bus_unlock(dssdev);
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001434 return IRQ_HANDLED;
1435}
1436
1437static void taal_te_timeout_work_callback(struct work_struct *work)
1438{
1439 struct taal_data *td = container_of(work, struct taal_data,
1440 te_timeout_work.work);
1441 struct omap_dss_device *dssdev = td->dssdev;
1442
1443 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1444
1445 atomic_set(&td->do_update, 0);
Archit Taneja1ffefe72011-05-12 17:26:24 +05301446 dsi_bus_unlock(dssdev);
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001447}
1448
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001449static int taal_update(struct omap_dss_device *dssdev,
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001450 u16 x, u16 y, u16 w, u16 h)
1451{
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001452 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001453 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001454 int r;
1455
1456 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
1457
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001458 mutex_lock(&td->lock);
Archit Taneja1ffefe72011-05-12 17:26:24 +05301459 dsi_bus_lock(dssdev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001460
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001461 r = taal_wake_up(dssdev);
1462 if (r)
1463 goto err;
1464
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001465 if (!td->enabled) {
1466 r = 0;
1467 goto err;
1468 }
1469
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03001470 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001471 if (r)
1472 goto err;
1473
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301474 r = taal_set_update_window(td, x, y, w, h);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001475 if (r)
1476 goto err;
1477
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001478 if (td->te_enabled && panel_data->use_ext_te) {
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001479 td->update_region.x = x;
1480 td->update_region.y = y;
1481 td->update_region.w = w;
1482 td->update_region.h = h;
1483 barrier();
1484 schedule_delayed_work(&td->te_timeout_work,
1485 msecs_to_jiffies(250));
1486 atomic_set(&td->do_update, 1);
1487 } else {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301488 r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001489 taal_framedone_cb, dssdev);
1490 if (r)
1491 goto err;
1492 }
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001493
1494 /* note: no bus_unlock here. unlock is in framedone_cb */
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001495 mutex_unlock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001496 return 0;
1497err:
Archit Taneja1ffefe72011-05-12 17:26:24 +05301498 dsi_bus_unlock(dssdev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001499 mutex_unlock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001500 return r;
1501}
1502
1503static int taal_sync(struct omap_dss_device *dssdev)
1504{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001505 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1506
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001507 dev_dbg(&dssdev->dev, "sync\n");
1508
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001509 mutex_lock(&td->lock);
Archit Taneja1ffefe72011-05-12 17:26:24 +05301510 dsi_bus_lock(dssdev);
1511 dsi_bus_unlock(dssdev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001512 mutex_unlock(&td->lock);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001513
1514 dev_dbg(&dssdev->dev, "sync done\n");
1515
1516 return 0;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001517}
1518
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001519static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001520{
Jani Nikulae7f6c3f2010-04-15 12:55:38 +03001521 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001522 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001523 int r;
1524
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001525 if (enable)
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301526 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001527 else
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301528 r = taal_dcs_write_0(td, DCS_TEAR_OFF);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001529
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001530 if (!panel_data->use_ext_te)
Jani Nikula7ae2fb12010-04-13 10:57:52 +03001531 omapdss_dsi_enable_te(dssdev, enable);
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001532
Jani Nikulae7f6c3f2010-04-15 12:55:38 +03001533 if (td->panel_config->sleep.enable_te)
1534 msleep(td->panel_config->sleep.enable_te);
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001535
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001536 return r;
1537}
1538
1539static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1540{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001541 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001542 int r;
1543
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001544 mutex_lock(&td->lock);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001545
1546 if (td->te_enabled == enable)
1547 goto end;
1548
Archit Taneja1ffefe72011-05-12 17:26:24 +05301549 dsi_bus_lock(dssdev);
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001550
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001551 if (td->enabled) {
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001552 r = taal_wake_up(dssdev);
1553 if (r)
1554 goto err;
1555
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001556 r = _taal_enable_te(dssdev, enable);
1557 if (r)
1558 goto err;
1559 }
Tomi Valkeinen21df20f2010-03-02 12:13:55 +02001560
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001561 td->te_enabled = enable;
1562
Archit Taneja1ffefe72011-05-12 17:26:24 +05301563 dsi_bus_unlock(dssdev);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001564end:
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001565 mutex_unlock(&td->lock);
1566
1567 return 0;
1568err:
Archit Taneja1ffefe72011-05-12 17:26:24 +05301569 dsi_bus_unlock(dssdev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001570 mutex_unlock(&td->lock);
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001571
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001572 return r;
1573}
1574
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001575static int taal_get_te(struct omap_dss_device *dssdev)
1576{
1577 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001578 int r;
1579
1580 mutex_lock(&td->lock);
1581 r = td->te_enabled;
1582 mutex_unlock(&td->lock);
1583
1584 return r;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001585}
1586
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001587static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
1588{
1589 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1590 int r;
1591
1592 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
1593
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001594 mutex_lock(&td->lock);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001595
1596 if (td->rotate == rotate)
1597 goto end;
1598
Archit Taneja1ffefe72011-05-12 17:26:24 +05301599 dsi_bus_lock(dssdev);
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001600
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001601 if (td->enabled) {
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001602 r = taal_wake_up(dssdev);
1603 if (r)
1604 goto err;
1605
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301606 r = taal_set_addr_mode(td, rotate, td->mirror);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001607 if (r)
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001608 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001609 }
1610
1611 td->rotate = rotate;
1612
Archit Taneja1ffefe72011-05-12 17:26:24 +05301613 dsi_bus_unlock(dssdev);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001614end:
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001615 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001616 return 0;
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001617err:
Archit Taneja1ffefe72011-05-12 17:26:24 +05301618 dsi_bus_unlock(dssdev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001619 mutex_unlock(&td->lock);
Tomi Valkeinen87424e12010-01-08 16:52:48 +02001620 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001621}
1622
1623static u8 taal_get_rotate(struct omap_dss_device *dssdev)
1624{
1625 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001626 int r;
1627
1628 mutex_lock(&td->lock);
1629 r = td->rotate;
1630 mutex_unlock(&td->lock);
1631
1632 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001633}
1634
1635static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
1636{
1637 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1638 int r;
1639
1640 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
1641
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001642 mutex_lock(&td->lock);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001643
1644 if (td->mirror == enable)
1645 goto end;
1646
Archit Taneja1ffefe72011-05-12 17:26:24 +05301647 dsi_bus_lock(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001648 if (td->enabled) {
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001649 r = taal_wake_up(dssdev);
1650 if (r)
1651 goto err;
1652
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301653 r = taal_set_addr_mode(td, td->rotate, enable);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001654 if (r)
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001655 goto err;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001656 }
1657
1658 td->mirror = enable;
1659
Archit Taneja1ffefe72011-05-12 17:26:24 +05301660 dsi_bus_unlock(dssdev);
Tomi Valkeinenffb63c92010-05-21 10:09:18 +03001661end:
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001662 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001663 return 0;
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001664err:
Archit Taneja1ffefe72011-05-12 17:26:24 +05301665 dsi_bus_unlock(dssdev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001666 mutex_unlock(&td->lock);
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +02001667 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001668}
1669
1670static bool taal_get_mirror(struct omap_dss_device *dssdev)
1671{
1672 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001673 int r;
1674
1675 mutex_lock(&td->lock);
1676 r = td->mirror;
1677 mutex_unlock(&td->lock);
1678
1679 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001680}
1681
1682static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1683{
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001684 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001685 u8 id1, id2, id3;
1686 int r;
1687
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001688 mutex_lock(&td->lock);
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001689
1690 if (!td->enabled) {
1691 r = -ENODEV;
1692 goto err1;
1693 }
1694
Archit Taneja1ffefe72011-05-12 17:26:24 +05301695 dsi_bus_lock(dssdev);
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +02001696
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001697 r = taal_wake_up(dssdev);
1698 if (r)
1699 goto err2;
1700
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301701 r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001702 if (r)
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001703 goto err2;
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301704 r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001705 if (r)
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001706 goto err2;
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301707 r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001708 if (r)
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001709 goto err2;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001710
Archit Taneja1ffefe72011-05-12 17:26:24 +05301711 dsi_bus_unlock(dssdev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001712 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001713 return 0;
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001714err2:
Archit Taneja1ffefe72011-05-12 17:26:24 +05301715 dsi_bus_unlock(dssdev);
Jani Nikulaee52c0a2010-04-12 09:36:05 +03001716err1:
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001717 mutex_unlock(&td->lock);
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +02001718 return r;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001719}
1720
1721static int taal_memory_read(struct omap_dss_device *dssdev,
1722 void *buf, size_t size,
1723 u16 x, u16 y, u16 w, u16 h)
1724{
1725 int r;
1726 int first = 1;
1727 int plen;
1728 unsigned buf_used = 0;
Tomi Valkeinenc75d9462010-01-08 16:56:44 +02001729 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1730
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001731 if (size < w * h * 3)
1732 return -ENOMEM;
1733
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001734 mutex_lock(&td->lock);
1735
1736 if (!td->enabled) {
1737 r = -ENODEV;
1738 goto err1;
1739 }
1740
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001741 size = min(w * h * 3,
1742 dssdev->panel.timings.x_res *
1743 dssdev->panel.timings.y_res * 3);
1744
Archit Taneja1ffefe72011-05-12 17:26:24 +05301745 dsi_bus_lock(dssdev);
Tomi Valkeinenc75d9462010-01-08 16:56:44 +02001746
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001747 r = taal_wake_up(dssdev);
1748 if (r)
1749 goto err2;
1750
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001751 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1752 * use short packets. plen 32 works, but bigger packets seem to cause
1753 * an error. */
1754 if (size % 2)
1755 plen = 1;
1756 else
1757 plen = 2;
1758
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301759 taal_set_update_window(td, x, y, w, h);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001760
Archit Taneja1ffefe72011-05-12 17:26:24 +05301761 r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001762 if (r)
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001763 goto err2;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001764
1765 while (buf_used < size) {
1766 u8 dcs_cmd = first ? 0x2e : 0x3e;
1767 first = 0;
1768
Archit Taneja1ffefe72011-05-12 17:26:24 +05301769 r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001770 buf + buf_used, size - buf_used);
1771
1772 if (r < 0) {
1773 dev_err(&dssdev->dev, "read error\n");
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001774 goto err3;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001775 }
1776
1777 buf_used += r;
1778
1779 if (r < plen) {
1780 dev_err(&dssdev->dev, "short read\n");
1781 break;
1782 }
1783
1784 if (signal_pending(current)) {
1785 dev_err(&dssdev->dev, "signal pending, "
1786 "aborting memory read\n");
1787 r = -ERESTARTSYS;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001788 goto err3;
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001789 }
1790 }
1791
1792 r = buf_used;
1793
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001794err3:
Archit Taneja1ffefe72011-05-12 17:26:24 +05301795 dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001796err2:
Archit Taneja1ffefe72011-05-12 17:26:24 +05301797 dsi_bus_unlock(dssdev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001798err1:
1799 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001800 return r;
1801}
1802
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001803static void taal_ulps_work(struct work_struct *work)
1804{
1805 struct taal_data *td = container_of(work, struct taal_data,
1806 ulps_work.work);
1807 struct omap_dss_device *dssdev = td->dssdev;
1808
1809 mutex_lock(&td->lock);
1810
1811 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
1812 mutex_unlock(&td->lock);
1813 return;
1814 }
1815
Archit Taneja1ffefe72011-05-12 17:26:24 +05301816 dsi_bus_lock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001817
1818 taal_enter_ulps(dssdev);
1819
Archit Taneja1ffefe72011-05-12 17:26:24 +05301820 dsi_bus_unlock(dssdev);
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001821 mutex_unlock(&td->lock);
1822}
1823
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001824static void taal_esd_work(struct work_struct *work)
1825{
1826 struct taal_data *td = container_of(work, struct taal_data,
1827 esd_work.work);
1828 struct omap_dss_device *dssdev = td->dssdev;
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001829 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001830 u8 state1, state2;
1831 int r;
1832
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001833 mutex_lock(&td->lock);
1834
1835 if (!td->enabled) {
1836 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001837 return;
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001838 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001839
Archit Taneja1ffefe72011-05-12 17:26:24 +05301840 dsi_bus_lock(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001841
Tomi Valkeinen1abf7812011-03-24 14:53:27 +02001842 r = taal_wake_up(dssdev);
1843 if (r) {
1844 dev_err(&dssdev->dev, "failed to exit ULPS\n");
1845 goto err;
1846 }
1847
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301848 r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001849 if (r) {
1850 dev_err(&dssdev->dev, "failed to read Taal status\n");
1851 goto err;
1852 }
1853
1854 /* Run self diagnostics */
1855 r = taal_sleep_out(td);
1856 if (r) {
1857 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
1858 goto err;
1859 }
1860
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301861 r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001862 if (r) {
1863 dev_err(&dssdev->dev, "failed to read Taal status\n");
1864 goto err;
1865 }
1866
1867 /* Each sleep out command will trigger a self diagnostic and flip
1868 * Bit6 if the test passes.
1869 */
1870 if (!((state1 ^ state2) & (1 << 6))) {
1871 dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
1872 goto err;
1873 }
1874 /* Self-diagnostics result is also shown on TE GPIO line. We need
1875 * to re-enable TE after self diagnostics */
Tomi Valkeinen8d3573c2010-06-09 15:23:44 +03001876 if (td->te_enabled && panel_data->use_ext_te) {
Archit Tanejabc6d4b12011-03-01 13:59:46 +05301877 r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
Tomi Valkeinen1189b7f2010-03-01 13:52:10 +02001878 if (r)
1879 goto err;
1880 }
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001881
Archit Taneja1ffefe72011-05-12 17:26:24 +05301882 dsi_bus_unlock(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001883
Tomi Valkeinen1663d2f2011-03-24 14:01:49 +02001884 taal_queue_esd_work(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001885
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001886 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001887 return;
1888err:
1889 dev_err(&dssdev->dev, "performing LCD reset\n");
1890
Tomi Valkeinenbb5476c72011-03-24 15:00:06 +02001891 taal_panel_reset(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001892
Archit Taneja1ffefe72011-05-12 17:26:24 +05301893 dsi_bus_unlock(dssdev);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001894
Tomi Valkeinen1663d2f2011-03-24 14:01:49 +02001895 taal_queue_esd_work(dssdev);
Tomi Valkeinena3201a02010-03-03 14:31:45 +02001896
1897 mutex_unlock(&td->lock);
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001898}
1899
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001900static int taal_set_update_mode(struct omap_dss_device *dssdev,
1901 enum omap_dss_update_mode mode)
1902{
1903 if (mode != OMAP_DSS_UPDATE_MANUAL)
1904 return -EINVAL;
1905 return 0;
1906}
1907
1908static enum omap_dss_update_mode taal_get_update_mode(
1909 struct omap_dss_device *dssdev)
1910{
1911 return OMAP_DSS_UPDATE_MANUAL;
1912}
1913
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001914static struct omap_dss_driver taal_driver = {
1915 .probe = taal_probe,
Tomi Valkeinen14e4d782011-03-31 12:03:51 +03001916 .remove = __exit_p(taal_remove),
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001917
1918 .enable = taal_enable,
1919 .disable = taal_disable,
1920 .suspend = taal_suspend,
1921 .resume = taal_resume,
1922
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001923 .set_update_mode = taal_set_update_mode,
1924 .get_update_mode = taal_get_update_mode,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02001925
1926 .update = taal_update,
1927 .sync = taal_sync,
1928
Tomi Valkeinen96adcec2010-01-11 13:54:33 +02001929 .get_resolution = taal_get_resolution,
Tomi Valkeinena2699502010-01-11 14:33:40 +02001930 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1931
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001932 .enable_te = taal_enable_te,
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001933 .get_te = taal_get_te,
Tomi Valkeinen225b6502010-01-11 15:11:01 +02001934
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001935 .set_rotate = taal_rotate,
1936 .get_rotate = taal_get_rotate,
1937 .set_mirror = taal_mirror,
1938 .get_mirror = taal_get_mirror,
1939 .run_test = taal_run_test,
1940 .memory_read = taal_memory_read,
1941
Tomi Valkeinen69b20482010-01-20 12:11:25 +02001942 .get_timings = taal_get_timings,
1943
Tomi Valkeinenf133a9d2009-10-28 11:31:05 +02001944 .driver = {
1945 .name = "taal",
1946 .owner = THIS_MODULE,
1947 },
1948};
1949
1950static int __init taal_init(void)
1951{
1952 omap_dss_register_driver(&taal_driver);
1953
1954 return 0;
1955}
1956
1957static void __exit taal_exit(void)
1958{
1959 omap_dss_unregister_driver(&taal_driver);
1960}
1961
1962module_init(taal_init);
1963module_exit(taal_exit);
1964
1965MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
1966MODULE_DESCRIPTION("Taal Driver");
1967MODULE_LICENSE("GPL");