23 #include <linux/wait.h>
30 #include <linux/kernel.h>
33 #include <linux/module.h>
38 #define SLEEPMSEC 0x1000
40 #define DEFMASK 0xFF00
41 #define COMMAND_ONLY 0xFE
42 #define DATA_ONLY 0xFF
44 #define MIN_BRIGHTNESS 0
45 #define MAX_BRIGHTNESS 24
46 #define power_is_on(pwr) ((pwr) <= FB_BLANK_NORMAL)
63 { .supply =
"vdd3", },
67 static void ld9040_regulator_enable(
struct ld9040 *
lcd)
86 static void ld9040_regulator_disable(
struct ld9040 *lcd)
102 static const unsigned short seq_swreset[] = {
107 static const unsigned short seq_user_setting[] = {
114 static const unsigned short seq_elvss_on[] = {
122 static const unsigned short seq_gtcon[] = {
130 static const unsigned short seq_panel_condition[] = {
158 static const unsigned short seq_gamma_set1[] = {
184 static const unsigned short seq_gamma_ctrl[] = {
191 static const unsigned short seq_gamma_start[] = {
197 static const unsigned short seq_apon[] = {
207 static const unsigned short seq_display_ctrl[] = {
217 static const unsigned short seq_manual_pwr[] = {
222 static const unsigned short seq_pwr_ctrl[] = {
234 static const unsigned short seq_sleep_out[] = {
239 static const unsigned short seq_sleep_in[] = {
244 static const unsigned short seq_display_on[] = {
249 static const unsigned short seq_display_off[] = {
254 static const unsigned short seq_vci1_1st_en[] = {
264 static const unsigned short seq_vl1_en[] = {
274 static const unsigned short seq_vl2_en[] = {
284 static const unsigned short seq_vci1_2nd_en[] = {
294 static const unsigned short seq_vl3_en[] = {
304 static const unsigned short seq_vreg1_amp_en[] = {
314 static const unsigned short seq_vgh_amp_en[] = {
324 static const unsigned short seq_vgl_amp_en[] = {
334 static const unsigned short seq_vmos_amp_en[] = {
344 static const unsigned short seq_vint_amp_en[] = {
356 static const unsigned short seq_vbh_amp_en[] = {
366 static const unsigned short seq_vbl_amp_en[] = {
376 static const unsigned short seq_gam_amp_en[] = {
388 static const unsigned short seq_sd_amp_en[] = {
400 static const unsigned short seq_gls_en[] = {
412 static const unsigned short seq_els_en[] = {
424 static const unsigned short seq_el_on[] = {
436 static int ld9040_spi_write_byte(
struct ld9040 *lcd,
int addr,
int data)
446 buf[0] = (addr << 8) | data;
448 spi_message_init(&
msg);
449 spi_message_add_tail(&xfer, &
msg);
454 static int ld9040_spi_write(
struct ld9040 *lcd,
unsigned char address,
460 ret = ld9040_spi_write_byte(lcd, 0x0, address);
462 ret = ld9040_spi_write_byte(lcd, 0x1, command);
467 static int ld9040_panel_send_sequence(
struct ld9040 *lcd,
468 const unsigned short *wbuf)
474 ret = ld9040_spi_write(lcd, wbuf[
i], wbuf[i+1]);
485 static int _ld9040_gamma_ctl(
struct ld9040 *lcd,
const unsigned int *
gamma)
491 ret = ld9040_panel_send_sequence(lcd, seq_gamma_start);
493 dev_err(lcd->
dev,
"failed to disable gamma table updating.\n");
498 ret = ld9040_spi_write(lcd,
DATA_ONLY, gamma[i]);
500 dev_err(lcd->
dev,
"failed to set gamma table.\n");
506 ret = ld9040_panel_send_sequence(lcd, seq_gamma_ctrl);
508 dev_err(lcd->
dev,
"failed to update gamma table.\n");
514 static int ld9040_gamma_ctl(
struct ld9040 *lcd,
int gamma)
518 ret = _ld9040_gamma_ctl(lcd,
gamma_table.gamma_22_table[gamma]);
524 static int ld9040_ldi_init(
struct ld9040 *lcd)
527 static const unsigned short *init_seq[] = {
540 ret = ld9040_panel_send_sequence(lcd, init_seq[i]);
550 static int ld9040_ldi_enable(
struct ld9040 *lcd)
554 ret = ld9040_panel_send_sequence(lcd, seq_display_on);
559 static int ld9040_ldi_disable(
struct ld9040 *lcd)
563 ret = ld9040_panel_send_sequence(lcd, seq_display_off);
564 ret = ld9040_panel_send_sequence(lcd, seq_sleep_in);
569 static int ld9040_power_on(
struct ld9040 *lcd)
575 dev_err(lcd->
dev,
"platform data is NULL.\n");
580 ld9040_regulator_enable(lcd);
590 ret = ld9040_ldi_init(lcd);
592 dev_err(lcd->
dev,
"failed to initialize ldi.\n");
596 ret = ld9040_ldi_enable(lcd);
605 static int ld9040_power_off(
struct ld9040 *lcd)
612 dev_err(lcd->
dev,
"platform data is NULL.\n");
616 ret = ld9040_ldi_disable(lcd);
625 ld9040_regulator_disable(lcd);
630 static int ld9040_power(
struct ld9040 *lcd,
int power)
635 ret = ld9040_power_on(lcd);
637 ret = ld9040_power_off(lcd);
645 static int ld9040_set_power(
struct lcd_device *
ld,
int power)
647 struct ld9040 *lcd = lcd_get_data(ld);
651 dev_err(lcd->
dev,
"power value should be 0, 1 or 4.\n");
655 return ld9040_power(lcd, power);
658 static int ld9040_get_power(
struct lcd_device *ld)
660 struct ld9040 *lcd = lcd_get_data(ld);
667 return bd->
props.brightness;
673 struct ld9040 *lcd = bl_get_data(bd);
677 dev_err(&bd->
dev,
"lcd brightness should be %d to %d.\n",
682 ret = ld9040_gamma_ctl(lcd, bd->
props.brightness);
684 dev_err(&bd->
dev,
"lcd brightness setting failed.\n");
691 static struct lcd_ops ld9040_lcd_ops = {
692 .set_power = ld9040_set_power,
693 .get_power = ld9040_get_power,
697 .get_brightness = ld9040_get_brightness,
698 .update_status = ld9040_set_brightness,
724 lcd->dev = &spi->
dev;
726 lcd->lcd_pd = spi->
dev.platform_data;
728 dev_err(&spi->
dev,
"platform data is NULL.\n");
736 dev_err(lcd->dev,
"Failed to get regulators: %d\n", ret);
743 goto out_free_regulator;
753 lcd, &ld9040_backlight_ops, &props);
756 goto out_unregister_lcd;
766 if (!lcd->lcd_pd->lcd_enabled) {
780 dev_info(&spi->
dev,
"ld9040 panel driver has been probed.\n");
803 #if defined(CONFIG_PM)
832 #define ld9040_suspend NULL
833 #define ld9040_resume NULL
837 static void ld9040_shutdown(
struct spi_device *spi)
849 .probe = ld9040_probe,
851 .shutdown = ld9040_shutdown,