]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /*-*- linux-c -*- |
2 | * linux/drivers/video/i810_main.c -- Intel 810 frame buffer device | |
3 | * | |
4 | * Copyright (C) 2001 Antonino Daplas<adaplas@pol.net> | |
5 | * All Rights Reserved | |
6 | * | |
7 | * Contributors: | |
8 | * Michael Vogt <mvogt@acm.org> - added support for Intel 815 chipsets | |
9 | * and enabling the power-on state of | |
10 | * external VGA connectors for | |
11 | * secondary displays | |
12 | * | |
13 | * Fredrik Andersson <krueger@shell.linux.se> - alpha testing of | |
14 | * the VESA GTF | |
15 | * | |
16 | * Brad Corrion <bcorrion@web-co.com> - alpha testing of customized | |
17 | * timings support | |
18 | * | |
19 | * The code framework is a modification of vfb.c by Geert Uytterhoeven. | |
20 | * DotClock and PLL calculations are partly based on i810_driver.c | |
21 | * in xfree86 v4.0.3 by Precision Insight. | |
22 | * Watermark calculation and tables are based on i810_wmark.c | |
23 | * in xfre86 v4.0.3 by Precision Insight. Slight modifications | |
24 | * only to allow for integer operations instead of floating point. | |
25 | * | |
26 | * This file is subject to the terms and conditions of the GNU General Public | |
27 | * License. See the file COPYING in the main directory of this archive for | |
28 | * more details. | |
29 | */ | |
30 | ||
31 | #include <linux/module.h> | |
1da177e4 LT |
32 | #include <linux/kernel.h> |
33 | #include <linux/errno.h> | |
34 | #include <linux/string.h> | |
35 | #include <linux/mm.h> | |
1da177e4 LT |
36 | #include <linux/slab.h> |
37 | #include <linux/fb.h> | |
38 | #include <linux/init.h> | |
39 | #include <linux/pci.h> | |
40 | #include <linux/pci_ids.h> | |
41 | #include <linux/resource.h> | |
42 | #include <linux/unistd.h> | |
c5eec03f | 43 | #include <linux/console.h> |
1da177e4 LT |
44 | |
45 | #include <asm/io.h> | |
46 | #include <asm/div64.h> | |
1da177e4 LT |
47 | #include <asm/page.h> |
48 | ||
49 | #include "i810_regs.h" | |
50 | #include "i810.h" | |
51 | #include "i810_main.h" | |
52 | ||
a0aa7d06 AB |
53 | /* |
54 | * voffset - framebuffer offset in MiB from aperture start address. In order for | |
55 | * the driver to work with X, we must try to use memory holes left untouched by X. The | |
56 | * following table lists where X's different surfaces start at. | |
57 | * | |
58 | * --------------------------------------------- | |
59 | * : : 64 MiB : 32 MiB : | |
60 | * ---------------------------------------------- | |
61 | * : FrontBuffer : 0 : 0 : | |
62 | * : DepthBuffer : 48 : 16 : | |
63 | * : BackBuffer : 56 : 24 : | |
64 | * ---------------------------------------------- | |
65 | * | |
66 | * So for chipsets with 64 MiB Aperture sizes, 32 MiB for v_offset is okay, allowing up to | |
67 | * 15 + 1 MiB of Framebuffer memory. For 32 MiB Aperture sizes, a v_offset of 8 MiB should | |
68 | * work, allowing 7 + 1 MiB of Framebuffer memory. | |
69 | * Note, the size of the hole may change depending on how much memory you allocate to X, | |
70 | * and how the memory is split up between these surfaces. | |
71 | * | |
72 | * Note: Anytime the DepthBuffer or FrontBuffer is overlapped, X would still run but with | |
73 | * DRI disabled. But if the Frontbuffer is overlapped, X will fail to load. | |
74 | * | |
75 | * Experiment with v_offset to find out which works best for you. | |
76 | */ | |
9e8a3d22 AM |
77 | static u32 v_offset_default __devinitdata; /* For 32 MiB Aper size, 8 should be the default */ |
78 | static u32 voffset __devinitdata; | |
a0aa7d06 AB |
79 | |
80 | static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor); | |
81 | static int __devinit i810fb_init_pci (struct pci_dev *dev, | |
82 | const struct pci_device_id *entry); | |
83 | static void __exit i810fb_remove_pci(struct pci_dev *dev); | |
84 | static int i810fb_resume(struct pci_dev *dev); | |
85 | static int i810fb_suspend(struct pci_dev *dev, pm_message_t state); | |
86 | ||
87 | /* Chipset Specific Functions */ | |
88 | static int i810fb_set_par (struct fb_info *info); | |
89 | static int i810fb_getcolreg (u8 regno, u8 *red, u8 *green, u8 *blue, | |
90 | u8 *transp, struct fb_info *info); | |
91 | static int i810fb_setcolreg (unsigned regno, unsigned red, unsigned green, unsigned blue, | |
92 | unsigned transp, struct fb_info *info); | |
93 | static int i810fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info); | |
94 | static int i810fb_blank (int blank_mode, struct fb_info *info); | |
95 | ||
96 | /* Initialization */ | |
97 | static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par); | |
98 | ||
1da177e4 LT |
99 | /* PCI */ |
100 | static const char *i810_pci_list[] __devinitdata = { | |
101 | "Intel(R) 810 Framebuffer Device" , | |
102 | "Intel(R) 810-DC100 Framebuffer Device" , | |
103 | "Intel(R) 810E Framebuffer Device" , | |
104 | "Intel(R) 815 (Internal Graphics 100Mhz FSB) Framebuffer Device" , | |
105 | "Intel(R) 815 (Internal Graphics only) Framebuffer Device" , | |
106 | "Intel(R) 815 (Internal Graphics with AGP) Framebuffer Device" | |
107 | }; | |
108 | ||
109 | static struct pci_device_id i810fb_pci_tbl[] = { | |
110 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG1, | |
111 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, | |
112 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3, | |
113 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, | |
114 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810E_IG, | |
115 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 }, | |
116 | /* mvo: added i815 PCI-ID */ | |
117 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_100, | |
118 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 }, | |
119 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_NOAGP, | |
120 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 }, | |
121 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC, | |
122 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 }, | |
123 | { 0 }, | |
124 | }; | |
125 | ||
126 | static struct pci_driver i810fb_driver = { | |
127 | .name = "i810fb", | |
128 | .id_table = i810fb_pci_tbl, | |
129 | .probe = i810fb_init_pci, | |
130 | .remove = __exit_p(i810fb_remove_pci), | |
131 | .suspend = i810fb_suspend, | |
132 | .resume = i810fb_resume, | |
133 | }; | |
134 | ||
74f6ae84 AD |
135 | static char *mode_option __devinitdata = NULL; |
136 | static int vram __devinitdata = 4; | |
137 | static int bpp __devinitdata = 8; | |
595e8a97 AD |
138 | static int mtrr __devinitdata; |
139 | static int accel __devinitdata; | |
140 | static int hsync1 __devinitdata; | |
141 | static int hsync2 __devinitdata; | |
142 | static int vsync1 __devinitdata; | |
143 | static int vsync2 __devinitdata; | |
144 | static int xres __devinitdata; | |
145 | static int yres __devinitdata; | |
146 | static int vyres __devinitdata; | |
147 | static int sync __devinitdata; | |
747a5054 | 148 | static int extvga __devinitdata; |
595e8a97 | 149 | static int dcolor __devinitdata; |
00d340b9 | 150 | static int ddc3 __devinitdata = 2; |
1da177e4 LT |
151 | |
152 | /*------------------------------------------------------------*/ | |
153 | ||
154 | /************************************************************** | |
155 | * Hardware Low Level Routines * | |
156 | **************************************************************/ | |
157 | ||
158 | /** | |
159 | * i810_screen_off - turns off/on display | |
160 | * @mmio: address of register space | |
161 | * @mode: on or off | |
162 | * | |
163 | * DESCRIPTION: | |
164 | * Blanks/unblanks the display | |
165 | */ | |
166 | static void i810_screen_off(u8 __iomem *mmio, u8 mode) | |
167 | { | |
168 | u32 count = WAIT_COUNT; | |
169 | u8 val; | |
170 | ||
171 | i810_writeb(SR_INDEX, mmio, SR01); | |
172 | val = i810_readb(SR_DATA, mmio); | |
173 | val = (mode == OFF) ? val | SCR_OFF : | |
174 | val & ~SCR_OFF; | |
175 | ||
176 | while((i810_readw(DISP_SL, mmio) & 0xFFF) && count--); | |
177 | i810_writeb(SR_INDEX, mmio, SR01); | |
178 | i810_writeb(SR_DATA, mmio, val); | |
179 | } | |
180 | ||
181 | /** | |
182 | * i810_dram_off - turns off/on dram refresh | |
183 | * @mmio: address of register space | |
184 | * @mode: on or off | |
185 | * | |
186 | * DESCRIPTION: | |
187 | * Turns off DRAM refresh. Must be off for only 2 vsyncs | |
188 | * before data becomes corrupt | |
189 | */ | |
190 | static void i810_dram_off(u8 __iomem *mmio, u8 mode) | |
191 | { | |
192 | u8 val; | |
193 | ||
194 | val = i810_readb(DRAMCH, mmio); | |
195 | val &= DRAM_OFF; | |
196 | val = (mode == OFF) ? val : val | DRAM_ON; | |
197 | i810_writeb(DRAMCH, mmio, val); | |
198 | } | |
199 | ||
200 | /** | |
201 | * i810_protect_regs - allows rw/ro mode of certain VGA registers | |
202 | * @mmio: address of register space | |
203 | * @mode: protect/unprotect | |
204 | * | |
205 | * DESCRIPTION: | |
206 | * The IBM VGA standard allows protection of certain VGA registers. | |
207 | * This will protect or unprotect them. | |
208 | */ | |
209 | static void i810_protect_regs(u8 __iomem *mmio, int mode) | |
210 | { | |
211 | u8 reg; | |
212 | ||
213 | i810_writeb(CR_INDEX_CGA, mmio, CR11); | |
214 | reg = i810_readb(CR_DATA_CGA, mmio); | |
215 | reg = (mode == OFF) ? reg & ~0x80 : | |
216 | reg | 0x80; | |
217 | ||
218 | i810_writeb(CR_INDEX_CGA, mmio, CR11); | |
219 | i810_writeb(CR_DATA_CGA, mmio, reg); | |
220 | } | |
221 | ||
222 | /** | |
223 | * i810_load_pll - loads values for the hardware PLL clock | |
224 | * @par: pointer to i810fb_par structure | |
225 | * | |
226 | * DESCRIPTION: | |
227 | * Loads the P, M, and N registers. | |
228 | */ | |
229 | static void i810_load_pll(struct i810fb_par *par) | |
230 | { | |
231 | u32 tmp1, tmp2; | |
232 | u8 __iomem *mmio = par->mmio_start_virtual; | |
233 | ||
234 | tmp1 = par->regs.M | par->regs.N << 16; | |
235 | tmp2 = i810_readl(DCLK_2D, mmio); | |
236 | tmp2 &= ~MN_MASK; | |
237 | i810_writel(DCLK_2D, mmio, tmp1 | tmp2); | |
238 | ||
239 | tmp1 = par->regs.P; | |
240 | tmp2 = i810_readl(DCLK_0DS, mmio); | |
241 | tmp2 &= ~(P_OR << 16); | |
242 | i810_writel(DCLK_0DS, mmio, (tmp1 << 16) | tmp2); | |
243 | ||
244 | i810_writeb(MSR_WRITE, mmio, par->regs.msr | 0xC8 | 1); | |
245 | ||
246 | } | |
247 | ||
248 | /** | |
249 | * i810_load_vga - load standard VGA registers | |
250 | * @par: pointer to i810fb_par structure | |
251 | * | |
252 | * DESCRIPTION: | |
253 | * Load values to VGA registers | |
254 | */ | |
255 | static void i810_load_vga(struct i810fb_par *par) | |
256 | { | |
257 | u8 __iomem *mmio = par->mmio_start_virtual; | |
258 | ||
259 | /* interlace */ | |
260 | i810_writeb(CR_INDEX_CGA, mmio, CR70); | |
261 | i810_writeb(CR_DATA_CGA, mmio, par->interlace); | |
262 | ||
263 | i810_writeb(CR_INDEX_CGA, mmio, CR00); | |
264 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr00); | |
265 | i810_writeb(CR_INDEX_CGA, mmio, CR01); | |
266 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr01); | |
267 | i810_writeb(CR_INDEX_CGA, mmio, CR02); | |
268 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr02); | |
269 | i810_writeb(CR_INDEX_CGA, mmio, CR03); | |
270 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr03); | |
271 | i810_writeb(CR_INDEX_CGA, mmio, CR04); | |
272 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr04); | |
273 | i810_writeb(CR_INDEX_CGA, mmio, CR05); | |
274 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr05); | |
275 | i810_writeb(CR_INDEX_CGA, mmio, CR06); | |
276 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr06); | |
277 | i810_writeb(CR_INDEX_CGA, mmio, CR09); | |
278 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr09); | |
279 | i810_writeb(CR_INDEX_CGA, mmio, CR10); | |
280 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr10); | |
281 | i810_writeb(CR_INDEX_CGA, mmio, CR11); | |
282 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr11); | |
283 | i810_writeb(CR_INDEX_CGA, mmio, CR12); | |
284 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr12); | |
285 | i810_writeb(CR_INDEX_CGA, mmio, CR15); | |
286 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr15); | |
287 | i810_writeb(CR_INDEX_CGA, mmio, CR16); | |
288 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr16); | |
289 | } | |
290 | ||
291 | /** | |
292 | * i810_load_vgax - load extended VGA registers | |
293 | * @par: pointer to i810fb_par structure | |
294 | * | |
295 | * DESCRIPTION: | |
296 | * Load values to extended VGA registers | |
297 | */ | |
298 | static void i810_load_vgax(struct i810fb_par *par) | |
299 | { | |
300 | u8 __iomem *mmio = par->mmio_start_virtual; | |
301 | ||
302 | i810_writeb(CR_INDEX_CGA, mmio, CR30); | |
303 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr30); | |
304 | i810_writeb(CR_INDEX_CGA, mmio, CR31); | |
305 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr31); | |
306 | i810_writeb(CR_INDEX_CGA, mmio, CR32); | |
307 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr32); | |
308 | i810_writeb(CR_INDEX_CGA, mmio, CR33); | |
309 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr33); | |
310 | i810_writeb(CR_INDEX_CGA, mmio, CR35); | |
311 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr35); | |
312 | i810_writeb(CR_INDEX_CGA, mmio, CR39); | |
313 | i810_writeb(CR_DATA_CGA, mmio, par->regs.cr39); | |
314 | } | |
315 | ||
316 | /** | |
317 | * i810_load_2d - load grahics registers | |
318 | * @par: pointer to i810fb_par structure | |
319 | * | |
320 | * DESCRIPTION: | |
321 | * Load values to graphics registers | |
322 | */ | |
323 | static void i810_load_2d(struct i810fb_par *par) | |
324 | { | |
325 | u32 tmp; | |
326 | u8 tmp8; | |
327 | u8 __iomem *mmio = par->mmio_start_virtual; | |
328 | ||
329 | i810_writel(FW_BLC, mmio, par->watermark); | |
330 | tmp = i810_readl(PIXCONF, mmio); | |
331 | tmp |= 1 | 1 << 20; | |
332 | i810_writel(PIXCONF, mmio, tmp); | |
333 | ||
334 | i810_writel(OVRACT, mmio, par->ovract); | |
335 | ||
336 | i810_writeb(GR_INDEX, mmio, GR10); | |
337 | tmp8 = i810_readb(GR_DATA, mmio); | |
338 | tmp8 |= 2; | |
339 | i810_writeb(GR_INDEX, mmio, GR10); | |
340 | i810_writeb(GR_DATA, mmio, tmp8); | |
341 | } | |
342 | ||
343 | /** | |
344 | * i810_hires - enables high resolution mode | |
345 | * @mmio: address of register space | |
346 | */ | |
347 | static void i810_hires(u8 __iomem *mmio) | |
348 | { | |
349 | u8 val; | |
350 | ||
351 | i810_writeb(CR_INDEX_CGA, mmio, CR80); | |
352 | val = i810_readb(CR_DATA_CGA, mmio); | |
353 | i810_writeb(CR_INDEX_CGA, mmio, CR80); | |
354 | i810_writeb(CR_DATA_CGA, mmio, val | 1); | |
63edceac AD |
355 | /* Stop LCD displays from flickering */ |
356 | i810_writel(MEM_MODE, mmio, i810_readl(MEM_MODE, mmio) | 4); | |
1da177e4 LT |
357 | } |
358 | ||
359 | /** | |
360 | * i810_load_pitch - loads the characters per line of the display | |
361 | * @par: pointer to i810fb_par structure | |
362 | * | |
363 | * DESCRIPTION: | |
364 | * Loads the characters per line | |
365 | */ | |
366 | static void i810_load_pitch(struct i810fb_par *par) | |
367 | { | |
368 | u32 tmp, pitch; | |
369 | u8 val; | |
370 | u8 __iomem *mmio = par->mmio_start_virtual; | |
371 | ||
372 | pitch = par->pitch >> 3; | |
373 | i810_writeb(SR_INDEX, mmio, SR01); | |
374 | val = i810_readb(SR_DATA, mmio); | |
375 | val &= 0xE0; | |
376 | val |= 1 | 1 << 2; | |
377 | i810_writeb(SR_INDEX, mmio, SR01); | |
378 | i810_writeb(SR_DATA, mmio, val); | |
379 | ||
380 | tmp = pitch & 0xFF; | |
381 | i810_writeb(CR_INDEX_CGA, mmio, CR13); | |
382 | i810_writeb(CR_DATA_CGA, mmio, (u8) tmp); | |
383 | ||
384 | tmp = pitch >> 8; | |
385 | i810_writeb(CR_INDEX_CGA, mmio, CR41); | |
386 | val = i810_readb(CR_DATA_CGA, mmio) & ~0x0F; | |
387 | i810_writeb(CR_INDEX_CGA, mmio, CR41); | |
388 | i810_writeb(CR_DATA_CGA, mmio, (u8) tmp | val); | |
389 | } | |
390 | ||
391 | /** | |
392 | * i810_load_color - loads the color depth of the display | |
393 | * @par: pointer to i810fb_par structure | |
394 | * | |
395 | * DESCRIPTION: | |
396 | * Loads the color depth of the display and the graphics engine | |
397 | */ | |
398 | static void i810_load_color(struct i810fb_par *par) | |
399 | { | |
400 | u8 __iomem *mmio = par->mmio_start_virtual; | |
401 | u32 reg1; | |
402 | u16 reg2; | |
403 | ||
404 | reg1 = i810_readl(PIXCONF, mmio) & ~(0xF0000 | 1 << 27); | |
405 | reg2 = i810_readw(BLTCNTL, mmio) & ~0x30; | |
406 | ||
407 | reg1 |= 0x8000 | par->pixconf; | |
408 | reg2 |= par->bltcntl; | |
409 | i810_writel(PIXCONF, mmio, reg1); | |
410 | i810_writew(BLTCNTL, mmio, reg2); | |
411 | } | |
412 | ||
413 | /** | |
414 | * i810_load_regs - loads all registers for the mode | |
415 | * @par: pointer to i810fb_par structure | |
416 | * | |
417 | * DESCRIPTION: | |
418 | * Loads registers | |
419 | */ | |
420 | static void i810_load_regs(struct i810fb_par *par) | |
421 | { | |
422 | u8 __iomem *mmio = par->mmio_start_virtual; | |
423 | ||
424 | i810_screen_off(mmio, OFF); | |
425 | i810_protect_regs(mmio, OFF); | |
426 | i810_dram_off(mmio, OFF); | |
427 | i810_load_pll(par); | |
428 | i810_load_vga(par); | |
429 | i810_load_vgax(par); | |
430 | i810_dram_off(mmio, ON); | |
431 | i810_load_2d(par); | |
432 | i810_hires(mmio); | |
433 | i810_screen_off(mmio, ON); | |
434 | i810_protect_regs(mmio, ON); | |
435 | i810_load_color(par); | |
436 | i810_load_pitch(par); | |
437 | } | |
438 | ||
439 | static void i810_write_dac(u8 regno, u8 red, u8 green, u8 blue, | |
440 | u8 __iomem *mmio) | |
441 | { | |
442 | i810_writeb(CLUT_INDEX_WRITE, mmio, regno); | |
443 | i810_writeb(CLUT_DATA, mmio, red); | |
444 | i810_writeb(CLUT_DATA, mmio, green); | |
445 | i810_writeb(CLUT_DATA, mmio, blue); | |
446 | } | |
447 | ||
448 | static void i810_read_dac(u8 regno, u8 *red, u8 *green, u8 *blue, | |
449 | u8 __iomem *mmio) | |
450 | { | |
451 | i810_writeb(CLUT_INDEX_READ, mmio, regno); | |
452 | *red = i810_readb(CLUT_DATA, mmio); | |
453 | *green = i810_readb(CLUT_DATA, mmio); | |
454 | *blue = i810_readb(CLUT_DATA, mmio); | |
455 | } | |
456 | ||
457 | /************************************************************ | |
458 | * VGA State Restore * | |
459 | ************************************************************/ | |
460 | static void i810_restore_pll(struct i810fb_par *par) | |
461 | { | |
462 | u32 tmp1, tmp2; | |
463 | u8 __iomem *mmio = par->mmio_start_virtual; | |
464 | ||
465 | tmp1 = par->hw_state.dclk_2d; | |
466 | tmp2 = i810_readl(DCLK_2D, mmio); | |
467 | tmp1 &= ~MN_MASK; | |
468 | tmp2 &= MN_MASK; | |
469 | i810_writel(DCLK_2D, mmio, tmp1 | tmp2); | |
470 | ||
471 | tmp1 = par->hw_state.dclk_1d; | |
472 | tmp2 = i810_readl(DCLK_1D, mmio); | |
473 | tmp1 &= ~MN_MASK; | |
474 | tmp2 &= MN_MASK; | |
475 | i810_writel(DCLK_1D, mmio, tmp1 | tmp2); | |
476 | ||
477 | i810_writel(DCLK_0DS, mmio, par->hw_state.dclk_0ds); | |
478 | } | |
479 | ||
480 | static void i810_restore_dac(struct i810fb_par *par) | |
481 | { | |
482 | u32 tmp1, tmp2; | |
483 | u8 __iomem *mmio = par->mmio_start_virtual; | |
484 | ||
485 | tmp1 = par->hw_state.pixconf; | |
486 | tmp2 = i810_readl(PIXCONF, mmio); | |
487 | tmp1 &= DAC_BIT; | |
488 | tmp2 &= ~DAC_BIT; | |
489 | i810_writel(PIXCONF, mmio, tmp1 | tmp2); | |
490 | } | |
491 | ||
492 | static void i810_restore_vgax(struct i810fb_par *par) | |
493 | { | |
494 | u8 i, j; | |
495 | u8 __iomem *mmio = par->mmio_start_virtual; | |
496 | ||
497 | for (i = 0; i < 4; i++) { | |
498 | i810_writeb(CR_INDEX_CGA, mmio, CR30+i); | |
499 | i810_writeb(CR_DATA_CGA, mmio, *(&(par->hw_state.cr30) + i)); | |
500 | } | |
501 | i810_writeb(CR_INDEX_CGA, mmio, CR35); | |
502 | i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr35); | |
503 | i810_writeb(CR_INDEX_CGA, mmio, CR39); | |
504 | i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr39); | |
505 | i810_writeb(CR_INDEX_CGA, mmio, CR41); | |
506 | i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr39); | |
507 | ||
508 | /*restore interlace*/ | |
509 | i810_writeb(CR_INDEX_CGA, mmio, CR70); | |
510 | i = par->hw_state.cr70; | |
511 | i &= INTERLACE_BIT; | |
512 | j = i810_readb(CR_DATA_CGA, mmio); | |
513 | i810_writeb(CR_INDEX_CGA, mmio, CR70); | |
514 | i810_writeb(CR_DATA_CGA, mmio, j | i); | |
515 | ||
516 | i810_writeb(CR_INDEX_CGA, mmio, CR80); | |
517 | i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr80); | |
518 | i810_writeb(MSR_WRITE, mmio, par->hw_state.msr); | |
519 | i810_writeb(SR_INDEX, mmio, SR01); | |
520 | i = (par->hw_state.sr01) & ~0xE0 ; | |
521 | j = i810_readb(SR_DATA, mmio) & 0xE0; | |
522 | i810_writeb(SR_INDEX, mmio, SR01); | |
523 | i810_writeb(SR_DATA, mmio, i | j); | |
524 | } | |
525 | ||
526 | static void i810_restore_vga(struct i810fb_par *par) | |
527 | { | |
528 | u8 i; | |
529 | u8 __iomem *mmio = par->mmio_start_virtual; | |
530 | ||
531 | for (i = 0; i < 10; i++) { | |
532 | i810_writeb(CR_INDEX_CGA, mmio, CR00 + i); | |
533 | i810_writeb(CR_DATA_CGA, mmio, *((&par->hw_state.cr00) + i)); | |
534 | } | |
535 | for (i = 0; i < 8; i++) { | |
536 | i810_writeb(CR_INDEX_CGA, mmio, CR10 + i); | |
537 | i810_writeb(CR_DATA_CGA, mmio, *((&par->hw_state.cr10) + i)); | |
538 | } | |
539 | } | |
540 | ||
541 | static void i810_restore_addr_map(struct i810fb_par *par) | |
542 | { | |
543 | u8 tmp; | |
544 | u8 __iomem *mmio = par->mmio_start_virtual; | |
545 | ||
546 | i810_writeb(GR_INDEX, mmio, GR10); | |
547 | tmp = i810_readb(GR_DATA, mmio); | |
548 | tmp &= ADDR_MAP_MASK; | |
549 | tmp |= par->hw_state.gr10; | |
550 | i810_writeb(GR_INDEX, mmio, GR10); | |
551 | i810_writeb(GR_DATA, mmio, tmp); | |
552 | } | |
553 | ||
554 | static void i810_restore_2d(struct i810fb_par *par) | |
555 | { | |
556 | u32 tmp_long; | |
557 | u16 tmp_word; | |
558 | u8 __iomem *mmio = par->mmio_start_virtual; | |
559 | ||
560 | tmp_word = i810_readw(BLTCNTL, mmio); | |
561 | tmp_word &= ~(3 << 4); | |
562 | tmp_word |= par->hw_state.bltcntl; | |
563 | i810_writew(BLTCNTL, mmio, tmp_word); | |
564 | ||
565 | i810_dram_off(mmio, OFF); | |
566 | i810_writel(PIXCONF, mmio, par->hw_state.pixconf); | |
567 | i810_dram_off(mmio, ON); | |
568 | ||
569 | tmp_word = i810_readw(HWSTAM, mmio); | |
570 | tmp_word &= 3 << 13; | |
571 | tmp_word |= par->hw_state.hwstam; | |
572 | i810_writew(HWSTAM, mmio, tmp_word); | |
573 | ||
574 | tmp_long = i810_readl(FW_BLC, mmio); | |
575 | tmp_long &= FW_BLC_MASK; | |
576 | tmp_long |= par->hw_state.fw_blc; | |
577 | i810_writel(FW_BLC, mmio, tmp_long); | |
578 | ||
579 | i810_writel(HWS_PGA, mmio, par->hw_state.hws_pga); | |
580 | i810_writew(IER, mmio, par->hw_state.ier); | |
581 | i810_writew(IMR, mmio, par->hw_state.imr); | |
582 | i810_writel(DPLYSTAS, mmio, par->hw_state.dplystas); | |
583 | } | |
584 | ||
585 | static void i810_restore_vga_state(struct i810fb_par *par) | |
586 | { | |
587 | u8 __iomem *mmio = par->mmio_start_virtual; | |
588 | ||
589 | i810_screen_off(mmio, OFF); | |
590 | i810_protect_regs(mmio, OFF); | |
591 | i810_dram_off(mmio, OFF); | |
592 | i810_restore_pll(par); | |
593 | i810_restore_dac(par); | |
594 | i810_restore_vga(par); | |
595 | i810_restore_vgax(par); | |
596 | i810_restore_addr_map(par); | |
597 | i810_dram_off(mmio, ON); | |
598 | i810_restore_2d(par); | |
599 | i810_screen_off(mmio, ON); | |
600 | i810_protect_regs(mmio, ON); | |
601 | } | |
602 | ||
603 | /*********************************************************************** | |
604 | * VGA State Save * | |
605 | ***********************************************************************/ | |
606 | ||
607 | static void i810_save_vgax(struct i810fb_par *par) | |
608 | { | |
609 | u8 i; | |
610 | u8 __iomem *mmio = par->mmio_start_virtual; | |
611 | ||
612 | for (i = 0; i < 4; i++) { | |
613 | i810_writeb(CR_INDEX_CGA, mmio, CR30 + i); | |
614 | *(&(par->hw_state.cr30) + i) = i810_readb(CR_DATA_CGA, mmio); | |
615 | } | |
616 | i810_writeb(CR_INDEX_CGA, mmio, CR35); | |
617 | par->hw_state.cr35 = i810_readb(CR_DATA_CGA, mmio); | |
618 | i810_writeb(CR_INDEX_CGA, mmio, CR39); | |
619 | par->hw_state.cr39 = i810_readb(CR_DATA_CGA, mmio); | |
620 | i810_writeb(CR_INDEX_CGA, mmio, CR41); | |
621 | par->hw_state.cr41 = i810_readb(CR_DATA_CGA, mmio); | |
622 | i810_writeb(CR_INDEX_CGA, mmio, CR70); | |
623 | par->hw_state.cr70 = i810_readb(CR_DATA_CGA, mmio); | |
624 | par->hw_state.msr = i810_readb(MSR_READ, mmio); | |
625 | i810_writeb(CR_INDEX_CGA, mmio, CR80); | |
626 | par->hw_state.cr80 = i810_readb(CR_DATA_CGA, mmio); | |
627 | i810_writeb(SR_INDEX, mmio, SR01); | |
628 | par->hw_state.sr01 = i810_readb(SR_DATA, mmio); | |
629 | } | |
630 | ||
631 | static void i810_save_vga(struct i810fb_par *par) | |
632 | { | |
633 | u8 i; | |
634 | u8 __iomem *mmio = par->mmio_start_virtual; | |
635 | ||
636 | for (i = 0; i < 10; i++) { | |
637 | i810_writeb(CR_INDEX_CGA, mmio, CR00 + i); | |
638 | *((&par->hw_state.cr00) + i) = i810_readb(CR_DATA_CGA, mmio); | |
639 | } | |
640 | for (i = 0; i < 8; i++) { | |
641 | i810_writeb(CR_INDEX_CGA, mmio, CR10 + i); | |
642 | *((&par->hw_state.cr10) + i) = i810_readb(CR_DATA_CGA, mmio); | |
643 | } | |
644 | } | |
645 | ||
646 | static void i810_save_2d(struct i810fb_par *par) | |
647 | { | |
648 | u8 __iomem *mmio = par->mmio_start_virtual; | |
649 | ||
650 | par->hw_state.dclk_2d = i810_readl(DCLK_2D, mmio); | |
651 | par->hw_state.dclk_1d = i810_readl(DCLK_1D, mmio); | |
652 | par->hw_state.dclk_0ds = i810_readl(DCLK_0DS, mmio); | |
653 | par->hw_state.pixconf = i810_readl(PIXCONF, mmio); | |
654 | par->hw_state.fw_blc = i810_readl(FW_BLC, mmio); | |
655 | par->hw_state.bltcntl = i810_readw(BLTCNTL, mmio); | |
656 | par->hw_state.hwstam = i810_readw(HWSTAM, mmio); | |
657 | par->hw_state.hws_pga = i810_readl(HWS_PGA, mmio); | |
658 | par->hw_state.ier = i810_readw(IER, mmio); | |
659 | par->hw_state.imr = i810_readw(IMR, mmio); | |
660 | par->hw_state.dplystas = i810_readl(DPLYSTAS, mmio); | |
661 | } | |
662 | ||
663 | static void i810_save_vga_state(struct i810fb_par *par) | |
664 | { | |
665 | i810_save_vga(par); | |
666 | i810_save_vgax(par); | |
667 | i810_save_2d(par); | |
668 | } | |
669 | ||
670 | /************************************************************ | |
671 | * Helpers * | |
672 | ************************************************************/ | |
673 | /** | |
674 | * get_line_length - calculates buffer pitch in bytes | |
675 | * @par: pointer to i810fb_par structure | |
676 | * @xres_virtual: virtual resolution of the frame | |
677 | * @bpp: bits per pixel | |
678 | * | |
679 | * DESCRIPTION: | |
680 | * Calculates buffer pitch in bytes. | |
681 | */ | |
682 | static u32 get_line_length(struct i810fb_par *par, int xres_virtual, int bpp) | |
683 | { | |
684 | u32 length; | |
685 | ||
686 | length = xres_virtual*bpp; | |
687 | length = (length+31)&-32; | |
688 | length >>= 3; | |
689 | return length; | |
690 | } | |
691 | ||
692 | /** | |
693 | * i810_calc_dclk - calculates the P, M, and N values of a pixelclock value | |
694 | * @freq: target pixelclock in picoseconds | |
695 | * @m: where to write M register | |
696 | * @n: where to write N register | |
697 | * @p: where to write P register | |
698 | * | |
699 | * DESCRIPTION: | |
700 | * Based on the formula Freq_actual = (4*M*Freq_ref)/(N^P) | |
701 | * Repeatedly computes the Freq until the actual Freq is equal to | |
702 | * the target Freq or until the loop count is zero. In the latter | |
703 | * case, the actual frequency nearest the target will be used. | |
704 | */ | |
705 | static void i810_calc_dclk(u32 freq, u32 *m, u32 *n, u32 *p) | |
706 | { | |
707 | u32 m_reg, n_reg, p_divisor, n_target_max; | |
708 | u32 m_target, n_target, p_target, n_best, m_best, mod; | |
709 | u32 f_out, target_freq, diff = 0, mod_min, diff_min; | |
710 | ||
711 | diff_min = mod_min = 0xFFFFFFFF; | |
712 | n_best = m_best = m_target = f_out = 0; | |
713 | ||
714 | target_freq = freq; | |
715 | n_target_max = 30; | |
716 | ||
717 | /* | |
718 | * find P such that target freq is 16x reference freq (Hz). | |
719 | */ | |
720 | p_divisor = 1; | |
721 | p_target = 0; | |
722 | while(!((1000000 * p_divisor)/(16 * 24 * target_freq)) && | |
723 | p_divisor <= 32) { | |
724 | p_divisor <<= 1; | |
725 | p_target++; | |
726 | } | |
727 | ||
728 | n_reg = m_reg = n_target = 3; | |
729 | while (diff_min && mod_min && (n_target < n_target_max)) { | |
730 | f_out = (p_divisor * n_reg * 1000000)/(4 * 24 * m_reg); | |
731 | mod = (p_divisor * n_reg * 1000000) % (4 * 24 * m_reg); | |
732 | m_target = m_reg; | |
733 | n_target = n_reg; | |
734 | if (f_out <= target_freq) { | |
735 | n_reg++; | |
736 | diff = target_freq - f_out; | |
737 | } else { | |
738 | m_reg++; | |
739 | diff = f_out - target_freq; | |
740 | } | |
741 | ||
742 | if (diff_min > diff) { | |
743 | diff_min = diff; | |
744 | n_best = n_target; | |
745 | m_best = m_target; | |
746 | } | |
747 | ||
748 | if (!diff && mod_min > mod) { | |
749 | mod_min = mod; | |
750 | n_best = n_target; | |
751 | m_best = m_target; | |
752 | } | |
753 | } | |
754 | if (m) *m = (m_best - 2) & 0x3FF; | |
755 | if (n) *n = (n_best - 2) & 0x3FF; | |
756 | if (p) *p = (p_target << 4); | |
757 | } | |
758 | ||
759 | /************************************************************* | |
760 | * Hardware Cursor Routines * | |
761 | *************************************************************/ | |
762 | ||
763 | /** | |
764 | * i810_enable_cursor - show or hide the hardware cursor | |
765 | * @mmio: address of register space | |
766 | * @mode: show (1) or hide (0) | |
767 | * | |
768 | * Description: | |
769 | * Shows or hides the hardware cursor | |
770 | */ | |
771 | static void i810_enable_cursor(u8 __iomem *mmio, int mode) | |
772 | { | |
773 | u32 temp; | |
774 | ||
775 | temp = i810_readl(PIXCONF, mmio); | |
776 | temp = (mode == ON) ? temp | CURSOR_ENABLE_MASK : | |
777 | temp & ~CURSOR_ENABLE_MASK; | |
778 | ||
779 | i810_writel(PIXCONF, mmio, temp); | |
780 | } | |
781 | ||
782 | static void i810_reset_cursor_image(struct i810fb_par *par) | |
783 | { | |
784 | u8 __iomem *addr = par->cursor_heap.virtual; | |
785 | int i, j; | |
786 | ||
787 | for (i = 64; i--; ) { | |
788 | for (j = 0; j < 8; j++) { | |
789 | i810_writeb(j, addr, 0xff); | |
790 | i810_writeb(j+8, addr, 0x00); | |
791 | } | |
792 | addr +=16; | |
793 | } | |
794 | } | |
795 | ||
796 | static void i810_load_cursor_image(int width, int height, u8 *data, | |
797 | struct i810fb_par *par) | |
798 | { | |
799 | u8 __iomem *addr = par->cursor_heap.virtual; | |
800 | int i, j, w = width/8; | |
801 | int mod = width % 8, t_mask, d_mask; | |
802 | ||
803 | t_mask = 0xff >> mod; | |
804 | d_mask = ~(0xff >> mod); | |
805 | for (i = height; i--; ) { | |
806 | for (j = 0; j < w; j++) { | |
807 | i810_writeb(j+0, addr, 0x00); | |
808 | i810_writeb(j+8, addr, *data++); | |
809 | } | |
810 | if (mod) { | |
811 | i810_writeb(j+0, addr, t_mask); | |
812 | i810_writeb(j+8, addr, *data++ & d_mask); | |
813 | } | |
814 | addr += 16; | |
815 | } | |
816 | } | |
817 | ||
818 | static void i810_load_cursor_colors(int fg, int bg, struct fb_info *info) | |
819 | { | |
c019c0ec | 820 | struct i810fb_par *par = info->par; |
1da177e4 LT |
821 | u8 __iomem *mmio = par->mmio_start_virtual; |
822 | u8 red, green, blue, trans, temp; | |
823 | ||
824 | i810fb_getcolreg(bg, &red, &green, &blue, &trans, info); | |
825 | ||
826 | temp = i810_readb(PIXCONF1, mmio); | |
827 | i810_writeb(PIXCONF1, mmio, temp | EXTENDED_PALETTE); | |
828 | ||
829 | i810_write_dac(4, red, green, blue, mmio); | |
830 | ||
831 | i810_writeb(PIXCONF1, mmio, temp); | |
832 | ||
833 | i810fb_getcolreg(fg, &red, &green, &blue, &trans, info); | |
834 | temp = i810_readb(PIXCONF1, mmio); | |
835 | i810_writeb(PIXCONF1, mmio, temp | EXTENDED_PALETTE); | |
836 | ||
837 | i810_write_dac(5, red, green, blue, mmio); | |
838 | ||
839 | i810_writeb(PIXCONF1, mmio, temp); | |
840 | } | |
841 | ||
842 | /** | |
843 | * i810_init_cursor - initializes the cursor | |
844 | * @par: pointer to i810fb_par structure | |
845 | * | |
846 | * DESCRIPTION: | |
847 | * Initializes the cursor registers | |
848 | */ | |
849 | static void i810_init_cursor(struct i810fb_par *par) | |
850 | { | |
851 | u8 __iomem *mmio = par->mmio_start_virtual; | |
852 | ||
853 | i810_enable_cursor(mmio, OFF); | |
854 | i810_writel(CURBASE, mmio, par->cursor_heap.physical); | |
855 | i810_writew(CURCNTR, mmio, COORD_ACTIVE | CURSOR_MODE_64_XOR); | |
856 | } | |
857 | ||
858 | /********************************************************************* | |
859 | * Framebuffer hook helpers * | |
860 | *********************************************************************/ | |
861 | /** | |
862 | * i810_round_off - Round off values to capability of hardware | |
863 | * @var: pointer to fb_var_screeninfo structure | |
864 | * | |
865 | * DESCRIPTION: | |
866 | * @var contains user-defined information for the mode to be set. | |
867 | * This will try modify those values to ones nearest the | |
868 | * capability of the hardware | |
869 | */ | |
870 | static void i810_round_off(struct fb_var_screeninfo *var) | |
871 | { | |
872 | u32 xres, yres, vxres, vyres; | |
873 | ||
874 | /* | |
875 | * Presently supports only these configurations | |
876 | */ | |
877 | ||
878 | xres = var->xres; | |
879 | yres = var->yres; | |
880 | vxres = var->xres_virtual; | |
881 | vyres = var->yres_virtual; | |
882 | ||
883 | var->bits_per_pixel += 7; | |
884 | var->bits_per_pixel &= ~7; | |
885 | ||
886 | if (var->bits_per_pixel < 8) | |
887 | var->bits_per_pixel = 8; | |
888 | if (var->bits_per_pixel > 32) | |
889 | var->bits_per_pixel = 32; | |
890 | ||
891 | round_off_xres(&xres); | |
892 | if (xres < 40) | |
893 | xres = 40; | |
894 | if (xres > 2048) | |
895 | xres = 2048; | |
896 | xres = (xres + 7) & ~7; | |
897 | ||
898 | if (vxres < xres) | |
899 | vxres = xres; | |
900 | ||
901 | round_off_yres(&xres, &yres); | |
902 | if (yres < 1) | |
903 | yres = 1; | |
904 | if (yres >= 2048) | |
905 | yres = 2048; | |
906 | ||
907 | if (vyres < yres) | |
908 | vyres = yres; | |
909 | ||
910 | if (var->bits_per_pixel == 32) | |
911 | var->accel_flags = 0; | |
912 | ||
913 | /* round of horizontal timings to nearest 8 pixels */ | |
914 | var->left_margin = (var->left_margin + 4) & ~7; | |
915 | var->right_margin = (var->right_margin + 4) & ~7; | |
916 | var->hsync_len = (var->hsync_len + 4) & ~7; | |
917 | ||
918 | if (var->vmode & FB_VMODE_INTERLACED) { | |
919 | if (!((yres + var->upper_margin + var->vsync_len + | |
920 | var->lower_margin) & 1)) | |
921 | var->upper_margin++; | |
922 | } | |
923 | ||
924 | var->xres = xres; | |
925 | var->yres = yres; | |
926 | var->xres_virtual = vxres; | |
927 | var->yres_virtual = vyres; | |
928 | } | |
929 | ||
930 | /** | |
931 | * set_color_bitfields - sets rgba fields | |
932 | * @var: pointer to fb_var_screeninfo | |
933 | * | |
934 | * DESCRIPTION: | |
935 | * The length, offset and ordering for each color field | |
936 | * (red, green, blue) will be set as specified | |
937 | * by the hardware | |
938 | */ | |
939 | static void set_color_bitfields(struct fb_var_screeninfo *var) | |
940 | { | |
941 | switch (var->bits_per_pixel) { | |
942 | case 8: | |
943 | var->red.offset = 0; | |
944 | var->red.length = 8; | |
945 | var->green.offset = 0; | |
946 | var->green.length = 8; | |
947 | var->blue.offset = 0; | |
948 | var->blue.length = 8; | |
949 | var->transp.offset = 0; | |
950 | var->transp.length = 0; | |
951 | break; | |
952 | case 16: | |
953 | var->green.length = (var->green.length == 5) ? 5 : 6; | |
954 | var->red.length = 5; | |
955 | var->blue.length = 5; | |
956 | var->transp.length = 6 - var->green.length; | |
957 | var->blue.offset = 0; | |
958 | var->green.offset = 5; | |
959 | var->red.offset = 5 + var->green.length; | |
960 | var->transp.offset = (5 + var->red.offset) & 15; | |
961 | break; | |
962 | case 24: /* RGB 888 */ | |
963 | case 32: /* RGBA 8888 */ | |
964 | var->red.offset = 16; | |
965 | var->red.length = 8; | |
966 | var->green.offset = 8; | |
967 | var->green.length = 8; | |
968 | var->blue.offset = 0; | |
969 | var->blue.length = 8; | |
970 | var->transp.length = var->bits_per_pixel - 24; | |
971 | var->transp.offset = (var->transp.length) ? 24 : 0; | |
972 | break; | |
973 | } | |
974 | var->red.msb_right = 0; | |
975 | var->green.msb_right = 0; | |
976 | var->blue.msb_right = 0; | |
977 | var->transp.msb_right = 0; | |
978 | } | |
979 | ||
980 | /** | |
981 | * i810_check_params - check if contents in var are valid | |
982 | * @var: pointer to fb_var_screeninfo | |
983 | * @info: pointer to fb_info | |
984 | * | |
985 | * DESCRIPTION: | |
986 | * This will check if the framebuffer size is sufficient | |
987 | * for the current mode and if the user's monitor has the | |
988 | * required specifications to display the current mode. | |
989 | */ | |
990 | static int i810_check_params(struct fb_var_screeninfo *var, | |
991 | struct fb_info *info) | |
992 | { | |
c019c0ec | 993 | struct i810fb_par *par = info->par; |
883f6451 | 994 | int line_length, vidmem, mode_valid = 0, retval = 0; |
74f6ae84 | 995 | u32 vyres = var->yres_virtual, vxres = var->xres_virtual; |
1da177e4 LT |
996 | /* |
997 | * Memory limit | |
998 | */ | |
74f6ae84 | 999 | line_length = get_line_length(par, vxres, var->bits_per_pixel); |
1da177e4 | 1000 | vidmem = line_length*vyres; |
74f6ae84 | 1001 | |
1da177e4 LT |
1002 | if (vidmem > par->fb.size) { |
1003 | vyres = par->fb.size/line_length; | |
74f6ae84 | 1004 | if (vyres < var->yres) { |
1da177e4 LT |
1005 | vyres = yres; |
1006 | vxres = par->fb.size/vyres; | |
1007 | vxres /= var->bits_per_pixel >> 3; | |
1008 | line_length = get_line_length(par, vxres, | |
1009 | var->bits_per_pixel); | |
1010 | vidmem = line_length * yres; | |
74f6ae84 | 1011 | if (vxres < var->xres) { |
1da177e4 LT |
1012 | printk("i810fb: required video memory, " |
1013 | "%d bytes, for %dx%d-%d (virtual) " | |
1014 | "is out of range\n", | |
1015 | vidmem, vxres, vyres, | |
1016 | var->bits_per_pixel); | |
1017 | return -ENOMEM; | |
1018 | } | |
1019 | } | |
1020 | } | |
74f6ae84 AD |
1021 | |
1022 | var->xres_virtual = vxres; | |
1023 | var->yres_virtual = vyres; | |
1024 | ||
1da177e4 LT |
1025 | /* |
1026 | * Monitor limit | |
1027 | */ | |
1028 | switch (var->bits_per_pixel) { | |
1029 | case 8: | |
1030 | info->monspecs.dclkmax = 234000000; | |
1031 | break; | |
1032 | case 16: | |
1033 | info->monspecs.dclkmax = 229000000; | |
1034 | break; | |
1035 | case 24: | |
1036 | case 32: | |
1037 | info->monspecs.dclkmax = 204000000; | |
1038 | break; | |
1039 | } | |
74f6ae84 | 1040 | |
1da177e4 LT |
1041 | info->monspecs.dclkmin = 15000000; |
1042 | ||
74f6ae84 AD |
1043 | if (!fb_validate_mode(var, info)) |
1044 | mode_valid = 1; | |
1045 | ||
1046 | #ifdef CONFIG_FB_I810_I2C | |
1047 | if (!mode_valid && info->monspecs.gtf && | |
1048 | !fb_get_mode(FB_MAXTIMINGS, 0, var, info)) | |
1049 | mode_valid = 1; | |
1050 | ||
1051 | if (!mode_valid && info->monspecs.modedb_len) { | |
1052 | struct fb_videomode *mode; | |
1053 | ||
1054 | mode = fb_find_best_mode(var, &info->modelist); | |
1055 | if (mode) { | |
1056 | fb_videomode_to_var(var, mode); | |
1057 | mode_valid = 1; | |
1058 | } | |
1059 | } | |
1060 | #endif | |
1061 | if (!mode_valid && info->monspecs.modedb_len == 0) { | |
db9f1d9d | 1062 | if (fb_get_mode(FB_MAXTIMINGS, 0, var, info)) { |
836eeed6 | 1063 | int default_sync = (info->monspecs.hfmin-HFMIN) |
74f6ae84 AD |
1064 | |(info->monspecs.hfmax-HFMAX) |
1065 | |(info->monspecs.vfmin-VFMIN) | |
1066 | |(info->monspecs.vfmax-VFMAX); | |
db9f1d9d | 1067 | printk("i810fb: invalid video mode%s\n", |
74f6ae84 AD |
1068 | default_sync ? "" : ". Specifying " |
1069 | "vsyncN/hsyncN parameters may help"); | |
883f6451 | 1070 | retval = -EINVAL; |
db9f1d9d | 1071 | } |
1da177e4 | 1072 | } |
74f6ae84 | 1073 | |
883f6451 | 1074 | return retval; |
1da177e4 LT |
1075 | } |
1076 | ||
1077 | /** | |
1078 | * encode_fix - fill up fb_fix_screeninfo structure | |
1079 | * @fix: pointer to fb_fix_screeninfo | |
1080 | * @info: pointer to fb_info | |
1081 | * | |
1082 | * DESCRIPTION: | |
1083 | * This will set up parameters that are unmodifiable by the user. | |
1084 | */ | |
1085 | static int encode_fix(struct fb_fix_screeninfo *fix, struct fb_info *info) | |
1086 | { | |
c019c0ec | 1087 | struct i810fb_par *par = info->par; |
1da177e4 LT |
1088 | |
1089 | memset(fix, 0, sizeof(struct fb_fix_screeninfo)); | |
1090 | ||
1091 | strcpy(fix->id, "I810"); | |
1092 | fix->smem_start = par->fb.physical; | |
1093 | fix->smem_len = par->fb.size; | |
1094 | fix->type = FB_TYPE_PACKED_PIXELS; | |
1095 | fix->type_aux = 0; | |
1096 | fix->xpanstep = 8; | |
1097 | fix->ypanstep = 1; | |
1098 | ||
1099 | switch (info->var.bits_per_pixel) { | |
1100 | case 8: | |
1101 | fix->visual = FB_VISUAL_PSEUDOCOLOR; | |
1102 | break; | |
1103 | case 16: | |
1104 | case 24: | |
1105 | case 32: | |
1106 | if (info->var.nonstd) | |
1107 | fix->visual = FB_VISUAL_DIRECTCOLOR; | |
1108 | else | |
1109 | fix->visual = FB_VISUAL_TRUECOLOR; | |
1110 | break; | |
1111 | default: | |
1112 | return -EINVAL; | |
1113 | } | |
1114 | fix->ywrapstep = 0; | |
1115 | fix->line_length = par->pitch; | |
1116 | fix->mmio_start = par->mmio_start_phys; | |
1117 | fix->mmio_len = MMIO_SIZE; | |
1118 | fix->accel = FB_ACCEL_I810; | |
1119 | ||
1120 | return 0; | |
1121 | } | |
1122 | ||
1123 | /** | |
1124 | * decode_var - modify par according to contents of var | |
1125 | * @var: pointer to fb_var_screeninfo | |
1126 | * @par: pointer to i810fb_par | |
1127 | * | |
1128 | * DESCRIPTION: | |
1129 | * Based on the contents of @var, @par will be dynamically filled up. | |
1130 | * @par contains all information necessary to modify the hardware. | |
1131 | */ | |
1132 | static void decode_var(const struct fb_var_screeninfo *var, | |
1133 | struct i810fb_par *par) | |
1134 | { | |
1135 | u32 xres, yres, vxres, vyres; | |
1136 | ||
1137 | xres = var->xres; | |
1138 | yres = var->yres; | |
1139 | vxres = var->xres_virtual; | |
1140 | vyres = var->yres_virtual; | |
1141 | ||
1142 | switch (var->bits_per_pixel) { | |
1143 | case 8: | |
1144 | par->pixconf = PIXCONF8; | |
1145 | par->bltcntl = 0; | |
1146 | par->depth = 1; | |
1147 | par->blit_bpp = BPP8; | |
1148 | break; | |
1149 | case 16: | |
1150 | if (var->green.length == 5) | |
1151 | par->pixconf = PIXCONF15; | |
1152 | else | |
1153 | par->pixconf = PIXCONF16; | |
1154 | par->bltcntl = 16; | |
1155 | par->depth = 2; | |
1156 | par->blit_bpp = BPP16; | |
1157 | break; | |
1158 | case 24: | |
1159 | par->pixconf = PIXCONF24; | |
1160 | par->bltcntl = 32; | |
1161 | par->depth = 3; | |
1162 | par->blit_bpp = BPP24; | |
1163 | break; | |
1164 | case 32: | |
1165 | par->pixconf = PIXCONF32; | |
1166 | par->bltcntl = 0; | |
1167 | par->depth = 4; | |
1168 | par->blit_bpp = 3 << 24; | |
1169 | break; | |
1170 | } | |
1171 | if (var->nonstd && var->bits_per_pixel != 8) | |
1172 | par->pixconf |= 1 << 27; | |
1173 | ||
1174 | i810_calc_dclk(var->pixclock, &par->regs.M, | |
1175 | &par->regs.N, &par->regs.P); | |
1176 | i810fb_encode_registers(var, par, xres, yres); | |
1177 | ||
1178 | par->watermark = i810_get_watermark(var, par); | |
1179 | par->pitch = get_line_length(par, vxres, var->bits_per_pixel); | |
1180 | } | |
1181 | ||
1182 | /** | |
1183 | * i810fb_getcolreg - gets red, green and blue values of the hardware DAC | |
1184 | * @regno: DAC index | |
1185 | * @red: red | |
1186 | * @green: green | |
1187 | * @blue: blue | |
1188 | * @transp: transparency (alpha) | |
1189 | * @info: pointer to fb_info | |
1190 | * | |
1191 | * DESCRIPTION: | |
1192 | * Gets the red, green and blue values of the hardware DAC as pointed by @regno | |
1193 | * and writes them to @red, @green and @blue respectively | |
1194 | */ | |
1195 | static int i810fb_getcolreg(u8 regno, u8 *red, u8 *green, u8 *blue, | |
1196 | u8 *transp, struct fb_info *info) | |
1197 | { | |
c019c0ec | 1198 | struct i810fb_par *par = info->par; |
1da177e4 LT |
1199 | u8 __iomem *mmio = par->mmio_start_virtual; |
1200 | u8 temp; | |
1201 | ||
1202 | if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) { | |
1203 | if ((info->var.green.length == 5 && regno > 31) || | |
1204 | (info->var.green.length == 6 && regno > 63)) | |
1205 | return 1; | |
1206 | } | |
1207 | ||
1208 | temp = i810_readb(PIXCONF1, mmio); | |
1209 | i810_writeb(PIXCONF1, mmio, temp & ~EXTENDED_PALETTE); | |
1210 | ||
1211 | if (info->fix.visual == FB_VISUAL_DIRECTCOLOR && | |
1212 | info->var.green.length == 5) | |
1213 | i810_read_dac(regno * 8, red, green, blue, mmio); | |
1214 | ||
1215 | else if (info->fix.visual == FB_VISUAL_DIRECTCOLOR && | |
1216 | info->var.green.length == 6) { | |
1217 | u8 tmp; | |
1218 | ||
1219 | i810_read_dac(regno * 8, red, &tmp, blue, mmio); | |
1220 | i810_read_dac(regno * 4, &tmp, green, &tmp, mmio); | |
1221 | } | |
1222 | else | |
1223 | i810_read_dac(regno, red, green, blue, mmio); | |
1224 | ||
1225 | *transp = 0; | |
1226 | i810_writeb(PIXCONF1, mmio, temp); | |
1227 | ||
1228 | return 0; | |
1229 | } | |
1230 | ||
1231 | /****************************************************************** | |
1232 | * Framebuffer device-specific hooks * | |
1233 | ******************************************************************/ | |
1234 | ||
1235 | static int i810fb_open(struct fb_info *info, int user) | |
1236 | { | |
c019c0ec | 1237 | struct i810fb_par *par = info->par; |
1da177e4 LT |
1238 | u32 count = atomic_read(&par->use_count); |
1239 | ||
1240 | if (count == 0) { | |
1241 | memset(&par->state, 0, sizeof(struct vgastate)); | |
1242 | par->state.flags = VGA_SAVE_CMAP; | |
1243 | par->state.vgabase = par->mmio_start_virtual; | |
1244 | save_vga(&par->state); | |
1245 | ||
1246 | i810_save_vga_state(par); | |
1247 | } | |
1248 | ||
1249 | atomic_inc(&par->use_count); | |
1250 | ||
1251 | return 0; | |
1252 | } | |
1253 | ||
1254 | static int i810fb_release(struct fb_info *info, int user) | |
1255 | { | |
c019c0ec | 1256 | struct i810fb_par *par = info->par; |
1da177e4 LT |
1257 | u32 count; |
1258 | ||
1259 | count = atomic_read(&par->use_count); | |
1260 | if (count == 0) | |
1261 | return -EINVAL; | |
1262 | ||
1263 | if (count == 1) { | |
1264 | i810_restore_vga_state(par); | |
1265 | restore_vga(&par->state); | |
1266 | } | |
1267 | ||
1268 | atomic_dec(&par->use_count); | |
1269 | ||
1270 | return 0; | |
1271 | } | |
1272 | ||
1273 | ||
1274 | static int i810fb_setcolreg(unsigned regno, unsigned red, unsigned green, | |
1275 | unsigned blue, unsigned transp, | |
1276 | struct fb_info *info) | |
1277 | { | |
c019c0ec | 1278 | struct i810fb_par *par = info->par; |
1da177e4 LT |
1279 | u8 __iomem *mmio = par->mmio_start_virtual; |
1280 | u8 temp; | |
1281 | int i; | |
1282 | ||
1283 | if (regno > 255) return 1; | |
1284 | ||
1285 | if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) { | |
1286 | if ((info->var.green.length == 5 && regno > 31) || | |
1287 | (info->var.green.length == 6 && regno > 63)) | |
1288 | return 1; | |
1289 | } | |
1290 | ||
1291 | if (info->var.grayscale) | |
1292 | red = green = blue = (19595 * red + 38470 * green + | |
1293 | 7471 * blue) >> 16; | |
1294 | ||
1295 | temp = i810_readb(PIXCONF1, mmio); | |
1296 | i810_writeb(PIXCONF1, mmio, temp & ~EXTENDED_PALETTE); | |
1297 | ||
1298 | if (info->fix.visual == FB_VISUAL_DIRECTCOLOR && | |
1299 | info->var.green.length == 5) { | |
1300 | for (i = 0; i < 8; i++) | |
1301 | i810_write_dac((u8) (regno * 8) + i, (u8) red, | |
1302 | (u8) green, (u8) blue, mmio); | |
1303 | } else if (info->fix.visual == FB_VISUAL_DIRECTCOLOR && | |
1304 | info->var.green.length == 6) { | |
1305 | u8 r, g, b; | |
1306 | ||
1307 | if (regno < 32) { | |
1308 | for (i = 0; i < 8; i++) | |
1309 | i810_write_dac((u8) (regno * 8) + i, | |
1310 | (u8) red, (u8) green, | |
1311 | (u8) blue, mmio); | |
1312 | } | |
1313 | i810_read_dac((u8) (regno*4), &r, &g, &b, mmio); | |
1314 | for (i = 0; i < 4; i++) | |
1315 | i810_write_dac((u8) (regno*4) + i, r, (u8) green, | |
1316 | b, mmio); | |
1317 | } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) { | |
1318 | i810_write_dac((u8) regno, (u8) red, (u8) green, | |
1319 | (u8) blue, mmio); | |
1320 | } | |
1321 | ||
1322 | i810_writeb(PIXCONF1, mmio, temp); | |
1323 | ||
1324 | if (regno < 16) { | |
1325 | switch (info->var.bits_per_pixel) { | |
1326 | case 16: | |
1327 | if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) { | |
1328 | if (info->var.green.length == 5) | |
1329 | ((u32 *)info->pseudo_palette)[regno] = | |
1330 | (regno << 10) | (regno << 5) | | |
1331 | regno; | |
1332 | else | |
1333 | ((u32 *)info->pseudo_palette)[regno] = | |
1334 | (regno << 11) | (regno << 5) | | |
1335 | regno; | |
1336 | } else { | |
1337 | if (info->var.green.length == 5) { | |
1338 | /* RGB 555 */ | |
1339 | ((u32 *)info->pseudo_palette)[regno] = | |
1340 | ((red & 0xf800) >> 1) | | |
1341 | ((green & 0xf800) >> 6) | | |
1342 | ((blue & 0xf800) >> 11); | |
1343 | } else { | |
1344 | /* RGB 565 */ | |
1345 | ((u32 *)info->pseudo_palette)[regno] = | |
1346 | (red & 0xf800) | | |
1347 | ((green & 0xf800) >> 5) | | |
1348 | ((blue & 0xf800) >> 11); | |
1349 | } | |
1350 | } | |
1351 | break; | |
1352 | case 24: /* RGB 888 */ | |
1353 | case 32: /* RGBA 8888 */ | |
1354 | if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) | |
1355 | ((u32 *)info->pseudo_palette)[regno] = | |
1356 | (regno << 16) | (regno << 8) | | |
1357 | regno; | |
1358 | else | |
1359 | ((u32 *)info->pseudo_palette)[regno] = | |
1360 | ((red & 0xff00) << 8) | | |
1361 | (green & 0xff00) | | |
1362 | ((blue & 0xff00) >> 8); | |
1363 | break; | |
1364 | } | |
1365 | } | |
1366 | return 0; | |
1367 | } | |
1368 | ||
1369 | static int i810fb_pan_display(struct fb_var_screeninfo *var, | |
1370 | struct fb_info *info) | |
1371 | { | |
c019c0ec | 1372 | struct i810fb_par *par = info->par; |
1da177e4 LT |
1373 | u32 total; |
1374 | ||
1375 | total = var->xoffset * par->depth + | |
1376 | var->yoffset * info->fix.line_length; | |
1377 | i810fb_load_front(total, info); | |
1378 | ||
1379 | return 0; | |
1380 | } | |
1381 | ||
1382 | static int i810fb_blank (int blank_mode, struct fb_info *info) | |
1383 | { | |
c019c0ec | 1384 | struct i810fb_par *par = info->par; |
1da177e4 LT |
1385 | u8 __iomem *mmio = par->mmio_start_virtual; |
1386 | int mode = 0, pwr, scr_off = 0; | |
1387 | ||
1388 | pwr = i810_readl(PWR_CLKC, mmio); | |
1389 | ||
1390 | switch (blank_mode) { | |
1391 | case FB_BLANK_UNBLANK: | |
1392 | mode = POWERON; | |
1393 | pwr |= 1; | |
1394 | scr_off = ON; | |
1395 | break; | |
1396 | case FB_BLANK_NORMAL: | |
1397 | mode = POWERON; | |
1398 | pwr |= 1; | |
1399 | scr_off = OFF; | |
1400 | break; | |
1401 | case FB_BLANK_VSYNC_SUSPEND: | |
1402 | mode = STANDBY; | |
1403 | pwr |= 1; | |
1404 | scr_off = OFF; | |
1405 | break; | |
1406 | case FB_BLANK_HSYNC_SUSPEND: | |
1407 | mode = SUSPEND; | |
1408 | pwr |= 1; | |
1409 | scr_off = OFF; | |
1410 | break; | |
1411 | case FB_BLANK_POWERDOWN: | |
1412 | mode = POWERDOWN; | |
1413 | pwr &= ~1; | |
1414 | scr_off = OFF; | |
1415 | break; | |
1416 | default: | |
1417 | return -EINVAL; | |
1418 | } | |
1419 | ||
1420 | i810_screen_off(mmio, scr_off); | |
1421 | i810_writel(HVSYNC, mmio, mode); | |
1422 | i810_writel(PWR_CLKC, mmio, pwr); | |
1423 | ||
1424 | return 0; | |
1425 | } | |
1426 | ||
1427 | static int i810fb_set_par(struct fb_info *info) | |
1428 | { | |
c019c0ec | 1429 | struct i810fb_par *par = info->par; |
1da177e4 LT |
1430 | |
1431 | decode_var(&info->var, par); | |
1432 | i810_load_regs(par); | |
1433 | i810_init_cursor(par); | |
1da177e4 LT |
1434 | encode_fix(&info->fix, info); |
1435 | ||
1436 | if (info->var.accel_flags && !(par->dev_flags & LOCKUP)) { | |
1437 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN | | |
1438 | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT | | |
1439 | FBINFO_HWACCEL_IMAGEBLIT; | |
1440 | info->pixmap.scan_align = 2; | |
1441 | } else { | |
1442 | info->pixmap.scan_align = 1; | |
1443 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; | |
1444 | } | |
1445 | return 0; | |
1446 | } | |
1447 | ||
1448 | static int i810fb_check_var(struct fb_var_screeninfo *var, | |
1449 | struct fb_info *info) | |
1450 | { | |
1451 | int err; | |
1452 | ||
1453 | if (IS_DVT) { | |
1454 | var->vmode &= ~FB_VMODE_MASK; | |
1455 | var->vmode |= FB_VMODE_NONINTERLACED; | |
1456 | } | |
1457 | if (var->vmode & FB_VMODE_DOUBLE) { | |
1458 | var->vmode &= ~FB_VMODE_MASK; | |
1459 | var->vmode |= FB_VMODE_NONINTERLACED; | |
1460 | } | |
1461 | ||
1462 | i810_round_off(var); | |
1463 | if ((err = i810_check_params(var, info))) | |
1464 | return err; | |
1465 | ||
1466 | i810fb_fill_var_timings(var); | |
1467 | set_color_bitfields(var); | |
1468 | return 0; | |
1469 | } | |
1470 | ||
1471 | static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor) | |
1472 | { | |
c019c0ec | 1473 | struct i810fb_par *par = info->par; |
1da177e4 LT |
1474 | u8 __iomem *mmio = par->mmio_start_virtual; |
1475 | ||
4c7ffe0b JS |
1476 | if (!par->dev_flags & LOCKUP) |
1477 | return -ENXIO; | |
1da177e4 LT |
1478 | |
1479 | if (cursor->image.width > 64 || cursor->image.height > 64) | |
1480 | return -ENXIO; | |
1481 | ||
1482 | if ((i810_readl(CURBASE, mmio) & 0xf) != par->cursor_heap.physical) { | |
1483 | i810_init_cursor(par); | |
1484 | cursor->set |= FB_CUR_SETALL; | |
1485 | } | |
1486 | ||
1487 | i810_enable_cursor(mmio, OFF); | |
1488 | ||
1489 | if (cursor->set & FB_CUR_SETPOS) { | |
1490 | u32 tmp; | |
1491 | ||
1492 | tmp = (cursor->image.dx - info->var.xoffset) & 0xffff; | |
1493 | tmp |= (cursor->image.dy - info->var.yoffset) << 16; | |
1494 | i810_writel(CURPOS, mmio, tmp); | |
1495 | } | |
1496 | ||
1497 | if (cursor->set & FB_CUR_SETSIZE) | |
1498 | i810_reset_cursor_image(par); | |
1499 | ||
1500 | if (cursor->set & FB_CUR_SETCMAP) | |
1501 | i810_load_cursor_colors(cursor->image.fg_color, | |
1502 | cursor->image.bg_color, | |
1503 | info); | |
1504 | ||
1505 | if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) { | |
1506 | int size = ((cursor->image.width + 7) >> 3) * | |
1507 | cursor->image.height; | |
1508 | int i; | |
8a2cda00 | 1509 | u8 *data = kmalloc(64 * 8, GFP_ATOMIC); |
1da177e4 LT |
1510 | |
1511 | if (data == NULL) | |
1512 | return -ENOMEM; | |
1513 | ||
1514 | switch (cursor->rop) { | |
1515 | case ROP_XOR: | |
1516 | for (i = 0; i < size; i++) | |
1517 | data[i] = cursor->image.data[i] ^ cursor->mask[i]; | |
1518 | break; | |
1519 | case ROP_COPY: | |
1520 | default: | |
1521 | for (i = 0; i < size; i++) | |
1522 | data[i] = cursor->image.data[i] & cursor->mask[i]; | |
1523 | break; | |
1524 | } | |
1525 | ||
1526 | i810_load_cursor_image(cursor->image.width, | |
1527 | cursor->image.height, data, | |
1528 | par); | |
1529 | kfree(data); | |
1530 | } | |
1531 | ||
1532 | if (cursor->enable) | |
1533 | i810_enable_cursor(mmio, ON); | |
1534 | ||
1535 | return 0; | |
1536 | } | |
1537 | ||
1538 | static struct fb_ops i810fb_ops __devinitdata = { | |
1539 | .owner = THIS_MODULE, | |
1540 | .fb_open = i810fb_open, | |
1541 | .fb_release = i810fb_release, | |
1542 | .fb_check_var = i810fb_check_var, | |
1543 | .fb_set_par = i810fb_set_par, | |
1544 | .fb_setcolreg = i810fb_setcolreg, | |
1545 | .fb_blank = i810fb_blank, | |
1546 | .fb_pan_display = i810fb_pan_display, | |
1547 | .fb_fillrect = i810fb_fillrect, | |
1548 | .fb_copyarea = i810fb_copyarea, | |
1549 | .fb_imageblit = i810fb_imageblit, | |
1550 | .fb_cursor = i810fb_cursor, | |
1551 | .fb_sync = i810fb_sync, | |
1552 | }; | |
1553 | ||
1554 | /*********************************************************************** | |
1555 | * Power Management * | |
1556 | ***********************************************************************/ | |
1557 | static int i810fb_suspend(struct pci_dev *dev, pm_message_t state) | |
1558 | { | |
1559 | struct fb_info *info = pci_get_drvdata(dev); | |
c019c0ec | 1560 | struct i810fb_par *par = info->par; |
1da177e4 | 1561 | |
ca078bae | 1562 | par->cur_state = state.event; |
1da177e4 | 1563 | |
c5eec03f AD |
1564 | if (state.event == PM_EVENT_FREEZE) { |
1565 | dev->dev.power.power_state = state; | |
1566 | return 0; | |
1da177e4 | 1567 | } |
1da177e4 | 1568 | |
c5eec03f AD |
1569 | acquire_console_sem(); |
1570 | fb_set_suspend(info, 1); | |
1571 | ||
1572 | if (info->fbops->fb_sync) | |
1573 | info->fbops->fb_sync(info); | |
1574 | ||
1575 | i810fb_blank(FB_BLANK_POWERDOWN, info); | |
1576 | agp_unbind_memory(par->i810_gtt.i810_fb_memory); | |
1577 | agp_unbind_memory(par->i810_gtt.i810_cursor_memory); | |
1578 | ||
1da177e4 | 1579 | pci_save_state(dev); |
c5eec03f | 1580 | pci_disable_device(dev); |
1da177e4 | 1581 | pci_set_power_state(dev, pci_choose_state(dev, state)); |
c5eec03f | 1582 | release_console_sem(); |
1da177e4 LT |
1583 | |
1584 | return 0; | |
1585 | } | |
1586 | ||
1587 | static int i810fb_resume(struct pci_dev *dev) | |
1588 | { | |
1589 | struct fb_info *info = pci_get_drvdata(dev); | |
c019c0ec | 1590 | struct i810fb_par *par = info->par; |
c5eec03f AD |
1591 | int cur_state = par->cur_state; |
1592 | ||
1593 | par->cur_state = PM_EVENT_ON; | |
1da177e4 | 1594 | |
c5eec03f AD |
1595 | if (cur_state == PM_EVENT_FREEZE) { |
1596 | pci_set_power_state(dev, PCI_D0); | |
1da177e4 | 1597 | return 0; |
c5eec03f | 1598 | } |
1da177e4 | 1599 | |
c5eec03f | 1600 | acquire_console_sem(); |
1da177e4 | 1601 | pci_set_power_state(dev, PCI_D0); |
c5eec03f | 1602 | pci_restore_state(dev); |
1da177e4 | 1603 | pci_enable_device(dev); |
c5eec03f | 1604 | pci_set_master(dev); |
1da177e4 LT |
1605 | agp_bind_memory(par->i810_gtt.i810_fb_memory, |
1606 | par->fb.offset); | |
1607 | agp_bind_memory(par->i810_gtt.i810_cursor_memory, | |
1608 | par->cursor_heap.offset); | |
c5eec03f AD |
1609 | i810fb_set_par(info); |
1610 | fb_set_suspend (info, 0); | |
1da177e4 | 1611 | info->fbops->fb_blank(VESA_NO_BLANKING, info); |
c5eec03f | 1612 | release_console_sem(); |
1da177e4 LT |
1613 | return 0; |
1614 | } | |
1615 | /*********************************************************************** | |
1616 | * AGP resource allocation * | |
1617 | ***********************************************************************/ | |
1618 | ||
1619 | static void __devinit i810_fix_pointers(struct i810fb_par *par) | |
1620 | { | |
1621 | par->fb.physical = par->aperture.physical+(par->fb.offset << 12); | |
1622 | par->fb.virtual = par->aperture.virtual+(par->fb.offset << 12); | |
1623 | par->iring.physical = par->aperture.physical + | |
1624 | (par->iring.offset << 12); | |
1625 | par->iring.virtual = par->aperture.virtual + | |
1626 | (par->iring.offset << 12); | |
1627 | par->cursor_heap.virtual = par->aperture.virtual+ | |
1628 | (par->cursor_heap.offset << 12); | |
1629 | } | |
1630 | ||
1631 | static void __devinit i810_fix_offsets(struct i810fb_par *par) | |
1632 | { | |
1633 | if (vram + 1 > par->aperture.size >> 20) | |
1634 | vram = (par->aperture.size >> 20) - 1; | |
1635 | if (v_offset_default > (par->aperture.size >> 20)) | |
1636 | v_offset_default = (par->aperture.size >> 20); | |
1637 | if (vram + v_offset_default + 1 > par->aperture.size >> 20) | |
1638 | v_offset_default = (par->aperture.size >> 20) - (vram + 1); | |
1639 | ||
1640 | par->fb.size = vram << 20; | |
1641 | par->fb.offset = v_offset_default << 20; | |
1642 | par->fb.offset >>= 12; | |
1643 | ||
1644 | par->iring.offset = par->fb.offset + (par->fb.size >> 12); | |
1645 | par->iring.size = RINGBUFFER_SIZE; | |
1646 | ||
1647 | par->cursor_heap.offset = par->iring.offset + (RINGBUFFER_SIZE >> 12); | |
1648 | par->cursor_heap.size = 4096; | |
1649 | } | |
1650 | ||
1651 | static int __devinit i810_alloc_agp_mem(struct fb_info *info) | |
1652 | { | |
c019c0ec | 1653 | struct i810fb_par *par = info->par; |
1da177e4 LT |
1654 | int size; |
1655 | struct agp_bridge_data *bridge; | |
1656 | ||
1657 | i810_fix_offsets(par); | |
1658 | size = par->fb.size + par->iring.size; | |
1659 | ||
1660 | if (!(bridge = agp_backend_acquire(par->dev))) { | |
1661 | printk("i810fb_alloc_fbmem: cannot acquire agpgart\n"); | |
1662 | return -ENODEV; | |
1663 | } | |
1664 | if (!(par->i810_gtt.i810_fb_memory = | |
1665 | agp_allocate_memory(bridge, size >> 12, AGP_NORMAL_MEMORY))) { | |
1666 | printk("i810fb_alloc_fbmem: can't allocate framebuffer " | |
1667 | "memory\n"); | |
1668 | agp_backend_release(bridge); | |
1669 | return -ENOMEM; | |
1670 | } | |
1671 | if (agp_bind_memory(par->i810_gtt.i810_fb_memory, | |
1672 | par->fb.offset)) { | |
1673 | printk("i810fb_alloc_fbmem: can't bind framebuffer memory\n"); | |
1674 | agp_backend_release(bridge); | |
1675 | return -EBUSY; | |
1676 | } | |
1677 | ||
1678 | if (!(par->i810_gtt.i810_cursor_memory = | |
1679 | agp_allocate_memory(bridge, par->cursor_heap.size >> 12, | |
1680 | AGP_PHYSICAL_MEMORY))) { | |
1681 | printk("i810fb_alloc_cursormem: can't allocate" | |
1682 | "cursor memory\n"); | |
1683 | agp_backend_release(bridge); | |
1684 | return -ENOMEM; | |
1685 | } | |
1686 | if (agp_bind_memory(par->i810_gtt.i810_cursor_memory, | |
1687 | par->cursor_heap.offset)) { | |
1688 | printk("i810fb_alloc_cursormem: cannot bind cursor memory\n"); | |
1689 | agp_backend_release(bridge); | |
1690 | return -EBUSY; | |
1691 | } | |
1692 | ||
1693 | par->cursor_heap.physical = par->i810_gtt.i810_cursor_memory->physical; | |
1694 | ||
1695 | i810_fix_pointers(par); | |
1696 | ||
1697 | agp_backend_release(bridge); | |
1698 | ||
1699 | return 0; | |
1700 | } | |
1701 | ||
1702 | /*************************************************************** | |
1703 | * Initialization * | |
1704 | ***************************************************************/ | |
1705 | ||
1706 | /** | |
1707 | * i810_init_monspecs | |
1708 | * @info: pointer to device specific info structure | |
1709 | * | |
1710 | * DESCRIPTION: | |
1711 | * Sets the the user monitor's horizontal and vertical | |
1712 | * frequency limits | |
1713 | */ | |
1714 | static void __devinit i810_init_monspecs(struct fb_info *info) | |
1715 | { | |
1716 | if (!hsync1) | |
1717 | hsync1 = HFMIN; | |
1718 | if (!hsync2) | |
1719 | hsync2 = HFMAX; | |
1720 | if (!info->monspecs.hfmax) | |
1721 | info->monspecs.hfmax = hsync2; | |
1722 | if (!info->monspecs.hfmin) | |
1723 | info->monspecs.hfmin = hsync1; | |
1724 | if (hsync2 < hsync1) | |
1725 | info->monspecs.hfmin = hsync2; | |
1726 | ||
1727 | if (!vsync1) | |
1728 | vsync1 = VFMIN; | |
1729 | if (!vsync2) | |
1730 | vsync2 = VFMAX; | |
1731 | if (IS_DVT && vsync1 < 60) | |
1732 | vsync1 = 60; | |
1733 | if (!info->monspecs.vfmax) | |
1734 | info->monspecs.vfmax = vsync2; | |
1735 | if (!info->monspecs.vfmin) | |
1736 | info->monspecs.vfmin = vsync1; | |
1737 | if (vsync2 < vsync1) | |
1738 | info->monspecs.vfmin = vsync2; | |
1739 | } | |
1740 | ||
1741 | /** | |
1742 | * i810_init_defaults - initializes default values to use | |
1743 | * @par: pointer to i810fb_par structure | |
1744 | * @info: pointer to current fb_info structure | |
1745 | */ | |
1746 | static void __devinit i810_init_defaults(struct i810fb_par *par, | |
1747 | struct fb_info *info) | |
1748 | { | |
1749 | if (voffset) | |
1750 | v_offset_default = voffset; | |
1751 | else if (par->aperture.size > 32 * 1024 * 1024) | |
1752 | v_offset_default = 16; | |
1753 | else | |
1754 | v_offset_default = 8; | |
1755 | ||
1756 | if (!vram) | |
1757 | vram = 1; | |
1758 | ||
1759 | if (accel) | |
1760 | par->dev_flags |= HAS_ACCELERATION; | |
1761 | ||
1762 | if (sync) | |
1763 | par->dev_flags |= ALWAYS_SYNC; | |
1764 | ||
00d340b9 ML |
1765 | par->ddc_num = ddc3; |
1766 | ||
1da177e4 LT |
1767 | if (bpp < 8) |
1768 | bpp = 8; | |
1769 | ||
595e8a97 AD |
1770 | par->i810fb_ops = i810fb_ops; |
1771 | ||
1772 | if (xres) | |
1773 | info->var.xres = xres; | |
1774 | else | |
1775 | info->var.xres = 640; | |
1776 | ||
1777 | if (yres) | |
1778 | info->var.yres = yres; | |
1779 | else | |
1780 | info->var.yres = 480; | |
1781 | ||
1da177e4 | 1782 | if (!vyres) |
595e8a97 | 1783 | vyres = (vram << 20)/(info->var.xres*bpp >> 3); |
1da177e4 | 1784 | |
1da177e4 LT |
1785 | info->var.yres_virtual = vyres; |
1786 | info->var.bits_per_pixel = bpp; | |
1787 | ||
1788 | if (dcolor) | |
1789 | info->var.nonstd = 1; | |
1790 | ||
1791 | if (par->dev_flags & HAS_ACCELERATION) | |
1792 | info->var.accel_flags = 1; | |
1793 | ||
1794 | i810_init_monspecs(info); | |
1795 | } | |
1796 | ||
1797 | /** | |
1798 | * i810_init_device - initialize device | |
1799 | * @par: pointer to i810fb_par structure | |
1800 | */ | |
1801 | static void __devinit i810_init_device(struct i810fb_par *par) | |
1802 | { | |
1803 | u8 reg; | |
1804 | u8 __iomem *mmio = par->mmio_start_virtual; | |
1805 | ||
1806 | if (mtrr) set_mtrr(par); | |
1807 | ||
1808 | i810_init_cursor(par); | |
1809 | ||
1810 | /* mvo: enable external vga-connector (for laptops) */ | |
747a5054 | 1811 | if (extvga) { |
1da177e4 LT |
1812 | i810_writel(HVSYNC, mmio, 0); |
1813 | i810_writel(PWR_CLKC, mmio, 3); | |
1814 | } | |
1815 | ||
1816 | pci_read_config_byte(par->dev, 0x50, ®); | |
1817 | reg &= FREQ_MASK; | |
1818 | par->mem_freq = (reg) ? 133 : 100; | |
1819 | ||
1820 | } | |
1821 | ||
1822 | static int __devinit | |
1823 | i810_allocate_pci_resource(struct i810fb_par *par, | |
1824 | const struct pci_device_id *entry) | |
1825 | { | |
1826 | int err; | |
1827 | ||
1828 | if ((err = pci_enable_device(par->dev))) { | |
1829 | printk("i810fb_init: cannot enable device\n"); | |
1830 | return err; | |
1831 | } | |
1832 | par->res_flags |= PCI_DEVICE_ENABLED; | |
1833 | ||
1834 | if (pci_resource_len(par->dev, 0) > 512 * 1024) { | |
1835 | par->aperture.physical = pci_resource_start(par->dev, 0); | |
1836 | par->aperture.size = pci_resource_len(par->dev, 0); | |
1837 | par->mmio_start_phys = pci_resource_start(par->dev, 1); | |
1838 | } else { | |
1839 | par->aperture.physical = pci_resource_start(par->dev, 1); | |
1840 | par->aperture.size = pci_resource_len(par->dev, 1); | |
1841 | par->mmio_start_phys = pci_resource_start(par->dev, 0); | |
1842 | } | |
1843 | if (!par->aperture.size) { | |
1844 | printk("i810fb_init: device is disabled\n"); | |
1845 | return -ENOMEM; | |
1846 | } | |
1847 | ||
1848 | if (!request_mem_region(par->aperture.physical, | |
1849 | par->aperture.size, | |
1850 | i810_pci_list[entry->driver_data])) { | |
1851 | printk("i810fb_init: cannot request framebuffer region\n"); | |
1852 | return -ENODEV; | |
1853 | } | |
1854 | par->res_flags |= FRAMEBUFFER_REQ; | |
1855 | ||
1856 | par->aperture.virtual = ioremap_nocache(par->aperture.physical, | |
1857 | par->aperture.size); | |
1858 | if (!par->aperture.virtual) { | |
1859 | printk("i810fb_init: cannot remap framebuffer region\n"); | |
1860 | return -ENODEV; | |
1861 | } | |
1862 | ||
1863 | if (!request_mem_region(par->mmio_start_phys, | |
1864 | MMIO_SIZE, | |
1865 | i810_pci_list[entry->driver_data])) { | |
1866 | printk("i810fb_init: cannot request mmio region\n"); | |
1867 | return -ENODEV; | |
1868 | } | |
1869 | par->res_flags |= MMIO_REQ; | |
1870 | ||
1871 | par->mmio_start_virtual = ioremap_nocache(par->mmio_start_phys, | |
1872 | MMIO_SIZE); | |
1873 | if (!par->mmio_start_virtual) { | |
1874 | printk("i810fb_init: cannot remap mmio region\n"); | |
1875 | return -ENODEV; | |
1876 | } | |
1877 | ||
1878 | return 0; | |
1879 | } | |
1880 | ||
74f6ae84 AD |
1881 | static void __devinit i810fb_find_init_mode(struct fb_info *info) |
1882 | { | |
1883 | struct fb_videomode mode; | |
1884 | struct fb_var_screeninfo var; | |
883f6451 | 1885 | struct fb_monspecs *specs = &info->monspecs; |
74f6ae84 AD |
1886 | int found = 0; |
1887 | #ifdef CONFIG_FB_I810_I2C | |
1888 | int i; | |
00d340b9 | 1889 | int err = 1; |
74f6ae84 AD |
1890 | struct i810fb_par *par = info->par; |
1891 | #endif | |
1892 | ||
1893 | INIT_LIST_HEAD(&info->modelist); | |
1894 | memset(&mode, 0, sizeof(struct fb_videomode)); | |
1895 | var = info->var; | |
1896 | #ifdef CONFIG_FB_I810_I2C | |
1897 | i810_create_i2c_busses(par); | |
1898 | ||
00d340b9 ML |
1899 | for (i = 0; i < par->ddc_num + 1; i++) { |
1900 | err = i810_probe_i2c_connector(info, &par->edid, i); | |
74f6ae84 AD |
1901 | if (!err) |
1902 | break; | |
1903 | } | |
1904 | ||
1905 | if (!err) | |
1906 | printk("i810fb_init_pci: DDC probe successful\n"); | |
1907 | ||
883f6451 | 1908 | fb_edid_to_monspecs(par->edid, specs); |
74f6ae84 | 1909 | |
883f6451 | 1910 | if (specs->modedb == NULL) |
74f6ae84 AD |
1911 | printk("i810fb_init_pci: Unable to get Mode Database\n"); |
1912 | ||
74f6ae84 AD |
1913 | fb_videomode_to_modelist(specs->modedb, specs->modedb_len, |
1914 | &info->modelist); | |
1915 | if (specs->modedb != NULL) { | |
5ee1ef96 | 1916 | struct fb_videomode *m; |
595e8a97 | 1917 | |
5ee1ef96 | 1918 | if (xres && yres) { |
595e8a97 AD |
1919 | if ((m = fb_find_best_mode(&var, &info->modelist))) { |
1920 | mode = *m; | |
1921 | found = 1; | |
1922 | } | |
1923 | } | |
1924 | ||
74f6ae84 | 1925 | if (!found) { |
5ee1ef96 AD |
1926 | m = fb_find_best_display(&info->monspecs, &info->modelist); |
1927 | mode = *m; | |
74f6ae84 AD |
1928 | found = 1; |
1929 | } | |
1930 | ||
1931 | fb_videomode_to_var(&var, &mode); | |
1932 | } | |
1933 | #endif | |
1934 | if (mode_option) | |
1935 | fb_find_mode(&var, info, mode_option, specs->modedb, | |
1936 | specs->modedb_len, (found) ? &mode : NULL, | |
1937 | info->var.bits_per_pixel); | |
1938 | ||
1939 | info->var = var; | |
1940 | fb_destroy_modedb(specs->modedb); | |
1941 | specs->modedb = NULL; | |
1942 | } | |
1943 | ||
1da177e4 | 1944 | #ifndef MODULE |
74f6ae84 | 1945 | static int __devinit i810fb_setup(char *options) |
1da177e4 LT |
1946 | { |
1947 | char *this_opt, *suffix = NULL; | |
1948 | ||
1949 | if (!options || !*options) | |
1950 | return 0; | |
1951 | ||
1952 | while ((this_opt = strsep(&options, ",")) != NULL) { | |
1953 | if (!strncmp(this_opt, "mtrr", 4)) | |
1954 | mtrr = 1; | |
1955 | else if (!strncmp(this_opt, "accel", 5)) | |
1956 | accel = 1; | |
747a5054 AD |
1957 | else if (!strncmp(this_opt, "extvga", 6)) |
1958 | extvga = 1; | |
1da177e4 LT |
1959 | else if (!strncmp(this_opt, "sync", 4)) |
1960 | sync = 1; | |
1961 | else if (!strncmp(this_opt, "vram:", 5)) | |
1962 | vram = (simple_strtoul(this_opt+5, NULL, 0)); | |
1963 | else if (!strncmp(this_opt, "voffset:", 8)) | |
1964 | voffset = (simple_strtoul(this_opt+8, NULL, 0)); | |
1965 | else if (!strncmp(this_opt, "xres:", 5)) | |
1966 | xres = simple_strtoul(this_opt+5, NULL, 0); | |
1967 | else if (!strncmp(this_opt, "yres:", 5)) | |
1968 | yres = simple_strtoul(this_opt+5, NULL, 0); | |
1969 | else if (!strncmp(this_opt, "vyres:", 6)) | |
1970 | vyres = simple_strtoul(this_opt+6, NULL, 0); | |
1971 | else if (!strncmp(this_opt, "bpp:", 4)) | |
1972 | bpp = simple_strtoul(this_opt+4, NULL, 0); | |
1973 | else if (!strncmp(this_opt, "hsync1:", 7)) { | |
1974 | hsync1 = simple_strtoul(this_opt+7, &suffix, 0); | |
1975 | if (strncmp(suffix, "H", 1)) | |
1976 | hsync1 *= 1000; | |
1977 | } else if (!strncmp(this_opt, "hsync2:", 7)) { | |
1978 | hsync2 = simple_strtoul(this_opt+7, &suffix, 0); | |
1979 | if (strncmp(suffix, "H", 1)) | |
1980 | hsync2 *= 1000; | |
1981 | } else if (!strncmp(this_opt, "vsync1:", 7)) | |
1982 | vsync1 = simple_strtoul(this_opt+7, NULL, 0); | |
1983 | else if (!strncmp(this_opt, "vsync2:", 7)) | |
1984 | vsync2 = simple_strtoul(this_opt+7, NULL, 0); | |
1985 | else if (!strncmp(this_opt, "dcolor", 6)) | |
1986 | dcolor = 1; | |
00d340b9 ML |
1987 | else if (!strncmp(this_opt, "ddc3", 4)) |
1988 | ddc3 = 3; | |
74f6ae84 AD |
1989 | else |
1990 | mode_option = this_opt; | |
1da177e4 LT |
1991 | } |
1992 | return 0; | |
1993 | } | |
1994 | #endif | |
1995 | ||
1996 | static int __devinit i810fb_init_pci (struct pci_dev *dev, | |
1997 | const struct pci_device_id *entry) | |
1998 | { | |
1999 | struct fb_info *info; | |
2000 | struct i810fb_par *par = NULL; | |
74f6ae84 | 2001 | struct fb_videomode mode; |
1da177e4 LT |
2002 | int i, err = -1, vfreq, hfreq, pixclock; |
2003 | ||
2004 | i = 0; | |
2005 | ||
2006 | info = framebuffer_alloc(sizeof(struct i810fb_par), &dev->dev); | |
2007 | if (!info) | |
2008 | return -ENOMEM; | |
2009 | ||
74f6ae84 | 2010 | par = info->par; |
1da177e4 LT |
2011 | par->dev = dev; |
2012 | ||
2013 | if (!(info->pixmap.addr = kmalloc(8*1024, GFP_KERNEL))) { | |
2014 | i810fb_release_resource(info, par); | |
2015 | return -ENOMEM; | |
2016 | } | |
2017 | memset(info->pixmap.addr, 0, 8*1024); | |
2018 | info->pixmap.size = 8*1024; | |
2019 | info->pixmap.buf_align = 8; | |
58a60643 | 2020 | info->pixmap.access_align = 32; |
1da177e4 LT |
2021 | info->pixmap.flags = FB_PIXMAP_SYSTEM; |
2022 | ||
2023 | if ((err = i810_allocate_pci_resource(par, entry))) { | |
2024 | i810fb_release_resource(info, par); | |
2025 | return err; | |
2026 | } | |
2027 | ||
2028 | i810_init_defaults(par, info); | |
2029 | ||
2030 | if ((err = i810_alloc_agp_mem(info))) { | |
2031 | i810fb_release_resource(info, par); | |
2032 | return err; | |
2033 | } | |
2034 | ||
2035 | i810_init_device(par); | |
2036 | ||
2037 | info->screen_base = par->fb.virtual; | |
2038 | info->fbops = &par->i810fb_ops; | |
2039 | info->pseudo_palette = par->pseudo_palette; | |
2040 | fb_alloc_cmap(&info->cmap, 256, 0); | |
74f6ae84 | 2041 | i810fb_find_init_mode(info); |
1da177e4 LT |
2042 | |
2043 | if ((err = info->fbops->fb_check_var(&info->var, info))) { | |
2044 | i810fb_release_resource(info, par); | |
2045 | return err; | |
2046 | } | |
74f6ae84 AD |
2047 | |
2048 | fb_var_to_videomode(&mode, &info->var); | |
2049 | fb_add_videomode(&mode, &info->modelist); | |
1da177e4 LT |
2050 | encode_fix(&info->fix, info); |
2051 | ||
2052 | i810fb_init_ringbuffer(info); | |
2053 | err = register_framebuffer(info); | |
74f6ae84 | 2054 | |
1da177e4 LT |
2055 | if (err < 0) { |
2056 | i810fb_release_resource(info, par); | |
2057 | printk("i810fb_init: cannot register framebuffer device\n"); | |
2058 | return err; | |
2059 | } | |
2060 | ||
2061 | pci_set_drvdata(dev, info); | |
2062 | pixclock = 1000000000/(info->var.pixclock); | |
2063 | pixclock *= 1000; | |
2064 | hfreq = pixclock/(info->var.xres + info->var.left_margin + | |
2065 | info->var.hsync_len + info->var.right_margin); | |
2066 | vfreq = hfreq/(info->var.yres + info->var.upper_margin + | |
2067 | info->var.vsync_len + info->var.lower_margin); | |
2068 | ||
2069 | printk("I810FB: fb%d : %s v%d.%d.%d%s\n" | |
2070 | "I810FB: Video RAM : %dK\n" | |
2071 | "I810FB: Monitor : H: %d-%d KHz V: %d-%d Hz\n" | |
2072 | "I810FB: Mode : %dx%d-%dbpp@%dHz\n", | |
2073 | info->node, | |
2074 | i810_pci_list[entry->driver_data], | |
2075 | VERSION_MAJOR, VERSION_MINOR, VERSION_TEENIE, BRANCH_VERSION, | |
2076 | (int) par->fb.size>>10, info->monspecs.hfmin/1000, | |
2077 | info->monspecs.hfmax/1000, info->monspecs.vfmin, | |
2078 | info->monspecs.vfmax, info->var.xres, | |
2079 | info->var.yres, info->var.bits_per_pixel, vfreq); | |
2080 | return 0; | |
2081 | } | |
2082 | ||
2083 | /*************************************************************** | |
2084 | * De-initialization * | |
2085 | ***************************************************************/ | |
2086 | ||
2087 | static void i810fb_release_resource(struct fb_info *info, | |
2088 | struct i810fb_par *par) | |
2089 | { | |
2090 | struct gtt_data *gtt = &par->i810_gtt; | |
2091 | unset_mtrr(par); | |
2092 | ||
74f6ae84 AD |
2093 | i810_delete_i2c_busses(par); |
2094 | ||
1da177e4 LT |
2095 | if (par->i810_gtt.i810_cursor_memory) |
2096 | agp_free_memory(gtt->i810_cursor_memory); | |
2097 | if (par->i810_gtt.i810_fb_memory) | |
2098 | agp_free_memory(gtt->i810_fb_memory); | |
2099 | ||
2100 | if (par->mmio_start_virtual) | |
2101 | iounmap(par->mmio_start_virtual); | |
2102 | if (par->aperture.virtual) | |
2103 | iounmap(par->aperture.virtual); | |
6044ec88 | 2104 | kfree(par->edid); |
1da177e4 LT |
2105 | if (par->res_flags & FRAMEBUFFER_REQ) |
2106 | release_mem_region(par->aperture.physical, | |
2107 | par->aperture.size); | |
2108 | if (par->res_flags & MMIO_REQ) | |
2109 | release_mem_region(par->mmio_start_phys, MMIO_SIZE); | |
2110 | ||
1da177e4 LT |
2111 | framebuffer_release(info); |
2112 | ||
2113 | } | |
2114 | ||
2115 | static void __exit i810fb_remove_pci(struct pci_dev *dev) | |
2116 | { | |
2117 | struct fb_info *info = pci_get_drvdata(dev); | |
c019c0ec | 2118 | struct i810fb_par *par = info->par; |
1da177e4 LT |
2119 | |
2120 | unregister_framebuffer(info); | |
2121 | i810fb_release_resource(info, par); | |
2122 | pci_set_drvdata(dev, NULL); | |
2123 | printk("cleanup_module: unloaded i810 framebuffer device\n"); | |
2124 | } | |
2125 | ||
2126 | #ifndef MODULE | |
74f6ae84 | 2127 | static int __devinit i810fb_init(void) |
1da177e4 LT |
2128 | { |
2129 | char *option = NULL; | |
2130 | ||
2131 | if (fb_get_options("i810fb", &option)) | |
2132 | return -ENODEV; | |
2133 | i810fb_setup(option); | |
2134 | ||
2135 | return pci_register_driver(&i810fb_driver); | |
2136 | } | |
2137 | #endif | |
2138 | ||
2139 | /********************************************************************* | |
2140 | * Modularization * | |
2141 | *********************************************************************/ | |
2142 | ||
2143 | #ifdef MODULE | |
2144 | ||
74f6ae84 | 2145 | static int __devinit i810fb_init(void) |
1da177e4 LT |
2146 | { |
2147 | hsync1 *= 1000; | |
2148 | hsync2 *= 1000; | |
2149 | ||
2150 | return pci_register_driver(&i810fb_driver); | |
2151 | } | |
2152 | ||
2153 | module_param(vram, int, 0); | |
2154 | MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB" | |
2155 | " (default=4)"); | |
2156 | module_param(voffset, int, 0); | |
2157 | MODULE_PARM_DESC(voffset, "at what offset to place start of framebuffer " | |
2158 | "memory (0 to maximum aperture size), in MiB (default = 48)"); | |
2159 | module_param(bpp, int, 0); | |
2160 | MODULE_PARM_DESC(bpp, "Color depth for display in bits per pixel" | |
2161 | " (default = 8)"); | |
2162 | module_param(xres, int, 0); | |
2163 | MODULE_PARM_DESC(xres, "Horizontal resolution in pixels (default = 640)"); | |
2164 | module_param(yres, int, 0); | |
2165 | MODULE_PARM_DESC(yres, "Vertical resolution in scanlines (default = 480)"); | |
2166 | module_param(vyres,int, 0); | |
2167 | MODULE_PARM_DESC(vyres, "Virtual vertical resolution in scanlines" | |
2168 | " (default = 480)"); | |
2169 | module_param(hsync1, int, 0); | |
2170 | MODULE_PARM_DESC(hsync1, "Minimum horizontal frequency of monitor in KHz" | |
db9f1d9d | 2171 | " (default = 29)"); |
1da177e4 LT |
2172 | module_param(hsync2, int, 0); |
2173 | MODULE_PARM_DESC(hsync2, "Maximum horizontal frequency of monitor in KHz" | |
db9f1d9d | 2174 | " (default = 30)"); |
1da177e4 LT |
2175 | module_param(vsync1, int, 0); |
2176 | MODULE_PARM_DESC(vsync1, "Minimum vertical frequency of monitor in Hz" | |
2177 | " (default = 50)"); | |
2178 | module_param(vsync2, int, 0); | |
2179 | MODULE_PARM_DESC(vsync2, "Maximum vertical frequency of monitor in Hz" | |
2180 | " (default = 60)"); | |
2181 | module_param(accel, bool, 0); | |
2182 | MODULE_PARM_DESC(accel, "Use Acceleration (BLIT) engine (default = 0)"); | |
2183 | module_param(mtrr, bool, 0); | |
2184 | MODULE_PARM_DESC(mtrr, "Use MTRR (default = 0)"); | |
747a5054 AD |
2185 | module_param(extvga, bool, 0); |
2186 | MODULE_PARM_DESC(extvga, "Enable external VGA connector (default = 0)"); | |
1da177e4 LT |
2187 | module_param(sync, bool, 0); |
2188 | MODULE_PARM_DESC(sync, "wait for accel engine to finish drawing" | |
2189 | " (default = 0)"); | |
2190 | module_param(dcolor, bool, 0); | |
2191 | MODULE_PARM_DESC(dcolor, "use DirectColor visuals" | |
2192 | " (default = 0 = TrueColor)"); | |
00d340b9 ML |
2193 | module_param(ddc3, bool, 0); |
2194 | MODULE_PARM_DESC(ddc3, "Probe DDC bus 3 (default = 0 = no)"); | |
74f6ae84 AD |
2195 | module_param(mode_option, charp, 0); |
2196 | MODULE_PARM_DESC(mode_option, "Specify initial video mode"); | |
1da177e4 LT |
2197 | |
2198 | MODULE_AUTHOR("Tony A. Daplas"); | |
2199 | MODULE_DESCRIPTION("Framebuffer device for the Intel 810/815 and" | |
2200 | " compatible cards"); | |
2201 | MODULE_LICENSE("GPL"); | |
2202 | ||
2203 | static void __exit i810fb_exit(void) | |
2204 | { | |
2205 | pci_unregister_driver(&i810fb_driver); | |
2206 | } | |
2207 | module_exit(i810fb_exit); | |
2208 | ||
2209 | #endif /* MODULE */ | |
2210 | ||
2211 | module_init(i810fb_init); |