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