hgafb.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:23k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/drivers/video/hgafb.c -- Hercules graphics adaptor frame buffer device
  3.  * 
  4.  *      Created 25 Nov 1999 by Ferenc Bakonyi (fero@drama.obuda.kando.hu)
  5.  *      Based on skeletonfb.c by Geert Uytterhoeven and
  6.  *               mdacon.c by Andrew Apted
  7.  *
  8.  * History:
  9.  *
  10.  * - Revision 0.1.7 (23 Jan 2001): fix crash resulting from MDA only cards 
  11.  *    being detected as Hercules.  (Paul G.)
  12.  * - Revision 0.1.6 (17 Aug 2000): new style structs
  13.  *                                 documentation
  14.  * - Revision 0.1.5 (13 Mar 2000): spinlocks instead of saveflags();cli();etc
  15.  *                                 minor fixes
  16.  * - Revision 0.1.4 (24 Jan 2000): fixed a bug in hga_card_detect() for 
  17.  *                                  HGA-only systems
  18.  * - Revision 0.1.3 (22 Jan 2000): modified for the new fb_info structure
  19.  *                                 screen is cleared after rmmod
  20.  *                                 virtual resolutions
  21.  *                                 kernel parameter 'video=hga:font:{fontname}'
  22.  *                                 module parameter 'font={fontname}'
  23.  *                                 module parameter 'nologo={0|1}'
  24.  *                                 the most important: boot logo :)
  25.  * - Revision 0.1.0  (6 Dec 1999): faster scrolling and minor fixes
  26.  * - First release  (25 Nov 1999)
  27.  *
  28.  * This file is subject to the terms and conditions of the GNU General Public
  29.  * License.  See the file COPYING in the main directory of this archive
  30.  * for more details.
  31.  */
  32. #include <linux/module.h>
  33. #include <linux/kernel.h>
  34. #include <linux/errno.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/string.h>
  37. #include <linux/mm.h>
  38. #include <linux/tty.h>
  39. #include <linux/slab.h>
  40. #include <linux/delay.h>
  41. #include <linux/fb.h>
  42. #include <linux/init.h>
  43. #include <linux/ioport.h>
  44. #include <asm/io.h>
  45. #include <asm/vga.h>
  46. #include <video/fbcon.h>
  47. #include <video/fbcon-hga.h>
  48. #ifdef MODULE
  49. #define INCLUDE_LINUX_LOGO_DATA
  50. #include <linux/linux_logo.h>
  51. #endif /* MODULE */
  52. #if 0
  53. #define DPRINTK(args...) printk(KERN_DEBUG __FILE__": " ##args)
  54. #else
  55. #define DPRINTK(args...)
  56. #endif
  57. #if 0
  58. #define CHKINFO(ret) if (info != &fb_info) { printk(KERN_DEBUG __FILE__": This should never happen, line:%d n", __LINE__); return ret; }
  59. #else
  60. #define CHKINFO(ret)
  61. #endif
  62. /* Description of the hardware layout */
  63. static unsigned long hga_vram_base; /* Base of video memory */
  64. static unsigned long hga_vram_len; /* Size of video memory */
  65. #define HGA_TXT 0
  66. #define HGA_GFX 1
  67. static int hga_mode = -1; /* 0 = txt, 1 = gfx mode */
  68. static enum { TYPE_HERC, TYPE_HERCPLUS, TYPE_HERCCOLOR } hga_type;
  69. static char *hga_type_name;
  70. #define HGA_INDEX_PORT 0x3b4 /* Register select port */
  71. #define HGA_VALUE_PORT 0x3b5 /* Register value port */
  72. #define HGA_MODE_PORT 0x3b8 /* Mode control port */
  73. #define HGA_STATUS_PORT 0x3ba /* Status and Config port */
  74. #define HGA_GFX_PORT 0x3bf /* Graphics control port */
  75. /* HGA register values */
  76. #define HGA_CURSOR_BLINKING 0x00
  77. #define HGA_CURSOR_OFF 0x20
  78. #define HGA_CURSOR_SLOWBLINK 0x60
  79. #define HGA_MODE_GRAPHICS 0x02
  80. #define HGA_MODE_VIDEO_EN 0x08
  81. #define HGA_MODE_BLINK_EN 0x20
  82. #define HGA_MODE_GFX_PAGE1 0x80
  83. #define HGA_STATUS_HSYNC 0x01
  84. #define HGA_STATUS_VSYNC 0x80
  85. #define HGA_STATUS_VIDEO 0x08
  86. #define HGA_CONFIG_COL132 0x08
  87. #define HGA_GFX_MODE_EN 0x01
  88. #define HGA_GFX_PAGE_EN 0x02
  89. /* Global locks */
  90. static spinlock_t hga_reg_lock = SPIN_LOCK_UNLOCKED;
  91. /* Framebuffer driver structures */
  92. static struct fb_var_screeninfo hga_default_var = {
  93. xres: 720,
  94. yres: 348,
  95. xres_virtual: 720,
  96. yres_virtual: 348,
  97. xoffset: 0,
  98. yoffset: 0,
  99. bits_per_pixel: 1,
  100. grayscale: 0,
  101. red: {0, 1, 0},
  102. green: {0, 1, 0},
  103. blue: {0, 1, 0},
  104. transp: {0, 0, 0},
  105. nonstd: 0, /* (FB_NONSTD_HGA ?) */
  106. activate: 0,
  107. height: -1,
  108. width: -1,
  109. accel_flags: 0,
  110. /* pixclock */
  111. /* left_margin, right_margin */
  112. /* upper_margin, lower_margin */
  113. /* hsync_len, vsync_len */
  114. /* sync */
  115. /* vmode */
  116. };
  117. static struct fb_fix_screeninfo hga_fix = {
  118. id: "HGA",
  119. smem_start: (unsigned long) NULL,
  120. smem_len: 0,
  121. type: FB_TYPE_PACKED_PIXELS, /* (not sure) */
  122. type_aux: 0, /* (not sure) */
  123. visual: FB_VISUAL_MONO10,
  124. xpanstep: 8,
  125. ypanstep: 8,
  126. ywrapstep: 0,
  127. line_length: 90,
  128. mmio_start: 0,
  129. mmio_len: 0,
  130. accel: FB_ACCEL_NONE
  131. };
  132. static struct fb_info fb_info;
  133. static struct display disp;
  134. /* Don't assume that tty1 will be the initial current console. */
  135. static int currcon = -1; 
  136. static int release_io_port = 0;
  137. static int release_io_ports = 0;
  138. #ifdef MODULE
  139. static char *font = NULL;
  140. static int nologo = 0;
  141. #endif
  142. /* -------------------------------------------------------------------------
  143.  *
  144.  * Low level hardware functions
  145.  *
  146.  * ------------------------------------------------------------------------- */
  147. static void write_hga_b(unsigned int val, unsigned char reg)
  148. {
  149. outb_p(reg, HGA_INDEX_PORT); 
  150. outb_p(val, HGA_VALUE_PORT);
  151. }
  152. static void write_hga_w(unsigned int val, unsigned char reg)
  153. {
  154. outb_p(reg,   HGA_INDEX_PORT); outb_p(val >> 8,   HGA_VALUE_PORT);
  155. outb_p(reg+1, HGA_INDEX_PORT); outb_p(val & 0xff, HGA_VALUE_PORT);
  156. }
  157. static int test_hga_b(unsigned char val, unsigned char reg)
  158. {
  159. outb_p(reg, HGA_INDEX_PORT); 
  160. outb  (val, HGA_VALUE_PORT);
  161. udelay(20); val = (inb_p(HGA_VALUE_PORT) == val);
  162. return val;
  163. }
  164. static void hga_clear_screen(void)
  165. {
  166. unsigned char fillchar = 0xbf; /* magic */
  167. unsigned long flags;
  168. spin_lock_irqsave(&hga_reg_lock, flags);
  169. if (hga_mode == HGA_TXT)
  170. fillchar = ' ';
  171. else if (hga_mode == HGA_GFX)
  172. fillchar = 0x00;
  173. spin_unlock_irqrestore(&hga_reg_lock, flags);
  174. if (fillchar != 0xbf)
  175. isa_memset_io(hga_vram_base, fillchar, hga_vram_len);
  176. }
  177. #ifdef MODULE
  178. static void hga_txt_mode(void)
  179. {
  180. unsigned long flags;
  181. spin_lock_irqsave(&hga_reg_lock, flags);
  182. outb_p(HGA_MODE_VIDEO_EN | HGA_MODE_BLINK_EN, HGA_MODE_PORT);
  183. outb_p(0x00, HGA_GFX_PORT);
  184. outb_p(0x00, HGA_STATUS_PORT);
  185. write_hga_b(0x61, 0x00); /* horizontal total */
  186. write_hga_b(0x50, 0x01); /* horizontal displayed */
  187. write_hga_b(0x52, 0x02); /* horizontal sync pos */
  188. write_hga_b(0x0f, 0x03); /* horizontal sync width */
  189. write_hga_b(0x19, 0x04); /* vertical total */
  190. write_hga_b(0x06, 0x05); /* vertical total adjust */
  191. write_hga_b(0x19, 0x06); /* vertical displayed */
  192. write_hga_b(0x19, 0x07); /* vertical sync pos */
  193. write_hga_b(0x02, 0x08); /* interlace mode */
  194. write_hga_b(0x0d, 0x09); /* maximum scanline */
  195. write_hga_b(0x0c, 0x0a); /* cursor start */
  196. write_hga_b(0x0d, 0x0b); /* cursor end */
  197. write_hga_w(0x0000, 0x0c); /* start address */
  198. write_hga_w(0x0000, 0x0e); /* cursor location */
  199. hga_mode = HGA_TXT;
  200. spin_unlock_irqrestore(&hga_reg_lock, flags);
  201. }
  202. #endif /* MODULE */
  203. static void hga_gfx_mode(void)
  204. {
  205. unsigned long flags;
  206. spin_lock_irqsave(&hga_reg_lock, flags);
  207. outb_p(0x00, HGA_STATUS_PORT);
  208. outb_p(HGA_GFX_MODE_EN, HGA_GFX_PORT);
  209. outb_p(HGA_MODE_VIDEO_EN | HGA_MODE_GRAPHICS, HGA_MODE_PORT);
  210. write_hga_b(0x35, 0x00); /* horizontal total */
  211. write_hga_b(0x2d, 0x01); /* horizontal displayed */
  212. write_hga_b(0x2e, 0x02); /* horizontal sync pos */
  213. write_hga_b(0x07, 0x03); /* horizontal sync width */
  214. write_hga_b(0x5b, 0x04); /* vertical total */
  215. write_hga_b(0x02, 0x05); /* vertical total adjust */
  216. write_hga_b(0x57, 0x06); /* vertical displayed */
  217. write_hga_b(0x57, 0x07); /* vertical sync pos */
  218. write_hga_b(0x02, 0x08); /* interlace mode */
  219. write_hga_b(0x03, 0x09); /* maximum scanline */
  220. write_hga_b(0x00, 0x0a); /* cursor start */
  221. write_hga_b(0x00, 0x0b); /* cursor end */
  222. write_hga_w(0x0000, 0x0c); /* start address */
  223. write_hga_w(0x0000, 0x0e); /* cursor location */
  224. hga_mode = HGA_GFX;
  225. spin_unlock_irqrestore(&hga_reg_lock, flags);
  226. }
  227. #ifdef MODULE
  228. static void hga_show_logo(void)
  229. {
  230. int x, y;
  231. unsigned long dest = hga_vram_base;
  232. char *logo = linux_logo_bw;
  233. for (y = 134; y < 134 + 80 ; y++) /* this needs some cleanup */
  234. for (x = 0; x < 10 ; x++)
  235. isa_writeb(~*(logo++),
  236.    (dest + (y%4)*8192 + (y>>2)*90 + x + 40));
  237. }
  238. #endif /* MODULE */
  239. static void hga_pan(unsigned int xoffset, unsigned int yoffset)
  240. {
  241. unsigned int base;
  242. unsigned long flags;
  243. base = (yoffset / 8) * 90 + xoffset;
  244. spin_lock_irqsave(&hga_reg_lock, flags);
  245. write_hga_w(base, 0x0c); /* start address */
  246. spin_unlock_irqrestore(&hga_reg_lock, flags);
  247. DPRINTK("hga_pan: base:%dn", base);
  248. }
  249. static void hga_blank(int blank_mode)
  250. {
  251. unsigned long flags;
  252. spin_lock_irqsave(&hga_reg_lock, flags);
  253. if (blank_mode) {
  254. outb_p(0x00, HGA_MODE_PORT); /* disable video */
  255. } else {
  256. outb_p(HGA_MODE_VIDEO_EN | HGA_MODE_GRAPHICS, HGA_MODE_PORT);
  257. }
  258. spin_unlock_irqrestore(&hga_reg_lock, flags);
  259. }
  260. static int __init hga_card_detect(void)
  261. {
  262. int count=0;
  263. unsigned long p, q;
  264. unsigned short p_save, q_save;
  265. hga_vram_base = 0xb0000;
  266. hga_vram_len  = 0x08000;
  267. if (request_region(0x3b0, 12, "hgafb"))
  268. release_io_ports = 1;
  269. if (request_region(0x3bf, 1, "hgafb"))
  270. release_io_port = 1;
  271. /* do a memory check */
  272. p = hga_vram_base;
  273. q = hga_vram_base + 0x01000;
  274. p_save = isa_readw(p); q_save = isa_readw(q);
  275. isa_writew(0xaa55, p); if (isa_readw(p) == 0xaa55) count++;
  276. isa_writew(0x55aa, p); if (isa_readw(p) == 0x55aa) count++;
  277. isa_writew(p_save, p);
  278. if (count != 2) {
  279. return 0;
  280. }
  281. /* Ok, there is definitely a card registering at the correct
  282.  * memory location, so now we do an I/O port test.
  283.  */
  284. if (!test_hga_b(0x66, 0x0f)) {     /* cursor low register */
  285. return 0;
  286. }
  287. if (!test_hga_b(0x99, 0x0f)) {     /* cursor low register */
  288. return 0;
  289. }
  290. /* See if the card is a Hercules, by checking whether the vsync
  291.  * bit of the status register is changing.  This test lasts for
  292.  * approximately 1/10th of a second.
  293.  */
  294. p_save = q_save = inb_p(HGA_STATUS_PORT) & HGA_STATUS_VSYNC;
  295. for (count=0; count < 50000 && p_save == q_save; count++) {
  296. q_save = inb(HGA_STATUS_PORT) & HGA_STATUS_VSYNC;
  297. udelay(2);
  298. }
  299. if (p_save == q_save) 
  300. return 0;
  301. switch (inb_p(HGA_STATUS_PORT) & 0x70) {
  302. case 0x10:
  303. hga_type = TYPE_HERCPLUS;
  304. hga_type_name = "HerculesPlus";
  305. break;
  306. case 0x50:
  307. hga_type = TYPE_HERCCOLOR;
  308. hga_type_name = "HerculesColor";
  309. break;
  310. default:
  311. hga_type = TYPE_HERC;
  312. hga_type_name = "Hercules";
  313. break;
  314. }
  315. return 1;
  316. }
  317. /* ------------------------------------------------------------------------- *
  318.  *
  319.  * dispsw functions
  320.  *
  321.  * ------------------------------------------------------------------------- */
  322. /**
  323.  * hga_get_fix - get the fixed part of the display
  324.  * @fix:struct fb_fix_screeninfo to fill in
  325.  * @con:unused
  326.  * @info:pointer to fb_info object containing info for current hga board
  327.  *
  328.  * This wrapper function copies @info->fix to @fix.
  329.  * A zero is returned on success and %-EINVAL for failure.
  330.  */
  331. int hga_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
  332. {
  333. CHKINFO(-EINVAL);
  334. DPRINTK("hga_get_fix: con:%d, info:%x, fb_info:%xn", con, (unsigned)info, (unsigned)&fb_info);
  335. *fix = info->fix;
  336. return 0;
  337. }
  338. /**
  339.  * hga_get_var - get the user defined part of the display
  340.  * @var:struct fb_var_screeninfo to fill in
  341.  * @con:unused
  342.  * @info:pointer to fb_info object containing info for current hga board
  343.  *
  344.  * This wrapper function copies @info->var to @var.
  345.  * A zero is returned on success and %-EINVAL for failure.
  346.  */
  347. int hga_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
  348. {
  349. CHKINFO(-EINVAL);
  350. DPRINTK("hga_get_var: con:%d, info:%x, fb_info:%xn", con, (unsigned)info, (unsigned)&fb_info);
  351. *var = info->var;
  352. return 0;
  353. }
  354. /**
  355.  * hga_set_var - set the user defined part of the display
  356.  * @var:new video mode
  357.  * @con:unused
  358.  * @info:pointer to fb_info object containing info for current hga board
  359.  *
  360.  * This function is called for changing video modes. Since HGA cards have
  361.  * only one fixed mode we have not much to do. After checking input 
  362.  * parameters @var is copied to @info->var and @info->changevar is called.
  363.  * A zero is returned on success and %-EINVAL for failure.
  364.  *
  365.  * FIXME:
  366.  * This is the most mystical function (at least for me).
  367.  * What is the exact specification of xxx_set_var()?
  368.  * Should it handle xoffset, yoffset? Should it do panning?
  369.  * What does vmode mean?
  370.  */
  371. int hga_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
  372. {
  373. CHKINFO(-EINVAL);
  374. DPRINTK("hga_set_var: con:%d, activate:%x, info:0x%x, fb_info:%xn", con, var->activate, (unsigned)info, (unsigned)&fb_info);
  375. if (var->xres != 720 || var->yres != 348 ||
  376.     var->xres_virtual != 720 ||
  377.     var->yres_virtual < 348 || var->yres_virtual > 348 + 16 ||
  378.     var->bits_per_pixel != 1 || var->grayscale != 0) {
  379. return -EINVAL;
  380. }
  381. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
  382. info->var = *var;
  383. if (info->changevar) 
  384. (*info->changevar)(con);
  385. }
  386. return 0;
  387. }
  388. /**
  389.  * hga_getcolreg - read color registers
  390.  * @regno:register index to read out
  391.  * @red:red value
  392.  * @green:green value
  393.  * @blue:blue value
  394.  * @transp:transparency value
  395.  * @info:unused
  396.  *
  397.  * This callback function is used to read the color registers of a HGA
  398.  * board. Since we have only two fixed colors, RGB values are 0x0000 
  399.  * for register0 and 0xaaaa for register1.
  400.  * A zero is returned on success and 1 for failure.
  401.  */
  402. static int hga_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
  403.  u_int *transp, struct fb_info *info)
  404. {
  405. if (regno == 0) {
  406. *red = *green = *blue = 0x0000;
  407. *transp = 0;
  408. } else if (regno == 1) {
  409. *red = *green = *blue = 0xaaaa;
  410. *transp = 0;
  411. } else
  412. return 1;
  413. return 0;
  414. }
  415. /**
  416.  * hga_get_cmap - get the colormap
  417.  * @cmap:struct fb_cmap to fill in
  418.  * @kspc:called from kernel space?
  419.  * @con:unused
  420.  * @info:pointer to fb_info object containing info for current hga board
  421.  *
  422.  * This wrapper function passes it's input parameters to fb_get_cmap().
  423.  * Callback function hga_getcolreg() is used to read the color registers.
  424.  */
  425. int hga_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  426.                  struct fb_info *info)
  427. {
  428. CHKINFO(-EINVAL);
  429. DPRINTK("hga_get_cmap: con:%dn", con);
  430. return fb_get_cmap(cmap, kspc, hga_getcolreg, info);
  431. }
  432. /**
  433.  * hga_setcolreg - set color registers
  434.  * @regno:register index to set
  435.  * @red:red value, unused
  436.  * @green:green value, unused
  437.  * @blue:blue value, unused
  438.  * @transp:transparency value, unused
  439.  * @info:unused
  440.  *
  441.  * This callback function is used to set the color registers of a HGA
  442.  * board. Since we have only two fixed colors only @regno is checked.
  443.  * A zero is returned on success and 1 for failure.
  444.  */
  445. static int hga_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  446.  u_int transp, struct fb_info *info)
  447. {
  448. if (regno > 1)
  449. return 1;
  450. return 0;
  451. }
  452. /**
  453.  * hga_set_cmap - set the colormap
  454.  * @cmap:struct fb_cmap to set
  455.  * @kspc:called from kernel space?
  456.  * @con:unused
  457.  * @info:pointer to fb_info object containing info for current hga board
  458.  *
  459.  * This wrapper function passes it's input parameters to fb_set_cmap().
  460.  * Callback function hga_setcolreg() is used to set the color registers.
  461.  */
  462. int hga_set_cmap(struct fb_cmap *cmap, int kspc, int con,
  463.                  struct fb_info *info)
  464. {
  465. CHKINFO(-EINVAL);
  466. DPRINTK("hga_set_cmap: con:%dn", con);
  467. return fb_set_cmap(cmap, kspc, hga_setcolreg, info);
  468. }
  469. /**
  470.  * hga_pan_display - pan or wrap the display
  471.  * @var:contains new xoffset, yoffset and vmode values
  472.  * @con:unused
  473.  * @info:pointer to fb_info object containing info for current hga board
  474.  *
  475.  * This function looks only at xoffset, yoffset and the %FB_VMODE_YWRAP
  476.  * flag in @var. If input parameters are correct it calls hga_pan() to 
  477.  * program the hardware. @info->var is updated to the new values.
  478.  * A zero is returned on success and %-EINVAL for failure.
  479.  */
  480. int hga_pan_display(struct fb_var_screeninfo *var, int con,
  481.                     struct fb_info *info)
  482. {
  483. CHKINFO(-EINVAL);
  484. DPRINTK("pan_disp: con:%d, wrap:%d, xoff:%d, yoff:%dn", con, var->vmode & FB_VMODE_YWRAP, var->xoffset, var->yoffset);
  485. if (var->vmode & FB_VMODE_YWRAP) {
  486. if (var->yoffset < 0 || 
  487.     var->yoffset >= info->var.yres_virtual ||
  488.     var->xoffset)
  489. return -EINVAL;
  490. } else {
  491. if (var->xoffset + var->xres > info->var.xres_virtual
  492.  || var->yoffset + var->yres > info->var.yres_virtual
  493.  || var->yoffset % 8)
  494. return -EINVAL;
  495. }
  496. hga_pan(var->xoffset, var->yoffset);
  497. info->var.xoffset = var->xoffset;
  498. info->var.yoffset = var->yoffset;
  499. if (var->vmode & FB_VMODE_YWRAP)
  500. info->var.vmode |= FB_VMODE_YWRAP;
  501. else
  502. info->var.vmode &= ~FB_VMODE_YWRAP;
  503. return 0;
  504. }
  505.     
  506. static struct fb_ops hgafb_ops = {
  507. owner: THIS_MODULE,
  508. fb_get_fix: hga_get_fix,
  509. fb_get_var: hga_get_var,
  510. fb_set_var: hga_set_var,
  511. fb_get_cmap: hga_get_cmap,
  512. fb_set_cmap: hga_set_cmap,
  513. fb_pan_display: hga_pan_display,
  514. };
  515. /* ------------------------------------------------------------------------- *
  516.  *
  517.  * Functions in fb_info
  518.  * 
  519.  * ------------------------------------------------------------------------- */
  520. /**
  521.  * hgafbcon_switch - switch console
  522.  * @con:new console to switch to
  523.  * @info:pointer to fb_info object containing info for current hga board
  524.  *
  525.  * This function should install a new colormap and change the video mode.
  526.  * Since we have fixed colors and only one video mode we have nothing to 
  527.  * do.
  528.  * Only console administration is done but it should go to fbcon.c IMHO.
  529.  * A zero is returned on success and %-EINVAL for failure.
  530.  */
  531. static int hgafbcon_switch(int con, struct fb_info *info)
  532. {
  533. CHKINFO(-EINVAL);
  534. DPRINTK("hgafbcon_switch: currcon:%d, con:%d, info:%x, fb_info:%xn", currcon, con, (unsigned)info, (unsigned)&fb_info);
  535. /* Save the colormap and video mode */
  536. #if 0 /* Not necessary in hgafb, we use fixed colormap */
  537. fb_copy_cmap(&info->cmap, &fb_display[currcon].cmap, 0);
  538. #endif
  539. if (currcon != -1) /* this check is absolute necessary! */
  540. memcpy(&fb_display[currcon].var, &info->var,
  541. sizeof(struct fb_var_screeninfo));
  542. /* Install a new colormap and change the video mode. By default fbcon
  543.  * sets all the colormaps and video modes to the default values at
  544.  * bootup.
  545.  */
  546. #if 0
  547. fb_copy_cmap(&fb_display[con].cmap, &info->cmap, 0);
  548. fb_set_cmap(&info->cmap, 1, hga_setcolreg, info);
  549. #endif
  550. memcpy(&info->var, &fb_display[con].var,
  551. sizeof(struct fb_var_screeninfo));
  552. /* hga_set_var(&info->var, con, &fb_info); is it necessary? */
  553. currcon = con;
  554. /* Hack to work correctly with XF86_Mono */
  555. hga_gfx_mode();
  556. return 0;
  557. }
  558. /**
  559.  * hgafbcon_updatevar - update the user defined part of the display
  560.  * @con:console to update or -1 when no consoles defined on this fb
  561.  * @info:pointer to fb_info object containing info for current hga board
  562.  *
  563.  * This function is called when @var is changed by fbcon.c without calling 
  564.  * hga_set_var(). It usually means scrolling.  hga_pan_display() is called
  565.  * to update the hardware and @info->var.
  566.  * A zero is returned on success and %-EINVAL for failure.
  567.  */
  568. static int hgafbcon_updatevar(int con, struct fb_info *info)
  569. {
  570. CHKINFO(-EINVAL);
  571. DPRINTK("hga_update_var: con:%d, info:%x, fb_info:%xn", con, (unsigned)info, (unsigned)&fb_info);
  572. return (con < 0) ? -EINVAL : hga_pan_display(&fb_display[con].var, con, info);
  573. }
  574. /**
  575.  * hgafbcon_blank - (un)blank the screen
  576.  * @blank_mode:blanking method to use
  577.  * @info:unused
  578.  *
  579.  * Blank the screen if blank_mode != 0, else unblank. 
  580.  * Implements VESA suspend and powerdown modes on hardware that supports 
  581.  * disabling hsync/vsync:
  582.  * @blank_mode == 2 means suspend vsync,
  583.  * @blank_mode == 3 means suspend hsync,
  584.  * @blank_mode == 4 means powerdown.
  585.  */
  586. static void hgafbcon_blank(int blank_mode, struct fb_info *info)
  587. {
  588. CHKINFO( );
  589. DPRINTK("hga_blank: blank_mode:%d, info:%x, fb_info:%xn", blank_mode, (unsigned)info, (unsigned)&fb_info);
  590. hga_blank(blank_mode);
  591. }
  592. /* ------------------------------------------------------------------------- */
  593.     
  594. /*
  595.  *  Initialization
  596.  */
  597. int __init hgafb_init(void)
  598. {
  599. if (! hga_card_detect()) {
  600. printk(KERN_ERR "hgafb: HGA card not detected.n");
  601. return -EINVAL;
  602. }
  603. printk(KERN_INFO "hgafb: %s with %ldK of memory detected.n",
  604. hga_type_name, hga_vram_len/1024);
  605. hga_gfx_mode();
  606. hga_clear_screen();
  607. #ifdef MODULE
  608. if (!nologo) hga_show_logo();
  609. #endif /* MODULE */
  610. hga_fix.smem_start = VGA_MAP_MEM(hga_vram_base);
  611. hga_fix.smem_len = hga_vram_len;
  612. disp.var = hga_default_var;
  613. /* disp.cmap = ???; */
  614. disp.screen_base = (char*)hga_fix.smem_start;
  615. disp.visual = hga_fix.visual;
  616. disp.type = hga_fix.type;
  617. disp.type_aux = hga_fix.type_aux;
  618. disp.ypanstep = hga_fix.ypanstep;
  619. disp.ywrapstep = hga_fix.ywrapstep;
  620. disp.line_length = hga_fix.line_length;
  621. disp.can_soft_blank = 1;
  622. disp.inverse = 0;
  623. #ifdef FBCON_HAS_HGA
  624. disp.dispsw = &fbcon_hga;
  625. #else
  626. #warning HGAFB will not work as a console!
  627. disp.dispsw = &fbcon_dummy;
  628. #endif
  629. disp.dispsw_data = NULL;
  630. disp.scrollmode = SCROLL_YREDRAW;
  631. strcpy (fb_info.modename, hga_fix.id);
  632. fb_info.node = -1;
  633. fb_info.flags = FBINFO_FLAG_DEFAULT;
  634. /* fb_info.open = ??? */
  635. fb_info.var = hga_default_var;
  636. fb_info.fix = hga_fix;
  637. fb_info.monspecs.hfmin = 0;
  638. fb_info.monspecs.hfmax = 0;
  639. fb_info.monspecs.vfmin = 10000;
  640. fb_info.monspecs.vfmax = 10000;
  641. fb_info.monspecs.dpms = 0;
  642. fb_info.fbops = &hgafb_ops;
  643. fb_info.screen_base = (char *)hga_fix.smem_start;
  644. fb_info.disp = &disp;
  645. /* fb_info.display_fg = ??? */
  646. /* fb_info.fontname initialized later */
  647. fb_info.changevar = NULL;
  648. fb_info.switch_con = hgafbcon_switch;
  649. fb_info.updatevar = hgafbcon_updatevar;
  650. fb_info.blank = hgafbcon_blank;
  651. fb_info.pseudo_palette = NULL; /* ??? */
  652. fb_info.par = NULL;
  653.         if (register_framebuffer(&fb_info) < 0)
  654.                 return -EINVAL;
  655.         printk(KERN_INFO "fb%d: %s frame buffer devicen",
  656.                GET_FB_IDX(fb_info.node), fb_info.modename);
  657. return 0;
  658. }
  659. /*
  660.  *  Setup
  661.  */
  662. #ifndef MODULE
  663. int __init hgafb_setup(char *options)
  664. {
  665. /* 
  666.  * Parse user speficied options
  667.  * `video=hga:font:VGA8x16' or
  668.  * `video=hga:font:SUN8x16' recommended
  669.  * Other supported fonts: VGA8x8, Acorn8x8, PEARL8x8
  670.  * More different fonts can be used with the `setfont' utility.
  671.  */
  672. char *this_opt;
  673. fb_info.fontname[0] = '';
  674. if (!options || !*options)
  675. return 0;
  676. while ((this_opt = strsep(&options, ","))) {
  677. if (!strncmp(this_opt, "font:", 5))
  678. strcpy(fb_info.fontname, this_opt+5);
  679. }
  680. return 0;
  681. }
  682. #endif /* !MODULE */
  683. /*
  684.  * Cleanup
  685.  */
  686. #ifdef MODULE
  687. static void hgafb_cleanup(struct fb_info *info)
  688. {
  689. hga_txt_mode();
  690. hga_clear_screen();
  691. unregister_framebuffer(info);
  692. if (release_io_ports) release_region(0x3b0, 12);
  693. if (release_io_port) release_region(0x3bf, 1);
  694. }
  695. #endif /* MODULE */
  696. /* -------------------------------------------------------------------------
  697.  *
  698.  *  Modularization
  699.  *
  700.  * ------------------------------------------------------------------------- */
  701. #ifdef MODULE
  702. int init_module(void)
  703. {
  704. if (font)
  705. strncpy(fb_info.fontname, font, sizeof(fb_info.fontname)-1);
  706. else
  707. fb_info.fontname[0] = '';
  708. return hgafb_init();
  709. }
  710. void cleanup_module(void)
  711. {
  712. hgafb_cleanup(&fb_info);
  713. }
  714. MODULE_AUTHOR("Ferenc Bakonyi (fero@drama.obuda.kando.hu)");
  715. MODULE_DESCRIPTION("FBDev driver for Hercules Graphics Adaptor");
  716. MODULE_LICENSE("GPL");
  717. MODULE_PARM(font, "s");
  718. MODULE_PARM_DESC(font, "Specifies one of the compiled-in fonts (VGA8x8, VGA8x16, SUN8x16, Acorn8x8, PEARL8x8) (default=none)");
  719. MODULE_PARM(nologo, "i");
  720. MODULE_PARM_DESC(nologo, "Disables startup logo if != 0 (default=0)");
  721. #endif /* MODULE */