aboutsummaryrefslogtreecommitdiff
path: root/board/lge/sniper/hub_dpi.c
blob: ad7c75db64851204515a362a3e548355f9db7dc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* u-boot/board/hub/hub_dpi.c
 *
 * Author: Kyungtae Oh <kyungtae.oh@lge.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */
#include <common.h>
#include <asm/io.h>
#include <asm/arch/gpio.h>
#include <asm/arch/cpu.h>
#include <asm/errno.h>
#include <asm/arch/sys_proto.h>
#include "hub_dss.h"


#define LCD_XRES		480
#define LCD_YRES		800

/* [skykrkrk@lge.com] 2010-01-14, optimized clock speed : 26.585MHz. if 24700 is selected, pixel-clock will be 24.686MHz */
#define LCD_PIXCLOCK_OPT      	26583
#define LCD_PIXCLOCK_MIN      	24700 /* NEC MIN PIX Clock is 21.8MHz */
#define LCD_PIXCLOCK_TYP      	26000 /* Typical PIX clock is 23.8MHz */
#define LCD_PIXCLOCK_MAX      	27300 /* Maximum is 25.7MHz */

/* Current Pixel clock */
#define LCD_PIXEL_CLOCK		LCD_PIXCLOCK_OPT

//PAULK: not used
static struct omap_video_timings hub_panel_timings = {
	/* LGE_CHANGE_S [HEAVEN:FW:tosungmin@lge.com] 2009-09-07, lcd drivers */
	.x_res          = LCD_XRES,
	.y_res          = LCD_YRES,
	.pixel_clock    = LCD_PIXEL_CLOCK,
	.hfp            = 1, //right_margin - 1
	.hsw            = 1, //hsync_len - 1
	.hbp            = 1, //left_margin - 1
	.vfp            = 0, //lower_margin
	.vsw            = 1, //vsync_len - 1
	.vbp            = 0, //upper_margin

};

static u32 hub_config = (OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |OMAP_DSS_LCD_IHS);
static u8 data_lines = 24;
static int hub_acbi = 0; /* ac-bias pin transitions per interrupt */
/* Unit: line clocks */
static int hub_acb = 0; /* ac-bias pin frequency */
static int dss_state = OMAP_DSS_DISPLAY_DISABLED;

static int dpi_set_dsi_clk(bool is_tft, unsigned long pck_req,
		unsigned long *fck, int *lck_div, int *pck_div)
{
	struct dsi_clock_info cinfo;
	int r;

	r = dsi_pll_calc_pck(is_tft, pck_req, &cinfo);
	if (r)
		return r;

	r = dsi_pll_program(&cinfo);
	if (r)
		return r;

	dss_select_clk_source(0, 1);

	dispc_set_lcd_divisor(cinfo.lck_div, cinfo.pck_div);

	*fck = cinfo.dsi1_pll_fclk;
	*lck_div = cinfo.lck_div;
	*pck_div = cinfo.pck_div;

	return 0;
}

static int dpi_set_dispc_clk(bool is_tft, unsigned long pck_req,
		unsigned long *fck, int *lck_div, int *pck_div)
{
	struct dispc_clock_info cinfo;
	int r;

	r = dispc_calc_clock_div(is_tft, pck_req, &cinfo);
	if (r)
		return r;

	r = dispc_set_clock_div(&cinfo);
	if (r)
		return r;

	*fck = cinfo.fck;
	*lck_div = cinfo.lck_div;
	*pck_div = cinfo.pck_div;

	return 0;
}

//PAULK: Not called
static int dpi_set_mode(void)
{
	int lck_div, pck_div;
	unsigned long fck;
	unsigned long pck;
	bool is_tft;
	int r = 0;

	//dss_clk_enable(1);

	dispc_set_pol_freq(hub_config, hub_acbi, hub_acb);

	is_tft = (hub_config & OMAP_DSS_LCD_TFT) != 0;

	r = dpi_set_dsi_clk(is_tft, hub_panel_timings.pixel_clock * 1000,
			&fck, &lck_div, &pck_div);
	//r = dpi_set_dispc_clk(is_tft, hub_panel_timings.pixel_clock * 1000,
	//		&fck, &lck_div, &pck_div);
	if (r)
		goto err0;

	pck = fck / lck_div / pck_div / 1000;

	if (pck != hub_panel_timings.pixel_clock) {
#if 0
		DSSWARN("Could not find exact pixel clock. "
				"Requested %d kHz, got %lu kHz\n",
				t->pixel_clock, pck);
#endif
		hub_panel_timings.pixel_clock = pck;
	}

	dispc_set_lcd_timings(&hub_panel_timings);
	return 0;

err0:
	//dss_clk_enable(0);
	printf("dpi_set_mode_err0\n");
	return r;
}

