i810_main.c 59 KB

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