vga16fb.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  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. */