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 tgafb_register(struct device
*dev
);
65 static void 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 tgafb_pci_register(struct pci_dev
*, const struct pci_device_id
*);
97 static void tgafb_pci_unregister(struct pci_dev
*);
99 static struct pci_device_id
const tgafb_pci_table
[] = {
100 { PCI_DEVICE(PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TGA
) },
103 MODULE_DEVICE_TABLE(pci
, tgafb_pci_table
);
105 static struct pci_driver tgafb_pci_driver
= {
107 .id_table
= tgafb_pci_table
,
108 .probe
= tgafb_pci_register
,
109 .remove
= tgafb_pci_unregister
,
112 static int tgafb_pci_register(struct pci_dev
*pdev
,
113 const struct pci_device_id
*ent
)
115 return tgafb_register(&pdev
->dev
);
118 static void tgafb_pci_unregister(struct pci_dev
*pdev
)
120 tgafb_unregister(&pdev
->dev
);
122 #endif /* CONFIG_PCI */
126 * TC registration operations
128 static int tgafb_tc_register(struct device
*);
129 static int tgafb_tc_unregister(struct device
*);
131 static struct tc_device_id
const tgafb_tc_table
[] = {
132 { "DEC ", "PMAGD-AA" },
133 { "DEC ", "PMAGD " },
136 MODULE_DEVICE_TABLE(tc
, tgafb_tc_table
);
138 static struct tc_driver tgafb_tc_driver
= {
139 .id_table
= tgafb_tc_table
,
143 .probe
= tgafb_tc_register
,
144 .remove
= tgafb_tc_unregister
,
148 static int tgafb_tc_register(struct device
*dev
)
150 int status
= tgafb_register(dev
);
156 static int tgafb_tc_unregister(struct device
*dev
)
159 tgafb_unregister(dev
);
162 #endif /* CONFIG_TC */
166 * tgafb_check_var - Optional function. Validates a var passed in.
167 * @var: frame buffer variable screen structure
168 * @info: frame buffer structure that represents a single frame buffer
171 tgafb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
173 struct tga_par
*par
= (struct tga_par
*)info
->par
;
175 if (par
->tga_type
== TGA_TYPE_8PLANE
) {
176 if (var
->bits_per_pixel
!= 8)
179 if (var
->bits_per_pixel
!= 32)
182 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 8;
183 if (var
->bits_per_pixel
== 32) {
184 var
->red
.offset
= 16;
185 var
->green
.offset
= 8;
186 var
->blue
.offset
= 0;
189 if (var
->xres_virtual
!= var
->xres
|| var
->yres_virtual
!= var
->yres
)
191 if (var
->xres
* var
->yres
* (var
->bits_per_pixel
>> 3) > info
->fix
.smem_len
)
195 if (1000000000 / var
->pixclock
> TGA_PLL_MAX_FREQ
)
197 if ((var
->vmode
& FB_VMODE_MASK
) != FB_VMODE_NONINTERLACED
)
200 /* Some of the acceleration routines assume the line width is
201 a multiple of 64 bytes. */
202 if (var
->xres
* (par
->tga_type
== TGA_TYPE_8PLANE
? 1 : 4) % 64)
209 * tgafb_set_par - Optional function. Alters the hardware state.
210 * @info: frame buffer structure that represents a single frame buffer
213 tgafb_set_par(struct fb_info
*info
)
215 static unsigned int const deep_presets
[4] = {
221 static unsigned int const rasterop_presets
[4] = {
227 static unsigned int const mode_presets
[4] = {
233 static unsigned int const base_addr_presets
[4] = {
240 struct tga_par
*par
= (struct tga_par
*) info
->par
;
241 int tga_bus_pci
= TGA_BUS_PCI(par
->dev
);
242 int tga_bus_tc
= TGA_BUS_TC(par
->dev
);
243 u32 htimings
, vtimings
, pll_freq
;
247 /* Encode video timings. */
248 htimings
= (((info
->var
.xres
/4) & TGA_HORIZ_ACT_LSB
)
249 | (((info
->var
.xres
/4) & 0x600 << 19) & TGA_HORIZ_ACT_MSB
));
250 vtimings
= (info
->var
.yres
& TGA_VERT_ACTIVE
);
251 htimings
|= ((info
->var
.right_margin
/4) << 9) & TGA_HORIZ_FP
;
252 vtimings
|= (info
->var
.lower_margin
<< 11) & TGA_VERT_FP
;
253 htimings
|= ((info
->var
.hsync_len
/4) << 14) & TGA_HORIZ_SYNC
;
254 vtimings
|= (info
->var
.vsync_len
<< 16) & TGA_VERT_SYNC
;
255 htimings
|= ((info
->var
.left_margin
/4) << 21) & TGA_HORIZ_BP
;
256 vtimings
|= (info
->var
.upper_margin
<< 22) & TGA_VERT_BP
;
258 if (info
->var
.sync
& FB_SYNC_HOR_HIGH_ACT
)
259 htimings
|= TGA_HORIZ_POLARITY
;
260 if (info
->var
.sync
& FB_SYNC_VERT_HIGH_ACT
)
261 vtimings
|= TGA_VERT_POLARITY
;
263 par
->htimings
= htimings
;
264 par
->vtimings
= vtimings
;
266 par
->sync_on_green
= !!(info
->var
.sync
& FB_SYNC_ON_GREEN
);
268 /* Store other useful values in par. */
269 par
->xres
= info
->var
.xres
;
270 par
->yres
= info
->var
.yres
;
271 par
->pll_freq
= pll_freq
= 1000000000 / info
->var
.pixclock
;
272 par
->bits_per_pixel
= info
->var
.bits_per_pixel
;
273 info
->fix
.line_length
= par
->xres
* (par
->bits_per_pixel
>> 3);
275 tga_type
= par
->tga_type
;
277 /* First, disable video. */
278 TGA_WRITE_REG(par
, TGA_VALID_VIDEO
| TGA_VALID_BLANK
, TGA_VALID_REG
);
280 /* Write the DEEP register. */
281 while (TGA_READ_REG(par
, TGA_CMD_STAT_REG
) & 1) /* wait for not busy */
284 TGA_WRITE_REG(par
, deep_presets
[tga_type
] |
285 (par
->sync_on_green
? 0x0 : 0x00010000),
287 while (TGA_READ_REG(par
, TGA_CMD_STAT_REG
) & 1) /* wait for not busy */
291 /* Write some more registers. */
292 TGA_WRITE_REG(par
, rasterop_presets
[tga_type
], TGA_RASTEROP_REG
);
293 TGA_WRITE_REG(par
, mode_presets
[tga_type
], TGA_MODE_REG
);
294 TGA_WRITE_REG(par
, base_addr_presets
[tga_type
], TGA_BASE_ADDR_REG
);
296 /* Calculate & write the PLL. */
297 tgafb_set_pll(par
, pll_freq
);
299 /* Write some more registers. */
300 TGA_WRITE_REG(par
, 0xffffffff, TGA_PLANEMASK_REG
);
301 TGA_WRITE_REG(par
, 0xffffffff, TGA_PIXELMASK_REG
);
303 /* Init video timing regs. */
304 TGA_WRITE_REG(par
, htimings
, TGA_HORIZ_REG
);
305 TGA_WRITE_REG(par
, vtimings
, TGA_VERT_REG
);
307 /* Initialise RAMDAC. */
308 if (tga_type
== TGA_TYPE_8PLANE
&& tga_bus_pci
) {
310 /* Init BT485 RAMDAC registers. */
311 BT485_WRITE(par
, 0xa2 | (par
->sync_on_green
? 0x8 : 0x0),
313 BT485_WRITE(par
, 0x01, BT485_ADDR_PAL_WRITE
);
314 BT485_WRITE(par
, 0x14, BT485_CMD_3
); /* cursor 64x64 */
315 BT485_WRITE(par
, 0x40, BT485_CMD_1
);
316 BT485_WRITE(par
, 0x20, BT485_CMD_2
); /* cursor off, for now */
317 BT485_WRITE(par
, 0xff, BT485_PIXEL_MASK
);
319 /* Fill palette registers. */
320 BT485_WRITE(par
, 0x00, BT485_ADDR_PAL_WRITE
);
321 TGA_WRITE_REG(par
, BT485_DATA_PAL
, TGA_RAMDAC_SETUP_REG
);
323 for (i
= 0; i
< 256 * 3; i
+= 4) {
324 TGA_WRITE_REG(par
, 0x55 | (BT485_DATA_PAL
<< 8),
326 TGA_WRITE_REG(par
, 0x00 | (BT485_DATA_PAL
<< 8),
328 TGA_WRITE_REG(par
, 0x00 | (BT485_DATA_PAL
<< 8),
330 TGA_WRITE_REG(par
, 0x00 | (BT485_DATA_PAL
<< 8),
334 } else if (tga_type
== TGA_TYPE_8PLANE
&& tga_bus_tc
) {
336 /* Init BT459 RAMDAC registers. */
337 BT459_WRITE(par
, BT459_REG_ACC
, BT459_CMD_REG_0
, 0x40);
338 BT459_WRITE(par
, BT459_REG_ACC
, BT459_CMD_REG_1
, 0x00);
339 BT459_WRITE(par
, BT459_REG_ACC
, BT459_CMD_REG_2
,
340 (par
->sync_on_green
? 0xc0 : 0x40));
342 BT459_WRITE(par
, BT459_REG_ACC
, BT459_CUR_CMD_REG
, 0x00);
344 /* Fill the palette. */
345 BT459_LOAD_ADDR(par
, 0x0000);
346 TGA_WRITE_REG(par
, BT459_PALETTE
<< 2, TGA_RAMDAC_SETUP_REG
);
348 for (i
= 0; i
< 256 * 3; i
+= 4) {
349 TGA_WRITE_REG(par
, 0x55, TGA_RAMDAC_REG
);
350 TGA_WRITE_REG(par
, 0x00, TGA_RAMDAC_REG
);
351 TGA_WRITE_REG(par
, 0x00, TGA_RAMDAC_REG
);
352 TGA_WRITE_REG(par
, 0x00, TGA_RAMDAC_REG
);
355 } else { /* 24-plane or 24plusZ */
357 /* Init BT463 RAMDAC registers. */
358 BT463_WRITE(par
, BT463_REG_ACC
, BT463_CMD_REG_0
, 0x40);
359 BT463_WRITE(par
, BT463_REG_ACC
, BT463_CMD_REG_1
, 0x08);
360 BT463_WRITE(par
, BT463_REG_ACC
, BT463_CMD_REG_2
,
361 (par
->sync_on_green
? 0xc0 : 0x40));
363 BT463_WRITE(par
, BT463_REG_ACC
, BT463_READ_MASK_0
, 0xff);
364 BT463_WRITE(par
, BT463_REG_ACC
, BT463_READ_MASK_1
, 0xff);
365 BT463_WRITE(par
, BT463_REG_ACC
, BT463_READ_MASK_2
, 0xff);
366 BT463_WRITE(par
, BT463_REG_ACC
, BT463_READ_MASK_3
, 0x0f);
368 BT463_WRITE(par
, BT463_REG_ACC
, BT463_BLINK_MASK_0
, 0x00);
369 BT463_WRITE(par
, BT463_REG_ACC
, BT463_BLINK_MASK_1
, 0x00);
370 BT463_WRITE(par
, BT463_REG_ACC
, BT463_BLINK_MASK_2
, 0x00);
371 BT463_WRITE(par
, BT463_REG_ACC
, BT463_BLINK_MASK_3
, 0x00);
373 /* Fill the palette. */
374 BT463_LOAD_ADDR(par
, 0x0000);
375 TGA_WRITE_REG(par
, BT463_PALETTE
<< 2, TGA_RAMDAC_SETUP_REG
);
377 #ifdef CONFIG_HW_CONSOLE
378 for (i
= 0; i
< 16; i
++) {
379 int j
= color_table
[i
];
381 TGA_WRITE_REG(par
, default_red
[j
], TGA_RAMDAC_REG
);
382 TGA_WRITE_REG(par
, default_grn
[j
], TGA_RAMDAC_REG
);
383 TGA_WRITE_REG(par
, default_blu
[j
], TGA_RAMDAC_REG
);
385 for (i
= 0; i
< 512 * 3; i
+= 4) {
387 for (i
= 0; i
< 528 * 3; i
+= 4) {
389 TGA_WRITE_REG(par
, 0x55, TGA_RAMDAC_REG
);
390 TGA_WRITE_REG(par
, 0x00, TGA_RAMDAC_REG
);
391 TGA_WRITE_REG(par
, 0x00, TGA_RAMDAC_REG
);
392 TGA_WRITE_REG(par
, 0x00, TGA_RAMDAC_REG
);
395 /* Fill window type table after start of vertical retrace. */
396 while (!(TGA_READ_REG(par
, TGA_INTR_STAT_REG
) & 0x01))
398 TGA_WRITE_REG(par
, 0x01, TGA_INTR_STAT_REG
);
400 while (!(TGA_READ_REG(par
, TGA_INTR_STAT_REG
) & 0x01))
402 TGA_WRITE_REG(par
, 0x01, TGA_INTR_STAT_REG
);
404 BT463_LOAD_ADDR(par
, BT463_WINDOW_TYPE_BASE
);
405 TGA_WRITE_REG(par
, BT463_REG_ACC
<< 2, TGA_RAMDAC_SETUP_REG
);
407 for (i
= 0; i
< 16; i
++) {
408 TGA_WRITE_REG(par
, 0x00, TGA_RAMDAC_REG
);
409 TGA_WRITE_REG(par
, 0x01, TGA_RAMDAC_REG
);
410 TGA_WRITE_REG(par
, 0x00, TGA_RAMDAC_REG
);
415 /* Finally, enable video scan (and pray for the monitor... :-) */
416 TGA_WRITE_REG(par
, TGA_VALID_VIDEO
, TGA_VALID_REG
);
421 #define DIFFCHECK(X) \
424 int delta = f - (TGA_PLL_BASE_FREQ * (X)) / (r << shift); \
427 if (delta < min_diff) \
428 min_diff = delta, vm = m, va = a, vr = r; \
433 tgafb_set_pll(struct tga_par
*par
, int f
)
435 int n
, shift
, base
, min_diff
, target
;
436 int r
,a
,m
,vm
= 34, va
= 1, vr
= 30;
438 for (r
= 0 ; r
< 12 ; r
++)
439 TGA_WRITE_REG(par
, !r
, TGA_CLOCK_REG
);
441 if (f
> TGA_PLL_MAX_FREQ
)
442 f
= TGA_PLL_MAX_FREQ
;
444 if (f
>= TGA_PLL_MAX_FREQ
/ 2)
446 else if (f
>= TGA_PLL_MAX_FREQ
/ 4)
451 TGA_WRITE_REG(par
, shift
& 1, TGA_CLOCK_REG
);
452 TGA_WRITE_REG(par
, shift
>> 1, TGA_CLOCK_REG
);
454 for (r
= 0 ; r
< 10 ; r
++)
455 TGA_WRITE_REG(par
, 0, TGA_CLOCK_REG
);
458 TGA_WRITE_REG(par
, 0, TGA_CLOCK_REG
);
459 TGA_WRITE_REG(par
, 0, TGA_CLOCK_REG
);
461 else if (f
<= 200000) {
462 TGA_WRITE_REG(par
, 1, TGA_CLOCK_REG
);
463 TGA_WRITE_REG(par
, 0, TGA_CLOCK_REG
);
466 TGA_WRITE_REG(par
, 0, TGA_CLOCK_REG
);
467 TGA_WRITE_REG(par
, 1, TGA_CLOCK_REG
);
470 TGA_WRITE_REG(par
, 1, TGA_CLOCK_REG
);
471 TGA_WRITE_REG(par
, 0, TGA_CLOCK_REG
);
472 TGA_WRITE_REG(par
, 0, TGA_CLOCK_REG
);
473 TGA_WRITE_REG(par
, 1, TGA_CLOCK_REG
);
474 TGA_WRITE_REG(par
, 0, TGA_CLOCK_REG
);
475 TGA_WRITE_REG(par
, 1, TGA_CLOCK_REG
);
477 target
= (f
<< shift
) / TGA_PLL_BASE_FREQ
;
478 min_diff
= TGA_PLL_MAX_FREQ
;
485 for (n
= base
< 7 ? 7 : base
; n
< base
+ target
&& n
< 449; n
++) {
486 m
= ((n
+ 3) / 7) - 1;
488 DIFFCHECK((m
+ 1) * 7);
490 DIFFCHECK((m
+ 1) * 7);
501 for (r
= 0; r
< 8; r
++)
502 TGA_WRITE_REG(par
, (vm
>> r
) & 1, TGA_CLOCK_REG
);
503 for (r
= 0; r
< 8 ; r
++)
504 TGA_WRITE_REG(par
, (va
>> r
) & 1, TGA_CLOCK_REG
);
505 for (r
= 0; r
< 7 ; r
++)
506 TGA_WRITE_REG(par
, (vr
>> r
) & 1, TGA_CLOCK_REG
);
507 TGA_WRITE_REG(par
, ((vr
>> 7) & 1)|2, TGA_CLOCK_REG
);
512 * tgafb_setcolreg - Optional function. Sets a color register.
513 * @regno: boolean, 0 copy local, 1 get_user() function
514 * @red: frame buffer colormap structure
515 * @green: The green value which can be up to 16 bits wide
516 * @blue: The blue value which can be up to 16 bits wide.
517 * @transp: If supported the alpha value which can be up to 16 bits wide.
518 * @info: frame buffer info structure
521 tgafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
, unsigned blue
,
522 unsigned transp
, struct fb_info
*info
)
524 struct tga_par
*par
= (struct tga_par
*) info
->par
;
525 int tga_bus_pci
= TGA_BUS_PCI(par
->dev
);
526 int tga_bus_tc
= TGA_BUS_TC(par
->dev
);
534 if (par
->tga_type
== TGA_TYPE_8PLANE
&& tga_bus_pci
) {
535 BT485_WRITE(par
, regno
, BT485_ADDR_PAL_WRITE
);
536 TGA_WRITE_REG(par
, BT485_DATA_PAL
, TGA_RAMDAC_SETUP_REG
);
537 TGA_WRITE_REG(par
, red
|(BT485_DATA_PAL
<<8),TGA_RAMDAC_REG
);
538 TGA_WRITE_REG(par
, green
|(BT485_DATA_PAL
<<8),TGA_RAMDAC_REG
);
539 TGA_WRITE_REG(par
, blue
|(BT485_DATA_PAL
<<8),TGA_RAMDAC_REG
);
540 } else if (par
->tga_type
== TGA_TYPE_8PLANE
&& tga_bus_tc
) {
541 BT459_LOAD_ADDR(par
, regno
);
542 TGA_WRITE_REG(par
, BT459_PALETTE
<< 2, TGA_RAMDAC_SETUP_REG
);
543 TGA_WRITE_REG(par
, red
, TGA_RAMDAC_REG
);
544 TGA_WRITE_REG(par
, green
, TGA_RAMDAC_REG
);
545 TGA_WRITE_REG(par
, blue
, TGA_RAMDAC_REG
);
548 u32 value
= (regno
<< 16) | (regno
<< 8) | regno
;
549 ((u32
*)info
->pseudo_palette
)[regno
] = value
;
551 BT463_LOAD_ADDR(par
, regno
);
552 TGA_WRITE_REG(par
, BT463_PALETTE
<< 2, TGA_RAMDAC_SETUP_REG
);
553 TGA_WRITE_REG(par
, red
, TGA_RAMDAC_REG
);
554 TGA_WRITE_REG(par
, green
, TGA_RAMDAC_REG
);
555 TGA_WRITE_REG(par
, blue
, TGA_RAMDAC_REG
);
563 * tgafb_blank - Optional function. Blanks the display.
564 * @blank_mode: the blank mode we want.
565 * @info: frame buffer structure that represents a single frame buffer
568 tgafb_blank(int blank
, struct fb_info
*info
)
570 struct tga_par
*par
= (struct tga_par
*) info
->par
;
571 u32 vhcr
, vvcr
, vvvr
;
574 local_irq_save(flags
);
576 vhcr
= TGA_READ_REG(par
, TGA_HORIZ_REG
);
577 vvcr
= TGA_READ_REG(par
, TGA_VERT_REG
);
578 vvvr
= TGA_READ_REG(par
, TGA_VALID_REG
);
579 vvvr
&= ~(TGA_VALID_VIDEO
| TGA_VALID_BLANK
);
582 case FB_BLANK_UNBLANK
: /* Unblanking */
583 if (par
->vesa_blanked
) {
584 TGA_WRITE_REG(par
, vhcr
& 0xbfffffff, TGA_HORIZ_REG
);
585 TGA_WRITE_REG(par
, vvcr
& 0xbfffffff, TGA_VERT_REG
);
586 par
->vesa_blanked
= 0;
588 TGA_WRITE_REG(par
, vvvr
| TGA_VALID_VIDEO
, TGA_VALID_REG
);
591 case FB_BLANK_NORMAL
: /* Normal blanking */
592 TGA_WRITE_REG(par
, vvvr
| TGA_VALID_VIDEO
| TGA_VALID_BLANK
,
596 case FB_BLANK_VSYNC_SUSPEND
: /* VESA blank (vsync off) */
597 TGA_WRITE_REG(par
, vvcr
| 0x40000000, TGA_VERT_REG
);
598 TGA_WRITE_REG(par
, vvvr
| TGA_VALID_BLANK
, TGA_VALID_REG
);
599 par
->vesa_blanked
= 1;
602 case FB_BLANK_HSYNC_SUSPEND
: /* VESA blank (hsync off) */
603 TGA_WRITE_REG(par
, vhcr
| 0x40000000, TGA_HORIZ_REG
);
604 TGA_WRITE_REG(par
, vvvr
| TGA_VALID_BLANK
, TGA_VALID_REG
);
605 par
->vesa_blanked
= 1;
608 case FB_BLANK_POWERDOWN
: /* Poweroff */
609 TGA_WRITE_REG(par
, vhcr
| 0x40000000, TGA_HORIZ_REG
);
610 TGA_WRITE_REG(par
, vvcr
| 0x40000000, TGA_VERT_REG
);
611 TGA_WRITE_REG(par
, vvvr
| TGA_VALID_BLANK
, TGA_VALID_REG
);
612 par
->vesa_blanked
= 1;
616 local_irq_restore(flags
);
626 tgafb_mono_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
628 struct tga_par
*par
= (struct tga_par
*) info
->par
;
629 u32 fgcolor
, bgcolor
, dx
, dy
, width
, height
, vxres
, vyres
, pixelmask
;
630 unsigned long rincr
, line_length
, shift
, pos
, is8bpp
;
632 const unsigned char *data
;
633 void __iomem
*regs_base
;
634 void __iomem
*fb_base
;
636 is8bpp
= info
->var
.bits_per_pixel
== 8;
640 width
= image
->width
;
641 height
= image
->height
;
642 vxres
= info
->var
.xres_virtual
;
643 vyres
= info
->var
.yres_virtual
;
644 line_length
= info
->fix
.line_length
;
645 rincr
= (width
+ 7) / 8;
647 /* A shift below cannot cope with. */
648 if (unlikely(width
== 0))
650 /* Crop the image to the screen. */
651 if (dx
> vxres
|| dy
> vyres
)
653 if (dx
+ width
> vxres
)
655 if (dy
+ height
> vyres
)
658 regs_base
= par
->tga_regs_base
;
659 fb_base
= par
->tga_fb_base
;
661 /* Expand the color values to fill 32-bits. */
662 /* ??? Would be nice to notice colour changes elsewhere, so
663 that we can do this only when necessary. */
664 fgcolor
= image
->fg_color
;
665 bgcolor
= image
->bg_color
;
667 fgcolor
|= fgcolor
<< 8;
668 fgcolor
|= fgcolor
<< 16;
669 bgcolor
|= bgcolor
<< 8;
670 bgcolor
|= bgcolor
<< 16;
673 fgcolor
= ((u32
*)info
->pseudo_palette
)[fgcolor
];
675 bgcolor
= ((u32
*)info
->pseudo_palette
)[bgcolor
];
677 __raw_writel(fgcolor
, regs_base
+ TGA_FOREGROUND_REG
);
678 __raw_writel(bgcolor
, regs_base
+ TGA_BACKGROUND_REG
);
680 /* Acquire proper alignment; set up the PIXELMASK register
681 so that we only write the proper character cell. */
682 pos
= dy
* line_length
;
689 shift
= (pos
& 7) >> 2;
693 data
= (const unsigned char *) image
->data
;
695 /* Enable opaque stipple mode. */
697 ? TGA_MODE_SBM_8BPP
| TGA_MODE_OPAQUE_STIPPLE
698 : TGA_MODE_SBM_24BPP
| TGA_MODE_OPAQUE_STIPPLE
),
699 regs_base
+ TGA_MODE_REG
);
701 if (width
+ shift
<= 32) {
702 unsigned long bwidth
;
704 /* Handle common case of imaging a single character, in
705 a font less than or 32 pixels wide. */
707 /* Avoid a shift by 32; width > 0 implied. */
708 pixelmask
= (2ul << (width
- 1)) - 1;
710 __raw_writel(pixelmask
, regs_base
+ TGA_PIXELMASK_REG
);
713 bwidth
= (width
+ 7) / 8;
715 for (i
= 0; i
< height
; ++i
) {
718 /* The image data is bit big endian; we need
720 for (j
= 0; j
< bwidth
; ++j
)
721 mask
|= bitrev8(data
[j
]) << (j
* 8);
723 __raw_writel(mask
<< shift
, fb_base
+ pos
);
729 __raw_writel(0xffffffff, regs_base
+ TGA_PIXELMASK_REG
);
730 } else if (shift
== 0) {
731 unsigned long pos0
= pos
;
732 const unsigned char *data0
= data
;
733 unsigned long bincr
= (is8bpp
? 8 : 8*4);
734 unsigned long bwidth
;
736 /* Handle another common case in which accel_putcs
737 generates a large bitmap, which happens to be aligned.
738 Allow the tail to be misaligned. This case is
739 interesting because we've not got to hold partial
740 bytes across the words being written. */
744 bwidth
= (width
/ 8) & -4;
745 for (i
= 0; i
< height
; ++i
) {
746 for (j
= 0; j
< bwidth
; j
+= 4) {
748 mask
|= bitrev8(data
[j
+0]) << (0 * 8);
749 mask
|= bitrev8(data
[j
+1]) << (1 * 8);
750 mask
|= bitrev8(data
[j
+2]) << (2 * 8);
751 mask
|= bitrev8(data
[j
+3]) << (3 * 8);
752 __raw_writel(mask
, fb_base
+ pos
+ j
*bincr
);
759 pixelmask
= (1ul << (width
& 31)) - 1;
761 __raw_writel(pixelmask
, regs_base
+ TGA_PIXELMASK_REG
);
764 pos
= pos0
+ bwidth
*bincr
;
765 data
= data0
+ bwidth
;
766 bwidth
= ((width
& 31) + 7) / 8;
768 for (i
= 0; i
< height
; ++i
) {
770 for (j
= 0; j
< bwidth
; ++j
)
771 mask
|= bitrev8(data
[j
]) << (j
* 8);
772 __raw_writel(mask
, fb_base
+ pos
);
777 __raw_writel(0xffffffff, regs_base
+ TGA_PIXELMASK_REG
);
780 unsigned long pos0
= pos
;
781 const unsigned char *data0
= data
;
782 unsigned long bincr
= (is8bpp
? 8 : 8*4);
783 unsigned long bwidth
;
785 /* Finally, handle the generic case of misaligned start.
786 Here we split the write into 16-bit spans. This allows
787 us to use only one pixel mask, instead of four as would
788 be required by writing 24-bit spans. */
790 pixelmask
= 0xffff << shift
;
791 __raw_writel(pixelmask
, regs_base
+ TGA_PIXELMASK_REG
);
794 bwidth
= (width
/ 8) & -2;
795 for (i
= 0; i
< height
; ++i
) {
796 for (j
= 0; j
< bwidth
; j
+= 2) {
798 mask
|= bitrev8(data
[j
+0]) << (0 * 8);
799 mask
|= bitrev8(data
[j
+1]) << (1 * 8);
801 __raw_writel(mask
, fb_base
+ pos
+ j
*bincr
);
808 pixelmask
= ((1ul << (width
& 15)) - 1) << shift
;
810 __raw_writel(pixelmask
, regs_base
+ TGA_PIXELMASK_REG
);
813 pos
= pos0
+ bwidth
*bincr
;
814 data
= data0
+ bwidth
;
815 bwidth
= (width
& 15) > 8;
817 for (i
= 0; i
< height
; ++i
) {
818 u32 mask
= bitrev8(data
[0]);
820 mask
|= bitrev8(data
[1]) << 8;
822 __raw_writel(mask
, fb_base
+ pos
);
828 __raw_writel(0xffffffff, regs_base
+ TGA_PIXELMASK_REG
);
831 /* Disable opaque stipple mode. */
833 ? TGA_MODE_SBM_8BPP
| TGA_MODE_SIMPLE
834 : TGA_MODE_SBM_24BPP
| TGA_MODE_SIMPLE
),
835 regs_base
+ TGA_MODE_REG
);
839 tgafb_clut_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
841 struct tga_par
*par
= (struct tga_par
*) info
->par
;
842 u32 color
, dx
, dy
, width
, height
, vxres
, vyres
;
843 u32
*palette
= ((u32
*)info
->pseudo_palette
);
844 unsigned long pos
, line_length
, i
, j
;
845 const unsigned char *data
;
846 void __iomem
*regs_base
, *fb_base
;
850 width
= image
->width
;
851 height
= image
->height
;
852 vxres
= info
->var
.xres_virtual
;
853 vyres
= info
->var
.yres_virtual
;
854 line_length
= info
->fix
.line_length
;
856 /* Crop the image to the screen. */
857 if (dx
> vxres
|| dy
> vyres
)
859 if (dx
+ width
> vxres
)
861 if (dy
+ height
> vyres
)
864 regs_base
= par
->tga_regs_base
;
865 fb_base
= par
->tga_fb_base
;
867 pos
= dy
* line_length
+ (dx
* 4);
870 /* Now copy the image, color_expanding via the palette. */
871 for (i
= 0; i
< height
; i
++) {
872 for (j
= 0; j
< width
; j
++) {
873 color
= palette
[*data
++];
874 __raw_writel(color
, fb_base
+ pos
+ j
*4);
881 * tgafb_imageblit - REQUIRED function. Can use generic routines if
882 * non acclerated hardware and packed pixel based.
883 * Copies a image from system memory to the screen.
885 * @info: frame buffer structure that represents a single frame buffer
886 * @image: structure defining the image.
889 tgafb_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
891 unsigned int is8bpp
= info
->var
.bits_per_pixel
== 8;
893 /* If a mono image, regardless of FB depth, go do it. */
894 if (image
->depth
== 1) {
895 tgafb_mono_imageblit(info
, image
);
899 /* For copies that aren't pixel expansion, there's little we
900 can do better than the generic code. */
901 /* ??? There is a DMA write mode; I wonder if that could be
902 made to pull the data from the image buffer... */
903 if (image
->depth
== info
->var
.bits_per_pixel
) {
904 cfb_imageblit(info
, image
);
908 /* If 24-plane FB and the image is 8-plane with CLUT, we can do it. */
909 if (!is8bpp
&& image
->depth
== 8) {
910 tgafb_clut_imageblit(info
, image
);
914 /* Silently return... */
918 * tgafb_fillrect - REQUIRED function. Can use generic routines if
919 * non acclerated hardware and packed pixel based.
920 * Draws a rectangle on the screen.
922 * @info: frame buffer structure that represents a single frame buffer
923 * @rect: structure defining the rectagle and operation.
926 tgafb_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
928 struct tga_par
*par
= (struct tga_par
*) info
->par
;
929 int is8bpp
= info
->var
.bits_per_pixel
== 8;
930 u32 dx
, dy
, width
, height
, vxres
, vyres
, color
;
931 unsigned long pos
, align
, line_length
, i
, j
;
932 void __iomem
*regs_base
;
933 void __iomem
*fb_base
;
938 height
= rect
->height
;
939 vxres
= info
->var
.xres_virtual
;
940 vyres
= info
->var
.yres_virtual
;
941 line_length
= info
->fix
.line_length
;
942 regs_base
= par
->tga_regs_base
;
943 fb_base
= par
->tga_fb_base
;
945 /* Crop the rectangle to the screen. */
946 if (dx
> vxres
|| dy
> vyres
|| !width
|| !height
)
948 if (dx
+ width
> vxres
)
950 if (dy
+ height
> vyres
)
953 pos
= dy
* line_length
+ dx
* (is8bpp
? 1 : 4);
955 /* ??? We could implement ROP_XOR with opaque fill mode
956 and a RasterOp setting of GXxor, but as far as I can
957 tell, this mode is not actually used in the kernel.
958 Thus I am ignoring it for now. */
959 if (rect
->rop
!= ROP_COPY
) {
960 cfb_fillrect(info
, rect
);
964 /* Expand the color value to fill 8 pixels. */
968 color
|= color
<< 16;
969 __raw_writel(color
, regs_base
+ TGA_BLOCK_COLOR0_REG
);
970 __raw_writel(color
, regs_base
+ TGA_BLOCK_COLOR1_REG
);
973 color
= ((u32
*)info
->pseudo_palette
)[color
];
974 __raw_writel(color
, regs_base
+ TGA_BLOCK_COLOR0_REG
);
975 __raw_writel(color
, regs_base
+ TGA_BLOCK_COLOR1_REG
);
976 __raw_writel(color
, regs_base
+ TGA_BLOCK_COLOR2_REG
);
977 __raw_writel(color
, regs_base
+ TGA_BLOCK_COLOR3_REG
);
978 __raw_writel(color
, regs_base
+ TGA_BLOCK_COLOR4_REG
);
979 __raw_writel(color
, regs_base
+ TGA_BLOCK_COLOR5_REG
);
980 __raw_writel(color
, regs_base
+ TGA_BLOCK_COLOR6_REG
);
981 __raw_writel(color
, regs_base
+ TGA_BLOCK_COLOR7_REG
);
984 /* The DATA register holds the fill mask for block fill mode.
985 Since we're not stippling, this is all ones. */
986 __raw_writel(0xffffffff, regs_base
+ TGA_DATA_REG
);
988 /* Enable block fill mode. */
990 ? TGA_MODE_SBM_8BPP
| TGA_MODE_BLOCK_FILL
991 : TGA_MODE_SBM_24BPP
| TGA_MODE_BLOCK_FILL
),
992 regs_base
+ TGA_MODE_REG
);
995 /* We can fill 2k pixels per operation. Notice blocks that fit
996 the width of the screen so that we can take advantage of this
997 and fill more than one line per write. */
998 if (width
== line_length
)
999 width
*= height
, height
= 1;
1001 /* The write into the frame buffer must be aligned to 4 bytes,
1002 but we are allowed to encode the offset within the word in
1003 the data word written. */
1004 align
= (pos
& 3) << 16;
1007 if (width
<= 2048) {
1010 data
= (width
- 1) | align
;
1012 for (i
= 0; i
< height
; ++i
) {
1013 __raw_writel(data
, fb_base
+ pos
);
1017 unsigned long Bpp
= (is8bpp
? 1 : 4);
1018 unsigned long nwidth
= width
& -2048;
1021 fdata
= (2048 - 1) | align
;
1022 ldata
= ((width
& 2047) - 1) | align
;
1024 for (i
= 0; i
< height
; ++i
) {
1025 for (j
= 0; j
< nwidth
; j
+= 2048)
1026 __raw_writel(fdata
, fb_base
+ pos
+ j
*Bpp
);
1028 __raw_writel(ldata
, fb_base
+ pos
+ j
*Bpp
);
1034 /* Disable block fill mode. */
1035 __raw_writel((is8bpp
1036 ? TGA_MODE_SBM_8BPP
| TGA_MODE_SIMPLE
1037 : TGA_MODE_SBM_24BPP
| TGA_MODE_SIMPLE
),
1038 regs_base
+ TGA_MODE_REG
);
1042 * tgafb_copyarea - REQUIRED function. Can use generic routines if
1043 * non acclerated hardware and packed pixel based.
1044 * Copies on area of the screen to another area.
1046 * @info: frame buffer structure that represents a single frame buffer
1047 * @area: structure defining the source and destination.
1050 /* Handle the special case of copying entire lines, e.g. during scrolling.
1051 We can avoid a lot of needless computation in this case. In the 8bpp
1052 case we need to use the COPY64 registers instead of mask writes into
1053 the frame buffer to achieve maximum performance. */
1056 copyarea_line_8bpp(struct fb_info
*info
, u32 dy
, u32 sy
,
1057 u32 height
, u32 width
)
1059 struct tga_par
*par
= (struct tga_par
*) info
->par
;
1060 void __iomem
*tga_regs
= par
->tga_regs_base
;
1061 unsigned long dpos
, spos
, i
, n64
;
1063 /* Set up the MODE and PIXELSHIFT registers. */
1064 __raw_writel(TGA_MODE_SBM_8BPP
| TGA_MODE_COPY
, tga_regs
+TGA_MODE_REG
);
1065 __raw_writel(0, tga_regs
+TGA_PIXELSHIFT_REG
);
1068 n64
= (height
* width
) / 64;
1071 spos
= (sy
+ height
) * width
;
1072 dpos
= (dy
+ height
) * width
;
1074 for (i
= 0; i
< n64
; ++i
) {
1077 __raw_writel(spos
, tga_regs
+TGA_COPY64_SRC
);
1079 __raw_writel(dpos
, tga_regs
+TGA_COPY64_DST
);
1086 for (i
= 0; i
< n64
; ++i
) {
1087 __raw_writel(spos
, tga_regs
+TGA_COPY64_SRC
);
1089 __raw_writel(dpos
, tga_regs
+TGA_COPY64_DST
);
1096 /* Reset the MODE register to normal. */
1097 __raw_writel(TGA_MODE_SBM_8BPP
|TGA_MODE_SIMPLE
, tga_regs
+TGA_MODE_REG
);
1101 copyarea_line_32bpp(struct fb_info
*info
, u32 dy
, u32 sy
,
1102 u32 height
, u32 width
)
1104 struct tga_par
*par
= (struct tga_par
*) info
->par
;
1105 void __iomem
*tga_regs
= par
->tga_regs_base
;
1106 void __iomem
*tga_fb
= par
->tga_fb_base
;
1109 unsigned long i
, n16
;
1111 /* Set up the MODE and PIXELSHIFT registers. */
1112 __raw_writel(TGA_MODE_SBM_24BPP
| TGA_MODE_COPY
, tga_regs
+TGA_MODE_REG
);
1113 __raw_writel(0, tga_regs
+TGA_PIXELSHIFT_REG
);
1116 n16
= (height
* width
) / 16;
1119 src
= tga_fb
+ (sy
+ height
) * width
* 4;
1120 dst
= tga_fb
+ (dy
+ height
) * width
* 4;
1122 for (i
= 0; i
< n16
; ++i
) {
1125 __raw_writel(0xffff, src
);
1127 __raw_writel(0xffff, dst
);
1131 src
= tga_fb
+ sy
* width
* 4;
1132 dst
= tga_fb
+ dy
* width
* 4;
1134 for (i
= 0; i
< n16
; ++i
) {
1135 __raw_writel(0xffff, src
);
1137 __raw_writel(0xffff, dst
);
1144 /* Reset the MODE register to normal. */
1145 __raw_writel(TGA_MODE_SBM_24BPP
|TGA_MODE_SIMPLE
, tga_regs
+TGA_MODE_REG
);
1148 /* The (almost) general case of backward copy in 8bpp mode. */
1150 copyarea_8bpp(struct fb_info
*info
, u32 dx
, u32 dy
, u32 sx
, u32 sy
,
1151 u32 height
, u32 width
, u32 line_length
,
1152 const struct fb_copyarea
*area
)
1154 struct tga_par
*par
= (struct tga_par
*) info
->par
;
1156 int depos
, sepos
, backward
, last_step
, step
;
1159 void __iomem
*tga_regs
;
1160 void __iomem
*tga_fb
;
1162 /* Do acceleration only if we are aligned on 8 pixels */
1163 if ((dx
| sx
| width
) & 7) {
1164 cfb_copyarea(info
, area
);
1168 yincr
= line_length
;
1174 backward
= dy
== sy
&& dx
> sx
&& dx
< sx
+ width
;
1176 /* Compute the offsets and alignments in the frame buffer.
1177 More than anything else, these control how we do copies. */
1178 depos
= dy
* line_length
+ dx
;
1179 sepos
= sy
* line_length
+ sx
;
1181 depos
+= width
, sepos
+= width
;
1183 /* Next copy full words at a time. */
1185 last_step
= width
% 32;
1187 /* Finally copy the unaligned head of the span. */
1188 mask_last
= (1ul << last_step
) - 1;
1195 last_step
= -last_step
;
1200 tga_regs
= par
->tga_regs_base
;
1201 tga_fb
= par
->tga_fb_base
;
1203 /* Set up the MODE and PIXELSHIFT registers. */
1204 __raw_writel(TGA_MODE_SBM_8BPP
|TGA_MODE_COPY
, tga_regs
+TGA_MODE_REG
);
1205 __raw_writel(0, tga_regs
+TGA_PIXELSHIFT_REG
);
1208 for (i
= 0; i
< height
; ++i
) {
1213 sfb
= tga_fb
+ sepos
;
1214 dfb
= tga_fb
+ depos
;
1216 for (j
= 0; j
< n32
; j
++) {
1217 if (j
< 2 && j
+ 1 < n32
&& !backward
&&
1218 !(((unsigned long)sfb
| (unsigned long)dfb
) & 63)) {
1220 __raw_writel(sfb
- tga_fb
, tga_regs
+TGA_COPY64_SRC
);
1222 __raw_writel(dfb
- tga_fb
, tga_regs
+TGA_COPY64_DST
);
1227 } while (j
+ 1 < n32
);
1231 __raw_writel(0xffffffff, sfb
);
1233 __raw_writel(0xffffffff, dfb
);
1240 sfb
+= last_step
- step
;
1241 dfb
+= last_step
- step
;
1242 __raw_writel(mask_last
, sfb
);
1244 __raw_writel(mask_last
, dfb
);
1252 /* Reset the MODE register to normal. */
1253 __raw_writel(TGA_MODE_SBM_8BPP
|TGA_MODE_SIMPLE
, tga_regs
+TGA_MODE_REG
);
1257 tgafb_copyarea(struct fb_info
*info
, const struct fb_copyarea
*area
)
1259 unsigned long dx
, dy
, width
, height
, sx
, sy
, vxres
, vyres
;
1260 unsigned long line_length
, bpp
;
1264 width
= area
->width
;
1265 height
= area
->height
;
1268 vxres
= info
->var
.xres_virtual
;
1269 vyres
= info
->var
.yres_virtual
;
1270 line_length
= info
->fix
.line_length
;
1272 /* The top left corners must be in the virtual screen. */
1273 if (dx
> vxres
|| sx
> vxres
|| dy
> vyres
|| sy
> vyres
)
1276 /* Clip the destination. */
1277 if (dx
+ width
> vxres
)
1279 if (dy
+ height
> vyres
)
1280 height
= vyres
- dy
;
1282 /* The source must be completely inside the virtual screen. */
1283 if (sx
+ width
> vxres
|| sy
+ height
> vyres
)
1286 bpp
= info
->var
.bits_per_pixel
;
1288 /* Detect copies of the entire line. */
1289 if (width
* (bpp
>> 3) == line_length
) {
1291 copyarea_line_8bpp(info
, dy
, sy
, height
, width
);
1293 copyarea_line_32bpp(info
, dy
, sy
, height
, width
);
1296 /* ??? The documentation is unclear to me exactly how the pixelshift
1297 register works in 32bpp mode. Since I don't have hardware to test,
1298 give up for now and fall back on the generic routines. */
1300 cfb_copyarea(info
, area
);
1303 copyarea_8bpp(info
, dx
, dy
, sx
, sy
, height
,
1304 width
, line_length
, area
);
1313 tgafb_init_fix(struct fb_info
*info
)
1315 struct tga_par
*par
= (struct tga_par
*)info
->par
;
1316 int tga_bus_pci
= TGA_BUS_PCI(par
->dev
);
1317 int tga_bus_tc
= TGA_BUS_TC(par
->dev
);
1318 u8 tga_type
= par
->tga_type
;
1319 const char *tga_type_name
= NULL
;
1320 unsigned memory_size
;
1323 case TGA_TYPE_8PLANE
:
1325 tga_type_name
= "Digital ZLXp-E1";
1327 tga_type_name
= "Digital ZLX-E1";
1328 memory_size
= 2097152;
1330 case TGA_TYPE_24PLANE
:
1332 tga_type_name
= "Digital ZLXp-E2";
1334 tga_type_name
= "Digital ZLX-E2";
1335 memory_size
= 8388608;
1337 case TGA_TYPE_24PLUSZ
:
1339 tga_type_name
= "Digital ZLXp-E3";
1341 tga_type_name
= "Digital ZLX-E3";
1342 memory_size
= 16777216;
1345 tga_type_name
= "Unknown";
1346 memory_size
= 16777216;
1350 strlcpy(info
->fix
.id
, tga_type_name
, sizeof(info
->fix
.id
));
1352 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1353 info
->fix
.type_aux
= 0;
1354 info
->fix
.visual
= (tga_type
== TGA_TYPE_8PLANE
1355 ? FB_VISUAL_PSEUDOCOLOR
1356 : FB_VISUAL_DIRECTCOLOR
);
1358 info
->fix
.smem_start
= (size_t) par
->tga_fb_base
;
1359 info
->fix
.smem_len
= memory_size
;
1360 info
->fix
.mmio_start
= (size_t) par
->tga_regs_base
;
1361 info
->fix
.mmio_len
= 512;
1363 info
->fix
.xpanstep
= 0;
1364 info
->fix
.ypanstep
= 0;
1365 info
->fix
.ywrapstep
= 0;
1367 info
->fix
.accel
= FB_ACCEL_DEC_TGA
;
1370 * These are needed by fb_set_logo_truepalette(), so we
1371 * set them here for 24-plane cards.
1373 if (tga_type
!= TGA_TYPE_8PLANE
) {
1374 info
->var
.red
.length
= 8;
1375 info
->var
.green
.length
= 8;
1376 info
->var
.blue
.length
= 8;
1377 info
->var
.red
.offset
= 16;
1378 info
->var
.green
.offset
= 8;
1379 info
->var
.blue
.offset
= 0;
1383 static int tgafb_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
1385 /* We just use this to catch switches out of graphics mode. */
1386 tgafb_set_par(info
); /* A bit of overkill for BASE_ADDR reset. */
1390 static int tgafb_register(struct device
*dev
)
1392 static const struct fb_videomode modedb_tc
= {
1393 /* 1280x1024 @ 72 Hz, 76.8 kHz hsync */
1394 "1280x1024@72", 0, 1280, 1024, 7645, 224, 28, 33, 3, 160, 3,
1395 FB_SYNC_ON_GREEN
, FB_VMODE_NONINTERLACED
1398 static unsigned int const fb_offset_presets
[4] = {
1399 TGA_8PLANE_FB_OFFSET
,
1400 TGA_24PLANE_FB_OFFSET
,
1402 TGA_24PLUSZ_FB_OFFSET
1405 const struct fb_videomode
*modedb_tga
= NULL
;
1406 resource_size_t bar0_start
= 0, bar0_len
= 0;
1407 const char *mode_option_tga
= NULL
;
1408 int tga_bus_pci
= TGA_BUS_PCI(dev
);
1409 int tga_bus_tc
= TGA_BUS_TC(dev
);
1410 unsigned int modedbsize_tga
= 0;
1411 void __iomem
*mem_base
;
1412 struct fb_info
*info
;
1413 struct tga_par
*par
;
1417 /* Enable device in PCI config. */
1418 if (tga_bus_pci
&& pci_enable_device(to_pci_dev(dev
))) {
1419 printk(KERN_ERR
"tgafb: Cannot enable PCI device\n");
1423 /* Allocate the fb and par structures. */
1424 info
= framebuffer_alloc(sizeof(struct tga_par
), dev
);
1426 printk(KERN_ERR
"tgafb: Cannot allocate memory\n");
1431 dev_set_drvdata(dev
, info
);
1433 /* Request the mem regions. */
1436 bar0_start
= pci_resource_start(to_pci_dev(dev
), 0);
1437 bar0_len
= pci_resource_len(to_pci_dev(dev
), 0);
1440 bar0_start
= to_tc_dev(dev
)->resource
.start
;
1441 bar0_len
= to_tc_dev(dev
)->resource
.end
- bar0_start
+ 1;
1443 if (!request_mem_region (bar0_start
, bar0_len
, "tgafb")) {
1444 printk(KERN_ERR
"tgafb: cannot reserve FB region\n");
1448 /* Map the framebuffer. */
1449 mem_base
= ioremap_nocache(bar0_start
, bar0_len
);
1451 printk(KERN_ERR
"tgafb: Cannot map MMIO\n");
1455 /* Grab info about the card. */
1456 tga_type
= (readl(mem_base
) >> 12) & 0x0f;
1458 par
->tga_mem_base
= mem_base
;
1459 par
->tga_fb_base
= mem_base
+ fb_offset_presets
[tga_type
];
1460 par
->tga_regs_base
= mem_base
+ TGA_REGS_OFFSET
;
1461 par
->tga_type
= tga_type
;
1463 par
->tga_chip_rev
= (to_pci_dev(dev
))->revision
;
1465 par
->tga_chip_rev
= TGA_READ_REG(par
, TGA_START_REG
) & 0xff;
1467 /* Setup framebuffer. */
1468 info
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_COPYAREA
|
1469 FBINFO_HWACCEL_IMAGEBLIT
| FBINFO_HWACCEL_FILLRECT
;
1470 info
->fbops
= &tgafb_ops
;
1471 info
->screen_base
= par
->tga_fb_base
;
1472 info
->pseudo_palette
= par
->palette
;
1474 /* This should give a reasonable default video mode. */
1476 mode_option_tga
= mode_option_pci
;
1479 mode_option_tga
= mode_option_tc
;
1480 modedb_tga
= &modedb_tc
;
1484 tgafb_init_fix(info
);
1486 ret
= fb_find_mode(&info
->var
, info
,
1487 mode_option
? mode_option
: mode_option_tga
,
1488 modedb_tga
, modedbsize_tga
, NULL
,
1489 tga_type
== TGA_TYPE_8PLANE
? 8 : 32);
1490 if (ret
== 0 || ret
== 4) {
1491 printk(KERN_ERR
"tgafb: Could not find valid video mode\n");
1496 if (fb_alloc_cmap(&info
->cmap
, 256, 0)) {
1497 printk(KERN_ERR
"tgafb: Could not allocate color map\n");
1502 tgafb_set_par(info
);
1504 if (register_framebuffer(info
) < 0) {
1505 printk(KERN_ERR
"tgafb: Could not register framebuffer\n");
1511 pr_info("tgafb: DC21030 [TGA] detected, rev=0x%02x\n",
1513 pr_info("tgafb: at PCI bus %d, device %d, function %d\n",
1514 to_pci_dev(dev
)->bus
->number
,
1515 PCI_SLOT(to_pci_dev(dev
)->devfn
),
1516 PCI_FUNC(to_pci_dev(dev
)->devfn
));
1519 pr_info("tgafb: SFB+ detected, rev=0x%02x\n",
1521 pr_info("fb%d: %s frame buffer device at 0x%lx\n",
1522 info
->node
, info
->fix
.id
, (long)bar0_start
);
1527 fb_dealloc_cmap(&info
->cmap
);
1531 release_mem_region(bar0_start
, bar0_len
);
1533 framebuffer_release(info
);
1537 static void tgafb_unregister(struct device
*dev
)
1539 resource_size_t bar0_start
= 0, bar0_len
= 0;
1540 int tga_bus_pci
= TGA_BUS_PCI(dev
);
1541 int tga_bus_tc
= TGA_BUS_TC(dev
);
1542 struct fb_info
*info
= NULL
;
1543 struct tga_par
*par
;
1545 info
= dev_get_drvdata(dev
);
1550 unregister_framebuffer(info
);
1551 fb_dealloc_cmap(&info
->cmap
);
1552 iounmap(par
->tga_mem_base
);
1554 bar0_start
= pci_resource_start(to_pci_dev(dev
), 0);
1555 bar0_len
= pci_resource_len(to_pci_dev(dev
), 0);
1558 bar0_start
= to_tc_dev(dev
)->resource
.start
;
1559 bar0_len
= to_tc_dev(dev
)->resource
.end
- bar0_start
+ 1;
1561 release_mem_region(bar0_start
, bar0_len
);
1562 framebuffer_release(info
);
1565 static void tgafb_exit(void)
1567 tc_unregister_driver(&tgafb_tc_driver
);
1568 pci_unregister_driver(&tgafb_pci_driver
);
1572 static int tgafb_setup(char *arg
)
1577 while ((this_opt
= strsep(&arg
, ","))) {
1580 if (!strncmp(this_opt
, "mode:", 5))
1581 mode_option
= this_opt
+5;
1584 "tgafb: unknown parameter %s\n",
1591 #endif /* !MODULE */
1593 static int tgafb_init(void)
1597 char *option
= NULL
;
1599 if (fb_get_options("tgafb", &option
))
1601 tgafb_setup(option
);
1603 status
= pci_register_driver(&tgafb_pci_driver
);
1605 status
= tc_register_driver(&tgafb_tc_driver
);
1613 module_init(tgafb_init
);
1614 module_exit(tgafb_exit
);
1616 MODULE_DESCRIPTION("Framebuffer driver for TGA/SFB+ chipset");
1617 MODULE_LICENSE("GPL");