blob: 75dfe0ccbfbca3c5983863f56f2da6a070cf9563 [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 Mittal37040832010-08-24 15:57:57 -070038#if MDP4
39#define MSM_MDP_BASE1 0xA3F00000
40#define LCDC_BASE 0xC0000
41#else
Ajay Dudani232ce812009-12-02 00:14:11 -080042#define MSM_MDP_BASE1 0xAA200000
Shashank Mittal37040832010-08-24 15:57:57 -070043#define LCDC_BASE 0xE0000
44#endif
Ajay Dudani232ce812009-12-02 00:14:11 -080045
46#define LCDC_PIXCLK_IN_PS 26
47#define LCDC_FB_PHYS 0x16600000
48#define LCDC_FB_BPP 16
49
Ajay Dudani232ce812009-12-02 00:14:11 -080050#define BIT(x) (1<<(x))
51#define DMA_DSTC0G_8BITS (BIT(1)|BIT(0))
52#define DMA_DSTC1B_8BITS (BIT(3)|BIT(2))
53#define DMA_DSTC2R_8BITS (BIT(5)|BIT(4))
54#define CLR_G 0x0
55#define CLR_B 0x1
56#define CLR_R 0x2
57#define MDP_GET_PACK_PATTERN(a,x,y,z,bit) (((a)<<(bit*3))|((x)<<(bit*2))|((y)<<bit)|(z))
58#define DMA_PACK_ALIGN_LSB 0
59#define DMA_PACK_PATTERN_RGB \
60 (MDP_GET_PACK_PATTERN(0,CLR_R,CLR_G,CLR_B,2)<<8)
61#define DMA_DITHER_EN BIT(24)
62#define DMA_OUT_SEL_LCDC BIT(20)
63#define DMA_IBUF_FORMAT_RGB565 BIT(25)
64
65static struct fbcon_config fb_cfg = {
66 .height = LCDC_FB_HEIGHT,
67 .width = LCDC_FB_WIDTH,
68 .stride = LCDC_FB_WIDTH,
69 .format = FB_FORMAT_RGB565,
70 .bpp = LCDC_FB_BPP,
71 .update_start = NULL,
72 .update_done = NULL,
73};
74
75void lcdc_clock_init(unsigned rate);
76
Shashank Mittal37040832010-08-24 15:57:57 -070077#if MDP4
78void mdp4_display_intf_sel(int intf)
79{
80 unsigned bits, mask;
81 bits = readl(MSM_MDP_BASE1 + 0x0038);
82 mask = 0x03; /* 2 bits */
83 intf &= 0x03; /* 2 bits */
84 bits &= ~mask;
85 bits |= intf;
86 writel(bits, MSM_MDP_BASE1 + 0x0038); /* MDP_DISP_INTF_SEL */
87}
88#endif
89
Ajay Dudani232ce812009-12-02 00:14:11 -080090struct fbcon_config *lcdc_init(void)
91{
92 dprintf(INFO, "lcdc_init(): panel is %d x %d\n", fb_cfg.width, fb_cfg.height);
93
94 fb_cfg.base =
95 memalign(4096, fb_cfg.width * fb_cfg.height * (fb_cfg.bpp / 8));
96
Ajay Dudani232ce812009-12-02 00:14:11 -080097 writel((unsigned) fb_cfg.base, MSM_MDP_BASE1 + 0x90008);
98
99 writel((fb_cfg.height << 16) | fb_cfg.width, MSM_MDP_BASE1 + 0x90004);
100 writel(fb_cfg.width * fb_cfg.bpp / 8, MSM_MDP_BASE1 + 0x9000c);
101 writel(0, MSM_MDP_BASE1 + 0x90010);
102
103 writel(DMA_PACK_ALIGN_LSB|DMA_PACK_PATTERN_RGB|DMA_DITHER_EN|DMA_OUT_SEL_LCDC|
104 DMA_IBUF_FORMAT_RGB565|DMA_DSTC0G_8BITS|DMA_DSTC1B_8BITS|DMA_DSTC2R_8BITS,
105 MSM_MDP_BASE1 + 0x90000);
106
107 int hsync_period = LCDC_HSYNC_PULSE_WIDTH_DCLK + LCDC_HSYNC_BACK_PORCH_DCLK + fb_cfg.width + LCDC_HSYNC_FRONT_PORCH_DCLK;
108 int vsync_period = (LCDC_VSYNC_PULSE_WIDTH_LINES + LCDC_VSYNC_BACK_PORCH_LINES + fb_cfg.height + LCDC_VSYNC_FRONT_PORCH_LINES) * hsync_period;
109 int hsync_start_x = LCDC_HSYNC_PULSE_WIDTH_DCLK + LCDC_HSYNC_BACK_PORCH_DCLK;
110 int hsync_end_x = hsync_period - LCDC_HSYNC_FRONT_PORCH_DCLK - 1;
111 int display_hctl = (hsync_end_x << 16) | hsync_start_x;
112 int display_vstart= (LCDC_VSYNC_PULSE_WIDTH_LINES + LCDC_VSYNC_BACK_PORCH_LINES) * hsync_period + LCDC_HSYNC_SKEW_DCLK;
113 int display_vend = vsync_period - (LCDC_VSYNC_FRONT_PORCH_LINES * hsync_period) + LCDC_HSYNC_SKEW_DCLK - 1;
114
Shashank Mittal37040832010-08-24 15:57:57 -0700115 writel((hsync_period << 16) | LCDC_HSYNC_PULSE_WIDTH_DCLK, MSM_MDP_BASE1 + LCDC_BASE + 0x4);
116 writel(vsync_period, MSM_MDP_BASE1 + LCDC_BASE + 0x8);
117 writel(LCDC_VSYNC_PULSE_WIDTH_LINES * hsync_period, MSM_MDP_BASE1 + LCDC_BASE + 0xc);
118 writel(display_hctl, MSM_MDP_BASE1 + LCDC_BASE + 0x10);
119 writel(display_vstart, MSM_MDP_BASE1 + LCDC_BASE + 0x14);
120 writel(display_vend, MSM_MDP_BASE1 + LCDC_BASE + 0x18);
121#if MDP4
122 writel(0xf, MSM_MDP_BASE1 + LCDC_BASE + 0x28);
123#else
124 writel(0, MSM_MDP_BASE1 + LCDC_BASE + 0x28);
125#endif
126 writel(0xff, MSM_MDP_BASE1 + LCDC_BASE + 0x2c);
127 writel(LCDC_HSYNC_SKEW_DCLK, MSM_MDP_BASE1 + LCDC_BASE + 0x30);
128#if MDP4
129 writel(0x3, MSM_MDP_BASE1 + LCDC_BASE + 0x38);
130#else
131 writel(0, MSM_MDP_BASE1 + LCDC_BASE + 0x38);
132#endif
133 writel(0, MSM_MDP_BASE1 + LCDC_BASE + 0x1c);
134 writel(0, MSM_MDP_BASE1 + LCDC_BASE + 0x20);
135 writel(0, MSM_MDP_BASE1 + LCDC_BASE + 0x24);
136#if MDP4
137 writel(0xB, MSM_MDP_BASE1 + 0x10004);
138 writel(0xB, MSM_MDP_BASE1 + 0x18004);
139#endif
140 writel(1, MSM_MDP_BASE1 + LCDC_BASE + 0x0);
Ajay Dudani232ce812009-12-02 00:14:11 -0800141
142 return &fb_cfg;
143}
Shashank Mittal4f99a882010-02-01 13:58:50 -0800144