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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *      linux/drivers/video/pmag-ba-fb.c
  3.  *
  4.  * PMAG-BA TurboChannel framebuffer card support ... derived from:
  5.  * "HP300 Topcat framebuffer support (derived from macfb of all things)
  6.  * Phil Blundell <philb@gnu.org> 1998", the original code can be
  7.  *      found in the file hpfb.c in the same directory.
  8.  *
  9.  * Based on digital document:
  10.  *  "PMAG-BA TURBOchannel Color Frame Buffer
  11.  *  Functional Specification", Revision 1.2, August 27, 1990
  12.  *
  13.  *      DECstation related code Copyright (C) 1999, 2000, 2001 by
  14.  *      Michael Engel <engel@unix-ag.org>, 
  15.  *      Karsten Merker <merker@linuxtag.org> and
  16.  * Harald Koerfgen.
  17.  *      This file is subject to the terms and conditions of the GNU General
  18.  *      Public License.  See the file COPYING in the main directory of this
  19.  *      archive for more details.
  20.  *
  21.  */
  22. #include <linux/module.h>
  23. #include <linux/kernel.h>
  24. #include <linux/sched.h>
  25. #include <linux/errno.h>
  26. #include <linux/string.h>
  27. #include <linux/timer.h>
  28. #include <linux/mm.h>
  29. #include <linux/tty.h>
  30. #include <linux/slab.h>
  31. #include <linux/delay.h>
  32. #include <linux/init.h>
  33. #include <linux/fb.h>
  34. #include <asm/bootinfo.h>
  35. #include <asm/dec/machtype.h>
  36. #include <asm/dec/tc.h>
  37. #include "pmag-ba-fb.h"
  38. #include <video/fbcon.h>
  39. #include <video/fbcon-mfb.h>
  40. #include <video/fbcon-cfb2.h>
  41. #include <video/fbcon-cfb4.h>
  42. #include <video/fbcon-cfb8.h>
  43. #define arraysize(x)    (sizeof(x)/sizeof(*(x)))
  44. struct pmag_ba_ramdac_regs {
  45. unsigned char addr_low;
  46. unsigned char pad0[3];
  47. unsigned char addr_hi;
  48. unsigned char pad1[3];
  49. unsigned char data;
  50. unsigned char pad2[3];
  51. unsigned char cmap;
  52. };
  53. struct pmag_ba_my_fb_info {
  54. struct fb_info info;
  55. struct pmag_ba_ramdac_regs *bt459_regs;
  56. unsigned long pmagba_fb_start;
  57. unsigned long pmagba_fb_size;
  58. unsigned long pmagba_fb_line_length;
  59. };
  60. static struct display disp;
  61. /*
  62.  * Max 3 TURBOchannel slots -> max 3 PMAG-BA :)
  63.  */
  64. static struct pmag_ba_my_fb_info pmagba_fb_info[3];
  65. static struct fb_var_screeninfo pmagbafb_defined = {
  66. 0, 0, 0, 0, /* W,H, W, H (virtual) load xres,xres_virtual */
  67. 0, 0, /* virtual -> visible no offset */
  68. 0, /* depth -> load bits_per_pixel */
  69. 0, /* greyscale ? */
  70. {0, 0, 0}, /* R */
  71. {0, 0, 0}, /* G */
  72. {0, 0, 0}, /* B */
  73. {0, 0, 0}, /* transparency */
  74. 0, /* standard pixel format */
  75. FB_ACTIVATE_NOW,
  76. 274, 195, /* 14" monitor */
  77. FB_ACCEL_NONE,
  78. 0L, 0L, 0L, 0L, 0L,
  79. 0L, 0L, 0, /* No sync info */
  80. FB_VMODE_NONINTERLACED,
  81. {0, 0, 0, 0, 0, 0}
  82. };
  83. struct pmagbafb_par {
  84. };
  85. static int currcon = 0;
  86. static struct pmagbafb_par current_par;
  87. static void pmagbafb_encode_var(struct fb_var_screeninfo *var,
  88. struct pmagbafb_par *par)
  89. {
  90. int i = 0;
  91. var->xres = 1024;
  92. var->yres = 864;
  93. var->xres_virtual = 1024;
  94. var->yres_virtual = 864;
  95. var->xoffset = 0;
  96. var->yoffset = 0;
  97. var->bits_per_pixel = 8;
  98. var->grayscale = 0;
  99. var->transp.offset = 0;
  100. var->transp.length = 0;
  101. var->transp.msb_right = 0;
  102. var->nonstd = 0;
  103. var->activate = 1;
  104. var->height = -1;
  105. var->width = -1;
  106. var->vmode = FB_VMODE_NONINTERLACED;
  107. var->pixclock = 0;
  108. var->sync = 0;
  109. var->left_margin = 0;
  110. var->right_margin = 0;
  111. var->upper_margin = 0;
  112. var->lower_margin = 0;
  113. var->hsync_len = 0;
  114. var->vsync_len = 0;
  115. for (i = 0; i < arraysize(var->reserved); i++)
  116. var->reserved[i] = 0;
  117. }
  118. static void pmagbafb_get_par(struct pmagbafb_par *par)
  119. {
  120. *par = current_par;
  121. }
  122. static int pmagba_fb_update_var(int con, struct fb_info *info)
  123. {
  124. return 0;
  125. }
  126. static int pmagba_do_fb_set_var(struct fb_var_screeninfo *var,
  127. int isactive)
  128. {
  129. struct pmagbafb_par par;
  130. pmagbafb_get_par(&par);
  131. pmagbafb_encode_var(var, &par);
  132. return 0;
  133. }
  134. /*
  135.  * Turn hardware cursor off
  136.  */
  137. void pmagbafb_erase_cursor(struct pmag_ba_my_fb_info *info)
  138. {
  139. info->bt459_regs->addr_low = 0;
  140. info->bt459_regs->addr_hi = 3;
  141. info->bt459_regs->data = 0;
  142. }
  143. /*
  144.  * Write to a Bt459 color map register
  145.  */
  146. void pmag_ba_bt459_write_colormap(struct pmag_ba_my_fb_info *info,
  147.   int reg, __u8 red, __u8 green, __u8 blue)
  148. {
  149. info->bt459_regs->addr_low = (__u8) reg;
  150. info->bt459_regs->addr_hi = 0;
  151. info->bt459_regs->cmap = red;
  152. info->bt459_regs->cmap = green;
  153. info->bt459_regs->cmap = blue;
  154. }
  155. /*
  156.  * Get the palette
  157.  */
  158. static int pmagbafb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  159.      struct fb_info *info)
  160. {
  161. unsigned int i;
  162. unsigned int length;
  163. if (((cmap->start) + (cmap->len)) >= 256) {
  164. length = 256 - (cmap->start);
  165. } else {
  166. length = cmap->len;
  167. }
  168. for (i = 0; i < length; i++) {
  169. /*
  170.  * TODO
  171.  */
  172. }
  173. return 0;
  174. }
  175. /*
  176.  * Set the palette. 
  177.  */
  178. static int pmagbafb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
  179.      struct fb_info *info)
  180. {
  181. unsigned int i;
  182. __u8 cmap_red, cmap_green, cmap_blue;
  183. unsigned int length;
  184. if (((cmap->start) + (cmap->len)) >= 256)
  185. length = 256 - (cmap->start);
  186. else
  187. length = cmap->len;
  188. for (i = 0; i < length; i++) {
  189. cmap_red = ((cmap->red[i]) >> 8); /* The cmap fields are 16 bits    */
  190. cmap_green = ((cmap->green[i]) >> 8); /* wide, but the harware colormap */
  191. cmap_blue = ((cmap->blue[i]) >> 8); /* registers are only 8 bits wide */
  192. pmag_ba_bt459_write_colormap((struct pmag_ba_my_fb_info *)
  193.      info, cmap->start + i,
  194.      cmap_red, cmap_green,
  195.      cmap_blue);
  196. }
  197. return 0;
  198. }
  199. static int pmagbafb_get_var(struct fb_var_screeninfo *var, int con,
  200.     struct fb_info *info)
  201. {
  202. struct pmagbafb_par par;
  203. if (con == -1) {
  204. pmagbafb_get_par(&par);
  205. pmagbafb_encode_var(var, &par);
  206. } else
  207. *var = fb_display[con].var;
  208. return 0;
  209. }
  210. static int pmagbafb_set_var(struct fb_var_screeninfo *var, int con,
  211.     struct fb_info *info)
  212. {
  213. int err;
  214. if ((err = pmagba_do_fb_set_var(var, 1)))
  215. return err;
  216. return 0;
  217. }
  218. static void pmagbafb_encode_fix(struct fb_fix_screeninfo *fix,
  219. struct pmagbafb_par *par,
  220. struct pmag_ba_my_fb_info *info)
  221. {
  222. memset(fix, 0, sizeof(struct fb_fix_screeninfo));
  223. strcpy(fix->id, "PMAG-BA");
  224. fix->smem_start = info->pmagba_fb_start;
  225. fix->smem_len = info->pmagba_fb_size;
  226. fix->type = FB_TYPE_PACKED_PIXELS;
  227. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  228. fix->xpanstep = 0;
  229. fix->ypanstep = 0;
  230. fix->ywrapstep = 0;
  231. fix->line_length = info->pmagba_fb_line_length;
  232. }
  233. static int pmagbafb_get_fix(struct fb_fix_screeninfo *fix, int con,
  234.     struct fb_info *info)
  235. {
  236. struct pmagbafb_par par;
  237. pmagbafb_get_par(&par);
  238. pmagbafb_encode_fix(fix, &par, (struct pmag_ba_my_fb_info *) info);
  239. return 0;
  240. }
  241. static int pmagbafb_ioctl(struct inode *inode, struct file *file,
  242.   unsigned int cmd, unsigned long arg, int con,
  243.   struct fb_info *info)
  244. {
  245. return -EINVAL;
  246. }
  247. static int pmagbafb_switch(int con, struct fb_info *info)
  248. {
  249. pmagba_do_fb_set_var(&fb_display[con].var, 1);
  250. currcon = con;
  251. return 0;
  252. }
  253. /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
  254. static void pmagbafb_blank(int blank, struct fb_info *info)
  255. {
  256. /* Not supported */
  257. }
  258. static int pmagbafb_open(struct fb_info *info, int user)
  259. {
  260. /*
  261.  * Nothing, only a usage count for the moment
  262.  */
  263. MOD_INC_USE_COUNT;
  264. return (0);
  265. }
  266. static void pmagbafb_set_disp(int con, struct pmag_ba_my_fb_info *info)
  267. {
  268. struct fb_fix_screeninfo fix;
  269. struct display *display;
  270. if (con >= 0)
  271. display = &fb_display[con];
  272. else
  273. display = &disp; /* used during initialization */
  274. pmagbafb_get_fix(&fix, con, (struct fb_info *) info);
  275. display->screen_base = (char *) fix.smem_start;
  276. display->visual = fix.visual;
  277. display->type = fix.type;
  278. display->type_aux = fix.type_aux;
  279. display->ypanstep = fix.ypanstep;
  280. display->ywrapstep = fix.ywrapstep;
  281. display->line_length = fix.line_length;
  282. display->next_line = fix.line_length;
  283. display->can_soft_blank = 0;
  284. display->inverse = 0;
  285. display->scrollmode = SCROLL_YREDRAW;
  286. display->dispsw = &fbcon_cfb8;
  287. }
  288. static int pmagbafb_release(struct fb_info *info, int user)
  289. {
  290. MOD_DEC_USE_COUNT;
  291. return (0);
  292. }
  293. static struct fb_ops pmagbafb_ops = {
  294. owner:THIS_MODULE,
  295. fb_open:pmagbafb_open,
  296. fb_release:pmagbafb_release,
  297. fb_get_fix:pmagbafb_get_fix,
  298. fb_get_var:pmagbafb_get_var,
  299. fb_set_var:pmagbafb_set_var,
  300. fb_get_cmap:pmagbafb_get_cmap,
  301. fb_set_cmap:pmagbafb_set_cmap,
  302. fb_ioctl:pmagbafb_ioctl,
  303. fb_mmap:0,
  304. fb_rasterimg:0
  305. };
  306. int __init pmagbafb_init_one(int slot)
  307. {
  308. unsigned long base_addr = get_tc_base_addr(slot);
  309. struct pmag_ba_my_fb_info *ip =
  310.     (struct pmag_ba_my_fb_info *) &pmagba_fb_info[slot];
  311. printk("PMAG-BA framebuffer in slot %dn", slot);
  312. /*
  313.  * Framebuffer display memory base address and friends
  314.  */
  315. ip->bt459_regs =
  316.     (struct pmag_ba_ramdac_regs *) (base_addr +
  317.     PMAG_BA_BT459_OFFSET);
  318. ip->pmagba_fb_start = base_addr + PMAG_BA_ONBOARD_FBMEM_OFFSET;
  319. ip->pmagba_fb_size = 1024 * 864;
  320. ip->pmagba_fb_line_length = 1024;
  321. /*
  322.  * Configure the Bt459 RAM DAC
  323.  */
  324. pmagbafb_erase_cursor(ip);
  325. /*
  326.  *      Fill in the available video resolution
  327.  */
  328. pmagbafb_defined.xres = 1024;
  329. pmagbafb_defined.yres = 864;
  330. pmagbafb_defined.xres_virtual = 1024;
  331. pmagbafb_defined.yres_virtual = 864;
  332. pmagbafb_defined.bits_per_pixel = 8;
  333. /*
  334.  *      Let there be consoles..
  335.  */
  336. strcpy(ip->info.modename, "PMAG-BA");
  337. ip->info.changevar = NULL;
  338. ip->info.node = -1;
  339. ip->info.fbops = &pmagbafb_ops;
  340. ip->info.disp = &disp;
  341. ip->info.switch_con = &pmagbafb_switch;
  342. ip->info.updatevar = &pmagba_fb_update_var;
  343. ip->info.blank = &pmagbafb_blank;
  344. ip->info.flags = FBINFO_FLAG_DEFAULT;
  345. pmagba_do_fb_set_var(&pmagbafb_defined, 1);
  346. pmagbafb_get_var(&disp.var, -1, (struct fb_info *) ip);
  347. pmagbafb_set_disp(-1, ip);
  348. if (register_framebuffer((struct fb_info *) ip) < 0)
  349. return 1;
  350. return 0;
  351. }
  352. /* 
  353.  * Initialise the framebuffer
  354.  */
  355. int __init pmagbafb_init(void)
  356. {
  357. int sid;
  358. int found = 0;
  359. if (TURBOCHANNEL) {
  360. while ((sid = search_tc_card("PMAG-BA")) >= 0) {
  361. found = 1;
  362. claim_tc_card(sid);
  363. pmagbafb_init_one(sid);
  364. }
  365. return found ? 0 : -ENODEV;
  366. } else {
  367. return -ENODEV;
  368. }
  369. }
  370. MODULE_LICENSE("GPL");