blob: a52a6a7e572ed4ccaaf98e560999a2f4a2ad387b [file] [log] [blame]
Donghwa Lee1baf0eb2011-03-22 16:30:18 -07001/*
2 * ld9040 AMOLED LCD panel driver.
3 *
4 * Copyright (c) 2011 Samsung Electronics
5 * Author: Donghwa Lee <dh09.lee@samsung.com>
6 * Derived from drivers/video/backlight/s6e63m0.c
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23#include <linux/wait.h>
24#include <linux/fb.h>
25#include <linux/delay.h>
26#include <linux/gpio.h>
27#include <linux/spi/spi.h>
28#include <linux/irq.h>
29#include <linux/interrupt.h>
30#include <linux/kernel.h>
31#include <linux/lcd.h>
32#include <linux/backlight.h>
Paul Gortmaker355b2002011-07-03 16:17:28 -040033#include <linux/module.h>
Donghwa Leeb148a272012-01-10 15:09:15 -080034#include <linux/regulator/consumer.h>
Donghwa Lee1baf0eb2011-03-22 16:30:18 -070035
36#include "ld9040_gamma.h"
37
38#define SLEEPMSEC 0x1000
39#define ENDDEF 0x2000
40#define DEFMASK 0xFF00
41#define COMMAND_ONLY 0xFE
42#define DATA_ONLY 0xFF
43
44#define MIN_BRIGHTNESS 0
45#define MAX_BRIGHTNESS 24
46#define power_is_on(pwr) ((pwr) <= FB_BLANK_NORMAL)
47
48struct ld9040 {
49 struct device *dev;
50 struct spi_device *spi;
51 unsigned int power;
52 unsigned int current_brightness;
53
54 struct lcd_device *ld;
55 struct backlight_device *bd;
56 struct lcd_platform_data *lcd_pd;
Donghwa Leeb148a272012-01-10 15:09:15 -080057
58 struct mutex lock;
59 bool enabled;
Donghwa Lee1baf0eb2011-03-22 16:30:18 -070060};
61
Donghwa Leeb148a272012-01-10 15:09:15 -080062static struct regulator_bulk_data supplies[] = {
63 { .supply = "vdd3", },
64 { .supply = "vci", },
65};
66
67static void ld9040_regulator_enable(struct ld9040 *lcd)
68{
69 int ret = 0;
70 struct lcd_platform_data *pd = NULL;
71
72 pd = lcd->lcd_pd;
73 mutex_lock(&lcd->lock);
74 if (!lcd->enabled) {
75 ret = regulator_bulk_enable(ARRAY_SIZE(supplies), supplies);
76 if (ret)
77 goto out;
78
79 lcd->enabled = true;
80 }
Jingoo Hand2fff292013-02-21 16:43:15 -080081 msleep(pd->power_on_delay);
Donghwa Leeb148a272012-01-10 15:09:15 -080082out:
83 mutex_unlock(&lcd->lock);
84}
85
86static void ld9040_regulator_disable(struct ld9040 *lcd)
87{
88 int ret = 0;
89
90 mutex_lock(&lcd->lock);
91 if (lcd->enabled) {
92 ret = regulator_bulk_disable(ARRAY_SIZE(supplies), supplies);
93 if (ret)
94 goto out;
95
96 lcd->enabled = false;
97 }
98out:
99 mutex_unlock(&lcd->lock);
100}
101
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700102static const unsigned short seq_swreset[] = {
103 0x01, COMMAND_ONLY,
104 ENDDEF, 0x00
105};
106
107static const unsigned short seq_user_setting[] = {
108 0xF0, 0x5A,
109
110 DATA_ONLY, 0x5A,
111 ENDDEF, 0x00
112};
113
114static const unsigned short seq_elvss_on[] = {
115 0xB1, 0x0D,
116
117 DATA_ONLY, 0x00,
118 DATA_ONLY, 0x16,
119 ENDDEF, 0x00
120};
121
122static const unsigned short seq_gtcon[] = {
123 0xF7, 0x09,
124
125 DATA_ONLY, 0x00,
126 DATA_ONLY, 0x00,
127 ENDDEF, 0x00
128};
129
130static const unsigned short seq_panel_condition[] = {
131 0xF8, 0x05,
132
133 DATA_ONLY, 0x65,
134 DATA_ONLY, 0x96,
135 DATA_ONLY, 0x71,
136 DATA_ONLY, 0x7D,
137 DATA_ONLY, 0x19,
138 DATA_ONLY, 0x3B,
139 DATA_ONLY, 0x0D,
140 DATA_ONLY, 0x19,
141 DATA_ONLY, 0x7E,
142 DATA_ONLY, 0x0D,
143 DATA_ONLY, 0xE2,
144 DATA_ONLY, 0x00,
145 DATA_ONLY, 0x00,
146 DATA_ONLY, 0x7E,
147 DATA_ONLY, 0x7D,
148 DATA_ONLY, 0x07,
149 DATA_ONLY, 0x07,
150 DATA_ONLY, 0x20,
151 DATA_ONLY, 0x20,
152 DATA_ONLY, 0x20,
153 DATA_ONLY, 0x02,
154 DATA_ONLY, 0x02,
155 ENDDEF, 0x00
156};
157
158static const unsigned short seq_gamma_set1[] = {
159 0xF9, 0x00,
160
161 DATA_ONLY, 0xA7,
162 DATA_ONLY, 0xB4,
163 DATA_ONLY, 0xAE,
164 DATA_ONLY, 0xBF,
165 DATA_ONLY, 0x00,
166 DATA_ONLY, 0x91,
167 DATA_ONLY, 0x00,
168 DATA_ONLY, 0xB2,
169 DATA_ONLY, 0xB4,
170 DATA_ONLY, 0xAA,
171 DATA_ONLY, 0xBB,
172 DATA_ONLY, 0x00,
173 DATA_ONLY, 0xAC,
174 DATA_ONLY, 0x00,
175 DATA_ONLY, 0xB3,
176 DATA_ONLY, 0xB1,
177 DATA_ONLY, 0xAA,
178 DATA_ONLY, 0xBC,
179 DATA_ONLY, 0x00,
180 DATA_ONLY, 0xB3,
181 ENDDEF, 0x00
182};
183
184static const unsigned short seq_gamma_ctrl[] = {
185 0xFB, 0x02,
186
187 DATA_ONLY, 0x5A,
188 ENDDEF, 0x00
189};
190
191static const unsigned short seq_gamma_start[] = {
192 0xF9, COMMAND_ONLY,
193
194 ENDDEF, 0x00
195};
196
197static const unsigned short seq_apon[] = {
198 0xF3, 0x00,
199
200 DATA_ONLY, 0x00,
201 DATA_ONLY, 0x00,
202 DATA_ONLY, 0x0A,
203 DATA_ONLY, 0x02,
204 ENDDEF, 0x00
205};
206
207static const unsigned short seq_display_ctrl[] = {
208 0xF2, 0x02,
209
210 DATA_ONLY, 0x08,
211 DATA_ONLY, 0x08,
212 DATA_ONLY, 0x10,
213 DATA_ONLY, 0x10,
214 ENDDEF, 0x00
215};
216
217static const unsigned short seq_manual_pwr[] = {
218 0xB0, 0x04,
219 ENDDEF, 0x00
220};
221
222static const unsigned short seq_pwr_ctrl[] = {
223 0xF4, 0x0A,
224
225 DATA_ONLY, 0x87,
226 DATA_ONLY, 0x25,
227 DATA_ONLY, 0x6A,
228 DATA_ONLY, 0x44,
229 DATA_ONLY, 0x02,
230 DATA_ONLY, 0x88,
231 ENDDEF, 0x00
232};
233
234static const unsigned short seq_sleep_out[] = {
235 0x11, COMMAND_ONLY,
236 ENDDEF, 0x00
237};
238
239static const unsigned short seq_sleep_in[] = {
240 0x10, COMMAND_ONLY,
241 ENDDEF, 0x00
242};
243
244static const unsigned short seq_display_on[] = {
245 0x29, COMMAND_ONLY,
246 ENDDEF, 0x00
247};
248
249static const unsigned short seq_display_off[] = {
250 0x28, COMMAND_ONLY,
251 ENDDEF, 0x00
252};
253
254static const unsigned short seq_vci1_1st_en[] = {
255 0xF3, 0x10,
256
257 DATA_ONLY, 0x00,
258 DATA_ONLY, 0x00,
259 DATA_ONLY, 0x00,
260 DATA_ONLY, 0x02,
261 ENDDEF, 0x00
262};
263
264static const unsigned short seq_vl1_en[] = {
265 0xF3, 0x11,
266
267 DATA_ONLY, 0x00,
268 DATA_ONLY, 0x00,
269 DATA_ONLY, 0x00,
270 DATA_ONLY, 0x02,
271 ENDDEF, 0x00
272};
273
274static const unsigned short seq_vl2_en[] = {
275 0xF3, 0x13,
276
277 DATA_ONLY, 0x00,
278 DATA_ONLY, 0x00,
279 DATA_ONLY, 0x00,
280 DATA_ONLY, 0x02,
281 ENDDEF, 0x00
282};
283
284static const unsigned short seq_vci1_2nd_en[] = {
285 0xF3, 0x33,
286
287 DATA_ONLY, 0x00,
288 DATA_ONLY, 0x00,
289 DATA_ONLY, 0x00,
290 DATA_ONLY, 0x02,
291 ENDDEF, 0x00
292};
293
294static const unsigned short seq_vl3_en[] = {
295 0xF3, 0x37,
296
297 DATA_ONLY, 0x00,
298 DATA_ONLY, 0x00,
299 DATA_ONLY, 0x00,
300 DATA_ONLY, 0x02,
301 ENDDEF, 0x00
302};
303
304static const unsigned short seq_vreg1_amp_en[] = {
305 0xF3, 0x37,
306
307 DATA_ONLY, 0x01,
308 DATA_ONLY, 0x00,
309 DATA_ONLY, 0x00,
310 DATA_ONLY, 0x02,
311 ENDDEF, 0x00
312};
313
314static const unsigned short seq_vgh_amp_en[] = {
315 0xF3, 0x37,
316
317 DATA_ONLY, 0x11,
318 DATA_ONLY, 0x00,
319 DATA_ONLY, 0x00,
320 DATA_ONLY, 0x02,
321 ENDDEF, 0x00
322};
323
324static const unsigned short seq_vgl_amp_en[] = {
325 0xF3, 0x37,
326
327 DATA_ONLY, 0x31,
328 DATA_ONLY, 0x00,
329 DATA_ONLY, 0x00,
330 DATA_ONLY, 0x02,
331 ENDDEF, 0x00
332};
333
334static const unsigned short seq_vmos_amp_en[] = {
335 0xF3, 0x37,
336
337 DATA_ONLY, 0xB1,
338 DATA_ONLY, 0x00,
339 DATA_ONLY, 0x00,
340 DATA_ONLY, 0x03,
341 ENDDEF, 0x00
342};
343
344static const unsigned short seq_vint_amp_en[] = {
345 0xF3, 0x37,
346
347 DATA_ONLY, 0xF1,
348 /* DATA_ONLY, 0x71, VMOS/VBL/VBH not used */
349 DATA_ONLY, 0x00,
350 DATA_ONLY, 0x00,
351 DATA_ONLY, 0x03,
352 /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */
353 ENDDEF, 0x00
354};
355
356static const unsigned short seq_vbh_amp_en[] = {
357 0xF3, 0x37,
358
359 DATA_ONLY, 0xF9,
360 DATA_ONLY, 0x00,
361 DATA_ONLY, 0x00,
362 DATA_ONLY, 0x03,
363 ENDDEF, 0x00
364};
365
366static const unsigned short seq_vbl_amp_en[] = {
367 0xF3, 0x37,
368
369 DATA_ONLY, 0xFD,
370 DATA_ONLY, 0x00,
371 DATA_ONLY, 0x00,
372 DATA_ONLY, 0x03,
373 ENDDEF, 0x00
374};
375
376static const unsigned short seq_gam_amp_en[] = {
377 0xF3, 0x37,
378
379 DATA_ONLY, 0xFF,
380 /* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */
381 DATA_ONLY, 0x00,
382 DATA_ONLY, 0x00,
383 DATA_ONLY, 0x03,
384 /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */
385 ENDDEF, 0x00
386};
387
388static const unsigned short seq_sd_amp_en[] = {
389 0xF3, 0x37,
390
391 DATA_ONLY, 0xFF,
392 /* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */
393 DATA_ONLY, 0x80,
394 DATA_ONLY, 0x00,
395 DATA_ONLY, 0x03,
396 /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */
397 ENDDEF, 0x00
398};
399
400static const unsigned short seq_gls_en[] = {
401 0xF3, 0x37,
402
403 DATA_ONLY, 0xFF,
404 /* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */
405 DATA_ONLY, 0x81,
406 DATA_ONLY, 0x00,
407 DATA_ONLY, 0x03,
408 /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */
409 ENDDEF, 0x00
410};
411
412static const unsigned short seq_els_en[] = {
413 0xF3, 0x37,
414
415 DATA_ONLY, 0xFF,
416 /* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */
417 DATA_ONLY, 0x83,
418 DATA_ONLY, 0x00,
419 DATA_ONLY, 0x03,
420 /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */
421 ENDDEF, 0x00
422};
423
424static const unsigned short seq_el_on[] = {
425 0xF3, 0x37,
426
427 DATA_ONLY, 0xFF,
428 /* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */
429 DATA_ONLY, 0x87,
430 DATA_ONLY, 0x00,
431 DATA_ONLY, 0x03,
432 /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */
433 ENDDEF, 0x00
434};
435
436static int ld9040_spi_write_byte(struct ld9040 *lcd, int addr, int data)
437{
438 u16 buf[1];
439 struct spi_message msg;
440
441 struct spi_transfer xfer = {
442 .len = 2,
443 .tx_buf = buf,
444 };
445
446 buf[0] = (addr << 8) | data;
447
448 spi_message_init(&msg);
449 spi_message_add_tail(&xfer, &msg);
450
451 return spi_sync(lcd->spi, &msg);
452}
453
454static int ld9040_spi_write(struct ld9040 *lcd, unsigned char address,
455 unsigned char command)
456{
457 int ret = 0;
458
459 if (address != DATA_ONLY)
460 ret = ld9040_spi_write_byte(lcd, 0x0, address);
461 if (command != COMMAND_ONLY)
462 ret = ld9040_spi_write_byte(lcd, 0x1, command);
463
464 return ret;
465}
466
467static int ld9040_panel_send_sequence(struct ld9040 *lcd,
468 const unsigned short *wbuf)
469{
470 int ret = 0, i = 0;
471
472 while ((wbuf[i] & DEFMASK) != ENDDEF) {
473 if ((wbuf[i] & DEFMASK) != SLEEPMSEC) {
474 ret = ld9040_spi_write(lcd, wbuf[i], wbuf[i+1]);
475 if (ret)
476 break;
Jingoo Hand2fff292013-02-21 16:43:15 -0800477 } else {
478 msleep(wbuf[i+1]);
479 }
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700480 i += 2;
481 }
482
483 return ret;
484}
485
486static int _ld9040_gamma_ctl(struct ld9040 *lcd, const unsigned int *gamma)
487{
488 unsigned int i = 0;
489 int ret = 0;
490
491 /* start gamma table updating. */
492 ret = ld9040_panel_send_sequence(lcd, seq_gamma_start);
493 if (ret) {
494 dev_err(lcd->dev, "failed to disable gamma table updating.\n");
495 goto gamma_err;
496 }
497
498 for (i = 0 ; i < GAMMA_TABLE_COUNT; i++) {
499 ret = ld9040_spi_write(lcd, DATA_ONLY, gamma[i]);
500 if (ret) {
501 dev_err(lcd->dev, "failed to set gamma table.\n");
502 goto gamma_err;
503 }
504 }
505
506 /* update gamma table. */
507 ret = ld9040_panel_send_sequence(lcd, seq_gamma_ctrl);
508 if (ret)
509 dev_err(lcd->dev, "failed to update gamma table.\n");
510
511gamma_err:
512 return ret;
513}
514
515static int ld9040_gamma_ctl(struct ld9040 *lcd, int gamma)
516{
517 int ret = 0;
518
519 ret = _ld9040_gamma_ctl(lcd, gamma_table.gamma_22_table[gamma]);
520
521 return ret;
522}
523
524
525static int ld9040_ldi_init(struct ld9040 *lcd)
526{
527 int ret, i;
528 static const unsigned short *init_seq[] = {
529 seq_user_setting,
530 seq_panel_condition,
531 seq_display_ctrl,
532 seq_manual_pwr,
533 seq_elvss_on,
534 seq_gtcon,
535 seq_gamma_set1,
536 seq_gamma_ctrl,
537 seq_sleep_out,
538 };
539
540 for (i = 0; i < ARRAY_SIZE(init_seq); i++) {
541 ret = ld9040_panel_send_sequence(lcd, init_seq[i]);
542 /* workaround: minimum delay time for transferring CMD */
Jingoo Hand2fff292013-02-21 16:43:15 -0800543 usleep_range(300, 310);
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700544 if (ret)
545 break;
546 }
547
548 return ret;
549}
550
551static int ld9040_ldi_enable(struct ld9040 *lcd)
552{
553 int ret = 0;
554
555 ret = ld9040_panel_send_sequence(lcd, seq_display_on);
556
557 return ret;
558}
559
560static int ld9040_ldi_disable(struct ld9040 *lcd)
561{
562 int ret;
563
564 ret = ld9040_panel_send_sequence(lcd, seq_display_off);
565 ret = ld9040_panel_send_sequence(lcd, seq_sleep_in);
566
567 return ret;
568}
569
570static int ld9040_power_on(struct ld9040 *lcd)
571{
572 int ret = 0;
573 struct lcd_platform_data *pd = NULL;
574 pd = lcd->lcd_pd;
575 if (!pd) {
576 dev_err(lcd->dev, "platform data is NULL.\n");
577 return -EFAULT;
578 }
579
Donghwa Leeb148a272012-01-10 15:09:15 -0800580 /* lcd power on */
581 ld9040_regulator_enable(lcd);
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700582
583 if (!pd->reset) {
584 dev_err(lcd->dev, "reset is NULL.\n");
585 return -EFAULT;
586 } else {
587 pd->reset(lcd->ld);
Jingoo Hand2fff292013-02-21 16:43:15 -0800588 msleep(pd->reset_delay);
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700589 }
590
591 ret = ld9040_ldi_init(lcd);
592 if (ret) {
593 dev_err(lcd->dev, "failed to initialize ldi.\n");
594 return ret;
595 }
596
597 ret = ld9040_ldi_enable(lcd);
598 if (ret) {
599 dev_err(lcd->dev, "failed to enable ldi.\n");
600 return ret;
601 }
602
603 return 0;
604}
605
606static int ld9040_power_off(struct ld9040 *lcd)
607{
608 int ret = 0;
609 struct lcd_platform_data *pd = NULL;
610
611 pd = lcd->lcd_pd;
612 if (!pd) {
613 dev_err(lcd->dev, "platform data is NULL.\n");
614 return -EFAULT;
615 }
616
617 ret = ld9040_ldi_disable(lcd);
618 if (ret) {
619 dev_err(lcd->dev, "lcd setting failed.\n");
620 return -EIO;
621 }
622
Jingoo Hand2fff292013-02-21 16:43:15 -0800623 msleep(pd->power_off_delay);
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700624
Donghwa Leeb148a272012-01-10 15:09:15 -0800625 /* lcd power off */
626 ld9040_regulator_disable(lcd);
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700627
628 return 0;
629}
630
631static int ld9040_power(struct ld9040 *lcd, int power)
632{
633 int ret = 0;
634
635 if (power_is_on(power) && !power_is_on(lcd->power))
636 ret = ld9040_power_on(lcd);
637 else if (!power_is_on(power) && power_is_on(lcd->power))
638 ret = ld9040_power_off(lcd);
639
640 if (!ret)
641 lcd->power = power;
642
643 return ret;
644}
645
646static int ld9040_set_power(struct lcd_device *ld, int power)
647{
648 struct ld9040 *lcd = lcd_get_data(ld);
649
650 if (power != FB_BLANK_UNBLANK && power != FB_BLANK_POWERDOWN &&
651 power != FB_BLANK_NORMAL) {
652 dev_err(lcd->dev, "power value should be 0, 1 or 4.\n");
653 return -EINVAL;
654 }
655
656 return ld9040_power(lcd, power);
657}
658
659static int ld9040_get_power(struct lcd_device *ld)
660{
661 struct ld9040 *lcd = lcd_get_data(ld);
662
663 return lcd->power;
664}
665
666static int ld9040_get_brightness(struct backlight_device *bd)
667{
668 return bd->props.brightness;
669}
670
671static int ld9040_set_brightness(struct backlight_device *bd)
672{
673 int ret = 0, brightness = bd->props.brightness;
674 struct ld9040 *lcd = bl_get_data(bd);
675
676 if (brightness < MIN_BRIGHTNESS ||
677 brightness > bd->props.max_brightness) {
678 dev_err(&bd->dev, "lcd brightness should be %d to %d.\n",
679 MIN_BRIGHTNESS, MAX_BRIGHTNESS);
680 return -EINVAL;
681 }
682
683 ret = ld9040_gamma_ctl(lcd, bd->props.brightness);
684 if (ret) {
685 dev_err(&bd->dev, "lcd brightness setting failed.\n");
686 return -EIO;
687 }
688
689 return ret;
690}
691
692static struct lcd_ops ld9040_lcd_ops = {
693 .set_power = ld9040_set_power,
694 .get_power = ld9040_get_power,
695};
696
697static const struct backlight_ops ld9040_backlight_ops = {
698 .get_brightness = ld9040_get_brightness,
699 .update_status = ld9040_set_brightness,
700};
701
702
703static int ld9040_probe(struct spi_device *spi)
704{
705 int ret = 0;
706 struct ld9040 *lcd = NULL;
707 struct lcd_device *ld = NULL;
708 struct backlight_device *bd = NULL;
Axel Linef22f6a2011-07-25 17:12:01 -0700709 struct backlight_properties props;
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700710
Jingoo Han86f6be42012-05-29 15:07:23 -0700711 lcd = devm_kzalloc(&spi->dev, sizeof(struct ld9040), GFP_KERNEL);
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700712 if (!lcd)
713 return -ENOMEM;
714
715 /* ld9040 lcd panel uses 3-wire 9bits SPI Mode. */
716 spi->bits_per_word = 9;
717
718 ret = spi_setup(spi);
719 if (ret < 0) {
720 dev_err(&spi->dev, "spi setup failed.\n");
Jingoo Han86f6be42012-05-29 15:07:23 -0700721 return ret;
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700722 }
723
724 lcd->spi = spi;
725 lcd->dev = &spi->dev;
726
727 lcd->lcd_pd = spi->dev.platform_data;
728 if (!lcd->lcd_pd) {
729 dev_err(&spi->dev, "platform data is NULL.\n");
Jingoo Han86f6be42012-05-29 15:07:23 -0700730 return -EFAULT;
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700731 }
732
Donghwa Leeb148a272012-01-10 15:09:15 -0800733 mutex_init(&lcd->lock);
734
735 ret = regulator_bulk_get(lcd->dev, ARRAY_SIZE(supplies), supplies);
736 if (ret) {
737 dev_err(lcd->dev, "Failed to get regulators: %d\n", ret);
Jingoo Han86f6be42012-05-29 15:07:23 -0700738 return ret;
Donghwa Leeb148a272012-01-10 15:09:15 -0800739 }
740
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700741 ld = lcd_device_register("ld9040", &spi->dev, lcd, &ld9040_lcd_ops);
742 if (IS_ERR(ld)) {
743 ret = PTR_ERR(ld);
Jingoo Han86f6be42012-05-29 15:07:23 -0700744 goto out_free_regulator;
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700745 }
746
747 lcd->ld = ld;
748
Axel Linef22f6a2011-07-25 17:12:01 -0700749 memset(&props, 0, sizeof(struct backlight_properties));
750 props.type = BACKLIGHT_RAW;
751 props.max_brightness = MAX_BRIGHTNESS;
752
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700753 bd = backlight_device_register("ld9040-bl", &spi->dev,
Axel Linef22f6a2011-07-25 17:12:01 -0700754 lcd, &ld9040_backlight_ops, &props);
Axel Line2e7da92011-07-25 17:11:58 -0700755 if (IS_ERR(bd)) {
756 ret = PTR_ERR(bd);
757 goto out_unregister_lcd;
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700758 }
759
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700760 bd->props.brightness = MAX_BRIGHTNESS;
761 lcd->bd = bd;
762
763 /*
764 * if lcd panel was on from bootloader like u-boot then
765 * do not lcd on.
766 */
767 if (!lcd->lcd_pd->lcd_enabled) {
768 /*
769 * if lcd panel was off from bootloader then
770 * current lcd status is powerdown and then
771 * it enables lcd panel.
772 */
773 lcd->power = FB_BLANK_POWERDOWN;
774
775 ld9040_power(lcd, FB_BLANK_UNBLANK);
776 } else
777 lcd->power = FB_BLANK_UNBLANK;
778
779 dev_set_drvdata(&spi->dev, lcd);
780
781 dev_info(&spi->dev, "ld9040 panel driver has been probed.\n");
782 return 0;
783
Axel Line2e7da92011-07-25 17:11:58 -0700784out_unregister_lcd:
785 lcd_device_unregister(lcd->ld);
Jingoo Han86f6be42012-05-29 15:07:23 -0700786out_free_regulator:
Donghwa Leeb148a272012-01-10 15:09:15 -0800787 regulator_bulk_free(ARRAY_SIZE(supplies), supplies);
788
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700789 return ret;
790}
791
Bill Pemberton7e4b9d02012-11-19 13:26:34 -0500792static int ld9040_remove(struct spi_device *spi)
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700793{
794 struct ld9040 *lcd = dev_get_drvdata(&spi->dev);
795
796 ld9040_power(lcd, FB_BLANK_POWERDOWN);
Axel Line2e7da92011-07-25 17:11:58 -0700797 backlight_device_unregister(lcd->bd);
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700798 lcd_device_unregister(lcd->ld);
Donghwa Leeb148a272012-01-10 15:09:15 -0800799 regulator_bulk_free(ARRAY_SIZE(supplies), supplies);
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700800
801 return 0;
802}
803
804#if defined(CONFIG_PM)
805static int ld9040_suspend(struct spi_device *spi, pm_message_t mesg)
806{
807 int ret = 0;
808 struct ld9040 *lcd = dev_get_drvdata(&spi->dev);
809
810 dev_dbg(&spi->dev, "lcd->power = %d\n", lcd->power);
811
812 /*
813 * when lcd panel is suspend, lcd panel becomes off
814 * regardless of status.
815 */
816 ret = ld9040_power(lcd, FB_BLANK_POWERDOWN);
817
818 return ret;
819}
820
821static int ld9040_resume(struct spi_device *spi)
822{
823 int ret = 0;
824 struct ld9040 *lcd = dev_get_drvdata(&spi->dev);
825
826 lcd->power = FB_BLANK_POWERDOWN;
827
828 ret = ld9040_power(lcd, FB_BLANK_UNBLANK);
829
830 return ret;
831}
832#else
833#define ld9040_suspend NULL
834#define ld9040_resume NULL
835#endif
836
837/* Power down all displays on reboot, poweroff or halt. */
838static void ld9040_shutdown(struct spi_device *spi)
839{
840 struct ld9040 *lcd = dev_get_drvdata(&spi->dev);
841
842 ld9040_power(lcd, FB_BLANK_POWERDOWN);
843}
844
845static struct spi_driver ld9040_driver = {
846 .driver = {
847 .name = "ld9040",
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700848 .owner = THIS_MODULE,
849 },
850 .probe = ld9040_probe,
Bill Pembertond1723fa2012-11-19 13:21:09 -0500851 .remove = ld9040_remove,
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700852 .shutdown = ld9040_shutdown,
853 .suspend = ld9040_suspend,
854 .resume = ld9040_resume,
855};
856
Axel Lin462dd832012-03-23 15:01:59 -0700857module_spi_driver(ld9040_driver);
Donghwa Lee1baf0eb2011-03-22 16:30:18 -0700858
859MODULE_AUTHOR("Donghwa Lee <dh09.lee@samsung.com>");
860MODULE_DESCRIPTION("ld9040 LCD Driver");
861MODULE_LICENSE("GPL");