blob: 725804d6b422b4f4b03550c10cf0e357d80ebb31 [file] [log] [blame]
Ajay Dudani232ce812009-12-02 00:14:11 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
Shashank Mittal37040832010-08-24 15:57:57 -07005 * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
6 *
Ajay Dudani232ce812009-12-02 00:14:11 -08007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <debug.h>
32#include <stdlib.h>
33#include <reg.h>
34#include <platform/iomap.h>
35#include <dev/fbcon.h>
Chandan Uddaraju07644852010-07-14 12:07:11 -070036#include <target/display.h>
Ajay Dudani232ce812009-12-02 00:14:11 -080037
Shashank Mittal402d0972010-09-29 10:09:52 -070038#if PLATFORM_MSM7X30
Shashank Mittal37040832010-08-24 15:57:57 -070039#define MSM_MDP_BASE1 0xA3F00000
40#define LCDC_BASE 0xC0000
Shashank Mittal402d0972010-09-29 10:09:52 -070041#elif PLATFORM_MSM8X60
42#define MSM_MDP_BASE1 0x05100000
43#define LCDC_BASE 0xC0000
44#define LCDC_FB_ADDR 0x43E00000
Shashank Mittal37040832010-08-24 15:57:57 -070045#else
Ajay Dudani232ce812009-12-02 00:14:11 -080046#define MSM_MDP_BASE1 0xAA200000
Shashank Mittal37040832010-08-24 15:57:57 -070047#define LCDC_BASE 0xE0000
48#endif
Ajay Dudani232ce812009-12-02 00:14:11 -080049
50#define LCDC_PIXCLK_IN_PS 26
51#define LCDC_FB_PHYS 0x16600000
52#define LCDC_FB_BPP 16
53
Ajay Dudani232ce812009-12-02 00:14:11 -080054#define BIT(x) (1<<(x))
55#define DMA_DSTC0G_8BITS (BIT(1)|BIT(0))
56#define DMA_DSTC1B_8BITS (BIT(3)|BIT(2))
57#define DMA_DSTC2R_8BITS (BIT(5)|BIT(4))
58#define CLR_G 0x0
59#define CLR_B 0x1
60#define CLR_R 0x2
61#define MDP_GET_PACK_PATTERN(a,x,y,z,bit) (((a)<<(bit*3))|((x)<<(bit*2))|((y)<<bit)|(z))
62#define DMA_PACK_ALIGN_LSB 0
63#define DMA_PACK_PATTERN_RGB \
64 (MDP_GET_PACK_PATTERN(0,CLR_R,CLR_G,CLR_B,2)<<8)
65#define DMA_DITHER_EN BIT(24)
66#define DMA_OUT_SEL_LCDC BIT(20)
67#define DMA_IBUF_FORMAT_RGB565 BIT(25)
68
69static struct fbcon_config fb_cfg = {
70 .height = LCDC_FB_HEIGHT,
71 .width = LCDC_FB_WIDTH,
72 .stride = LCDC_FB_WIDTH,
73 .format = FB_FORMAT_RGB565,
74 .bpp = LCDC_FB_BPP,
75 .update_start = NULL,
76 .update_done = NULL,
77};
78
79void lcdc_clock_init(unsigned rate);
80
Shashank Mittal37040832010-08-24 15:57:57 -070081#if MDP4
82void mdp4_display_intf_sel(int intf)
83{
84 unsigned bits, mask;
85 bits = readl(MSM_MDP_BASE1 + 0x0038);
86 mask = 0x03; /* 2 bits */
87 intf &= 0x03; /* 2 bits */
88 bits &= ~mask;
89 bits |= intf;
90 writel(bits, MSM_MDP_BASE1 + 0x0038); /* MDP_DISP_INTF_SEL */
91}
92#endif
93
Ajay Dudani232ce812009-12-02 00:14:11 -080094struct fbcon_config *lcdc_init(void)
95{
96 dprintf(INFO, "lcdc_init(): panel is %d x %d\n", fb_cfg.width, fb_cfg.height);
Shashank Mittal402d0972010-09-29 10:09:52 -070097#if PLATFORM_MSM8X60
98 fb_cfg.base = LCDC_FB_ADDR;
99#else
Ajay Dudani232ce812009-12-02 00:14:11 -0800100 fb_cfg.base =
101 memalign(4096, fb_cfg.width * fb_cfg.height * (fb_cfg.bpp / 8));
Shashank Mittal402d0972010-09-29 10:09:52 -0700102#endif
Ajay Dudani232ce812009-12-02 00:14:11 -0800103
Ajay Dudani232ce812009-12-02 00:14:11 -0800104 writel((unsigned) fb_cfg.base, MSM_MDP_BASE1 + 0x90008);
105
106 writel((fb_cfg.height << 16) | fb_cfg.width, MSM_MDP_BASE1 + 0x90004);
107 writel(fb_cfg.width * fb_cfg.bpp / 8, MSM_MDP_BASE1 + 0x9000c);
108 writel(0, MSM_MDP_BASE1 + 0x90010);
109
110 writel(DMA_PACK_ALIGN_LSB|DMA_PACK_PATTERN_RGB|DMA_DITHER_EN|DMA_OUT_SEL_LCDC|
111 DMA_IBUF_FORMAT_RGB565|DMA_DSTC0G_8BITS|DMA_DSTC1B_8BITS|DMA_DSTC2R_8BITS,
112 MSM_MDP_BASE1 + 0x90000);
113
114 int hsync_period = LCDC_HSYNC_PULSE_WIDTH_DCLK + LCDC_HSYNC_BACK_PORCH_DCLK + fb_cfg.width + LCDC_HSYNC_FRONT_PORCH_DCLK;
115 int vsync_period = (LCDC_VSYNC_PULSE_WIDTH_LINES + LCDC_VSYNC_BACK_PORCH_LINES + fb_cfg.height + LCDC_VSYNC_FRONT_PORCH_LINES) * hsync_period;
116 int hsync_start_x = LCDC_HSYNC_PULSE_WIDTH_DCLK + LCDC_HSYNC_BACK_PORCH_DCLK;
117 int hsync_end_x = hsync_period - LCDC_HSYNC_FRONT_PORCH_DCLK - 1;
118 int display_hctl = (hsync_end_x << 16) | hsync_start_x;
119 int display_vstart= (LCDC_VSYNC_PULSE_WIDTH_LINES + LCDC_VSYNC_BACK_PORCH_LINES) * hsync_period + LCDC_HSYNC_SKEW_DCLK;
120 int display_vend = vsync_period - (LCDC_VSYNC_FRONT_PORCH_LINES * hsync_period) + LCDC_HSYNC_SKEW_DCLK - 1;
121
Shashank Mittal37040832010-08-24 15:57:57 -0700122 writel((hsync_period << 16) | LCDC_HSYNC_PULSE_WIDTH_DCLK, MSM_MDP_BASE1 + LCDC_BASE + 0x4);
123 writel(vsync_period, MSM_MDP_BASE1 + LCDC_BASE + 0x8);
124 writel(LCDC_VSYNC_PULSE_WIDTH_LINES * hsync_period, MSM_MDP_BASE1 + LCDC_BASE + 0xc);
125 writel(display_hctl, MSM_MDP_BASE1 + LCDC_BASE + 0x10);
126 writel(display_vstart, MSM_MDP_BASE1 + LCDC_BASE + 0x14);
127 writel(display_vend, MSM_MDP_BASE1 + LCDC_BASE + 0x18);
128#if MDP4
129 writel(0xf, MSM_MDP_BASE1 + LCDC_BASE + 0x28);
130#else
131 writel(0, MSM_MDP_BASE1 + LCDC_BASE + 0x28);
132#endif
133 writel(0xff, MSM_MDP_BASE1 + LCDC_BASE + 0x2c);
134 writel(LCDC_HSYNC_SKEW_DCLK, MSM_MDP_BASE1 + LCDC_BASE + 0x30);
135#if MDP4
136 writel(0x3, MSM_MDP_BASE1 + LCDC_BASE + 0x38);
137#else
138 writel(0, MSM_MDP_BASE1 + LCDC_BASE + 0x38);
139#endif
140 writel(0, MSM_MDP_BASE1 + LCDC_BASE + 0x1c);
141 writel(0, MSM_MDP_BASE1 + LCDC_BASE + 0x20);
142 writel(0, MSM_MDP_BASE1 + LCDC_BASE + 0x24);
143#if MDP4
144 writel(0xB, MSM_MDP_BASE1 + 0x10004);
145 writel(0xB, MSM_MDP_BASE1 + 0x18004);
146#endif
147 writel(1, MSM_MDP_BASE1 + LCDC_BASE + 0x0);
Ajay Dudani232ce812009-12-02 00:14:11 -0800148
149 return &fb_cfg;
150}
Shashank Mittal4f99a882010-02-01 13:58:50 -0800151