// PAULK: NOT ACTUALLY CALLED
static int dpi_basic_init(void)
{
	bool is_tft;

	is_tft = (hub_config & OMAP_DSS_LCD_TFT) != 0;

	dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_BYPASS);
	dispc_set_lcd_display_type(is_tft ? OMAP_DSS_LCD_DISPLAY_TFT :
			OMAP_DSS_LCD_DISPLAY_STN);
	dispc_set_tft_data_lines(data_lines);

	return 0;
}

int dss_clk_enable(bool enable)
{
//#define FCK_DSS_ON	0x00000005 /* tv+dss1 (not dss2) */
#define FCK_DSS_ON	0x00000007 /* tv+dss1+dss2 */
#define ICK_DSS_ON	0x00000001

#define CM_FCLKEN_DSS       0x48004e00
#define CM_ICLKEN_DSS       0x48004e10

	if(enable) {
		out_le32(CM_FCLKEN_DSS, FCK_DSS_ON);
		out_le32(CM_ICLKEN_DSS, ICK_DSS_ON);

	}
	else {
		//sr32(CM_FCLKEN_DSS, 0, 32, 0x0);
		//sr32(CM_ICLKEN_DSS, 0, 32, 0x0);
	}

	return 0;
}

// PAULK: NOT ACTUALLY CALLED
static int dpi_display_enable(void)
{
	static int r;

	//dss_clk_enable(1);

	r = dpi_basic_init();
	if (r)
		goto err0;

	//dss_clk_enable(1);

	r = dsi_pll_init(1, 1);

	//r = dpi_set_mode();
	//if (r)
	//	goto err0;

	mdelay(2);

	//dispc_enable_lcd_out(1);

	//dss_state = OMAP_DSS_DISPLAY_ACTIVE;

	return 0;

err0:
	//dispc_enable_lcd_out(0);
	//dss_clk_enable(0);
	printf("kyungtae_dpi_display_enable_err0");
	return r;
}

//PAULK: never called
static void dpi_set_timings(struct omap_video_timings *timings)
{
	if (dss_state == OMAP_DSS_DISPLAY_ACTIVE) {
		dpi_set_mode();
		dispc_go(OMAP_DSS_CHANNEL_LCD);
	}
}

static int dpi_check_timings(struct omap_video_timings *timings)
{
	bool is_tft;
	int r;
	int lck_div, pck_div;
	unsigned long fck;
	unsigned long pck;

	if (!dispc_lcd_timings_ok(timings))
		return -EINVAL;

	if (timings->pixel_clock == 0)
		return -EINVAL;

	is_tft = (hub_config & OMAP_DSS_LCD_TFT) != 0;
	{
		struct dsi_clock_info cinfo;
		r = dsi_pll_calc_pck(is_tft, timings->pixel_clock * 1000,
				&cinfo);

		if (r)
			return r;

		fck = cinfo.dsi1_pll_fclk;
		lck_div = cinfo.lck_div;
		pck_div = cinfo.pck_div;
	}
#if 0
	{
		struct dispc_clock_info cinfo;
		r = dispc_calc_clock_div(is_tft, timings->pixel_clock * 1000,
				&cinfo);

		if (r)
			return r;

		fck = cinfo.fck;
		lck_div = cinfo.lck_div;
		pck_div = cinfo.pck_div;
	}
#endif
	pck = fck / lck_div / pck_div / 1000;

	timings->pixel_clock = pck;

	return 0;
}

static void dpi_get_timings(struct omap_video_timings *timings)
{
	*timings = hub_panel_timings;
}

//PAULK: not actually called
int dpi_init(void)
{
	dpi_display_enable();
	return 0;
}