xref: /openbmc/u-boot/drivers/video/ld9040.c (revision 730d2544)
1 /*
2  * ld9040 AMOLED LCD panel driver.
3  *
4  * Copyright (C) 2012 Samsung Electronics
5  * Donghwa Lee <dh09.lee@samsung.com>
6  *
7  * SPDX-License-Identifier:	GPL-2.0+
8  */
9 
10 #include <common.h>
11 #include <spi.h>
12 
13 static const unsigned char SEQ_SWRESET[] = {
14 	0x01,
15 };
16 
17 static const unsigned char SEQ_USER_SETTING[] = {
18 	0xF0, 0x5A, 0x5A
19 };
20 
21 static const unsigned char SEQ_ELVSS_ON[] = {
22 	0xB1, 0x0D, 0x00, 0x16,
23 };
24 
25 static const unsigned char SEQ_TEMP_SWIRE[] = {
26 	0xB2, 0x06, 0x06, 0x06, 0x06,
27 };
28 
29 static const unsigned char SEQ_GTCON[] = {
30 	0xF7, 0x09, 0x00, 0x00,
31 };
32 
33 static const unsigned char SEQ_PANEL_CONDITION[] = {
34 	0xF8, 0x05, 0x65, 0x96, 0x71, 0x7D, 0x19, 0x3B,
35 	0x0D, 0x19, 0x7E, 0x0D, 0xE2, 0x00, 0x00, 0x7E,
36 	0x7D, 0x07, 0x07, 0x20, 0x20, 0x20, 0x02, 0x02,
37 };
38 
39 static const unsigned char SEQ_GAMMA_SET1[] = {
40 	0xF9, 0x00, 0xA7, 0xB4, 0xAE, 0xBF, 0x00, 0x91,
41 	0x00, 0xB2, 0xB4, 0xAA, 0xBB, 0x00, 0xAC, 0x00,
42 	0xB3, 0xB1, 0xAA, 0xBC, 0x00, 0xB3,
43 };
44 
45 static const unsigned char SEQ_GAMMA_CTRL[] = {
46 	0xFB, 0x02, 0x5A,
47 };
48 
49 static const unsigned char SEQ_APON[] = {
50 	0xF3, 0x00, 0x00, 0x00, 0x0A, 0x02,
51 };
52 
53 static const unsigned char SEQ_DISPCTL[] = {
54 	0xF2, 0x02, 0x08, 0x08, 0x10, 0x10,
55 };
56 
57 static const unsigned char SEQ_MANPWR[] = {
58 	0xB0, 0x04,
59 };
60 
61 static const unsigned char SEQ_PWR_CTRL[] = {
62 	0xF4, 0x0A, 0x87, 0x25, 0x6A, 0x44, 0x02, 0x88,
63 };
64 
65 static const unsigned char SEQ_SLPOUT[] = {
66 	0x11,
67 };
68 
69 static const unsigned char SEQ_SLPIN[] = {
70 	0x10,
71 };
72 
73 static const unsigned char SEQ_DISPON[] = {
74 	0x29,
75 };
76 
77 static const unsigned char SEQ_DISPOFF[] = {
78 	0x28,
79 };
80 
81 static void ld9040_spi_write(const unsigned char *wbuf, unsigned int size_cmd)
82 {
83 	int i = 0;
84 
85 	/*
86 	 * Data are transmitted in 9-bit words:
87 	 * the first bit is command/parameter, the other are the value.
88 	 * The value's LSB is shifted to MSB position, to be sent as 9th bit
89 	 */
90 
91 	unsigned int data_out = 0, data_in = 0;
92 	for (i = 0; i < size_cmd; i++) {
93 		data_out = wbuf[i] >> 1;
94 		if (i != 0)
95 			data_out += 0x0080;
96 		if (wbuf[i] & 0x01)
97 			data_out += 0x8000;
98 		spi_xfer(NULL, 9, &data_out, &data_in, SPI_XFER_BEGIN);
99 	}
100 }
101 
102 void ld9040_cfg_ldo(void)
103 {
104 	udelay(10);
105 
106 	ld9040_spi_write(SEQ_USER_SETTING,
107 					ARRAY_SIZE(SEQ_USER_SETTING));
108 	ld9040_spi_write(SEQ_PANEL_CONDITION,
109 					ARRAY_SIZE(SEQ_PANEL_CONDITION));
110 	ld9040_spi_write(SEQ_DISPCTL, ARRAY_SIZE(SEQ_DISPCTL));
111 	ld9040_spi_write(SEQ_MANPWR, ARRAY_SIZE(SEQ_MANPWR));
112 	ld9040_spi_write(SEQ_PWR_CTRL, ARRAY_SIZE(SEQ_PWR_CTRL));
113 	ld9040_spi_write(SEQ_ELVSS_ON, ARRAY_SIZE(SEQ_ELVSS_ON));
114 	ld9040_spi_write(SEQ_GTCON, ARRAY_SIZE(SEQ_GTCON));
115 	ld9040_spi_write(SEQ_GAMMA_SET1, ARRAY_SIZE(SEQ_GAMMA_SET1));
116 	ld9040_spi_write(SEQ_GAMMA_CTRL, ARRAY_SIZE(SEQ_GAMMA_CTRL));
117 	ld9040_spi_write(SEQ_SLPOUT, ARRAY_SIZE(SEQ_SLPOUT));
118 
119 	udelay(120);
120 }
121 
122 void ld9040_enable_ldo(unsigned int onoff)
123 {
124 	if (onoff)
125 		ld9040_spi_write(SEQ_DISPON, ARRAY_SIZE(SEQ_DISPON));
126 	else
127 		ld9040_spi_write(SEQ_DISPOFF, ARRAY_SIZE(SEQ_DISPOFF));
128 }
129