blob: 7ac4092f3909e8e2ab5004803f7246dcc9eb7d9d [file] [log] [blame]
Ajay Dudani232ce812009-12-02 00:14:11 -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>
33#include <dev/fbcon.h>
Chandan Uddaraju07644852010-07-14 12:07:11 -070034#include <target/display.h>
Ajay Dudani232ce812009-12-02 00:14:11 -080035
36#define MSM_MDP_BASE1 0xAA200000
37
38#define LCDC_PIXCLK_IN_PS 26
39#define LCDC_FB_PHYS 0x16600000
40#define LCDC_FB_BPP 16
41
Ajay Dudani232ce812009-12-02 00:14:11 -080042#define BIT(x) (1<<(x))
43#define DMA_DSTC0G_8BITS (BIT(1)|BIT(0))
44#define DMA_DSTC1B_8BITS (BIT(3)|BIT(2))
45#define DMA_DSTC2R_8BITS (BIT(5)|BIT(4))
46#define CLR_G 0x0
47#define CLR_B 0x1
48#define CLR_R 0x2
49#define MDP_GET_PACK_PATTERN(a,x,y,z,bit) (((a)<<(bit*3))|((x)<<(bit*2))|((y)<<bit)|(z))
50#define DMA_PACK_ALIGN_LSB 0
51#define DMA_PACK_PATTERN_RGB \
52 (MDP_GET_PACK_PATTERN(0,CLR_R,CLR_G,CLR_B,2)<<8)
53#define DMA_DITHER_EN BIT(24)
54#define DMA_OUT_SEL_LCDC BIT(20)
55#define DMA_IBUF_FORMAT_RGB565 BIT(25)
56
57static struct fbcon_config fb_cfg = {
58 .height = LCDC_FB_HEIGHT,
59 .width = LCDC_FB_WIDTH,
60 .stride = LCDC_FB_WIDTH,
61 .format = FB_FORMAT_RGB565,
62 .bpp = LCDC_FB_BPP,
63 .update_start = NULL,
64 .update_done = NULL,
65};
66
67void lcdc_clock_init(unsigned rate);
68
69struct fbcon_config *lcdc_init(void)
70{
71 dprintf(INFO, "lcdc_init(): panel is %d x %d\n", fb_cfg.width, fb_cfg.height);
72
73 fb_cfg.base =
74 memalign(4096, fb_cfg.width * fb_cfg.height * (fb_cfg.bpp / 8));
75
Ajay Dudani232ce812009-12-02 00:14:11 -080076 writel((unsigned) fb_cfg.base, MSM_MDP_BASE1 + 0x90008);
77
78 writel((fb_cfg.height << 16) | fb_cfg.width, MSM_MDP_BASE1 + 0x90004);
79 writel(fb_cfg.width * fb_cfg.bpp / 8, MSM_MDP_BASE1 + 0x9000c);
80 writel(0, MSM_MDP_BASE1 + 0x90010);
81
82 writel(DMA_PACK_ALIGN_LSB|DMA_PACK_PATTERN_RGB|DMA_DITHER_EN|DMA_OUT_SEL_LCDC|
83 DMA_IBUF_FORMAT_RGB565|DMA_DSTC0G_8BITS|DMA_DSTC1B_8BITS|DMA_DSTC2R_8BITS,
84 MSM_MDP_BASE1 + 0x90000);
85
86 int hsync_period = LCDC_HSYNC_PULSE_WIDTH_DCLK + LCDC_HSYNC_BACK_PORCH_DCLK + fb_cfg.width + LCDC_HSYNC_FRONT_PORCH_DCLK;
87 int vsync_period = (LCDC_VSYNC_PULSE_WIDTH_LINES + LCDC_VSYNC_BACK_PORCH_LINES + fb_cfg.height + LCDC_VSYNC_FRONT_PORCH_LINES) * hsync_period;
88 int hsync_start_x = LCDC_HSYNC_PULSE_WIDTH_DCLK + LCDC_HSYNC_BACK_PORCH_DCLK;
89 int hsync_end_x = hsync_period - LCDC_HSYNC_FRONT_PORCH_DCLK - 1;
90 int display_hctl = (hsync_end_x << 16) | hsync_start_x;
91 int display_vstart= (LCDC_VSYNC_PULSE_WIDTH_LINES + LCDC_VSYNC_BACK_PORCH_LINES) * hsync_period + LCDC_HSYNC_SKEW_DCLK;
92 int display_vend = vsync_period - (LCDC_VSYNC_FRONT_PORCH_LINES * hsync_period) + LCDC_HSYNC_SKEW_DCLK - 1;
93
94 writel((hsync_period << 16) | LCDC_HSYNC_PULSE_WIDTH_DCLK, MSM_MDP_BASE1 + 0xe0004);
95 writel(vsync_period, MSM_MDP_BASE1 + 0xe0008);
96 writel(LCDC_VSYNC_PULSE_WIDTH_LINES * hsync_period, MSM_MDP_BASE1 + 0xe000c);
97 writel(display_hctl, MSM_MDP_BASE1 + 0xe0010);
98 writel(display_vstart, MSM_MDP_BASE1 + 0xe0014);
99 writel(display_vend, MSM_MDP_BASE1 + 0xe0018);
100 writel(0, MSM_MDP_BASE1 + 0xe0028);
101 writel(0xff, MSM_MDP_BASE1 + 0xe002c);
102 writel(LCDC_HSYNC_SKEW_DCLK, MSM_MDP_BASE1 + 0xe0030);
103 writel(0, MSM_MDP_BASE1 + 0xe0038);
104 writel(0, MSM_MDP_BASE1 + 0xe001c);
105 writel(0, MSM_MDP_BASE1 + 0xe0020);
106 writel(0, MSM_MDP_BASE1 + 0xe0024);
107
108 writel(1, MSM_MDP_BASE1 + 0xe0000);
109
110 return &fb_cfg;
111}
Shashank Mittal4f99a882010-02-01 13:58:50 -0800112