i810_main.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213
  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/kernel.h>
  32. #include <linux/errno.h>
  33. #include <linux/string.h>
  34. #include <linux/mm.h>
  35. #include <linux/slab.h>
  36. #include <linux/fb.h>
  37. #include <linux/init.h>
  38. #include <linux/pci.h>
  39. #include <linux/pci_ids.h>
  40. #include <linux/resource.h>
  41. #include <linux/unistd.h>
  42. #include <linux/console.h>
  43. #include <asm/io.h>
  44. #include <asm/div64.h>
  45. #include <asm/page.h>
  46. #include "i810_regs.h"
  47. #include "i810.h"
  48. #include "i810_main.h"
  49. /*
  50. * voffset - framebuffer offset in MiB from aperture start address. In order for
  51. * the driver to work with X, we must try to use memory holes left untouched by X. The
  52. * following table lists where X's different surfaces start at.
  53. *
  54. * ---------------------------------------------
  55. * : : 64 MiB : 32 MiB :
  56. * ----------------------------------------------
  57. * : FrontBuffer : 0 : 0 :
  58. * : DepthBuffer : 48 : 16 :
  59. * : BackBuffer : 56 : 24 :
  60. * ----------------------------------------------
  61. *
  62. * So for chipsets with 64 MiB Aperture sizes, 32 MiB for v_offset is okay, allowing up to
  63. * 15 + 1 MiB of Framebuffer memory. For 32 MiB Aperture sizes, a v_offset of 8 MiB should
  64. * work, allowing 7 + 1 MiB of Framebuffer memory.
  65. * Note, the size of the hole may change depending on how much memory you allocate to X,
  66. * and how the memory is split up between these surfaces.
  67. *
  68. * Note: Anytime the DepthBuffer or FrontBuffer is overlapped, X would still run but with
  69. * DRI disabled. But if the Frontbuffer is overlapped, X will fail to load.
  70. *
  71. * Experiment with v_offset to find out which works best for you.
  72. */
  73. static u32 v_offset_default __devinitdata; /* For 32 MiB Aper size, 8 should be the default */
  74. static u32 voffset __devinitdata;
  75. static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor);
  76. static int __devinit i810fb_init_pci (struct pci_dev *dev,
  77. const struct pci_device_id *entry);
  78. static void __exit i810fb_remove_pci(struct pci_dev *dev);
  79. static int i810fb_resume(struct pci_dev *dev);
  80. static int i810fb_suspend(struct pci_dev *dev, pm_message_t state);
  81. /* Chipset Specific Functions */
  82. static int i810fb_set_par (struct fb_info *info);
  83. static int i810fb_getcolreg (u8 regno, u8 *red, u8 *green, u8 *blue,
  84. u8 *transp, struct fb_info *info);
  85. static int i810fb_setcolreg (unsigned regno, unsigned red, unsigned green, unsigned blue,
  86. unsigned transp, struct fb_info *info);
  87. static int i810fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
  88. static int i810fb_blank (int blank_mode, struct fb_info *info);
  89. /* Initialization */
  90. static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
  91. /* PCI */
  92. static const char *i810_pci_list[] __devinitdata = {
  93. "Intel(R) 810 Framebuffer Device" ,
  94. "Intel(R) 810-DC100 Framebuffer Device" ,
  95. "Intel(R) 810E Framebuffer Device" ,
  96. "Intel(R) 815 (Internal Graphics 100Mhz FSB) Framebuffer Device" ,
  97. "Intel(R) 815 (Internal Graphics only) Framebuffer Device" ,
  98. "Intel(R) 815 (Internal Graphics with AGP) Framebuffer Device"
  99. };
  100. static struct pci_device_id i810fb_pci_tbl[] = {
  101. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG1,
  102. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  103. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3,
  104. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
  105. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810E_IG,
  106. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
  107. /* mvo: added i815 PCI-ID */
  108. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_100,
  109. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
  110. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_NOAGP,
  111. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
  112. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
  113. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
  114. { 0 },
  115. };
  116. static struct pci_driver i810fb_driver = {
  117. .name = "i810fb",
  118. .id_table = i810fb_pci_tbl,
  119. .probe = i810fb_init_pci,
  120. .remove = __exit_p(i810fb_remove_pci),
  121. .suspend = i810fb_suspend,
  122. .resume = i810fb_resume,
  123. };
  124. static char *mode_option __devinitdata = NULL;
  125. static int vram __devinitdata = 4;
  126. static int bpp __devinitdata = 8;
  127. static int mtrr __devinitdata;
  128. static int accel __devinitdata;
  129. static int hsync1 __devinitdata;
  130. static int hsync2 __devinitdata;
  131. static int vsync1 __devinitdata;
  132. static int vsync2 __devinitdata;
  133. static int xres __devinitdata;
  134. static int yres __devinitdata;
  135. static int vyres __devinitdata;
  136. static int sync __devinitdata;
  137. static int extvga __devinitdata;
  138. static int dcolor __devinitdata;
  139. static int ddc3 __devinitdata = 2;
  140. /*------------------------------------------------------------*/
  141. /**************************************************************
  142. * Hardware Low Level Routines *
  143. **************************************************************/
  144. /**
  145. * i810_screen_off - turns off/on display
  146. * @mmio: address of register space
  147. * @mode: on or off
  148. *
  149. * DESCRIPTION:
  150. * Blanks/unblanks the display
  151. */
  152. static void i810_screen_off(u8 __iomem *mmio, u8 mode)
  153. {
  154. u32 count = WAIT_COUNT;
  155. u8 val;
  156. i810_writeb(SR_INDEX, mmio, SR01);
  157. val = i810_readb(SR_DATA, mmio);
  158. val = (mode == OFF) ? val | SCR_OFF :
  159. val & ~SCR_OFF;
  160. while((i810_readw(DISP_SL, mmio) & 0xFFF) && count--);
  161. i810_writeb(SR_INDEX, mmio, SR01);
  162. i810_writeb(SR_DATA, mmio, val);
  163. }
  164. /**
  165. * i810_dram_off - turns off/on dram refresh
  166. * @mmio: address of register space
  167. * @mode: on or off
  168. *
  169. * DESCRIPTION:
  170. * Turns off DRAM refresh. Must be off for only 2 vsyncs
  171. * before data becomes corrupt
  172. */
  173. static void i810_dram_off(u8 __iomem *mmio, u8 mode)
  174. {
  175. u8 val;
  176. val = i810_readb(DRAMCH, mmio);
  177. val &= DRAM_OFF;
  178. val = (mode == OFF) ? val : val | DRAM_ON;
  179. i810_writeb(DRAMCH, mmio, val);
  180. }
  181. /**
  182. * i810_protect_regs - allows rw/ro mode of certain VGA registers
  183. * @mmio: address of register space
  184. * @mode: protect/unprotect
  185. *
  186. * DESCRIPTION:
  187. * The IBM VGA standard allows protection of certain VGA registers.
  188. * This will protect or unprotect them.
  189. */
  190. static void i810_protect_regs(u8 __iomem *mmio, int mode)
  191. {
  192. u8 reg;
  193. i810_writeb(CR_INDEX_CGA, mmio, CR11);
  194. reg = i810_readb(CR_DATA_CGA, mmio);
  195. reg = (mode == OFF) ? reg & ~0x80 :
  196. reg | 0x80;
  197. i810_writeb(CR_INDEX_CGA, mmio, CR11);
  198. i810_writeb(CR_DATA_CGA, mmio, reg);
  199. }
  200. /**
  201. * i810_load_pll - loads values for the hardware PLL clock
  202. * @par: pointer to i810fb_par structure
  203. *
  204. * DESCRIPTION:
  205. * Loads the P, M, and N registers.
  206. */
  207. static void i810_load_pll(struct i810fb_par *par)
  208. {
  209. u32 tmp1, tmp2;
  210. u8 __iomem *mmio = par->mmio_start_virtual;
  211. tmp1 = par->regs.M | par->regs.N << 16;
  212. tmp2 = i810_readl(DCLK_2D, mmio);
  213. tmp2 &= ~MN_MASK;
  214. i810_writel(DCLK_2D, mmio, tmp1 | tmp2);
  215. tmp1 = par->regs.P;
  216. tmp2 = i810_readl(DCLK_0DS, mmio);
  217. tmp2 &= ~(P_OR << 16);
  218. i810_writel(DCLK_0DS, mmio, (tmp1 << 16) | tmp2);
  219. i810_writeb(MSR_WRITE, mmio, par->regs.msr | 0xC8 | 1);
  220. }
  221. /**
  222. * i810_load_vga - load standard VGA registers
  223. * @par: pointer to i810fb_par structure
  224. *
  225. * DESCRIPTION:
  226. * Load values to VGA registers
  227. */
  228. static void i810_load_vga(struct i810fb_par *par)
  229. {
  230. u8 __iomem *mmio = par->mmio_start_virtual;
  231. /* interlace */
  232. i810_writeb(CR_INDEX_CGA, mmio, CR70);
  233. i810_writeb(CR_DATA_CGA, mmio, par->interlace);
  234. i810_writeb(CR_INDEX_CGA, mmio, CR00);
  235. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr00);
  236. i810_writeb(CR_INDEX_CGA, mmio, CR01);
  237. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr01);
  238. i810_writeb(CR_INDEX_CGA, mmio, CR02);
  239. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr02);
  240. i810_writeb(CR_INDEX_CGA, mmio, CR03);
  241. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr03);
  242. i810_writeb(CR_INDEX_CGA, mmio, CR04);
  243. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr04);
  244. i810_writeb(CR_INDEX_CGA, mmio, CR05);
  245. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr05);
  246. i810_writeb(CR_INDEX_CGA, mmio, CR06);
  247. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr06);
  248. i810_writeb(CR_INDEX_CGA, mmio, CR09);
  249. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr09);
  250. i810_writeb(CR_INDEX_CGA, mmio, CR10);
  251. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr10);
  252. i810_writeb(CR_INDEX_CGA, mmio, CR11);
  253. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr11);
  254. i810_writeb(CR_INDEX_CGA, mmio, CR12);
  255. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr12);
  256. i810_writeb(CR_INDEX_CGA, mmio, CR15);
  257. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr15);
  258. i810_writeb(CR_INDEX_CGA, mmio, CR16);
  259. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr16);
  260. }
  261. /**
  262. * i810_load_vgax - load extended VGA registers
  263. * @par: pointer to i810fb_par structure
  264. *
  265. * DESCRIPTION:
  266. * Load values to extended VGA registers
  267. */
  268. static void i810_load_vgax(struct i810fb_par *par)
  269. {
  270. u8 __iomem *mmio = par->mmio_start_virtual;
  271. i810_writeb(CR_INDEX_CGA, mmio, CR30);
  272. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr30);
  273. i810_writeb(CR_INDEX_CGA, mmio, CR31);
  274. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr31);
  275. i810_writeb(CR_INDEX_CGA, mmio, CR32);
  276. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr32);
  277. i810_writeb(CR_INDEX_CGA, mmio, CR33);
  278. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr33);
  279. i810_writeb(CR_INDEX_CGA, mmio, CR35);
  280. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr35);
  281. i810_writeb(CR_INDEX_CGA, mmio, CR39);
  282. i810_writeb(CR_DATA_CGA, mmio, par->regs.cr39);
  283. }
  284. /**
  285. * i810_load_2d - load grahics registers
  286. * @par: pointer to i810fb_par structure
  287. *
  288. * DESCRIPTION:
  289. * Load values to graphics registers
  290. */
  291. static void i810_load_2d(struct i810fb_par *par)
  292. {
  293. u32 tmp;
  294. u8 tmp8;
  295. u8 __iomem *mmio = par->mmio_start_virtual;
  296. i810_writel(FW_BLC, mmio, par->watermark);
  297. tmp = i810_readl(PIXCONF, mmio);
  298. tmp |= 1 | 1 << 20;
  299. i810_writel(PIXCONF, mmio, tmp);
  300. i810_writel(OVRACT, mmio, par->ovract);
  301. i810_writeb(GR_INDEX, mmio, GR10);
  302. tmp8 = i810_readb(GR_DATA, mmio);
  303. tmp8 |= 2;
  304. i810_writeb(GR_INDEX, mmio, GR10);
  305. i810_writeb(GR_DATA, mmio, tmp8);
  306. }
  307. /**
  308. * i810_hires - enables high resolution mode
  309. * @mmio: address of register space
  310. */
  311. static void i810_hires(u8 __iomem *mmio)
  312. {
  313. u8 val;
  314. i810_writeb(CR_INDEX_CGA, mmio, CR80);
  315. val = i810_readb(CR_DATA_CGA, mmio);
  316. i810_writeb(CR_INDEX_CGA, mmio, CR80);
  317. i810_writeb(CR_DATA_CGA, mmio, val | 1);
  318. /* Stop LCD displays from flickering */
  319. i810_writel(MEM_MODE, mmio, i810_readl(MEM_MODE, mmio) | 4);
  320. }
  321. /**
  322. * i810_load_pitch - loads the characters per line of the display
  323. * @par: pointer to i810fb_par structure
  324. *
  325. * DESCRIPTION:
  326. * Loads the characters per line
  327. */
  328. static void i810_load_pitch(struct i810fb_par *par)
  329. {
  330. u32 tmp, pitch;
  331. u8 val;
  332. u8 __iomem *mmio = par->mmio_start_virtual;
  333. pitch = par->pitch >> 3;
  334. i810_writeb(SR_INDEX, mmio, SR01);
  335. val = i810_readb(SR_DATA, mmio);
  336. val &= 0xE0;
  337. val |= 1 | 1 << 2;
  338. i810_writeb(SR_INDEX, mmio, SR01);
  339. i810_writeb(SR_DATA, mmio, val);
  340. tmp = pitch & 0xFF;
  341. i810_writeb(CR_INDEX_CGA, mmio, CR13);
  342. i810_writeb(CR_DATA_CGA, mmio, (u8) tmp);
  343. tmp = pitch >> 8;
  344. i810_writeb(CR_INDEX_CGA, mmio, CR41);
  345. val = i810_readb(CR_DATA_CGA, mmio) & ~0x0F;
  346. i810_writeb(CR_INDEX_CGA, mmio, CR41);
  347. i810_writeb(CR_DATA_CGA, mmio, (u8) tmp | val);
  348. }
  349. /**
  350. * i810_load_color - loads the color depth of the display
  351. * @par: pointer to i810fb_par structure
  352. *
  353. * DESCRIPTION:
  354. * Loads the color depth of the display and the graphics engine
  355. */
  356. static void i810_load_color(struct i810fb_par *par)
  357. {
  358. u8 __iomem *mmio = par->mmio_start_virtual;
  359. u32 reg1;
  360. u16 reg2;
  361. reg1 = i810_readl(PIXCONF, mmio) & ~(0xF0000 | 1 << 27);
  362. reg2 = i810_readw(BLTCNTL, mmio) & ~0x30;
  363. reg1 |= 0x8000 | par->pixconf;
  364. reg2 |= par->bltcntl;
  365. i810_writel(PIXCONF, mmio, reg1);
  366. i810_writew(BLTCNTL, mmio, reg2);
  367. }
  368. /**
  369. * i810_load_regs - loads all registers for the mode
  370. * @par: pointer to i810fb_par structure
  371. *
  372. * DESCRIPTION:
  373. * Loads registers
  374. */
  375. static void i810_load_regs(struct i810fb_par *par)
  376. {
  377. u8 __iomem *mmio = par->mmio_start_virtual;
  378. i810_screen_off(mmio, OFF);
  379. i810_protect_regs(mmio, OFF);
  380. i810_dram_off(mmio, OFF);
  381. i810_load_pll(par);
  382. i810_load_vga(par);
  383. i810_load_vgax(par);
  384. i810_dram_off(mmio, ON);
  385. i810_load_2d(par);
  386. i810_hires(mmio);
  387. i810_screen_off(mmio, ON);
  388. i810_protect_regs(mmio, ON);
  389. i810_load_color(par);
  390. i810_load_pitch(par);
  391. }
  392. static void i810_write_dac(u8 regno, u8 red, u8 green, u8 blue,
  393. u8 __iomem *mmio)
  394. {
  395. i810_writeb(CLUT_INDEX_WRITE, mmio, regno);
  396. i810_writeb(CLUT_DATA, mmio, red);
  397. i810_writeb(CLUT_DATA, mmio, green);
  398. i810_writeb(CLUT_DATA, mmio, blue);
  399. }
  400. static void i810_read_dac(u8 regno, u8 *red, u8 *green, u8 *blue,
  401. u8 __iomem *mmio)
  402. {
  403. i810_writeb(CLUT_INDEX_READ, mmio, regno);
  404. *red = i810_readb(CLUT_DATA, mmio);
  405. *green = i810_readb(CLUT_DATA, mmio);
  406. *blue = i810_readb(CLUT_DATA, mmio);
  407. }
  408. /************************************************************
  409. * VGA State Restore *
  410. ************************************************************/
  411. static void i810_restore_pll(struct i810fb_par *par)
  412. {
  413. u32 tmp1, tmp2;
  414. u8 __iomem *mmio = par->mmio_start_virtual;
  415. tmp1 = par->hw_state.dclk_2d;
  416. tmp2 = i810_readl(DCLK_2D, mmio);
  417. tmp1 &= ~MN_MASK;
  418. tmp2 &= MN_MASK;
  419. i810_writel(DCLK_2D, mmio, tmp1 | tmp2);
  420. tmp1 = par->hw_state.dclk_1d;
  421. tmp2 = i810_readl(DCLK_1D, mmio);
  422. tmp1 &= ~MN_MASK;
  423. tmp2 &= MN_MASK;
  424. i810_writel(DCLK_1D, mmio, tmp1 | tmp2);
  425. i810_writel(DCLK_0DS, mmio, par->hw_state.dclk_0ds);
  426. }
  427. static void i810_restore_dac(struct i810fb_par *par)
  428. {
  429. u32 tmp1, tmp2;
  430. u8 __iomem *mmio = par->mmio_start_virtual;
  431. tmp1 = par->hw_state.pixconf;
  432. tmp2 = i810_readl(PIXCONF, mmio);
  433. tmp1 &= DAC_BIT;
  434. tmp2 &= ~DAC_BIT;
  435. i810_writel(PIXCONF, mmio, tmp1 | tmp2);
  436. }
  437. static void i810_restore_vgax(struct i810fb_par *par)
  438. {
  439. u8 i, j;
  440. u8 __iomem *mmio = par->mmio_start_virtual;
  441. for (i = 0; i < 4; i++) {
  442. i810_writeb(CR_INDEX_CGA, mmio, CR30+i);
  443. i810_writeb(CR_DATA_CGA, mmio, *(&(par->hw_state.cr30) + i));
  444. }
  445. i810_writeb(CR_INDEX_CGA, mmio, CR35);
  446. i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr35);
  447. i810_writeb(CR_INDEX_CGA, mmio, CR39);
  448. i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr39);
  449. i810_writeb(CR_INDEX_CGA, mmio, CR41);
  450. i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr39);
  451. /*restore interlace*/
  452. i810_writeb(CR_INDEX_CGA, mmio, CR70);
  453. i = par->hw_state.cr70;
  454. i &= INTERLACE_BIT;
  455. j = i810_readb(CR_DATA_CGA, mmio);
  456. i810_writeb(CR_INDEX_CGA, mmio, CR70);
  457. i810_writeb(CR_DATA_CGA, mmio, j | i);
  458. i810_writeb(CR_INDEX_CGA, mmio, CR80);
  459. i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr80);
  460. i810_writeb(MSR_WRITE, mmio, par->hw_state.msr);
  461. i810_writeb(SR_INDEX, mmio, SR01);
  462. i = (par->hw_state.sr01) & ~0xE0 ;
  463. j = i810_readb(SR_DATA, mmio) & 0xE0;
  464. i810_writeb(SR_INDEX, mmio, SR01);
  465. i810_writeb(SR_DATA, mmio, i | j);
  466. }
  467. static void i810_restore_vga(struct i810fb_par *par)
  468. {
  469. u8 i;
  470. u8 __iomem *mmio = par->mmio_start_virtual;
  471. for (i = 0; i < 10; i++) {
  472. i810_writeb(CR_INDEX_CGA, mmio, CR00 + i);
  473. i810_writeb(CR_DATA_CGA, mmio, *((&par->hw_state.cr00) + i));
  474. }
  475. for (i = 0; i < 8; i++) {
  476. i810_writeb(CR_INDEX_CGA, mmio, CR10 + i);
  477. i810_writeb(CR_DATA_CGA, mmio, *((&par->hw_state.cr10) + i));
  478. }
  479. }
  480. static void i810_restore_addr_map(struct i810fb_par *par)
  481. {
  482. u8 tmp;
  483. u8 __iomem *mmio = par->mmio_start_virtual;
  484. i810_writeb(GR_INDEX, mmio, GR10);
  485. tmp = i810_readb(GR_DATA, mmio);
  486. tmp &= ADDR_MAP_MASK;
  487. tmp |= par->hw_state.gr10;
  488. i810_writeb(GR_INDEX, mmio, GR10);
  489. i810_writeb(GR_DATA, mmio, tmp);
  490. }
  491. static void i810_restore_2d(struct i810fb_par *par)
  492. {
  493. u32 tmp_long;
  494. u16 tmp_word;
  495. u8 __iomem *mmio = par->mmio_start_virtual;
  496. tmp_word = i810_readw(BLTCNTL, mmio);
  497. tmp_word &= ~(3 << 4);
  498. tmp_word |= par->hw_state.bltcntl;
  499. i810_writew(BLTCNTL, mmio, tmp_word);
  500. i810_dram_off(mmio, OFF);
  501. i810_writel(PIXCONF, mmio, par->hw_state.pixconf);
  502. i810_dram_off(mmio, ON);
  503. tmp_word = i810_readw(HWSTAM, mmio);
  504. tmp_word &= 3 << 13;
  505. tmp_word |= par->hw_state.hwstam;
  506. i810_writew(HWSTAM, mmio, tmp_word);
  507. tmp_long = i810_readl(FW_BLC, mmio);
  508. tmp_long &= FW_BLC_MASK;
  509. tmp_long |= par->hw_state.fw_blc;
  510. i810_writel(FW_BLC, mmio, tmp_long);
  511. i810_writel(HWS_PGA, mmio, par->hw_state.hws_pga);
  512. i810_writew(IER, mmio, par->hw_state.ier);
  513. i810_writew(IMR, mmio, par->hw_state.imr);
  514. i810_writel(DPLYSTAS, mmio, par->hw_state.dplystas);
  515. }
  516. static void i810_restore_vga_state(struct i810fb_par *par)
  517. {
  518. u8 __iomem *mmio = par->mmio_start_virtual;
  519. i810_screen_off(mmio, OFF);
  520. i810_protect_regs(mmio, OFF);
  521. i810_dram_off(mmio, OFF);
  522. i810_restore_pll(par);
  523. i810_restore_dac(par);
  524. i810_restore_vga(par);
  525. i810_restore_vgax(par);
  526. i810_restore_addr_map(par);
  527. i810_dram_off(mmio, ON);
  528. i810_restore_2d(par);
  529. i810_screen_off(mmio, ON);
  530. i810_protect_regs(mmio, ON);
  531. }
  532. /***********************************************************************
  533. * VGA State Save *
  534. ***********************************************************************/
  535. static void i810_save_vgax(struct i810fb_par *par)
  536. {
  537. u8 i;
  538. u8 __iomem *mmio = par->mmio_start_virtual;
  539. for (i = 0; i < 4; i++) {
  540. i810_writeb(CR_INDEX_CGA, mmio, CR30 + i);
  541. *(&(par->hw_state.cr30) + i) = i810_readb(CR_DATA_CGA, mmio);
  542. }
  543. i810_writeb(CR_INDEX_CGA, mmio, CR35);
  544. par->hw_state.cr35 = i810_readb(CR_DATA_CGA, mmio);
  545. i810_writeb(CR_INDEX_CGA, mmio, CR39);
  546. par->hw_state.cr39 = i810_readb(CR_DATA_CGA, mmio);
  547. i810_writeb(CR_INDEX_CGA, mmio, CR41);
  548. par->hw_state.cr41 = i810_readb(CR_DATA_CGA, mmio);
  549. i810_writeb(CR_INDEX_CGA, mmio, CR70);
  550. par->hw_state.cr70 = i810_readb(CR_DATA_CGA, mmio);
  551. par->hw_state.msr = i810_readb(MSR_READ, mmio);
  552. i810_writeb(CR_INDEX_CGA, mmio, CR80);
  553. par->hw_state.cr80 = i810_readb(CR_DATA_CGA, mmio);
  554. i810_writeb(SR_INDEX, mmio, SR01);
  555. par->hw_state.sr01 = i810_readb(SR_DATA, mmio);
  556. }
  557. static void i810_save_vga(struct i810fb_par *par)
  558. {
  559. u8 i;
  560. u8 __iomem *mmio = par->mmio_start_virtual;
  561. for (i = 0; i < 10; i++) {
  562. i810_writeb(CR_INDEX_CGA, mmio, CR00 + i);
  563. *((&par->hw_state.cr00) + i) = i810_readb(CR_DATA_CGA, mmio);
  564. }
  565. for (i = 0; i < 8; i++) {
  566. i810_writeb(CR_INDEX_CGA, mmio, CR10 + i);
  567. *((&par->hw_state.cr10) + i) = i810_readb(CR_DATA_CGA, mmio);
  568. }
  569. }
  570. static void i810_save_2d(struct i810fb_par *par)
  571. {
  572. u8 __iomem *mmio = par->mmio_start_virtual;
  573. par->hw_state.dclk_2d = i810_readl(DCLK_2D, mmio);
  574. par->hw_state.dclk_1d = i810_readl(DCLK_1D, mmio);
  575. par->hw_state.dclk_0ds = i810_readl(DCLK_0DS, mmio);
  576. par->hw_state.pixconf = i810_readl(PIXCONF, mmio);
  577. par->hw_state.fw_blc = i810_readl(FW_BLC, mmio);
  578. par->hw_state.bltcntl = i810_readw(BLTCNTL, mmio);
  579. par->hw_state.hwstam = i810_readw(HWSTAM, mmio);
  580. par->hw_state.hws_pga = i810_readl(HWS_PGA, mmio);
  581. par->hw_state.ier = i810_readw(IER, mmio);
  582. par->hw_state.imr = i810_readw(IMR, mmio);
  583. par->hw_state.dplystas = i810_readl(DPLYSTAS, mmio);
  584. }
  585. static void i810_save_vga_state(struct i810fb_par *par)
  586. {
  587. i810_save_vga(par);
  588. i810_save_vgax(par);
  589. i810_save_2d(par);
  590. }
  591. /************************************************************
  592. * Helpers *
  593. ************************************************************/
  594. /**
  595. * get_line_length - calculates buffer pitch in bytes
  596. * @par: pointer to i810fb_par structure
  597. * @xres_virtual: virtual resolution of the frame
  598. * @bpp: bits per pixel
  599. *
  600. * DESCRIPTION:
  601. * Calculates buffer pitch in bytes.
  602. */
  603. static u32 get_line_length(struct i810fb_par *par, int xres_virtual, int bpp)
  604. {
  605. u32 length;
  606. length = xres_virtual*bpp;
  607. length = (length+31)&-32;
  608. length >>= 3;
  609. return length;
  610. }
  611. /**
  612. * i810_calc_dclk - calculates the P, M, and N values of a pixelclock value
  613. * @freq: target pixelclock in picoseconds
  614. * @m: where to write M register
  615. * @n: where to write N register
  616. * @p: where to write P register
  617. *
  618. * DESCRIPTION:
  619. * Based on the formula Freq_actual = (4*M*Freq_ref)/(N^P)
  620. * Repeatedly computes the Freq until the actual Freq is equal to
  621. * the target Freq or until the loop count is zero. In the latter
  622. * case, the actual frequency nearest the target will be used.
  623. */
  624. static void i810_calc_dclk(u32 freq, u32 *m, u32 *n, u32 *p)
  625. {
  626. u32 m_reg, n_reg, p_divisor, n_target_max;
  627. u32 m_target, n_target, p_target, n_best, m_best, mod;
  628. u32 f_out, target_freq, diff = 0, mod_min, diff_min;
  629. diff_min = mod_min = 0xFFFFFFFF;
  630. n_best = m_best = m_target = f_out = 0;
  631. target_freq = freq;
  632. n_target_max = 30;
  633. /*
  634. * find P such that target freq is 16x reference freq (Hz).
  635. */
  636. p_divisor = 1;
  637. p_target = 0;
  638. while(!((1000000 * p_divisor)/(16 * 24 * target_freq)) &&
  639. p_divisor <= 32) {
  640. p_divisor <<= 1;
  641. p_target++;
  642. }
  643. n_reg = m_reg = n_target = 3;
  644. while (diff_min && mod_min && (n_target < n_target_max)) {
  645. f_out = (p_divisor * n_reg * 1000000)/(4 * 24 * m_reg);
  646. mod = (p_divisor * n_reg * 1000000) % (4 * 24 * m_reg);
  647. m_target = m_reg;
  648. n_target = n_reg;
  649. if (f_out <= target_freq) {
  650. n_reg++;
  651. diff = target_freq - f_out;
  652. } else {
  653. m_reg++;
  654. diff = f_out - target_freq;
  655. }
  656. if (diff_min > diff) {
  657. diff_min = diff;
  658. n_best = n_target;
  659. m_best = m_target;
  660. }
  661. if (!diff && mod_min > mod) {
  662. mod_min = mod;
  663. n_best = n_target;
  664. m_best = m_target;
  665. }
  666. }
  667. if (m) *m = (m_best - 2) & 0x3FF;
  668. if (n) *n = (n_best - 2) & 0x3FF;
  669. if (p) *p = (p_target << 4);
  670. }
  671. /*************************************************************
  672. * Hardware Cursor Routines *
  673. *************************************************************/
  674. /**
  675. * i810_enable_cursor - show or hide the hardware cursor
  676. * @mmio: address of register space
  677. * @mode: show (1) or hide (0)
  678. *
  679. * Description:
  680. * Shows or hides the hardware cursor
  681. */
  682. static void i810_enable_cursor(u8 __iomem *mmio, int mode)
  683. {
  684. u32 temp;
  685. temp = i810_readl(PIXCONF, mmio);
  686. temp = (mode == ON) ? temp | CURSOR_ENABLE_MASK :
  687. temp & ~CURSOR_ENABLE_MASK;
  688. i810_writel(PIXCONF, mmio, temp);
  689. }
  690. static void i810_reset_cursor_image(struct i810fb_par *par)
  691. {
  692. u8 __iomem *addr = par->cursor_heap.virtual;
  693. int i, j;
  694. for (i = 64; i--; ) {
  695. for (j = 0; j < 8; j++) {
  696. i810_writeb(j, addr, 0xff);
  697. i810_writeb(j+8, addr, 0x00);
  698. }
  699. addr +=16;
  700. }
  701. }
  702. static void i810_load_cursor_image(int width, int height, u8 *data,
  703. struct i810fb_par *par)
  704. {
  705. u8 __iomem *addr = par->cursor_heap.virtual;
  706. int i, j, w = width/8;
  707. int mod = width % 8, t_mask, d_mask;
  708. t_mask = 0xff >> mod;
  709. d_mask = ~(0xff >> mod);
  710. for (i = height; i--; ) {
  711. for (j = 0; j < w; j++) {
  712. i810_writeb(j+0, addr, 0x00);
  713. i810_writeb(j+8, addr, *data++);
  714. }
  715. if (mod) {
  716. i810_writeb(j+0, addr, t_mask);
  717. i810_writeb(j+8, addr, *data++ & d_mask);
  718. }
  719. addr += 16;
  720. }
  721. }
  722. static void i810_load_cursor_colors(int fg, int bg, struct fb_info *info)
  723. {
  724. struct i810fb_par *par = info->par;
  725. u8 __iomem *mmio = par->mmio_start_virtual;
  726. u8 red, green, blue, trans, temp;
  727. i810fb_getcolreg(bg, &red, &green, &blue, &trans, info);
  728. temp = i810_readb(PIXCONF1, mmio);
  729. i810_writeb(PIXCONF1, mmio, temp | EXTENDED_PALETTE);
  730. i810_write_dac(4, red, green, blue, mmio);
  731. i810_writeb(PIXCONF1, mmio, temp);
  732. i810fb_getcolreg(fg, &red, &green, &blue, &trans, info);
  733. temp = i810_readb(PIXCONF1, mmio);
  734. i810_writeb(PIXCONF1, mmio, temp | EXTENDED_PALETTE);
  735. i810_write_dac(5, red, green, blue, mmio);
  736. i810_writeb(PIXCONF1, mmio, temp);
  737. }
  738. /**
  739. * i810_init_cursor - initializes the cursor
  740. * @par: pointer to i810fb_par structure
  741. *
  742. * DESCRIPTION:
  743. * Initializes the cursor registers
  744. */
  745. static void i810_init_cursor(struct i810fb_par *par)
  746. {
  747. u8 __iomem *mmio = par->mmio_start_virtual;
  748. i810_enable_cursor(mmio, OFF);
  749. i810_writel(CURBASE, mmio, par->cursor_heap.physical);
  750. i810_writew(CURCNTR, mmio, COORD_ACTIVE | CURSOR_MODE_64_XOR);
  751. }
  752. /*********************************************************************
  753. * Framebuffer hook helpers *
  754. *********************************************************************/
  755. /**
  756. * i810_round_off - Round off values to capability of hardware
  757. * @var: pointer to fb_var_screeninfo structure
  758. *
  759. * DESCRIPTION:
  760. * @var contains user-defined information for the mode to be set.
  761. * This will try modify those values to ones nearest the
  762. * capability of the hardware
  763. */
  764. static void i810_round_off(struct fb_var_screeninfo *var)
  765. {
  766. u32 xres, yres, vxres, vyres;
  767. /*
  768. * Presently supports only these configurations
  769. */
  770. xres = var->xres;
  771. yres = var->yres;
  772. vxres = var->xres_virtual;
  773. vyres = var->yres_virtual;
  774. var->bits_per_pixel += 7;
  775. var->bits_per_pixel &= ~7;
  776. if (var->bits_per_pixel < 8)
  777. var->bits_per_pixel = 8;
  778. if (var->bits_per_pixel > 32)
  779. var->bits_per_pixel = 32;
  780. round_off_xres(&xres);
  781. if (xres < 40)
  782. xres = 40;
  783. if (xres > 2048)
  784. xres = 2048;
  785. xres = (xres + 7) & ~7;
  786. if (vxres < xres)
  787. vxres = xres;
  788. round_off_yres(&xres, &yres);
  789. if (yres < 1)
  790. yres = 1;
  791. if (yres >= 2048)
  792. yres = 2048;
  793. if (vyres < yres)
  794. vyres = yres;
  795. if (var->bits_per_pixel == 32)
  796. var->accel_flags = 0;
  797. /* round of horizontal timings to nearest 8 pixels */
  798. var->left_margin = (var->left_margin + 4) & ~7;
  799. var->right_margin = (var->right_margin + 4) & ~7;
  800. var->hsync_len = (var->hsync_len + 4) & ~7;
  801. if (var->vmode & FB_VMODE_INTERLACED) {
  802. if (!((yres + var->upper_margin + var->vsync_len +
  803. var->lower_margin) & 1))
  804. var->upper_margin++;
  805. }
  806. var->xres = xres;
  807. var->yres = yres;
  808. var->xres_virtual = vxres;
  809. var->yres_virtual = vyres;
  810. }
  811. /**
  812. * set_color_bitfields - sets rgba fields
  813. * @var: pointer to fb_var_screeninfo
  814. *
  815. * DESCRIPTION:
  816. * The length, offset and ordering for each color field
  817. * (red, green, blue) will be set as specified
  818. * by the hardware
  819. */
  820. static void set_color_bitfields(struct fb_var_screeninfo *var)
  821. {
  822. switch (var->bits_per_pixel) {
  823. case 8:
  824. var->red.offset = 0;
  825. var->red.length = 8;
  826. var->green.offset = 0;
  827. var->green.length = 8;
  828. var->blue.offset = 0;
  829. var->blue.length = 8;
  830. var->transp.offset = 0;
  831. var->transp.length = 0;
  832. break;
  833. case 16:
  834. var->green.length = (var->green.length == 5) ? 5 : 6;
  835. var->red.length = 5;
  836. var->blue.length = 5;
  837. var->transp.length = 6 - var->green.length;
  838. var->blue.offset = 0;
  839. var->green.offset = 5;
  840. var->red.offset = 5 + var->green.length;
  841. var->transp.offset = (5 + var->red.offset) & 15;
  842. break;
  843. case 24: /* RGB 888 */
  844. case 32: /* RGBA 8888 */
  845. var->red.offset = 16;
  846. var->red.length = 8;
  847. var->green.offset = 8;
  848. var->green.length = 8;
  849. var->blue.offset = 0;
  850. var->blue.length = 8;
  851. var->transp.length = var->bits_per_pixel - 24;
  852. var->transp.offset = (var->transp.length) ? 24 : 0;
  853. break;
  854. }
  855. var->red.msb_right = 0;
  856. var->green.msb_right = 0;
  857. var->blue.msb_right = 0;
  858. var->transp.msb_right = 0;
  859. }
  860. /**
  861. * i810_check_params - check if contents in var are valid
  862. * @var: pointer to fb_var_screeninfo
  863. * @info: pointer to fb_info
  864. *
  865. * DESCRIPTION:
  866. * This will check if the framebuffer size is sufficient
  867. * for the current mode and if the user's monitor has the
  868. * required specifications to display the current mode.
  869. */
  870. static int i810_check_params(struct fb_var_screeninfo *var,
  871. struct fb_info *info)
  872. {
  873. struct i810fb_par *par = info->par;
  874. int line_length, vidmem, mode_valid = 0, retval = 0;
  875. u32 vyres = var->yres_virtual, vxres = var->xres_virtual;
  876. /*
  877. * Memory limit
  878. */
  879. line_length = get_line_length(par, vxres, var->bits_per_pixel);
  880. vidmem = line_length*vyres;
  881. if (vidmem > par->fb.size) {
  882. vyres = par->fb.size/line_length;
  883. if (vyres < var->yres) {
  884. vyres = yres;
  885. vxres = par->fb.size/vyres;
  886. vxres /= var->bits_per_pixel >> 3;
  887. line_length = get_line_length(par, vxres,
  888. var->bits_per_pixel);
  889. vidmem = line_length * yres;
  890. if (vxres < var->xres) {
  891. printk("i810fb: required video memory, "
  892. "%d bytes, for %dx%d-%d (virtual) "
  893. "is out of range\n",
  894. vidmem, vxres, vyres,
  895. var->bits_per_pixel);
  896. return -ENOMEM;
  897. }
  898. }
  899. }
  900. var->xres_virtual = vxres;
  901. var->yres_virtual = vyres;
  902. /*
  903. * Monitor limit
  904. */
  905. switch (var->bits_per_pixel) {
  906. case 8:
  907. info->monspecs.dclkmax = 234000000;
  908. break;
  909. case 16:
  910. info->monspecs.dclkmax = 229000000;
  911. break;
  912. case 24:
  913. case 32:
  914. info->monspecs.dclkmax = 204000000;
  915. break;
  916. }
  917. info->monspecs.dclkmin = 15000000;
  918. if (!fb_validate_mode(var, info))
  919. mode_valid = 1;
  920. #ifdef CONFIG_FB_I810_I2C
  921. if (!mode_valid && info->monspecs.gtf &&
  922. !fb_get_mode(FB_MAXTIMINGS, 0, var, info))
  923. mode_valid = 1;
  924. if (!mode_valid && info->monspecs.modedb_len) {
  925. struct fb_videomode *mode;
  926. mode = fb_find_best_mode(var, &info->modelist);
  927. if (mode) {
  928. fb_videomode_to_var(var, mode);
  929. mode_valid = 1;
  930. }
  931. }
  932. #endif
  933. if (!mode_valid && info->monspecs.modedb_len == 0) {
  934. if (fb_get_mode(FB_MAXTIMINGS, 0, var, info)) {
  935. int default_sync = (info->monspecs.hfmin-HFMIN)
  936. |(info->monspecs.hfmax-HFMAX)
  937. |(info->monspecs.vfmin-VFMIN)
  938. |(info->monspecs.vfmax-VFMAX);
  939. printk("i810fb: invalid video mode%s\n",
  940. default_sync ? "" : ". Specifying "
  941. "vsyncN/hsyncN parameters may help");
  942. retval = -EINVAL;
  943. }
  944. }
  945. return retval;
  946. }
  947. /**
  948. * encode_fix - fill up fb_fix_screeninfo structure
  949. * @fix: pointer to fb_fix_screeninfo
  950. * @info: pointer to fb_info
  951. *
  952. * DESCRIPTION:
  953. * This will set up parameters that are unmodifiable by the user.
  954. */
  955. static int encode_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
  956. {
  957. struct i810fb_par *par = info->par;
  958. memset(fix, 0, sizeof(struct fb_fix_screeninfo));
  959. strcpy(fix->id, "I810");
  960. fix->smem_start = par->fb.physical;
  961. fix->smem_len = par->fb.size;
  962. fix->type = FB_TYPE_PACKED_PIXELS;
  963. fix->type_aux = 0;
  964. fix->xpanstep = 8;
  965. fix->ypanstep = 1;
  966. switch (info->var.bits_per_pixel) {
  967. case 8:
  968. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  969. break;
  970. case 16:
  971. case 24:
  972. case 32:
  973. if (info->var.nonstd)
  974. fix->visual = FB_VISUAL_DIRECTCOLOR;
  975. else
  976. fix->visual = FB_VISUAL_TRUECOLOR;
  977. break;
  978. default:
  979. return -EINVAL;
  980. }
  981. fix->ywrapstep = 0;
  982. fix->line_length = par->pitch;
  983. fix->mmio_start = par->mmio_start_phys;
  984. fix->mmio_len = MMIO_SIZE;
  985. fix->accel = FB_ACCEL_I810;
  986. return 0;
  987. }
  988. /**
  989. * decode_var - modify par according to contents of var
  990. * @var: pointer to fb_var_screeninfo
  991. * @par: pointer to i810fb_par
  992. *
  993. * DESCRIPTION:
  994. * Based on the contents of @var, @par will be dynamically filled up.
  995. * @par contains all information necessary to modify the hardware.
  996. */
  997. static void decode_var(const struct fb_var_screeninfo *var,
  998. struct i810fb_par *par)
  999. {
  1000. u32 xres, yres, vxres, vyres;
  1001. xres = var->xres;
  1002. yres = var->yres;
  1003. vxres = var->xres_virtual;
  1004. vyres = var->yres_virtual;
  1005. switch (var->bits_per_pixel) {
  1006. case 8:
  1007. par->pixconf = PIXCONF8;
  1008. par->bltcntl = 0;
  1009. par->depth = 1;
  1010. par->blit_bpp = BPP8;
  1011. break;
  1012. case 16:
  1013. if (var->green.length == 5)
  1014. par->pixconf = PIXCONF15;
  1015. else
  1016. par->pixconf = PIXCONF16;
  1017. par->bltcntl = 16;
  1018. par->depth = 2;
  1019. par->blit_bpp = BPP16;
  1020. break;
  1021. case 24:
  1022. par->pixconf = PIXCONF24;
  1023. par->bltcntl = 32;
  1024. par->depth = 3;
  1025. par->blit_bpp = BPP24;
  1026. break;
  1027. case 32:
  1028. par->pixconf = PIXCONF32;
  1029. par->bltcntl = 0;
  1030. par->depth = 4;
  1031. par->blit_bpp = 3 << 24;
  1032. break;
  1033. }
  1034. if (var->nonstd && var->bits_per_pixel != 8)
  1035. par->pixconf |= 1 << 27;
  1036. i810_calc_dclk(var->pixclock, &par->regs.M,
  1037. &par->regs.N, &par->regs.P);
  1038. i810fb_encode_registers(var, par, xres, yres);
  1039. par->watermark = i810_get_watermark(var, par);
  1040. par->pitch = get_line_length(par, vxres, var->bits_per_pixel);
  1041. }
  1042. /**
  1043. * i810fb_getcolreg - gets red, green and blue values of the hardware DAC
  1044. * @regno: DAC index
  1045. * @red: red
  1046. * @green: green
  1047. * @blue: blue
  1048. * @transp: transparency (alpha)
  1049. * @info: pointer to fb_info
  1050. *
  1051. * DESCRIPTION:
  1052. * Gets the red, green and blue values of the hardware DAC as pointed by @regno
  1053. * and writes them to @red, @green and @blue respectively
  1054. */
  1055. static int i810fb_getcolreg(u8 regno, u8 *red, u8 *green, u8 *blue,
  1056. u8 *transp, struct fb_info *info)
  1057. {
  1058. struct i810fb_par *par = info->par;
  1059. u8 __iomem *mmio = par->mmio_start_virtual;
  1060. u8 temp;
  1061. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  1062. if ((info->var.green.length == 5 && regno > 31) ||
  1063. (info->var.green.length == 6 && regno > 63))
  1064. return 1;
  1065. }
  1066. temp = i810_readb(PIXCONF1, mmio);
  1067. i810_writeb(PIXCONF1, mmio, temp & ~EXTENDED_PALETTE);
  1068. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
  1069. info->var.green.length == 5)
  1070. i810_read_dac(regno * 8, red, green, blue, mmio);
  1071. else if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
  1072. info->var.green.length == 6) {
  1073. u8 tmp;
  1074. i810_read_dac(regno * 8, red, &tmp, blue, mmio);
  1075. i810_read_dac(regno * 4, &tmp, green, &tmp, mmio);
  1076. }
  1077. else
  1078. i810_read_dac(regno, red, green, blue, mmio);
  1079. *transp = 0;
  1080. i810_writeb(PIXCONF1, mmio, temp);
  1081. return 0;
  1082. }
  1083. /******************************************************************
  1084. * Framebuffer device-specific hooks *
  1085. ******************************************************************/
  1086. static int i810fb_open(struct fb_info *info, int user)
  1087. {
  1088. struct i810fb_par *par = info->par;
  1089. u32 count = atomic_read(&par->use_count);
  1090. if (count == 0) {
  1091. memset(&par->state, 0, sizeof(struct vgastate));
  1092. par->state.flags = VGA_SAVE_CMAP;
  1093. par->state.vgabase = par->mmio_start_virtual;
  1094. save_vga(&par->state);
  1095. i810_save_vga_state(par);
  1096. }
  1097. atomic_inc(&par->use_count);
  1098. return 0;
  1099. }
  1100. static int i810fb_release(struct fb_info *info, int user)
  1101. {
  1102. struct i810fb_par *par = info->par;
  1103. u32 count;
  1104. count = atomic_read(&par->use_count);
  1105. if (count == 0)
  1106. return -EINVAL;
  1107. if (count == 1) {
  1108. i810_restore_vga_state(par);
  1109. restore_vga(&par->state);
  1110. }
  1111. atomic_dec(&par->use_count);
  1112. return 0;
  1113. }
  1114. static int i810fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  1115. unsigned blue, unsigned transp,
  1116. struct fb_info *info)
  1117. {
  1118. struct i810fb_par *par = info->par;
  1119. u8 __iomem *mmio = par->mmio_start_virtual;
  1120. u8 temp;
  1121. int i;
  1122. if (regno > 255) return 1;
  1123. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  1124. if ((info->var.green.length == 5 && regno > 31) ||
  1125. (info->var.green.length == 6 && regno > 63))
  1126. return 1;
  1127. }
  1128. if (info->var.grayscale)
  1129. red = green = blue = (19595 * red + 38470 * green +
  1130. 7471 * blue) >> 16;
  1131. temp = i810_readb(PIXCONF1, mmio);
  1132. i810_writeb(PIXCONF1, mmio, temp & ~EXTENDED_PALETTE);
  1133. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
  1134. info->var.green.length == 5) {
  1135. for (i = 0; i < 8; i++)
  1136. i810_write_dac((u8) (regno * 8) + i, (u8) red,
  1137. (u8) green, (u8) blue, mmio);
  1138. } else if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
  1139. info->var.green.length == 6) {
  1140. u8 r, g, b;
  1141. if (regno < 32) {
  1142. for (i = 0; i < 8; i++)
  1143. i810_write_dac((u8) (regno * 8) + i,
  1144. (u8) red, (u8) green,
  1145. (u8) blue, mmio);
  1146. }
  1147. i810_read_dac((u8) (regno*4), &r, &g, &b, mmio);
  1148. for (i = 0; i < 4; i++)
  1149. i810_write_dac((u8) (regno*4) + i, r, (u8) green,
  1150. b, mmio);
  1151. } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
  1152. i810_write_dac((u8) regno, (u8) red, (u8) green,
  1153. (u8) blue, mmio);
  1154. }
  1155. i810_writeb(PIXCONF1, mmio, temp);
  1156. if (regno < 16) {
  1157. switch (info->var.bits_per_pixel) {
  1158. case 16:
  1159. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  1160. if (info->var.green.length == 5)
  1161. ((u32 *)info->pseudo_palette)[regno] =
  1162. (regno << 10) | (regno << 5) |
  1163. regno;
  1164. else
  1165. ((u32 *)info->pseudo_palette)[regno] =
  1166. (regno << 11) | (regno << 5) |
  1167. regno;
  1168. } else {
  1169. if (info->var.green.length == 5) {
  1170. /* RGB 555 */
  1171. ((u32 *)info->pseudo_palette)[regno] =
  1172. ((red & 0xf800) >> 1) |
  1173. ((green & 0xf800) >> 6) |
  1174. ((blue & 0xf800) >> 11);
  1175. } else {
  1176. /* RGB 565 */
  1177. ((u32 *)info->pseudo_palette)[regno] =
  1178. (red & 0xf800) |
  1179. ((green & 0xf800) >> 5) |
  1180. ((blue & 0xf800) >> 11);
  1181. }
  1182. }
  1183. break;
  1184. case 24: /* RGB 888 */
  1185. case 32: /* RGBA 8888 */
  1186. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  1187. ((u32 *)info->pseudo_palette)[regno] =
  1188. (regno << 16) | (regno << 8) |
  1189. regno;
  1190. else
  1191. ((u32 *)info->pseudo_palette)[regno] =
  1192. ((red & 0xff00) << 8) |
  1193. (green & 0xff00) |
  1194. ((blue & 0xff00) >> 8);
  1195. break;
  1196. }
  1197. }
  1198. return 0;
  1199. }
  1200. static int i810fb_pan_display(struct fb_var_screeninfo *var,
  1201. struct fb_info *info)
  1202. {
  1203. struct i810fb_par *par = info->par;
  1204. u32 total;
  1205. total = var->xoffset * par->depth +
  1206. var->yoffset * info->fix.line_length;
  1207. i810fb_load_front(total, info);
  1208. return 0;
  1209. }
  1210. static int i810fb_blank (int blank_mode, struct fb_info *info)
  1211. {
  1212. struct i810fb_par *par = info->par;
  1213. u8 __iomem *mmio = par->mmio_start_virtual;
  1214. int mode = 0, pwr, scr_off = 0;
  1215. pwr = i810_readl(PWR_CLKC, mmio);
  1216. switch (blank_mode) {
  1217. case FB_BLANK_UNBLANK:
  1218. mode = POWERON;
  1219. pwr |= 1;
  1220. scr_off = ON;
  1221. break;
  1222. case FB_BLANK_NORMAL:
  1223. mode = POWERON;
  1224. pwr |= 1;
  1225. scr_off = OFF;
  1226. break;
  1227. case FB_BLANK_VSYNC_SUSPEND:
  1228. mode = STANDBY;
  1229. pwr |= 1;
  1230. scr_off = OFF;
  1231. break;
  1232. case FB_BLANK_HSYNC_SUSPEND:
  1233. mode = SUSPEND;
  1234. pwr |= 1;
  1235. scr_off = OFF;
  1236. break;
  1237. case FB_BLANK_POWERDOWN:
  1238. mode = POWERDOWN;
  1239. pwr &= ~1;
  1240. scr_off = OFF;
  1241. break;
  1242. default:
  1243. return -EINVAL;
  1244. }
  1245. i810_screen_off(mmio, scr_off);
  1246. i810_writel(HVSYNC, mmio, mode);
  1247. i810_writel(PWR_CLKC, mmio, pwr);
  1248. return 0;
  1249. }
  1250. static int i810fb_set_par(struct fb_info *info)
  1251. {
  1252. struct i810fb_par *par = info->par;
  1253. decode_var(&info->var, par);
  1254. i810_load_regs(par);
  1255. i810_init_cursor(par);
  1256. encode_fix(&info->fix, info);
  1257. if (info->var.accel_flags && !(par->dev_flags & LOCKUP)) {
  1258. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
  1259. FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
  1260. FBINFO_HWACCEL_IMAGEBLIT;
  1261. info->pixmap.scan_align = 2;
  1262. } else {
  1263. info->pixmap.scan_align = 1;
  1264. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1265. }
  1266. return 0;
  1267. }
  1268. static int i810fb_check_var(struct fb_var_screeninfo *var,
  1269. struct fb_info *info)
  1270. {
  1271. int err;
  1272. if (IS_DVT) {
  1273. var->vmode &= ~FB_VMODE_MASK;
  1274. var->vmode |= FB_VMODE_NONINTERLACED;
  1275. }
  1276. if (var->vmode & FB_VMODE_DOUBLE) {
  1277. var->vmode &= ~FB_VMODE_MASK;
  1278. var->vmode |= FB_VMODE_NONINTERLACED;
  1279. }
  1280. i810_round_off(var);
  1281. if ((err = i810_check_params(var, info)))
  1282. return err;
  1283. i810fb_fill_var_timings(var);
  1284. set_color_bitfields(var);
  1285. return 0;
  1286. }
  1287. static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  1288. {
  1289. struct i810fb_par *par = info->par;
  1290. u8 __iomem *mmio = par->mmio_start_virtual;
  1291. if (!par->dev_flags & LOCKUP)
  1292. return -ENXIO;
  1293. if (cursor->image.width > 64 || cursor->image.height > 64)
  1294. return -ENXIO;
  1295. if ((i810_readl(CURBASE, mmio) & 0xf) != par->cursor_heap.physical) {
  1296. i810_init_cursor(par);
  1297. cursor->set |= FB_CUR_SETALL;
  1298. }
  1299. i810_enable_cursor(mmio, OFF);
  1300. if (cursor->set & FB_CUR_SETPOS) {
  1301. u32 tmp;
  1302. tmp = (cursor->image.dx - info->var.xoffset) & 0xffff;
  1303. tmp |= (cursor->image.dy - info->var.yoffset) << 16;
  1304. i810_writel(CURPOS, mmio, tmp);
  1305. }
  1306. if (cursor->set & FB_CUR_SETSIZE)
  1307. i810_reset_cursor_image(par);
  1308. if (cursor->set & FB_CUR_SETCMAP)
  1309. i810_load_cursor_colors(cursor->image.fg_color,
  1310. cursor->image.bg_color,
  1311. info);
  1312. if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
  1313. int size = ((cursor->image.width + 7) >> 3) *
  1314. cursor->image.height;
  1315. int i;
  1316. u8 *data = kmalloc(64 * 8, GFP_ATOMIC);
  1317. if (data == NULL)
  1318. return -ENOMEM;
  1319. switch (cursor->rop) {
  1320. case ROP_XOR:
  1321. for (i = 0; i < size; i++)
  1322. data[i] = cursor->image.data[i] ^ cursor->mask[i];
  1323. break;
  1324. case ROP_COPY:
  1325. default:
  1326. for (i = 0; i < size; i++)
  1327. data[i] = cursor->image.data[i] & cursor->mask[i];
  1328. break;
  1329. }
  1330. i810_load_cursor_image(cursor->image.width,
  1331. cursor->image.height, data,
  1332. par);
  1333. kfree(data);
  1334. }
  1335. if (cursor->enable)
  1336. i810_enable_cursor(mmio, ON);
  1337. return 0;
  1338. }
  1339. static struct fb_ops i810fb_ops __devinitdata = {
  1340. .owner = THIS_MODULE,
  1341. .fb_open = i810fb_open,
  1342. .fb_release = i810fb_release,
  1343. .fb_check_var = i810fb_check_var,
  1344. .fb_set_par = i810fb_set_par,
  1345. .fb_setcolreg = i810fb_setcolreg,
  1346. .fb_blank = i810fb_blank,
  1347. .fb_pan_display = i810fb_pan_display,
  1348. .fb_fillrect = i810fb_fillrect,
  1349. .fb_copyarea = i810fb_copyarea,
  1350. .fb_imageblit = i810fb_imageblit,
  1351. .fb_cursor = i810fb_cursor,
  1352. .fb_sync = i810fb_sync,
  1353. };
  1354. /***********************************************************************
  1355. * Power Management *
  1356. ***********************************************************************/
  1357. static int i810fb_suspend(struct pci_dev *dev, pm_message_t mesg)
  1358. {
  1359. struct fb_info *info = pci_get_drvdata(dev);
  1360. struct i810fb_par *par = info->par;
  1361. par->cur_state = mesg.event;
  1362. switch (mesg.event) {
  1363. case PM_EVENT_FREEZE:
  1364. case PM_EVENT_PRETHAW:
  1365. dev->dev.power.power_state = mesg;
  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, mesg));
  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. framebuffer_release(info);
  1823. }
  1824. static void __exit i810fb_remove_pci(struct pci_dev *dev)
  1825. {
  1826. struct fb_info *info = pci_get_drvdata(dev);
  1827. struct i810fb_par *par = info->par;
  1828. unregister_framebuffer(info);
  1829. i810fb_release_resource(info, par);
  1830. pci_set_drvdata(dev, NULL);
  1831. printk("cleanup_module: unloaded i810 framebuffer device\n");
  1832. }
  1833. #ifndef MODULE
  1834. static int __devinit i810fb_init(void)
  1835. {
  1836. char *option = NULL;
  1837. if (fb_get_options("i810fb", &option))
  1838. return -ENODEV;
  1839. i810fb_setup(option);
  1840. return pci_register_driver(&i810fb_driver);
  1841. }
  1842. #endif
  1843. /*********************************************************************
  1844. * Modularization *
  1845. *********************************************************************/
  1846. #ifdef MODULE
  1847. static int __devinit i810fb_init(void)
  1848. {
  1849. hsync1 *= 1000;
  1850. hsync2 *= 1000;
  1851. return pci_register_driver(&i810fb_driver);
  1852. }
  1853. module_param(vram, int, 0);
  1854. MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB"
  1855. " (default=4)");
  1856. module_param(voffset, int, 0);
  1857. MODULE_PARM_DESC(voffset, "at what offset to place start of framebuffer "
  1858. "memory (0 to maximum aperture size), in MiB (default = 48)");
  1859. module_param(bpp, int, 0);
  1860. MODULE_PARM_DESC(bpp, "Color depth for display in bits per pixel"
  1861. " (default = 8)");
  1862. module_param(xres, int, 0);
  1863. MODULE_PARM_DESC(xres, "Horizontal resolution in pixels (default = 640)");
  1864. module_param(yres, int, 0);
  1865. MODULE_PARM_DESC(yres, "Vertical resolution in scanlines (default = 480)");
  1866. module_param(vyres,int, 0);
  1867. MODULE_PARM_DESC(vyres, "Virtual vertical resolution in scanlines"
  1868. " (default = 480)");
  1869. module_param(hsync1, int, 0);
  1870. MODULE_PARM_DESC(hsync1, "Minimum horizontal frequency of monitor in KHz"
  1871. " (default = 29)");
  1872. module_param(hsync2, int, 0);
  1873. MODULE_PARM_DESC(hsync2, "Maximum horizontal frequency of monitor in KHz"
  1874. " (default = 30)");
  1875. module_param(vsync1, int, 0);
  1876. MODULE_PARM_DESC(vsync1, "Minimum vertical frequency of monitor in Hz"
  1877. " (default = 50)");
  1878. module_param(vsync2, int, 0);
  1879. MODULE_PARM_DESC(vsync2, "Maximum vertical frequency of monitor in Hz"
  1880. " (default = 60)");
  1881. module_param(accel, bool, 0);
  1882. MODULE_PARM_DESC(accel, "Use Acceleration (BLIT) engine (default = 0)");
  1883. module_param(mtrr, bool, 0);
  1884. MODULE_PARM_DESC(mtrr, "Use MTRR (default = 0)");
  1885. module_param(extvga, bool, 0);
  1886. MODULE_PARM_DESC(extvga, "Enable external VGA connector (default = 0)");
  1887. module_param(sync, bool, 0);
  1888. MODULE_PARM_DESC(sync, "wait for accel engine to finish drawing"
  1889. " (default = 0)");
  1890. module_param(dcolor, bool, 0);
  1891. MODULE_PARM_DESC(dcolor, "use DirectColor visuals"
  1892. " (default = 0 = TrueColor)");
  1893. module_param(ddc3, bool, 0);
  1894. MODULE_PARM_DESC(ddc3, "Probe DDC bus 3 (default = 0 = no)");
  1895. module_param(mode_option, charp, 0);
  1896. MODULE_PARM_DESC(mode_option, "Specify initial video mode");
  1897. MODULE_AUTHOR("Tony A. Daplas");
  1898. MODULE_DESCRIPTION("Framebuffer device for the Intel 810/815 and"
  1899. " compatible cards");
  1900. MODULE_LICENSE("GPL");
  1901. static void __exit i810fb_exit(void)
  1902. {
  1903. pci_unregister_driver(&i810fb_driver);
  1904. }
  1905. module_exit(i810fb_exit);
  1906. #endif /* MODULE */
  1907. module_init(i810fb_init);