1 /*-*- linux-c -*-
2  *  linux/drivers/video/i810_dvt.c -- Intel 810 Discrete Video Timings (Intel)
3  *
4  *      Copyright (C) 2001 Antonino Daplas<adaplas@pol.net>
5  *      All Rights Reserved
6  *
7  *
8  *  This file is subject to the terms and conditions of the GNU General Public
9  *  License. See the file COPYING in the main directory of this archive for
10  *  more details.
11  */
12 
13 #include <linux/kernel.h>
14 
15 #include "i810_regs.h"
16 #include "i810.h"
17 #include "i810_main.h"
18 
19 struct mode_registers std_modes[] = {
20 	/* 640x480 @ 60Hz */
21 	{ 25000, 0x0013, 0x0003, 0x40, 0x5F, 0x4F, 0x50, 0x82, 0x51, 0x9D,
22 	  0x0B, 0x10, 0x40, 0xE9, 0x0B, 0xDF, 0x50, 0xE7, 0x04, 0x02,
23 	  0x01, 0x01, 0x01, 0x00, 0x01, 0x22002000, 0x22004000, 0x22006000,
24 	  0x22002000, 0x22004000, 0x22006000, 0xC0 },
25 
26 	/* 640x480 @ 70Hz */
27 	{ 28000, 0x0053, 0x0010, 0x40, 0x61, 0x4F, 0x4F, 0x85, 0x52, 0x9A,
28 	  0xF2, 0x10, 0x40, 0xE0, 0x03, 0xDF, 0x50, 0xDF, 0xF3, 0x01,
29 	  0x01, 0x01, 0x01, 0x00, 0x01, 0x22002000, 0x22004000, 0x22005000,
30           0x22002000, 0x22004000, 0x22005000, 0xC0 },
31 
32         /* 640x480 @ 72Hz */
33         { 31000, 0x0013, 0x0002, 0x40, 0x63, 0x4F, 0x4F, 0x87, 0x52, 0x97,
34           0x06, 0x0F, 0x40, 0xE8, 0x0B, 0xDF, 0x50, 0xDF, 0x07, 0x02,
35           0x01, 0x01, 0x01, 0x00, 0x01, 0x22003000, 0x22005000, 0x22007000,
36           0x22003000, 0x22005000, 0x22007000, 0xC0 },
37 
38         /* 640x480 @ 75Hz */
39         { 31000, 0x0013, 0x0002, 0x40, 0x64, 0x4F, 0x4F, 0x88, 0x51, 0x99,
40           0xF2, 0x10, 0x40, 0xE0, 0x03, 0xDF, 0x50, 0xDF, 0xF3, 0x01,
41           0x01, 0x01, 0x01, 0x00, 0x01, 0x22003000, 0x22005000, 0x22007000,
42           0x22003000, 0x22005000, 0x22007000, 0xC0 },
43 
44         /* 640x480 @ 85Hz */
45         { 36000, 0x0010, 0x0001, 0x40, 0x63, 0x4F, 0x4F, 0x87, 0x56, 0x9D,
46           0xFB, 0x10, 0x40, 0xE0, 0x03, 0xDF, 0x50, 0xDF, 0xFC, 0x01,
47           0x01, 0x01, 0x01, 0x00, 0x01, 0x22003000, 0x22005000, 0x22107000,
48           0x22003000, 0x22005000, 0x22107000, 0xC0 },
49 
50         /* 800x600 @ 56Hz */
51         { 36000, 0x0010, 0x0001, 0x40, 0x7B, 0x63, 0x63, 0x9F, 0x66, 0x8F,
52           0x6F, 0x10, 0x40, 0x58, 0x0A, 0x57, 0xC8, 0x57, 0x70, 0x02,
53           0x02, 0x02, 0x02, 0x00, 0x01, 0x22003000, 0x22005000, 0x22107000,
54           0x22003000, 0x22005000, 0x22107000, 0x00 },
55 
56         /* 800x600 @ 60Hz */
57         { 40000, 0x0008, 0x0001, 0x30, 0x7F, 0x63, 0x63, 0x83, 0x68, 0x18,
58           0x72, 0x10, 0x40, 0x58, 0x0C, 0x57, 0xC8, 0x57, 0x73, 0x02,
59           0x02, 0x02, 0x02, 0x00, 0x00, 0x22003000, 0x22006000, 0x22108000,
60           0x22003000, 0x22006000, 0x22108000, 0x00 },
61 
62         /* 800x600 @ 70Hz */
63         { 45000, 0x0054, 0x0015, 0x30, 0x7D, 0x63, 0x63, 0x81, 0x68, 0x12,
64           0x6f, 0x10, 0x40, 0x58, 0x0b, 0x57, 0x64, 0x57, 0x70, 0x02,
65           0x02, 0x02, 0x02, 0x00, 0x00, 0x22004000, 0x22007000, 0x2210A000,
66           0x22004000, 0x22007000, 0x2210A000, 0x00 },
67 
68         /* 800x600 @ 72Hz */
69         { 50000, 0x0017, 0x0004, 0x30, 0x7D, 0x63, 0x63, 0x81, 0x6A, 0x19,
70           0x98, 0x10, 0x40, 0x7C, 0x02, 0x57, 0xC8, 0x57, 0x99, 0x02,
71           0x02, 0x02, 0x02, 0x00, 0x00, 0x22004000, 0x22007000, 0x2210A000,
72           0x22004000, 0x22007000, 0x2210A000, 0x00 },
73 
74         /* 800x600 @ 75Hz */
75         { 49000, 0x001F, 0x0006, 0x30, 0x7F, 0x63, 0x63, 0x83, 0x65, 0x0F,
76           0x6F, 0x10, 0x40, 0x58, 0x0B, 0x57, 0xC8, 0x57, 0x70, 0x02,
77           0x02, 0x02, 0x02, 0x00, 0x00, 0x22004000, 0x22007000, 0x2210B000,
78           0x22004000, 0x22007000, 0x2210B000, 0x00 },
79 
80         /* 800x600 @ 85Hz */
81         { 56000, 0x0049, 0x000E, 0x30, 0x7E, 0x63, 0x63, 0x82, 0x67, 0x0F,
82           0x75, 0x10, 0x40, 0x58, 0x0B, 0x57, 0xC8, 0x57, 0x76, 0x02,
83           0x02, 0x02, 0x02, 0x00, 0x00, 0x22004000, 0x22108000, 0x2210b000,
84           0x22004000, 0x22108000, 0x2210b000, 0x00 },
85 
86         /* 1024x768 @ 60Hz */
87         { 65000, 0x003F, 0x000A, 0x30, 0xA3, 0x7F, 0x7F, 0x87, 0x83, 0x94,
88           0x24, 0x10, 0x40, 0x02, 0x08, 0xFF, 0x80, 0xFF, 0x25, 0x03,
89           0x02, 0x03, 0x02, 0x00, 0x00, 0x22005000, 0x22109000, 0x2220D000,
90           0x22005000, 0x22109000, 0x2220D000, 0xC0 },
91 
92         /* 1024x768 @ 70Hz */
93 	{ 75000, 0x0017, 0x0002, 0x30, 0xA1, 0x7F, 0x7F, 0x85, 0x82, 0x93,
94 	  0x24, 0x10, 0x40, 0x02, 0x08, 0xFF, 0x80, 0xFF, 0x25, 0x03,
95 	  0x02, 0x03, 0x02, 0x00, 0x00, 0x22005000, 0x2210A000, 0x2220F000,
96 	  0x22005000, 0x2210A000, 0x2220F000, 0xC0 },
97 
98 	/* 1024x768 @ 75Hz */
99 	{ 78000, 0x0050, 0x0017, 0x20, 0x9F, 0x7F, 0x7F, 0x83, 0x81, 0x8D,
100 	  0x1E, 0x10, 0x40, 0x00, 0x03, 0xFF, 0x80, 0xFF, 0x1F, 0x03,
101 	  0x02, 0x03, 0x02, 0x00, 0x00, 0x22006000, 0x2210B000, 0x22210000,
102 	  0x22006000, 0x2210B000, 0x22210000, 0x00 },
103 
104 	/* 1024x768 @ 85Hz */
105 	{ 94000, 0x003D, 0x000E, 0x20, 0xA7, 0x7F, 0x7F, 0x8B, 0x85, 0x91,
106 	  0x26, 0x10, 0x40, 0x00, 0x03, 0xFF, 0x80, 0xFF, 0x27, 0x03,
107 	  0x02, 0x03, 0x02, 0x00, 0x00, 0x22007000, 0x2220E000, 0x22212000,
108 	  0x22007000, 0x2220E000, 0x22212000, 0x00 },
109 
110 	/* 1152x864 @ 60Hz */
111 	{ 80000, 0x0008, 0x0001, 0x20, 0xB3, 0x8F, 0x8F, 0x97, 0x93, 0x9f,
112 	  0x87, 0x10, 0x40, 0x60, 0x03, 0x5F, 0x90, 0x5f, 0x88, 0x03,
113 	  0x03, 0x03, 0x03, 0x00, 0x00, 0x2220C000, 0x22210000, 0x22415000,
114 	  0x2220C000, 0x22210000, 0x22415000, 0x00 },
115 
116 	/* 1152x864 @ 70Hz */
117 	{ 96000, 0x000a, 0x0001, 0x20, 0xbb, 0x8F, 0x8F, 0x9f, 0x98, 0x87,
118 	  0x82, 0x10, 0x40, 0x60, 0x03, 0x5F, 0x90, 0x5F, 0x83, 0x03,
119 	  0x03, 0x03, 0x03, 0x00, 0x00, 0x22107000, 0x22210000, 0x22415000,
120 	  0x22107000, 0x22210000, 0x22415000, 0x00 },
121 
122 	/* 1152x864 @ 72Hz */
123 	{ 99000, 0x001f, 0x0006, 0x20, 0xbb, 0x8F, 0x8F, 0x9f, 0x98, 0x87,
124 	  0x83, 0x10, 0x40, 0x60, 0x03, 0x5F, 0x90, 0x5F, 0x84, 0x03,
125 	  0x03, 0x03, 0x03, 0x00, 0x00, 0x22107000, 0x22210000, 0x22415000,
126 	  0x22107000, 0x22210000, 0x22415000, 0x00 },
127 
128 	/* 1152x864 @ 75Hz */
129 	{ 108000, 0x0010, 0x0002, 0x20, 0xC3, 0x8F, 0x8F, 0x87, 0x97, 0x07,
130 	  0x82, 0x10, 0x40, 0x60, 0x03, 0x5F, 0x90, 0x5F, 0x83, 0x03,
131 	  0x03, 0x03, 0x03, 0x00, 0x01, 0x22107000, 0x22210000, 0x22415000,
132 	  0x22107000, 0x22210000, 0x22415000, 0x00 },
133 
134 	/* 1152x864 @ 85Hz */
135 	{ 121000, 0x006D, 0x0014, 0x20, 0xc0, 0x8F, 0x8F, 0x84, 0x97, 0x07,
136 	  0x93, 0x10, 0x40, 0x60, 0x03, 0x5F, 0x90, 0x5F, 0x94, 0x03,
137 	  0x03, 0x03, 0x03, 0x00, 0x01, 0x2220C000, 0x22210000, 0x22415000,
138 	  0x2220C000, 0x22210000, 0x22415000, 0x0 },
139 
140 	/* 1280x960 @ 60Hz */
141 	{ 108000, 0x0010, 0x0002, 0x20, 0xDC, 0x9F, 0x9F, 0x80, 0xAB, 0x99,
142 	  0xE6, 0x10, 0x40, 0xC0, 0x03, 0xBF, 0xA0, 0xBF, 0xE7, 0x03,
143 	  0x03, 0x03, 0x03, 0x00, 0x01, 0x2210A000, 0x22210000, 0x22415000,
144 	  0x2210A000, 0x22210000, 0x22415000, 0x00 },
145 
146 	/* 1280x960 @ 75Hz */
147 	{ 129000, 0x0029, 0x0006, 0x20, 0xD3, 0x9F, 0x9F, 0x97, 0xaa, 0x1b,
148 	  0xE8, 0x10, 0x40, 0xC0, 0x03, 0xBF, 0xA0, 0xBF, 0xE9, 0x03,
149 	  0x03, 0x03, 0x03, 0x00, 0x01, 0x2210A000, 0x22210000, 0x2241B000,
150 	  0x2210A000, 0x22210000, 0x2241B000, 0x00 },
151 
152 	/* 1280x960 @ 85Hz */
153 	{ 148000, 0x0042, 0x0009, 0x20, 0xD3, 0x9F, 0x9F, 0x97, 0xA7, 0x1B,
154 	  0xF1, 0x10, 0x40, 0xC0, 0x03, 0xBF, 0xA0, 0xBF, 0xF2, 0x03,
155 	  0x03, 0x03, 0x03, 0x00, 0x01, 0x2210A000, 0x22220000, 0x2241D000,
156 	  0x2210A000, 0x22220000, 0x2241D000, 0x00 },
157 
158 	/* 1600x1200 @ 60Hz */
159 	{ 162000, 0x0019, 0x0006, 0x10, 0x09, 0xC7, 0xC7, 0x8D, 0xcf, 0x07,
160 	  0xE0, 0x10, 0x40, 0xB0, 0x03, 0xAF, 0xC8, 0xAF, 0xE1, 0x04,
161 	  0x04, 0x04, 0x04, 0x01, 0x00, 0x2210b000, 0x22416000, 0x44419000,
162 	  0x2210b000, 0x22416000, 0x44419000, 0x00 },
163 
164 	/* 1600x1200 @ 65 Hz */
165 	{ 175000, 0x005d, 0x0018, 0x10, 0x09, 0xC7, 0xC7, 0x8D, 0xcf, 0x07,
166 	  0xE0, 0x10, 0x40, 0xB0, 0x03, 0xAF, 0xC8, 0xAF, 0xE1, 0x04,
167 	  0x04, 0x04, 0x04, 0x01, 0x00, 0x2210c000, 0x22416000, 0x44419000,
168 	  0x2210c000, 0x22416000, 0x44419000, 0x00 },
169 
170 	/* 1600x1200 @ 70 Hz */
171 	{ 189000, 0x003D, 0x000e, 0x10, 0x09, 0xC7, 0xC7, 0x8d, 0xcf, 0x07,
172 	  0xE0, 0x10, 0x40, 0xb0, 0x03, 0xAF, 0xC8, 0xaf, 0xE1, 0x04,
173 	  0x04, 0x04, 0x04, 0x01, 0x00, 0x2220e000, 0x22416000, 0x44419000,
174 	  0x2220e000, 0x22416000, 0x44419000, 0x00 },
175 
176  	/* 1600x1200 @ 72 Hz */
177  	{ 195000, 0x003f, 0x000e, 0x10, 0x0b, 0xC7, 0xC7, 0x8f, 0xd5, 0x0b,
178  	  0xE1, 0x10, 0x40, 0xb0, 0x03, 0xAF, 0xC8, 0xaf, 0xe2, 0x04, 0x04,
179  	  0x04, 0x04, 0x01, 0x00, 0x2220e000, 0x22416000, 0x44419000,
180  	  0x2220e000, 0x22416000, 0x44419000, 0x00 },
181 
182  	/* 1600x1200 @ 75 Hz */
183  	{ 202000, 0x0024, 0x0007, 0x10, 0x09, 0xC7, 0xC7, 0x8d, 0xcf, 0x07,
184  	  0xE0, 0x10, 0x40, 0xb0, 0x03, 0xAF, 0xC8, 0xaf, 0xE1, 0x04, 0x04,
185  	  0x04, 0x04, 0x01, 0x00, 0x2220e000, 0x22416000, 0x44419000,
186  	  0x2220e000, 0x22416000, 0x44419000,  0x00 },
187 
188  	/* 1600x1200 @ 85 Hz */
189 	{ 229000, 0x0029, 0x0007, 0x10, 0x09, 0xC7, 0xC7, 0x8d, 0xcf, 0x07,
190 	  0xE0, 0x10, 0x40, 0xb0, 0x03, 0xAF, 0xC8, 0xaf, 0xE1, 0x04, 0x04,
191 	  0x04, 0x04, 0x01, 0x00, 0x22210000, 0x22416000, 0x0,
192 	  0x22210000, 0x22416000, 0x0, 0x00 },
193 };
194 
round_off_xres(u32 * xres)195 void round_off_xres(u32 *xres)
196 {
197 	if (*xres <= 640)
198 		*xres = 640;
199 	else if (*xres <= 800)
200 		*xres = 800;
201 	else if (*xres <= 1024)
202 		*xres = 1024;
203 	else if (*xres <= 1152)
204 		*xres = 1152;
205 	else if (*xres <= 1280)
206 		*xres = 1280;
207 	else
208 		*xres = 1600;
209 }
210 
round_off_yres(u32 * xres,u32 * yres)211 inline void round_off_yres(u32 *xres, u32 *yres)
212 {
213 	*yres = (*xres * 3) >> 2;
214 }
215 
i810fb_find_best_mode(u32 xres,u32 yres,u32 pixclock)216 static int i810fb_find_best_mode(u32 xres, u32 yres, u32 pixclock)
217 {
218 	u32 diff = 0, diff_best = 0xFFFFFFFF, i = 0, i_best = 0;
219 	u8 hfl = (u8) ((xres >> 3) - 1);
220 
221 	for (i = 0; i < ARRAY_SIZE(std_modes); i++) {
222 		if (std_modes[i].cr01 == hfl) {
223 			if (std_modes[i].pixclock <= pixclock)
224 				diff = pixclock - std_modes[i].pixclock;
225 			if (diff < diff_best) {
226 		    		i_best = i;
227 		    		diff_best = diff;
228 			}
229 		}
230 	}
231 	return i_best;
232 }
233 
i810fb_encode_registers(const struct fb_var_screeninfo * var,struct i810fb_par * par,u32 xres,u32 yres)234 void i810fb_encode_registers(const struct fb_var_screeninfo *var,
235 			     struct i810fb_par *par, u32 xres, u32 yres)
236 {
237 	u32 i_best = i810fb_find_best_mode(xres, yres, par->regs.pixclock);
238 
239 	par->regs = std_modes[i_best];
240 
241 	/* overlay */
242 	par->ovract = ((xres + var->right_margin + var->hsync_len +
243 			var->left_margin - 32) | ((xres - 32) << 16));
244 }
245 
i810fb_fill_var_timings(struct fb_var_screeninfo * var)246 void i810fb_fill_var_timings(struct fb_var_screeninfo *var)
247 {
248 	u32 total, xres, yres;
249 	u32 mode, pixclock;
250 
251 	xres = var->xres;
252 	yres = var->yres;
253 
254 	pixclock = 1000000000 / var->pixclock;
255 	mode = i810fb_find_best_mode(xres, yres, pixclock);
256 
257 	total = (std_modes[mode].cr00 | (std_modes[mode].cr35 & 1) << 8) + 3;
258 	total <<= 3;
259 
260 	var->pixclock = 1000000000 / std_modes[mode].pixclock;
261 	var->right_margin = (std_modes[mode].cr04 << 3) - xres;
262 	var->hsync_len = ((std_modes[mode].cr05 & 0x1F) -
263 			 (std_modes[mode].cr04 & 0x1F)) << 3;
264 	var->left_margin = (total - (xres + var->right_margin +
265 				     var->hsync_len));
266 	var->sync = FB_SYNC_ON_GREEN;
267 	if (~(std_modes[mode].msr & (1 << 6)))
268 		var->sync |= FB_SYNC_HOR_HIGH_ACT;
269 	if (~(std_modes[mode].msr & (1 << 7)))
270 		var->sync |= FB_SYNC_VERT_HIGH_ACT;
271 
272 	total = (std_modes[mode].cr06 | (std_modes[mode].cr30 & 0xF)  << 8) + 2;
273 	var->lower_margin = (std_modes[mode].cr10 |
274 			    (std_modes[mode].cr32 & 0x0F) << 8) - yres;
275 	var->vsync_len = (std_modes[mode].cr11 & 0x0F) -
276 			 (var->lower_margin & 0x0F);
277 	var->upper_margin = total - (yres + var->lower_margin + var->vsync_len);
278 }
279 
i810_get_watermark(const struct fb_var_screeninfo * var,struct i810fb_par * par)280 u32 i810_get_watermark(const struct fb_var_screeninfo *var,
281 		       struct i810fb_par *par)
282 {
283 	struct mode_registers *params = &par->regs;
284 	u32 wmark = 0;
285 
286 	if (par->mem_freq == 100) {
287 		switch (var->bits_per_pixel) {
288 		case 8:
289 			wmark = params->bpp8_100;
290 			break;
291 		case 16:
292 			wmark = params->bpp16_100;
293 			break;
294 		case 24:
295 		case 32:
296 			wmark = params->bpp24_100;
297 		}
298 	} else {
299 		switch (var->bits_per_pixel) {
300 		case 8:
301 			wmark = params->bpp8_133;
302 			break;
303 		case 16:
304 			wmark = params->bpp16_133;
305 			break;
306 		case 24:
307 		case 32:
308 			wmark = params->bpp24_133;
309 		}
310 	}
311 	return wmark;
312 }
313 
314