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