2 * lms501kf03 TFT LCD panel driver.
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Author: Jingoo Han <jg1.han@samsung.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 #include <linux/backlight.h>
14 #include <linux/delay.h>
16 #include <linux/gpio.h>
17 #include <linux/lcd.h>
18 #include <linux/module.h>
19 #include <linux/spi/spi.h>
20 #include <linux/wait.h>
22 #define COMMAND_ONLY 0x00
23 #define DATA_ONLY 0x01
27 struct spi_device
*spi
;
29 struct lcd_device
*ld
;
30 struct lcd_platform_data
*lcd_pd
;
33 static const unsigned char seq_password
[] = {
34 0xb9, 0xff, 0x83, 0x69,
37 static const unsigned char seq_power
[] = {
38 0xb1, 0x01, 0x00, 0x34, 0x06, 0x00, 0x14, 0x14, 0x20, 0x28,
39 0x12, 0x12, 0x17, 0x0a, 0x01, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6,
42 static const unsigned char seq_display
[] = {
43 0xb2, 0x00, 0x2b, 0x03, 0x03, 0x70, 0x00, 0xff, 0x00, 0x00,
44 0x00, 0x00, 0x03, 0x03, 0x00, 0x01,
47 static const unsigned char seq_rgb_if
[] = {
51 static const unsigned char seq_display_inv
[] = {
52 0xb4, 0x01, 0x08, 0x77, 0x0e, 0x06,
55 static const unsigned char seq_vcom
[] = {
59 static const unsigned char seq_gate
[] = {
60 0xd5, 0x00, 0x05, 0x03, 0x29, 0x01, 0x07, 0x17, 0x68, 0x13,
61 0x37, 0x20, 0x31, 0x8a, 0x46, 0x9b, 0x57, 0x13, 0x02, 0x75,
62 0xb9, 0x64, 0xa8, 0x07, 0x0f, 0x04, 0x07,
65 static const unsigned char seq_panel
[] = {
69 static const unsigned char seq_col_mod
[] = {
73 static const unsigned char seq_w_gamma
[] = {
74 0xe0, 0x00, 0x04, 0x09, 0x0f, 0x1f, 0x3f, 0x1f, 0x2f, 0x0a,
75 0x0f, 0x10, 0x16, 0x18, 0x16, 0x17, 0x0d, 0x15, 0x00, 0x04,
76 0x09, 0x0f, 0x38, 0x3f, 0x20, 0x39, 0x0a, 0x0f, 0x10, 0x16,
77 0x18, 0x16, 0x17, 0x0d, 0x15,
80 static const unsigned char seq_rgb_gamma
[] = {
81 0xc1, 0x01, 0x03, 0x07, 0x0f, 0x1a, 0x22, 0x2c, 0x33, 0x3c,
82 0x46, 0x4f, 0x58, 0x60, 0x69, 0x71, 0x79, 0x82, 0x89, 0x92,
83 0x9a, 0xa1, 0xa9, 0xb1, 0xb9, 0xc1, 0xc9, 0xcf, 0xd6, 0xde,
84 0xe5, 0xec, 0xf3, 0xf9, 0xff, 0xdd, 0x39, 0x07, 0x1c, 0xcb,
85 0xab, 0x5f, 0x49, 0x80, 0x03, 0x07, 0x0f, 0x19, 0x20, 0x2a,
86 0x31, 0x39, 0x42, 0x4b, 0x53, 0x5b, 0x63, 0x6b, 0x73, 0x7b,
87 0x83, 0x8a, 0x92, 0x9b, 0xa2, 0xaa, 0xb2, 0xba, 0xc2, 0xca,
88 0xd0, 0xd8, 0xe1, 0xe8, 0xf0, 0xf8, 0xff, 0xf7, 0xd8, 0xbe,
89 0xa7, 0x39, 0x40, 0x85, 0x8c, 0xc0, 0x04, 0x07, 0x0c, 0x17,
90 0x1c, 0x23, 0x2b, 0x34, 0x3b, 0x43, 0x4c, 0x54, 0x5b, 0x63,
91 0x6a, 0x73, 0x7a, 0x82, 0x8a, 0x91, 0x98, 0xa1, 0xa8, 0xb0,
92 0xb7, 0xc1, 0xc9, 0xcf, 0xd9, 0xe3, 0xea, 0xf4, 0xff, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 static const unsigned char seq_up_dn
[] = {
100 static const unsigned char seq_sleep_in
[] = {
104 static const unsigned char seq_sleep_out
[] = {
108 static const unsigned char seq_display_on
[] = {
112 static const unsigned char seq_display_off
[] = {
116 static int lms501kf03_spi_write_byte(struct lms501kf03
*lcd
, int addr
, int data
)
119 struct spi_message msg
;
121 struct spi_transfer xfer
= {
126 buf
[0] = (addr
<< 8) | data
;
128 spi_message_init(&msg
);
129 spi_message_add_tail(&xfer
, &msg
);
131 return spi_sync(lcd
->spi
, &msg
);
134 static int lms501kf03_spi_write(struct lms501kf03
*lcd
, unsigned char address
,
135 unsigned char command
)
137 return lms501kf03_spi_write_byte(lcd
, address
, command
);
140 static int lms501kf03_panel_send_sequence(struct lms501kf03
*lcd
,
141 const unsigned char *wbuf
,
148 ret
= lms501kf03_spi_write(lcd
, COMMAND_ONLY
, wbuf
[i
]);
150 ret
= lms501kf03_spi_write(lcd
, DATA_ONLY
, wbuf
[i
]);
159 static int lms501kf03_ldi_init(struct lms501kf03
*lcd
)
162 static const unsigned char *init_seq
[] = {
177 static const unsigned int size_seq
[] = {
178 ARRAY_SIZE(seq_password
),
179 ARRAY_SIZE(seq_power
),
180 ARRAY_SIZE(seq_display
),
181 ARRAY_SIZE(seq_rgb_if
),
182 ARRAY_SIZE(seq_display_inv
),
183 ARRAY_SIZE(seq_vcom
),
184 ARRAY_SIZE(seq_gate
),
185 ARRAY_SIZE(seq_panel
),
186 ARRAY_SIZE(seq_col_mod
),
187 ARRAY_SIZE(seq_w_gamma
),
188 ARRAY_SIZE(seq_rgb_gamma
),
189 ARRAY_SIZE(seq_sleep_out
),
192 for (i
= 0; i
< ARRAY_SIZE(init_seq
); i
++) {
193 ret
= lms501kf03_panel_send_sequence(lcd
, init_seq
[i
],
199 * According to the datasheet, 120ms delay time is required.
200 * After sleep out sequence, command is blocked for 120ms.
201 * Thus, LDI should wait for 120ms.
208 static int lms501kf03_ldi_enable(struct lms501kf03
*lcd
)
210 return lms501kf03_panel_send_sequence(lcd
, seq_display_on
,
211 ARRAY_SIZE(seq_display_on
));
214 static int lms501kf03_ldi_disable(struct lms501kf03
*lcd
)
216 return lms501kf03_panel_send_sequence(lcd
, seq_display_off
,
217 ARRAY_SIZE(seq_display_off
));
220 static int lms501kf03_power_is_on(int power
)
222 return (power
) <= FB_BLANK_NORMAL
;
225 static int lms501kf03_power_on(struct lms501kf03
*lcd
)
228 struct lcd_platform_data
*pd
;
233 dev_err(lcd
->dev
, "power_on is NULL.\n");
237 pd
->power_on(lcd
->ld
, 1);
238 msleep(pd
->power_on_delay
);
241 dev_err(lcd
->dev
, "reset is NULL.\n");
246 msleep(pd
->reset_delay
);
248 ret
= lms501kf03_ldi_init(lcd
);
250 dev_err(lcd
->dev
, "failed to initialize ldi.\n");
254 ret
= lms501kf03_ldi_enable(lcd
);
256 dev_err(lcd
->dev
, "failed to enable ldi.\n");
263 static int lms501kf03_power_off(struct lms501kf03
*lcd
)
266 struct lcd_platform_data
*pd
;
270 ret
= lms501kf03_ldi_disable(lcd
);
272 dev_err(lcd
->dev
, "lcd setting failed.\n");
276 msleep(pd
->power_off_delay
);
278 pd
->power_on(lcd
->ld
, 0);
283 static int lms501kf03_power(struct lms501kf03
*lcd
, int power
)
287 if (lms501kf03_power_is_on(power
) &&
288 !lms501kf03_power_is_on(lcd
->power
))
289 ret
= lms501kf03_power_on(lcd
);
290 else if (!lms501kf03_power_is_on(power
) &&
291 lms501kf03_power_is_on(lcd
->power
))
292 ret
= lms501kf03_power_off(lcd
);
300 static int lms501kf03_get_power(struct lcd_device
*ld
)
302 struct lms501kf03
*lcd
= lcd_get_data(ld
);
307 static int lms501kf03_set_power(struct lcd_device
*ld
, int power
)
309 struct lms501kf03
*lcd
= lcd_get_data(ld
);
311 if (power
!= FB_BLANK_UNBLANK
&& power
!= FB_BLANK_POWERDOWN
&&
312 power
!= FB_BLANK_NORMAL
) {
313 dev_err(lcd
->dev
, "power value should be 0, 1 or 4.\n");
317 return lms501kf03_power(lcd
, power
);
320 static struct lcd_ops lms501kf03_lcd_ops
= {
321 .get_power
= lms501kf03_get_power
,
322 .set_power
= lms501kf03_set_power
,
325 static int lms501kf03_probe(struct spi_device
*spi
)
327 struct lms501kf03
*lcd
= NULL
;
328 struct lcd_device
*ld
= NULL
;
331 lcd
= devm_kzalloc(&spi
->dev
, sizeof(struct lms501kf03
), GFP_KERNEL
);
335 /* lms501kf03 lcd panel uses 3-wire 9-bit SPI Mode. */
336 spi
->bits_per_word
= 9;
338 ret
= spi_setup(spi
);
340 dev_err(&spi
->dev
, "spi setup failed.\n");
345 lcd
->dev
= &spi
->dev
;
347 lcd
->lcd_pd
= dev_get_platdata(&spi
->dev
);
349 dev_err(&spi
->dev
, "platform data is NULL\n");
353 ld
= devm_lcd_device_register(&spi
->dev
, "lms501kf03", &spi
->dev
, lcd
,
354 &lms501kf03_lcd_ops
);
360 if (!lcd
->lcd_pd
->lcd_enabled
) {
362 * if lcd panel was off from bootloader then
363 * current lcd status is powerdown and then
364 * it enables lcd panel.
366 lcd
->power
= FB_BLANK_POWERDOWN
;
368 lms501kf03_power(lcd
, FB_BLANK_UNBLANK
);
370 lcd
->power
= FB_BLANK_UNBLANK
;
373 spi_set_drvdata(spi
, lcd
);
375 dev_info(&spi
->dev
, "lms501kf03 panel driver has been probed.\n");
380 static int lms501kf03_remove(struct spi_device
*spi
)
382 struct lms501kf03
*lcd
= spi_get_drvdata(spi
);
384 lms501kf03_power(lcd
, FB_BLANK_POWERDOWN
);
388 #ifdef CONFIG_PM_SLEEP
389 static int lms501kf03_suspend(struct device
*dev
)
391 struct lms501kf03
*lcd
= dev_get_drvdata(dev
);
393 dev_dbg(dev
, "lcd->power = %d\n", lcd
->power
);
396 * when lcd panel is suspend, lcd panel becomes off
397 * regardless of status.
399 return lms501kf03_power(lcd
, FB_BLANK_POWERDOWN
);
402 static int lms501kf03_resume(struct device
*dev
)
404 struct lms501kf03
*lcd
= dev_get_drvdata(dev
);
406 lcd
->power
= FB_BLANK_POWERDOWN
;
408 return lms501kf03_power(lcd
, FB_BLANK_UNBLANK
);
412 static SIMPLE_DEV_PM_OPS(lms501kf03_pm_ops
, lms501kf03_suspend
,
415 static void lms501kf03_shutdown(struct spi_device
*spi
)
417 struct lms501kf03
*lcd
= spi_get_drvdata(spi
);
419 lms501kf03_power(lcd
, FB_BLANK_POWERDOWN
);
422 static struct spi_driver lms501kf03_driver
= {
424 .name
= "lms501kf03",
425 .pm
= &lms501kf03_pm_ops
,
427 .probe
= lms501kf03_probe
,
428 .remove
= lms501kf03_remove
,
429 .shutdown
= lms501kf03_shutdown
,
432 module_spi_driver(lms501kf03_driver
);
434 MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
435 MODULE_DESCRIPTION("lms501kf03 LCD Driver");
436 MODULE_LICENSE("GPL");