i810_main.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209
  1. /*-*- linux-c -*-
  2. * linux/drivers/video/i810_main.c -- Intel 810 frame buffer device
  3. *
  4. * Copyright (C) 2001 Antonino Daplas<adaplas@pol.net>
  5. * All Rights Reserved
  6. *
  7. * Contributors:
  8. * Michael Vogt <mvogt@acm.org> - added support for Intel 815 chipsets
  9. * and enabling the power-on state of
  10. * external VGA connectors for
  11. * secondary displays
  12. *
  13. * Fredrik Andersson <krueger@shell.linux.se> - alpha testing of
  14. * the VESA GTF
  15. *
  16. * Brad Corrion <bcorrion@web-co.com> - alpha testing of customized
  17. * timings support
  18. *
  19. * The code framework is a modification of vfb.c by Geert Uytterhoeven.
  20. * DotClock and PLL calculations are partly based on i810_driver.c
  21. * in xfree86 v4.0.3 by Precision Insight.
  22. * Watermark calculation and tables are based on i810_wmark.c
  23. * in xfre86 v4.0.3 by Precision Insight. Slight modifications
  24. * only to allow for integer operations instead of floating point.
  25. *
  26. * This file is subject to the terms and conditions of the GNU General Public
  27. * License. See the file COPYING in the main directory of this archive for
  28. * more details.
  29. */
  30. #include <linux/module.h>
  31. #include <linux/config.h>
  32. #include <linux/kernel.h>
  33. #include <linux/errno.h>
  34. #include <linux/string.h>
  35. #include <linux/mm.h>
  36. #include <linux/tty.h>
  37. #include <linux/slab.h>
  38. #include <linux/fb.h>
  39. #include <linux/init.h>
  40. #include <linux/pci.h>
  41. #include <linux/pci_ids.h>
  42. #include <linux/resource.h>
  43. #include <linux/unistd.h>
  44. #include <linux/console.h>
  45. #include <asm/io.h>
  46. #include <asm/div64.h>
  47. #include <asm/page.h>
  48. #include "i810_regs.h"
  49. #include "i810.h"
  50. #include "i810_main.h"
  51. /*
  52. * voffset - framebuffer offset in MiB from aperture start address. In order for
  53. * the driver to work with X, we must try to use memory holes left untouched by X. The
  54. * following table lists where X's different surfaces start at.
  55. *
  56. * ---------------------------------------------
  57. * : : 64 MiB : 32 MiB :
  58. * ----------------------------------------------
  59. * : FrontBuffer : 0 : 0 :
  60. * : DepthBuffer : 48 : 16 :
  61. * : BackBuffer : 56 : 24 :
  62. * ----------------------------------------------
  63. *
  64. * So for chipsets with 64 MiB Aperture sizes, 32 MiB for v_offset is okay, allowing up to
  65. * 15 + 1 MiB of Framebuffer memory. For 32 MiB Aperture sizes, a v_offset of 8 MiB should
  66. * work, allowing 7 + 1 MiB of Framebuffer memory.
  67. * Note, the size of the hole may change depending on how much memory you allocate to X,
  68. * and how the memory is split up between these surfaces.
  69. *
  70. * Note: Anytime the DepthBuffer or FrontBuffer is overlapped, X would still run but with
  71. * DRI disabled. But if the Frontbuffer is overlapped, X will fail to load.
  72. *
  73. * Experiment with v_offset to find out which works best for you.
  74. */
  75. static u32 v_offset_default __initdata; /* For 32 MiB Aper size, 8 should be the default */
  76. static u32 voffset __initdata = 0;
  77. static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor);
  78. static int __devinit i810fb_init_pci (struct pci_dev *dev,
  79. const struct pci_device_id *entry);
  80. static void __exit i810fb_remove_pci(struct pci_dev *dev);
  81. static int i810fb_resume(struct pci_dev *dev);
  82. static int i810fb_suspend(struct pci_dev *dev, pm_message_t state);
  83. /* Chipset Specific Functions */
  84. static int i810fb_set_par (struct fb_info *info);
  85. static int i810fb_getcolreg (u8 regno, u8 *red, u8 *green, u8 *blue,
  86. u8 *transp, struct fb_info *info);
  87. static int i810fb_setcolreg (unsigned regno, unsigned red, unsigned green, unsigned blue,
  88. unsigned transp, struct fb_info *info);
  89. static int i810fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
  90. static int i810fb_blank (int blank_mode, struct fb_info *info);
  91. /* Initialization */
  92. static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
  93. /* PCI */
  94. static const char *i810_pci_list[] __devinitdata = {
  95. "Intel(R) 810 Framebuffer Device" ,
  96. "Intel(R) 810-DC100 Framebuffer Device" ,
  97. "Intel(R) 810E Framebuffer Device" ,
  98. "Intel(R) 815 (Internal Graphics 100Mhz FSB) Framebuffer Device" ,
  99. "Intel(R) 815 (Internal Graphics only) Framebuffer Device" ,
  100. "Intel(R) 815 (Internal Graphics with AGP) Framebuffer Device"
  101. };
  102. static struct pci_device_id i810fb_pci_tbl[] = {
  103. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG1,
  104. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  105. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3,
  106. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
  107. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810E_IG,
  108. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
  109. /* mvo: added i815 PCI-ID */
  110. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_100,
  111. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
  112. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_NOAGP,
  113. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
  114. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
  115. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
  116. { 0 },
  117. };
  118. static struct pci_driver i810fb_driver = {
  119. .name = "i810fb",
  120. .id_table = i810fb_pci_tbl,
  121. .probe = i810fb_init_pci,
  122. .remove = __exit_p(i810fb_remove_pci),
  123. .suspend = i810fb_suspend,
  124. .resume = i810fb_resume,
  125. };
  126. static char *mode_option __devinitdata = NULL;
  127. static int vram __devinitdata = 4;
  128. static int bpp __devinitdata = 8;
  129. static int mtrr __devinitdata;
  130. static int accel __devinitdata;
  131. static int hsync1 __devinitdata;
  132. static int hsync2 __devinitdata;
  133. static int vsync1 __devinitdata;
  134. static int vsync2 __devinitdata;
  135. static int xres __devinitdata;
  136. static int yres __devinitdata;
  137. static int vyres __devinitdata;
  138. static int sync __devinitdata;
  139. static int extvga __devinitdata;
  140. static int dcolor __devinitdata;
  141. /*------------------------------------------------------------*/
  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 = 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 * 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. 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. fix->smem_start = par->fb.physical;
  962. fix->smem_len = par->fb.size;
  963. fix->type = FB_TYPE_PACKED_PIXELS;
  964. fix->type_aux = 0;
  965. fix->xpanstep = 8;
  966. fix->ypanstep = 1;
  967. switch (info->var.bits_per_pixel) {
  968. case 8:
  969. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  970. break;
  971. case 16:
  972. case 24:
  973. case 32:
  974. if (info->var.nonstd)
  975. fix->visual = FB_VISUAL_DIRECTCOLOR;
  976. else
  977. fix->visual = FB_VISUAL_TRUECOLOR;
  978. break;
  979. default:
  980. return -EINVAL;
  981. }
  982. fix->ywrapstep = 0;
  983. fix->line_length = par->pitch;
  984. fix->mmio_start = par->mmio_start_phys;
  985. fix->mmio_len = MMIO_SIZE;
  986. fix->accel = FB_ACCEL_I810;
  987. return 0;
  988. }
  989. /**
  990. * decode_var - modify par according to contents of var
  991. * @var: pointer to fb_var_screeninfo
  992. * @par: pointer to i810fb_par
  993. *
  994. * DESCRIPTION:
  995. * Based on the contents of @var, @par will be dynamically filled up.
  996. * @par contains all information necessary to modify the hardware.
  997. */
  998. static void decode_var(const struct fb_var_screeninfo *var,
  999. struct i810fb_par *par)
  1000. {
  1001. u32 xres, yres, vxres, vyres;
  1002. xres = var->xres;
  1003. yres = var->yres;
  1004. vxres = var->xres_virtual;
  1005. vyres = var->yres_virtual;
  1006. switch (var->bits_per_pixel) {
  1007. case 8:
  1008. par->pixconf = PIXCONF8;
  1009. par->bltcntl = 0;
  1010. par->depth = 1;
  1011. par->blit_bpp = BPP8;
  1012. break;
  1013. case 16:
  1014. if (var->green.length == 5)
  1015. par->pixconf = PIXCONF15;
  1016. else
  1017. par->pixconf = PIXCONF16;
  1018. par->bltcntl = 16;
  1019. par->depth = 2;
  1020. par->blit_bpp = BPP16;
  1021. break;
  1022. case 24:
  1023. par->pixconf = PIXCONF24;
  1024. par->bltcntl = 32;
  1025. par->depth = 3;
  1026. par->blit_bpp = BPP24;
  1027. break;
  1028. case 32:
  1029. par->pixconf = PIXCONF32;
  1030. par->bltcntl = 0;
  1031. par->depth = 4;
  1032. par->blit_bpp = 3 << 24;
  1033. break;
  1034. }
  1035. if (var->nonstd && var->bits_per_pixel != 8)
  1036. par->pixconf |= 1 << 27;
  1037. i810_calc_dclk(var->pixclock, &par->regs.M,
  1038. &par->regs.N, &par->regs.P);
  1039. i810fb_encode_registers(var, par, xres, yres);
  1040. par->watermark = i810_get_watermark(var, par);
  1041. par->pitch = get_line_length(par, vxres, var->bits_per_pixel);
  1042. }
  1043. /**
  1044. * i810fb_getcolreg - gets red, green and blue values of the hardware DAC
  1045. * @regno: DAC index
  1046. * @red: red
  1047. * @green: green
  1048. * @blue: blue
  1049. * @transp: transparency (alpha)
  1050. * @info: pointer to fb_info
  1051. *
  1052. * DESCRIPTION:
  1053. * Gets the red, green and blue values of the hardware DAC as pointed by @regno
  1054. * and writes them to @red, @green and @blue respectively
  1055. */
  1056. static int i810fb_getcolreg(u8 regno, u8 *red, u8 *green, u8 *blue,
  1057. u8 *transp, struct fb_info *info)
  1058. {
  1059. struct i810fb_par *par = info->par;
  1060. u8 __iomem *mmio = par->mmio_start_virtual;
  1061. u8 temp;
  1062. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  1063. if ((info->var.green.length == 5 && regno > 31) ||
  1064. (info->var.green.length == 6 && regno > 63))
  1065. return 1;
  1066. }
  1067. temp = i810_readb(PIXCONF1, mmio);
  1068. i810_writeb(PIXCONF1, mmio, temp & ~EXTENDED_PALETTE);
  1069. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
  1070. info->var.green.length == 5)
  1071. i810_read_dac(regno * 8, red, green, blue, mmio);
  1072. else if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
  1073. info->var.green.length == 6) {
  1074. u8 tmp;
  1075. i810_read_dac(regno * 8, red, &tmp, blue, mmio);
  1076. i810_read_dac(regno * 4, &tmp, green, &tmp, mmio);
  1077. }
  1078. else
  1079. i810_read_dac(regno, red, green, blue, mmio);
  1080. *transp = 0;
  1081. i810_writeb(PIXCONF1, mmio, temp);
  1082. return 0;
  1083. }
  1084. /******************************************************************
  1085. * Framebuffer device-specific hooks *
  1086. ******************************************************************/
  1087. static int i810fb_open(struct fb_info *info, int user)
  1088. {
  1089. struct i810fb_par *par = info->par;
  1090. u32 count = atomic_read(&par->use_count);
  1091. if (count == 0) {
  1092. memset(&par->state, 0, sizeof(struct vgastate));
  1093. par->state.flags = VGA_SAVE_CMAP;
  1094. par->state.vgabase = par->mmio_start_virtual;
  1095. save_vga(&par->state);
  1096. i810_save_vga_state(par);
  1097. }
  1098. atomic_inc(&par->use_count);
  1099. return 0;
  1100. }
  1101. static int i810fb_release(struct fb_info *info, int user)
  1102. {
  1103. struct i810fb_par *par = info->par;
  1104. u32 count;
  1105. count = atomic_read(&par->use_count);
  1106. if (count == 0)
  1107. return -EINVAL;
  1108. if (count == 1) {
  1109. i810_restore_vga_state(par);
  1110. restore_vga(&par->state);
  1111. }
  1112. atomic_dec(&par->use_count);
  1113. return 0;
  1114. }
  1115. static int i810fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  1116. unsigned blue, unsigned transp,
  1117. struct fb_info *info)
  1118. {
  1119. struct i810fb_par *par = info->par;
  1120. u8 __iomem *mmio = par->mmio_start_virtual;
  1121. u8 temp;
  1122. int i;
  1123. if (regno > 255) return 1;
  1124. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  1125. if ((info->var.green.length == 5 && regno > 31) ||
  1126. (info->var.green.length == 6 && regno > 63))
  1127. return 1;
  1128. }
  1129. if (info->var.grayscale)
  1130. red = green = blue = (19595 * red + 38470 * green +
  1131. 7471 * blue) >> 16;
  1132. temp = i810_readb(PIXCONF1, mmio);
  1133. i810_writeb(PIXCONF1, mmio, temp & ~EXTENDED_PALETTE);
  1134. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
  1135. info->var.green.length == 5) {
  1136. for (i = 0; i < 8; i++)
  1137. i810_write_dac((u8) (regno * 8) + i, (u8) red,
  1138. (u8) green, (u8) blue, mmio);
  1139. } else if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
  1140. info->var.green.length == 6) {
  1141. u8 r, g, b;
  1142. if (regno < 32) {
  1143. for (i = 0; i < 8; i++)
  1144. i810_write_dac((u8) (regno * 8) + i,
  1145. (u8) red, (u8) green,
  1146. (u8) blue, mmio);
  1147. }
  1148. i810_read_dac((u8) (regno*4), &r, &g, &b, mmio);
  1149. for (i = 0; i < 4; i++)
  1150. i810_write_dac((u8) (regno*4) + i, r, (u8) green,
  1151. b, mmio);
  1152. } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
  1153. i810_write_dac((u8) regno, (u8) red, (u8) green,
  1154. (u8) blue, mmio);
  1155. }
  1156. i810_writeb(PIXCONF1, mmio, temp);
  1157. if (regno < 16) {
  1158. switch (info->var.bits_per_pixel) {
  1159. case 16:
  1160. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  1161. if (info->var.green.length == 5)
  1162. ((u32 *)info->pseudo_palette)[regno] =
  1163. (regno << 10) | (regno << 5) |
  1164. regno;
  1165. else
  1166. ((u32 *)info->pseudo_palette)[regno] =
  1167. (regno << 11) | (regno << 5) |
  1168. regno;
  1169. } else {
  1170. if (info->var.green.length == 5) {
  1171. /* RGB 555 */
  1172. ((u32 *)info->pseudo_palette)[regno] =
  1173. ((red & 0xf800) >> 1) |
  1174. ((green & 0xf800) >> 6) |
  1175. ((blue & 0xf800) >> 11);
  1176. } else {
  1177. /* RGB 565 */
  1178. ((u32 *)info->pseudo_palette)[regno] =
  1179. (red & 0xf800) |
  1180. ((green & 0xf800) >> 5) |
  1181. ((blue & 0xf800) >> 11);
  1182. }
  1183. }
  1184. break;
  1185. case 24: /* RGB 888 */
  1186. case 32: /* RGBA 8888 */
  1187. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  1188. ((u32 *)info->pseudo_palette)[regno] =
  1189. (regno << 16) | (regno << 8) |
  1190. regno;
  1191. else
  1192. ((u32 *)info->pseudo_palette)[regno] =
  1193. ((red & 0xff00) << 8) |
  1194. (green & 0xff00) |
  1195. ((blue & 0xff00) >> 8);
  1196. break;
  1197. }
  1198. }
  1199. return 0;
  1200. }
  1201. static int i810fb_pan_display(struct fb_var_screeninfo *var,
  1202. struct fb_info *info)
  1203. {
  1204. struct i810fb_par *par = info->par;
  1205. u32 total;
  1206. total = var->xoffset * par->depth +
  1207. var->yoffset * info->fix.line_length;
  1208. i810fb_load_front(total, info);
  1209. return 0;
  1210. }
  1211. static int i810fb_blank (int blank_mode, struct fb_info *info)
  1212. {
  1213. struct i810fb_par *par = info->par;
  1214. u8 __iomem *mmio = par->mmio_start_virtual;
  1215. int mode = 0, pwr, scr_off = 0;
  1216. pwr = i810_readl(PWR_CLKC, mmio);
  1217. switch (blank_mode) {
  1218. case FB_BLANK_UNBLANK:
  1219. mode = POWERON;
  1220. pwr |= 1;
  1221. scr_off = ON;
  1222. break;
  1223. case FB_BLANK_NORMAL:
  1224. mode = POWERON;
  1225. pwr |= 1;
  1226. scr_off = OFF;
  1227. break;
  1228. case FB_BLANK_VSYNC_SUSPEND:
  1229. mode = STANDBY;
  1230. pwr |= 1;
  1231. scr_off = OFF;
  1232. break;
  1233. case FB_BLANK_HSYNC_SUSPEND:
  1234. mode = SUSPEND;
  1235. pwr |= 1;
  1236. scr_off = OFF;
  1237. break;
  1238. case FB_BLANK_POWERDOWN:
  1239. mode = POWERDOWN;
  1240. pwr &= ~1;
  1241. scr_off = OFF;
  1242. break;
  1243. default:
  1244. return -EINVAL;
  1245. }
  1246. i810_screen_off(mmio, scr_off);
  1247. i810_writel(HVSYNC, mmio, mode);
  1248. i810_writel(PWR_CLKC, mmio, pwr);
  1249. return 0;
  1250. }
  1251. static int i810fb_set_par(struct fb_info *info)
  1252. {
  1253. struct i810fb_par *par = info->par;
  1254. decode_var(&info->var, par);
  1255. i810_load_regs(par);
  1256. i810_init_cursor(par);
  1257. encode_fix(&info->fix, info);
  1258. if (info->var.accel_flags && !(par->dev_flags & LOCKUP)) {
  1259. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
  1260. FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
  1261. FBINFO_HWACCEL_IMAGEBLIT;
  1262. info->pixmap.scan_align = 2;
  1263. } else {
  1264. info->pixmap.scan_align = 1;
  1265. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1266. }
  1267. return 0;
  1268. }
  1269. static int i810fb_check_var(struct fb_var_screeninfo *var,
  1270. struct fb_info *info)
  1271. {
  1272. int err;
  1273. if (IS_DVT) {
  1274. var->vmode &= ~FB_VMODE_MASK;
  1275. var->vmode |= FB_VMODE_NONINTERLACED;
  1276. }
  1277. if (var->vmode & FB_VMODE_DOUBLE) {
  1278. var->vmode &= ~FB_VMODE_MASK;
  1279. var->vmode |= FB_VMODE_NONINTERLACED;
  1280. }
  1281. i810_round_off(var);
  1282. if ((err = i810_check_params(var, info)))
  1283. return err;
  1284. i810fb_fill_var_timings(var);
  1285. set_color_bitfields(var);
  1286. return 0;
  1287. }
  1288. static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  1289. {
  1290. struct i810fb_par *par = info->par;
  1291. u8 __iomem *mmio = par->mmio_start_virtual;
  1292. if (!par->dev_flags & LOCKUP)
  1293. return -ENXIO;
  1294. if (cursor->image.width > 64 || cursor->image.height > 64)
  1295. return -ENXIO;
  1296. if ((i810_readl(CURBASE, mmio) & 0xf) != par->cursor_heap.physical) {
  1297. i810_init_cursor(par);
  1298. cursor->set |= FB_CUR_SETALL;
  1299. }
  1300. i810_enable_cursor(mmio, OFF);
  1301. if (cursor->set & FB_CUR_SETPOS) {
  1302. u32 tmp;
  1303. tmp = (cursor->image.dx - info->var.xoffset) & 0xffff;
  1304. tmp |= (cursor->image.dy - info->var.yoffset) << 16;
  1305. i810_writel(CURPOS, mmio, tmp);
  1306. }
  1307. if (cursor->set & FB_CUR_SETSIZE)
  1308. i810_reset_cursor_image(par);
  1309. if (cursor->set & FB_CUR_SETCMAP)
  1310. i810_load_cursor_colors(cursor->image.fg_color,
  1311. cursor->image.bg_color,
  1312. info);
  1313. if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
  1314. int size = ((cursor->image.width + 7) >> 3) *
  1315. cursor->image.height;
  1316. int i;
  1317. u8 *data = kmalloc(64 * 8, GFP_KERNEL);
  1318. if (data == NULL)
  1319. return -ENOMEM;
  1320. switch (cursor->rop) {
  1321. case ROP_XOR:
  1322. for (i = 0; i < size; i++)
  1323. data[i] = cursor->image.data[i] ^ cursor->mask[i];
  1324. break;
  1325. case ROP_COPY:
  1326. default:
  1327. for (i = 0; i < size; i++)
  1328. data[i] = cursor->image.data[i] & cursor->mask[i];
  1329. break;
  1330. }
  1331. i810_load_cursor_image(cursor->image.width,
  1332. cursor->image.height, data,
  1333. par);
  1334. kfree(data);
  1335. }
  1336. if (cursor->enable)
  1337. i810_enable_cursor(mmio, ON);
  1338. return 0;
  1339. }
  1340. static struct fb_ops i810fb_ops __devinitdata = {
  1341. .owner = THIS_MODULE,
  1342. .fb_open = i810fb_open,
  1343. .fb_release = i810fb_release,
  1344. .fb_check_var = i810fb_check_var,
  1345. .fb_set_par = i810fb_set_par,
  1346. .fb_setcolreg = i810fb_setcolreg,
  1347. .fb_blank = i810fb_blank,
  1348. .fb_pan_display = i810fb_pan_display,
  1349. .fb_fillrect = i810fb_fillrect,
  1350. .fb_copyarea = i810fb_copyarea,
  1351. .fb_imageblit = i810fb_imageblit,
  1352. .fb_cursor = i810fb_cursor,
  1353. .fb_sync = i810fb_sync,
  1354. };
  1355. /***********************************************************************
  1356. * Power Management *
  1357. ***********************************************************************/
  1358. static int i810fb_suspend(struct pci_dev *dev, pm_message_t state)
  1359. {
  1360. struct fb_info *info = pci_get_drvdata(dev);
  1361. struct i810fb_par *par = info->par;
  1362. par->cur_state = state.event;
  1363. if (state.event == PM_EVENT_FREEZE) {
  1364. dev->dev.power.power_state = state;
  1365. return 0;
  1366. }
  1367. acquire_console_sem();
  1368. fb_set_suspend(info, 1);
  1369. if (info->fbops->fb_sync)
  1370. info->fbops->fb_sync(info);
  1371. i810fb_blank(FB_BLANK_POWERDOWN, info);
  1372. agp_unbind_memory(par->i810_gtt.i810_fb_memory);
  1373. agp_unbind_memory(par->i810_gtt.i810_cursor_memory);
  1374. pci_save_state(dev);
  1375. pci_disable_device(dev);
  1376. pci_set_power_state(dev, pci_choose_state(dev, state));
  1377. release_console_sem();
  1378. return 0;
  1379. }
  1380. static int i810fb_resume(struct pci_dev *dev)
  1381. {
  1382. struct fb_info *info = pci_get_drvdata(dev);
  1383. struct i810fb_par *par = info->par;
  1384. int cur_state = par->cur_state;
  1385. par->cur_state = PM_EVENT_ON;
  1386. if (cur_state == PM_EVENT_FREEZE) {
  1387. pci_set_power_state(dev, PCI_D0);
  1388. return 0;
  1389. }
  1390. acquire_console_sem();
  1391. pci_set_power_state(dev, PCI_D0);
  1392. pci_restore_state(dev);
  1393. pci_enable_device(dev);
  1394. pci_set_master(dev);
  1395. agp_bind_memory(par->i810_gtt.i810_fb_memory,
  1396. par->fb.offset);
  1397. agp_bind_memory(par->i810_gtt.i810_cursor_memory,
  1398. par->cursor_heap.offset);
  1399. i810fb_set_par(info);
  1400. fb_set_suspend (info, 0);
  1401. info->fbops->fb_blank(VESA_NO_BLANKING, info);
  1402. release_console_sem();
  1403. return 0;
  1404. }
  1405. /***********************************************************************
  1406. * AGP resource allocation *
  1407. ***********************************************************************/
  1408. static void __devinit i810_fix_pointers(struct i810fb_par *par)
  1409. {
  1410. par->fb.physical = par->aperture.physical+(par->fb.offset << 12);
  1411. par->fb.virtual = par->aperture.virtual+(par->fb.offset << 12);
  1412. par->iring.physical = par->aperture.physical +
  1413. (par->iring.offset << 12);
  1414. par->iring.virtual = par->aperture.virtual +
  1415. (par->iring.offset << 12);
  1416. par->cursor_heap.virtual = par->aperture.virtual+
  1417. (par->cursor_heap.offset << 12);
  1418. }
  1419. static void __devinit i810_fix_offsets(struct i810fb_par *par)
  1420. {
  1421. if (vram + 1 > par->aperture.size >> 20)
  1422. vram = (par->aperture.size >> 20) - 1;
  1423. if (v_offset_default > (par->aperture.size >> 20))
  1424. v_offset_default = (par->aperture.size >> 20);
  1425. if (vram + v_offset_default + 1 > par->aperture.size >> 20)
  1426. v_offset_default = (par->aperture.size >> 20) - (vram + 1);
  1427. par->fb.size = vram << 20;
  1428. par->fb.offset = v_offset_default << 20;
  1429. par->fb.offset >>= 12;
  1430. par->iring.offset = par->fb.offset + (par->fb.size >> 12);
  1431. par->iring.size = RINGBUFFER_SIZE;
  1432. par->cursor_heap.offset = par->iring.offset + (RINGBUFFER_SIZE >> 12);
  1433. par->cursor_heap.size = 4096;
  1434. }
  1435. static int __devinit i810_alloc_agp_mem(struct fb_info *info)
  1436. {
  1437. struct i810fb_par *par = info->par;
  1438. int size;
  1439. struct agp_bridge_data *bridge;
  1440. i810_fix_offsets(par);
  1441. size = par->fb.size + par->iring.size;
  1442. if (!(bridge = agp_backend_acquire(par->dev))) {
  1443. printk("i810fb_alloc_fbmem: cannot acquire agpgart\n");
  1444. return -ENODEV;
  1445. }
  1446. if (!(par->i810_gtt.i810_fb_memory =
  1447. agp_allocate_memory(bridge, size >> 12, AGP_NORMAL_MEMORY))) {
  1448. printk("i810fb_alloc_fbmem: can't allocate framebuffer "
  1449. "memory\n");
  1450. agp_backend_release(bridge);
  1451. return -ENOMEM;
  1452. }
  1453. if (agp_bind_memory(par->i810_gtt.i810_fb_memory,
  1454. par->fb.offset)) {
  1455. printk("i810fb_alloc_fbmem: can't bind framebuffer memory\n");
  1456. agp_backend_release(bridge);
  1457. return -EBUSY;
  1458. }
  1459. if (!(par->i810_gtt.i810_cursor_memory =
  1460. agp_allocate_memory(bridge, par->cursor_heap.size >> 12,
  1461. AGP_PHYSICAL_MEMORY))) {
  1462. printk("i810fb_alloc_cursormem: can't allocate"
  1463. "cursor memory\n");
  1464. agp_backend_release(bridge);
  1465. return -ENOMEM;
  1466. }
  1467. if (agp_bind_memory(par->i810_gtt.i810_cursor_memory,
  1468. par->cursor_heap.offset)) {
  1469. printk("i810fb_alloc_cursormem: cannot bind cursor memory\n");
  1470. agp_backend_release(bridge);
  1471. return -EBUSY;
  1472. }
  1473. par->cursor_heap.physical = par->i810_gtt.i810_cursor_memory->physical;
  1474. i810_fix_pointers(par);
  1475. agp_backend_release(bridge);
  1476. return 0;
  1477. }
  1478. /***************************************************************
  1479. * Initialization *
  1480. ***************************************************************/
  1481. /**
  1482. * i810_init_monspecs
  1483. * @info: pointer to device specific info structure
  1484. *
  1485. * DESCRIPTION:
  1486. * Sets the the user monitor's horizontal and vertical
  1487. * frequency limits
  1488. */
  1489. static void __devinit i810_init_monspecs(struct fb_info *info)
  1490. {
  1491. if (!hsync1)
  1492. hsync1 = HFMIN;
  1493. if (!hsync2)
  1494. hsync2 = HFMAX;
  1495. if (!info->monspecs.hfmax)
  1496. info->monspecs.hfmax = hsync2;
  1497. if (!info->monspecs.hfmin)
  1498. info->monspecs.hfmin = hsync1;
  1499. if (hsync2 < hsync1)
  1500. info->monspecs.hfmin = hsync2;
  1501. if (!vsync1)
  1502. vsync1 = VFMIN;
  1503. if (!vsync2)
  1504. vsync2 = VFMAX;
  1505. if (IS_DVT && vsync1 < 60)
  1506. vsync1 = 60;
  1507. if (!info->monspecs.vfmax)
  1508. info->monspecs.vfmax = vsync2;
  1509. if (!info->monspecs.vfmin)
  1510. info->monspecs.vfmin = vsync1;
  1511. if (vsync2 < vsync1)
  1512. info->monspecs.vfmin = vsync2;
  1513. }
  1514. /**
  1515. * i810_init_defaults - initializes default values to use
  1516. * @par: pointer to i810fb_par structure
  1517. * @info: pointer to current fb_info structure
  1518. */
  1519. static void __devinit i810_init_defaults(struct i810fb_par *par,
  1520. struct fb_info *info)
  1521. {
  1522. if (voffset)
  1523. v_offset_default = voffset;
  1524. else if (par->aperture.size > 32 * 1024 * 1024)
  1525. v_offset_default = 16;
  1526. else
  1527. v_offset_default = 8;
  1528. if (!vram)
  1529. vram = 1;
  1530. if (accel)
  1531. par->dev_flags |= HAS_ACCELERATION;
  1532. if (sync)
  1533. par->dev_flags |= ALWAYS_SYNC;
  1534. if (bpp < 8)
  1535. bpp = 8;
  1536. par->i810fb_ops = i810fb_ops;
  1537. if (xres)
  1538. info->var.xres = xres;
  1539. else
  1540. info->var.xres = 640;
  1541. if (yres)
  1542. info->var.yres = yres;
  1543. else
  1544. info->var.yres = 480;
  1545. if (!vyres)
  1546. vyres = (vram << 20)/(info->var.xres*bpp >> 3);
  1547. info->var.yres_virtual = vyres;
  1548. info->var.bits_per_pixel = bpp;
  1549. if (dcolor)
  1550. info->var.nonstd = 1;
  1551. if (par->dev_flags & HAS_ACCELERATION)
  1552. info->var.accel_flags = 1;
  1553. i810_init_monspecs(info);
  1554. }
  1555. /**
  1556. * i810_init_device - initialize device
  1557. * @par: pointer to i810fb_par structure
  1558. */
  1559. static void __devinit i810_init_device(struct i810fb_par *par)
  1560. {
  1561. u8 reg;
  1562. u8 __iomem *mmio = par->mmio_start_virtual;
  1563. if (mtrr) set_mtrr(par);
  1564. i810_init_cursor(par);
  1565. /* mvo: enable external vga-connector (for laptops) */
  1566. if (extvga) {
  1567. i810_writel(HVSYNC, mmio, 0);
  1568. i810_writel(PWR_CLKC, mmio, 3);
  1569. }
  1570. pci_read_config_byte(par->dev, 0x50, &reg);
  1571. reg &= FREQ_MASK;
  1572. par->mem_freq = (reg) ? 133 : 100;
  1573. }
  1574. static int __devinit
  1575. i810_allocate_pci_resource(struct i810fb_par *par,
  1576. const struct pci_device_id *entry)
  1577. {
  1578. int err;
  1579. if ((err = pci_enable_device(par->dev))) {
  1580. printk("i810fb_init: cannot enable device\n");
  1581. return err;
  1582. }
  1583. par->res_flags |= PCI_DEVICE_ENABLED;
  1584. if (pci_resource_len(par->dev, 0) > 512 * 1024) {
  1585. par->aperture.physical = pci_resource_start(par->dev, 0);
  1586. par->aperture.size = pci_resource_len(par->dev, 0);
  1587. par->mmio_start_phys = pci_resource_start(par->dev, 1);
  1588. } else {
  1589. par->aperture.physical = pci_resource_start(par->dev, 1);
  1590. par->aperture.size = pci_resource_len(par->dev, 1);
  1591. par->mmio_start_phys = pci_resource_start(par->dev, 0);
  1592. }
  1593. if (!par->aperture.size) {
  1594. printk("i810fb_init: device is disabled\n");
  1595. return -ENOMEM;
  1596. }
  1597. if (!request_mem_region(par->aperture.physical,
  1598. par->aperture.size,
  1599. i810_pci_list[entry->driver_data])) {
  1600. printk("i810fb_init: cannot request framebuffer region\n");
  1601. return -ENODEV;
  1602. }
  1603. par->res_flags |= FRAMEBUFFER_REQ;
  1604. par->aperture.virtual = ioremap_nocache(par->aperture.physical,
  1605. par->aperture.size);
  1606. if (!par->aperture.virtual) {
  1607. printk("i810fb_init: cannot remap framebuffer region\n");
  1608. return -ENODEV;
  1609. }
  1610. if (!request_mem_region(par->mmio_start_phys,
  1611. MMIO_SIZE,
  1612. i810_pci_list[entry->driver_data])) {
  1613. printk("i810fb_init: cannot request mmio region\n");
  1614. return -ENODEV;
  1615. }
  1616. par->res_flags |= MMIO_REQ;
  1617. par->mmio_start_virtual = ioremap_nocache(par->mmio_start_phys,
  1618. MMIO_SIZE);
  1619. if (!par->mmio_start_virtual) {
  1620. printk("i810fb_init: cannot remap mmio region\n");
  1621. return -ENODEV;
  1622. }
  1623. return 0;
  1624. }
  1625. static void __devinit i810fb_find_init_mode(struct fb_info *info)
  1626. {
  1627. struct fb_videomode mode;
  1628. struct fb_var_screeninfo var;
  1629. struct fb_monspecs *specs = &info->monspecs;
  1630. int found = 0;
  1631. #ifdef CONFIG_FB_I810_I2C
  1632. int i;
  1633. int err;
  1634. struct i810fb_par *par = info->par;
  1635. #endif
  1636. INIT_LIST_HEAD(&info->modelist);
  1637. memset(&mode, 0, sizeof(struct fb_videomode));
  1638. var = info->var;
  1639. #ifdef CONFIG_FB_I810_I2C
  1640. i810_create_i2c_busses(par);
  1641. for (i = 0; i < 4; i++) {
  1642. err = i810_probe_i2c_connector(info, &par->edid, i+1);
  1643. if (!err)
  1644. break;
  1645. }
  1646. if (!err)
  1647. printk("i810fb_init_pci: DDC probe successful\n");
  1648. fb_edid_to_monspecs(par->edid, specs);
  1649. if (specs->modedb == NULL)
  1650. printk("i810fb_init_pci: Unable to get Mode Database\n");
  1651. fb_videomode_to_modelist(specs->modedb, specs->modedb_len,
  1652. &info->modelist);
  1653. if (specs->modedb != NULL) {
  1654. struct fb_videomode *m;
  1655. if (xres && yres) {
  1656. if ((m = fb_find_best_mode(&var, &info->modelist))) {
  1657. mode = *m;
  1658. found = 1;
  1659. }
  1660. }
  1661. if (!found) {
  1662. m = fb_find_best_display(&info->monspecs, &info->modelist);
  1663. mode = *m;
  1664. found = 1;
  1665. }
  1666. fb_videomode_to_var(&var, &mode);
  1667. }
  1668. #endif
  1669. if (mode_option)
  1670. fb_find_mode(&var, info, mode_option, specs->modedb,
  1671. specs->modedb_len, (found) ? &mode : NULL,
  1672. info->var.bits_per_pixel);
  1673. info->var = var;
  1674. fb_destroy_modedb(specs->modedb);
  1675. specs->modedb = NULL;
  1676. }
  1677. #ifndef MODULE
  1678. static int __devinit i810fb_setup(char *options)
  1679. {
  1680. char *this_opt, *suffix = NULL;
  1681. if (!options || !*options)
  1682. return 0;
  1683. while ((this_opt = strsep(&options, ",")) != NULL) {
  1684. if (!strncmp(this_opt, "mtrr", 4))
  1685. mtrr = 1;
  1686. else if (!strncmp(this_opt, "accel", 5))
  1687. accel = 1;
  1688. else if (!strncmp(this_opt, "extvga", 6))
  1689. extvga = 1;
  1690. else if (!strncmp(this_opt, "sync", 4))
  1691. sync = 1;
  1692. else if (!strncmp(this_opt, "vram:", 5))
  1693. vram = (simple_strtoul(this_opt+5, NULL, 0));
  1694. else if (!strncmp(this_opt, "voffset:", 8))
  1695. voffset = (simple_strtoul(this_opt+8, NULL, 0));
  1696. else if (!strncmp(this_opt, "xres:", 5))
  1697. xres = simple_strtoul(this_opt+5, NULL, 0);
  1698. else if (!strncmp(this_opt, "yres:", 5))
  1699. yres = simple_strtoul(this_opt+5, NULL, 0);
  1700. else if (!strncmp(this_opt, "vyres:", 6))
  1701. vyres = simple_strtoul(this_opt+6, NULL, 0);
  1702. else if (!strncmp(this_opt, "bpp:", 4))
  1703. bpp = simple_strtoul(this_opt+4, NULL, 0);
  1704. else if (!strncmp(this_opt, "hsync1:", 7)) {
  1705. hsync1 = simple_strtoul(this_opt+7, &suffix, 0);
  1706. if (strncmp(suffix, "H", 1))
  1707. hsync1 *= 1000;
  1708. } else if (!strncmp(this_opt, "hsync2:", 7)) {
  1709. hsync2 = simple_strtoul(this_opt+7, &suffix, 0);
  1710. if (strncmp(suffix, "H", 1))
  1711. hsync2 *= 1000;
  1712. } else if (!strncmp(this_opt, "vsync1:", 7))
  1713. vsync1 = simple_strtoul(this_opt+7, NULL, 0);
  1714. else if (!strncmp(this_opt, "vsync2:", 7))
  1715. vsync2 = simple_strtoul(this_opt+7, NULL, 0);
  1716. else if (!strncmp(this_opt, "dcolor", 6))
  1717. dcolor = 1;
  1718. else
  1719. mode_option = this_opt;
  1720. }
  1721. return 0;
  1722. }
  1723. #endif
  1724. static int __devinit i810fb_init_pci (struct pci_dev *dev,
  1725. const struct pci_device_id *entry)
  1726. {
  1727. struct fb_info *info;
  1728. struct i810fb_par *par = NULL;
  1729. struct fb_videomode mode;
  1730. int i, err = -1, vfreq, hfreq, pixclock;
  1731. i = 0;
  1732. info = framebuffer_alloc(sizeof(struct i810fb_par), &dev->dev);
  1733. if (!info)
  1734. return -ENOMEM;
  1735. par = info->par;
  1736. par->dev = dev;
  1737. if (!(info->pixmap.addr = kmalloc(8*1024, GFP_KERNEL))) {
  1738. i810fb_release_resource(info, par);
  1739. return -ENOMEM;
  1740. }
  1741. memset(info->pixmap.addr, 0, 8*1024);
  1742. info->pixmap.size = 8*1024;
  1743. info->pixmap.buf_align = 8;
  1744. info->pixmap.access_align = 32;
  1745. info->pixmap.flags = FB_PIXMAP_SYSTEM;
  1746. if ((err = i810_allocate_pci_resource(par, entry))) {
  1747. i810fb_release_resource(info, par);
  1748. return err;
  1749. }
  1750. i810_init_defaults(par, info);
  1751. if ((err = i810_alloc_agp_mem(info))) {
  1752. i810fb_release_resource(info, par);
  1753. return err;
  1754. }
  1755. i810_init_device(par);
  1756. info->screen_base = par->fb.virtual;
  1757. info->fbops = &par->i810fb_ops;
  1758. info->pseudo_palette = par->pseudo_palette;
  1759. fb_alloc_cmap(&info->cmap, 256, 0);
  1760. i810fb_find_init_mode(info);
  1761. if ((err = info->fbops->fb_check_var(&info->var, info))) {
  1762. i810fb_release_resource(info, par);
  1763. return err;
  1764. }
  1765. fb_var_to_videomode(&mode, &info->var);
  1766. fb_add_videomode(&mode, &info->modelist);
  1767. encode_fix(&info->fix, info);
  1768. i810fb_init_ringbuffer(info);
  1769. err = register_framebuffer(info);
  1770. if (err < 0) {
  1771. i810fb_release_resource(info, par);
  1772. printk("i810fb_init: cannot register framebuffer device\n");
  1773. return err;
  1774. }
  1775. pci_set_drvdata(dev, info);
  1776. pixclock = 1000000000/(info->var.pixclock);
  1777. pixclock *= 1000;
  1778. hfreq = pixclock/(info->var.xres + info->var.left_margin +
  1779. info->var.hsync_len + info->var.right_margin);
  1780. vfreq = hfreq/(info->var.yres + info->var.upper_margin +
  1781. info->var.vsync_len + info->var.lower_margin);
  1782. printk("I810FB: fb%d : %s v%d.%d.%d%s\n"
  1783. "I810FB: Video RAM : %dK\n"
  1784. "I810FB: Monitor : H: %d-%d KHz V: %d-%d Hz\n"
  1785. "I810FB: Mode : %dx%d-%dbpp@%dHz\n",
  1786. info->node,
  1787. i810_pci_list[entry->driver_data],
  1788. VERSION_MAJOR, VERSION_MINOR, VERSION_TEENIE, BRANCH_VERSION,
  1789. (int) par->fb.size>>10, info->monspecs.hfmin/1000,
  1790. info->monspecs.hfmax/1000, info->monspecs.vfmin,
  1791. info->monspecs.vfmax, info->var.xres,
  1792. info->var.yres, info->var.bits_per_pixel, vfreq);
  1793. return 0;
  1794. }
  1795. /***************************************************************
  1796. * De-initialization *
  1797. ***************************************************************/
  1798. static void i810fb_release_resource(struct fb_info *info,
  1799. struct i810fb_par *par)
  1800. {
  1801. struct gtt_data *gtt = &par->i810_gtt;
  1802. unset_mtrr(par);
  1803. i810_delete_i2c_busses(par);
  1804. if (par->i810_gtt.i810_cursor_memory)
  1805. agp_free_memory(gtt->i810_cursor_memory);
  1806. if (par->i810_gtt.i810_fb_memory)
  1807. agp_free_memory(gtt->i810_fb_memory);
  1808. if (par->mmio_start_virtual)
  1809. iounmap(par->mmio_start_virtual);
  1810. if (par->aperture.virtual)
  1811. iounmap(par->aperture.virtual);
  1812. kfree(par->edid);
  1813. if (par->res_flags & FRAMEBUFFER_REQ)
  1814. release_mem_region(par->aperture.physical,
  1815. par->aperture.size);
  1816. if (par->res_flags & MMIO_REQ)
  1817. release_mem_region(par->mmio_start_phys, MMIO_SIZE);
  1818. if (par->res_flags & PCI_DEVICE_ENABLED)
  1819. pci_disable_device(par->dev);
  1820. framebuffer_release(info);
  1821. }
  1822. static void __exit i810fb_remove_pci(struct pci_dev *dev)
  1823. {
  1824. struct fb_info *info = pci_get_drvdata(dev);
  1825. struct i810fb_par *par = info->par;
  1826. unregister_framebuffer(info);
  1827. i810fb_release_resource(info, par);
  1828. pci_set_drvdata(dev, NULL);
  1829. printk("cleanup_module: unloaded i810 framebuffer device\n");
  1830. }
  1831. #ifndef MODULE
  1832. static int __devinit i810fb_init(void)
  1833. {
  1834. char *option = NULL;
  1835. if (fb_get_options("i810fb", &option))
  1836. return -ENODEV;
  1837. i810fb_setup(option);
  1838. return pci_register_driver(&i810fb_driver);
  1839. }
  1840. #endif
  1841. /*********************************************************************
  1842. * Modularization *
  1843. *********************************************************************/
  1844. #ifdef MODULE
  1845. static int __devinit i810fb_init(void)
  1846. {
  1847. hsync1 *= 1000;
  1848. hsync2 *= 1000;
  1849. return pci_register_driver(&i810fb_driver);
  1850. }
  1851. module_param(vram, int, 0);
  1852. MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB"
  1853. " (default=4)");
  1854. module_param(voffset, int, 0);
  1855. MODULE_PARM_DESC(voffset, "at what offset to place start of framebuffer "
  1856. "memory (0 to maximum aperture size), in MiB (default = 48)");
  1857. module_param(bpp, int, 0);
  1858. MODULE_PARM_DESC(bpp, "Color depth for display in bits per pixel"
  1859. " (default = 8)");
  1860. module_param(xres, int, 0);
  1861. MODULE_PARM_DESC(xres, "Horizontal resolution in pixels (default = 640)");
  1862. module_param(yres, int, 0);
  1863. MODULE_PARM_DESC(yres, "Vertical resolution in scanlines (default = 480)");
  1864. module_param(vyres,int, 0);
  1865. MODULE_PARM_DESC(vyres, "Virtual vertical resolution in scanlines"
  1866. " (default = 480)");
  1867. module_param(hsync1, int, 0);
  1868. MODULE_PARM_DESC(hsync1, "Minimum horizontal frequency of monitor in KHz"
  1869. " (default = 29)");
  1870. module_param(hsync2, int, 0);
  1871. MODULE_PARM_DESC(hsync2, "Maximum horizontal frequency of monitor in KHz"
  1872. " (default = 30)");
  1873. module_param(vsync1, int, 0);
  1874. MODULE_PARM_DESC(vsync1, "Minimum vertical frequency of monitor in Hz"
  1875. " (default = 50)");
  1876. module_param(vsync2, int, 0);
  1877. MODULE_PARM_DESC(vsync2, "Maximum vertical frequency of monitor in Hz"
  1878. " (default = 60)");
  1879. module_param(accel, bool, 0);
  1880. MODULE_PARM_DESC(accel, "Use Acceleration (BLIT) engine (default = 0)");
  1881. module_param(mtrr, bool, 0);
  1882. MODULE_PARM_DESC(mtrr, "Use MTRR (default = 0)");
  1883. module_param(extvga, bool, 0);
  1884. MODULE_PARM_DESC(extvga, "Enable external VGA connector (default = 0)");
  1885. module_param(sync, bool, 0);
  1886. MODULE_PARM_DESC(sync, "wait for accel engine to finish drawing"
  1887. " (default = 0)");
  1888. module_param(dcolor, bool, 0);
  1889. MODULE_PARM_DESC(dcolor, "use DirectColor visuals"
  1890. " (default = 0 = TrueColor)");
  1891. module_param(mode_option, charp, 0);
  1892. MODULE_PARM_DESC(mode_option, "Specify initial video mode");
  1893. MODULE_AUTHOR("Tony A. Daplas");
  1894. MODULE_DESCRIPTION("Framebuffer device for the Intel 810/815 and"
  1895. " compatible cards");
  1896. MODULE_LICENSE("GPL");
  1897. static void __exit i810fb_exit(void)
  1898. {
  1899. pci_unregister_driver(&i810fb_driver);
  1900. }
  1901. module_exit(i810fb_exit);
  1902. #endif /* MODULE */
  1903. module_init(i810fb_init);