vga16fb.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  1. /*
  2. * linux/drivers/video/vga16.c -- VGA 16-color framebuffer driver
  3. *
  4. * Copyright 1999 Ben Pfaff <pfaffben@debian.org> and Petr Vandrovec <VANDROVE@vc.cvut.cz>
  5. * Based on VGA info at http://www.goodnet.com/~tinara/FreeVGA/home.htm
  6. * Based on VESA framebuffer (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General
  9. * Public License. See the file COPYING in the main directory of this
  10. * archive for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/string.h>
  16. #include <linux/mm.h>
  17. #include <linux/delay.h>
  18. #include <linux/fb.h>
  19. #include <linux/ioport.h>
  20. #include <linux/init.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/screen_info.h>
  23. #include <asm/io.h>
  24. #include <video/vga.h>
  25. #define VGA_FB_PHYS 0xA0000
  26. #define VGA_FB_PHYS_LEN 65536
  27. #define MODE_SKIP4 1
  28. #define MODE_8BPP 2
  29. #define MODE_CFB 4
  30. #define MODE_TEXT 8
  31. /* --------------------------------------------------------------------- */
  32. /*
  33. * card parameters
  34. */
  35. struct vga16fb_par {
  36. /* structure holding original VGA register settings when the
  37. screen is blanked */
  38. struct {
  39. unsigned char SeqCtrlIndex; /* Sequencer Index reg. */
  40. unsigned char CrtCtrlIndex; /* CRT-Contr. Index reg. */
  41. unsigned char CrtMiscIO; /* Miscellaneous register */
  42. unsigned char HorizontalTotal; /* CRT-Controller:00h */
  43. unsigned char HorizDisplayEnd; /* CRT-Controller:01h */
  44. unsigned char StartHorizRetrace;/* CRT-Controller:04h */
  45. unsigned char EndHorizRetrace; /* CRT-Controller:05h */
  46. unsigned char Overflow; /* CRT-Controller:07h */
  47. unsigned char StartVertRetrace; /* CRT-Controller:10h */
  48. unsigned char EndVertRetrace; /* CRT-Controller:11h */
  49. unsigned char ModeControl; /* CRT-Controller:17h */
  50. unsigned char ClockingMode; /* Seq-Controller:01h */
  51. } vga_state;
  52. struct vgastate state;
  53. unsigned int ref_count;
  54. int palette_blanked, vesa_blanked, mode, isVGA;
  55. u8 misc, pel_msk, vss, clkdiv;
  56. u8 crtc[VGA_CRT_C];
  57. };
  58. /* --------------------------------------------------------------------- */
  59. static struct fb_var_screeninfo vga16fb_defined = {
  60. .xres = 640,
  61. .yres = 480,
  62. .xres_virtual = 640,
  63. .yres_virtual = 480,
  64. .bits_per_pixel = 4,
  65. .activate = FB_ACTIVATE_TEST,
  66. .height = -1,
  67. .width = -1,
  68. .pixclock = 39721,
  69. .left_margin = 48,
  70. .right_margin = 16,
  71. .upper_margin = 33,
  72. .lower_margin = 10,
  73. .hsync_len = 96,
  74. .vsync_len = 2,
  75. .vmode = FB_VMODE_NONINTERLACED,
  76. };
  77. /* name should not depend on EGA/VGA */
  78. static struct fb_fix_screeninfo vga16fb_fix = {
  79. .id = "VGA16 VGA",
  80. .smem_start = VGA_FB_PHYS,
  81. .smem_len = VGA_FB_PHYS_LEN,
  82. .type = FB_TYPE_VGA_PLANES,
  83. .type_aux = FB_AUX_VGA_PLANES_VGA4,
  84. .visual = FB_VISUAL_PSEUDOCOLOR,
  85. .xpanstep = 8,
  86. .ypanstep = 1,
  87. .line_length = 640 / 8,
  88. .accel = FB_ACCEL_NONE
  89. };
  90. /* The VGA's weird architecture often requires that we read a byte and
  91. write a byte to the same location. It doesn't matter *what* byte
  92. we write, however. This is because all the action goes on behind
  93. the scenes in the VGA's 32-bit latch register, and reading and writing
  94. video memory just invokes latch behavior.
  95. To avoid race conditions (is this necessary?), reading and writing
  96. the memory byte should be done with a single instruction. One
  97. suitable instruction is the x86 bitwise OR. The following
  98. read-modify-write routine should optimize to one such bitwise
  99. OR. */
  100. static inline void rmw(volatile char __iomem *p)
  101. {
  102. readb(p);
  103. writeb(1, p);
  104. }
  105. /* Set the Graphics Mode Register, and return its previous value.
  106. Bits 0-1 are write mode, bit 3 is read mode. */
  107. static inline int setmode(int mode)
  108. {
  109. int oldmode;
  110. oldmode = vga_io_rgfx(VGA_GFX_MODE);
  111. vga_io_w(VGA_GFX_D, mode);
  112. return oldmode;
  113. }
  114. /* Select the Bit Mask Register and return its value. */
  115. static inline int selectmask(void)
  116. {
  117. return vga_io_rgfx(VGA_GFX_BIT_MASK);
  118. }
  119. /* Set the value of the Bit Mask Register. It must already have been
  120. selected with selectmask(). */
  121. static inline void setmask(int mask)
  122. {
  123. vga_io_w(VGA_GFX_D, mask);
  124. }
  125. /* Set the Data Rotate Register and return its old value.
  126. Bits 0-2 are rotate count, bits 3-4 are logical operation
  127. (0=NOP, 1=AND, 2=OR, 3=XOR). */
  128. static inline int setop(int op)
  129. {
  130. int oldop;
  131. oldop = vga_io_rgfx(VGA_GFX_DATA_ROTATE);
  132. vga_io_w(VGA_GFX_D, op);
  133. return oldop;
  134. }
  135. /* Set the Enable Set/Reset Register and return its old value.
  136. The code here always uses value 0xf for this register. */
  137. static inline int setsr(int sr)
  138. {
  139. int oldsr;
  140. oldsr = vga_io_rgfx(VGA_GFX_SR_ENABLE);
  141. vga_io_w(VGA_GFX_D, sr);
  142. return oldsr;
  143. }
  144. /* Set the Set/Reset Register and return its old value. */
  145. static inline int setcolor(int color)
  146. {
  147. int oldcolor;
  148. oldcolor = vga_io_rgfx(VGA_GFX_SR_VALUE);
  149. vga_io_w(VGA_GFX_D, color);
  150. return oldcolor;
  151. }
  152. /* Return the value in the Graphics Address Register. */
  153. static inline int getindex(void)
  154. {
  155. return vga_io_r(VGA_GFX_I);
  156. }
  157. /* Set the value in the Graphics Address Register. */
  158. static inline void setindex(int index)
  159. {
  160. vga_io_w(VGA_GFX_I, index);
  161. }
  162. static void vga16fb_pan_var(struct fb_info *info,
  163. struct fb_var_screeninfo *var)
  164. {
  165. struct vga16fb_par *par = info->par;
  166. u32 xoffset, pos;
  167. xoffset = var->xoffset;
  168. if (info->var.bits_per_pixel == 8) {
  169. pos = (info->var.xres_virtual * var->yoffset + xoffset) >> 2;
  170. } else if (par->mode & MODE_TEXT) {
  171. int fh = 16; // FIXME !!! font height. Fugde for now.
  172. pos = (info->var.xres_virtual * (var->yoffset / fh) + xoffset) >> 3;
  173. } else {
  174. if (info->var.nonstd)
  175. xoffset--;
  176. pos = (info->var.xres_virtual * var->yoffset + xoffset) >> 3;
  177. }
  178. vga_io_wcrt(VGA_CRTC_START_HI, pos >> 8);
  179. vga_io_wcrt(VGA_CRTC_START_LO, pos & 0xFF);
  180. /* if we support CFB4, then we must! support xoffset with pixel
  181. * granularity if someone supports xoffset in bit resolution */
  182. vga_io_r(VGA_IS1_RC); /* reset flip-flop */
  183. vga_io_w(VGA_ATT_IW, VGA_ATC_PEL);
  184. if (info->var.bits_per_pixel == 8)
  185. vga_io_w(VGA_ATT_IW, (xoffset & 3) << 1);
  186. else
  187. vga_io_w(VGA_ATT_IW, xoffset & 7);
  188. vga_io_r(VGA_IS1_RC);
  189. vga_io_w(VGA_ATT_IW, 0x20);
  190. }
  191. static void vga16fb_update_fix(struct fb_info *info)
  192. {
  193. if (info->var.bits_per_pixel == 4) {
  194. if (info->var.nonstd) {
  195. info->fix.type = FB_TYPE_PACKED_PIXELS;
  196. info->fix.line_length = info->var.xres_virtual / 2;
  197. } else {
  198. info->fix.type = FB_TYPE_VGA_PLANES;
  199. info->fix.type_aux = FB_AUX_VGA_PLANES_VGA4;
  200. info->fix.line_length = info->var.xres_virtual / 8;
  201. }
  202. } else if (info->var.bits_per_pixel == 0) {
  203. info->fix.type = FB_TYPE_TEXT;
  204. info->fix.type_aux = FB_AUX_TEXT_CGA;
  205. info->fix.line_length = info->var.xres_virtual / 4;
  206. } else { /* 8bpp */
  207. if (info->var.nonstd) {
  208. info->fix.type = FB_TYPE_VGA_PLANES;
  209. info->fix.type_aux = FB_AUX_VGA_PLANES_CFB8;
  210. info->fix.line_length = info->var.xres_virtual / 4;
  211. } else {
  212. info->fix.type = FB_TYPE_PACKED_PIXELS;
  213. info->fix.line_length = info->var.xres_virtual;
  214. }
  215. }
  216. }
  217. static void vga16fb_clock_chip(struct vga16fb_par *par,
  218. unsigned int pixclock,
  219. const struct fb_info *info,
  220. int mul, int div)
  221. {
  222. static const struct {
  223. u32 pixclock;
  224. u8 misc;
  225. u8 seq_clock_mode;
  226. } *ptr, *best, vgaclocks[] = {
  227. { 79442 /* 12.587 */, 0x00, 0x08},
  228. { 70616 /* 14.161 */, 0x04, 0x08},
  229. { 39721 /* 25.175 */, 0x00, 0x00},
  230. { 35308 /* 28.322 */, 0x04, 0x00},
  231. { 0 /* bad */, 0x00, 0x00}};
  232. int err;
  233. pixclock = (pixclock * mul) / div;
  234. best = vgaclocks;
  235. err = pixclock - best->pixclock;
  236. if (err < 0) err = -err;
  237. for (ptr = vgaclocks + 1; ptr->pixclock; ptr++) {
  238. int tmp;
  239. tmp = pixclock - ptr->pixclock;
  240. if (tmp < 0) tmp = -tmp;
  241. if (tmp < err) {
  242. err = tmp;
  243. best = ptr;
  244. }
  245. }
  246. par->misc |= best->misc;
  247. par->clkdiv = best->seq_clock_mode;
  248. pixclock = (best->pixclock * div) / mul;
  249. }
  250. #define FAIL(X) return -EINVAL
  251. static int vga16fb_open(struct fb_info *info, int user)
  252. {
  253. struct vga16fb_par *par = info->par;
  254. if (!par->ref_count) {
  255. memset(&par->state, 0, sizeof(struct vgastate));
  256. par->state.flags = VGA_SAVE_FONTS | VGA_SAVE_MODE |
  257. VGA_SAVE_CMAP;
  258. save_vga(&par->state);
  259. }
  260. par->ref_count++;
  261. return 0;
  262. }
  263. static int vga16fb_release(struct fb_info *info, int user)
  264. {
  265. struct vga16fb_par *par = info->par;
  266. if (!par->ref_count)
  267. return -EINVAL;
  268. if (par->ref_count == 1)
  269. restore_vga(&par->state);
  270. par->ref_count--;
  271. return 0;
  272. }
  273. static int vga16fb_check_var(struct fb_var_screeninfo *var,
  274. struct fb_info *info)
  275. {
  276. struct vga16fb_par *par = info->par;
  277. u32 xres, right, hslen, left, xtotal;
  278. u32 yres, lower, vslen, upper, ytotal;
  279. u32 vxres, xoffset, vyres, yoffset;
  280. u32 pos;
  281. u8 r7, rMode;
  282. int shift;
  283. int mode;
  284. u32 maxmem;
  285. par->pel_msk = 0xFF;
  286. if (var->bits_per_pixel == 4) {
  287. if (var->nonstd) {
  288. if (!par->isVGA)
  289. return -EINVAL;
  290. shift = 3;
  291. mode = MODE_SKIP4 | MODE_CFB;
  292. maxmem = 16384;
  293. par->pel_msk = 0x0F;
  294. } else {
  295. shift = 3;
  296. mode = 0;
  297. maxmem = 65536;
  298. }
  299. } else if (var->bits_per_pixel == 8) {
  300. if (!par->isVGA)
  301. return -EINVAL; /* no support on EGA */
  302. shift = 2;
  303. if (var->nonstd) {
  304. mode = MODE_8BPP | MODE_CFB;
  305. maxmem = 65536;
  306. } else {
  307. mode = MODE_SKIP4 | MODE_8BPP | MODE_CFB;
  308. maxmem = 16384;
  309. }
  310. } else
  311. return -EINVAL;
  312. xres = (var->xres + 7) & ~7;
  313. vxres = (var->xres_virtual + 0xF) & ~0xF;
  314. xoffset = (var->xoffset + 7) & ~7;
  315. left = (var->left_margin + 7) & ~7;
  316. right = (var->right_margin + 7) & ~7;
  317. hslen = (var->hsync_len + 7) & ~7;
  318. if (vxres < xres)
  319. vxres = xres;
  320. if (xres + xoffset > vxres)
  321. xoffset = vxres - xres;
  322. var->xres = xres;
  323. var->right_margin = right;
  324. var->hsync_len = hslen;
  325. var->left_margin = left;
  326. var->xres_virtual = vxres;
  327. var->xoffset = xoffset;
  328. xres >>= shift;
  329. right >>= shift;
  330. hslen >>= shift;
  331. left >>= shift;
  332. vxres >>= shift;
  333. xtotal = xres + right + hslen + left;
  334. if (xtotal >= 256)
  335. FAIL("xtotal too big");
  336. if (hslen > 32)
  337. FAIL("hslen too big");
  338. if (right + hslen + left > 64)
  339. FAIL("hblank too big");
  340. par->crtc[VGA_CRTC_H_TOTAL] = xtotal - 5;
  341. par->crtc[VGA_CRTC_H_BLANK_START] = xres - 1;
  342. par->crtc[VGA_CRTC_H_DISP] = xres - 1;
  343. pos = xres + right;
  344. par->crtc[VGA_CRTC_H_SYNC_START] = pos;
  345. pos += hslen;
  346. par->crtc[VGA_CRTC_H_SYNC_END] = pos & 0x1F;
  347. pos += left - 2; /* blank_end + 2 <= total + 5 */
  348. par->crtc[VGA_CRTC_H_BLANK_END] = (pos & 0x1F) | 0x80;
  349. if (pos & 0x20)
  350. par->crtc[VGA_CRTC_H_SYNC_END] |= 0x80;
  351. yres = var->yres;
  352. lower = var->lower_margin;
  353. vslen = var->vsync_len;
  354. upper = var->upper_margin;
  355. vyres = var->yres_virtual;
  356. yoffset = var->yoffset;
  357. if (yres > vyres)
  358. vyres = yres;
  359. if (vxres * vyres > maxmem) {
  360. vyres = maxmem / vxres;
  361. if (vyres < yres)
  362. return -ENOMEM;
  363. }
  364. if (yoffset + yres > vyres)
  365. yoffset = vyres - yres;
  366. var->yres = yres;
  367. var->lower_margin = lower;
  368. var->vsync_len = vslen;
  369. var->upper_margin = upper;
  370. var->yres_virtual = vyres;
  371. var->yoffset = yoffset;
  372. if (var->vmode & FB_VMODE_DOUBLE) {
  373. yres <<= 1;
  374. lower <<= 1;
  375. vslen <<= 1;
  376. upper <<= 1;
  377. }
  378. ytotal = yres + lower + vslen + upper;
  379. if (ytotal > 1024) {
  380. ytotal >>= 1;
  381. yres >>= 1;
  382. lower >>= 1;
  383. vslen >>= 1;
  384. upper >>= 1;
  385. rMode = 0x04;
  386. } else
  387. rMode = 0x00;
  388. if (ytotal > 1024)
  389. FAIL("ytotal too big");
  390. if (vslen > 16)
  391. FAIL("vslen too big");
  392. par->crtc[VGA_CRTC_V_TOTAL] = ytotal - 2;
  393. r7 = 0x10; /* disable linecompare */
  394. if (ytotal & 0x100) r7 |= 0x01;
  395. if (ytotal & 0x200) r7 |= 0x20;
  396. par->crtc[VGA_CRTC_PRESET_ROW] = 0;
  397. par->crtc[VGA_CRTC_MAX_SCAN] = 0x40; /* 1 scanline, no linecmp */
  398. if (var->vmode & FB_VMODE_DOUBLE)
  399. par->crtc[VGA_CRTC_MAX_SCAN] |= 0x80;
  400. par->crtc[VGA_CRTC_CURSOR_START] = 0x20;
  401. par->crtc[VGA_CRTC_CURSOR_END] = 0x00;
  402. if ((mode & (MODE_CFB | MODE_8BPP)) == MODE_CFB)
  403. xoffset--;
  404. pos = yoffset * vxres + (xoffset >> shift);
  405. par->crtc[VGA_CRTC_START_HI] = pos >> 8;
  406. par->crtc[VGA_CRTC_START_LO] = pos & 0xFF;
  407. par->crtc[VGA_CRTC_CURSOR_HI] = 0x00;
  408. par->crtc[VGA_CRTC_CURSOR_LO] = 0x00;
  409. pos = yres - 1;
  410. par->crtc[VGA_CRTC_V_DISP_END] = pos & 0xFF;
  411. par->crtc[VGA_CRTC_V_BLANK_START] = pos & 0xFF;
  412. if (pos & 0x100)
  413. r7 |= 0x0A; /* 0x02 -> DISP_END, 0x08 -> BLANK_START */
  414. if (pos & 0x200) {
  415. r7 |= 0x40; /* 0x40 -> DISP_END */
  416. par->crtc[VGA_CRTC_MAX_SCAN] |= 0x20; /* BLANK_START */
  417. }
  418. pos += lower;
  419. par->crtc[VGA_CRTC_V_SYNC_START] = pos & 0xFF;
  420. if (pos & 0x100)
  421. r7 |= 0x04;
  422. if (pos & 0x200)
  423. r7 |= 0x80;
  424. pos += vslen;
  425. par->crtc[VGA_CRTC_V_SYNC_END] = (pos & 0x0F) & ~0x10; /* disabled IRQ */
  426. pos += upper - 1; /* blank_end + 1 <= ytotal + 2 */
  427. par->crtc[VGA_CRTC_V_BLANK_END] = pos & 0xFF; /* 0x7F for original VGA,
  428. but some SVGA chips requires all 8 bits to set */
  429. if (vxres >= 512)
  430. FAIL("vxres too long");
  431. par->crtc[VGA_CRTC_OFFSET] = vxres >> 1;
  432. if (mode & MODE_SKIP4)
  433. par->crtc[VGA_CRTC_UNDERLINE] = 0x5F; /* 256, cfb8 */
  434. else
  435. par->crtc[VGA_CRTC_UNDERLINE] = 0x1F; /* 16, vgap */
  436. par->crtc[VGA_CRTC_MODE] = rMode | ((mode & MODE_TEXT) ? 0xA3 : 0xE3);
  437. par->crtc[VGA_CRTC_LINE_COMPARE] = 0xFF;
  438. par->crtc[VGA_CRTC_OVERFLOW] = r7;
  439. par->vss = 0x00; /* 3DA */
  440. par->misc = 0xE3; /* enable CPU, ports 0x3Dx, positive sync */
  441. if (var->sync & FB_SYNC_HOR_HIGH_ACT)
  442. par->misc &= ~0x40;
  443. if (var->sync & FB_SYNC_VERT_HIGH_ACT)
  444. par->misc &= ~0x80;
  445. par->mode = mode;
  446. if (mode & MODE_8BPP)
  447. /* pixel clock == vga clock / 2 */
  448. vga16fb_clock_chip(par, var->pixclock, info, 1, 2);
  449. else
  450. /* pixel clock == vga clock */
  451. vga16fb_clock_chip(par, var->pixclock, info, 1, 1);
  452. var->red.offset = var->green.offset = var->blue.offset =
  453. var->transp.offset = 0;
  454. var->red.length = var->green.length = var->blue.length =
  455. (par->isVGA) ? 6 : 2;
  456. var->transp.length = 0;
  457. var->activate = FB_ACTIVATE_NOW;
  458. var->height = -1;
  459. var->width = -1;
  460. var->accel_flags = 0;
  461. return 0;
  462. }
  463. #undef FAIL
  464. static int vga16fb_set_par(struct fb_info *info)
  465. {
  466. struct vga16fb_par *par = info->par;
  467. u8 gdc[VGA_GFX_C];
  468. u8 seq[VGA_SEQ_C];
  469. u8 atc[VGA_ATT_C];
  470. int fh, i;
  471. seq[VGA_SEQ_CLOCK_MODE] = 0x01 | par->clkdiv;
  472. if (par->mode & MODE_TEXT)
  473. seq[VGA_SEQ_PLANE_WRITE] = 0x03;
  474. else
  475. seq[VGA_SEQ_PLANE_WRITE] = 0x0F;
  476. seq[VGA_SEQ_CHARACTER_MAP] = 0x00;
  477. if (par->mode & MODE_TEXT)
  478. seq[VGA_SEQ_MEMORY_MODE] = 0x03;
  479. else if (par->mode & MODE_SKIP4)
  480. seq[VGA_SEQ_MEMORY_MODE] = 0x0E;
  481. else
  482. seq[VGA_SEQ_MEMORY_MODE] = 0x06;
  483. gdc[VGA_GFX_SR_VALUE] = 0x00;
  484. gdc[VGA_GFX_SR_ENABLE] = 0x00;
  485. gdc[VGA_GFX_COMPARE_VALUE] = 0x00;
  486. gdc[VGA_GFX_DATA_ROTATE] = 0x00;
  487. gdc[VGA_GFX_PLANE_READ] = 0;
  488. if (par->mode & MODE_TEXT) {
  489. gdc[VGA_GFX_MODE] = 0x10;
  490. gdc[VGA_GFX_MISC] = 0x06;
  491. } else {
  492. if (par->mode & MODE_CFB)
  493. gdc[VGA_GFX_MODE] = 0x40;
  494. else
  495. gdc[VGA_GFX_MODE] = 0x00;
  496. gdc[VGA_GFX_MISC] = 0x05;
  497. }
  498. gdc[VGA_GFX_COMPARE_MASK] = 0x0F;
  499. gdc[VGA_GFX_BIT_MASK] = 0xFF;
  500. for (i = 0x00; i < 0x10; i++)
  501. atc[i] = i;
  502. if (par->mode & MODE_TEXT)
  503. atc[VGA_ATC_MODE] = 0x04;
  504. else if (par->mode & MODE_8BPP)
  505. atc[VGA_ATC_MODE] = 0x41;
  506. else
  507. atc[VGA_ATC_MODE] = 0x81;
  508. atc[VGA_ATC_OVERSCAN] = 0x00; /* 0 for EGA, 0xFF for VGA */
  509. atc[VGA_ATC_PLANE_ENABLE] = 0x0F;
  510. if (par->mode & MODE_8BPP)
  511. atc[VGA_ATC_PEL] = (info->var.xoffset & 3) << 1;
  512. else
  513. atc[VGA_ATC_PEL] = info->var.xoffset & 7;
  514. atc[VGA_ATC_COLOR_PAGE] = 0x00;
  515. if (par->mode & MODE_TEXT) {
  516. fh = 16; // FIXME !!! Fudge font height.
  517. par->crtc[VGA_CRTC_MAX_SCAN] = (par->crtc[VGA_CRTC_MAX_SCAN]
  518. & ~0x1F) | (fh - 1);
  519. }
  520. vga_io_w(VGA_MIS_W, vga_io_r(VGA_MIS_R) | 0x01);
  521. /* Enable graphics register modification */
  522. if (!par->isVGA) {
  523. vga_io_w(EGA_GFX_E0, 0x00);
  524. vga_io_w(EGA_GFX_E1, 0x01);
  525. }
  526. /* update misc output register */
  527. vga_io_w(VGA_MIS_W, par->misc);
  528. /* synchronous reset on */
  529. vga_io_wseq(0x00, 0x01);
  530. if (par->isVGA)
  531. vga_io_w(VGA_PEL_MSK, par->pel_msk);
  532. /* write sequencer registers */
  533. vga_io_wseq(VGA_SEQ_CLOCK_MODE, seq[VGA_SEQ_CLOCK_MODE] | 0x20);
  534. for (i = 2; i < VGA_SEQ_C; i++) {
  535. vga_io_wseq(i, seq[i]);
  536. }
  537. /* synchronous reset off */
  538. vga_io_wseq(0x00, 0x03);
  539. /* deprotect CRT registers 0-7 */
  540. vga_io_wcrt(VGA_CRTC_V_SYNC_END, par->crtc[VGA_CRTC_V_SYNC_END]);
  541. /* write CRT registers */
  542. for (i = 0; i < VGA_CRTC_REGS; i++) {
  543. vga_io_wcrt(i, par->crtc[i]);
  544. }
  545. /* write graphics controller registers */
  546. for (i = 0; i < VGA_GFX_C; i++) {
  547. vga_io_wgfx(i, gdc[i]);
  548. }
  549. /* write attribute controller registers */
  550. for (i = 0; i < VGA_ATT_C; i++) {
  551. vga_io_r(VGA_IS1_RC); /* reset flip-flop */
  552. vga_io_wattr(i, atc[i]);
  553. }
  554. /* Wait for screen to stabilize. */
  555. mdelay(50);
  556. vga_io_wseq(VGA_SEQ_CLOCK_MODE, seq[VGA_SEQ_CLOCK_MODE]);
  557. vga_io_r(VGA_IS1_RC);
  558. vga_io_w(VGA_ATT_IW, 0x20);
  559. vga16fb_update_fix(info);
  560. return 0;
  561. }
  562. static void ega16_setpalette(int regno, unsigned red, unsigned green, unsigned blue)
  563. {
  564. static const unsigned char map[] = { 000, 001, 010, 011 };
  565. int val;
  566. if (regno >= 16)
  567. return;
  568. val = map[red>>14] | ((map[green>>14]) << 1) | ((map[blue>>14]) << 2);
  569. vga_io_r(VGA_IS1_RC); /* ! 0x3BA */
  570. vga_io_wattr(regno, val);
  571. vga_io_r(VGA_IS1_RC); /* some clones need it */
  572. vga_io_w(VGA_ATT_IW, 0x20); /* unblank screen */
  573. }
  574. static void vga16_setpalette(int regno, unsigned red, unsigned green, unsigned blue)
  575. {
  576. outb(regno, VGA_PEL_IW);
  577. outb(red >> 10, VGA_PEL_D);
  578. outb(green >> 10, VGA_PEL_D);
  579. outb(blue >> 10, VGA_PEL_D);
  580. }
  581. static int vga16fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  582. unsigned blue, unsigned transp,
  583. struct fb_info *info)
  584. {
  585. struct vga16fb_par *par = info->par;
  586. int gray;
  587. /*
  588. * Set a single color register. The values supplied are
  589. * already rounded down to the hardware's capabilities
  590. * (according to the entries in the `var' structure). Return
  591. * != 0 for invalid regno.
  592. */
  593. if (regno >= 256)
  594. return 1;
  595. gray = info->var.grayscale;
  596. if (gray) {
  597. /* gray = 0.30*R + 0.59*G + 0.11*B */
  598. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  599. }
  600. if (par->isVGA)
  601. vga16_setpalette(regno,red,green,blue);
  602. else
  603. ega16_setpalette(regno,red,green,blue);
  604. return 0;
  605. }
  606. static int vga16fb_pan_display(struct fb_var_screeninfo *var,
  607. struct fb_info *info)
  608. {
  609. vga16fb_pan_var(info, var);
  610. return 0;
  611. }
  612. /* The following VESA blanking code is taken from vgacon.c. The VGA
  613. blanking code was originally by Huang shi chao, and modified by
  614. Christoph Rimek (chrimek@toppoint.de) and todd j. derr
  615. (tjd@barefoot.org) for Linux. */
  616. static void vga_vesa_blank(struct vga16fb_par *par, int mode)
  617. {
  618. unsigned char SeqCtrlIndex = vga_io_r(VGA_SEQ_I);
  619. unsigned char CrtCtrlIndex = vga_io_r(VGA_CRT_IC);
  620. /* save original values of VGA controller registers */
  621. if(!par->vesa_blanked) {
  622. par->vga_state.CrtMiscIO = vga_io_r(VGA_MIS_R);
  623. //sti();
  624. par->vga_state.HorizontalTotal = vga_io_rcrt(0x00); /* HorizontalTotal */
  625. par->vga_state.HorizDisplayEnd = vga_io_rcrt(0x01); /* HorizDisplayEnd */
  626. par->vga_state.StartHorizRetrace = vga_io_rcrt(0x04); /* StartHorizRetrace */
  627. par->vga_state.EndHorizRetrace = vga_io_rcrt(0x05); /* EndHorizRetrace */
  628. par->vga_state.Overflow = vga_io_rcrt(0x07); /* Overflow */
  629. par->vga_state.StartVertRetrace = vga_io_rcrt(0x10); /* StartVertRetrace */
  630. par->vga_state.EndVertRetrace = vga_io_rcrt(0x11); /* EndVertRetrace */
  631. par->vga_state.ModeControl = vga_io_rcrt(0x17); /* ModeControl */
  632. par->vga_state.ClockingMode = vga_io_rseq(0x01); /* ClockingMode */
  633. }
  634. /* assure that video is enabled */
  635. /* "0x20" is VIDEO_ENABLE_bit in register 01 of sequencer */
  636. vga_io_wseq(0x01, par->vga_state.ClockingMode | 0x20);
  637. /* test for vertical retrace in process.... */
  638. if ((par->vga_state.CrtMiscIO & 0x80) == 0x80)
  639. vga_io_w(VGA_MIS_W, par->vga_state.CrtMiscIO & 0xef);
  640. /*
  641. * Set <End of vertical retrace> to minimum (0) and
  642. * <Start of vertical Retrace> to maximum (incl. overflow)
  643. * Result: turn off vertical sync (VSync) pulse.
  644. */
  645. if (mode & FB_BLANK_VSYNC_SUSPEND) {
  646. vga_io_wcrt(VGA_CRTC_V_SYNC_START, 0xff);
  647. vga_io_wcrt(VGA_CRTC_V_SYNC_END, 0x40);
  648. /* bits 9,10 of vert. retrace */
  649. vga_io_wcrt(VGA_CRTC_OVERFLOW, par->vga_state.Overflow | 0x84);
  650. }
  651. if (mode & FB_BLANK_HSYNC_SUSPEND) {
  652. /*
  653. * Set <End of horizontal retrace> to minimum (0) and
  654. * <Start of horizontal Retrace> to maximum
  655. * Result: turn off horizontal sync (HSync) pulse.
  656. */
  657. vga_io_wcrt(VGA_CRTC_H_SYNC_START, 0xff);
  658. vga_io_wcrt(VGA_CRTC_H_SYNC_END, 0x00);
  659. }
  660. /* restore both index registers */
  661. outb_p(SeqCtrlIndex, VGA_SEQ_I);
  662. outb_p(CrtCtrlIndex, VGA_CRT_IC);
  663. }
  664. static void vga_vesa_unblank(struct vga16fb_par *par)
  665. {
  666. unsigned char SeqCtrlIndex = vga_io_r(VGA_SEQ_I);
  667. unsigned char CrtCtrlIndex = vga_io_r(VGA_CRT_IC);
  668. /* restore original values of VGA controller registers */
  669. vga_io_w(VGA_MIS_W, par->vga_state.CrtMiscIO);
  670. /* HorizontalTotal */
  671. vga_io_wcrt(0x00, par->vga_state.HorizontalTotal);
  672. /* HorizDisplayEnd */
  673. vga_io_wcrt(0x01, par->vga_state.HorizDisplayEnd);
  674. /* StartHorizRetrace */
  675. vga_io_wcrt(0x04, par->vga_state.StartHorizRetrace);
  676. /* EndHorizRetrace */
  677. vga_io_wcrt(0x05, par->vga_state.EndHorizRetrace);
  678. /* Overflow */
  679. vga_io_wcrt(0x07, par->vga_state.Overflow);
  680. /* StartVertRetrace */
  681. vga_io_wcrt(0x10, par->vga_state.StartVertRetrace);
  682. /* EndVertRetrace */
  683. vga_io_wcrt(0x11, par->vga_state.EndVertRetrace);
  684. /* ModeControl */
  685. vga_io_wcrt(0x17, par->vga_state.ModeControl);
  686. /* ClockingMode */
  687. vga_io_wseq(0x01, par->vga_state.ClockingMode);
  688. /* restore index/control registers */
  689. vga_io_w(VGA_SEQ_I, SeqCtrlIndex);
  690. vga_io_w(VGA_CRT_IC, CrtCtrlIndex);
  691. }
  692. static void vga_pal_blank(void)
  693. {
  694. int i;
  695. for (i=0; i<16; i++) {
  696. outb_p(i, VGA_PEL_IW);
  697. outb_p(0, VGA_PEL_D);
  698. outb_p(0, VGA_PEL_D);
  699. outb_p(0, VGA_PEL_D);
  700. }
  701. }
  702. /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
  703. static int vga16fb_blank(int blank, struct fb_info *info)
  704. {
  705. struct vga16fb_par *par = info->par;
  706. switch (blank) {
  707. case FB_BLANK_UNBLANK: /* Unblank */
  708. if (par->vesa_blanked) {
  709. vga_vesa_unblank(par);
  710. par->vesa_blanked = 0;
  711. }
  712. if (par->palette_blanked) {
  713. par->palette_blanked = 0;
  714. }
  715. break;
  716. case FB_BLANK_NORMAL: /* blank */
  717. vga_pal_blank();
  718. par->palette_blanked = 1;
  719. break;
  720. default: /* VESA blanking */
  721. vga_vesa_blank(par, blank);
  722. par->vesa_blanked = 1;
  723. break;
  724. }
  725. return 0;
  726. }
  727. static void vga_8planes_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  728. {
  729. u32 dx = rect->dx, width = rect->width;
  730. char oldindex = getindex();
  731. char oldmode = setmode(0x40);
  732. char oldmask = selectmask();
  733. int line_ofs, height;
  734. char oldop, oldsr;
  735. char __iomem *where;
  736. dx /= 4;
  737. where = info->screen_base + dx + rect->dy * info->fix.line_length;
  738. if (rect->rop == ROP_COPY) {
  739. oldop = setop(0);
  740. oldsr = setsr(0);
  741. width /= 4;
  742. line_ofs = info->fix.line_length - width;
  743. setmask(0xff);
  744. height = rect->height;
  745. while (height--) {
  746. int x;
  747. /* we can do memset... */
  748. for (x = width; x > 0; --x) {
  749. writeb(rect->color, where);
  750. where++;
  751. }
  752. where += line_ofs;
  753. }
  754. } else {
  755. char oldcolor = setcolor(0xf);
  756. int y;
  757. oldop = setop(0x18);
  758. oldsr = setsr(0xf);
  759. setmask(0x0F);
  760. for (y = 0; y < rect->height; y++) {
  761. rmw(where);
  762. rmw(where+1);
  763. where += info->fix.line_length;
  764. }
  765. setcolor(oldcolor);
  766. }
  767. setmask(oldmask);
  768. setsr(oldsr);
  769. setop(oldop);
  770. setmode(oldmode);
  771. setindex(oldindex);
  772. }
  773. static void vga16fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  774. {
  775. int x, x2, y2, vxres, vyres, width, height, line_ofs;
  776. char __iomem *dst;
  777. vxres = info->var.xres_virtual;
  778. vyres = info->var.yres_virtual;
  779. if (!rect->width || !rect->height || rect->dx > vxres || rect->dy > vyres)
  780. return;
  781. /* We could use hardware clipping but on many cards you get around
  782. * hardware clipping by writing to framebuffer directly. */
  783. x2 = rect->dx + rect->width;
  784. y2 = rect->dy + rect->height;
  785. x2 = x2 < vxres ? x2 : vxres;
  786. y2 = y2 < vyres ? y2 : vyres;
  787. width = x2 - rect->dx;
  788. switch (info->fix.type) {
  789. case FB_TYPE_VGA_PLANES:
  790. if (info->fix.type_aux == FB_AUX_VGA_PLANES_VGA4) {
  791. height = y2 - rect->dy;
  792. width = rect->width/8;
  793. line_ofs = info->fix.line_length - width;
  794. dst = info->screen_base + (rect->dx/8) + rect->dy * info->fix.line_length;
  795. switch (rect->rop) {
  796. case ROP_COPY:
  797. setmode(0);
  798. setop(0);
  799. setsr(0xf);
  800. setcolor(rect->color);
  801. selectmask();
  802. setmask(0xff);
  803. while (height--) {
  804. for (x = 0; x < width; x++) {
  805. writeb(0, dst);
  806. dst++;
  807. }
  808. dst += line_ofs;
  809. }
  810. break;
  811. case ROP_XOR:
  812. setmode(0);
  813. setop(0x18);
  814. setsr(0xf);
  815. setcolor(0xf);
  816. selectmask();
  817. setmask(0xff);
  818. while (height--) {
  819. for (x = 0; x < width; x++) {
  820. rmw(dst);
  821. dst++;
  822. }
  823. dst += line_ofs;
  824. }
  825. break;
  826. }
  827. } else
  828. vga_8planes_fillrect(info, rect);
  829. break;
  830. case FB_TYPE_PACKED_PIXELS:
  831. default:
  832. cfb_fillrect(info, rect);
  833. break;
  834. }
  835. }
  836. static void vga_8planes_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  837. {
  838. char oldindex = getindex();
  839. char oldmode = setmode(0x41);
  840. char oldop = setop(0);
  841. char oldsr = setsr(0xf);
  842. int height, line_ofs, x;
  843. u32 sx, dx, width;
  844. char __iomem *dest;
  845. char __iomem *src;
  846. height = area->height;
  847. sx = area->sx / 4;
  848. dx = area->dx / 4;
  849. width = area->width / 4;
  850. if (area->dy < area->sy || (area->dy == area->sy && dx < sx)) {
  851. line_ofs = info->fix.line_length - width;
  852. dest = info->screen_base + dx + area->dy * info->fix.line_length;
  853. src = info->screen_base + sx + area->sy * info->fix.line_length;
  854. while (height--) {
  855. for (x = 0; x < width; x++) {
  856. readb(src);
  857. writeb(0, dest);
  858. src++;
  859. dest++;
  860. }
  861. src += line_ofs;
  862. dest += line_ofs;
  863. }
  864. } else {
  865. line_ofs = info->fix.line_length - width;
  866. dest = info->screen_base + dx + width +
  867. (area->dy + height - 1) * info->fix.line_length;
  868. src = info->screen_base + sx + width +
  869. (area->sy + height - 1) * info->fix.line_length;
  870. while (height--) {
  871. for (x = 0; x < width; x++) {
  872. --src;
  873. --dest;
  874. readb(src);
  875. writeb(0, dest);
  876. }
  877. src -= line_ofs;
  878. dest -= line_ofs;
  879. }
  880. }
  881. setsr(oldsr);
  882. setop(oldop);
  883. setmode(oldmode);
  884. setindex(oldindex);
  885. }
  886. static void vga16fb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  887. {
  888. u32 dx = area->dx, dy = area->dy, sx = area->sx, sy = area->sy;
  889. int x, x2, y2, old_dx, old_dy, vxres, vyres;
  890. int height, width, line_ofs;
  891. char __iomem *dst = NULL;
  892. char __iomem *src = NULL;
  893. vxres = info->var.xres_virtual;
  894. vyres = info->var.yres_virtual;
  895. if (area->dx > vxres || area->sx > vxres || area->dy > vyres ||
  896. area->sy > vyres)
  897. return;
  898. /* clip the destination */
  899. old_dx = area->dx;
  900. old_dy = area->dy;
  901. /*
  902. * We could use hardware clipping but on many cards you get around
  903. * hardware clipping by writing to framebuffer directly.
  904. */
  905. x2 = area->dx + area->width;
  906. y2 = area->dy + area->height;
  907. dx = area->dx > 0 ? area->dx : 0;
  908. dy = area->dy > 0 ? area->dy : 0;
  909. x2 = x2 < vxres ? x2 : vxres;
  910. y2 = y2 < vyres ? y2 : vyres;
  911. width = x2 - dx;
  912. height = y2 - dy;
  913. if (sx + dx < old_dx || sy + dy < old_dy)
  914. return;
  915. /* update sx1,sy1 */
  916. sx += (dx - old_dx);
  917. sy += (dy - old_dy);
  918. /* the source must be completely inside the virtual screen */
  919. if (sx + width > vxres || sy + height > vyres)
  920. return;
  921. switch (info->fix.type) {
  922. case FB_TYPE_VGA_PLANES:
  923. if (info->fix.type_aux == FB_AUX_VGA_PLANES_VGA4) {
  924. width = width/8;
  925. height = height;
  926. line_ofs = info->fix.line_length - width;
  927. setmode(1);
  928. setop(0);
  929. setsr(0xf);
  930. if (dy < sy || (dy == sy && dx < sx)) {
  931. dst = info->screen_base + (dx/8) + dy * info->fix.line_length;
  932. src = info->screen_base + (sx/8) + sy * info->fix.line_length;
  933. while (height--) {
  934. for (x = 0; x < width; x++) {
  935. readb(src);
  936. writeb(0, dst);
  937. dst++;
  938. src++;
  939. }
  940. src += line_ofs;
  941. dst += line_ofs;
  942. }
  943. } else {
  944. dst = info->screen_base + (dx/8) + width +
  945. (dy + height - 1) * info->fix.line_length;
  946. src = info->screen_base + (sx/8) + width +
  947. (sy + height - 1) * info->fix.line_length;
  948. while (height--) {
  949. for (x = 0; x < width; x++) {
  950. dst--;
  951. src--;
  952. readb(src);
  953. writeb(0, dst);
  954. }
  955. src -= line_ofs;
  956. dst -= line_ofs;
  957. }
  958. }
  959. } else
  960. vga_8planes_copyarea(info, area);
  961. break;
  962. case FB_TYPE_PACKED_PIXELS:
  963. default:
  964. cfb_copyarea(info, area);
  965. break;
  966. }
  967. }
  968. #define TRANS_MASK_LOW {0x0,0x8,0x4,0xC,0x2,0xA,0x6,0xE,0x1,0x9,0x5,0xD,0x3,0xB,0x7,0xF}
  969. #define TRANS_MASK_HIGH {0x000, 0x800, 0x400, 0xC00, 0x200, 0xA00, 0x600, 0xE00, \
  970. 0x100, 0x900, 0x500, 0xD00, 0x300, 0xB00, 0x700, 0xF00}
  971. #if defined(__LITTLE_ENDIAN)
  972. static const u16 transl_l[] = TRANS_MASK_LOW;
  973. static const u16 transl_h[] = TRANS_MASK_HIGH;
  974. #elif defined(__BIG_ENDIAN)
  975. static const u16 transl_l[] = TRANS_MASK_HIGH;
  976. static const u16 transl_h[] = TRANS_MASK_LOW;
  977. #else
  978. #error "Only __BIG_ENDIAN and __LITTLE_ENDIAN are supported in vga-planes"
  979. #endif
  980. static void vga_8planes_imageblit(struct fb_info *info, const struct fb_image *image)
  981. {
  982. char oldindex = getindex();
  983. char oldmode = setmode(0x40);
  984. char oldop = setop(0);
  985. char oldsr = setsr(0);
  986. char oldmask = selectmask();
  987. const char *cdat = image->data;
  988. u32 dx = image->dx;
  989. char __iomem *where;
  990. int y;
  991. dx /= 4;
  992. where = info->screen_base + dx + image->dy * info->fix.line_length;
  993. setmask(0xff);
  994. writeb(image->bg_color, where);
  995. readb(where);
  996. selectmask();
  997. setmask(image->fg_color ^ image->bg_color);
  998. setmode(0x42);
  999. setop(0x18);
  1000. for (y = 0; y < image->height; y++, where += info->fix.line_length)
  1001. writew(transl_h[cdat[y]&0xF] | transl_l[cdat[y] >> 4], where);
  1002. setmask(oldmask);
  1003. setsr(oldsr);
  1004. setop(oldop);
  1005. setmode(oldmode);
  1006. setindex(oldindex);
  1007. }
  1008. static void vga_imageblit_expand(struct fb_info *info, const struct fb_image *image)
  1009. {
  1010. char __iomem *where = info->screen_base + (image->dx/8) +
  1011. image->dy * info->fix.line_length;
  1012. struct vga16fb_par *par = info->par;
  1013. char *cdat = (char *) image->data;
  1014. char __iomem *dst;
  1015. int x, y;
  1016. switch (info->fix.type) {
  1017. case FB_TYPE_VGA_PLANES:
  1018. if (info->fix.type_aux == FB_AUX_VGA_PLANES_VGA4) {
  1019. if (par->isVGA) {
  1020. setmode(2);
  1021. setop(0);
  1022. setsr(0xf);
  1023. setcolor(image->fg_color);
  1024. selectmask();
  1025. setmask(0xff);
  1026. writeb(image->bg_color, where);
  1027. rmb();
  1028. readb(where); /* fill latches */
  1029. setmode(3);
  1030. wmb();
  1031. for (y = 0; y < image->height; y++) {
  1032. dst = where;
  1033. for (x = image->width/8; x--;)
  1034. writeb(*cdat++, dst++);
  1035. where += info->fix.line_length;
  1036. }
  1037. wmb();
  1038. } else {
  1039. setmode(0);
  1040. setop(0);
  1041. setsr(0xf);
  1042. setcolor(image->bg_color);
  1043. selectmask();
  1044. setmask(0xff);
  1045. for (y = 0; y < image->height; y++) {
  1046. dst = where;
  1047. for (x=image->width/8; x--;){
  1048. rmw(dst);
  1049. setcolor(image->fg_color);
  1050. selectmask();
  1051. if (*cdat) {
  1052. setmask(*cdat++);
  1053. rmw(dst++);
  1054. }
  1055. }
  1056. where += info->fix.line_length;
  1057. }
  1058. }
  1059. } else
  1060. vga_8planes_imageblit(info, image);
  1061. break;
  1062. case FB_TYPE_PACKED_PIXELS:
  1063. default:
  1064. cfb_imageblit(info, image);
  1065. break;
  1066. }
  1067. }
  1068. static void vga_imageblit_color(struct fb_info *info, const struct fb_image *image)
  1069. {
  1070. /*
  1071. * Draw logo
  1072. */
  1073. struct vga16fb_par *par = info->par;
  1074. char __iomem *where =
  1075. info->screen_base + image->dy * info->fix.line_length +
  1076. image->dx/8;
  1077. const char *cdat = image->data;
  1078. char __iomem *dst;
  1079. int x, y;
  1080. switch (info->fix.type) {
  1081. case FB_TYPE_VGA_PLANES:
  1082. if (info->fix.type_aux == FB_AUX_VGA_PLANES_VGA4 &&
  1083. par->isVGA) {
  1084. setsr(0xf);
  1085. setop(0);
  1086. setmode(0);
  1087. for (y = 0; y < image->height; y++) {
  1088. for (x = 0; x < image->width; x++) {
  1089. dst = where + x/8;
  1090. setcolor(*cdat);
  1091. selectmask();
  1092. setmask(1 << (7 - (x % 8)));
  1093. fb_readb(dst);
  1094. fb_writeb(0, dst);
  1095. cdat++;
  1096. }
  1097. where += info->fix.line_length;
  1098. }
  1099. }
  1100. break;
  1101. case FB_TYPE_PACKED_PIXELS:
  1102. cfb_imageblit(info, image);
  1103. break;
  1104. default:
  1105. break;
  1106. }
  1107. }
  1108. static void vga16fb_imageblit(struct fb_info *info, const struct fb_image *image)
  1109. {
  1110. if (image->depth == 1)
  1111. vga_imageblit_expand(info, image);
  1112. else
  1113. vga_imageblit_color(info, image);
  1114. }
  1115. static void vga16fb_destroy(struct fb_info *info)
  1116. {
  1117. iounmap(info->screen_base);
  1118. fb_dealloc_cmap(&info->cmap);
  1119. /* XXX unshare VGA regions */
  1120. framebuffer_release(info);
  1121. }
  1122. static struct fb_ops vga16fb_ops = {
  1123. .owner = THIS_MODULE,
  1124. .fb_open = vga16fb_open,
  1125. .fb_release = vga16fb_release,
  1126. .fb_destroy = vga16fb_destroy,
  1127. .fb_check_var = vga16fb_check_var,
  1128. .fb_set_par = vga16fb_set_par,
  1129. .fb_setcolreg = vga16fb_setcolreg,
  1130. .fb_pan_display = vga16fb_pan_display,
  1131. .fb_blank = vga16fb_blank,
  1132. .fb_fillrect = vga16fb_fillrect,
  1133. .fb_copyarea = vga16fb_copyarea,
  1134. .fb_imageblit = vga16fb_imageblit,
  1135. };
  1136. #ifndef MODULE
  1137. static int __init vga16fb_setup(char *options)
  1138. {
  1139. char *this_opt;
  1140. if (!options || !*options)
  1141. return 0;
  1142. while ((this_opt = strsep(&options, ",")) != NULL) {
  1143. if (!*this_opt) continue;
  1144. }
  1145. return 0;
  1146. }
  1147. #endif
  1148. static int vga16fb_probe(struct platform_device *dev)
  1149. {
  1150. struct fb_info *info;
  1151. struct vga16fb_par *par;
  1152. int i;
  1153. int ret = 0;
  1154. printk(KERN_DEBUG "vga16fb: initializing\n");
  1155. info = framebuffer_alloc(sizeof(struct vga16fb_par), &dev->dev);
  1156. if (!info) {
  1157. ret = -ENOMEM;
  1158. goto err_fb_alloc;
  1159. }
  1160. info->apertures = alloc_apertures(1);
  1161. if (!info->apertures) {
  1162. ret = -ENOMEM;
  1163. goto err_ioremap;
  1164. }
  1165. /* XXX share VGA_FB_PHYS and I/O region with vgacon and others */
  1166. info->screen_base = (void __iomem *)VGA_MAP_MEM(VGA_FB_PHYS, 0);
  1167. if (!info->screen_base) {
  1168. printk(KERN_ERR "vga16fb: unable to map device\n");
  1169. ret = -ENOMEM;
  1170. goto err_ioremap;
  1171. }
  1172. printk(KERN_INFO "vga16fb: mapped to 0x%p\n", info->screen_base);
  1173. par = info->par;
  1174. par->isVGA = screen_info.orig_video_isVGA;
  1175. par->palette_blanked = 0;
  1176. par->vesa_blanked = 0;
  1177. i = par->isVGA? 6 : 2;
  1178. vga16fb_defined.red.length = i;
  1179. vga16fb_defined.green.length = i;
  1180. vga16fb_defined.blue.length = i;
  1181. /* name should not depend on EGA/VGA */
  1182. info->fbops = &vga16fb_ops;
  1183. info->var = vga16fb_defined;
  1184. info->fix = vga16fb_fix;
  1185. /* supports rectangles with widths of multiples of 8 */
  1186. info->pixmap.blit_x = 1 << 7 | 1 << 15 | 1 << 23 | 1 << 31;
  1187. info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
  1188. FBINFO_HWACCEL_YPAN;
  1189. i = (info->var.bits_per_pixel == 8) ? 256 : 16;
  1190. ret = fb_alloc_cmap(&info->cmap, i, 0);
  1191. if (ret) {
  1192. printk(KERN_ERR "vga16fb: unable to allocate colormap\n");
  1193. ret = -ENOMEM;
  1194. goto err_alloc_cmap;
  1195. }
  1196. if (vga16fb_check_var(&info->var, info)) {
  1197. printk(KERN_ERR "vga16fb: unable to validate variable\n");
  1198. ret = -EINVAL;
  1199. goto err_check_var;
  1200. }
  1201. vga16fb_update_fix(info);
  1202. info->apertures->ranges[0].base = VGA_FB_PHYS;
  1203. info->apertures->ranges[0].size = VGA_FB_PHYS_LEN;
  1204. if (register_framebuffer(info) < 0) {
  1205. printk(KERN_ERR "vga16fb: unable to register framebuffer\n");
  1206. ret = -EINVAL;
  1207. goto err_check_var;
  1208. }
  1209. fb_info(info, "%s frame buffer device\n", info->fix.id);
  1210. platform_set_drvdata(dev, info);
  1211. return 0;
  1212. err_check_var:
  1213. fb_dealloc_cmap(&info->cmap);
  1214. err_alloc_cmap:
  1215. iounmap(info->screen_base);
  1216. err_ioremap:
  1217. framebuffer_release(info);
  1218. err_fb_alloc:
  1219. return ret;
  1220. }
  1221. static int vga16fb_remove(struct platform_device *dev)
  1222. {
  1223. struct fb_info *info = platform_get_drvdata(dev);
  1224. if (info)
  1225. unregister_framebuffer(info);
  1226. return 0;
  1227. }
  1228. static struct platform_driver vga16fb_driver = {
  1229. .probe = vga16fb_probe,
  1230. .remove = vga16fb_remove,
  1231. .driver = {
  1232. .name = "vga16fb",
  1233. },
  1234. };
  1235. static struct platform_device *vga16fb_device;
  1236. static int __init vga16fb_init(void)
  1237. {
  1238. int ret;
  1239. #ifndef MODULE
  1240. char *option = NULL;
  1241. if (fb_get_options("vga16fb", &option))
  1242. return -ENODEV;
  1243. vga16fb_setup(option);
  1244. #endif
  1245. ret = platform_driver_register(&vga16fb_driver);
  1246. if (!ret) {
  1247. vga16fb_device = platform_device_alloc("vga16fb", 0);
  1248. if (vga16fb_device)
  1249. ret = platform_device_add(vga16fb_device);
  1250. else
  1251. ret = -ENOMEM;
  1252. if (ret) {
  1253. platform_device_put(vga16fb_device);
  1254. platform_driver_unregister(&vga16fb_driver);
  1255. }
  1256. }
  1257. return ret;
  1258. }
  1259. static void __exit vga16fb_exit(void)
  1260. {
  1261. platform_device_unregister(vga16fb_device);
  1262. platform_driver_unregister(&vga16fb_driver);
  1263. }
  1264. MODULE_DESCRIPTION("Legacy VGA framebuffer device driver");
  1265. MODULE_LICENSE("GPL");
  1266. module_init(vga16fb_init);
  1267. module_exit(vga16fb_exit);
  1268. /*
  1269. * Overrides for Emacs so that we follow Linus's tabbing style.
  1270. * ---------------------------------------------------------------------------
  1271. * Local variables:
  1272. * c-basic-offset: 8
  1273. * End:
  1274. */