pmag-aa-fb.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /*
  2. * linux/drivers/video/pmag-aa-fb.c
  3. * Copyright 2002 Karsten Merker <merker@debian.org>
  4. *
  5. * PMAG-AA TurboChannel framebuffer card support ... derived from
  6. * pmag-ba-fb.c, which is Copyright (C) 1999, 2000, 2001 by
  7. * Michael Engel <engel@unix-ag.org>, Karsten Merker <merker@debian.org>
  8. * and Harald Koerfgen <hkoerfg@web.de>, which itself is derived from
  9. * "HP300 Topcat framebuffer support (derived from macfb of all things)
  10. * Phil Blundell <philb@gnu.org> 1998"
  11. *
  12. * This file is subject to the terms and conditions of the GNU General
  13. * Public License. See the file COPYING in the main directory of this
  14. * archive for more details.
  15. *
  16. * 2002-09-28 Karsten Merker <merker@linuxtag.org>
  17. * Version 0.01: First try to get a PMAG-AA running.
  18. *
  19. * 2003-02-24 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
  20. * Version 0.02: Major code cleanup.
  21. *
  22. * 2003-09-21 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
  23. * Hardware cursor support.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/kernel.h>
  27. #include <linux/sched.h>
  28. #include <linux/errno.h>
  29. #include <linux/string.h>
  30. #include <linux/timer.h>
  31. #include <linux/mm.h>
  32. #include <linux/tty.h>
  33. #include <linux/slab.h>
  34. #include <linux/delay.h>
  35. #include <linux/init.h>
  36. #include <linux/fb.h>
  37. #include <linux/console.h>
  38. #include <asm/bootinfo.h>
  39. #include <asm/dec/machtype.h>
  40. #include <asm/dec/tc.h>
  41. #include <video/fbcon.h>
  42. #include <video/fbcon-cfb8.h>
  43. #include "bt455.h"
  44. #include "bt431.h"
  45. /* Version information */
  46. #define DRIVER_VERSION "0.02"
  47. #define DRIVER_AUTHOR "Karsten Merker <merker@linuxtag.org>"
  48. #define DRIVER_DESCRIPTION "PMAG-AA Framebuffer Driver"
  49. /* Prototypes */
  50. static int aafb_set_var(struct fb_var_screeninfo *var, int con,
  51. struct fb_info *info);
  52. /*
  53. * Bt455 RAM DAC register base offset (rel. to TC slot base address).
  54. */
  55. #define PMAG_AA_BT455_OFFSET 0x100000
  56. /*
  57. * Bt431 cursor generator offset (rel. to TC slot base address).
  58. */
  59. #define PMAG_AA_BT431_OFFSET 0x180000
  60. /*
  61. * Begin of PMAG-AA framebuffer memory relative to TC slot address,
  62. * resolution is 1280x1024x1 (8 bits deep, but only LSB is used).
  63. */
  64. #define PMAG_AA_ONBOARD_FBMEM_OFFSET 0x200000
  65. struct aafb_cursor {
  66. struct timer_list timer;
  67. int enable;
  68. int on;
  69. int vbl_cnt;
  70. int blink_rate;
  71. u16 x, y, width, height;
  72. };
  73. #define CURSOR_TIMER_FREQ (HZ / 50)
  74. #define CURSOR_BLINK_RATE (20)
  75. #define CURSOR_DRAW_DELAY (2)
  76. struct aafb_info {
  77. struct fb_info info;
  78. struct display disp;
  79. struct aafb_cursor cursor;
  80. struct bt455_regs *bt455;
  81. struct bt431_regs *bt431;
  82. unsigned long fb_start;
  83. unsigned long fb_size;
  84. unsigned long fb_line_length;
  85. };
  86. /*
  87. * Max 3 TURBOchannel slots -> max 3 PMAG-AA.
  88. */
  89. static struct aafb_info my_fb_info[3];
  90. static struct aafb_par {
  91. } current_par;
  92. static int currcon = -1;
  93. static void aafb_set_cursor(struct aafb_info *info, int on)
  94. {
  95. struct aafb_cursor *c = &info->cursor;
  96. if (on) {
  97. bt431_position_cursor(info->bt431, c->x, c->y);
  98. bt431_enable_cursor(info->bt431);
  99. } else
  100. bt431_erase_cursor(info->bt431);
  101. }
  102. static void aafbcon_cursor(struct display *disp, int mode, int x, int y)
  103. {
  104. struct aafb_info *info = (struct aafb_info *)disp->fb_info;
  105. struct aafb_cursor *c = &info->cursor;
  106. x *= fontwidth(disp);
  107. y *= fontheight(disp);
  108. if (c->x == x && c->y == y && (mode == CM_ERASE) == !c->enable)
  109. return;
  110. c->enable = 0;
  111. if (c->on)
  112. aafb_set_cursor(info, 0);
  113. c->x = x - disp->var.xoffset;
  114. c->y = y - disp->var.yoffset;
  115. switch (mode) {
  116. case CM_ERASE:
  117. c->on = 0;
  118. break;
  119. case CM_DRAW:
  120. case CM_MOVE:
  121. if (c->on)
  122. aafb_set_cursor(info, c->on);
  123. else
  124. c->vbl_cnt = CURSOR_DRAW_DELAY;
  125. c->enable = 1;
  126. break;
  127. }
  128. }
  129. static int aafbcon_set_font(struct display *disp, int width, int height)
  130. {
  131. struct aafb_info *info = (struct aafb_info *)disp->fb_info;
  132. struct aafb_cursor *c = &info->cursor;
  133. u8 fgc = ~attr_bgcol_ec(disp, disp->conp);
  134. if (width > 64 || height > 64 || width < 0 || height < 0)
  135. return -EINVAL;
  136. c->height = height;
  137. c->width = width;
  138. bt431_set_font(info->bt431, fgc, width, height);
  139. return 1;
  140. }
  141. static void aafb_cursor_timer_handler(unsigned long data)
  142. {
  143. struct aafb_info *info = (struct aafb_info *)data;
  144. struct aafb_cursor *c = &info->cursor;
  145. if (!c->enable)
  146. goto out;
  147. if (c->vbl_cnt && --c->vbl_cnt == 0) {
  148. c->on ^= 1;
  149. aafb_set_cursor(info, c->on);
  150. c->vbl_cnt = c->blink_rate;
  151. }
  152. out:
  153. c->timer.expires = jiffies + CURSOR_TIMER_FREQ;
  154. add_timer(&c->timer);
  155. }
  156. static void __init aafb_cursor_init(struct aafb_info *info)
  157. {
  158. struct aafb_cursor *c = &info->cursor;
  159. c->enable = 1;
  160. c->on = 1;
  161. c->x = c->y = 0;
  162. c->width = c->height = 0;
  163. c->vbl_cnt = CURSOR_DRAW_DELAY;
  164. c->blink_rate = CURSOR_BLINK_RATE;
  165. init_timer(&c->timer);
  166. c->timer.data = (unsigned long)info;
  167. c->timer.function = aafb_cursor_timer_handler;
  168. mod_timer(&c->timer, jiffies + CURSOR_TIMER_FREQ);
  169. }
  170. static void __exit aafb_cursor_exit(struct aafb_info *info)
  171. {
  172. struct aafb_cursor *c = &info->cursor;
  173. del_timer_sync(&c->timer);
  174. }
  175. static struct display_switch aafb_switch8 = {
  176. .setup = fbcon_cfb8_setup,
  177. .bmove = fbcon_cfb8_bmove,
  178. .clear = fbcon_cfb8_clear,
  179. .putc = fbcon_cfb8_putc,
  180. .putcs = fbcon_cfb8_putcs,
  181. .revc = fbcon_cfb8_revc,
  182. .cursor = aafbcon_cursor,
  183. .set_font = aafbcon_set_font,
  184. .clear_margins = fbcon_cfb8_clear_margins,
  185. .fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
  186. };
  187. static void aafb_get_par(struct aafb_par *par)
  188. {
  189. *par = current_par;
  190. }
  191. static int aafb_get_fix(struct fb_fix_screeninfo *fix, int con,
  192. struct fb_info *info)
  193. {
  194. struct aafb_info *ip = (struct aafb_info *)info;
  195. memset(fix, 0, sizeof(struct fb_fix_screeninfo));
  196. strcpy(fix->id, "PMAG-AA");
  197. fix->smem_start = ip->fb_start;
  198. fix->smem_len = ip->fb_size;
  199. fix->type = FB_TYPE_PACKED_PIXELS;
  200. fix->ypanstep = 1;
  201. fix->ywrapstep = 1;
  202. fix->visual = FB_VISUAL_MONO10;
  203. fix->line_length = 1280;
  204. fix->accel = FB_ACCEL_NONE;
  205. return 0;
  206. }
  207. static void aafb_set_disp(struct display *disp, int con,
  208. struct aafb_info *info)
  209. {
  210. struct fb_fix_screeninfo fix;
  211. disp->fb_info = &info->info;
  212. aafb_set_var(&disp->var, con, &info->info);
  213. if (disp->conp && disp->conp->vc_sw && disp->conp->vc_sw->con_cursor)
  214. disp->conp->vc_sw->con_cursor(disp->conp, CM_ERASE);
  215. disp->dispsw = &aafb_switch8;
  216. disp->dispsw_data = 0;
  217. aafb_get_fix(&fix, con, &info->info);
  218. disp->screen_base = (u8 *) fix.smem_start;
  219. disp->visual = fix.visual;
  220. disp->type = fix.type;
  221. disp->type_aux = fix.type_aux;
  222. disp->ypanstep = fix.ypanstep;
  223. disp->ywrapstep = fix.ywrapstep;
  224. disp->line_length = fix.line_length;
  225. disp->next_line = 2048;
  226. disp->can_soft_blank = 1;
  227. disp->inverse = 0;
  228. disp->scrollmode = SCROLL_YREDRAW;
  229. aafbcon_set_font(disp, fontwidth(disp), fontheight(disp));
  230. }
  231. static int aafb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  232. struct fb_info *info)
  233. {
  234. static u16 color[2] = {0x0000, 0x000f};
  235. static struct fb_cmap aafb_cmap = {0, 2, color, color, color, NULL};
  236. fb_copy_cmap(&aafb_cmap, cmap, kspc ? 0 : 2);
  237. return 0;
  238. }
  239. static int aafb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
  240. struct fb_info *info)
  241. {
  242. u16 color[2] = {0x0000, 0x000f};
  243. if (cmap->start == 0
  244. && cmap->len == 2
  245. && memcmp(cmap->red, color, sizeof(color)) == 0
  246. && memcmp(cmap->green, color, sizeof(color)) == 0
  247. && memcmp(cmap->blue, color, sizeof(color)) == 0
  248. && cmap->transp == NULL)
  249. return 0;
  250. else
  251. return -EINVAL;
  252. }
  253. static int aafb_ioctl(struct inode *inode, struct file *file, u32 cmd,
  254. unsigned long arg, int con, struct fb_info *info)
  255. {
  256. /* TODO: Not yet implemented */
  257. return -ENOIOCTLCMD;
  258. }
  259. static int aafb_switch(int con, struct fb_info *info)
  260. {
  261. struct aafb_info *ip = (struct aafb_info *)info;
  262. struct display *old = (currcon < 0) ? &ip->disp : (fb_display + currcon);
  263. struct display *new = (con < 0) ? &ip->disp : (fb_display + con);
  264. if (old->conp && old->conp->vc_sw && old->conp->vc_sw->con_cursor)
  265. old->conp->vc_sw->con_cursor(old->conp, CM_ERASE);
  266. /* Set the current console. */
  267. currcon = con;
  268. aafb_set_disp(new, con, ip);
  269. return 0;
  270. }
  271. static void aafb_encode_var(struct fb_var_screeninfo *var,
  272. struct aafb_par *par)
  273. {
  274. var->xres = 1280;
  275. var->yres = 1024;
  276. var->xres_virtual = 2048;
  277. var->yres_virtual = 1024;
  278. var->xoffset = 0;
  279. var->yoffset = 0;
  280. var->bits_per_pixel = 8;
  281. var->grayscale = 1;
  282. var->red.offset = 0;
  283. var->red.length = 0;
  284. var->red.msb_right = 0;
  285. var->green.offset = 0;
  286. var->green.length = 1;
  287. var->green.msb_right = 0;
  288. var->blue.offset = 0;
  289. var->blue.length = 0;
  290. var->blue.msb_right = 0;
  291. var->transp.offset = 0;
  292. var->transp.length = 0;
  293. var->transp.msb_right = 0;
  294. var->nonstd = 0;
  295. var->activate &= ~FB_ACTIVATE_MASK & FB_ACTIVATE_NOW;
  296. var->accel_flags = 0;
  297. var->sync = FB_SYNC_ON_GREEN;
  298. var->vmode &= ~FB_VMODE_MASK & FB_VMODE_NONINTERLACED;
  299. }
  300. static int aafb_get_var(struct fb_var_screeninfo *var, int con,
  301. struct fb_info *info)
  302. {
  303. if (con < 0) {
  304. struct aafb_par par;
  305. memset(var, 0, sizeof(struct fb_var_screeninfo));
  306. aafb_get_par(&par);
  307. aafb_encode_var(var, &par);
  308. } else
  309. *var = info->var;
  310. return 0;
  311. }
  312. static int aafb_set_var(struct fb_var_screeninfo *var, int con,
  313. struct fb_info *info)
  314. {
  315. struct aafb_par par;
  316. aafb_get_par(&par);
  317. aafb_encode_var(var, &par);
  318. info->var = *var;
  319. return 0;
  320. }
  321. static int aafb_update_var(int con, struct fb_info *info)
  322. {
  323. struct aafb_info *ip = (struct aafb_info *)info;
  324. struct display *disp = (con < 0) ? &ip->disp : (fb_display + con);
  325. if (con == currcon)
  326. aafbcon_cursor(disp, CM_ERASE, ip->cursor.x, ip->cursor.y);
  327. return 0;
  328. }
  329. /* 0 unblanks, any other blanks. */
  330. static void aafb_blank(int blank, struct fb_info *info)
  331. {
  332. struct aafb_info *ip = (struct aafb_info *)info;
  333. u8 val = blank ? 0x00 : 0x0f;
  334. bt455_write_cmap_entry(ip->bt455, 1, val, val, val);
  335. aafbcon_cursor(&ip->disp, CM_ERASE, ip->cursor.x, ip->cursor.y);
  336. }
  337. static struct fb_ops aafb_ops = {
  338. .owner = THIS_MODULE,
  339. .fb_get_fix = aafb_get_fix,
  340. .fb_get_var = aafb_get_var,
  341. .fb_set_var = aafb_set_var,
  342. .fb_get_cmap = aafb_get_cmap,
  343. .fb_set_cmap = aafb_set_cmap,
  344. .fb_ioctl = aafb_ioctl
  345. };
  346. static int __init init_one(int slot)
  347. {
  348. unsigned long base_addr = CKSEG1ADDR(get_tc_base_addr(slot));
  349. struct aafb_info *ip = &my_fb_info[slot];
  350. memset(ip, 0, sizeof(struct aafb_info));
  351. /*
  352. * Framebuffer display memory base address and friends.
  353. */
  354. ip->bt455 = (struct bt455_regs *) (base_addr + PMAG_AA_BT455_OFFSET);
  355. ip->bt431 = (struct bt431_regs *) (base_addr + PMAG_AA_BT431_OFFSET);
  356. ip->fb_start = base_addr + PMAG_AA_ONBOARD_FBMEM_OFFSET;
  357. ip->fb_size = 2048 * 1024; /* fb_fix_screeninfo.smem_length
  358. seems to be physical */
  359. ip->fb_line_length = 2048;
  360. /*
  361. * Let there be consoles..
  362. */
  363. strcpy(ip->info.modename, "PMAG-AA");
  364. ip->info.node = -1;
  365. ip->info.flags = FBINFO_FLAG_DEFAULT;
  366. ip->info.fbops = &aafb_ops;
  367. ip->info.disp = &ip->disp;
  368. ip->info.changevar = NULL;
  369. ip->info.switch_con = &aafb_switch;
  370. ip->info.updatevar = &aafb_update_var;
  371. ip->info.blank = &aafb_blank;
  372. aafb_set_disp(&ip->disp, currcon, ip);
  373. /*
  374. * Configure the RAM DACs.
  375. */
  376. bt455_erase_cursor(ip->bt455);
  377. /* Init colormap. */
  378. bt455_write_cmap_entry(ip->bt455, 0, 0x00, 0x00, 0x00);
  379. bt455_write_cmap_entry(ip->bt455, 1, 0x0f, 0x0f, 0x0f);
  380. /* Init hardware cursor. */
  381. bt431_init_cursor(ip->bt431);
  382. aafb_cursor_init(ip);
  383. /* Clear the screen. */
  384. memset ((void *)ip->fb_start, 0, ip->fb_size);
  385. if (register_framebuffer(&ip->info) < 0)
  386. return -EINVAL;
  387. printk(KERN_INFO "fb%d: %s frame buffer in TC slot %d\n",
  388. GET_FB_IDX(ip->info.node), ip->info.modename, slot);
  389. return 0;
  390. }
  391. static int __exit exit_one(int slot)
  392. {
  393. struct aafb_info *ip = &my_fb_info[slot];
  394. if (unregister_framebuffer(&ip->info) < 0)
  395. return -EINVAL;
  396. return 0;
  397. }
  398. /*
  399. * Initialise the framebuffer.
  400. */
  401. int __init pmagaafb_init(void)
  402. {
  403. int sid;
  404. int found = 0;
  405. while ((sid = search_tc_card("PMAG-AA")) >= 0) {
  406. found = 1;
  407. claim_tc_card(sid);
  408. init_one(sid);
  409. }
  410. return found ? 0 : -ENXIO;
  411. }
  412. static void __exit pmagaafb_exit(void)
  413. {
  414. int sid;
  415. while ((sid = search_tc_card("PMAG-AA")) >= 0) {
  416. exit_one(sid);
  417. release_tc_card(sid);
  418. }
  419. }
  420. MODULE_AUTHOR(DRIVER_AUTHOR);
  421. MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
  422. MODULE_LICENSE("GPL");
  423. #ifdef MODULE
  424. module_init(pmagaafb_init);
  425. module_exit(pmagaafb_exit);
  426. #endif