i810_main.c 57 KB

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