Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 1 | /* |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011, The Linux Foundation. All rights reserved. |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 3 | * |
| 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 Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 13 | * * Neither the name of The Linux Foundation nor |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 14 | * 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 */ |
| 54 | static struct lcdc_timing_parameters param = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 55 | .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 Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 61 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 62 | .lcdc_vsync_pulse_width_lines = 2, |
| 63 | .lcdc_vsync_back_porch_lines = 1, |
| 64 | .lcdc_vsync_front_porch_lines = 28, |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | struct lcdc_timing_parameters *auo_timing_param() |
| 68 | { |
| 69 | return ¶m; |
| 70 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 71 | |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 72 | /* spi commands */ |
| 73 | static 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 Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 91 | static uint32_t auo_serigo(uint32_t * input_data, uint32_t input_len) |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 92 | { |
| 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 Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 108 | static void auo_write_cmd(uint32_t cmd) |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 109 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 110 | uint32_t local_data[4]; |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 111 | |
| 112 | local_data[0] = 0x20; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 113 | local_data[1] = (uint32_t) (cmd >> 8); |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 114 | local_data[2] = 0; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 115 | local_data[3] = (uint32_t) cmd; |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 116 | auo_serigo(local_data, 4); |
| 117 | } |
| 118 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 119 | static void auo_write_cmd_param(uint32_t cmd, uint32_t param) |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 120 | { |
| 121 | uint32_t local_data[6]; |
| 122 | |
| 123 | local_data[0] = 0x20; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 124 | local_data[1] = (uint32_t) (cmd >> 8); |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 125 | local_data[2] = 0; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 126 | local_data[3] = (uint32_t) cmd; |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 127 | local_data[4] = 0x40; |
| 128 | local_data[5] = param; |
| 129 | auo_serigo(local_data, 6); |
| 130 | } |
| 131 | |
| 132 | static void auo_spi_init(void) |
| 133 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 134 | 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 Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 140 | |
| 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 */ |
| 150 | static 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 | |
| 180 | void auo_lcdc_init(void) |
| 181 | { |
| 182 | auo_spi_init(); |
| 183 | auo_panel_init(); |
| 184 | } |