summaryrefslogtreecommitdiff
path: root/firmware/target/arm/rk27xx/lcdif-rk27xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/rk27xx/lcdif-rk27xx.c')
-rw-r--r--firmware/target/arm/rk27xx/lcdif-rk27xx.c161
1 files changed, 161 insertions, 0 deletions
diff --git a/firmware/target/arm/rk27xx/lcdif-rk27xx.c b/firmware/target/arm/rk27xx/lcdif-rk27xx.c
new file mode 100644
index 0000000000..aeee63ee7e
--- /dev/null
+++ b/firmware/target/arm/rk27xx/lcdif-rk27xx.c
@@ -0,0 +1,161 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 Marcin Bukat
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include "kernel.h"
24#include "lcd.h"
25#include "system.h"
26#include "cpu.h"
27#include "lcdif-rk27xx.h"
28
29
30unsigned int lcd_data_transform(unsigned int data)
31{
32 unsigned int r, g, b;
33
34#if defined(RK27_GENERIC)
35 /* 18 bit interface */
36 r = (data & 0x0000fc00)<<8;
37 /* g = ((data & 0x00000300) >> 2) | ((data & 0x000000e0) >> 3); */
38 g = ((data & 0x00000300) << 6) | ((data & 0x000000e0) << 5);
39 b = (data & 0x00000001f) << 3;
40#elif defined(HM60X)
41 /* 16 bit interface */
42 r = (data & 0x0000f800) << 8;
43 g = (data & 0x000007e0) << 5;
44 b = (data & 0x0000001f) << 3;
45#else
46#error "Unknown target"
47#endif
48
49 return (r | g | b);
50}
51
52void lcd_cmd(unsigned int cmd)
53{
54 LCD_COMMAND = lcd_data_transform(cmd);
55}
56
57void lcd_data(unsigned int data)
58{
59 LCD_DATA = lcd_data_transform(data);
60}
61
62void lcd_write_reg(unsigned int reg, unsigned int val)
63{
64 lcd_cmd(reg);
65 lcd_data(val);
66}
67
68static void lcdctrl_bypass(unsigned int on_off)
69{
70 while (!(LCDC_STA & LCDC_MCU_IDLE));
71
72 if (on_off)
73 MCU_CTRL |= MCU_CTRL_BYPASS;
74 else
75 MCU_CTRL &= ~MCU_CTRL_BYPASS;
76}
77
78/* This part is unclear. I am unable to use buffered/FIFO based writes
79 * to lcd. Depending on settings of IF I get various patterns on display
80 * but not what I want to display apparently.
81 */
82static void lcdctrl_init(void)
83{
84 /* alpha b111
85 * stop at current frame complete
86 * MCU mode
87 * 24b RGB
88 */
89 LCDC_CTRL = ALPHA(7) | LCDC_STOP | LCDC_MCU | RGB24B;
90 MCU_CTRL = ALPHA_BASE(0x3f) | MCU_CTRL_BYPASS;
91
92 HOR_ACT = LCD_WIDTH + 3; /* define horizonatal active region */
93 VERT_ACT = LCD_HEIGHT; /* define vertical active region */
94 VERT_PERIOD = 0xfff; /* CSn/WEn/RDn signal timings */
95
96 LINE0_YADDR = LINE_ALPHA_EN | 0x7fe;
97 LINE1_YADDR = LINE_ALPHA_EN | ((1 * LCD_WIDTH) - 2);
98 LINE2_YADDR = LINE_ALPHA_EN | ((2 * LCD_WIDTH) - 2);
99 LINE3_YADDR = LINE_ALPHA_EN | ((3 * LCD_WIDTH) - 2);
100
101 LINE0_UVADDR = 0x7fe + 1;
102 LINE1_UVADDR = ((1 * LCD_WIDTH) - 2 + 1);
103 LINE2_UVADDR = ((2 * LCD_WIDTH) - 2 + 1);
104 LINE3_UVADDR = ((3 * LCD_WIDTH) - 2 + 1);
105
106#if 0
107 LINE0_YADDR = 0;
108 LINE1_YADDR = (1 * LCD_WIDTH);
109 LINE2_YADDR = (2 * LCD_WIDTH);
110 LINE3_YADDR = (3 * LCD_WIDTH);
111
112 LINE0_UVADDR = 1;
113 LINE1_UVADDR = (1 * LCD_WIDTH) + 1;
114 LINE2_UVADDR = (2 * LCD_WIDTH) + 1;
115 LINE3_UVADDR = (3 * LCD_WIDTH) + 1;
116
117 START_X = 0;
118 START_Y = 0;
119 DELTA_X = 0x200; /* no scaling */
120 DELTA_Y = 0x200; /* no scaling */
121#endif
122 LCDC_INTR_MASK = INTR_MASK_LINE; /* INTR_MASK_EVENLINE; */
123}
124
125/* configure pins to drive lcd in 18bit mode */
126static void iomux_lcd(void)
127{
128 unsigned long muxa;
129
130 muxa = SCU_IOMUXA_CON & ~(IOMUX_LCD_VSYNC|IOMUX_LCD_DEN|0xff);
131 muxa |= IOMUX_LCD_D18|IOMUX_LCD_D20|IOMUX_LCD_D22|IOMUX_LCD_D17|IOMUX_LCD_D16;
132
133 SCU_IOMUXA_CON = muxa;
134 SCU_IOMUXB_CON |= IOMUX_LCD_D815;
135}
136
137void lcd_init_device()
138{
139 iomux_lcd(); /* setup pins for 16bit lcd interface */
140 lcdctrl_init(); /* basic lcdc module configuration */
141
142 lcdctrl_bypass(1); /* run in bypass mode - all writes goes directly to lcd controller */
143 lcd_display_init();
144}
145
146/* This is ugly hack. We drive lcd in bypass mode
147 * where all writes goes directly to lcd controller.
148 * This is suboptimal at best. IF module povides
149 * FIFO, internal sram buffer, hardware scaller,
150 * DMA signals, hardware alpha blending and more.
151 * BUT the fact is that I have no idea how to use
152 * this modes. Datasheet floating around is very
153 * unclean in this regard and OF uses ackward
154 * lcd update routines which are hard to understand.
155 * Moreover OF sets some bits in IF module registers
156 * which are referred as reseved in datasheet.
157 */
158void lcd_update()
159{
160 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
161}