pmag-aa-fb.c 12 KB

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