2 * linux/drivers/video/tgafb.c -- DEC 21030 TGA frame buffer device
4 * Copyright (C) 1995 Jay Estabrook
5 * Copyright (C) 1997 Geert Uytterhoeven
6 * Copyright (C) 1999,2000 Martin Lucina, Tom Zerucha
7 * Copyright (C) 2002 Richard Henderson
8 * Copyright (C) 2006, 2007 Maciej W. Rozycki
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive for
15 #include <linux/bitrev.h>
16 #include <linux/compiler.h>
17 #include <linux/delay.h>
18 #include <linux/device.h>
19 #include <linux/errno.h>
21 #include <linux/init.h>
22 #include <linux/ioport.h>
23 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/pci.h>
27 #include <linux/selection.h>
28 #include <linux/string.h>
33 #include <video/tgafb.h>
36 #define TGA_BUS_PCI(dev) (dev->bus == &pci_bus_type)
38 #define TGA_BUS_PCI(dev) 0
42 #define TGA_BUS_TC(dev) (dev->bus == &tc_bus_type)
44 #define TGA_BUS_TC(dev) 0
51 static int tgafb_check_var(struct fb_var_screeninfo *, struct fb_info *);
52 static int tgafb_set_par(struct fb_info *);
53 static void tgafb_set_pll(struct tga_par *, int);
54 static int tgafb_setcolreg(unsigned, unsigned, unsigned, unsigned,
55 unsigned, struct fb_info *);
56 static int tgafb_blank(int, struct fb_info *);
57 static void tgafb_init_fix(struct fb_info *);
59 static void tgafb_imageblit(struct fb_info *, const struct fb_image *);
60 static void tgafb_fillrect(struct fb_info *, const struct fb_fillrect *);
61 static void tgafb_copyarea(struct fb_info *, const struct fb_copyarea *);
62 static int tgafb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
64 static int __devinit tgafb_register(struct device *dev);
65 static void __devexit tgafb_unregister(struct device *dev);
67 static const char *mode_option;
68 static const char *mode_option_pci = "640x480@60";
69 static const char *mode_option_tc = "1280x1024@72";
72 static struct pci_driver tgafb_pci_driver;
73 static struct tc_driver tgafb_tc_driver;
76 * Frame buffer operations
79 static struct fb_ops tgafb_ops = {
81 .fb_check_var = tgafb_check_var,
82 .fb_set_par = tgafb_set_par,
83 .fb_setcolreg = tgafb_setcolreg,
84 .fb_blank = tgafb_blank,
85 .fb_pan_display = tgafb_pan_display,
86 .fb_fillrect = tgafb_fillrect,
87 .fb_copyarea = tgafb_copyarea,
88 .fb_imageblit = tgafb_imageblit,
94 * PCI registration operations
96 static int __devinit tgafb_pci_register(struct pci_dev *,
97 const struct pci_device_id *);
98 static void __devexit tgafb_pci_unregister(struct pci_dev *);
100 static struct pci_device_id const tgafb_pci_table[] = {
101 { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TGA) },
104 MODULE_DEVICE_TABLE(pci, tgafb_pci_table);
106 static struct pci_driver tgafb_pci_driver = {
108 .id_table = tgafb_pci_table,
109 .probe = tgafb_pci_register,
110 .remove = __devexit_p(tgafb_pci_unregister),
114 tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
116 return tgafb_register(&pdev->dev);
119 static void __devexit
120 tgafb_pci_unregister(struct pci_dev *pdev)
122 tgafb_unregister(&pdev->dev);
124 #endif /* CONFIG_PCI */
128 * TC registration operations
130 static int __devinit tgafb_tc_register(struct device *);
131 static int __devexit tgafb_tc_unregister(struct device *);
133 static struct tc_device_id const tgafb_tc_table[] = {
134 { "DEC ", "PMAGD-AA" },
135 { "DEC ", "PMAGD " },
138 MODULE_DEVICE_TABLE(tc, tgafb_tc_table);
140 static struct tc_driver tgafb_tc_driver = {
141 .id_table = tgafb_tc_table,
145 .probe = tgafb_tc_register,
146 .remove = __devexit_p(tgafb_tc_unregister),
151 tgafb_tc_register(struct device *dev)
153 int status = tgafb_register(dev);
160 tgafb_tc_unregister(struct device *dev)
163 tgafb_unregister(dev);
166 #endif /* CONFIG_TC */
170 * tgafb_check_var - Optional function. Validates a var passed in.
171 * @var: frame buffer variable screen structure
172 * @info: frame buffer structure that represents a single frame buffer
175 tgafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
177 struct tga_par *par = (struct tga_par *)info->par;
179 if (par->tga_type == TGA_TYPE_8PLANE) {
180 if (var->bits_per_pixel != 8)
183 if (var->bits_per_pixel != 32)
186 var->red.length = var->green.length = var->blue.length = 8;
187 if (var->bits_per_pixel == 32) {
188 var->red.offset = 16;
189 var->green.offset = 8;
190 var->blue.offset = 0;
193 if (var->xres_virtual != var->xres || var->yres_virtual != var->yres)
195 if (var->xres * var->yres * (var->bits_per_pixel >> 3) > info->fix.smem_len)
199 if (1000000000 / var->pixclock > TGA_PLL_MAX_FREQ)
201 if ((var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
204 /* Some of the acceleration routines assume the line width is
205 a multiple of 64 bytes. */
206 if (var->xres * (par->tga_type == TGA_TYPE_8PLANE ? 1 : 4) % 64)
213 * tgafb_set_par - Optional function. Alters the hardware state.
214 * @info: frame buffer structure that represents a single frame buffer
217 tgafb_set_par(struct fb_info *info)
219 static unsigned int const deep_presets[4] = {
225 static unsigned int const rasterop_presets[4] = {
231 static unsigned int const mode_presets[4] = {
237 static unsigned int const base_addr_presets[4] = {
244 struct tga_par *par = (struct tga_par *) info->par;
245 int tga_bus_pci = TGA_BUS_PCI(par->dev);
246 int tga_bus_tc = TGA_BUS_TC(par->dev);
247 u32 htimings, vtimings, pll_freq;
251 /* Encode video timings. */
252 htimings = (((info->var.xres/4) & TGA_HORIZ_ACT_LSB)
253 | (((info->var.xres/4) & 0x600 << 19) & TGA_HORIZ_ACT_MSB));
254 vtimings = (info->var.yres & TGA_VERT_ACTIVE);
255 htimings |= ((info->var.right_margin/4) << 9) & TGA_HORIZ_FP;
256 vtimings |= (info->var.lower_margin << 11) & TGA_VERT_FP;
257 htimings |= ((info->var.hsync_len/4) << 14) & TGA_HORIZ_SYNC;
258 vtimings |= (info->var.vsync_len << 16) & TGA_VERT_SYNC;
259 htimings |= ((info->var.left_margin/4) << 21) & TGA_HORIZ_BP;
260 vtimings |= (info->var.upper_margin << 22) & TGA_VERT_BP;
262 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
263 htimings |= TGA_HORIZ_POLARITY;
264 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
265 vtimings |= TGA_VERT_POLARITY;
267 par->htimings = htimings;
268 par->vtimings = vtimings;
270 par->sync_on_green = !!(info->var.sync & FB_SYNC_ON_GREEN);
272 /* Store other useful values in par. */
273 par->xres = info->var.xres;
274 par->yres = info->var.yres;
275 par->pll_freq = pll_freq = 1000000000 / info->var.pixclock;
276 par->bits_per_pixel = info->var.bits_per_pixel;
277 info->fix.line_length = par->xres * (par->bits_per_pixel >> 3);
279 tga_type = par->tga_type;
281 /* First, disable video. */
282 TGA_WRITE_REG(par, TGA_VALID_VIDEO | TGA_VALID_BLANK, TGA_VALID_REG);
284 /* Write the DEEP register. */
285 while (TGA_READ_REG(par, TGA_CMD_STAT_REG) & 1) /* wait for not busy */
288 TGA_WRITE_REG(par, deep_presets[tga_type] |
289 (par->sync_on_green ? 0x0 : 0x00010000),
291 while (TGA_READ_REG(par, TGA_CMD_STAT_REG) & 1) /* wait for not busy */
295 /* Write some more registers. */
296 TGA_WRITE_REG(par, rasterop_presets[tga_type], TGA_RASTEROP_REG);
297 TGA_WRITE_REG(par, mode_presets[tga_type], TGA_MODE_REG);
298 TGA_WRITE_REG(par, base_addr_presets[tga_type], TGA_BASE_ADDR_REG);
300 /* Calculate & write the PLL. */
301 tgafb_set_pll(par, pll_freq);
303 /* Write some more registers. */
304 TGA_WRITE_REG(par, 0xffffffff, TGA_PLANEMASK_REG);
305 TGA_WRITE_REG(par, 0xffffffff, TGA_PIXELMASK_REG);
307 /* Init video timing regs. */
308 TGA_WRITE_REG(par, htimings, TGA_HORIZ_REG);
309 TGA_WRITE_REG(par, vtimings, TGA_VERT_REG);
311 /* Initialise RAMDAC. */
312 if (tga_type == TGA_TYPE_8PLANE && tga_bus_pci) {
314 /* Init BT485 RAMDAC registers. */
315 BT485_WRITE(par, 0xa2 | (par->sync_on_green ? 0x8 : 0x0),
317 BT485_WRITE(par, 0x01, BT485_ADDR_PAL_WRITE);
318 BT485_WRITE(par, 0x14, BT485_CMD_3); /* cursor 64x64 */
319 BT485_WRITE(par, 0x40, BT485_CMD_1);
320 BT485_WRITE(par, 0x20, BT485_CMD_2); /* cursor off, for now */
321 BT485_WRITE(par, 0xff, BT485_PIXEL_MASK);
323 /* Fill palette registers. */
324 BT485_WRITE(par, 0x00, BT485_ADDR_PAL_WRITE);
325 TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG);
327 for (i = 0; i < 256 * 3; i += 4) {
328 TGA_WRITE_REG(par, 0x55 | (BT485_DATA_PAL << 8),
330 TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8),
332 TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8),
334 TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8),
338 } else if (tga_type == TGA_TYPE_8PLANE && tga_bus_tc) {
340 /* Init BT459 RAMDAC registers. */
341 BT459_WRITE(par, BT459_REG_ACC, BT459_CMD_REG_0, 0x40);
342 BT459_WRITE(par, BT459_REG_ACC, BT459_CMD_REG_1, 0x00);
343 BT459_WRITE(par, BT459_REG_ACC, BT459_CMD_REG_2,
344 (par->sync_on_green ? 0xc0 : 0x40));
346 BT459_WRITE(par, BT459_REG_ACC, BT459_CUR_CMD_REG, 0x00);
348 /* Fill the palette. */
349 BT459_LOAD_ADDR(par, 0x0000);
350 TGA_WRITE_REG(par, BT459_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
352 for (i = 0; i < 256 * 3; i += 4) {
353 TGA_WRITE_REG(par, 0x55, TGA_RAMDAC_REG);
354 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
355 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
356 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
359 } else { /* 24-plane or 24plusZ */
361 /* Init BT463 RAMDAC registers. */
362 BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_0, 0x40);
363 BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_1, 0x08);
364 BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_2,
365 (par->sync_on_green ? 0xc0 : 0x40));
367 BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_0, 0xff);
368 BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_1, 0xff);
369 BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_2, 0xff);
370 BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_3, 0x0f);
372 BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_0, 0x00);
373 BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_1, 0x00);
374 BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_2, 0x00);
375 BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_3, 0x00);
377 /* Fill the palette. */
378 BT463_LOAD_ADDR(par, 0x0000);
379 TGA_WRITE_REG(par, BT463_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
381 #ifdef CONFIG_HW_CONSOLE
382 for (i = 0; i < 16; i++) {
383 int j = color_table[i];
385 TGA_WRITE_REG(par, default_red[j], TGA_RAMDAC_REG);
386 TGA_WRITE_REG(par, default_grn[j], TGA_RAMDAC_REG);
387 TGA_WRITE_REG(par, default_blu[j], TGA_RAMDAC_REG);
389 for (i = 0; i < 512 * 3; i += 4) {
391 for (i = 0; i < 528 * 3; i += 4) {
393 TGA_WRITE_REG(par, 0x55, TGA_RAMDAC_REG);
394 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
395 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
396 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
399 /* Fill window type table after start of vertical retrace. */
400 while (!(TGA_READ_REG(par, TGA_INTR_STAT_REG) & 0x01))
402 TGA_WRITE_REG(par, 0x01, TGA_INTR_STAT_REG);
404 while (!(TGA_READ_REG(par, TGA_INTR_STAT_REG) & 0x01))
406 TGA_WRITE_REG(par, 0x01, TGA_INTR_STAT_REG);
408 BT463_LOAD_ADDR(par, BT463_WINDOW_TYPE_BASE);
409 TGA_WRITE_REG(par, BT463_REG_ACC << 2, TGA_RAMDAC_SETUP_REG);
411 for (i = 0; i < 16; i++) {
412 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
413 TGA_WRITE_REG(par, 0x01, TGA_RAMDAC_REG);
414 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
419 /* Finally, enable video scan (and pray for the monitor... :-) */
420 TGA_WRITE_REG(par, TGA_VALID_VIDEO, TGA_VALID_REG);
425 #define DIFFCHECK(X) \
428 int delta = f - (TGA_PLL_BASE_FREQ * (X)) / (r << shift); \
431 if (delta < min_diff) \
432 min_diff = delta, vm = m, va = a, vr = r; \
437 tgafb_set_pll(struct tga_par *par, int f)
439 int n, shift, base, min_diff, target;
440 int r,a,m,vm = 34, va = 1, vr = 30;
442 for (r = 0 ; r < 12 ; r++)
443 TGA_WRITE_REG(par, !r, TGA_CLOCK_REG);
445 if (f > TGA_PLL_MAX_FREQ)
446 f = TGA_PLL_MAX_FREQ;
448 if (f >= TGA_PLL_MAX_FREQ / 2)
450 else if (f >= TGA_PLL_MAX_FREQ / 4)
455 TGA_WRITE_REG(par, shift & 1, TGA_CLOCK_REG);
456 TGA_WRITE_REG(par, shift >> 1, TGA_CLOCK_REG);
458 for (r = 0 ; r < 10 ; r++)
459 TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
462 TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
463 TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
465 else if (f <= 200000) {
466 TGA_WRITE_REG(par, 1, TGA_CLOCK_REG);
467 TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
470 TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
471 TGA_WRITE_REG(par, 1, TGA_CLOCK_REG);
474 TGA_WRITE_REG(par, 1, TGA_CLOCK_REG);
475 TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
476 TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
477 TGA_WRITE_REG(par, 1, TGA_CLOCK_REG);
478 TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
479 TGA_WRITE_REG(par, 1, TGA_CLOCK_REG);
481 target = (f << shift) / TGA_PLL_BASE_FREQ;
482 min_diff = TGA_PLL_MAX_FREQ;
489 for (n = base < 7 ? 7 : base; n < base + target && n < 449; n++) {
490 m = ((n + 3) / 7) - 1;
492 DIFFCHECK((m + 1) * 7);
494 DIFFCHECK((m + 1) * 7);
505 for (r = 0; r < 8; r++)
506 TGA_WRITE_REG(par, (vm >> r) & 1, TGA_CLOCK_REG);
507 for (r = 0; r < 8 ; r++)
508 TGA_WRITE_REG(par, (va >> r) & 1, TGA_CLOCK_REG);
509 for (r = 0; r < 7 ; r++)
510 TGA_WRITE_REG(par, (vr >> r) & 1, TGA_CLOCK_REG);
511 TGA_WRITE_REG(par, ((vr >> 7) & 1)|2, TGA_CLOCK_REG);
516 * tgafb_setcolreg - Optional function. Sets a color register.
517 * @regno: boolean, 0 copy local, 1 get_user() function
518 * @red: frame buffer colormap structure
519 * @green: The green value which can be up to 16 bits wide
520 * @blue: The blue value which can be up to 16 bits wide.
521 * @transp: If supported the alpha value which can be up to 16 bits wide.
522 * @info: frame buffer info structure
525 tgafb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
526 unsigned transp, struct fb_info *info)
528 struct tga_par *par = (struct tga_par *) info->par;
529 int tga_bus_pci = TGA_BUS_PCI(par->dev);
530 int tga_bus_tc = TGA_BUS_TC(par->dev);
538 if (par->tga_type == TGA_TYPE_8PLANE && tga_bus_pci) {
539 BT485_WRITE(par, regno, BT485_ADDR_PAL_WRITE);
540 TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG);
541 TGA_WRITE_REG(par, red|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
542 TGA_WRITE_REG(par, green|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
543 TGA_WRITE_REG(par, blue|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
544 } else if (par->tga_type == TGA_TYPE_8PLANE && tga_bus_tc) {
545 BT459_LOAD_ADDR(par, regno);
546 TGA_WRITE_REG(par, BT459_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
547 TGA_WRITE_REG(par, red, TGA_RAMDAC_REG);
548 TGA_WRITE_REG(par, green, TGA_RAMDAC_REG);
549 TGA_WRITE_REG(par, blue, TGA_RAMDAC_REG);
552 u32 value = (regno << 16) | (regno << 8) | regno;
553 ((u32 *)info->pseudo_palette)[regno] = value;
555 BT463_LOAD_ADDR(par, regno);
556 TGA_WRITE_REG(par, BT463_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
557 TGA_WRITE_REG(par, red, TGA_RAMDAC_REG);
558 TGA_WRITE_REG(par, green, TGA_RAMDAC_REG);
559 TGA_WRITE_REG(par, blue, TGA_RAMDAC_REG);
567 * tgafb_blank - Optional function. Blanks the display.
568 * @blank_mode: the blank mode we want.
569 * @info: frame buffer structure that represents a single frame buffer
572 tgafb_blank(int blank, struct fb_info *info)
574 struct tga_par *par = (struct tga_par *) info->par;
575 u32 vhcr, vvcr, vvvr;
578 local_irq_save(flags);
580 vhcr = TGA_READ_REG(par, TGA_HORIZ_REG);
581 vvcr = TGA_READ_REG(par, TGA_VERT_REG);
582 vvvr = TGA_READ_REG(par, TGA_VALID_REG);
583 vvvr &= ~(TGA_VALID_VIDEO | TGA_VALID_BLANK);
586 case FB_BLANK_UNBLANK: /* Unblanking */
587 if (par->vesa_blanked) {
588 TGA_WRITE_REG(par, vhcr & 0xbfffffff, TGA_HORIZ_REG);
589 TGA_WRITE_REG(par, vvcr & 0xbfffffff, TGA_VERT_REG);
590 par->vesa_blanked = 0;
592 TGA_WRITE_REG(par, vvvr | TGA_VALID_VIDEO, TGA_VALID_REG);
595 case FB_BLANK_NORMAL: /* Normal blanking */
596 TGA_WRITE_REG(par, vvvr | TGA_VALID_VIDEO | TGA_VALID_BLANK,
600 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
601 TGA_WRITE_REG(par, vvcr | 0x40000000, TGA_VERT_REG);
602 TGA_WRITE_REG(par, vvvr | TGA_VALID_BLANK, TGA_VALID_REG);
603 par->vesa_blanked = 1;
606 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
607 TGA_WRITE_REG(par, vhcr | 0x40000000, TGA_HORIZ_REG);
608 TGA_WRITE_REG(par, vvvr | TGA_VALID_BLANK, TGA_VALID_REG);
609 par->vesa_blanked = 1;
612 case FB_BLANK_POWERDOWN: /* Poweroff */
613 TGA_WRITE_REG(par, vhcr | 0x40000000, TGA_HORIZ_REG);
614 TGA_WRITE_REG(par, vvcr | 0x40000000, TGA_VERT_REG);
615 TGA_WRITE_REG(par, vvvr | TGA_VALID_BLANK, TGA_VALID_REG);
616 par->vesa_blanked = 1;
620 local_irq_restore(flags);
630 tgafb_mono_imageblit(struct fb_info *info, const struct fb_image *image)
632 struct tga_par *par = (struct tga_par *) info->par;
633 u32 fgcolor, bgcolor, dx, dy, width, height, vxres, vyres, pixelmask;
634 unsigned long rincr, line_length, shift, pos, is8bpp;
636 const unsigned char *data;
637 void __iomem *regs_base;
638 void __iomem *fb_base;
640 is8bpp = info->var.bits_per_pixel == 8;
644 width = image->width;
645 height = image->height;
646 vxres = info->var.xres_virtual;
647 vyres = info->var.yres_virtual;
648 line_length = info->fix.line_length;
649 rincr = (width + 7) / 8;
651 /* A shift below cannot cope with. */
652 if (unlikely(width == 0))
654 /* Crop the image to the screen. */
655 if (dx > vxres || dy > vyres)
657 if (dx + width > vxres)
659 if (dy + height > vyres)
662 regs_base = par->tga_regs_base;
663 fb_base = par->tga_fb_base;
665 /* Expand the color values to fill 32-bits. */
666 /* ??? Would be nice to notice colour changes elsewhere, so
667 that we can do this only when necessary. */
668 fgcolor = image->fg_color;
669 bgcolor = image->bg_color;
671 fgcolor |= fgcolor << 8;
672 fgcolor |= fgcolor << 16;
673 bgcolor |= bgcolor << 8;
674 bgcolor |= bgcolor << 16;
677 fgcolor = ((u32 *)info->pseudo_palette)[fgcolor];
679 bgcolor = ((u32 *)info->pseudo_palette)[bgcolor];
681 __raw_writel(fgcolor, regs_base + TGA_FOREGROUND_REG);
682 __raw_writel(bgcolor, regs_base + TGA_BACKGROUND_REG);
684 /* Acquire proper alignment; set up the PIXELMASK register
685 so that we only write the proper character cell. */
686 pos = dy * line_length;
693 shift = (pos & 7) >> 2;
697 data = (const unsigned char *) image->data;
699 /* Enable opaque stipple mode. */
701 ? TGA_MODE_SBM_8BPP | TGA_MODE_OPAQUE_STIPPLE
702 : TGA_MODE_SBM_24BPP | TGA_MODE_OPAQUE_STIPPLE),
703 regs_base + TGA_MODE_REG);
705 if (width + shift <= 32) {
706 unsigned long bwidth;
708 /* Handle common case of imaging a single character, in
709 a font less than or 32 pixels wide. */
711 /* Avoid a shift by 32; width > 0 implied. */
712 pixelmask = (2ul << (width - 1)) - 1;
714 __raw_writel(pixelmask, regs_base + TGA_PIXELMASK_REG);
717 bwidth = (width + 7) / 8;
719 for (i = 0; i < height; ++i) {
722 /* The image data is bit big endian; we need
724 for (j = 0; j < bwidth; ++j)
725 mask |= bitrev8(data[j]) << (j * 8);
727 __raw_writel(mask << shift, fb_base + pos);
733 __raw_writel(0xffffffff, regs_base + TGA_PIXELMASK_REG);
734 } else if (shift == 0) {
735 unsigned long pos0 = pos;
736 const unsigned char *data0 = data;
737 unsigned long bincr = (is8bpp ? 8 : 8*4);
738 unsigned long bwidth;
740 /* Handle another common case in which accel_putcs
741 generates a large bitmap, which happens to be aligned.
742 Allow the tail to be misaligned. This case is
743 interesting because we've not got to hold partial
744 bytes across the words being written. */
748 bwidth = (width / 8) & -4;
749 for (i = 0; i < height; ++i) {
750 for (j = 0; j < bwidth; j += 4) {
752 mask |= bitrev8(data[j+0]) << (0 * 8);
753 mask |= bitrev8(data[j+1]) << (1 * 8);
754 mask |= bitrev8(data[j+2]) << (2 * 8);
755 mask |= bitrev8(data[j+3]) << (3 * 8);
756 __raw_writel(mask, fb_base + pos + j*bincr);
763 pixelmask = (1ul << (width & 31)) - 1;
765 __raw_writel(pixelmask, regs_base + TGA_PIXELMASK_REG);
768 pos = pos0 + bwidth*bincr;
769 data = data0 + bwidth;
770 bwidth = ((width & 31) + 7) / 8;
772 for (i = 0; i < height; ++i) {
774 for (j = 0; j < bwidth; ++j)
775 mask |= bitrev8(data[j]) << (j * 8);
776 __raw_writel(mask, fb_base + pos);
781 __raw_writel(0xffffffff, regs_base + TGA_PIXELMASK_REG);
784 unsigned long pos0 = pos;
785 const unsigned char *data0 = data;
786 unsigned long bincr = (is8bpp ? 8 : 8*4);
787 unsigned long bwidth;
789 /* Finally, handle the generic case of misaligned start.
790 Here we split the write into 16-bit spans. This allows
791 us to use only one pixel mask, instead of four as would
792 be required by writing 24-bit spans. */
794 pixelmask = 0xffff << shift;
795 __raw_writel(pixelmask, regs_base + TGA_PIXELMASK_REG);
798 bwidth = (width / 8) & -2;
799 for (i = 0; i < height; ++i) {
800 for (j = 0; j < bwidth; j += 2) {
802 mask |= bitrev8(data[j+0]) << (0 * 8);
803 mask |= bitrev8(data[j+1]) << (1 * 8);
805 __raw_writel(mask, fb_base + pos + j*bincr);
812 pixelmask = ((1ul << (width & 15)) - 1) << shift;
814 __raw_writel(pixelmask, regs_base + TGA_PIXELMASK_REG);
817 pos = pos0 + bwidth*bincr;
818 data = data0 + bwidth;
819 bwidth = (width & 15) > 8;
821 for (i = 0; i < height; ++i) {
822 u32 mask = bitrev8(data[0]);
824 mask |= bitrev8(data[1]) << 8;
826 __raw_writel(mask, fb_base + pos);
832 __raw_writel(0xffffffff, regs_base + TGA_PIXELMASK_REG);
835 /* Disable opaque stipple mode. */
837 ? TGA_MODE_SBM_8BPP | TGA_MODE_SIMPLE
838 : TGA_MODE_SBM_24BPP | TGA_MODE_SIMPLE),
839 regs_base + TGA_MODE_REG);
843 tgafb_clut_imageblit(struct fb_info *info, const struct fb_image *image)
845 struct tga_par *par = (struct tga_par *) info->par;
846 u32 color, dx, dy, width, height, vxres, vyres;
847 u32 *palette = ((u32 *)info->pseudo_palette);
848 unsigned long pos, line_length, i, j;
849 const unsigned char *data;
850 void __iomem *regs_base, *fb_base;
854 width = image->width;
855 height = image->height;
856 vxres = info->var.xres_virtual;
857 vyres = info->var.yres_virtual;
858 line_length = info->fix.line_length;
860 /* Crop the image to the screen. */
861 if (dx > vxres || dy > vyres)
863 if (dx + width > vxres)
865 if (dy + height > vyres)
868 regs_base = par->tga_regs_base;
869 fb_base = par->tga_fb_base;
871 pos = dy * line_length + (dx * 4);
874 /* Now copy the image, color_expanding via the palette. */
875 for (i = 0; i < height; i++) {
876 for (j = 0; j < width; j++) {
877 color = palette[*data++];
878 __raw_writel(color, fb_base + pos + j*4);
885 * tgafb_imageblit - REQUIRED function. Can use generic routines if
886 * non acclerated hardware and packed pixel based.
887 * Copies a image from system memory to the screen.
889 * @info: frame buffer structure that represents a single frame buffer
890 * @image: structure defining the image.
893 tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
895 unsigned int is8bpp = info->var.bits_per_pixel == 8;
897 /* If a mono image, regardless of FB depth, go do it. */
898 if (image->depth == 1) {
899 tgafb_mono_imageblit(info, image);
903 /* For copies that aren't pixel expansion, there's little we
904 can do better than the generic code. */
905 /* ??? There is a DMA write mode; I wonder if that could be
906 made to pull the data from the image buffer... */
907 if (image->depth == info->var.bits_per_pixel) {
908 cfb_imageblit(info, image);
912 /* If 24-plane FB and the image is 8-plane with CLUT, we can do it. */
913 if (!is8bpp && image->depth == 8) {
914 tgafb_clut_imageblit(info, image);
918 /* Silently return... */
922 * tgafb_fillrect - REQUIRED function. Can use generic routines if
923 * non acclerated hardware and packed pixel based.
924 * Draws a rectangle on the screen.
926 * @info: frame buffer structure that represents a single frame buffer
927 * @rect: structure defining the rectagle and operation.
930 tgafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
932 struct tga_par *par = (struct tga_par *) info->par;
933 int is8bpp = info->var.bits_per_pixel == 8;
934 u32 dx, dy, width, height, vxres, vyres, color;
935 unsigned long pos, align, line_length, i, j;
936 void __iomem *regs_base;
937 void __iomem *fb_base;
942 height = rect->height;
943 vxres = info->var.xres_virtual;
944 vyres = info->var.yres_virtual;
945 line_length = info->fix.line_length;
946 regs_base = par->tga_regs_base;
947 fb_base = par->tga_fb_base;
949 /* Crop the rectangle to the screen. */
950 if (dx > vxres || dy > vyres || !width || !height)
952 if (dx + width > vxres)
954 if (dy + height > vyres)
957 pos = dy * line_length + dx * (is8bpp ? 1 : 4);
959 /* ??? We could implement ROP_XOR with opaque fill mode
960 and a RasterOp setting of GXxor, but as far as I can
961 tell, this mode is not actually used in the kernel.
962 Thus I am ignoring it for now. */
963 if (rect->rop != ROP_COPY) {
964 cfb_fillrect(info, rect);
968 /* Expand the color value to fill 8 pixels. */
972 color |= color << 16;
973 __raw_writel(color, regs_base + TGA_BLOCK_COLOR0_REG);
974 __raw_writel(color, regs_base + TGA_BLOCK_COLOR1_REG);
977 color = ((u32 *)info->pseudo_palette)[color];
978 __raw_writel(color, regs_base + TGA_BLOCK_COLOR0_REG);
979 __raw_writel(color, regs_base + TGA_BLOCK_COLOR1_REG);
980 __raw_writel(color, regs_base + TGA_BLOCK_COLOR2_REG);
981 __raw_writel(color, regs_base + TGA_BLOCK_COLOR3_REG);
982 __raw_writel(color, regs_base + TGA_BLOCK_COLOR4_REG);
983 __raw_writel(color, regs_base + TGA_BLOCK_COLOR5_REG);
984 __raw_writel(color, regs_base + TGA_BLOCK_COLOR6_REG);
985 __raw_writel(color, regs_base + TGA_BLOCK_COLOR7_REG);
988 /* The DATA register holds the fill mask for block fill mode.
989 Since we're not stippling, this is all ones. */
990 __raw_writel(0xffffffff, regs_base + TGA_DATA_REG);
992 /* Enable block fill mode. */
994 ? TGA_MODE_SBM_8BPP | TGA_MODE_BLOCK_FILL
995 : TGA_MODE_SBM_24BPP | TGA_MODE_BLOCK_FILL),
996 regs_base + TGA_MODE_REG);
999 /* We can fill 2k pixels per operation. Notice blocks that fit
1000 the width of the screen so that we can take advantage of this
1001 and fill more than one line per write. */
1002 if (width == line_length)
1003 width *= height, height = 1;
1005 /* The write into the frame buffer must be aligned to 4 bytes,
1006 but we are allowed to encode the offset within the word in
1007 the data word written. */
1008 align = (pos & 3) << 16;
1011 if (width <= 2048) {
1014 data = (width - 1) | align;
1016 for (i = 0; i < height; ++i) {
1017 __raw_writel(data, fb_base + pos);
1021 unsigned long Bpp = (is8bpp ? 1 : 4);
1022 unsigned long nwidth = width & -2048;
1025 fdata = (2048 - 1) | align;
1026 ldata = ((width & 2047) - 1) | align;
1028 for (i = 0; i < height; ++i) {
1029 for (j = 0; j < nwidth; j += 2048)
1030 __raw_writel(fdata, fb_base + pos + j*Bpp);
1032 __raw_writel(ldata, fb_base + pos + j*Bpp);
1038 /* Disable block fill mode. */
1039 __raw_writel((is8bpp
1040 ? TGA_MODE_SBM_8BPP | TGA_MODE_SIMPLE
1041 : TGA_MODE_SBM_24BPP | TGA_MODE_SIMPLE),
1042 regs_base + TGA_MODE_REG);
1046 * tgafb_copyarea - REQUIRED function. Can use generic routines if
1047 * non acclerated hardware and packed pixel based.
1048 * Copies on area of the screen to another area.
1050 * @info: frame buffer structure that represents a single frame buffer
1051 * @area: structure defining the source and destination.
1054 /* Handle the special case of copying entire lines, e.g. during scrolling.
1055 We can avoid a lot of needless computation in this case. In the 8bpp
1056 case we need to use the COPY64 registers instead of mask writes into
1057 the frame buffer to achieve maximum performance. */
1060 copyarea_line_8bpp(struct fb_info *info, u32 dy, u32 sy,
1061 u32 height, u32 width)
1063 struct tga_par *par = (struct tga_par *) info->par;
1064 void __iomem *tga_regs = par->tga_regs_base;
1065 unsigned long dpos, spos, i, n64;
1067 /* Set up the MODE and PIXELSHIFT registers. */
1068 __raw_writel(TGA_MODE_SBM_8BPP | TGA_MODE_COPY, tga_regs+TGA_MODE_REG);
1069 __raw_writel(0, tga_regs+TGA_PIXELSHIFT_REG);
1072 n64 = (height * width) / 64;
1075 spos = (sy + height) * width;
1076 dpos = (dy + height) * width;
1078 for (i = 0; i < n64; ++i) {
1081 __raw_writel(spos, tga_regs+TGA_COPY64_SRC);
1083 __raw_writel(dpos, tga_regs+TGA_COPY64_DST);
1090 for (i = 0; i < n64; ++i) {
1091 __raw_writel(spos, tga_regs+TGA_COPY64_SRC);
1093 __raw_writel(dpos, tga_regs+TGA_COPY64_DST);
1100 /* Reset the MODE register to normal. */
1101 __raw_writel(TGA_MODE_SBM_8BPP|TGA_MODE_SIMPLE, tga_regs+TGA_MODE_REG);
1105 copyarea_line_32bpp(struct fb_info *info, u32 dy, u32 sy,
1106 u32 height, u32 width)
1108 struct tga_par *par = (struct tga_par *) info->par;
1109 void __iomem *tga_regs = par->tga_regs_base;
1110 void __iomem *tga_fb = par->tga_fb_base;
1113 unsigned long i, n16;
1115 /* Set up the MODE and PIXELSHIFT registers. */
1116 __raw_writel(TGA_MODE_SBM_24BPP | TGA_MODE_COPY, tga_regs+TGA_MODE_REG);
1117 __raw_writel(0, tga_regs+TGA_PIXELSHIFT_REG);
1120 n16 = (height * width) / 16;
1123 src = tga_fb + (sy + height) * width * 4;
1124 dst = tga_fb + (dy + height) * width * 4;
1126 for (i = 0; i < n16; ++i) {
1129 __raw_writel(0xffff, src);
1131 __raw_writel(0xffff, dst);
1135 src = tga_fb + sy * width * 4;
1136 dst = tga_fb + dy * width * 4;
1138 for (i = 0; i < n16; ++i) {
1139 __raw_writel(0xffff, src);
1141 __raw_writel(0xffff, dst);
1148 /* Reset the MODE register to normal. */
1149 __raw_writel(TGA_MODE_SBM_24BPP|TGA_MODE_SIMPLE, tga_regs+TGA_MODE_REG);
1152 /* The (almost) general case of backward copy in 8bpp mode. */
1154 copyarea_8bpp(struct fb_info *info, u32 dx, u32 dy, u32 sx, u32 sy,
1155 u32 height, u32 width, u32 line_length,
1156 const struct fb_copyarea *area)
1158 struct tga_par *par = (struct tga_par *) info->par;
1160 int depos, sepos, backward, last_step, step;
1163 void __iomem *tga_regs;
1164 void __iomem *tga_fb;
1166 /* Do acceleration only if we are aligned on 8 pixels */
1167 if ((dx | sx | width) & 7) {
1168 cfb_copyarea(info, area);
1172 yincr = line_length;
1178 backward = dy == sy && dx > sx && dx < sx + width;
1180 /* Compute the offsets and alignments in the frame buffer.
1181 More than anything else, these control how we do copies. */
1182 depos = dy * line_length + dx;
1183 sepos = sy * line_length + sx;
1185 depos += width, sepos += width;
1187 /* Next copy full words at a time. */
1189 last_step = width % 32;
1191 /* Finally copy the unaligned head of the span. */
1192 mask_last = (1ul << last_step) - 1;
1199 last_step = -last_step;
1204 tga_regs = par->tga_regs_base;
1205 tga_fb = par->tga_fb_base;
1207 /* Set up the MODE and PIXELSHIFT registers. */
1208 __raw_writel(TGA_MODE_SBM_8BPP|TGA_MODE_COPY, tga_regs+TGA_MODE_REG);
1209 __raw_writel(0, tga_regs+TGA_PIXELSHIFT_REG);
1212 for (i = 0; i < height; ++i) {
1217 sfb = tga_fb + sepos;
1218 dfb = tga_fb + depos;
1220 for (j = 0; j < n32; j++) {
1221 if (j < 2 && j + 1 < n32 && !backward &&
1222 !(((unsigned long)sfb | (unsigned long)dfb) & 63)) {
1224 __raw_writel(sfb - tga_fb, tga_regs+TGA_COPY64_SRC);
1226 __raw_writel(dfb - tga_fb, tga_regs+TGA_COPY64_DST);
1231 } while (j + 1 < n32);
1235 __raw_writel(0xffffffff, sfb);
1237 __raw_writel(0xffffffff, dfb);
1244 sfb += last_step - step;
1245 dfb += last_step - step;
1246 __raw_writel(mask_last, sfb);
1248 __raw_writel(mask_last, dfb);
1256 /* Reset the MODE register to normal. */
1257 __raw_writel(TGA_MODE_SBM_8BPP|TGA_MODE_SIMPLE, tga_regs+TGA_MODE_REG);
1261 tgafb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
1263 unsigned long dx, dy, width, height, sx, sy, vxres, vyres;
1264 unsigned long line_length, bpp;
1268 width = area->width;
1269 height = area->height;
1272 vxres = info->var.xres_virtual;
1273 vyres = info->var.yres_virtual;
1274 line_length = info->fix.line_length;
1276 /* The top left corners must be in the virtual screen. */
1277 if (dx > vxres || sx > vxres || dy > vyres || sy > vyres)
1280 /* Clip the destination. */
1281 if (dx + width > vxres)
1283 if (dy + height > vyres)
1284 height = vyres - dy;
1286 /* The source must be completely inside the virtual screen. */
1287 if (sx + width > vxres || sy + height > vyres)
1290 bpp = info->var.bits_per_pixel;
1292 /* Detect copies of the entire line. */
1293 if (width * (bpp >> 3) == line_length) {
1295 copyarea_line_8bpp(info, dy, sy, height, width);
1297 copyarea_line_32bpp(info, dy, sy, height, width);
1300 /* ??? The documentation is unclear to me exactly how the pixelshift
1301 register works in 32bpp mode. Since I don't have hardware to test,
1302 give up for now and fall back on the generic routines. */
1304 cfb_copyarea(info, area);
1307 copyarea_8bpp(info, dx, dy, sx, sy, height,
1308 width, line_length, area);
1317 tgafb_init_fix(struct fb_info *info)
1319 struct tga_par *par = (struct tga_par *)info->par;
1320 int tga_bus_pci = TGA_BUS_PCI(par->dev);
1321 int tga_bus_tc = TGA_BUS_TC(par->dev);
1322 u8 tga_type = par->tga_type;
1323 const char *tga_type_name = NULL;
1324 unsigned memory_size;
1327 case TGA_TYPE_8PLANE:
1329 tga_type_name = "Digital ZLXp-E1";
1331 tga_type_name = "Digital ZLX-E1";
1332 memory_size = 2097152;
1334 case TGA_TYPE_24PLANE:
1336 tga_type_name = "Digital ZLXp-E2";
1338 tga_type_name = "Digital ZLX-E2";
1339 memory_size = 8388608;
1341 case TGA_TYPE_24PLUSZ:
1343 tga_type_name = "Digital ZLXp-E3";
1345 tga_type_name = "Digital ZLX-E3";
1346 memory_size = 16777216;
1349 tga_type_name = "Unknown";
1350 memory_size = 16777216;
1354 strlcpy(info->fix.id, tga_type_name, sizeof(info->fix.id));
1356 info->fix.type = FB_TYPE_PACKED_PIXELS;
1357 info->fix.type_aux = 0;
1358 info->fix.visual = (tga_type == TGA_TYPE_8PLANE
1359 ? FB_VISUAL_PSEUDOCOLOR
1360 : FB_VISUAL_DIRECTCOLOR);
1362 info->fix.smem_start = (size_t) par->tga_fb_base;
1363 info->fix.smem_len = memory_size;
1364 info->fix.mmio_start = (size_t) par->tga_regs_base;
1365 info->fix.mmio_len = 512;
1367 info->fix.xpanstep = 0;
1368 info->fix.ypanstep = 0;
1369 info->fix.ywrapstep = 0;
1371 info->fix.accel = FB_ACCEL_DEC_TGA;
1374 * These are needed by fb_set_logo_truepalette(), so we
1375 * set them here for 24-plane cards.
1377 if (tga_type != TGA_TYPE_8PLANE) {
1378 info->var.red.length = 8;
1379 info->var.green.length = 8;
1380 info->var.blue.length = 8;
1381 info->var.red.offset = 16;
1382 info->var.green.offset = 8;
1383 info->var.blue.offset = 0;
1387 static int tgafb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1389 /* We just use this to catch switches out of graphics mode. */
1390 tgafb_set_par(info); /* A bit of overkill for BASE_ADDR reset. */
1394 static int __devinit
1395 tgafb_register(struct device *dev)
1397 static const struct fb_videomode modedb_tc = {
1398 /* 1280x1024 @ 72 Hz, 76.8 kHz hsync */
1399 "1280x1024@72", 0, 1280, 1024, 7645, 224, 28, 33, 3, 160, 3,
1400 FB_SYNC_ON_GREEN, FB_VMODE_NONINTERLACED
1403 static unsigned int const fb_offset_presets[4] = {
1404 TGA_8PLANE_FB_OFFSET,
1405 TGA_24PLANE_FB_OFFSET,
1407 TGA_24PLUSZ_FB_OFFSET
1410 const struct fb_videomode *modedb_tga = NULL;
1411 resource_size_t bar0_start = 0, bar0_len = 0;
1412 const char *mode_option_tga = NULL;
1413 int tga_bus_pci = TGA_BUS_PCI(dev);
1414 int tga_bus_tc = TGA_BUS_TC(dev);
1415 unsigned int modedbsize_tga = 0;
1416 void __iomem *mem_base;
1417 struct fb_info *info;
1418 struct tga_par *par;
1422 /* Enable device in PCI config. */
1423 if (tga_bus_pci && pci_enable_device(to_pci_dev(dev))) {
1424 printk(KERN_ERR "tgafb: Cannot enable PCI device\n");
1428 /* Allocate the fb and par structures. */
1429 info = framebuffer_alloc(sizeof(struct tga_par), dev);
1431 printk(KERN_ERR "tgafb: Cannot allocate memory\n");
1436 dev_set_drvdata(dev, info);
1438 /* Request the mem regions. */
1441 bar0_start = pci_resource_start(to_pci_dev(dev), 0);
1442 bar0_len = pci_resource_len(to_pci_dev(dev), 0);
1445 bar0_start = to_tc_dev(dev)->resource.start;
1446 bar0_len = to_tc_dev(dev)->resource.end - bar0_start + 1;
1448 if (!request_mem_region (bar0_start, bar0_len, "tgafb")) {
1449 printk(KERN_ERR "tgafb: cannot reserve FB region\n");
1453 /* Map the framebuffer. */
1454 mem_base = ioremap_nocache(bar0_start, bar0_len);
1456 printk(KERN_ERR "tgafb: Cannot map MMIO\n");
1460 /* Grab info about the card. */
1461 tga_type = (readl(mem_base) >> 12) & 0x0f;
1463 par->tga_mem_base = mem_base;
1464 par->tga_fb_base = mem_base + fb_offset_presets[tga_type];
1465 par->tga_regs_base = mem_base + TGA_REGS_OFFSET;
1466 par->tga_type = tga_type;
1468 par->tga_chip_rev = (to_pci_dev(dev))->revision;
1470 par->tga_chip_rev = TGA_READ_REG(par, TGA_START_REG) & 0xff;
1472 /* Setup framebuffer. */
1473 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA |
1474 FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_FILLRECT;
1475 info->fbops = &tgafb_ops;
1476 info->screen_base = par->tga_fb_base;
1477 info->pseudo_palette = par->palette;
1479 /* This should give a reasonable default video mode. */
1481 mode_option_tga = mode_option_pci;
1484 mode_option_tga = mode_option_tc;
1485 modedb_tga = &modedb_tc;
1489 tgafb_init_fix(info);
1491 ret = fb_find_mode(&info->var, info,
1492 mode_option ? mode_option : mode_option_tga,
1493 modedb_tga, modedbsize_tga, NULL,
1494 tga_type == TGA_TYPE_8PLANE ? 8 : 32);
1495 if (ret == 0 || ret == 4) {
1496 printk(KERN_ERR "tgafb: Could not find valid video mode\n");
1501 if (fb_alloc_cmap(&info->cmap, 256, 0)) {
1502 printk(KERN_ERR "tgafb: Could not allocate color map\n");
1507 tgafb_set_par(info);
1509 if (register_framebuffer(info) < 0) {
1510 printk(KERN_ERR "tgafb: Could not register framebuffer\n");
1516 pr_info("tgafb: DC21030 [TGA] detected, rev=0x%02x\n",
1518 pr_info("tgafb: at PCI bus %d, device %d, function %d\n",
1519 to_pci_dev(dev)->bus->number,
1520 PCI_SLOT(to_pci_dev(dev)->devfn),
1521 PCI_FUNC(to_pci_dev(dev)->devfn));
1524 pr_info("tgafb: SFB+ detected, rev=0x%02x\n",
1526 pr_info("fb%d: %s frame buffer device at 0x%lx\n",
1527 info->node, info->fix.id, (long)bar0_start);
1532 fb_dealloc_cmap(&info->cmap);
1536 release_mem_region(bar0_start, bar0_len);
1538 framebuffer_release(info);
1542 static void __devexit
1543 tgafb_unregister(struct device *dev)
1545 resource_size_t bar0_start = 0, bar0_len = 0;
1546 int tga_bus_pci = TGA_BUS_PCI(dev);
1547 int tga_bus_tc = TGA_BUS_TC(dev);
1548 struct fb_info *info = NULL;
1549 struct tga_par *par;
1551 info = dev_get_drvdata(dev);
1556 unregister_framebuffer(info);
1557 fb_dealloc_cmap(&info->cmap);
1558 iounmap(par->tga_mem_base);
1560 bar0_start = pci_resource_start(to_pci_dev(dev), 0);
1561 bar0_len = pci_resource_len(to_pci_dev(dev), 0);
1564 bar0_start = to_tc_dev(dev)->resource.start;
1565 bar0_len = to_tc_dev(dev)->resource.end - bar0_start + 1;
1567 release_mem_region(bar0_start, bar0_len);
1568 framebuffer_release(info);
1571 static void __devexit
1574 tc_unregister_driver(&tgafb_tc_driver);
1575 pci_unregister_driver(&tgafb_pci_driver);
1579 static int __devinit
1580 tgafb_setup(char *arg)
1585 while ((this_opt = strsep(&arg, ","))) {
1588 if (!strncmp(this_opt, "mode:", 5))
1589 mode_option = this_opt+5;
1592 "tgafb: unknown parameter %s\n",
1599 #endif /* !MODULE */
1601 static int __devinit
1606 char *option = NULL;
1608 if (fb_get_options("tgafb", &option))
1610 tgafb_setup(option);
1612 status = pci_register_driver(&tgafb_pci_driver);
1614 status = tc_register_driver(&tgafb_tc_driver);
1622 module_init(tgafb_init);
1623 module_exit(tgafb_exit);
1625 MODULE_DESCRIPTION("Framebuffer driver for TGA/SFB+ chipset");
1626 MODULE_LICENSE("GPL");