i810_main.c 58 KB

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