blob: 29152d30b5fc7f7e7825ebf4f8a7a381fb94f91e [file] [log] [blame]
Brian Swetlanddfdb4612009-01-01 11:44:36 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <stdlib.h>
31#include <reg.h>
32#include <platform/iomap.h>
Dima Zavine35e75b2009-01-15 18:09:26 -080033#include <dev/fbcon.h>
Brian Swetlanddfdb4612009-01-01 11:44:36 -080034
35#define MSM_MDP_BASE1 0xAA200000
36
Brian Swetlanddfdb4612009-01-01 11:44:36 -080037#define LCDC_PIXCLK_IN_PS 26
38#define LCDC_FB_PHYS 0x16600000
39#define LCDC_FB_BPP 16
40
41#if 1
42/* SURF */
43#define LCDC_FB_WIDTH 800
44#define LCDC_FB_HEIGHT 480
45
46#define LCDC_HSYNC_PULSE_WIDTH_DCLK 60
47#define LCDC_HSYNC_BACK_PORCH_DCLK 81
48#define LCDC_HSYNC_FRONT_PORCH_DCLK 81
49#define LCDC_HSYNC_SKEW_DCLK 0
50
51#define LCDC_VSYNC_PULSE_WIDTH_LINES 2
52#define LCDC_VSYNC_BACK_PORCH_LINES 20
53#define LCDC_VSYNC_FRONT_PORCH_LINES 27
54
55#else
56/* FFA */
57#define LCDC_FB_WIDTH 480
58#define LCDC_FB_HEIGHT 640
59
60#define LCDC_HSYNC_PULSE_WIDTH_DCLK 60
61#define LCDC_HSYNC_BACK_PORCH_DCLK 144
62#define LCDC_HSYNC_FRONT_PORCH_DCLK 33
63#define LCDC_HSYNC_SKEW_DCLK 0
64
65#define LCDC_VSYNC_PULSE_WIDTH_LINES 2
66#define LCDC_VSYNC_BACK_PORCH_LINES 2
67#define LCDC_VSYNC_FRONT_PORCH_LINES 2
68
69#endif
70
71#define BIT(x) (1<<(x))
72#define DMA_DSTC0G_8BITS (BIT(1)|BIT(0))
73#define DMA_DSTC1B_8BITS (BIT(3)|BIT(2))
74#define DMA_DSTC2R_8BITS (BIT(5)|BIT(4))
75#define CLR_G 0x0
76#define CLR_B 0x1
77#define CLR_R 0x2
78#define MDP_GET_PACK_PATTERN(a,x,y,z,bit) (((a)<<(bit*3))|((x)<<(bit*2))|((y)<<bit)|(z))
79#define DMA_PACK_ALIGN_LSB 0
80#define DMA_PACK_PATTERN_RGB \
81 (MDP_GET_PACK_PATTERN(0,CLR_R,CLR_G,CLR_B,2)<<8)
82#define DMA_DITHER_EN BIT(24)
83#define DMA_OUT_SEL_LCDC BIT(20)
84#define DMA_IBUF_FORMAT_RGB565 BIT(25)
85
Dima Zavine35e75b2009-01-15 18:09:26 -080086static struct fbcon_config fb_cfg = {
87 .height = LCDC_FB_HEIGHT,
88 .width = LCDC_FB_WIDTH,
89 .stride = LCDC_FB_WIDTH,
90 .format = FB_FORMAT_RGB565,
91 .bpp = LCDC_FB_BPP,
92 .update_start = NULL,
93 .update_done = NULL,
94};
95
Brian Swetlanddfdb4612009-01-01 11:44:36 -080096void lcdc_clock_init(unsigned rate);
97
Dima Zavine35e75b2009-01-15 18:09:26 -080098struct fbcon_config *lcdc_init(void)
Brian Swetlanddfdb4612009-01-01 11:44:36 -080099{
Brian Swetlandb3d66d92009-01-29 20:42:39 -0800100 dprintf(INFO, "lcdc_init(): panel is %d x %d\n", fb_cfg.width, fb_cfg.height);
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800101
Dima Zavine35e75b2009-01-15 18:09:26 -0800102 fb_cfg.base =
103 memalign(4096, fb_cfg.width * fb_cfg.height * (fb_cfg.bpp / 8));
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800104
105 lcdc_clock_init(1000000000 / LCDC_PIXCLK_IN_PS);
106
Brian Swetlandb3d66d92009-01-29 20:42:39 -0800107 writel((unsigned) fb_cfg.base, MSM_MDP_BASE1 + 0x90008);
Dima Zavine35e75b2009-01-15 18:09:26 -0800108
109 writel((fb_cfg.height << 16) | fb_cfg.width, MSM_MDP_BASE1 + 0x90004);
110 writel(fb_cfg.width * fb_cfg.bpp / 8, MSM_MDP_BASE1 + 0x9000c);
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800111 writel(0, MSM_MDP_BASE1 + 0x90010);
112
113 writel(DMA_PACK_ALIGN_LSB|DMA_PACK_PATTERN_RGB|DMA_DITHER_EN|DMA_OUT_SEL_LCDC|
114 DMA_IBUF_FORMAT_RGB565|DMA_DSTC0G_8BITS|DMA_DSTC1B_8BITS|DMA_DSTC2R_8BITS,
115 MSM_MDP_BASE1 + 0x90000);
116
Dima Zavine35e75b2009-01-15 18:09:26 -0800117 int hsync_period = LCDC_HSYNC_PULSE_WIDTH_DCLK + LCDC_HSYNC_BACK_PORCH_DCLK + fb_cfg.width + LCDC_HSYNC_FRONT_PORCH_DCLK;
118 int vsync_period = (LCDC_VSYNC_PULSE_WIDTH_LINES + LCDC_VSYNC_BACK_PORCH_LINES + fb_cfg.height + LCDC_VSYNC_FRONT_PORCH_LINES) * hsync_period;
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800119 int hsync_start_x = LCDC_HSYNC_PULSE_WIDTH_DCLK + LCDC_HSYNC_BACK_PORCH_DCLK;
120 int hsync_end_x = hsync_period - LCDC_HSYNC_FRONT_PORCH_DCLK - 1;
121 int display_hctl = (hsync_end_x << 16) | hsync_start_x;
122 int display_vstart= (LCDC_VSYNC_PULSE_WIDTH_LINES + LCDC_VSYNC_BACK_PORCH_LINES) * hsync_period + LCDC_HSYNC_SKEW_DCLK;
123 int display_vend = vsync_period - (LCDC_VSYNC_FRONT_PORCH_LINES * hsync_period) + LCDC_HSYNC_SKEW_DCLK - 1;
124
125 writel((hsync_period << 16) | LCDC_HSYNC_PULSE_WIDTH_DCLK, MSM_MDP_BASE1 + 0xe0004);
126 writel(vsync_period, MSM_MDP_BASE1 + 0xe0008);
127 writel(LCDC_VSYNC_PULSE_WIDTH_LINES * hsync_period, MSM_MDP_BASE1 + 0xe000c);
128 writel(display_hctl, MSM_MDP_BASE1 + 0xe0010);
129 writel(display_vstart, MSM_MDP_BASE1 + 0xe0014);
130 writel(display_vend, MSM_MDP_BASE1 + 0xe0018);
131 writel(0, MSM_MDP_BASE1 + 0xe0028);
132 writel(0xff, MSM_MDP_BASE1 + 0xe002c);
133 writel(LCDC_HSYNC_SKEW_DCLK, MSM_MDP_BASE1 + 0xe0030);
134 writel(0, MSM_MDP_BASE1 + 0xe0038);
135 writel(0, MSM_MDP_BASE1 + 0xe001c);
136 writel(0, MSM_MDP_BASE1 + 0xe0020);
137 writel(0, MSM_MDP_BASE1 + 0xe0024);
138
139 writel(1, MSM_MDP_BASE1 + 0xe0000);
140
Dima Zavine35e75b2009-01-15 18:09:26 -0800141 return &fb_cfg;
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800142}