hm60x/hm801: Buttons rework.
[maemo-rb.git] / firmware / target / arm / rk27xx / lcdif-rk27xx.c
blobaffc49b2138066139a53abe29873c94c833d889b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2011 Marcin Bukat
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
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"
30 unsigned int lcd_data_transform(unsigned int data)
32 unsigned int r, g, b;
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) || defined(HM801)
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
49 return (r | g | b);
52 void lcd_cmd(unsigned int cmd)
54 LCD_COMMAND = lcd_data_transform(cmd);
57 void lcd_data(unsigned int data)
59 LCD_DATA = lcd_data_transform(data);
62 void lcd_write_reg(unsigned int reg, unsigned int val)
64 lcd_cmd(reg);
65 lcd_data(val);
68 static void lcdctrl_bypass(unsigned int on_off)
70 while (!(LCDC_STA & LCDC_MCU_IDLE));
72 if (on_off)
73 MCU_CTRL |= MCU_CTRL_BYPASS;
74 else
75 MCU_CTRL &= ~MCU_CTRL_BYPASS;
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.
82 static void lcdctrl_init(void)
84 /* alpha b111
85 * stop at current frame complete
86 * MCU mode
87 * 24b RGB
89 LCDC_CTRL = ALPHA(7) | LCDC_STOP | LCDC_MCU | RGB24B;
90 MCU_CTRL = ALPHA_BASE(0x3f) | MCU_CTRL_BYPASS;
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 */
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);
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);
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);
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;
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; */
125 /* configure pins to drive lcd in 18bit mode (16bit mode for HiFiMAN's) */
126 static void iomux_lcd(enum lcdif_mode_t mode)
128 unsigned long muxa;
130 muxa = SCU_IOMUXA_CON & ~(IOMUX_LCD_VSYNC|IOMUX_LCD_DEN|0xff);
132 if (mode == LCDIF_18BIT)
134 muxa |= IOMUX_LCD_D18|IOMUX_LCD_D20|IOMUX_LCD_D22|IOMUX_LCD_D17|IOMUX_LCD_D16;
137 SCU_IOMUXA_CON = muxa;
138 SCU_IOMUXB_CON |= IOMUX_LCD_D815;
141 void lcdif_init(enum lcdif_mode_t mode)
143 iomux_lcd(mode); /* setup pins for lcd interface */
144 lcdctrl_init(); /* basic lcdc module configuration */
145 lcdctrl_bypass(1); /* run in bypass mode - all writes goes directly to lcd controller */
148 /* This is ugly hack. We drive lcd in bypass mode
149 * where all writes goes directly to lcd controller.
150 * This is suboptimal at best. IF module povides
151 * FIFO, internal sram buffer, hardware scaller,
152 * DMA signals, hardware alpha blending and more.
153 * BUT the fact is that I have no idea how to use
154 * this modes. Datasheet floating around is very
155 * unclean in this regard and OF uses ackward
156 * lcd update routines which are hard to understand.
157 * Moreover OF sets some bits in IF module registers
158 * which are referred as reseved in datasheet.
160 void lcd_update()
162 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);