blob: 41290f54d5aac07a7cf7a60dced7d2c2bca598d9 [file] [log] [blame]
Channagoud Kadabi43000a62012-06-28 18:23:24 +05301/*
Duy Truongf3ac7b32013-02-13 01:07:28 -08002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Channagoud Kadabi43000a62012-06-28 18:23:24 +05303 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in
11 * the documentation and/or other materials provided with the
12 * distribution.
Duy Truongf3ac7b32013-02-13 01:07:28 -080013 * * Neither the name of The Linux Foundation nor
Channagoud Kadabi43000a62012-06-28 18:23:24 +053014 * the names of its contributors may be used to endorse or promote
15 * products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#include <msm_panel.h>
32#include <platform/gpio.h>
33#include <debug.h>
34#include <err.h>
35#include "lcdc_truly.h"
36
37extern void spi_bit_bang_write(uint8_t, uint8_t, uint8_t, uint8_t);
38
39static char data1[] = { 0xff, 0x83, 0x57, };
40static char data2[] = { 0x03, };
41static char data3[] = { 0x00, 0x13, 0x1C, 0x1C, 0x83, 0x48, };
42static char data4[] = { 0x43, 0x06, 0x06, 0x06, };
43static char data5[] = { 0x53, };
44static char data6[] = { 0x02, 0x40, 0x00, 0x2a, 0x2a, 0x0d, 0x3f, };
45static char data7[] = { 0x70, 0x50, 0x01, 0x3c, 0xe8, 0x08, };
46static char data8[] = { 0x17, 0x0f, };
47static char data9[] = { 0x60};
48static char data10[] = { 0x00, 0x13, 0x1a, 0x29, 0x2d, 0x41, 0x49,
49 0x52, 0x48, 0x41, 0x3c, 0x33, 0x30, 0x1c,
50 0x19, 0x03, 0x00, 0x13, 0x1a, 0x29, 0x2d,
51 0x41, 0x49, 0x52, 0x48, 0x41, 0x3c, 0x33,
52 0x31, 0x1c, 0x19, 0x03, 0x00, 0x01,
53};
54static char data11[] = { 0x40, };
55
56static void lcdc_truly_panel_power(int on)
57{
58 uint32_t func = 0;
59 uint32_t pull = 0;
60 uint32_t drv = 0;
61 uint32_t dir = 0;
62
63 dprintf(SPEW, "lcdc_truly_panel_power on = %d\n", on);
64
65 if (on) {
66 func = 0;
67 dir = GPIO_OUTPUT;
68 pull = GPIO_NO_PULL;
69 drv = GPIO_2MA;
70
71 /* config SPI, RESET and Backlight */
72 gpio_tlmm_config(GPIO_CFG(SPI_MOSI, func, dir, pull, drv), 0);
73 gpio_tlmm_config(GPIO_CFG(SPI_SCLK, func, dir, pull, drv), 0);
74 gpio_tlmm_config(GPIO_CFG(SPI_CS, func, dir, pull, drv), 0);
75 gpio_tlmm_config(GPIO_CFG(BACKLIGHT_EN, func, dir, pull, drv), 0);
76 gpio_tlmm_config(GPIO_CFG(DISPLAY_RESET, func, dir, pull, drv), 0);
77 gpio_tlmm_config(GPIO_CFG(LCD_LDO_2V8, func, dir, pull, drv), 0);
78 gpio_tlmm_config(GPIO_CFG(LCD_LDO_1V8, func, dir, pull, drv), 0);
79
80 gpio_config(SPI_MOSI, GPIO_OUTPUT);
81 gpio_config(SPI_SCLK, GPIO_OUTPUT);
82 gpio_config(SPI_CS, GPIO_OUTPUT);
83 gpio_config(BACKLIGHT_EN, GPIO_OUTPUT);
84 gpio_config(DISPLAY_RESET, GPIO_OUTPUT);
85 gpio_config(LCD_LDO_2V8, GPIO_OUTPUT);
86 gpio_config(LCD_LDO_1V8, GPIO_OUTPUT);
87
88 /* turn on backlight */
89 gpio_set(BACKLIGHT_EN, 1);
90 /* turn on power */
91 gpio_set(LCD_LDO_1V8, 1);
92 gpio_set(LCD_LDO_2V8, 1);
93
94 /* reset */
95 gpio_set(DISPLAY_RESET, 1);
96 /*
97 * H/w requires delay between toggle
98 * reset pin
99 */
100 mdelay(20);
101 gpio_set(DISPLAY_RESET, 0);
102 mdelay(20);
103 gpio_set(DISPLAY_RESET, 1);
104 mdelay(20);
105 } else {
106 /* turn off backlight */
107 gpio_set(BACKLIGHT_EN, 0);
108
109 gpio_set(DISPLAY_RESET, 0);
110
111 /* turn off power */
112 gpio_set(LCD_LDO_1V8, 0);
113 gpio_set(LCD_LDO_2V8, 0);
114 }
115 return;
116}
117
118static int truly_spi_write(char cmd, char *data, int num)
119{
120 int i;
121
122 gpio_set(SPI_CS, 0); /* cs low */
123 /* command byte first */
124 spi_bit_bang_write(SPI_SCLK, SPI_MOSI, 0, cmd);
125 /* followed by parameter bytes */
126 for(i = 0; i < num; i++) {
127 if(data)
128 spi_bit_bang_write(SPI_SCLK, SPI_MOSI, 1, data[i]);
129 }
130 gpio_set(SPI_MOSI, 1); /* mosi high */
131 gpio_set(SPI_CS, 1); /* cs high */
132 /*
133 * H/W needs delay for gpio's to turn high
134 */
135 udelay(10);
136 return 0;
137}
138
139void lcdc_truly_disp_on(void)
140{
141 int i;
142
143 dprintf(SPEW, "lcdc_truly_disp_on\n");
144
145 gpio_set(SPI_CS, 1); /* cs high */
146 /*
147 * This function uses delays as defined by the panel
148 * vendor before writing to registers
149 */
150 truly_spi_write(0xb9, data1, sizeof(data1));
151 mdelay(20);
152 truly_spi_write(0xcc, data2, sizeof(data2));
153 truly_spi_write(0xb1, data3, sizeof(data3));
154 truly_spi_write(0xb3, data4, sizeof(data4));
155 truly_spi_write(0xb6, data5, sizeof(data5));
156 truly_spi_write(0xb4, data6, sizeof(data6));
157 truly_spi_write(0xc0, data7, sizeof(data7));
158 truly_spi_write(0xe3, data8, sizeof(data8));
159 truly_spi_write(0x3a, data9, sizeof(data9));
160 truly_spi_write(0xe0, data10, sizeof(data10));
161 truly_spi_write(0x36, data11, sizeof(data11));
162 truly_spi_write(0x11, NULL, 0);
163 mdelay(150);
164 truly_spi_write(0x29, NULL, 0);
165 mdelay(25);
166}
167
168void lcdc_truly_disp_off(void)
169{
170 dprintf(SPEW, "lcdc_truly_disp_off\n");
171 truly_spi_write(0x28, NULL, 0);
172 mdelay(5);
173 truly_spi_write(0x10, NULL, 0);
174}
175
176int lcdc_truly_panel_on(int on)
177{
178 dprintf(SPEW, "lcdc_truly_panel_on\n");
179 if (on) {
180 lcdc_truly_panel_power(1);
181 lcdc_truly_disp_on();
182 } else {
183 lcdc_truly_panel_power(0);
184 lcdc_truly_disp_off();
185 }
186 return NO_ERROR;
187}
188
189int lcdc_truly_hvga_on()
190{
191 return NO_ERROR;
192}
193
194int lcdc_truly_hvga_off()
195{
196 return NO_ERROR;
197}
198
199void lcdc_truly_hvga_init(struct msm_panel_info *pinfo)
200{
201 if (!pinfo)
202 return;
203
204 pinfo->xres = 320;
205 pinfo->yres = 480;
206
207 pinfo->type = LCDC_PANEL;
208 pinfo->wait_cycle = 0;
209 pinfo->bpp = 16;
210 pinfo->clk_rate = 10240000;
211 pinfo->lcdc.h_pulse_width = 8;
212 pinfo->lcdc.h_back_porch = 16;
213 pinfo->lcdc.h_front_porch = 4;
214 pinfo->lcdc.hsync_skew = 0;
215 pinfo->lcdc.v_pulse_width = 1;
216 pinfo->lcdc.v_back_porch = 7;
217 pinfo->lcdc.v_front_porch = 3;
218
219 pinfo->on = lcdc_truly_hvga_on;
220 pinfo->off = lcdc_truly_hvga_off;
221
222 return;
223}