i810_main.c 57 KB

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