blob: 2e6719115467fcb1a930e647910c184819316cf8 [file] [log] [blame]
Wentao Xu8d6150c2011-06-22 11:03:18 -04001/*
Duy Truongf3ac7b32013-02-13 01:07:28 -08002 * Copyright (c) 2011, The Linux Foundation. All rights reserved.
Wentao Xu8d6150c2011-06-22 11:03:18 -04003 *
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
Wentao Xu8d6150c2011-06-22 11:03:18 -040014 * 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
32#include <debug.h>
33#include <dev/gpio.h>
34#include <kernel/thread.h>
35#include <platform/gpio.h>
36#include <dev/lcdc.h>
37
38#define GPIO_SET_OUT_VAL(gpio,val) (gpio_set(gpio,(val)<<1))
39
40#define LCDC_SPI_GPIO_CLK 73
41#define LCDC_SPI_GPIO_CS 72
42#define LCDC_SPI_GPIO_MOSI 70
43
44/* panel cmd addresses */
45#define PANEL_CMD_SLEEP_OUT 0x1100
46#define PANEL_CMD_RGBCTRL 0x3B00
47#define PANEL_CMD_DISP_ON 0x2900
48#define PANEL_CMD_BCTRL 0x5300
49#define PANEL_CMD_PWM_EN 0x6A17
50#define PANEL_CMD_FORMAT 0x3A00
51#define PANEL_CMD_CABC_FORCE2 0x6A18 /* backlight level */
52
53/* timing info */
54static struct lcdc_timing_parameters param = {
Ajay Dudanib01e5062011-12-03 23:23:42 -080055 .lcdc_fb_width = 480,
56 .lcdc_fb_height = 800,
57 .lcdc_hsync_pulse_width_dclk = 2,
58 .lcdc_hsync_back_porch_dclk = 14,
59 .lcdc_hsync_front_porch_dclk = 16,
60 .lcdc_hsync_skew_dclk = 0,
Wentao Xu8d6150c2011-06-22 11:03:18 -040061
Ajay Dudanib01e5062011-12-03 23:23:42 -080062 .lcdc_vsync_pulse_width_lines = 2,
63 .lcdc_vsync_back_porch_lines = 1,
64 .lcdc_vsync_front_porch_lines = 28,
Wentao Xu8d6150c2011-06-22 11:03:18 -040065};
66
67struct lcdc_timing_parameters *auo_timing_param()
68{
69 return &param;
70}
Ajay Dudanib01e5062011-12-03 23:23:42 -080071
Wentao Xu8d6150c2011-06-22 11:03:18 -040072/* spi commands */
73static void auo_spi_write_byte(uint32_t data)
74{
75 uint32_t bit;
76 uint32_t bnum;
77
78 bnum = 8;
79 bit = 0x80;
80 while (bnum--) {
81 GPIO_SET_OUT_VAL(LCDC_SPI_GPIO_CLK, 0);
82 GPIO_SET_OUT_VAL(LCDC_SPI_GPIO_MOSI, (data & bit) ? 1 : 0);
83 udelay(1);
84 GPIO_SET_OUT_VAL(LCDC_SPI_GPIO_CLK, 1);
85 udelay(1);
86 bit >>= 1;
87 }
88 GPIO_SET_OUT_VAL(LCDC_SPI_GPIO_MOSI, 0);
89}
90
Ajay Dudanib01e5062011-12-03 23:23:42 -080091static uint32_t auo_serigo(uint32_t * input_data, uint32_t input_len)
Wentao Xu8d6150c2011-06-22 11:03:18 -040092{
93 uint32_t i;
94
95 GPIO_SET_OUT_VAL(LCDC_SPI_GPIO_CS, 0);
96 udelay(2);
97
98 for (i = 0; i < input_len; ++i) {
99 auo_spi_write_byte(input_data[i]);
100 udelay(2);
101 }
102
103 GPIO_SET_OUT_VAL(LCDC_SPI_GPIO_CS, 1);
104
105 return 0;
106}
107
Ajay Dudanib01e5062011-12-03 23:23:42 -0800108static void auo_write_cmd(uint32_t cmd)
Wentao Xu8d6150c2011-06-22 11:03:18 -0400109{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800110 uint32_t local_data[4];
Wentao Xu8d6150c2011-06-22 11:03:18 -0400111
112 local_data[0] = 0x20;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800113 local_data[1] = (uint32_t) (cmd >> 8);
Wentao Xu8d6150c2011-06-22 11:03:18 -0400114 local_data[2] = 0;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800115 local_data[3] = (uint32_t) cmd;
Wentao Xu8d6150c2011-06-22 11:03:18 -0400116 auo_serigo(local_data, 4);
117}
118
Ajay Dudanib01e5062011-12-03 23:23:42 -0800119static void auo_write_cmd_param(uint32_t cmd, uint32_t param)
Wentao Xu8d6150c2011-06-22 11:03:18 -0400120{
121 uint32_t local_data[6];
122
123 local_data[0] = 0x20;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800124 local_data[1] = (uint32_t) (cmd >> 8);
Wentao Xu8d6150c2011-06-22 11:03:18 -0400125 local_data[2] = 0;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800126 local_data[3] = (uint32_t) cmd;
Wentao Xu8d6150c2011-06-22 11:03:18 -0400127 local_data[4] = 0x40;
128 local_data[5] = param;
129 auo_serigo(local_data, 6);
130}
131
132static void auo_spi_init(void)
133{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800134 gpio_tlmm_config(LCDC_SPI_GPIO_CLK, 0, GPIO_OUTPUT, GPIO_NO_PULL,
135 GPIO_2MA, 1);
136 gpio_tlmm_config(LCDC_SPI_GPIO_CS, 0, GPIO_OUTPUT, GPIO_NO_PULL,
137 GPIO_2MA, 1);
138 gpio_tlmm_config(LCDC_SPI_GPIO_MOSI, 0, GPIO_OUTPUT, GPIO_NO_PULL,
139 GPIO_2MA, 1);
Wentao Xu8d6150c2011-06-22 11:03:18 -0400140
141 /* Set the output so that we don't disturb the slave device */
142 GPIO_SET_OUT_VAL(LCDC_SPI_GPIO_CLK, 1);
143 GPIO_SET_OUT_VAL(LCDC_SPI_GPIO_MOSI, 0);
144
145 /* Set the Chip Select deasserted (active low) */
146 GPIO_SET_OUT_VAL(LCDC_SPI_GPIO_CS, 1);
147}
148
149/* panel initialization */
150static void auo_panel_init(void)
151{
152 auo_write_cmd(PANEL_CMD_SLEEP_OUT);
153 mdelay(150);
154
155 /* SET_PIXEL_FORMAT: Set how many bits per pixel are used (3A00h), 18bits */
156 auo_write_cmd_param(PANEL_CMD_FORMAT, 0x66);
157 mdelay(1);
158
159 /* RGBCTRL: RGB Interface Signal Control (3B00h) */
160 auo_write_cmd_param(PANEL_CMD_RGBCTRL, 0x2B);
161 mdelay(1);
162
163 /* Turn on display */
164 auo_write_cmd(PANEL_CMD_DISP_ON);
165 mdelay(1);
166
167 /* Turn on backlight */
168 auo_write_cmd_param(PANEL_CMD_BCTRL, 0x24);
169 mdelay(1);
170
171 /* Enable PWM level */
172 auo_write_cmd_param(PANEL_CMD_PWM_EN, 0x01);
173 mdelay(1);
174
175 /* Set backlight level to mid range level */
176 auo_write_cmd_param(PANEL_CMD_CABC_FORCE2, 0x77);
177 mdelay(10);
178}
179
180void auo_lcdc_init(void)
181{
182 auo_spi_init();
183 auo_panel_init();
184}