i810_main.c 56 KB

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