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>
41 #include <video/permedia2.h>
42 #include <video/cvisionppc.h>
44 #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
45 #error "The endianness of the target host has not been defined."
48 #if !defined(CONFIG_PCI)
49 #error "Only generic PCI cards supported."
52 #undef PM2FB_MASTER_DEBUG
53 #ifdef PM2FB_MASTER_DEBUG
54 #define DPRINTK(a, b...) \
55 printk(KERN_DEBUG "pm2fb: %s: " a, __func__ , ## b)
57 #define DPRINTK(a, b...) no_printk(a, ##b)
60 #define PM2_PIXMAP_SIZE (1600 * 4)
65 static int hwcursor = 1;
66 static char *mode_option;
69 * The XFree GLINT driver will (I think to implement hardware cursor
70 * support on TVP4010 and similar where there is no RAMDAC - see
71 * comment in set_video) always request +ve sync regardless of what
72 * the mode requires. This screws me because I have a Sun
73 * fixed-frequency monitor which absolutely has to have -ve sync. So
74 * these flags allow the user to specify that requests for +ve sync
75 * should be silently turned in -ve sync.
83 * The hardware state of the graphics card that isn't part of the
88 pm2type_t type; /* Board type */
89 unsigned char __iomem *v_regs;/* virtual address of p_regs */
90 u32 memclock; /* memclock */
91 u32 video; /* video flags before blanking */
92 u32 mem_config; /* MemConfig reg at probe */
93 u32 mem_control; /* MemControl reg at probe */
94 u32 boot_address; /* BootAddress reg at probe */
100 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
101 * if we don't use modedb.
103 static struct fb_fix_screeninfo pm2fb_fix = {
105 .type = FB_TYPE_PACKED_PIXELS,
106 .visual = FB_VISUAL_PSEUDOCOLOR,
110 .accel = FB_ACCEL_3DLABS_PERMEDIA2,
114 * Default video mode. In case the modedb doesn't work.
116 static const struct fb_var_screeninfo pm2fb_var = {
117 /* "640x480, 8 bpp @ 60 Hz */
126 .activate = FB_ACTIVATE_NOW,
137 .vmode = FB_VMODE_NONINTERLACED
144 static inline u32 pm2_RD(struct pm2fb_par *p, s32 off)
146 return fb_readl(p->v_regs + off);
149 static inline void pm2_WR(struct pm2fb_par *p, s32 off, u32 v)
151 fb_writel(v, p->v_regs + off);
154 static inline u32 pm2_RDAC_RD(struct pm2fb_par *p, s32 idx)
156 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx);
158 return pm2_RD(p, PM2R_RD_INDEXED_DATA);
161 static inline u32 pm2v_RDAC_RD(struct pm2fb_par *p, s32 idx)
163 pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
165 return pm2_RD(p, PM2VR_RD_INDEXED_DATA);
168 static inline void pm2_RDAC_WR(struct pm2fb_par *p, s32 idx, u32 v)
170 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx);
172 pm2_WR(p, PM2R_RD_INDEXED_DATA, v);
176 static inline void pm2v_RDAC_WR(struct pm2fb_par *p, s32 idx, u32 v)
178 pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
180 pm2_WR(p, PM2VR_RD_INDEXED_DATA, v);
184 #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
185 #define WAIT_FIFO(p, a)
187 static inline void WAIT_FIFO(struct pm2fb_par *p, u32 a)
189 while (pm2_RD(p, PM2R_IN_FIFO_SPACE) < a)
195 * partial products for the supported horizontal resolutions.
197 #define PACKPP(p0, p1, p2) (((p2) << 6) | ((p1) << 3) | (p0))
198 static const struct {
202 { 32, PACKPP(1, 0, 0) }, { 64, PACKPP(1, 1, 0) },
203 { 96, PACKPP(1, 1, 1) }, { 128, PACKPP(2, 1, 1) },
204 { 160, PACKPP(2, 2, 1) }, { 192, PACKPP(2, 2, 2) },
205 { 224, PACKPP(3, 2, 1) }, { 256, PACKPP(3, 2, 2) },
206 { 288, PACKPP(3, 3, 1) }, { 320, PACKPP(3, 3, 2) },
207 { 384, PACKPP(3, 3, 3) }, { 416, PACKPP(4, 3, 1) },
208 { 448, PACKPP(4, 3, 2) }, { 512, PACKPP(4, 3, 3) },
209 { 544, PACKPP(4, 4, 1) }, { 576, PACKPP(4, 4, 2) },
210 { 640, PACKPP(4, 4, 3) }, { 768, PACKPP(4, 4, 4) },
211 { 800, PACKPP(5, 4, 1) }, { 832, PACKPP(5, 4, 2) },
212 { 896, PACKPP(5, 4, 3) }, { 1024, PACKPP(5, 4, 4) },
213 { 1056, PACKPP(5, 5, 1) }, { 1088, PACKPP(5, 5, 2) },
214 { 1152, PACKPP(5, 5, 3) }, { 1280, PACKPP(5, 5, 4) },
215 { 1536, PACKPP(5, 5, 5) }, { 1568, PACKPP(6, 5, 1) },
216 { 1600, PACKPP(6, 5, 2) }, { 1664, PACKPP(6, 5, 3) },
217 { 1792, PACKPP(6, 5, 4) }, { 2048, PACKPP(6, 5, 5) },
220 static u32 partprod(u32 xres)
224 for (i = 0; pp_table[i].width && pp_table[i].width != xres; i++)
226 if (pp_table[i].width == 0)
227 DPRINTK("invalid width %u\n", xres);
228 return pp_table[i].pp;
231 static u32 to3264(u32 timing, int bpp, int is64)
251 static void pm2_mnp(u32 clk, unsigned char *mm, unsigned char *nn,
262 for (n = 2; n < 15; n++) {
263 for (m = 2; m; m++) {
264 f = PM2_REFERENCE_CLOCK * m / n;
265 if (f >= 150000 && f <= 300000) {
266 for (p = 0; p < 5; p++, f >>= 1) {
267 curr = (clk > f) ? clk - f : f - clk;
280 static void pm2v_mnp(u32 clk, unsigned char *mm, unsigned char *nn,
290 for (m = 1; m < 128; m++) {
291 for (n = 2 * m + 1; n; n++) {
292 for (p = 0; p < 2; p++) {
293 f = (PM2_REFERENCE_CLOCK >> (p + 1)) * n / m;
294 if (clk > f - delta && clk < f + delta) {
295 delta = (clk > f) ? clk - f : f - clk;
305 static void clear_palette(struct pm2fb_par *p)
310 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, 0);
314 pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
315 pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
316 pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
320 static void reset_card(struct pm2fb_par *p)
322 if (p->type == PM2_TYPE_PERMEDIA2V)
323 pm2_WR(p, PM2VR_RD_INDEX_HIGH, 0);
324 pm2_WR(p, PM2R_RESET_STATUS, 0);
326 while (pm2_RD(p, PM2R_RESET_STATUS) & PM2F_BEING_RESET)
329 #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
330 DPRINTK("FIFO disconnect enabled\n");
331 pm2_WR(p, PM2R_FIFO_DISCON, 1);
335 /* Restore stashed memory config information from probe */
337 pm2_WR(p, PM2R_MEM_CONTROL, p->mem_control);
338 pm2_WR(p, PM2R_BOOT_ADDRESS, p->boot_address);
340 pm2_WR(p, PM2R_MEM_CONFIG, p->mem_config);
343 static void reset_config(struct pm2fb_par *p)
346 pm2_WR(p, PM2R_CHIP_CONFIG, pm2_RD(p, PM2R_CHIP_CONFIG) &
347 ~(PM2F_VGA_ENABLE | PM2F_VGA_FIXED));
348 pm2_WR(p, PM2R_BYPASS_WRITE_MASK, ~(0L));
349 pm2_WR(p, PM2R_FRAMEBUFFER_WRITE_MASK, ~(0L));
350 pm2_WR(p, PM2R_FIFO_CONTROL, 0);
351 pm2_WR(p, PM2R_APERTURE_ONE, 0);
352 pm2_WR(p, PM2R_APERTURE_TWO, 0);
353 pm2_WR(p, PM2R_RASTERIZER_MODE, 0);
354 pm2_WR(p, PM2R_DELTA_MODE, PM2F_DELTA_ORDER_RGB);
355 pm2_WR(p, PM2R_LB_READ_FORMAT, 0);
356 pm2_WR(p, PM2R_LB_WRITE_FORMAT, 0);
357 pm2_WR(p, PM2R_LB_READ_MODE, 0);
358 pm2_WR(p, PM2R_LB_SOURCE_OFFSET, 0);
359 pm2_WR(p, PM2R_FB_SOURCE_OFFSET, 0);
360 pm2_WR(p, PM2R_FB_PIXEL_OFFSET, 0);
361 pm2_WR(p, PM2R_FB_WINDOW_BASE, 0);
362 pm2_WR(p, PM2R_LB_WINDOW_BASE, 0);
363 pm2_WR(p, PM2R_FB_SOFT_WRITE_MASK, ~(0L));
364 pm2_WR(p, PM2R_FB_HARD_WRITE_MASK, ~(0L));
365 pm2_WR(p, PM2R_FB_READ_PIXEL, 0);
366 pm2_WR(p, PM2R_DITHER_MODE, 0);
367 pm2_WR(p, PM2R_AREA_STIPPLE_MODE, 0);
368 pm2_WR(p, PM2R_DEPTH_MODE, 0);
369 pm2_WR(p, PM2R_STENCIL_MODE, 0);
370 pm2_WR(p, PM2R_TEXTURE_ADDRESS_MODE, 0);
371 pm2_WR(p, PM2R_TEXTURE_READ_MODE, 0);
372 pm2_WR(p, PM2R_TEXEL_LUT_MODE, 0);
373 pm2_WR(p, PM2R_YUV_MODE, 0);
374 pm2_WR(p, PM2R_COLOR_DDA_MODE, 0);
375 pm2_WR(p, PM2R_TEXTURE_COLOR_MODE, 0);
376 pm2_WR(p, PM2R_FOG_MODE, 0);
377 pm2_WR(p, PM2R_ALPHA_BLEND_MODE, 0);
378 pm2_WR(p, PM2R_LOGICAL_OP_MODE, 0);
379 pm2_WR(p, PM2R_STATISTICS_MODE, 0);
380 pm2_WR(p, PM2R_SCISSOR_MODE, 0);
381 pm2_WR(p, PM2R_FILTER_MODE, PM2F_SYNCHRONIZATION);
382 pm2_WR(p, PM2R_RD_PIXEL_MASK, 0xff);
384 case PM2_TYPE_PERMEDIA2:
385 pm2_RDAC_WR(p, PM2I_RD_MODE_CONTROL, 0); /* no overlay */
386 pm2_RDAC_WR(p, PM2I_RD_CURSOR_CONTROL, 0);
387 pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, PM2F_RD_PALETTE_WIDTH_8);
388 pm2_RDAC_WR(p, PM2I_RD_COLOR_KEY_CONTROL, 0);
389 pm2_RDAC_WR(p, PM2I_RD_OVERLAY_KEY, 0);
390 pm2_RDAC_WR(p, PM2I_RD_RED_KEY, 0);
391 pm2_RDAC_WR(p, PM2I_RD_GREEN_KEY, 0);
392 pm2_RDAC_WR(p, PM2I_RD_BLUE_KEY, 0);
394 case PM2_TYPE_PERMEDIA2V:
395 pm2v_RDAC_WR(p, PM2VI_RD_MISC_CONTROL, 1); /* 8bit */
400 static void set_aperture(struct pm2fb_par *p, u32 depth)
403 * The hardware is little-endian. When used in big-endian
404 * hosts, the on-chip aperture settings are used where
405 * possible to translate from host to card byte order.
408 #ifdef __LITTLE_ENDIAN
409 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD);
412 case 24: /* RGB->BGR */
414 * We can't use the aperture to translate host to
415 * card byte order here, so we switch to BGR mode
416 * in pm2fb_set_par().
419 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD);
421 case 16: /* HL->LH */
422 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_HALFWORDSWAP);
424 case 32: /* RGBA->ABGR */
425 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_BYTESWAP);
430 /* We don't use aperture two, so this may be superflous */
431 pm2_WR(p, PM2R_APERTURE_TWO, PM2F_APERTURE_STANDARD);
434 static void set_color(struct pm2fb_par *p, unsigned char regno,
435 unsigned char r, unsigned char g, unsigned char b)
438 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, regno);
440 pm2_WR(p, PM2R_RD_PALETTE_DATA, r);
442 pm2_WR(p, PM2R_RD_PALETTE_DATA, g);
444 pm2_WR(p, PM2R_RD_PALETTE_DATA, b);
447 static void set_memclock(struct pm2fb_par *par, u32 clk)
450 unsigned char m, n, p;
453 case PM2_TYPE_PERMEDIA2V:
454 pm2v_mnp(clk/2, &m, &n, &p);
456 pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_MCLK_CONTROL >> 8);
457 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 0);
458 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_PRESCALE, m);
459 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_FEEDBACK, n);
460 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_POSTSCALE, p);
461 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 1);
463 for (i = 256; i; i--)
464 if (pm2v_RDAC_RD(par, PM2VI_RD_MCLK_CONTROL) & 2)
466 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
468 case PM2_TYPE_PERMEDIA2:
469 pm2_mnp(clk, &m, &n, &p);
471 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 6);
472 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_1, m);
473 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_2, n);
474 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 8|p);
475 pm2_RDAC_RD(par, PM2I_RD_MEMORY_CLOCK_STATUS);
477 for (i = 256; i; i--)
478 if (pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED)
484 static void set_pixclock(struct pm2fb_par *par, u32 clk)
487 unsigned char m, n, p;
490 case PM2_TYPE_PERMEDIA2:
491 pm2_mnp(clk, &m, &n, &p);
493 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 0);
494 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A1, m);
495 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A2, n);
496 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 8|p);
497 pm2_RDAC_RD(par, PM2I_RD_PIXEL_CLOCK_STATUS);
499 for (i = 256; i; i--)
500 if (pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED)
503 case PM2_TYPE_PERMEDIA2V:
504 pm2v_mnp(clk/2, &m, &n, &p);
506 pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CLK0_PRESCALE >> 8);
507 pm2v_RDAC_WR(par, PM2VI_RD_CLK0_PRESCALE, m);
508 pm2v_RDAC_WR(par, PM2VI_RD_CLK0_FEEDBACK, n);
509 pm2v_RDAC_WR(par, PM2VI_RD_CLK0_POSTSCALE, p);
510 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
515 static void set_video(struct pm2fb_par *p, u32 video)
520 DPRINTK("video = 0x%x\n", video);
523 * The hardware cursor needs +vsync to recognise vert retrace.
524 * We may not be using the hardware cursor, but the X Glint
525 * driver may well. So always set +hsync/+vsync and then set
526 * the RAMDAC to invert the sync if necessary.
528 vsync &= ~(PM2F_HSYNC_MASK | PM2F_VSYNC_MASK);
529 vsync |= PM2F_HSYNC_ACT_HIGH | PM2F_VSYNC_ACT_HIGH;
532 pm2_WR(p, PM2R_VIDEO_CONTROL, vsync);
535 case PM2_TYPE_PERMEDIA2:
536 tmp = PM2F_RD_PALETTE_WIDTH_8;
537 if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW)
538 tmp |= 4; /* invert hsync */
539 if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW)
540 tmp |= 8; /* invert vsync */
541 pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, tmp);
543 case PM2_TYPE_PERMEDIA2V:
545 if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW)
546 tmp |= 1; /* invert hsync */
547 if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW)
548 tmp |= 4; /* invert vsync */
549 pm2v_RDAC_WR(p, PM2VI_RD_SYNC_CONTROL, tmp);
555 * pm2fb_check_var - Optional function. Validates a var passed in.
556 * @var: frame buffer variable screen structure
557 * @info: frame buffer structure that represents a single frame buffer
559 * Checks to see if the hardware supports the state requested by
562 * Returns negative errno on error, or zero on success.
564 static int pm2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
568 if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 &&
569 var->bits_per_pixel != 24 && var->bits_per_pixel != 32) {
570 DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
574 if (var->xres != var->xres_virtual) {
575 DPRINTK("virtual x resolution != "
576 "physical x resolution not supported\n");
580 if (var->yres > var->yres_virtual) {
581 DPRINTK("virtual y resolution < "
582 "physical y resolution not possible\n");
586 /* permedia cannot blit over 2048 */
587 if (var->yres_virtual > 2047) {
588 var->yres_virtual = 2047;
592 DPRINTK("xoffset not supported\n");
596 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
597 DPRINTK("interlace not supported\n");
601 var->xres = (var->xres + 15) & ~15; /* could sometimes be 8 */
602 lpitch = var->xres * ((var->bits_per_pixel + 7) >> 3);
604 if (var->xres < 320 || var->xres > 1600) {
605 DPRINTK("width not supported: %u\n", var->xres);
609 if (var->yres < 200 || var->yres > 1200) {
610 DPRINTK("height not supported: %u\n", var->yres);
614 if (lpitch * var->yres_virtual > info->fix.smem_len) {
615 DPRINTK("no memory for screen (%ux%ux%u)\n",
616 var->xres, var->yres_virtual, var->bits_per_pixel);
620 if (PICOS2KHZ(var->pixclock) > PM2_MAX_PIXCLOCK) {
621 DPRINTK("pixclock too high (%ldKHz)\n",
622 PICOS2KHZ(var->pixclock));
626 var->transp.offset = 0;
627 var->transp.length = 0;
628 switch (var->bits_per_pixel) {
631 var->green.length = 8;
632 var->blue.length = 8;
635 var->red.offset = 11;
637 var->green.offset = 5;
638 var->green.length = 6;
639 var->blue.offset = 0;
640 var->blue.length = 5;
643 var->transp.offset = 24;
644 var->transp.length = 8;
645 var->red.offset = 16;
646 var->green.offset = 8;
647 var->blue.offset = 0;
649 var->green.length = 8;
650 var->blue.length = 8;
655 var->blue.offset = 16;
657 var->red.offset = 16;
658 var->blue.offset = 0;
660 var->green.offset = 8;
662 var->green.length = 8;
663 var->blue.length = 8;
669 var->accel_flags = 0; /* Can't mmap if this is on */
671 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
672 var->xres, var->yres, var->bits_per_pixel);
677 * pm2fb_set_par - Alters the hardware state.
678 * @info: frame buffer structure that represents a single frame buffer
680 * Using the fb_var_screeninfo in fb_info we set the resolution of the
681 * this particular framebuffer.
683 static int pm2fb_set_par(struct fb_info *info)
685 struct pm2fb_par *par = info->par;
687 u32 width = (info->var.xres_virtual + 7) & ~7;
688 u32 height = info->var.yres_virtual;
689 u32 depth = (info->var.bits_per_pixel + 7) & ~7;
690 u32 hsstart, hsend, hbend, htotal;
691 u32 vsstart, vsend, vbend, vtotal;
695 u32 clrmode = PM2F_RD_COLOR_MODE_RGB | PM2F_RD_GUI_ACTIVE;
699 u32 misc = 1; /* 8-bit DAC */
700 u32 xres = (info->var.xres + 31) & ~31;
707 set_memclock(par, par->memclock);
709 depth = (depth > 32) ? 32 : depth;
710 data64 = depth > 8 || par->type == PM2_TYPE_PERMEDIA2V;
712 pixclock = PICOS2KHZ(info->var.pixclock);
713 if (pixclock > PM2_MAX_PIXCLOCK) {
714 DPRINTK("pixclock too high (%uKHz)\n", pixclock);
718 hsstart = to3264(info->var.right_margin, depth, data64);
719 hsend = hsstart + to3264(info->var.hsync_len, depth, data64);
720 hbend = hsend + to3264(info->var.left_margin, depth, data64);
721 htotal = to3264(xres, depth, data64) + hbend - 1;
722 vsstart = (info->var.lower_margin)
723 ? info->var.lower_margin - 1
725 vsend = info->var.lower_margin + info->var.vsync_len - 1;
726 vbend = info->var.lower_margin + info->var.vsync_len +
727 info->var.upper_margin;
728 vtotal = info->var.yres + vbend - 1;
729 stride = to3264(width, depth, 1);
730 base = to3264(info->var.yoffset * xres + info->var.xoffset, depth, 1);
732 video |= PM2F_DATA_64_ENABLE;
734 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) {
736 DPRINTK("ignoring +hsync, using -hsync.\n");
737 video |= PM2F_HSYNC_ACT_LOW;
739 video |= PM2F_HSYNC_ACT_HIGH;
741 video |= PM2F_HSYNC_ACT_LOW;
743 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) {
745 DPRINTK("ignoring +vsync, using -vsync.\n");
746 video |= PM2F_VSYNC_ACT_LOW;
748 video |= PM2F_VSYNC_ACT_HIGH;
750 video |= PM2F_VSYNC_ACT_LOW;
752 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
753 DPRINTK("interlaced not supported\n");
756 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
757 video |= PM2F_LINE_DOUBLE;
758 if ((info->var.activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW)
759 video |= PM2F_VIDEO_ENABLE;
763 (depth == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
764 info->fix.line_length = info->var.xres * depth / 8;
765 info->cmap.len = 256;
768 * Settings calculated. Now write them out.
770 if (par->type == PM2_TYPE_PERMEDIA2V) {
772 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
775 set_aperture(par, depth);
781 pm2_WR(par, PM2R_FB_READ_PIXEL, 0);
785 pm2_WR(par, PM2R_FB_READ_PIXEL, 1);
786 clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB565;
787 txtmap = PM2F_TEXTEL_SIZE_16;
793 pm2_WR(par, PM2R_FB_READ_PIXEL, 2);
794 clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGBA8888;
795 txtmap = PM2F_TEXTEL_SIZE_32;
801 pm2_WR(par, PM2R_FB_READ_PIXEL, 4);
802 clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB888;
803 txtmap = PM2F_TEXTEL_SIZE_24;
809 pm2_WR(par, PM2R_FB_WRITE_MODE, PM2F_FB_WRITE_ENABLE);
810 pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres));
811 pm2_WR(par, PM2R_LB_READ_MODE, partprod(xres));
812 pm2_WR(par, PM2R_TEXTURE_MAP_FORMAT, txtmap | partprod(xres));
813 pm2_WR(par, PM2R_H_TOTAL, htotal);
814 pm2_WR(par, PM2R_HS_START, hsstart);
815 pm2_WR(par, PM2R_HS_END, hsend);
816 pm2_WR(par, PM2R_HG_END, hbend);
817 pm2_WR(par, PM2R_HB_END, hbend);
818 pm2_WR(par, PM2R_V_TOTAL, vtotal);
819 pm2_WR(par, PM2R_VS_START, vsstart);
820 pm2_WR(par, PM2R_VS_END, vsend);
821 pm2_WR(par, PM2R_VB_END, vbend);
822 pm2_WR(par, PM2R_SCREEN_STRIDE, stride);
824 pm2_WR(par, PM2R_WINDOW_ORIGIN, 0);
825 pm2_WR(par, PM2R_SCREEN_SIZE, (height << 16) | width);
826 pm2_WR(par, PM2R_SCISSOR_MODE, PM2F_SCREEN_SCISSOR_ENABLE);
828 pm2_WR(par, PM2R_SCREEN_BASE, base);
830 set_video(par, video);
833 case PM2_TYPE_PERMEDIA2:
834 pm2_RDAC_WR(par, PM2I_RD_COLOR_MODE, clrmode);
835 pm2_RDAC_WR(par, PM2I_RD_COLOR_KEY_CONTROL,
836 (depth == 8) ? 0 : PM2F_COLOR_KEY_TEST_OFF);
838 case PM2_TYPE_PERMEDIA2V:
839 pm2v_RDAC_WR(par, PM2VI_RD_DAC_CONTROL, 0);
840 pm2v_RDAC_WR(par, PM2VI_RD_PIXEL_SIZE, pixsize);
841 pm2v_RDAC_WR(par, PM2VI_RD_COLOR_FORMAT, clrformat);
842 pm2v_RDAC_WR(par, PM2VI_RD_MISC_CONTROL, misc);
843 pm2v_RDAC_WR(par, PM2VI_RD_OVERLAY_KEY, 0);
846 set_pixclock(par, pixclock);
847 DPRINTK("Setting graphics mode at %dx%d depth %d\n",
848 info->var.xres, info->var.yres, info->var.bits_per_pixel);
853 * pm2fb_setcolreg - Sets a color register.
854 * @regno: boolean, 0 copy local, 1 get_user() function
855 * @red: frame buffer colormap structure
856 * @green: The green value which can be up to 16 bits wide
857 * @blue: The blue value which can be up to 16 bits wide.
858 * @transp: If supported the alpha value which can be up to 16 bits wide.
859 * @info: frame buffer info structure
861 * Set a single color register. The values supplied have a 16 bit
862 * magnitude which needs to be scaled in this function for the hardware.
863 * Pretty much a direct lift from tdfxfb.c.
865 * Returns negative errno on error, or zero on success.
867 static int pm2fb_setcolreg(unsigned regno, unsigned red, unsigned green,
868 unsigned blue, unsigned transp,
869 struct fb_info *info)
871 struct pm2fb_par *par = info->par;
873 if (regno >= info->cmap.len) /* no. of hw registers */
876 * Program hardware... do anything you want with transp
879 /* grayscale works only partially under directcolor */
880 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
881 if (info->var.grayscale)
882 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
885 * var->{color}.offset contains start of bitfield
886 * var->{color}.length contains length of bitfield
887 * {hardwarespecific} contains width of DAC
888 * cmap[X] is programmed to
889 * (X << red.offset) | (X << green.offset) | (X << blue.offset)
890 * RAMDAC[X] is programmed to (red, green, blue)
893 * uses offset = 0 && length = DAC register width.
894 * var->{color}.offset is 0
895 * var->{color}.length contains width of DAC
897 * DAC[X] is programmed to (red, green, blue)
899 * does not use RAMDAC (usually has 3 of them).
900 * var->{color}.offset contains start of bitfield
901 * var->{color}.length contains length of bitfield
902 * cmap is programmed to
903 * (red << red.offset) | (green << green.offset) |
904 * (blue << blue.offset) | (transp << transp.offset)
905 * RAMDAC does not exist
907 #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF -(val)) >> 16)
908 switch (info->fix.visual) {
909 case FB_VISUAL_TRUECOLOR:
910 case FB_VISUAL_PSEUDOCOLOR:
911 red = CNVT_TOHW(red, info->var.red.length);
912 green = CNVT_TOHW(green, info->var.green.length);
913 blue = CNVT_TOHW(blue, info->var.blue.length);
914 transp = CNVT_TOHW(transp, info->var.transp.length);
916 case FB_VISUAL_DIRECTCOLOR:
917 /* example here assumes 8 bit DAC. Might be different
918 * for your hardware */
919 red = CNVT_TOHW(red, 8);
920 green = CNVT_TOHW(green, 8);
921 blue = CNVT_TOHW(blue, 8);
922 /* hey, there is bug in transp handling... */
923 transp = CNVT_TOHW(transp, 8);
927 /* Truecolor has hardware independent palette */
928 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
934 v = (red << info->var.red.offset) |
935 (green << info->var.green.offset) |
936 (blue << info->var.blue.offset) |
937 (transp << info->var.transp.offset);
939 switch (info->var.bits_per_pixel) {
945 par->palette[regno] = v;
949 } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
950 set_color(par, regno, red, green, blue);
956 * pm2fb_pan_display - Pans the display.
957 * @var: frame buffer variable screen structure
958 * @info: frame buffer structure that represents a single frame buffer
960 * Pan (or wrap, depending on the `vmode' field) the display using the
961 * `xoffset' and `yoffset' fields of the `var' structure.
962 * If the values don't fit, return -EINVAL.
964 * Returns negative errno on error, or zero on success.
967 static int pm2fb_pan_display(struct fb_var_screeninfo *var,
968 struct fb_info *info)
970 struct pm2fb_par *p = info->par;
972 u32 depth = (info->var.bits_per_pixel + 7) & ~7;
973 u32 xres = (info->var.xres + 31) & ~31;
975 depth = (depth > 32) ? 32 : depth;
976 base = to3264(var->yoffset * xres + var->xoffset, depth, 1);
978 pm2_WR(p, PM2R_SCREEN_BASE, base);
983 * pm2fb_blank - Blanks the display.
984 * @blank_mode: the blank mode we want.
985 * @info: frame buffer structure that represents a single frame buffer
987 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
988 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
989 * video mode which doesn't support it. Implements VESA suspend
990 * and powerdown modes on hardware that supports disabling hsync/vsync:
991 * blank_mode == 2: suspend vsync
992 * blank_mode == 3: suspend hsync
993 * blank_mode == 4: powerdown
995 * Returns negative errno on error, or zero on success.
998 static int pm2fb_blank(int blank_mode, struct fb_info *info)
1000 struct pm2fb_par *par = info->par;
1001 u32 video = par->video;
1003 DPRINTK("blank_mode %d\n", blank_mode);
1005 switch (blank_mode) {
1006 case FB_BLANK_UNBLANK:
1008 video |= PM2F_VIDEO_ENABLE;
1010 case FB_BLANK_NORMAL:
1012 video &= ~PM2F_VIDEO_ENABLE;
1014 case FB_BLANK_VSYNC_SUSPEND:
1016 video &= ~(PM2F_VSYNC_MASK | PM2F_BLANK_LOW);
1018 case FB_BLANK_HSYNC_SUSPEND:
1020 video &= ~(PM2F_HSYNC_MASK | PM2F_BLANK_LOW);
1022 case FB_BLANK_POWERDOWN:
1023 /* HSync: Off, VSync: Off */
1024 video &= ~(PM2F_VSYNC_MASK | PM2F_HSYNC_MASK | PM2F_BLANK_LOW);
1027 set_video(par, video);
1031 static int pm2fb_sync(struct fb_info *info)
1033 struct pm2fb_par *par = info->par;
1036 pm2_WR(par, PM2R_SYNC, 0);
1039 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;
1158 int raster_mode = 1; /* invert bits */
1160 #ifdef __LITTLE_ENDIAN
1161 raster_mode |= 3 << 7; /* reverse byte order */
1164 if (info->state != FBINFO_STATE_RUNNING)
1166 if (info->flags & FBINFO_HWACCEL_DISABLED || image->depth != 1) {
1167 cfb_imageblit(info, image);
1170 switch (info->fix.visual) {
1171 case FB_VISUAL_PSEUDOCOLOR:
1172 fgx = image->fg_color;
1173 bgx = image->bg_color;
1175 case FB_VISUAL_TRUECOLOR:
1177 fgx = par->palette[image->fg_color];
1178 bgx = par->palette[image->bg_color];
1181 if (info->var.bits_per_pixel == 8) {
1185 if (info->var.bits_per_pixel <= 16) {
1191 pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres));
1192 pm2_WR(par, PM2R_SCISSOR_MIN_XY,
1193 ((image->dy & 0xfff) << 16) | (image->dx & 0x0fff));
1194 pm2_WR(par, PM2R_SCISSOR_MAX_XY,
1195 (((image->dy + image->height) & 0x0fff) << 16) |
1196 ((image->dx + image->width) & 0x0fff));
1197 pm2_WR(par, PM2R_SCISSOR_MODE, 1);
1198 /* GXcopy & UNIT_ENABLE */
1199 pm2_WR(par, PM2R_LOGICAL_OP_MODE, (0x3 << 1) | 1);
1200 pm2_WR(par, PM2R_RECTANGLE_ORIGIN,
1201 ((image->dy & 0xfff) << 16) | (image->dx & 0x0fff));
1202 pm2_WR(par, PM2R_RECTANGLE_SIZE,
1203 ((image->height & 0x0fff) << 16) |
1204 ((image->width) & 0x0fff));
1205 if (info->var.bits_per_pixel == 24) {
1206 pm2_WR(par, PM2R_COLOR_DDA_MODE, 1);
1208 pm2_WR(par, PM2R_CONSTANT_COLOR, bgx);
1209 pm2_WR(par, PM2R_RENDER,
1210 PM2F_RENDER_RECTANGLE |
1211 PM2F_INCREASE_X | PM2F_INCREASE_Y);
1212 /* BitMapPackEachScanline */
1213 pm2_WR(par, PM2R_RASTERIZER_MODE, raster_mode | (1 << 9));
1214 pm2_WR(par, PM2R_CONSTANT_COLOR, fgx);
1215 pm2_WR(par, PM2R_RENDER,
1216 PM2F_RENDER_RECTANGLE |
1217 PM2F_INCREASE_X | PM2F_INCREASE_Y |
1218 PM2F_RENDER_SYNC_ON_BIT_MASK);
1220 pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);
1222 pm2_WR(par, PM2R_FB_BLOCK_COLOR, bgx);
1223 pm2_WR(par, PM2R_RENDER,
1224 PM2F_RENDER_RECTANGLE |
1225 PM2F_RENDER_FASTFILL |
1226 PM2F_INCREASE_X | PM2F_INCREASE_Y);
1227 pm2_WR(par, PM2R_RASTERIZER_MODE, raster_mode);
1228 pm2_WR(par, PM2R_FB_BLOCK_COLOR, fgx);
1229 pm2_WR(par, PM2R_RENDER,
1230 PM2F_RENDER_RECTANGLE |
1231 PM2F_INCREASE_X | PM2F_INCREASE_Y |
1232 PM2F_RENDER_FASTFILL |
1233 PM2F_RENDER_SYNC_ON_BIT_MASK);
1237 int width = ((image->width + 7) >> 3)
1238 + info->pixmap.scan_align - 1;
1240 WAIT_FIFO(par, width);
1242 pm2_WR(par, PM2R_BIT_MASK_PATTERN, *src);
1247 pm2_WR(par, PM2R_RASTERIZER_MODE, 0);
1248 pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);
1249 pm2_WR(par, PM2R_SCISSOR_MODE, 0);
1253 * Hardware cursor support.
1255 static const u8 cursor_bits_lookup[16] = {
1256 0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54,
1257 0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55
1260 static int pm2vfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1262 struct pm2fb_par *par = info->par;
1263 u8 mode = PM2F_CURSORMODE_TYPE_X;
1264 int x = cursor->image.dx - info->var.xoffset;
1265 int y = cursor->image.dy - info->var.yoffset;
1268 mode |= PM2F_CURSORMODE_CURSOR_ENABLE;
1270 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_MODE, mode);
1272 if (!cursor->enable)
1273 x = 2047; /* push it outside display */
1274 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_LOW, x & 0xff);
1275 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_HIGH, (x >> 8) & 0xf);
1276 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_LOW, y & 0xff);
1277 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_HIGH, (y >> 8) & 0xf);
1280 * If the cursor is not be changed this means either we want the
1281 * current cursor state (if enable is set) or we want to query what
1282 * we can do with the cursor (if enable is not set)
1287 if (cursor->set & FB_CUR_SETHOT) {
1288 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_HOT,
1289 cursor->hot.x & 0x3f);
1290 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_HOT,
1291 cursor->hot.y & 0x3f);
1294 if (cursor->set & FB_CUR_SETCMAP) {
1295 u32 fg_idx = cursor->image.fg_color;
1296 u32 bg_idx = cursor->image.bg_color;
1297 struct fb_cmap cmap = info->cmap;
1299 /* the X11 driver says one should use these color registers */
1300 pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CURSOR_PALETTE >> 8);
1301 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 0,
1302 cmap.red[bg_idx] >> 8 );
1303 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 1,
1304 cmap.green[bg_idx] >> 8 );
1305 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 2,
1306 cmap.blue[bg_idx] >> 8 );
1308 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 3,
1309 cmap.red[fg_idx] >> 8 );
1310 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 4,
1311 cmap.green[fg_idx] >> 8 );
1312 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 5,
1313 cmap.blue[fg_idx] >> 8 );
1314 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
1317 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1318 u8 *bitmap = (u8 *)cursor->image.data;
1319 u8 *mask = (u8 *)cursor->mask;
1321 int pos = PM2VI_RD_CURSOR_PATTERN;
1323 for (i = 0; i < cursor->image.height; i++) {
1324 int j = (cursor->image.width + 7) >> 3;
1327 pm2_WR(par, PM2VR_RD_INDEX_HIGH, pos >> 8);
1329 for (; j > 0; j--) {
1330 u8 data = *bitmap ^ *mask;
1332 if (cursor->rop == ROP_COPY)
1333 data = *mask & *bitmap;
1334 /* Upper 4 bits of bitmap data */
1335 pm2v_RDAC_WR(par, pos++,
1336 cursor_bits_lookup[data >> 4] |
1337 (cursor_bits_lookup[*mask >> 4] << 1));
1338 /* Lower 4 bits of bitmap */
1339 pm2v_RDAC_WR(par, pos++,
1340 cursor_bits_lookup[data & 0xf] |
1341 (cursor_bits_lookup[*mask & 0xf] << 1));
1345 for (; k > 0; k--) {
1346 pm2v_RDAC_WR(par, pos++, 0);
1347 pm2v_RDAC_WR(par, pos++, 0);
1351 while (pos < (1024 + PM2VI_RD_CURSOR_PATTERN)) {
1352 pm2_WR(par, PM2VR_RD_INDEX_HIGH, pos >> 8);
1353 pm2v_RDAC_WR(par, pos++, 0);
1356 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
1361 static int pm2fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1363 struct pm2fb_par *par = info->par;
1367 return -EINVAL; /* just to force soft_cursor() call */
1369 /* Too large of a cursor or wrong bpp :-( */
1370 if (cursor->image.width > 64 ||
1371 cursor->image.height > 64 ||
1372 cursor->image.depth > 1)
1375 if (par->type == PM2_TYPE_PERMEDIA2V)
1376 return pm2vfb_cursor(info, cursor);
1382 pm2_RDAC_WR(par, PM2I_RD_CURSOR_CONTROL, mode);
1385 * If the cursor is not be changed this means either we want the
1386 * current cursor state (if enable is set) or we want to query what
1387 * we can do with the cursor (if enable is not set)
1392 if (cursor->set & FB_CUR_SETPOS) {
1393 int x = cursor->image.dx - info->var.xoffset + 63;
1394 int y = cursor->image.dy - info->var.yoffset + 63;
1397 pm2_WR(par, PM2R_RD_CURSOR_X_LSB, x & 0xff);
1398 pm2_WR(par, PM2R_RD_CURSOR_X_MSB, (x >> 8) & 0x7);
1399 pm2_WR(par, PM2R_RD_CURSOR_Y_LSB, y & 0xff);
1400 pm2_WR(par, PM2R_RD_CURSOR_Y_MSB, (y >> 8) & 0x7);
1403 if (cursor->set & FB_CUR_SETCMAP) {
1404 u32 fg_idx = cursor->image.fg_color;
1405 u32 bg_idx = cursor->image.bg_color;
1408 pm2_WR(par, PM2R_RD_CURSOR_COLOR_ADDRESS, 1);
1409 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1410 info->cmap.red[bg_idx] >> 8);
1411 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1412 info->cmap.green[bg_idx] >> 8);
1413 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1414 info->cmap.blue[bg_idx] >> 8);
1416 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1417 info->cmap.red[fg_idx] >> 8);
1418 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1419 info->cmap.green[fg_idx] >> 8);
1420 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1421 info->cmap.blue[fg_idx] >> 8);
1424 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1425 u8 *bitmap = (u8 *)cursor->image.data;
1426 u8 *mask = (u8 *)cursor->mask;
1430 pm2_WR(par, PM2R_RD_PALETTE_WRITE_ADDRESS, 0);
1432 for (i = 0; i < cursor->image.height; i++) {
1433 int j = (cursor->image.width + 7) >> 3;
1437 for (; j > 0; j--) {
1438 u8 data = *bitmap ^ *mask;
1440 if (cursor->rop == ROP_COPY)
1441 data = *mask & *bitmap;
1443 pm2_WR(par, PM2R_RD_CURSOR_DATA, data);
1448 pm2_WR(par, PM2R_RD_CURSOR_DATA, 0);
1450 for (; i < 64; i++) {
1454 pm2_WR(par, PM2R_RD_CURSOR_DATA, 0);
1457 mask = (u8 *)cursor->mask;
1458 for (i = 0; i < cursor->image.height; i++) {
1459 int j = (cursor->image.width + 7) >> 3;
1463 for (; j > 0; j--) {
1465 pm2_WR(par, PM2R_RD_CURSOR_DATA, *mask);
1469 pm2_WR(par, PM2R_RD_CURSOR_DATA, 0);
1471 for (; i < 64; i++) {
1475 pm2_WR(par, PM2R_RD_CURSOR_DATA, 0);
1481 /* ------------ Hardware Independent Functions ------------ */
1484 * Frame buffer operations
1487 static const struct fb_ops pm2fb_ops = {
1488 .owner = THIS_MODULE,
1489 .fb_check_var = pm2fb_check_var,
1490 .fb_set_par = pm2fb_set_par,
1491 .fb_setcolreg = pm2fb_setcolreg,
1492 .fb_blank = pm2fb_blank,
1493 .fb_pan_display = pm2fb_pan_display,
1494 .fb_fillrect = pm2fb_fillrect,
1495 .fb_copyarea = pm2fb_copyarea,
1496 .fb_imageblit = pm2fb_imageblit,
1497 .fb_sync = pm2fb_sync,
1498 .fb_cursor = pm2fb_cursor,
1507 * Device initialisation
1509 * Initialise and allocate resource for PCI device.
1511 * @param pdev PCI device.
1512 * @param id PCI device ID.
1514 static int pm2fb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1516 struct pm2fb_par *default_par;
1517 struct fb_info *info;
1519 int retval = -ENXIO;
1521 err = pci_enable_device(pdev);
1523 printk(KERN_WARNING "pm2fb: Can't enable pdev: %d\n", err);
1527 info = framebuffer_alloc(sizeof(struct pm2fb_par), &pdev->dev);
1530 default_par = info->par;
1532 switch (pdev->device) {
1533 case PCI_DEVICE_ID_TI_TVP4020:
1534 strcpy(pm2fb_fix.id, "TVP4020");
1535 default_par->type = PM2_TYPE_PERMEDIA2;
1537 case PCI_DEVICE_ID_3DLABS_PERMEDIA2:
1538 strcpy(pm2fb_fix.id, "Permedia2");
1539 default_par->type = PM2_TYPE_PERMEDIA2;
1541 case PCI_DEVICE_ID_3DLABS_PERMEDIA2V:
1542 strcpy(pm2fb_fix.id, "Permedia2v");
1543 default_par->type = PM2_TYPE_PERMEDIA2V;
1547 pm2fb_fix.mmio_start = pci_resource_start(pdev, 0);
1548 pm2fb_fix.mmio_len = PM2_REGS_SIZE;
1550 #if defined(__BIG_ENDIAN)
1552 * PM2 has a 64k register file, mapped twice in 128k. Lower
1553 * map is little-endian, upper map is big-endian.
1555 pm2fb_fix.mmio_start += PM2_REGS_SIZE;
1556 DPRINTK("Adjusting register base for big-endian.\n");
1558 DPRINTK("Register base at 0x%lx\n", pm2fb_fix.mmio_start);
1560 /* Registers - request region and map it. */
1561 if (!request_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len,
1563 printk(KERN_WARNING "pm2fb: Can't reserve regbase.\n");
1564 goto err_exit_neither;
1566 default_par->v_regs =
1567 ioremap(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
1568 if (!default_par->v_regs) {
1569 printk(KERN_WARNING "pm2fb: Can't remap %s register area.\n",
1571 release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
1572 goto err_exit_neither;
1575 /* Stash away memory register info for use when we reset the board */
1576 default_par->mem_control = pm2_RD(default_par, PM2R_MEM_CONTROL);
1577 default_par->boot_address = pm2_RD(default_par, PM2R_BOOT_ADDRESS);
1578 default_par->mem_config = pm2_RD(default_par, PM2R_MEM_CONFIG);
1579 DPRINTK("MemControl 0x%x BootAddress 0x%x MemConfig 0x%x\n",
1580 default_par->mem_control, default_par->boot_address,
1581 default_par->mem_config);
1583 if (default_par->mem_control == 0 &&
1584 default_par->boot_address == 0x31 &&
1585 default_par->mem_config == 0x259fffff) {
1586 default_par->memclock = CVPPC_MEMCLOCK;
1587 default_par->mem_control = 0;
1588 default_par->boot_address = 0x20;
1589 default_par->mem_config = 0xe6002021;
1590 if (pdev->subsystem_vendor == 0x1048 &&
1591 pdev->subsystem_device == 0x0a31) {
1592 DPRINTK("subsystem_vendor: %04x, "
1593 "subsystem_device: %04x\n",
1594 pdev->subsystem_vendor, pdev->subsystem_device);
1595 DPRINTK("We have not been initialized by VGA BIOS and "
1596 "are running on an Elsa Winner 2000 Office\n");
1597 DPRINTK("Initializing card timings manually...\n");
1598 default_par->memclock = 100000;
1600 if (pdev->subsystem_vendor == 0x3d3d &&
1601 pdev->subsystem_device == 0x0100) {
1602 DPRINTK("subsystem_vendor: %04x, "
1603 "subsystem_device: %04x\n",
1604 pdev->subsystem_vendor, pdev->subsystem_device);
1605 DPRINTK("We have not been initialized by VGA BIOS and "
1606 "are running on an 3dlabs reference board\n");
1607 DPRINTK("Initializing card timings manually...\n");
1608 default_par->memclock = 74894;
1612 /* Now work out how big lfb is going to be. */
1613 switch (default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) {
1614 case PM2F_MEM_BANKS_1:
1615 pm2fb_fix.smem_len = 0x200000;
1617 case PM2F_MEM_BANKS_2:
1618 pm2fb_fix.smem_len = 0x400000;
1620 case PM2F_MEM_BANKS_3:
1621 pm2fb_fix.smem_len = 0x600000;
1623 case PM2F_MEM_BANKS_4:
1624 pm2fb_fix.smem_len = 0x800000;
1627 pm2fb_fix.smem_start = pci_resource_start(pdev, 1);
1629 /* Linear frame buffer - request region and map it. */
1630 if (!request_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len,
1632 printk(KERN_WARNING "pm2fb: Can't reserve smem.\n");
1636 ioremap_wc(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
1637 if (!info->screen_base) {
1638 printk(KERN_WARNING "pm2fb: Can't ioremap smem area.\n");
1639 release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
1644 default_par->wc_cookie = arch_phys_wc_add(pm2fb_fix.smem_start,
1645 pm2fb_fix.smem_len);
1647 info->fbops = &pm2fb_ops;
1648 info->fix = pm2fb_fix;
1649 info->pseudo_palette = default_par->palette;
1650 info->flags = FBINFO_DEFAULT |
1651 FBINFO_HWACCEL_YPAN |
1652 FBINFO_HWACCEL_COPYAREA |
1653 FBINFO_HWACCEL_IMAGEBLIT |
1654 FBINFO_HWACCEL_FILLRECT;
1656 info->pixmap.addr = kmalloc(PM2_PIXMAP_SIZE, GFP_KERNEL);
1657 if (!info->pixmap.addr) {
1659 goto err_exit_pixmap;
1661 info->pixmap.size = PM2_PIXMAP_SIZE;
1662 info->pixmap.buf_align = 4;
1663 info->pixmap.scan_align = 4;
1664 info->pixmap.access_align = 32;
1665 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1668 printk(KERN_DEBUG "disabling acceleration\n");
1669 info->flags |= FBINFO_HWACCEL_DISABLED;
1670 info->pixmap.scan_align = 1;
1674 mode_option = "640x480@60";
1676 err = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
1677 if (!err || err == 4)
1678 info->var = pm2fb_var;
1680 retval = fb_alloc_cmap(&info->cmap, 256, 0);
1684 retval = register_framebuffer(info);
1688 fb_info(info, "%s frame buffer device, memory = %dK\n",
1689 info->fix.id, pm2fb_fix.smem_len / 1024);
1694 pci_set_drvdata(pdev, info);
1699 fb_dealloc_cmap(&info->cmap);
1701 kfree(info->pixmap.addr);
1703 iounmap(info->screen_base);
1704 release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
1706 iounmap(default_par->v_regs);
1707 release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
1709 framebuffer_release(info);
1716 * Release all device resources.
1718 * @param pdev PCI device to clean up.
1720 static void pm2fb_remove(struct pci_dev *pdev)
1722 struct fb_info *info = pci_get_drvdata(pdev);
1723 struct fb_fix_screeninfo *fix = &info->fix;
1724 struct pm2fb_par *par = info->par;
1726 unregister_framebuffer(info);
1727 arch_phys_wc_del(par->wc_cookie);
1728 iounmap(info->screen_base);
1729 release_mem_region(fix->smem_start, fix->smem_len);
1730 iounmap(par->v_regs);
1731 release_mem_region(fix->mmio_start, fix->mmio_len);
1733 fb_dealloc_cmap(&info->cmap);
1734 kfree(info->pixmap.addr);
1735 framebuffer_release(info);
1738 static const struct pci_device_id pm2fb_id_table[] = {
1739 { PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TVP4020,
1740 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1741 { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2,
1742 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1743 { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V,
1744 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1748 static struct pci_driver pm2fb_driver = {
1750 .id_table = pm2fb_id_table,
1751 .probe = pm2fb_probe,
1752 .remove = pm2fb_remove,
1755 MODULE_DEVICE_TABLE(pci, pm2fb_id_table);
1760 * Parse user specified options.
1762 * This is, comma-separated options following `video=pm2fb:'.
1764 static int __init pm2fb_setup(char *options)
1768 if (!options || !*options)
1771 while ((this_opt = strsep(&options, ",")) != NULL) {
1774 if (!strcmp(this_opt, "lowhsync"))
1776 else if (!strcmp(this_opt, "lowvsync"))
1778 else if (!strncmp(this_opt, "hwcursor=", 9))
1779 hwcursor = simple_strtoul(this_opt + 9, NULL, 0);
1780 else if (!strncmp(this_opt, "nomtrr", 6))
1782 else if (!strncmp(this_opt, "noaccel", 7))
1785 mode_option = this_opt;
1792 static int __init pm2fb_init(void)
1795 char *option = NULL;
1797 if (fb_get_options("pm2fb", &option))
1799 pm2fb_setup(option);
1802 return pci_register_driver(&pm2fb_driver);
1805 module_init(pm2fb_init);
1812 static void __exit pm2fb_exit(void)
1814 pci_unregister_driver(&pm2fb_driver);
1819 module_exit(pm2fb_exit);
1821 module_param(mode_option, charp, 0);
1822 MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
1823 module_param_named(mode, mode_option, charp, 0);
1824 MODULE_PARM_DESC(mode, "Initial video mode e.g. '648x480-8@60' (deprecated)");
1825 module_param(lowhsync, bool, 0);
1826 MODULE_PARM_DESC(lowhsync, "Force horizontal sync low regardless of mode");
1827 module_param(lowvsync, bool, 0);
1828 MODULE_PARM_DESC(lowvsync, "Force vertical sync low regardless of mode");
1829 module_param(noaccel, bool, 0);
1830 MODULE_PARM_DESC(noaccel, "Disable acceleration");
1831 module_param(hwcursor, int, 0644);
1832 MODULE_PARM_DESC(hwcursor, "Enable hardware cursor "
1833 "(1=enable, 0=disable, default=1)");
1834 module_param(nomtrr, bool, 0);
1835 MODULE_PARM_DESC(nomtrr, "Disable MTRR support (0 or 1=disabled) (default=0)");
1837 MODULE_AUTHOR("Jim Hague <jim.hague@acm.org>");
1838 MODULE_DESCRIPTION("Permedia2 framebuffer device driver");
1839 MODULE_LICENSE("GPL");