pmag-aa-fb.c 12 KB

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