1 /* drivers/video/sprdfb/lcd_st7789v.c
3 * Support for st7789v LCD device
5 * Copyright (C) 2010 Spreadtrum
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <asm/arch/sprd_lcd.h>
18 #include "../sprdfb.h"
24 #define LCD_PRINT printk
26 #define LCD_PRINT(...)
29 #define ST7789V_BUS_WIDTH_8BIT // bus_width = 8
31 static int32_t st7789v_init(struct panel_spec *self)
33 send_data_t send_cmd = self->info.mcu->ops->send_cmd;
34 send_data_t send_data = self->info.mcu->ops->send_data;
36 LCD_PRINT("st7789v_init\n");
38 //Power setting sequence
42 #if defined(ST7789V_BUS_WIDTH_8BIT)
122 send_cmd(0xB7); send_data(0x35);
123 send_cmd(0xBB); send_data(0x1A);
124 send_cmd(0xC2); send_data(0x01);
125 send_cmd(0xC3); send_data(0x0B);
126 send_cmd(0xC4); send_data(0x20);
127 send_cmd(0xD0); send_data(0xA4);send_data(0xA1);
128 send_cmd(0xE8); send_data(0x83);
129 send_cmd(0xE9); send_data(0x09);send_data(0x09);send_data(0x08);
132 send_cmd(0x36); send_data(0x00);
133 send_cmd(0x35); send_data(0x00);
134 send_cmd(0x3A); send_data(0x05);//0x06: 262k 0x05:65k
135 send_cmd(0xD2); send_data(0x4C);
136 send_cmd(0xB2);send_data(0x0C);send_data(0x0C);send_data(0x00);send_data(0x33);send_data(0x33);
137 send_cmd(0xC6); send_data(0x09);
172 send_cmd(0x29); //Display On
175 LCD_PRINT("st7789v_init: end\n");
180 static int32_t st7789v_set_window(struct panel_spec *self,
181 uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
183 send_data_t send_cmd = self->info.mcu->ops->send_cmd;
184 send_data_t send_data = self->info.mcu->ops->send_data;
186 LCD_PRINT("st7789v_set_window\n");
187 #if defined(ST7789V_BUS_WIDTH_8BIT)
188 send_cmd(0x002A); // col
192 send_cmd(0x002B); // row
197 send_cmd(0x2A); // col
198 send_data((left >> 8));
199 send_data((left & 0xFF));
200 send_data((right >> 8));
201 send_data((right & 0xFF));
203 send_cmd(0x2B); // row
204 send_data((top >> 8));
205 send_data((top & 0xFF));
206 send_data((bottom >> 8));
207 send_data((bottom & 0xFF));
214 static int32_t st7789v_invalidate(struct panel_spec *self)
216 LCD_PRINT("st7789v_invalidate\n");
218 return self->ops->panel_set_window(self, 0, 0,
219 self->width-1, self->height-1);
222 static int32_t st7789v_invalidate_rect(struct panel_spec *self,
223 uint16_t left, uint16_t top,
224 uint16_t right, uint16_t bottom)
227 LCD_PRINT("st7789v_invalidate_rect : (%d, %d, %d, %d)\n",left, top, right, bottom);
229 return self->ops->panel_set_window(self, left, top,
233 static int32_t st7789v_set_direction(struct panel_spec *self, uint16_t direction)
236 LCD_PRINT("st7789v_set_direction\n");
240 static int32_t st7789v_enter_sleep(struct panel_spec *self, uint8_t is_sleep)
242 send_data_t send_cmd = self->info.mcu->ops->send_cmd;
255 #define LCD_MTP_ID 0x51a0f0
256 static int32_t st7789v_read_id(struct panel_spec *self)
258 int32_t read_value = 0;
259 send_data_t send_cmd = self->info.mcu->ops->send_cmd;
260 read_data_t read_data = self->info.mcu->ops->read_data;
264 #if defined(ST7789V_BUS_WIDTH_8BIT)
265 read_value += (read_data() &0xff)<<16;
266 read_value += read_data();
269 read_value += read_data()<< 16;
270 read_value += read_data()<< 8;
271 read_value += read_data();
273 LCD_PRINT("st7789v_read_id=%x\n",read_value);
274 if(read_value == LCD_MTP_ID)
280 static struct panel_operations lcd_st7789v_operations = {
281 .panel_init = st7789v_init,
282 .panel_set_window = st7789v_set_window,
283 .panel_invalidate = st7789v_invalidate,
284 //.lcd_invalidate_rect = st7789v_invalidate_rect,
285 .panel_set_direction = st7789v_set_direction,
286 .panel_enter_sleep = st7789v_enter_sleep,
287 .panel_readid = st7789v_read_id,
290 static struct timing_mcu lcd_st7789v_timing[] = {
291 [0] = { /* read/write register timing (ns) */
299 [1] = { /* read/write gram timing (ns) */
300 .rcss = 25, /* 25 ns */
309 static struct info_mcu lcd_st7789v_info = {
310 .bus_mode = LCD_BUS_8080,
313 .timing = &lcd_st7789v_timing,
317 struct panel_spec lcd_panel_st7789v = {
321 .type = LCD_MODE_MCU,
322 .direction = LCD_DIRECT_NORMAL,
324 .mcu = &lcd_st7789v_info
326 .ops = &lcd_st7789v_operations,