sun3fb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * linux/drivers/video/sun3fb.c -- Frame buffer driver for Sun3
  3. *
  4. * (C) 1998 Thomas Bogendoerfer
  5. *
  6. * This driver is bases on sbusfb.c, which is
  7. *
  8. * Copyright (C) 1998 Jakub Jelinek
  9. *
  10. * This driver is partly based on the Open Firmware console driver
  11. *
  12. * Copyright (C) 1997 Geert Uytterhoeven
  13. *
  14. * and SPARC console subsystem
  15. *
  16. * Copyright (C) 1995 Peter Zaitcev (zaitcev@yahoo.com)
  17. * Copyright (C) 1995-1997 David S. Miller (davem@caip.rutgers.edu)
  18. * Copyright (C) 1995-1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
  19. * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
  20. * Copyright (C) 1996-1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  21. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  22. *
  23. * This file is subject to the terms and conditions of the GNU General Public
  24. * License. See the file COPYING in the main directory of this archive for
  25. * more details.
  26. */
  27. #include <linux/module.h>
  28. #include <linux/kernel.h>
  29. #include <linux/errno.h>
  30. #include <linux/string.h>
  31. #include <linux/mm.h>
  32. #include <linux/tty.h>
  33. #include <linux/slab.h>
  34. #include <linux/vmalloc.h>
  35. #include <linux/delay.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/fb.h>
  38. #include <linux/selection.h>
  39. #include <linux/init.h>
  40. #include <linux/console.h>
  41. #include <linux/kd.h>
  42. #include <linux/vt_kern.h>
  43. #include <asm/uaccess.h>
  44. #include <asm/pgtable.h> /* io_remap_page_range() */
  45. #ifdef CONFIG_SUN3
  46. #include <asm/oplib.h>
  47. #include <asm/machines.h>
  48. #include <asm/idprom.h>
  49. #define CGFOUR_OBMEM_ADDR 0x1f300000
  50. #define BWTWO_OBMEM_ADDR 0x1f000000
  51. #define BWTWO_OBMEM50_ADDR 0x00100000
  52. #endif
  53. #ifdef CONFIG_SUN3X
  54. #include <asm/sun3x.h>
  55. #endif
  56. #include <video/sbusfb.h>
  57. #define DEFAULT_CURSOR_BLINK_RATE (2*HZ/5)
  58. #define CURSOR_SHAPE 1
  59. #define CURSOR_BLINK 2
  60. #define mymemset(x,y) memset(x,0,y)
  61. /*
  62. * Interface used by the world
  63. */
  64. int sun3fb_init(void);
  65. void sun3fb_setup(char *options);
  66. static char fontname[40] __initdata = { 0 };
  67. static int curblink __initdata = 1;
  68. static int sun3fb_get_fix(struct fb_fix_screeninfo *fix, int con,
  69. struct fb_info *info);
  70. static int sun3fb_get_var(struct fb_var_screeninfo *var, int con,
  71. struct fb_info *info);
  72. static int sun3fb_set_var(struct fb_var_screeninfo *var, int con,
  73. struct fb_info *info);
  74. static int sun3fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  75. struct fb_info *info);
  76. static int sun3fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
  77. struct fb_info *info);
  78. static int sun3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  79. u_int transp, struct fb_info *info);
  80. static int sun3fb_blank(int blank, struct fb_info *info);
  81. static void sun3fb_cursor(struct display *p, int mode, int x, int y);
  82. static void sun3fb_clear_margin(struct display *p, int s);
  83. /*
  84. * Interface to the low level console driver
  85. */
  86. static int sun3fbcon_switch(int con, struct fb_info *info);
  87. static int sun3fbcon_updatevar(int con, struct fb_info *info);
  88. /*
  89. * Internal routines
  90. */
  91. static int sun3fb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
  92. u_int *transp, struct fb_info *info);
  93. static struct fb_ops sun3fb_ops = {
  94. .owner = THIS_MODULE,
  95. .fb_get_fix = sun3fb_get_fix,
  96. .fb_get_var = sun3fb_get_var,
  97. .fb_set_var = sun3fb_set_var,
  98. .fb_get_cmap = sun3fb_get_cmap,
  99. .fb_set_cmap = sun3fb_set_cmap,
  100. .fb_setcolreg = sun3fb_setcolreg,
  101. .fb_blank = sun3fb_blank,
  102. };
  103. static void sun3fb_clear_margin(struct display *p, int s)
  104. {
  105. struct fb_info_sbusfb *fb = sbusfbinfod(p);
  106. return;
  107. if (fb->switch_from_graph)
  108. (*fb->switch_from_graph)(fb);
  109. if (fb->fill) {
  110. unsigned short rects [16];
  111. rects [0] = 0;
  112. rects [1] = 0;
  113. rects [2] = fb->var.xres_virtual;
  114. rects [3] = fb->y_margin;
  115. rects [4] = 0;
  116. rects [5] = fb->y_margin;
  117. rects [6] = fb->x_margin;
  118. rects [7] = fb->var.yres_virtual;
  119. rects [8] = fb->var.xres_virtual - fb->x_margin;
  120. rects [9] = fb->y_margin;
  121. rects [10] = fb->var.xres_virtual;
  122. rects [11] = fb->var.yres_virtual;
  123. rects [12] = fb->x_margin;
  124. rects [13] = fb->var.yres_virtual - fb->y_margin;
  125. rects [14] = fb->var.xres_virtual - fb->x_margin;
  126. rects [15] = fb->var.yres_virtual;
  127. (*fb->fill)(fb, p, s, 4, rects);
  128. } else {
  129. unsigned char *fb_base = fb->info.screen_base, *q;
  130. int skip_bytes = fb->y_margin * fb->var.xres_virtual;
  131. int scr_size = fb->var.xres_virtual * fb->var.yres_virtual;
  132. int h, he, incr, size;
  133. he = fb->var.yres;
  134. if (fb->var.bits_per_pixel == 1) {
  135. fb_base -= (skip_bytes + fb->x_margin) / 8;
  136. skip_bytes /= 8;
  137. scr_size /= 8;
  138. mymemset (fb_base, skip_bytes - fb->x_margin / 8);
  139. mymemset (fb_base + scr_size - skip_bytes + fb->x_margin / 8, skip_bytes - fb->x_margin / 8);
  140. incr = fb->var.xres_virtual / 8;
  141. size = fb->x_margin / 8 * 2;
  142. for (q = fb_base + skip_bytes - fb->x_margin / 8, h = 0;
  143. h <= he; q += incr, h++)
  144. mymemset (q, size);
  145. } else {
  146. fb_base -= (skip_bytes + fb->x_margin);
  147. memset (fb_base, attr_bgcol(p,s), skip_bytes - fb->x_margin);
  148. memset (fb_base + scr_size - skip_bytes + fb->x_margin, attr_bgcol(p,s), skip_bytes - fb->x_margin);
  149. incr = fb->var.xres_virtual;
  150. size = fb->x_margin * 2;
  151. for (q = fb_base + skip_bytes - fb->x_margin, h = 0;
  152. h <= he; q += incr, h++)
  153. memset (q, attr_bgcol(p,s), size);
  154. }
  155. }
  156. }
  157. static void sun3fb_disp_setup(struct display *p)
  158. {
  159. struct fb_info_sbusfb *fb = sbusfbinfod(p);
  160. if (fb->setup)
  161. fb->setup(p);
  162. sun3fb_clear_margin(p, 0);
  163. }
  164. /*
  165. * Get the Fixed Part of the Display
  166. */
  167. static int sun3fb_get_fix(struct fb_fix_screeninfo *fix, int con,
  168. struct fb_info *info)
  169. {
  170. struct fb_info_sbusfb *fb = sbusfbinfo(info);
  171. memcpy(fix, &fb->fix, sizeof(struct fb_fix_screeninfo));
  172. return 0;
  173. }
  174. /*
  175. * Get the User Defined Part of the Display
  176. */
  177. static int sun3fb_get_var(struct fb_var_screeninfo *var, int con,
  178. struct fb_info *info)
  179. {
  180. struct fb_info_sbusfb *fb = sbusfbinfo(info);
  181. memcpy(var, &fb->var, sizeof(struct fb_var_screeninfo));
  182. return 0;
  183. }
  184. /*
  185. * Set the User Defined Part of the Display
  186. */
  187. static int sun3fb_set_var(struct fb_var_screeninfo *var, int con,
  188. struct fb_info *info)
  189. {
  190. struct fb_info_sbusfb *fb = sbusfbinfo(info);
  191. if (var->xres > fb->var.xres || var->yres > fb->var.yres ||
  192. var->xres_virtual > fb->var.xres_virtual ||
  193. var->yres_virtual > fb->var.yres_virtual ||
  194. var->bits_per_pixel != fb->var.bits_per_pixel ||
  195. var->nonstd ||
  196. (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
  197. return -EINVAL;
  198. memcpy(var, &fb->var, sizeof(struct fb_var_screeninfo));
  199. return 0;
  200. }
  201. /*
  202. * Hardware cursor
  203. */
  204. static unsigned char hw_cursor_cmap[2] = { 0, 0xff };
  205. static void
  206. sun3fb_cursor_timer_handler(unsigned long dev_addr)
  207. {
  208. struct fb_info_sbusfb *fb = (struct fb_info_sbusfb *)dev_addr;
  209. if (!fb->setcursor) return;
  210. if (fb->cursor.mode & CURSOR_BLINK) {
  211. fb->cursor.enable ^= 1;
  212. fb->setcursor(fb);
  213. }
  214. fb->cursor.timer.expires = jiffies + fb->cursor.blink_rate;
  215. add_timer(&fb->cursor.timer);
  216. }
  217. static void sun3fb_cursor(struct display *p, int mode, int x, int y)
  218. {
  219. struct fb_info_sbusfb *fb = sbusfbinfod(p);
  220. switch (mode) {
  221. case CM_ERASE:
  222. fb->cursor.mode &= ~CURSOR_BLINK;
  223. fb->cursor.enable = 0;
  224. (*fb->setcursor)(fb);
  225. break;
  226. case CM_MOVE:
  227. case CM_DRAW:
  228. if (fb->cursor.mode & CURSOR_SHAPE) {
  229. fb->cursor.size.fbx = fontwidth(p);
  230. fb->cursor.size.fby = fontheight(p);
  231. fb->cursor.chot.fbx = 0;
  232. fb->cursor.chot.fby = 0;
  233. fb->cursor.enable = 1;
  234. memset (fb->cursor.bits, 0, sizeof (fb->cursor.bits));
  235. fb->cursor.bits[0][fontheight(p) - 2] = (0xffffffff << (32 - fontwidth(p)));
  236. fb->cursor.bits[1][fontheight(p) - 2] = (0xffffffff << (32 - fontwidth(p)));
  237. fb->cursor.bits[0][fontheight(p) - 1] = (0xffffffff << (32 - fontwidth(p)));
  238. fb->cursor.bits[1][fontheight(p) - 1] = (0xffffffff << (32 - fontwidth(p)));
  239. (*fb->setcursormap) (fb, hw_cursor_cmap, hw_cursor_cmap, hw_cursor_cmap);
  240. (*fb->setcurshape) (fb);
  241. }
  242. fb->cursor.mode = CURSOR_BLINK;
  243. if (fontwidthlog(p))
  244. fb->cursor.cpos.fbx = (x << fontwidthlog(p)) + fb->x_margin;
  245. else
  246. fb->cursor.cpos.fbx = (x * fontwidth(p)) + fb->x_margin;
  247. if (fontheightlog(p))
  248. fb->cursor.cpos.fby = (y << fontheightlog(p)) + fb->y_margin;
  249. else
  250. fb->cursor.cpos.fby = (y * fontheight(p)) + fb->y_margin;
  251. (*fb->setcursor)(fb);
  252. break;
  253. }
  254. }
  255. /*
  256. * Get the Colormap
  257. */
  258. static int sun3fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  259. struct fb_info *info)
  260. {
  261. if (con == info->currcon) /* current console? */
  262. return fb_get_cmap(cmap, kspc, sun3fb_getcolreg, info);
  263. else if (fb_display[con].cmap.len) /* non default colormap? */
  264. fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
  265. else
  266. fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel), cmap, kspc ? 0 : 2);
  267. return 0;
  268. }
  269. /*
  270. * Set the Colormap
  271. */
  272. static int sun3fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
  273. struct fb_info *info)
  274. {
  275. int err;
  276. if (!fb_display[con].cmap.len) { /* no colormap allocated? */
  277. if ((err = fb_alloc_cmap(&fb_display[con].cmap, 1<<fb_display[con].var.bits_per_pixel, 0)))
  278. return err;
  279. }
  280. if (con == info->currcon) { /* current console? */
  281. err = fb_set_cmap(cmap, kspc, info);
  282. if (!err) {
  283. struct fb_info_sbusfb *fb = sbusfbinfo(info);
  284. if (fb->loadcmap)
  285. (*fb->loadcmap)(fb, &fb_display[con], cmap->start, cmap->len);
  286. }
  287. return err;
  288. } else
  289. fb_copy_cmap(cmap, &fb_display[con].cmap, kspc ? 0 : 1);
  290. return 0;
  291. }
  292. /*
  293. * Setup: parse used options
  294. */
  295. void __init sun3fb_setup(char *options)
  296. {
  297. char *p;
  298. for (p = options;;) {
  299. if (!strncmp(p, "font=", 5)) {
  300. int i;
  301. for (i = 0; i < sizeof(fontname) - 1; i++)
  302. if (p[i+5] == ' ' || !p[i+5])
  303. break;
  304. memcpy(fontname, p+5, i);
  305. fontname[i] = 0;
  306. } else if (!strncmp(p, "noblink", 7))
  307. curblink = 0;
  308. while (*p && *p != ' ' && *p != ',') p++;
  309. if (*p != ',') break;
  310. p++;
  311. }
  312. return;
  313. }
  314. static int sun3fbcon_switch(int con, struct fb_info *info)
  315. {
  316. int x_margin, y_margin;
  317. struct fb_info_sbusfb *fb = sbusfbinfo(info);
  318. int lastconsole;
  319. /* Do we have to save the colormap? */
  320. if (fb_display[info->currcon].cmap.len)
  321. fb_get_cmap(&fb_display[info->currcon].cmap, 1, sun3fb_getcolreg, info);
  322. if (info->display_fg) {
  323. lastconsole = info->display_fg->vc_num;
  324. if (lastconsole != con &&
  325. (fontwidth(&fb_display[lastconsole]) != fontwidth(&fb_display[con]) ||
  326. fontheight(&fb_display[lastconsole]) != fontheight(&fb_display[con])))
  327. fb->cursor.mode |= CURSOR_SHAPE;
  328. }
  329. x_margin = (fb_display[con].var.xres_virtual - fb_display[con].var.xres) / 2;
  330. y_margin = (fb_display[con].var.yres_virtual - fb_display[con].var.yres) / 2;
  331. if (fb->margins)
  332. fb->margins(fb, &fb_display[con], x_margin, y_margin);
  333. if (fb->graphmode || fb->x_margin != x_margin || fb->y_margin != y_margin) {
  334. fb->x_margin = x_margin; fb->y_margin = y_margin;
  335. sun3fb_clear_margin(&fb_display[con], 0);
  336. }
  337. info->currcon = con;
  338. /* Install new colormap */
  339. do_install_cmap(con, info);
  340. return 0;
  341. }
  342. /*
  343. * Update the `var' structure (called by fbcon.c)
  344. */
  345. static int sun3fbcon_updatevar(int con, struct fb_info *info)
  346. {
  347. /* Nothing */
  348. return 0;
  349. }
  350. /*
  351. * Blank the display.
  352. */
  353. static int sun3fb_blank(int blank, struct fb_info *info)
  354. {
  355. struct fb_info_sbusfb *fb = sbusfbinfo(info);
  356. if (blank && fb->blank)
  357. return fb->blank(fb);
  358. else if (!blank && fb->unblank)
  359. return fb->unblank(fb);
  360. return 0;
  361. }
  362. /*
  363. * Read a single color register and split it into
  364. * colors/transparent. Return != 0 for invalid regno.
  365. */
  366. static int sun3fb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
  367. u_int *transp, struct fb_info *info)
  368. {
  369. struct fb_info_sbusfb *fb = sbusfbinfo(info);
  370. if (!fb->color_map || regno > 255)
  371. return 1;
  372. *red = (fb->color_map CM(regno, 0)<<8) | fb->color_map CM(regno, 0);
  373. *green = (fb->color_map CM(regno, 1)<<8) | fb->color_map CM(regno, 1);
  374. *blue = (fb->color_map CM(regno, 2)<<8) | fb->color_map CM(regno, 2);
  375. *transp = 0;
  376. return 0;
  377. }
  378. /*
  379. * Set a single color register. The values supplied are already
  380. * rounded down to the hardware's capabilities (according to the
  381. * entries in the var structure). Return != 0 for invalid regno.
  382. */
  383. static int sun3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  384. u_int transp, struct fb_info *info)
  385. {
  386. struct fb_info_sbusfb *fb = sbusfbinfo(info);
  387. if (!fb->color_map || regno > 255)
  388. return 1;
  389. red >>= 8;
  390. green >>= 8;
  391. blue >>= 8;
  392. fb->color_map CM(regno, 0) = red;
  393. fb->color_map CM(regno, 1) = green;
  394. fb->color_map CM(regno, 2) = blue;
  395. return 0;
  396. }
  397. static int sun3fb_set_font(struct display *p, int width, int height)
  398. {
  399. int w = p->var.xres_virtual, h = p->var.yres_virtual;
  400. int depth = p->var.bits_per_pixel;
  401. struct fb_info_sbusfb *fb = sbusfbinfod(p);
  402. int x_margin, y_margin;
  403. if (depth > 8) depth = 8;
  404. x_margin = (w % width) / 2;
  405. y_margin = (h % height) / 2;
  406. p->var.xres = w - 2*x_margin;
  407. p->var.yres = h - 2*y_margin;
  408. fb->cursor.mode |= CURSOR_SHAPE;
  409. if (fb->margins)
  410. fb->margins(fb, p, x_margin, y_margin);
  411. if (fb->x_margin != x_margin || fb->y_margin != y_margin) {
  412. fb->x_margin = x_margin; fb->y_margin = y_margin;
  413. sun3fb_clear_margin(p, 0);
  414. }
  415. return 1;
  416. }
  417. void sun3fb_palette(int enter)
  418. {
  419. int i;
  420. struct display *p;
  421. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  422. p = &fb_display[i];
  423. if (p->dispsw && p->dispsw->setup == sun3fb_disp_setup &&
  424. p->fb_info->display_fg &&
  425. p->fb_info->display_fg->vc_num == i) {
  426. struct fb_info_sbusfb *fb = sbusfbinfod(p);
  427. if (fb->restore_palette) {
  428. if (enter)
  429. fb->restore_palette(fb);
  430. else if (vc_cons[i].d->vc_mode != KD_GRAPHICS)
  431. vc_cons[i].d->vc_sw->con_set_palette(vc_cons[i].d, color_table);
  432. }
  433. }
  434. }
  435. }
  436. /*
  437. * Initialisation
  438. */
  439. static int __init sun3fb_init_fb(int fbtype, unsigned long addr)
  440. {
  441. static struct sbus_dev sdb;
  442. struct fb_fix_screeninfo *fix;
  443. struct fb_var_screeninfo *var;
  444. struct display *disp;
  445. struct fb_info_sbusfb *fb;
  446. struct fbtype *type;
  447. int linebytes, w, h, depth;
  448. char *p = NULL;
  449. fb = kmalloc(sizeof(struct fb_info_sbusfb), GFP_ATOMIC);
  450. if (!fb)
  451. return -ENOMEM;
  452. memset(fb, 0, sizeof(struct fb_info_sbusfb));
  453. fix = &fb->fix;
  454. var = &fb->var;
  455. disp = &fb->disp;
  456. type = &fb->type;
  457. sdb.reg_addrs[0].phys_addr = addr;
  458. fb->sbdp = &sdb;
  459. type->fb_type = fbtype;
  460. type->fb_height = h = 900;
  461. type->fb_width = w = 1152;
  462. sizechange:
  463. type->fb_depth = depth = (fbtype == FBTYPE_SUN2BW) ? 1 : 8;
  464. linebytes = w * depth / 8;
  465. type->fb_size = PAGE_ALIGN((linebytes) * h);
  466. /*
  467. fb->x_margin = (w & 7) / 2;
  468. fb->y_margin = (h & 15) / 2;
  469. */
  470. fb->x_margin = fb->y_margin = 0;
  471. var->xres_virtual = w;
  472. var->yres_virtual = h;
  473. var->xres = w - 2*fb->x_margin;
  474. var->yres = h - 2*fb->y_margin;
  475. var->bits_per_pixel = depth;
  476. var->height = var->width = -1;
  477. var->pixclock = 10000;
  478. var->vmode = FB_VMODE_NONINTERLACED;
  479. var->red.length = var->green.length = var->blue.length = 8;
  480. fix->line_length = linebytes;
  481. fix->smem_len = type->fb_size;
  482. fix->type = FB_TYPE_PACKED_PIXELS;
  483. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  484. fb->info.fbops = &sun3fb_ops;
  485. fb->info.disp = disp;
  486. fb->info.currcon = -1;
  487. strcpy(fb->info.fontname, fontname);
  488. fb->info.changevar = NULL;
  489. fb->info.switch_con = &sun3fbcon_switch;
  490. fb->info.updatevar = &sun3fbcon_updatevar;
  491. fb->info.flags = FBINFO_FLAG_DEFAULT;
  492. fb->cursor.hwsize.fbx = 32;
  493. fb->cursor.hwsize.fby = 32;
  494. if (depth > 1 && !fb->color_map) {
  495. if((fb->color_map = kmalloc(256 * 3, GFP_ATOMIC))==NULL)
  496. return -ENOMEM;
  497. }
  498. switch(fbtype) {
  499. #ifdef CONFIG_FB_CGSIX
  500. case FBTYPE_SUNFAST_COLOR:
  501. p = cgsixfb_init(fb); break;
  502. #endif
  503. #ifdef CONFIG_FB_BWTWO
  504. case FBTYPE_SUN2BW:
  505. p = bwtwofb_init(fb); break;
  506. #endif
  507. #ifdef CONFIG_FB_CGTHREE
  508. case FBTYPE_SUN4COLOR:
  509. case FBTYPE_SUN3COLOR:
  510. type->fb_size = 0x100000;
  511. p = cgthreefb_init(fb); break;
  512. #endif
  513. }
  514. fix->smem_start = (unsigned long)fb->info.screen_base; // FIXME
  515. if (!p) {
  516. kfree(fb);
  517. return -ENODEV;
  518. }
  519. if (p == SBUSFBINIT_SIZECHANGE)
  520. goto sizechange;
  521. disp->dispsw = &fb->dispsw;
  522. if (fb->setcursor) {
  523. fb->dispsw.cursor = sun3fb_cursor;
  524. if (curblink) {
  525. fb->cursor.blink_rate = DEFAULT_CURSOR_BLINK_RATE;
  526. init_timer(&fb->cursor.timer);
  527. fb->cursor.timer.expires = jiffies + fb->cursor.blink_rate;
  528. fb->cursor.timer.data = (unsigned long)fb;
  529. fb->cursor.timer.function = sun3fb_cursor_timer_handler;
  530. add_timer(&fb->cursor.timer);
  531. }
  532. }
  533. fb->cursor.mode = CURSOR_SHAPE;
  534. fb->dispsw.set_font = sun3fb_set_font;
  535. fb->setup = fb->dispsw.setup;
  536. fb->dispsw.setup = sun3fb_disp_setup;
  537. fb->dispsw.clear_margins = NULL;
  538. disp->var = *var;
  539. disp->visual = fix->visual;
  540. disp->type = fix->type;
  541. disp->type_aux = fix->type_aux;
  542. disp->line_length = fix->line_length;
  543. if (fb->blank)
  544. disp->can_soft_blank = 1;
  545. sun3fb_set_var(var, -1, &fb->info);
  546. if (register_framebuffer(&fb->info) < 0) {
  547. kfree(fb);
  548. return -EINVAL;
  549. }
  550. printk("fb%d: %s\n", fb->info.node, p);
  551. return 0;
  552. }
  553. int __init sun3fb_init(void)
  554. {
  555. extern int con_is_present(void);
  556. unsigned long addr;
  557. char p4id;
  558. if (!con_is_present()) return -ENODEV;
  559. #ifdef CONFIG_SUN3
  560. switch(*(romvec->pv_fbtype))
  561. {
  562. case FBTYPE_SUN2BW:
  563. addr = 0xfe20000;
  564. return sun3fb_init_fb(FBTYPE_SUN2BW, addr);
  565. case FBTYPE_SUN3COLOR:
  566. case FBTYPE_SUN4COLOR:
  567. if(idprom->id_machtype != (SM_SUN3|SM_3_60)) {
  568. printk("sun3fb: cgthree/four only supported on 3/60\n");
  569. return -ENODEV;
  570. }
  571. addr = CGFOUR_OBMEM_ADDR;
  572. return sun3fb_init_fb(*(romvec->pv_fbtype), addr);
  573. default:
  574. printk("sun3fb: unsupported framebuffer\n");
  575. return -ENODEV;
  576. }
  577. #else
  578. addr = SUN3X_VIDEO_BASE;
  579. p4id = *(char *)SUN3X_VIDEO_P4ID;
  580. p4id = (p4id == 0x45) ? p4id : (p4id & 0xf0);
  581. switch (p4id) {
  582. case 0x00:
  583. return sun3fb_init_fb(FBTYPE_SUN2BW, addr);
  584. #if 0 /* not yet */
  585. case 0x40:
  586. return sun3fb_init_fb(FBTYPE_SUN4COLOR, addr);
  587. break;
  588. case 0x45:
  589. return sun3fb_init_fb(FBTYPE_SUN8COLOR, addr);
  590. break;
  591. #endif
  592. case 0x60:
  593. return sun3fb_init_fb(FBTYPE_SUNFAST_COLOR, addr);
  594. }
  595. #endif
  596. return -ENODEV;
  597. }
  598. MODULE_LICENSE("GPL");