i810_main.c 58 KB

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