i810_main.c 54 KB

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