2 * Permedia2 framebuffer driver.
5 * Copyright (c) 2003 Jim Hague (jim.hague@acm.org)
8 * Copyright (c) 1998-2000 Ilario Nardinocchi (nardinoc@CS.UniBO.IT)
9 * Copyright (c) 1999 Jakub Jelinek (jakub@redhat.com)
11 * and additional input from James Simmon's port of Hannu Mallat's tdfx
14 * I have a Creative Graphics Blaster Exxtreme card - pm2fb on x86. I
15 * have no access to other pm2fb implementations. Sparc (and thus
16 * hopefully other big-endian) devices now work, thanks to a lot of
17 * testing work by Ron Murray. I have no access to CVision hardware,
18 * and therefore for now I am omitting the CVision code.
20 * Multiple boards support has been on the TODO list for ages.
21 * Don't expect this to change.
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
30 #include <linux/module.h>
31 #include <linux/moduleparam.h>
32 #include <linux/kernel.h>
33 #include <linux/errno.h>
34 #include <linux/string.h>
36 #include <linux/slab.h>
37 #include <linux/delay.h>
39 #include <linux/init.h>
40 #include <linux/pci.h>
45 #include <video/permedia2.h>
46 #include <video/cvisionppc.h>
48 #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
49 #error "The endianness of the target host has not been defined."
52 #if !defined(CONFIG_PCI)
53 #error "Only generic PCI cards supported."
56 #undef PM2FB_MASTER_DEBUG
57 #ifdef PM2FB_MASTER_DEBUG
58 #define DPRINTK(a, b...) \
59 printk(KERN_DEBUG "pm2fb: %s: " a, __FUNCTION__ , ## b)
61 #define DPRINTK(a, b...)
64 #define PM2_PIXMAP_SIZE (1600 * 4)
70 static char *mode __devinitdata;
73 * The XFree GLINT driver will (I think to implement hardware cursor
74 * support on TVP4010 and similar where there is no RAMDAC - see
75 * comment in set_video) always request +ve sync regardless of what
76 * the mode requires. This screws me because I have a Sun
77 * fixed-frequency monitor which absolutely has to have -ve sync. So
78 * these flags allow the user to specify that requests for +ve sync
79 * should be silently turned in -ve sync.
83 static int noaccel __devinitdata;
86 static int nomtrr __devinitdata;
90 * The hardware state of the graphics card that isn't part of the
95 pm2type_t type; /* Board type */
96 unsigned char __iomem *v_regs;/* virtual address of p_regs */
97 u32 memclock; /* memclock */
98 u32 video; /* video flags before blanking */
99 u32 mem_config; /* MemConfig reg at probe */
100 u32 mem_control; /* MemControl reg at probe */
101 u32 boot_address; /* BootAddress reg at probe */
107 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
108 * if we don't use modedb.
110 static struct fb_fix_screeninfo pm2fb_fix __devinitdata = {
112 .type = FB_TYPE_PACKED_PIXELS,
113 .visual = FB_VISUAL_PSEUDOCOLOR,
117 .accel = FB_ACCEL_3DLABS_PERMEDIA2,
121 * Default video mode. In case the modedb doesn't work.
123 static struct fb_var_screeninfo pm2fb_var __devinitdata = {
124 /* "640x480, 8 bpp @ 60 Hz */
133 .activate = FB_ACTIVATE_NOW,
144 .vmode = FB_VMODE_NONINTERLACED
151 static inline u32 pm2_RD(struct pm2fb_par *p, s32 off)
153 return fb_readl(p->v_regs + off);
156 static inline void pm2_WR(struct pm2fb_par *p, s32 off, u32 v)
158 fb_writel(v, p->v_regs + off);
161 static inline u32 pm2_RDAC_RD(struct pm2fb_par *p, s32 idx)
163 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx);
165 return pm2_RD(p, PM2R_RD_INDEXED_DATA);
168 static inline u32 pm2v_RDAC_RD(struct pm2fb_par *p, s32 idx)
170 pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
172 return pm2_RD(p, PM2VR_RD_INDEXED_DATA);
175 static inline void pm2_RDAC_WR(struct pm2fb_par *p, s32 idx, u32 v)
177 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx);
179 pm2_WR(p, PM2R_RD_INDEXED_DATA, v);
183 static inline void pm2v_RDAC_WR(struct pm2fb_par *p, s32 idx, u32 v)
185 pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
187 pm2_WR(p, PM2VR_RD_INDEXED_DATA, v);
191 #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
192 #define WAIT_FIFO(p, a)
194 static inline void WAIT_FIFO(struct pm2fb_par *p, u32 a)
196 while (pm2_RD(p, PM2R_IN_FIFO_SPACE) < a);
202 * partial products for the supported horizontal resolutions.
204 #define PACKPP(p0, p1, p2) (((p2) << 6) | ((p1) << 3) | (p0))
205 static const struct {
209 { 32, PACKPP(1, 0, 0) }, { 64, PACKPP(1, 1, 0) },
210 { 96, PACKPP(1, 1, 1) }, { 128, PACKPP(2, 1, 1) },
211 { 160, PACKPP(2, 2, 1) }, { 192, PACKPP(2, 2, 2) },
212 { 224, PACKPP(3, 2, 1) }, { 256, PACKPP(3, 2, 2) },
213 { 288, PACKPP(3, 3, 1) }, { 320, PACKPP(3, 3, 2) },
214 { 384, PACKPP(3, 3, 3) }, { 416, PACKPP(4, 3, 1) },
215 { 448, PACKPP(4, 3, 2) }, { 512, PACKPP(4, 3, 3) },
216 { 544, PACKPP(4, 4, 1) }, { 576, PACKPP(4, 4, 2) },
217 { 640, PACKPP(4, 4, 3) }, { 768, PACKPP(4, 4, 4) },
218 { 800, PACKPP(5, 4, 1) }, { 832, PACKPP(5, 4, 2) },
219 { 896, PACKPP(5, 4, 3) }, { 1024, PACKPP(5, 4, 4) },
220 { 1056, PACKPP(5, 5, 1) }, { 1088, PACKPP(5, 5, 2) },
221 { 1152, PACKPP(5, 5, 3) }, { 1280, PACKPP(5, 5, 4) },
222 { 1536, PACKPP(5, 5, 5) }, { 1568, PACKPP(6, 5, 1) },
223 { 1600, PACKPP(6, 5, 2) }, { 1664, PACKPP(6, 5, 3) },
224 { 1792, PACKPP(6, 5, 4) }, { 2048, PACKPP(6, 5, 5) },
227 static u32 partprod(u32 xres)
231 for (i = 0; pp_table[i].width && pp_table[i].width != xres; i++)
233 if (pp_table[i].width == 0)
234 DPRINTK("invalid width %u\n", xres);
235 return pp_table[i].pp;
238 static u32 to3264(u32 timing, int bpp, int is64)
255 static void pm2_mnp(u32 clk, unsigned char *mm, unsigned char *nn,
266 for (n = 2; n < 15; n++) {
267 for (m = 2; m; m++) {
268 f = PM2_REFERENCE_CLOCK * m / n;
269 if (f >= 150000 && f <= 300000) {
270 for (p = 0; p < 5; p++, f >>= 1) {
271 curr = (clk > f) ? clk - f : f - clk;
284 static void pm2v_mnp(u32 clk, unsigned char *mm, unsigned char *nn,
294 for (m = 1; m < 128; m++) {
295 for (n = 2 * m + 1; n; n++) {
296 for (p = 0; p < 2; p++) {
297 f = (PM2_REFERENCE_CLOCK >> (p + 1)) * n / m;
298 if (clk > f - delta && clk < f + delta) {
299 delta = (clk > f) ? clk - f : f - clk;
309 static void clear_palette(struct pm2fb_par *p)
314 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, 0);
318 pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
319 pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
320 pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
324 static void reset_card(struct pm2fb_par *p)
326 if (p->type == PM2_TYPE_PERMEDIA2V)
327 pm2_WR(p, PM2VR_RD_INDEX_HIGH, 0);
328 pm2_WR(p, PM2R_RESET_STATUS, 0);
330 while (pm2_RD(p, PM2R_RESET_STATUS) & PM2F_BEING_RESET)
333 #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
334 DPRINTK("FIFO disconnect enabled\n");
335 pm2_WR(p, PM2R_FIFO_DISCON, 1);
339 /* Restore stashed memory config information from probe */
341 pm2_WR(p, PM2R_MEM_CONTROL, p->mem_control);
342 pm2_WR(p, PM2R_BOOT_ADDRESS, p->boot_address);
344 pm2_WR(p, PM2R_MEM_CONFIG, p->mem_config);
347 static void reset_config(struct pm2fb_par *p)
350 pm2_WR(p, PM2R_CHIP_CONFIG, pm2_RD(p, PM2R_CHIP_CONFIG) &
351 ~(PM2F_VGA_ENABLE | PM2F_VGA_FIXED));
352 pm2_WR(p, PM2R_BYPASS_WRITE_MASK, ~(0L));
353 pm2_WR(p, PM2R_FRAMEBUFFER_WRITE_MASK, ~(0L));
354 pm2_WR(p, PM2R_FIFO_CONTROL, 0);
355 pm2_WR(p, PM2R_APERTURE_ONE, 0);
356 pm2_WR(p, PM2R_APERTURE_TWO, 0);
357 pm2_WR(p, PM2R_RASTERIZER_MODE, 0);
358 pm2_WR(p, PM2R_DELTA_MODE, PM2F_DELTA_ORDER_RGB);
359 pm2_WR(p, PM2R_LB_READ_FORMAT, 0);
360 pm2_WR(p, PM2R_LB_WRITE_FORMAT, 0);
361 pm2_WR(p, PM2R_LB_READ_MODE, 0);
362 pm2_WR(p, PM2R_LB_SOURCE_OFFSET, 0);
363 pm2_WR(p, PM2R_FB_SOURCE_OFFSET, 0);
364 pm2_WR(p, PM2R_FB_PIXEL_OFFSET, 0);
365 pm2_WR(p, PM2R_FB_WINDOW_BASE, 0);
366 pm2_WR(p, PM2R_LB_WINDOW_BASE, 0);
367 pm2_WR(p, PM2R_FB_SOFT_WRITE_MASK, ~(0L));
368 pm2_WR(p, PM2R_FB_HARD_WRITE_MASK, ~(0L));
369 pm2_WR(p, PM2R_FB_READ_PIXEL, 0);
370 pm2_WR(p, PM2R_DITHER_MODE, 0);
371 pm2_WR(p, PM2R_AREA_STIPPLE_MODE, 0);
372 pm2_WR(p, PM2R_DEPTH_MODE, 0);
373 pm2_WR(p, PM2R_STENCIL_MODE, 0);
374 pm2_WR(p, PM2R_TEXTURE_ADDRESS_MODE, 0);
375 pm2_WR(p, PM2R_TEXTURE_READ_MODE, 0);
376 pm2_WR(p, PM2R_TEXEL_LUT_MODE, 0);
377 pm2_WR(p, PM2R_YUV_MODE, 0);
378 pm2_WR(p, PM2R_COLOR_DDA_MODE, 0);
379 pm2_WR(p, PM2R_TEXTURE_COLOR_MODE, 0);
380 pm2_WR(p, PM2R_FOG_MODE, 0);
381 pm2_WR(p, PM2R_ALPHA_BLEND_MODE, 0);
382 pm2_WR(p, PM2R_LOGICAL_OP_MODE, 0);
383 pm2_WR(p, PM2R_STATISTICS_MODE, 0);
384 pm2_WR(p, PM2R_SCISSOR_MODE, 0);
385 pm2_WR(p, PM2R_FILTER_MODE, PM2F_SYNCHRONIZATION);
386 pm2_WR(p, PM2R_RD_PIXEL_MASK, 0xff);
388 case PM2_TYPE_PERMEDIA2:
389 pm2_RDAC_WR(p, PM2I_RD_MODE_CONTROL, 0); /* no overlay */
390 pm2_RDAC_WR(p, PM2I_RD_CURSOR_CONTROL, 0);
391 pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, PM2F_RD_PALETTE_WIDTH_8);
392 pm2_RDAC_WR(p, PM2I_RD_COLOR_KEY_CONTROL, 0);
393 pm2_RDAC_WR(p, PM2I_RD_OVERLAY_KEY, 0);
394 pm2_RDAC_WR(p, PM2I_RD_RED_KEY, 0);
395 pm2_RDAC_WR(p, PM2I_RD_GREEN_KEY, 0);
396 pm2_RDAC_WR(p, PM2I_RD_BLUE_KEY, 0);
398 case PM2_TYPE_PERMEDIA2V:
399 pm2v_RDAC_WR(p, PM2VI_RD_MISC_CONTROL, 1); /* 8bit */
404 static void set_aperture(struct pm2fb_par *p, u32 depth)
407 * The hardware is little-endian. When used in big-endian
408 * hosts, the on-chip aperture settings are used where
409 * possible to translate from host to card byte order.
412 #ifdef __LITTLE_ENDIAN
413 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD);
416 case 24: /* RGB->BGR */
418 * We can't use the aperture to translate host to
419 * card byte order here, so we switch to BGR mode
420 * in pm2fb_set_par().
423 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD);
425 case 16: /* HL->LH */
426 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_HALFWORDSWAP);
428 case 32: /* RGBA->ABGR */
429 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_BYTESWAP);
434 /* We don't use aperture two, so this may be superflous */
435 pm2_WR(p, PM2R_APERTURE_TWO, PM2F_APERTURE_STANDARD);
438 static void set_color(struct pm2fb_par *p, unsigned char regno,
439 unsigned char r, unsigned char g, unsigned char b)
442 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, regno);
444 pm2_WR(p, PM2R_RD_PALETTE_DATA, r);
446 pm2_WR(p, PM2R_RD_PALETTE_DATA, g);
448 pm2_WR(p, PM2R_RD_PALETTE_DATA, b);
451 static void set_memclock(struct pm2fb_par *par, u32 clk)
454 unsigned char m, n, p;
457 case PM2_TYPE_PERMEDIA2V:
458 pm2v_mnp(clk/2, &m, &n, &p);
460 pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_MCLK_CONTROL >> 8);
461 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 0);
462 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_PRESCALE, m);
463 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_FEEDBACK, n);
464 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_POSTSCALE, p);
465 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 1);
467 for (i = 256; i; i--)
468 if (pm2v_RDAC_RD(par, PM2VI_RD_MCLK_CONTROL) & 2)
470 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
472 case PM2_TYPE_PERMEDIA2:
473 pm2_mnp(clk, &m, &n, &p);
475 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 6);
476 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_1, m);
477 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_2, n);
478 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 8|p);
479 pm2_RDAC_RD(par, PM2I_RD_MEMORY_CLOCK_STATUS);
481 for (i = 256; i; i--)
482 if (pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED)
488 static void set_pixclock(struct pm2fb_par *par, u32 clk)
491 unsigned char m, n, p;
494 case PM2_TYPE_PERMEDIA2:
495 pm2_mnp(clk, &m, &n, &p);
497 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 0);
498 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A1, m);
499 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A2, n);
500 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 8|p);
501 pm2_RDAC_RD(par, PM2I_RD_PIXEL_CLOCK_STATUS);
503 for (i = 256; i; i--)
504 if (pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED)
507 case PM2_TYPE_PERMEDIA2V:
508 pm2v_mnp(clk/2, &m, &n, &p);
510 pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CLK0_PRESCALE >> 8);
511 pm2v_RDAC_WR(par, PM2VI_RD_CLK0_PRESCALE, m);
512 pm2v_RDAC_WR(par, PM2VI_RD_CLK0_FEEDBACK, n);
513 pm2v_RDAC_WR(par, PM2VI_RD_CLK0_POSTSCALE, p);
514 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
519 static void set_video(struct pm2fb_par *p, u32 video)
524 DPRINTK("video = 0x%x\n", video);
527 * The hardware cursor needs +vsync to recognise vert retrace.
528 * We may not be using the hardware cursor, but the X Glint
529 * driver may well. So always set +hsync/+vsync and then set
530 * the RAMDAC to invert the sync if necessary.
532 vsync &= ~(PM2F_HSYNC_MASK | PM2F_VSYNC_MASK);
533 vsync |= PM2F_HSYNC_ACT_HIGH | PM2F_VSYNC_ACT_HIGH;
536 pm2_WR(p, PM2R_VIDEO_CONTROL, vsync);
539 case PM2_TYPE_PERMEDIA2:
540 tmp = PM2F_RD_PALETTE_WIDTH_8;
541 if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW)
542 tmp |= 4; /* invert hsync */
543 if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW)
544 tmp |= 8; /* invert vsync */
545 pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, tmp);
547 case PM2_TYPE_PERMEDIA2V:
549 if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW)
550 tmp |= 1; /* invert hsync */
551 if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW)
552 tmp |= 4; /* invert vsync */
553 pm2v_RDAC_WR(p, PM2VI_RD_SYNC_CONTROL, tmp);
559 * pm2fb_check_var - Optional function. Validates a var passed in.
560 * @var: frame buffer variable screen structure
561 * @info: frame buffer structure that represents a single frame buffer
563 * Checks to see if the hardware supports the state requested by
566 * Returns negative errno on error, or zero on success.
568 static int pm2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
572 if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 &&
573 var->bits_per_pixel != 24 && var->bits_per_pixel != 32) {
574 DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
578 if (var->xres != var->xres_virtual) {
579 DPRINTK("virtual x resolution != "
580 "physical x resolution not supported\n");
584 if (var->yres > var->yres_virtual) {
585 DPRINTK("virtual y resolution < "
586 "physical y resolution not possible\n");
591 DPRINTK("xoffset not supported\n");
595 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
596 DPRINTK("interlace not supported\n");
600 var->xres = (var->xres + 15) & ~15; /* could sometimes be 8 */
601 lpitch = var->xres * ((var->bits_per_pixel + 7) >> 3);
603 if (var->xres < 320 || var->xres > 1600) {
604 DPRINTK("width not supported: %u\n", var->xres);
608 if (var->yres < 200 || var->yres > 1200) {
609 DPRINTK("height not supported: %u\n", var->yres);
613 if (lpitch * var->yres_virtual > info->fix.smem_len) {
614 DPRINTK("no memory for screen (%ux%ux%u)\n",
615 var->xres, var->yres_virtual, var->bits_per_pixel);
619 if (PICOS2KHZ(var->pixclock) > PM2_MAX_PIXCLOCK) {
620 DPRINTK("pixclock too high (%ldKHz)\n",
621 PICOS2KHZ(var->pixclock));
625 var->transp.offset = 0;
626 var->transp.length = 0;
627 switch (var->bits_per_pixel) {
630 var->green.length = 8;
631 var->blue.length = 8;
634 var->red.offset = 11;
636 var->green.offset = 5;
637 var->green.length = 6;
638 var->blue.offset = 0;
639 var->blue.length = 5;
642 var->transp.offset = 24;
643 var->transp.length = 8;
644 var->red.offset = 16;
645 var->green.offset = 8;
646 var->blue.offset = 0;
648 var->green.length = 8;
649 var->blue.length = 8;
654 var->blue.offset = 16;
656 var->red.offset = 16;
657 var->blue.offset = 0;
659 var->green.offset = 8;
661 var->green.length = 8;
662 var->blue.length = 8;
668 var->accel_flags = 0; /* Can't mmap if this is on */
670 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
671 var->xres, var->yres, var->bits_per_pixel);
676 * pm2fb_set_par - Alters the hardware state.
677 * @info: frame buffer structure that represents a single frame buffer
679 * Using the fb_var_screeninfo in fb_info we set the resolution of the
680 * this particular framebuffer.
682 static int pm2fb_set_par(struct fb_info *info)
684 struct pm2fb_par *par = info->par;
686 u32 width = (info->var.xres_virtual + 7) & ~7;
687 u32 height = info->var.yres_virtual;
688 u32 depth = (info->var.bits_per_pixel + 7) & ~7;
689 u32 hsstart, hsend, hbend, htotal;
690 u32 vsstart, vsend, vbend, vtotal;
694 u32 clrmode = PM2F_RD_COLOR_MODE_RGB | PM2F_RD_GUI_ACTIVE;
698 u32 misc = 1; /* 8-bit DAC */
699 u32 xres = (info->var.xres + 31) & ~31;
706 set_memclock(par, par->memclock);
708 depth = (depth > 32) ? 32 : depth;
709 data64 = depth > 8 || par->type == PM2_TYPE_PERMEDIA2V;
711 pixclock = PICOS2KHZ(info->var.pixclock);
712 if (pixclock > PM2_MAX_PIXCLOCK) {
713 DPRINTK("pixclock too high (%uKHz)\n", pixclock);
717 hsstart = to3264(info->var.right_margin, depth, data64);
718 hsend = hsstart + to3264(info->var.hsync_len, depth, data64);
719 hbend = hsend + to3264(info->var.left_margin, depth, data64);
720 htotal = to3264(xres, depth, data64) + hbend - 1;
721 vsstart = (info->var.lower_margin)
722 ? info->var.lower_margin - 1
724 vsend = info->var.lower_margin + info->var.vsync_len - 1;
725 vbend = info->var.lower_margin + info->var.vsync_len +
726 info->var.upper_margin;
727 vtotal = info->var.yres + vbend - 1;
728 stride = to3264(width, depth, 1);
729 base = to3264(info->var.yoffset * xres + info->var.xoffset, depth, 1);
731 video |= PM2F_DATA_64_ENABLE;
733 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) {
735 DPRINTK("ignoring +hsync, using -hsync.\n");
736 video |= PM2F_HSYNC_ACT_LOW;
738 video |= PM2F_HSYNC_ACT_HIGH;
740 video |= PM2F_HSYNC_ACT_LOW;
742 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) {
744 DPRINTK("ignoring +vsync, using -vsync.\n");
745 video |= PM2F_VSYNC_ACT_LOW;
747 video |= PM2F_VSYNC_ACT_HIGH;
749 video |= PM2F_VSYNC_ACT_LOW;
751 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
752 DPRINTK("interlaced not supported\n");
755 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
756 video |= PM2F_LINE_DOUBLE;
757 if ((info->var.activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW)
758 video |= PM2F_VIDEO_ENABLE;
762 (depth == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
763 info->fix.line_length = info->var.xres * depth / 8;
764 info->cmap.len = 256;
767 * Settings calculated. Now write them out.
769 if (par->type == PM2_TYPE_PERMEDIA2V) {
771 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
774 set_aperture(par, depth);
780 pm2_WR(par, PM2R_FB_READ_PIXEL, 0);
784 pm2_WR(par, PM2R_FB_READ_PIXEL, 1);
785 clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB565;
786 txtmap = PM2F_TEXTEL_SIZE_16;
792 pm2_WR(par, PM2R_FB_READ_PIXEL, 2);
793 clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGBA8888;
794 txtmap = PM2F_TEXTEL_SIZE_32;
800 pm2_WR(par, PM2R_FB_READ_PIXEL, 4);
801 clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB888;
802 txtmap = PM2F_TEXTEL_SIZE_24;
808 pm2_WR(par, PM2R_FB_WRITE_MODE, PM2F_FB_WRITE_ENABLE);
809 pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres));
810 pm2_WR(par, PM2R_LB_READ_MODE, partprod(xres));
811 pm2_WR(par, PM2R_TEXTURE_MAP_FORMAT, txtmap | partprod(xres));
812 pm2_WR(par, PM2R_H_TOTAL, htotal);
813 pm2_WR(par, PM2R_HS_START, hsstart);
814 pm2_WR(par, PM2R_HS_END, hsend);
815 pm2_WR(par, PM2R_HG_END, hbend);
816 pm2_WR(par, PM2R_HB_END, hbend);
817 pm2_WR(par, PM2R_V_TOTAL, vtotal);
818 pm2_WR(par, PM2R_VS_START, vsstart);
819 pm2_WR(par, PM2R_VS_END, vsend);
820 pm2_WR(par, PM2R_VB_END, vbend);
821 pm2_WR(par, PM2R_SCREEN_STRIDE, stride);
823 pm2_WR(par, PM2R_WINDOW_ORIGIN, 0);
824 pm2_WR(par, PM2R_SCREEN_SIZE, (height << 16) | width);
825 pm2_WR(par, PM2R_SCISSOR_MODE, PM2F_SCREEN_SCISSOR_ENABLE);
827 pm2_WR(par, PM2R_SCREEN_BASE, base);
829 set_video(par, video);
832 case PM2_TYPE_PERMEDIA2:
833 pm2_RDAC_WR(par, PM2I_RD_COLOR_MODE, clrmode);
834 pm2_RDAC_WR(par, PM2I_RD_COLOR_KEY_CONTROL,
835 (depth == 8) ? 0 : PM2F_COLOR_KEY_TEST_OFF);
837 case PM2_TYPE_PERMEDIA2V:
838 pm2v_RDAC_WR(par, PM2VI_RD_DAC_CONTROL, 0);
839 pm2v_RDAC_WR(par, PM2VI_RD_PIXEL_SIZE, pixsize);
840 pm2v_RDAC_WR(par, PM2VI_RD_COLOR_FORMAT, clrformat);
841 pm2v_RDAC_WR(par, PM2VI_RD_MISC_CONTROL, misc);
842 pm2v_RDAC_WR(par, PM2VI_RD_OVERLAY_KEY, 0);
845 set_pixclock(par, pixclock);
846 DPRINTK("Setting graphics mode at %dx%d depth %d\n",
847 info->var.xres, info->var.yres, info->var.bits_per_pixel);
852 * pm2fb_setcolreg - Sets a color register.
853 * @regno: boolean, 0 copy local, 1 get_user() function
854 * @red: frame buffer colormap structure
855 * @green: The green value which can be up to 16 bits wide
856 * @blue: The blue value which can be up to 16 bits wide.
857 * @transp: If supported the alpha value which can be up to 16 bits wide.
858 * @info: frame buffer info structure
860 * Set a single color register. The values supplied have a 16 bit
861 * magnitude which needs to be scaled in this function for the hardware.
862 * Pretty much a direct lift from tdfxfb.c.
864 * Returns negative errno on error, or zero on success.
866 static int pm2fb_setcolreg(unsigned regno, unsigned red, unsigned green,
867 unsigned blue, unsigned transp,
868 struct fb_info *info)
870 struct pm2fb_par *par = info->par;
872 if (regno >= info->cmap.len) /* no. of hw registers */
875 * Program hardware... do anything you want with transp
878 /* grayscale works only partially under directcolor */
879 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
880 if (info->var.grayscale)
881 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
884 * var->{color}.offset contains start of bitfield
885 * var->{color}.length contains length of bitfield
886 * {hardwarespecific} contains width of DAC
887 * cmap[X] is programmed to
888 * (X << red.offset) | (X << green.offset) | (X << blue.offset)
889 * RAMDAC[X] is programmed to (red, green, blue)
892 * uses offset = 0 && length = DAC register width.
893 * var->{color}.offset is 0
894 * var->{color}.length contains widht of DAC
896 * DAC[X] is programmed to (red, green, blue)
898 * does not use RAMDAC (usually has 3 of them).
899 * var->{color}.offset contains start of bitfield
900 * var->{color}.length contains length of bitfield
901 * cmap is programmed to
902 * (red << red.offset) | (green << green.offset) |
903 * (blue << blue.offset) | (transp << transp.offset)
904 * RAMDAC does not exist
906 #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF -(val)) >> 16)
907 switch (info->fix.visual) {
908 case FB_VISUAL_TRUECOLOR:
909 case FB_VISUAL_PSEUDOCOLOR:
910 red = CNVT_TOHW(red, info->var.red.length);
911 green = CNVT_TOHW(green, info->var.green.length);
912 blue = CNVT_TOHW(blue, info->var.blue.length);
913 transp = CNVT_TOHW(transp, info->var.transp.length);
915 case FB_VISUAL_DIRECTCOLOR:
916 /* example here assumes 8 bit DAC. Might be different
917 * for your hardware */
918 red = CNVT_TOHW(red, 8);
919 green = CNVT_TOHW(green, 8);
920 blue = CNVT_TOHW(blue, 8);
921 /* hey, there is bug in transp handling... */
922 transp = CNVT_TOHW(transp, 8);
926 /* Truecolor has hardware independent palette */
927 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
933 v = (red << info->var.red.offset) |
934 (green << info->var.green.offset) |
935 (blue << info->var.blue.offset) |
936 (transp << info->var.transp.offset);
938 switch (info->var.bits_per_pixel) {
944 par->palette[regno] = v;
948 } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
949 set_color(par, regno, red, green, blue);
955 * pm2fb_pan_display - Pans the display.
956 * @var: frame buffer variable screen structure
957 * @info: frame buffer structure that represents a single frame buffer
959 * Pan (or wrap, depending on the `vmode' field) the display using the
960 * `xoffset' and `yoffset' fields of the `var' structure.
961 * If the values don't fit, return -EINVAL.
963 * Returns negative errno on error, or zero on success.
966 static int pm2fb_pan_display(struct fb_var_screeninfo *var,
967 struct fb_info *info)
969 struct pm2fb_par *p = info->par;
971 u32 depth = (var->bits_per_pixel + 7) & ~7;
972 u32 xres = (var->xres + 31) & ~31;
974 depth = (depth > 32) ? 32 : depth;
975 base = to3264(var->yoffset * xres + var->xoffset, depth, 1);
977 pm2_WR(p, PM2R_SCREEN_BASE, base);
982 * pm2fb_blank - Blanks the display.
983 * @blank_mode: the blank mode we want.
984 * @info: frame buffer structure that represents a single frame buffer
986 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
987 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
988 * video mode which doesn't support it. Implements VESA suspend
989 * and powerdown modes on hardware that supports disabling hsync/vsync:
990 * blank_mode == 2: suspend vsync
991 * blank_mode == 3: suspend hsync
992 * blank_mode == 4: powerdown
994 * Returns negative errno on error, or zero on success.
997 static int pm2fb_blank(int blank_mode, struct fb_info *info)
999 struct pm2fb_par *par = info->par;
1000 u32 video = par->video;
1002 DPRINTK("blank_mode %d\n", blank_mode);
1004 switch (blank_mode) {
1005 case FB_BLANK_UNBLANK:
1007 video |= PM2F_VIDEO_ENABLE;
1009 case FB_BLANK_NORMAL:
1011 video &= ~PM2F_VIDEO_ENABLE;
1013 case FB_BLANK_VSYNC_SUSPEND:
1015 video &= ~(PM2F_VSYNC_MASK | PM2F_BLANK_LOW);
1017 case FB_BLANK_HSYNC_SUSPEND:
1019 video &= ~(PM2F_HSYNC_MASK | PM2F_BLANK_LOW);
1021 case FB_BLANK_POWERDOWN:
1022 /* HSync: Off, VSync: Off */
1023 video &= ~(PM2F_VSYNC_MASK | PM2F_HSYNC_MASK | PM2F_BLANK_LOW);
1026 set_video(par, video);
1030 static int pm2fb_sync(struct fb_info *info)
1032 struct pm2fb_par *par = info->par;
1035 pm2_WR(par, PM2R_SYNC, 0);
1038 while (pm2_RD(par, PM2R_OUT_FIFO_WORDS) == 0)
1041 } while (pm2_RD(par, PM2R_OUT_FIFO) != PM2TAG(PM2R_SYNC));
1046 static void pm2fb_fillrect(struct fb_info *info,
1047 const struct fb_fillrect *region)
1049 struct pm2fb_par *par = info->par;
1050 struct fb_fillrect modded;
1052 u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
1053 ((u32 *)info->pseudo_palette)[region->color] : region->color;
1055 if (info->state != FBINFO_STATE_RUNNING)
1057 if ((info->flags & FBINFO_HWACCEL_DISABLED) ||
1058 region->rop != ROP_COPY ) {
1059 cfb_fillrect(info, region);
1063 vxres = info->var.xres_virtual;
1064 vyres = info->var.yres_virtual;
1066 memcpy(&modded, region, sizeof(struct fb_fillrect));
1068 if (!modded.width || !modded.height ||
1069 modded.dx >= vxres || modded.dy >= vyres)
1072 if (modded.dx + modded.width > vxres)
1073 modded.width = vxres - modded.dx;
1074 if (modded.dy + modded.height > vyres)
1075 modded.height = vyres - modded.dy;
1077 if (info->var.bits_per_pixel == 8)
1078 color |= color << 8;
1079 if (info->var.bits_per_pixel <= 16)
1080 color |= color << 16;
1083 pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE);
1084 pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (modded.dy << 16) | modded.dx);
1085 pm2_WR(par, PM2R_RECTANGLE_SIZE, (modded.height << 16) | modded.width);
1086 if (info->var.bits_per_pixel != 24) {
1088 pm2_WR(par, PM2R_FB_BLOCK_COLOR, color);
1090 pm2_WR(par, PM2R_RENDER,
1091 PM2F_RENDER_RECTANGLE | PM2F_RENDER_FASTFILL);
1094 pm2_WR(par, PM2R_COLOR_DDA_MODE, 1);
1095 pm2_WR(par, PM2R_CONSTANT_COLOR, color);
1097 pm2_WR(par, PM2R_RENDER,
1098 PM2F_RENDER_RECTANGLE |
1099 PM2F_INCREASE_X | PM2F_INCREASE_Y );
1100 pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);
1104 static void pm2fb_copyarea(struct fb_info *info,
1105 const struct fb_copyarea *area)
1107 struct pm2fb_par *par = info->par;
1108 struct fb_copyarea modded;
1111 if (info->state != FBINFO_STATE_RUNNING)
1113 if (info->flags & FBINFO_HWACCEL_DISABLED) {
1114 cfb_copyarea(info, area);
1118 memcpy(&modded, area, sizeof(struct fb_copyarea));
1120 vxres = info->var.xres_virtual;
1121 vyres = info->var.yres_virtual;
1123 if (!modded.width || !modded.height ||
1124 modded.sx >= vxres || modded.sy >= vyres ||
1125 modded.dx >= vxres || modded.dy >= vyres)
1128 if (modded.sx + modded.width > vxres)
1129 modded.width = vxres - modded.sx;
1130 if (modded.dx + modded.width > vxres)
1131 modded.width = vxres - modded.dx;
1132 if (modded.sy + modded.height > vyres)
1133 modded.height = vyres - modded.sy;
1134 if (modded.dy + modded.height > vyres)
1135 modded.height = vyres - modded.dy;
1138 pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE |
1139 PM2F_CONFIG_FB_READ_SOURCE_ENABLE);
1140 pm2_WR(par, PM2R_FB_SOURCE_DELTA,
1141 ((modded.sy - modded.dy) & 0xfff) << 16 |
1142 ((modded.sx - modded.dx) & 0xfff));
1143 pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (modded.dy << 16) | modded.dx);
1144 pm2_WR(par, PM2R_RECTANGLE_SIZE, (modded.height << 16) | modded.width);
1146 pm2_WR(par, PM2R_RENDER, PM2F_RENDER_RECTANGLE |
1147 (modded.dx < modded.sx ? PM2F_INCREASE_X : 0) |
1148 (modded.dy < modded.sy ? PM2F_INCREASE_Y : 0));
1151 static void pm2fb_imageblit(struct fb_info *info, const struct fb_image *image)
1153 struct pm2fb_par *par = info->par;
1154 u32 height = image->height;
1156 const u32 *src = (const u32 *)image->data;
1157 u32 xres = (info->var.xres + 31) & ~31;
1159 if (info->state != FBINFO_STATE_RUNNING)
1161 if (info->flags & FBINFO_HWACCEL_DISABLED || image->depth != 1) {
1162 cfb_imageblit(info, image);
1165 switch (info->fix.visual) {
1166 case FB_VISUAL_PSEUDOCOLOR:
1167 fgx = image->fg_color;
1168 bgx = image->bg_color;
1170 case FB_VISUAL_TRUECOLOR:
1172 fgx = par->palette[image->fg_color];
1173 bgx = par->palette[image->bg_color];
1176 if (info->var.bits_per_pixel == 8) {
1180 if (info->var.bits_per_pixel <= 16) {
1186 pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres));
1187 pm2_WR(par, PM2R_SCISSOR_MIN_XY,
1188 ((image->dy & 0xfff) << 16) | (image->dx & 0x0fff));
1189 pm2_WR(par, PM2R_SCISSOR_MAX_XY,
1190 (((image->dy + image->height) & 0x0fff) << 16) |
1191 ((image->dx + image->width) & 0x0fff));
1192 pm2_WR(par, PM2R_SCISSOR_MODE, 1);
1193 /* GXcopy & UNIT_ENABLE */
1194 pm2_WR(par, PM2R_LOGICAL_OP_MODE, (0x3 << 1) | 1);
1195 pm2_WR(par, PM2R_RECTANGLE_ORIGIN,
1196 ((image->dy & 0xfff) << 16) | (image->dx & 0x0fff));
1197 pm2_WR(par, PM2R_RECTANGLE_SIZE,
1198 ((image->height & 0x0fff) << 16) |
1199 ((image->width) & 0x0fff));
1200 if (info->var.bits_per_pixel == 24) {
1201 pm2_WR(par, PM2R_COLOR_DDA_MODE, 1);
1203 pm2_WR(par, PM2R_CONSTANT_COLOR, bgx);
1204 pm2_WR(par, PM2R_RENDER,
1205 PM2F_RENDER_RECTANGLE |
1206 PM2F_INCREASE_X | PM2F_INCREASE_Y);
1207 /* BitMapPackEachScanline & invert bits and byte order*/
1208 /* force background */
1209 pm2_WR(par, PM2R_RASTERIZER_MODE, (1 << 9) | 1 | (3 << 7));
1210 pm2_WR(par, PM2R_CONSTANT_COLOR, fgx);
1211 pm2_WR(par, PM2R_RENDER,
1212 PM2F_RENDER_RECTANGLE |
1213 PM2F_INCREASE_X | PM2F_INCREASE_Y |
1214 PM2F_RENDER_SYNC_ON_BIT_MASK);
1216 pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);
1218 pm2_WR(par, PM2R_FB_BLOCK_COLOR, bgx);
1219 pm2_WR(par, PM2R_RENDER,
1220 PM2F_RENDER_RECTANGLE |
1221 PM2F_RENDER_FASTFILL |
1222 PM2F_INCREASE_X | PM2F_INCREASE_Y);
1223 /* invert bits and byte order*/
1224 pm2_WR(par, PM2R_RASTERIZER_MODE, 1 | (3 << 7));
1225 pm2_WR(par, PM2R_FB_BLOCK_COLOR, fgx);
1226 pm2_WR(par, PM2R_RENDER,
1227 PM2F_RENDER_RECTANGLE |
1228 PM2F_INCREASE_X | PM2F_INCREASE_Y |
1229 PM2F_RENDER_FASTFILL |
1230 PM2F_RENDER_SYNC_ON_BIT_MASK);
1234 int width = ((image->width + 7) >> 3)
1235 + info->pixmap.scan_align - 1;
1237 WAIT_FIFO(par, width);
1239 pm2_WR(par, PM2R_BIT_MASK_PATTERN, *src);
1244 pm2_WR(par, PM2R_RASTERIZER_MODE, 0);
1245 pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);
1246 pm2_WR(par, PM2R_SCISSOR_MODE, 0);
1250 * Hardware cursor support.
1252 static const u8 cursor_bits_lookup[16] = {
1253 0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54,
1254 0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55
1257 static int pm2vfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1259 struct pm2fb_par *par = info->par;
1263 return -EINVAL; /* just to force soft_cursor() call */
1265 /* Too large of a cursor or wrong bpp :-( */
1266 if (cursor->image.width > 64 ||
1267 cursor->image.height > 64 ||
1268 cursor->image.depth > 1)
1271 mode = PM2F_CURSORMODE_TYPE_X;
1273 mode |= PM2F_CURSORMODE_CURSOR_ENABLE;
1275 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_MODE, mode);
1278 * If the cursor is not be changed this means either we want the
1279 * current cursor state (if enable is set) or we want to query what
1280 * we can do with the cursor (if enable is not set)
1285 if (cursor->set & FB_CUR_SETPOS) {
1286 int x = cursor->image.dx - info->var.xoffset;
1287 int y = cursor->image.dy - info->var.yoffset;
1289 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_LOW, x & 0xff);
1290 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_HIGH, (x >> 8) & 0xf);
1291 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_LOW, y & 0xff);
1292 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_HIGH, (y >> 8) & 0xf);
1295 if (cursor->set & FB_CUR_SETHOT) {
1296 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_HOT,
1297 cursor->hot.x & 0x3f);
1298 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_HOT,
1299 cursor->hot.y & 0x3f);
1302 if (cursor->set & FB_CUR_SETCMAP) {
1303 u32 fg_idx = cursor->image.fg_color;
1304 u32 bg_idx = cursor->image.bg_color;
1305 struct fb_cmap cmap = info->cmap;
1307 /* the X11 driver says one should use these color registers */
1308 pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CURSOR_PALETTE >> 8);
1309 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 0,
1310 cmap.red[bg_idx] >> 8 );
1311 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 1,
1312 cmap.green[bg_idx] >> 8 );
1313 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 2,
1314 cmap.blue[bg_idx] >> 8 );
1316 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 3,
1317 cmap.red[fg_idx] >> 8 );
1318 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 4,
1319 cmap.green[fg_idx] >> 8 );
1320 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 5,
1321 cmap.blue[fg_idx] >> 8 );
1322 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
1325 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1326 u8 *bitmap = (u8 *)cursor->image.data;
1327 u8 *mask = (u8 *)cursor->mask;
1329 int pos = PM2VI_RD_CURSOR_PATTERN;
1331 for (i = 0; i < cursor->image.height; i++) {
1332 int j = (cursor->image.width + 7) >> 3;
1335 pm2_WR(par, PM2VR_RD_INDEX_HIGH, pos >> 8);
1337 for (; j > 0; j--) {
1338 u8 data = *bitmap ^ *mask;
1340 if (cursor->rop == ROP_COPY)
1341 data = *mask & *bitmap;
1342 /* Upper 4 bits of bitmap data */
1343 pm2v_RDAC_WR(par, pos++,
1344 cursor_bits_lookup[data >> 4] |
1345 (cursor_bits_lookup[*mask >> 4] << 1));
1346 /* Lower 4 bits of bitmap */
1347 pm2v_RDAC_WR(par, pos++,
1348 cursor_bits_lookup[data & 0xf] |
1349 (cursor_bits_lookup[*mask & 0xf] << 1));
1353 for (; k > 0; k--) {
1354 pm2v_RDAC_WR(par, pos++, 0);
1355 pm2v_RDAC_WR(par, pos++, 0);
1359 while (pos < (1024 + PM2VI_RD_CURSOR_PATTERN)) {
1360 pm2_WR(par, PM2VR_RD_INDEX_HIGH, pos >> 8);
1361 pm2v_RDAC_WR(par, pos++, 0);
1364 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
1369 static int pm2fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1371 struct pm2fb_par *par = info->par;
1373 if (par->type == PM2_TYPE_PERMEDIA2V)
1374 return pm2vfb_cursor(info, cursor);
1379 /* ------------ Hardware Independent Functions ------------ */
1382 * Frame buffer operations
1385 static struct fb_ops pm2fb_ops = {
1386 .owner = THIS_MODULE,
1387 .fb_check_var = pm2fb_check_var,
1388 .fb_set_par = pm2fb_set_par,
1389 .fb_setcolreg = pm2fb_setcolreg,
1390 .fb_blank = pm2fb_blank,
1391 .fb_pan_display = pm2fb_pan_display,
1392 .fb_fillrect = pm2fb_fillrect,
1393 .fb_copyarea = pm2fb_copyarea,
1394 .fb_imageblit = pm2fb_imageblit,
1395 .fb_sync = pm2fb_sync,
1396 .fb_cursor = pm2fb_cursor,
1405 * Device initialisation
1407 * Initialise and allocate resource for PCI device.
1409 * @param pdev PCI device.
1410 * @param id PCI device ID.
1412 static int __devinit pm2fb_probe(struct pci_dev *pdev,
1413 const struct pci_device_id *id)
1415 struct pm2fb_par *default_par;
1416 struct fb_info *info;
1418 int retval = -ENXIO;
1420 err = pci_enable_device(pdev);
1422 printk(KERN_WARNING "pm2fb: Can't enable pdev: %d\n", err);
1426 info = framebuffer_alloc(sizeof(struct pm2fb_par), &pdev->dev);
1429 default_par = info->par;
1431 switch (pdev->device) {
1432 case PCI_DEVICE_ID_TI_TVP4020:
1433 strcpy(pm2fb_fix.id, "TVP4020");
1434 default_par->type = PM2_TYPE_PERMEDIA2;
1436 case PCI_DEVICE_ID_3DLABS_PERMEDIA2:
1437 strcpy(pm2fb_fix.id, "Permedia2");
1438 default_par->type = PM2_TYPE_PERMEDIA2;
1440 case PCI_DEVICE_ID_3DLABS_PERMEDIA2V:
1441 strcpy(pm2fb_fix.id, "Permedia2v");
1442 default_par->type = PM2_TYPE_PERMEDIA2V;
1446 pm2fb_fix.mmio_start = pci_resource_start(pdev, 0);
1447 pm2fb_fix.mmio_len = PM2_REGS_SIZE;
1449 #if defined(__BIG_ENDIAN)
1451 * PM2 has a 64k register file, mapped twice in 128k. Lower
1452 * map is little-endian, upper map is big-endian.
1454 pm2fb_fix.mmio_start += PM2_REGS_SIZE;
1455 DPRINTK("Adjusting register base for big-endian.\n");
1457 DPRINTK("Register base at 0x%lx\n", pm2fb_fix.mmio_start);
1459 /* Registers - request region and map it. */
1460 if (!request_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len,
1462 printk(KERN_WARNING "pm2fb: Can't reserve regbase.\n");
1463 goto err_exit_neither;
1465 default_par->v_regs =
1466 ioremap_nocache(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
1467 if (!default_par->v_regs) {
1468 printk(KERN_WARNING "pm2fb: Can't remap %s register area.\n",
1470 release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
1471 goto err_exit_neither;
1474 /* Stash away memory register info for use when we reset the board */
1475 default_par->mem_control = pm2_RD(default_par, PM2R_MEM_CONTROL);
1476 default_par->boot_address = pm2_RD(default_par, PM2R_BOOT_ADDRESS);
1477 default_par->mem_config = pm2_RD(default_par, PM2R_MEM_CONFIG);
1478 DPRINTK("MemControl 0x%x BootAddress 0x%x MemConfig 0x%x\n",
1479 default_par->mem_control, default_par->boot_address,
1480 default_par->mem_config);
1482 if (default_par->mem_control == 0 &&
1483 default_par->boot_address == 0x31 &&
1484 default_par->mem_config == 0x259fffff) {
1485 default_par->memclock = CVPPC_MEMCLOCK;
1486 default_par->mem_control = 0;
1487 default_par->boot_address = 0x20;
1488 default_par->mem_config = 0xe6002021;
1489 if (pdev->subsystem_vendor == 0x1048 &&
1490 pdev->subsystem_device == 0x0a31) {
1491 DPRINTK("subsystem_vendor: %04x, "
1492 "subsystem_device: %04x\n",
1493 pdev->subsystem_vendor, pdev->subsystem_device);
1494 DPRINTK("We have not been initialized by VGA BIOS and "
1495 "are running on an Elsa Winner 2000 Office\n");
1496 DPRINTK("Initializing card timings manually...\n");
1497 default_par->memclock = 100000;
1499 if (pdev->subsystem_vendor == 0x3d3d &&
1500 pdev->subsystem_device == 0x0100) {
1501 DPRINTK("subsystem_vendor: %04x, "
1502 "subsystem_device: %04x\n",
1503 pdev->subsystem_vendor, pdev->subsystem_device);
1504 DPRINTK("We have not been initialized by VGA BIOS and "
1505 "are running on an 3dlabs reference board\n");
1506 DPRINTK("Initializing card timings manually...\n");
1507 default_par->memclock = 74894;
1511 /* Now work out how big lfb is going to be. */
1512 switch (default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) {
1513 case PM2F_MEM_BANKS_1:
1514 pm2fb_fix.smem_len = 0x200000;
1516 case PM2F_MEM_BANKS_2:
1517 pm2fb_fix.smem_len = 0x400000;
1519 case PM2F_MEM_BANKS_3:
1520 pm2fb_fix.smem_len = 0x600000;
1522 case PM2F_MEM_BANKS_4:
1523 pm2fb_fix.smem_len = 0x800000;
1526 pm2fb_fix.smem_start = pci_resource_start(pdev, 1);
1528 /* Linear frame buffer - request region and map it. */
1529 if (!request_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len,
1531 printk(KERN_WARNING "pm2fb: Can't reserve smem.\n");
1535 ioremap_nocache(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
1536 if (!info->screen_base) {
1537 printk(KERN_WARNING "pm2fb: Can't ioremap smem area.\n");
1538 release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
1543 default_par->mtrr_handle = -1;
1545 default_par->mtrr_handle =
1546 mtrr_add(pm2fb_fix.smem_start,
1548 MTRR_TYPE_WRCOMB, 1);
1551 info->fbops = &pm2fb_ops;
1552 info->fix = pm2fb_fix;
1553 info->pseudo_palette = default_par->palette;
1554 info->flags = FBINFO_DEFAULT |
1555 FBINFO_HWACCEL_YPAN |
1556 FBINFO_HWACCEL_COPYAREA |
1557 FBINFO_HWACCEL_IMAGEBLIT |
1558 FBINFO_HWACCEL_FILLRECT;
1560 info->pixmap.addr = kmalloc(PM2_PIXMAP_SIZE, GFP_KERNEL);
1561 if (!info->pixmap.addr) {
1563 goto err_exit_pixmap;
1565 info->pixmap.size = PM2_PIXMAP_SIZE;
1566 info->pixmap.buf_align = 4;
1567 info->pixmap.scan_align = 4;
1568 info->pixmap.access_align = 32;
1569 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1572 printk(KERN_DEBUG "disabling acceleration\n");
1573 info->flags |= FBINFO_HWACCEL_DISABLED;
1574 info->pixmap.scan_align = 1;
1578 mode = "640x480@60";
1580 err = fb_find_mode(&info->var, info, mode, NULL, 0, NULL, 8);
1581 if (!err || err == 4)
1582 info->var = pm2fb_var;
1584 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
1587 if (register_framebuffer(info) < 0)
1590 printk(KERN_INFO "fb%d: %s frame buffer device, memory = %dK.\n",
1591 info->node, info->fix.id, pm2fb_fix.smem_len / 1024);
1596 pci_set_drvdata(pdev, info);
1601 fb_dealloc_cmap(&info->cmap);
1603 kfree(info->pixmap.addr);
1605 iounmap(info->screen_base);
1606 release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
1608 iounmap(default_par->v_regs);
1609 release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
1611 framebuffer_release(info);
1618 * Release all device resources.
1620 * @param pdev PCI device to clean up.
1622 static void __devexit pm2fb_remove(struct pci_dev *pdev)
1624 struct fb_info *info = pci_get_drvdata(pdev);
1625 struct fb_fix_screeninfo *fix = &info->fix;
1626 struct pm2fb_par *par = info->par;
1628 unregister_framebuffer(info);
1631 if (par->mtrr_handle >= 0)
1632 mtrr_del(par->mtrr_handle, info->fix.smem_start,
1633 info->fix.smem_len);
1634 #endif /* CONFIG_MTRR */
1635 iounmap(info->screen_base);
1636 release_mem_region(fix->smem_start, fix->smem_len);
1637 iounmap(par->v_regs);
1638 release_mem_region(fix->mmio_start, fix->mmio_len);
1640 pci_set_drvdata(pdev, NULL);
1641 kfree(info->pixmap.addr);
1645 static struct pci_device_id pm2fb_id_table[] = {
1646 { PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TVP4020,
1647 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1648 { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2,
1649 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1650 { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V,
1651 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1655 static struct pci_driver pm2fb_driver = {
1657 .id_table = pm2fb_id_table,
1658 .probe = pm2fb_probe,
1659 .remove = __devexit_p(pm2fb_remove),
1662 MODULE_DEVICE_TABLE(pci, pm2fb_id_table);
1667 * Parse user speficied options.
1669 * This is, comma-separated options following `video=pm2fb:'.
1671 static int __init pm2fb_setup(char *options)
1675 if (!options || !*options)
1678 while ((this_opt = strsep(&options, ",")) != NULL) {
1681 if (!strcmp(this_opt, "lowhsync"))
1683 else if (!strcmp(this_opt, "lowvsync"))
1685 else if (!strncmp(this_opt, "hwcursor=", 9))
1686 hwcursor = simple_strtoul(this_opt + 9, NULL, 0);
1688 else if (!strncmp(this_opt, "nomtrr", 6))
1691 else if (!strncmp(this_opt, "noaccel", 7))
1701 static int __init pm2fb_init(void)
1704 char *option = NULL;
1706 if (fb_get_options("pm2fb", &option))
1708 pm2fb_setup(option);
1711 return pci_register_driver(&pm2fb_driver);
1714 module_init(pm2fb_init);
1721 static void __exit pm2fb_exit(void)
1723 pci_unregister_driver(&pm2fb_driver);
1728 module_exit(pm2fb_exit);
1730 module_param(mode, charp, 0);
1731 MODULE_PARM_DESC(mode, "Preferred video mode e.g. '648x480-8@60'");
1732 module_param(lowhsync, bool, 0);
1733 MODULE_PARM_DESC(lowhsync, "Force horizontal sync low regardless of mode");
1734 module_param(lowvsync, bool, 0);
1735 MODULE_PARM_DESC(lowvsync, "Force vertical sync low regardless of mode");
1736 module_param(noaccel, bool, 0);
1737 MODULE_PARM_DESC(noaccel, "Disable acceleration");
1738 module_param(hwcursor, int, 0644);
1739 MODULE_PARM_DESC(hwcursor, "Enable hardware cursor "
1740 "(1=enable, 0=disable, default=0)");
1742 module_param(nomtrr, bool, 0);
1743 MODULE_PARM_DESC(nomtrr, "Disable MTRR support (0 or 1=disabled) (default=0)");
1746 MODULE_AUTHOR("Jim Hague <jim.hague@acm.org>");
1747 MODULE_DESCRIPTION("Permedia2 framebuffer device driver");
1748 MODULE_LICENSE("GPL");