i810_main.c 59 KB

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