i810_main.c 56 KB

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