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