1fcb1fec7fece6b9889deaedf5b7d21f4f5a26381Paul Mundt/* 2fcb1fec7fece6b9889deaedf5b7d21f4f5a26381Paul Mundt * drivers/video/pvr2fb.c 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Frame buffer and fbcon support for the NEC PowerVR2 found within the Sega 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Dreamcast. 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (c) 2001 M. R. Brown <mrbrown@0xd6.org> 8fcb1fec7fece6b9889deaedf5b7d21f4f5a26381Paul Mundt * Copyright (c) 2001 - 2008 Paul Mundt <lethal@linux-sh.org> 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This driver is mostly based on the excellent amifb and vfb sources. It uses 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * an odd scheme for converting hardware values to/from framebuffer values, 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * here are some hacked-up formulas: 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The Dreamcast has screen offsets from each side of its four borders and 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the start offsets of the display window. I used these values to calculate 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 'pseudo' values (think of them as placeholders) for the fb video mode, so 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * that when it came time to convert these values back into their hardware 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * values, I could just add mode- specific offsets to get the correct mode 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * settings: 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * left_margin = diwstart_h - borderstart_h; 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * right_margin = borderstop_h - (diwstart_h + xres); 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * upper_margin = diwstart_v - borderstart_v; 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * lower_margin = borderstop_v - (diwstart_h + yres); 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * hsync_len = borderstart_h + (hsync_total - borderstop_h); 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * vsync_len = borderstart_v + (vsync_total - borderstop_v); 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Then, when it's time to convert back to hardware settings, the only 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * constants are the borderstart_* offsets, all other values are derived from 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the fb video mode: 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * // PAL 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * borderstart_h = 116; 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * borderstart_v = 44; 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ... 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * borderstop_h = borderstart_h + hsync_total - hsync_len; 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ... 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * diwstart_v = borderstart_v - upper_margin; 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * However, in the current implementation, the borderstart values haven't had 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the benefit of being fully researched, so some modes may be broken. 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef DEBUG 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h> 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/kernel.h> 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/errno.h> 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/string.h> 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/mm.h> 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/slab.h> 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/delay.h> 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/interrupt.h> 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/fb.h> 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h> 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/pci.h> 581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_SH_DREAMCAST 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/machvec.h> 610764bff445bb13cd17e41b6ab196ef83c23c6c17Paul Mundt#include <mach-dreamcast/mach/sysasic.h> 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 64da62e71d13ad0b76011491e36cb58999c464516aPaul Mundt#ifdef CONFIG_PVR2_DMA 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/pagemap.h> 660764bff445bb13cd17e41b6ab196ef83c23c6c17Paul Mundt#include <mach/dma.h> 671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/dma.h> 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_SH_STORE_QUEUES 7184902b7af642c86a518c17629c0dbe705a4b6d14Krzysztof Helt#include <linux/uaccess.h> 720764bff445bb13cd17e41b6ab196ef83c23c6c17Paul Mundt#include <cpu/sq.h> 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef PCI_DEVICE_ID_NEC_NEON250 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds# define PCI_DEVICE_ID_NEC_NEON250 0x0067 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 2D video registers */ 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_BASE par->mmio_base 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_BRDRCOLR (DISP_BASE + 0x40) 821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_DIWMODE (DISP_BASE + 0x44) 831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_DIWADDRL (DISP_BASE + 0x50) 841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_DIWADDRS (DISP_BASE + 0x54) 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_DIWSIZE (DISP_BASE + 0x5c) 861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_SYNCCONF (DISP_BASE + 0xd0) 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_BRDRHORZ (DISP_BASE + 0xd4) 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_SYNCSIZE (DISP_BASE + 0xd8) 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_BRDRVERT (DISP_BASE + 0xdc) 901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_DIWCONF (DISP_BASE + 0xe8) 911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_DIWHSTRT (DISP_BASE + 0xec) 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISP_DIWVSTRT (DISP_BASE + 0xf0) 93306c869c237a66fe85580f60558f105e3305d465Adrian McMenamin#define DISP_PIXDEPTH (DISP_BASE + 0x108) 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Pixel clocks, one for TV output, doubled for VGA output */ 961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define TV_CLK 74239 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define VGA_CLK 37119 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* This is for 60Hz - the VTOTAL is doubled for interlaced modes */ 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define PAL_HTOTAL 863 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define PAL_VTOTAL 312 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NTSC_HTOTAL 857 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NTSC_VTOTAL 262 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Supported cable types */ 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsenum { CT_VGA, CT_NONE, CT_RGB, CT_COMPOSITE }; 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Supported video output types */ 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsenum { VO_PAL, VO_NTSC, VO_VGA }; 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Supported palette types */ 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsenum { PAL_ARGB1555, PAL_RGB565, PAL_ARGB4444, PAL_ARGB8888 }; 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct pvr2_params { unsigned int val; char *name; }; 1157e7ec0d4ae57b258fed5ee29e9d007282898625aPaul Mundtstatic struct pvr2_params cables[] __devinitdata = { 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { CT_VGA, "VGA" }, { CT_RGB, "RGB" }, { CT_COMPOSITE, "COMPOSITE" }, 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1197e7ec0d4ae57b258fed5ee29e9d007282898625aPaul Mundtstatic struct pvr2_params outputs[] __devinitdata = { 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { VO_PAL, "PAL" }, { VO_NTSC, "NTSC" }, { VO_VGA, "VGA" }, 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This describes the current video mode 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct pvr2fb_par { 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int hsync_total; /* Clocks/line */ 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int vsync_total; /* Lines/field */ 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int borderstart_h; 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int borderstop_h; 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int borderstart_v; 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int borderstop_v; 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int diwstart_h; /* Horizontal offset of the display field */ 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int diwstart_v; /* Vertical offset of the display field, for 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds interlaced modes, this is the long field */ 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long disp_start; /* Address of image within VRAM */ 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned char is_interlaced; /* Is the display interlaced? */ 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned char is_doublescan; /* Are scanlines output twice? (doublescan) */ 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned char is_lowres; /* Is horizontal pixel-doubling enabled? */ 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long mmio_base; /* MMIO base */ 1439cd1c67434544b1d9a4fb4a4cdec15608167a233Antonino A. Daplas u32 palette[16]; 1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} *currentpar; 1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct fb_info *fb_info; 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 148e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundtstatic struct fb_fix_screeninfo pvr2_fix __devinitdata = { 1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .id = "NEC PowerVR2", 150e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt .type = FB_TYPE_PACKED_PIXELS, 151e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt .visual = FB_VISUAL_TRUECOLOR, 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .ypanstep = 1, 1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .ywrapstep = 1, 154e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt .accel = FB_ACCEL_NONE, 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 157e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundtstatic struct fb_var_screeninfo pvr2_var __devinitdata = { 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .xres = 640, 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .yres = 480, 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .xres_virtual = 640, 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .yres_virtual = 480, 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .bits_per_pixel =16, 1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .red = { 11, 5, 0 }, 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .green = { 5, 6, 0 }, 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .blue = { 0, 5, 0 }, 1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .activate = FB_ACTIVATE_NOW, 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .height = -1, 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .width = -1, 1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .vmode = FB_VMODE_NONINTERLACED, 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int cable_type = CT_VGA; 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int video_output = VO_VGA; 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int nopan = 0; 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int nowrap = 1; 1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * We do all updating, blanking, etc. during the vertical retrace period 1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic unsigned int do_vmode_full = 0; /* Change the video mode */ 1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic unsigned int do_vmode_pan = 0; /* Update the video mode */ 1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic short do_blank = 0; /* (Un)Blank the screen */ 1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic unsigned int is_blanked = 0; /* Is the screen blanked? */ 1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_SH_STORE_QUEUES 188d2b06a8b17f96b75fa1e8e7765cb900c99fd80fbPaul Mundtstatic unsigned long pvr2fb_map; 1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 191da62e71d13ad0b76011491e36cb58999c464516aPaul Mundt#ifdef CONFIG_PVR2_DMA 1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic unsigned int shdma = PVR2_CASCADE_CHAN; 1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic unsigned int pvr2dma = ONCHIP_NR_DMA_CHANNELS; 1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2fb_setcolreg(unsigned int regno, unsigned int red, unsigned int green, unsigned int blue, 1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int transp, struct fb_info *info); 1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2fb_blank(int blank, struct fb_info *info); 1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic unsigned long get_line_length(int xres_virtual, int bpp); 2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void set_color_bitfields(struct fb_var_screeninfo *var); 2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info); 2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2fb_set_par(struct fb_info *info); 2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void pvr2_update_display(struct fb_info *info); 2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void pvr2_init_display(struct fb_info *info); 2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void pvr2_do_blank(void); 2067d12e780e003f93433d49ce78cfedf4b4c52adc5David Howellsstatic irqreturn_t pvr2fb_interrupt(int irq, void *dev_id); 2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2_init_cable(void); 2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2_get_param(const struct pvr2_params *p, const char *s, 2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int val, int size); 210da62e71d13ad0b76011491e36cb58999c464516aPaul Mundt#ifdef CONFIG_PVR2_DMA 2113f9b0880e4a96b02bc0131451f2f6231cd90bd94Antonino A. Daplasstatic ssize_t pvr2fb_write(struct fb_info *info, const char *buf, 2121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t count, loff_t *ppos); 213d2b06a8b17f96b75fa1e8e7765cb900c99fd80fbPaul Mundt#endif 2141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct fb_ops pvr2fb_ops = { 216d2b06a8b17f96b75fa1e8e7765cb900c99fd80fbPaul Mundt .owner = THIS_MODULE, 217d2b06a8b17f96b75fa1e8e7765cb900c99fd80fbPaul Mundt .fb_setcolreg = pvr2fb_setcolreg, 218d2b06a8b17f96b75fa1e8e7765cb900c99fd80fbPaul Mundt .fb_blank = pvr2fb_blank, 219d2b06a8b17f96b75fa1e8e7765cb900c99fd80fbPaul Mundt .fb_check_var = pvr2fb_check_var, 220d2b06a8b17f96b75fa1e8e7765cb900c99fd80fbPaul Mundt .fb_set_par = pvr2fb_set_par, 221da62e71d13ad0b76011491e36cb58999c464516aPaul Mundt#ifdef CONFIG_PVR2_DMA 2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .fb_write = pvr2fb_write, 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 224e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt .fb_fillrect = cfb_fillrect, 2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .fb_copyarea = cfb_copyarea, 2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .fb_imageblit = cfb_imageblit, 2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2297e7ec0d4ae57b258fed5ee29e9d007282898625aPaul Mundtstatic struct fb_videomode pvr2_modedb[] __devinitdata = { 2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Broadcast video modes (PAL and NTSC). I'm unfamiliar with 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PAL-M and PAL-N, but from what I've read both modes parallel PAL and 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * NTSC, so it shouldn't be a problem (I hope). 2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 640x480 @ 60Hz interlaced (NTSC) */ 2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "ntsc_640x480i", 60, 640, 480, TV_CLK, 38, 33, 0, 18, 146, 26, 2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds FB_SYNC_BROADCAST, FB_VMODE_INTERLACED | FB_VMODE_YWRAP 2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds }, { 2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 640x240 @ 60Hz (NTSC) */ 2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* XXX: Broken! Don't use... */ 2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "ntsc_640x240", 60, 640, 240, TV_CLK, 38, 33, 0, 0, 146, 22, 2441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds FB_SYNC_BROADCAST, FB_VMODE_YWRAP 2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds }, { 2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 640x480 @ 60hz (VGA) */ 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "vga_640x480", 60, 640, 480, VGA_CLK, 38, 33, 0, 18, 146, 26, 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 0, FB_VMODE_YWRAP 249e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt }, 2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NUM_TOTAL_MODES ARRAY_SIZE(pvr2_modedb) 2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEFMODE_NTSC 0 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEFMODE_PAL 0 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEFMODE_VGA 2 2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int defmode = DEFMODE_NTSC; 2597e7ec0d4ae57b258fed5ee29e9d007282898625aPaul Mundtstatic char *mode_option __devinitdata = NULL; 2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void pvr2fb_set_pal_type(unsigned int type) 2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pvr2fb_par *par = (struct pvr2fb_par *)fb_info->par; 2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(type, par->mmio_base + 0x108); 2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void pvr2fb_set_pal_entry(struct pvr2fb_par *par, 2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int regno, 2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int val) 2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(val, par->mmio_base + 0x1000 + (4 * regno)); 2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2fb_blank(int blank, struct fb_info *info) 2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds do_blank = blank ? blank : -1; 2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline unsigned long get_line_length(int xres_virtual, int bpp) 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (unsigned long)((((xres_virtual*bpp)+31)&~31) >> 3); 2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void set_color_bitfields(struct fb_var_screeninfo *var) 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (var->bits_per_pixel) { 2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case 16: /* RGB 565 */ 290e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt pvr2fb_set_pal_type(PAL_RGB565); 2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->red.offset = 11; var->red.length = 5; 2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->green.offset = 5; var->green.length = 6; 2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->blue.offset = 0; var->blue.length = 5; 2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->transp.offset = 0; var->transp.length = 0; 2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case 24: /* RGB 888 */ 2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->red.offset = 16; var->red.length = 8; 2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->green.offset = 8; var->green.length = 8; 2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->blue.offset = 0; var->blue.length = 8; 3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->transp.offset = 0; var->transp.length = 0; 3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case 32: /* ARGB 8888 */ 303e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt pvr2fb_set_pal_type(PAL_ARGB8888); 3041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->red.offset = 16; var->red.length = 8; 3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->green.offset = 8; var->green.length = 8; 3061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->blue.offset = 0; var->blue.length = 8; 3071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->transp.offset = 24; var->transp.length = 8; 3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2fb_setcolreg(unsigned int regno, unsigned int red, 3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int green, unsigned int blue, 3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int transp, struct fb_info *info) 3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pvr2fb_par *par = (struct pvr2fb_par *)info->par; 3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int tmp; 3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (regno > info->cmap.len) 3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 1; 3211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 3231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * We only support the hardware palette for 16 and 32bpp. It's also 3241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * expected that the palette format has been set by the time we get 3251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * here, so we don't waste time setting it again. 3261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (info->var.bits_per_pixel) { 3281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case 16: /* RGB 565 */ 3291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds tmp = (red & 0xf800) | 3301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ((green & 0xfc00) >> 5) | 3311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ((blue & 0xf800) >> 11); 3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2fb_set_pal_entry(par, regno, tmp); 3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 3351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case 24: /* RGB 888 */ 3361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds red >>= 8; green >>= 8; blue >>= 8; 337a66ad56eb2c9644717da4d7f05f971d6786145e3Antonino A. Daplas tmp = (red << 16) | (green << 8) | blue; 3381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 3391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case 32: /* ARGB 8888 */ 3401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds red >>= 8; green >>= 8; blue >>= 8; 3411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds tmp = (transp << 24) | (red << 16) | (green << 8) | blue; 3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2fb_set_pal_entry(par, regno, tmp); 3441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 3451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds default: 3461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pr_debug("Invalid bit depth %d?!?\n", info->var.bits_per_pixel); 3471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 1; 3481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 350a66ad56eb2c9644717da4d7f05f971d6786145e3Antonino A. Daplas if (regno < 16) 351a66ad56eb2c9644717da4d7f05f971d6786145e3Antonino A. Daplas ((u32*)(info->pseudo_palette))[regno] = tmp; 352a66ad56eb2c9644717da4d7f05f971d6786145e3Antonino A. Daplas 3531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 3541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2fb_set_par(struct fb_info *info) 3571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pvr2fb_par *par = (struct pvr2fb_par *)info->par; 3591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fb_var_screeninfo *var = &info->var; 3601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long line_length; 3611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int vtotal; 3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 3641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * XXX: It's possible that a user could use a VGA box, change the cable 3651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * type in hardware (i.e. switch from VGA<->composite), then change 3661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * modes (i.e. switching to another VT). If that happens we should 3671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * automagically change the output format to cope, but currently I 3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * don't have a VGA box to make sure this works properly. 3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds cable_type = pvr2_init_cable(); 3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (cable_type == CT_VGA && video_output != VO_VGA) 3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds video_output = VO_VGA; 3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->vmode &= FB_VMODE_MASK; 3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->vmode & FB_VMODE_INTERLACED && video_output != VO_VGA) 3761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->is_interlaced = 1; 377e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt /* 3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * XXX: Need to be more creative with this (i.e. allow doublecan for 3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PAL/NTSC output). 3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->vmode & FB_VMODE_DOUBLE && video_output == VO_VGA) 3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->is_doublescan = 1; 383e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt 3841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->hsync_total = var->left_margin + var->xres + var->right_margin + 3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->hsync_len; 3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->vsync_total = var->upper_margin + var->yres + var->lower_margin + 3871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->vsync_len; 3881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->sync & FB_SYNC_BROADCAST) { 3901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds vtotal = par->vsync_total; 3911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (par->is_interlaced) 3921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds vtotal /= 2; 3931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (vtotal > (PAL_VTOTAL + NTSC_VTOTAL)/2) { 3941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* XXX: Check for start values here... */ 3951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* XXX: Check hardware for PAL-compatibility */ 3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->borderstart_h = 116; 3971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->borderstart_v = 44; 3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 3991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* NTSC video output */ 4001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->borderstart_h = 126; 4011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->borderstart_v = 18; 4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* VGA mode */ 4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* XXX: What else needs to be checked? */ 406e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt /* 4071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * XXX: We have a little freedom in VGA modes, what ranges 4081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * should be here (i.e. hsync/vsync totals, etc.)? 4091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 4101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->borderstart_h = 126; 4111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->borderstart_v = 40; 4121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Calculate the remainding offsets */ 4151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->diwstart_h = par->borderstart_h + var->left_margin; 4161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->diwstart_v = par->borderstart_v + var->upper_margin; 417e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt par->borderstop_h = par->diwstart_h + var->xres + 418e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt var->right_margin; 4191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->borderstop_v = par->diwstart_v + var->yres + 4201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->lower_margin; 4211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!par->is_interlaced) 4231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->borderstop_v /= 2; 4241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (info->var.xres < 640) 4251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->is_lowres = 1; 4261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds line_length = get_line_length(var->xres_virtual, var->bits_per_pixel); 4281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->disp_start = info->fix.smem_start + (line_length * var->yoffset) * line_length; 4291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds info->fix.line_length = line_length; 4301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 4311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 4321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 4341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pvr2fb_par *par = (struct pvr2fb_par *)info->par; 4361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int vtotal, hsync_total; 4371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long line_length; 4381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->pixclock != TV_CLK && var->pixclock != VGA_CLK) { 4401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pr_debug("Invalid pixclock value %d\n", var->pixclock); 4411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; 4421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->xres < 320) 4451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->xres = 320; 4461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->yres < 240) 4471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->yres = 240; 4481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->xres_virtual < var->xres) 4491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->xres_virtual = var->xres; 4501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->yres_virtual < var->yres) 4511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->yres_virtual = var->yres; 4521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->bits_per_pixel <= 16) 4541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->bits_per_pixel = 16; 4551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else if (var->bits_per_pixel <= 24) 4561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->bits_per_pixel = 24; 4571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else if (var->bits_per_pixel <= 32) 4581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->bits_per_pixel = 32; 4591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds set_color_bitfields(var); 4611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->vmode & FB_VMODE_YWRAP) { 463e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt if (var->xoffset || var->yoffset < 0 || 4641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->yoffset >= var->yres_virtual) { 4651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->xoffset = var->yoffset = 0; 4661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 4671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->xoffset > var->xres_virtual - var->xres || 468e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt var->yoffset > var->yres_virtual - var->yres || 4691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->xoffset < 0 || var->yoffset < 0) 4701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->xoffset = var->yoffset = 0; 4711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 4731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->xoffset = var->yoffset = 0; 4741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 476e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt /* 4771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * XXX: Need to be more creative with this (i.e. allow doublecan for 4781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PAL/NTSC output). 4791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 4801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->yres < 480 && video_output == VO_VGA) 4811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->vmode |= FB_VMODE_DOUBLE; 4821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (video_output != VO_VGA) { 4841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->sync |= FB_SYNC_BROADCAST; 4851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->vmode |= FB_VMODE_INTERLACED; 4861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 4871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->sync &= ~FB_SYNC_BROADCAST; 4881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->vmode &= ~FB_VMODE_INTERLACED; 489fcb1fec7fece6b9889deaedf5b7d21f4f5a26381Paul Mundt var->vmode |= FB_VMODE_NONINTERLACED; 4901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((var->activate & FB_ACTIVATE_MASK) != FB_ACTIVATE_TEST) { 4931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->right_margin = par->borderstop_h - 4941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (par->diwstart_h + var->xres); 4951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->left_margin = par->diwstart_h - par->borderstart_h; 4961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->hsync_len = par->borderstart_h + 4971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (par->hsync_total - par->borderstop_h); 4981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->upper_margin = par->diwstart_v - par->borderstart_v; 5001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->lower_margin = par->borderstop_v - 5011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (par->diwstart_v + var->yres); 5021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->vsync_len = par->borderstop_v + 5031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (par->vsync_total - par->borderstop_v); 5041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 505e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt 5061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds hsync_total = var->left_margin + var->xres + var->right_margin + 5071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->hsync_len; 5081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds vtotal = var->upper_margin + var->yres + var->lower_margin + 5091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds var->vsync_len; 5101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->sync & FB_SYNC_BROADCAST) { 5121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (var->vmode & FB_VMODE_INTERLACED) 5131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds vtotal /= 2; 5141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (vtotal > (PAL_VTOTAL + NTSC_VTOTAL)/2) { 5151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* PAL video output */ 5161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* XXX: Should be using a range here ... ? */ 5171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (hsync_total != PAL_HTOTAL) { 5181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pr_debug("invalid hsync total for PAL\n"); 5191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; 5201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 5221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* NTSC video output */ 5231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (hsync_total != NTSC_HTOTAL) { 5241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pr_debug("invalid hsync total for NTSC\n"); 5251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; 5261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 529e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt 5301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Check memory sizes */ 5311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds line_length = get_line_length(var->xres_virtual, var->bits_per_pixel); 5321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (line_length * var->yres_virtual > info->fix.smem_len) 5331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ENOMEM; 5341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 5361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void pvr2_update_display(struct fb_info *info) 5391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 5401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pvr2fb_par *par = (struct pvr2fb_par *) info->par; 5411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fb_var_screeninfo *var = &info->var; 5421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Update the start address of the display image */ 5441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(par->disp_start, DISP_DIWADDRL); 5451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(par->disp_start + 5461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds get_line_length(var->xoffset+var->xres, var->bits_per_pixel), 5471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DISP_DIWADDRS); 5481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 550e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt/* 5511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Initialize the video mode. Currently, the 16bpp and 24bpp modes aren't 5521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * very stable. It's probably due to the fact that a lot of the 2D video 5531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * registers are still undocumented. 5541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 5551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void pvr2_init_display(struct fb_info *info) 5571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 5581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pvr2fb_par *par = (struct pvr2fb_par *) info->par; 5591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fb_var_screeninfo *var = &info->var; 5601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int diw_height, diw_width, diw_modulo = 1; 5611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int bytesperpixel = var->bits_per_pixel >> 3; 5621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* hsync and vsync totals */ 5641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel((par->vsync_total << 16) | par->hsync_total, DISP_SYNCSIZE); 5651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* column height, modulo, row width */ 5671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* since we're "panning" within vram, we need to offset things based 5681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * on the offset from the virtual x start to our real gfx. */ 5691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (video_output != VO_VGA && par->is_interlaced) 5701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds diw_modulo += info->fix.line_length / 4; 5711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds diw_height = (par->is_interlaced ? var->yres / 2 : var->yres); 5721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds diw_width = get_line_length(var->xres, var->bits_per_pixel) / 4; 5731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel((diw_modulo << 20) | (--diw_height << 10) | --diw_width, 5741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DISP_DIWSIZE); 5751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* display address, long and short fields */ 5771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(par->disp_start, DISP_DIWADDRL); 5781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(par->disp_start + 5791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds get_line_length(var->xoffset+var->xres, var->bits_per_pixel), 5801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DISP_DIWADDRS); 5811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* border horizontal, border vertical, border color */ 5831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel((par->borderstart_h << 16) | par->borderstop_h, DISP_BRDRHORZ); 5841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel((par->borderstart_v << 16) | par->borderstop_v, DISP_BRDRVERT); 5851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(0, DISP_BRDRCOLR); 5861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* display window start position */ 5881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(par->diwstart_h, DISP_DIWHSTRT); 5891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel((par->diwstart_v << 16) | par->diwstart_v, DISP_DIWVSTRT); 590e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt 5911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* misc. settings */ 5921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel((0x16 << 16) | par->is_lowres, DISP_DIWCONF); 5931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* clock doubler (for VGA), scan doubler, display enable */ 595e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt fb_writel(((video_output == VO_VGA) << 23) | 5961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (par->is_doublescan << 1) | 1, DISP_DIWMODE); 5971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* bits per pixel */ 5991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(fb_readl(DISP_DIWMODE) | (--bytesperpixel << 2), DISP_DIWMODE); 600306c869c237a66fe85580f60558f105e3305d465Adrian McMenamin fb_writel(bytesperpixel << 2, DISP_PIXDEPTH); 6011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 602e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt /* video enable, color sync, interlace, 6031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * hsync and vsync polarity (currently unused) */ 6041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(0x100 | ((par->is_interlaced /*|4*/) << 4), DISP_SYNCCONF); 6051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Simulate blanking by making the border cover the entire screen */ 6081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define BLANK_BIT (1<<3) 6101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void pvr2_do_blank(void) 6121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pvr2fb_par *par = currentpar; 6141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long diwconf; 6151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds diwconf = fb_readl(DISP_DIWCONF); 6171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (do_blank > 0) 6181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(diwconf | BLANK_BIT, DISP_DIWCONF); 6191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 6201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(diwconf & ~BLANK_BIT, DISP_DIWCONF); 6211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds is_blanked = do_blank > 0 ? do_blank : 0; 6231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6257d12e780e003f93433d49ce78cfedf4b4c52adc5David Howellsstatic irqreturn_t pvr2fb_interrupt(int irq, void *dev_id) 6261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fb_info *info = dev_id; 6281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (do_vmode_pan || do_vmode_full) 6301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_update_display(info); 6311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (do_vmode_full) 6321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_init_display(info); 6331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (do_vmode_pan) 6341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds do_vmode_pan = 0; 6351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (do_vmode_full) 6361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds do_vmode_full = 0; 6371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (do_blank) { 6381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_do_blank(); 6391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds do_blank = 0; 6401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return IRQ_HANDLED; 6421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 6451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Determine the cable type and initialize the cable output format. Don't do 6461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * anything if the cable type has been overidden (via "cable:XX"). 6471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 6481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define PCTRA 0xff80002c 6501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define PDTRA 0xff800030 6511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define VOUTC 0xa0702c00 6521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pvr2_init_cable(void) 6541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (cable_type < 0) { 656e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt fb_writel((fb_readl(PCTRA) & 0xfff0ffff) | 0x000a0000, 6571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds PCTRA); 6581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds cable_type = (fb_readw(PDTRA) >> 8) & 3; 6591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Now select the output format (either composite or other) */ 6621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* XXX: Save the previous val first, as this reg is also AICA 6631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds related */ 6641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (cable_type == CT_COMPOSITE) 6651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(3 << 8, VOUTC); 66678d7e0e5b8e5d662c3e4bdceadbd84c913e69614Adrian McMenamin else if (cable_type == CT_RGB) 66778d7e0e5b8e5d662c3e4bdceadbd84c913e69614Adrian McMenamin fb_writel(1 << 9, VOUTC); 6681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 6691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_writel(0, VOUTC); 6701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return cable_type; 6721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 674da62e71d13ad0b76011491e36cb58999c464516aPaul Mundt#ifdef CONFIG_PVR2_DMA 6753f9b0880e4a96b02bc0131451f2f6231cd90bd94Antonino A. Daplasstatic ssize_t pvr2fb_write(struct fb_info *info, const char *buf, 6761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t count, loff_t *ppos) 6771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long dst, start, end, len; 6791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int nr_pages; 6801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct page **pages; 6811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int ret, i; 6821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds nr_pages = (count + PAGE_SIZE - 1) >> PAGE_SHIFT; 6841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pages = kmalloc(nr_pages * sizeof(struct page *), GFP_KERNEL); 6861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!pages) 6871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ENOMEM; 688e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt 6891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds down_read(¤t->mm->mmap_sem); 6901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = get_user_pages(current, current->mm, (unsigned long)buf, 6911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds nr_pages, WRITE, 0, pages, NULL); 6921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds up_read(¤t->mm->mmap_sem); 6931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ret < nr_pages) { 6951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds nr_pages = ret; 6961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = -EINVAL; 6971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_unmap; 6981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dma_configure_channel(shdma, 0x12c1); 701e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt 7021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dst = (unsigned long)fb_info->screen_base + *ppos; 7031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds start = (unsigned long)page_address(pages[0]); 7041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds end = (unsigned long)page_address(pages[nr_pages]); 7051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len = nr_pages << PAGE_SHIFT; 7061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Half-assed contig check */ 7081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (start + len == end) { 7091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* As we do this in one shot, it's either all or nothing.. */ 7101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((*ppos + len) > fb_info->fix.smem_len) { 7111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = -ENOSPC; 7121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_unmap; 7131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dma_write(shdma, start, 0, len); 7161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dma_write(pvr2dma, 0, dst, len); 7171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dma_wait_for_completion(pvr2dma); 7181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 7201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Not contiguous, writeout per-page instead.. */ 7231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i = 0; i < nr_pages; i++, dst += PAGE_SIZE) { 7241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((*ppos + (i << PAGE_SHIFT)) > fb_info->fix.smem_len) { 7251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = -ENOSPC; 7261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_unmap; 7271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dma_write_page(shdma, (unsigned long)page_address(pages[i]), 0); 7301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dma_write_page(pvr2dma, 0, dst); 7311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dma_wait_for_completion(pvr2dma); 7321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 7351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *ppos += count; 7361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = count; 7371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_unmap: 7391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i = 0; i < nr_pages; i++) 7401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds page_cache_release(pages[i]); 7411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(pages); 7431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ret; 745e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt} 746da62e71d13ad0b76011491e36cb58999c464516aPaul Mundt#endif /* CONFIG_PVR2_DMA */ 7471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 7491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * pvr2fb_common_init 7501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 7511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Common init code for the PVR2 chips. 7521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 7531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This mostly takes care of the common aspects of the fb setup and 7541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * registration. It's expected that the board-specific init code has 7551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * already setup pvr2_fix with something meaningful at this point. 7561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 7571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Device info reporting is also done here, as well as picking a sane 7581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * default from the modedb. For board-specific modelines, simply define 7591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * a per-board modedb. 7601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 7611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Also worth noting is that the cable and video output types are likely 7621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * always going to be VGA for the PCI-based PVR2 boards, but we leave this 7631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * in for flexibility anyways. Who knows, maybe someone has tv-out on a 7641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PCI-based version of these things ;-) 7651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 7667e7ec0d4ae57b258fed5ee29e9d007282898625aPaul Mundtstatic int __devinit pvr2fb_common_init(void) 7671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 7681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pvr2fb_par *par = currentpar; 7691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long modememused, rev; 7701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->screen_base = ioremap_nocache(pvr2_fix.smem_start, 7721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.smem_len); 773e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt 7741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!fb_info->screen_base) { 7751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "pvr2fb: Failed to remap smem space\n"); 7761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_err; 7771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds par->mmio_base = (unsigned long)ioremap_nocache(pvr2_fix.mmio_start, 780e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt pvr2_fix.mmio_len); 7811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!par->mmio_base) { 7821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "pvr2fb: Failed to remap mmio space\n"); 7831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_err; 7841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 786d2b06a8b17f96b75fa1e8e7765cb900c99fd80fbPaul Mundt fb_memset(fb_info->screen_base, 0, pvr2_fix.smem_len); 7871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.ypanstep = nopan ? 0 : 1; 7891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.ywrapstep = nowrap ? 0 : 1; 7901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->fbops = &pvr2fb_ops; 7921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->fix = pvr2_fix; 7931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->par = currentpar; 7949cd1c67434544b1d9a4fb4a4cdec15608167a233Antonino A. Daplas fb_info->pseudo_palette = currentpar->palette; 7951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; 7961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (video_output == VO_VGA) 7981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds defmode = DEFMODE_VGA; 7991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!mode_option) 8011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mode_option = "640x480@60"; 8021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!fb_find_mode(&fb_info->var, fb_info, mode_option, pvr2_modedb, 8041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NUM_TOTAL_MODES, &pvr2_modedb[defmode], 16)) 8051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->var = pvr2_var; 8061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_alloc_cmap(&fb_info->cmap, 256, 0); 8081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (register_framebuffer(fb_info) < 0) 8101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_err; 811306c869c237a66fe85580f60558f105e3305d465Adrian McMenamin /*Must write PIXDEPTH to register before anything is displayed - so force init */ 812306c869c237a66fe85580f60558f105e3305d465Adrian McMenamin pvr2_init_display(fb_info); 8131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds modememused = get_line_length(fb_info->var.xres_virtual, 8151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->var.bits_per_pixel); 8161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds modememused *= fb_info->var.yres_virtual; 8171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rev = fb_readl(par->mmio_base + 0x04); 8191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk("fb%d: %s (rev %ld.%ld) frame buffer device, using %ldk/%ldk of video memory\n", 8211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->node, fb_info->fix.id, (rev >> 4) & 0x0f, rev & 0x0f, 8221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds modememused >> 10, (unsigned long)(fb_info->fix.smem_len >> 10)); 823e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt printk("fb%d: Mode %dx%d-%d pitch = %ld cable: %s video output: %s\n", 8241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->node, fb_info->var.xres, fb_info->var.yres, 825d2b06a8b17f96b75fa1e8e7765cb900c99fd80fbPaul Mundt fb_info->var.bits_per_pixel, 8261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds get_line_length(fb_info->var.xres, fb_info->var.bits_per_pixel), 8271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (char *)pvr2_get_param(cables, NULL, cable_type, 3), 8281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (char *)pvr2_get_param(outputs, NULL, video_output, 3)); 8291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_SH_STORE_QUEUES 8311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_NOTICE "fb%d: registering with SQ API\n", fb_info->node); 8321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2fb_map = sq_remap(fb_info->fix.smem_start, fb_info->fix.smem_len, 8347bdda6209f224aa784a036df54b22cb338d2e859Paul Mundt fb_info->fix.id, PAGE_SHARED); 8351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_NOTICE "fb%d: Mapped video memory to SQ addr 0x%lx\n", 837d2b06a8b17f96b75fa1e8e7765cb900c99fd80fbPaul Mundt fb_info->node, pvr2fb_map); 8381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 8391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 8411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_err: 8431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fb_info->screen_base) 8441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iounmap(fb_info->screen_base); 8451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (par->mmio_base) 8461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iounmap((void *)par->mmio_base); 8471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ENXIO; 8491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 8501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_SH_DREAMCAST 8521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int __init pvr2fb_dc_init(void) 8531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 8541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!mach_is_dreamcast()) 8551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ENXIO; 8561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Make a guess at the monitor based on the attached cable */ 8581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (pvr2_init_cable() == CT_VGA) { 8591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->monspecs.hfmin = 30000; 8601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->monspecs.hfmax = 70000; 8611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->monspecs.vfmin = 60; 8621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->monspecs.vfmax = 60; 8631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 8641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Not VGA, using a TV (taken from acornfb) */ 8651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->monspecs.hfmin = 15469; 8661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->monspecs.hfmax = 15781; 8671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->monspecs.vfmin = 49; 8681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->monspecs.vfmax = 51; 8691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 8701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 8721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * XXX: This needs to pull default video output via BIOS or other means 8731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 8741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (video_output < 0) { 8751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (cable_type == CT_VGA) { 8761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds video_output = VO_VGA; 8771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 8781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds video_output = VO_NTSC; 8791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 8801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 881e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt 882e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt /* 8831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Nothing exciting about the DC PVR2 .. only a measly 8MiB. 8841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 8851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.smem_start = 0xa5000000; /* RAM starts here */ 8861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.smem_len = 8 << 20; 8871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.mmio_start = 0xa05f8000; /* registers start here */ 8891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.mmio_len = 0x2000; 8901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 891123f5f188638bfc673aca22ade64b863ec3a2804Adrian McMenamin if (request_irq(HW_EVENT_VSYNC, pvr2fb_interrupt, IRQF_SHARED, 8921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "pvr2 VBL handler", fb_info)) { 8931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EBUSY; 8941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 8951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 896da62e71d13ad0b76011491e36cb58999c464516aPaul Mundt#ifdef CONFIG_PVR2_DMA 8971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (request_dma(pvr2dma, "pvr2") != 0) { 898afb0499b0e43e2ee71a92bec9331635dc1173a07Julia Lawall free_irq(HW_EVENT_VSYNC, fb_info); 8991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EBUSY; 9001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 9011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 9021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return pvr2fb_common_init(); 9041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 9051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 906e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundtstatic void __exit pvr2fb_dc_exit(void) 9071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 908295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad if (fb_info->screen_base) { 909295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad iounmap(fb_info->screen_base); 910295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad fb_info->screen_base = NULL; 911295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad } 912295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad if (currentpar->mmio_base) { 913295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad iounmap((void *)currentpar->mmio_base); 914295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad currentpar->mmio_base = 0; 915295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad } 916295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad 917afb0499b0e43e2ee71a92bec9331635dc1173a07Julia Lawall free_irq(HW_EVENT_VSYNC, fb_info); 918da62e71d13ad0b76011491e36cb58999c464516aPaul Mundt#ifdef CONFIG_PVR2_DMA 9191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds free_dma(pvr2dma); 9201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 9211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 9221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* CONFIG_SH_DREAMCAST */ 9231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_PCI 9251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int __devinit pvr2fb_pci_probe(struct pci_dev *pdev, 9261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const struct pci_device_id *ent) 9271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 9281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int ret; 9291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = pci_enable_device(pdev); 9311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ret) { 9321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "pvr2fb: PCI enable failed\n"); 9331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ret; 9341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 9351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = pci_request_regions(pdev, "pvr2fb"); 9371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ret) { 9381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "pvr2fb: PCI request regions failed\n"); 9391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ret; 9401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 9411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 9431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Slightly more exciting than the DC PVR2 .. 16MiB! 9441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 9451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.smem_start = pci_resource_start(pdev, 0); 9461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.smem_len = pci_resource_len(pdev, 0); 9471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.mmio_start = pci_resource_start(pdev, 1); 9491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2_fix.mmio_len = pci_resource_len(pdev, 1); 9501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_info->device = &pdev->dev; 9521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return pvr2fb_common_init(); 9541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 9551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __devexit pvr2fb_pci_remove(struct pci_dev *pdev) 9571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 958295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad if (fb_info->screen_base) { 959295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad iounmap(fb_info->screen_base); 960295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad fb_info->screen_base = NULL; 961295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad } 962295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad if (currentpar->mmio_base) { 963295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad iounmap((void *)currentpar->mmio_base); 964295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad currentpar->mmio_base = 0; 965295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad } 966295a1b476749e8b6fa6c3c0978426360ac7dde4bAmol Lad 9671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pci_release_regions(pdev); 9681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 9691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct pci_device_id pvr2fb_pci_tbl[] __devinitdata = { 9711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_NEON250, 9721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 9731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 0, }, 9741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 9751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_DEVICE_TABLE(pci, pvr2fb_pci_tbl); 9771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct pci_driver pvr2fb_pci_driver = { 9791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .name = "pvr2fb", 9801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .id_table = pvr2fb_pci_tbl, 9811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .probe = pvr2fb_pci_probe, 9821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .remove = __devexit_p(pvr2fb_pci_remove), 9831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 9841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int __init pvr2fb_pci_init(void) 9861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 9871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return pci_register_driver(&pvr2fb_pci_driver); 9881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 9891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 990e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundtstatic void __exit pvr2fb_pci_exit(void) 9911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 9921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pci_unregister_driver(&pvr2fb_pci_driver); 9931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 9941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* CONFIG_PCI */ 9951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9967e7ec0d4ae57b258fed5ee29e9d007282898625aPaul Mundtstatic int __devinit pvr2_get_param(const struct pvr2_params *p, const char *s, 9971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int val, int size) 9981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 9991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i; 10001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i = 0 ; i < size ; i++ ) { 10021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (s != NULL) { 10031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!strnicmp(p[i].name, s, strlen(s))) 10041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return p[i].val; 10051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 10061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (p[i].val == val) 10071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (int)p[i].name; 10081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 10091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 10101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -1; 10111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 10141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Parse command arguments. Supported arguments are: 10151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * inverse Use inverse color maps 10161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * cable:composite|rgb|vga Override the video cable type 10171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * output:NTSC|PAL|VGA Override the video output format 10181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 10191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * <xres>x<yres>[-<bpp>][@<refresh>] or, 10201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * <name>[-<bpp>][@<refresh>] Startup using this video mode 10211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 10221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef MODULE 1024e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundtstatic int __init pvr2fb_setup(char *options) 10251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 10261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *this_opt; 10271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char cable_arg[80]; 10281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char output_arg[80]; 10291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!options || !*options) 10311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 10321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while ((this_opt = strsep(&options, ","))) { 10341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!*this_opt) 10351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; 10361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!strcmp(this_opt, "inverse")) { 10371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fb_invert_cmaps(); 10381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else if (!strncmp(this_opt, "cable:", 6)) { 10391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds strcpy(cable_arg, this_opt + 6); 10401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else if (!strncmp(this_opt, "output:", 7)) { 10411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds strcpy(output_arg, this_opt + 7); 10421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else if (!strncmp(this_opt, "nopan", 5)) { 10431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds nopan = 1; 10441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else if (!strncmp(this_opt, "nowrap", 6)) { 10451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds nowrap = 1; 10461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 10471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mode_option = this_opt; 10481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 10491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 10501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (*cable_arg) 10521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds cable_type = pvr2_get_param(cables, cable_arg, 0, 3); 10531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (*output_arg) 10541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds video_output = pvr2_get_param(outputs, output_arg, 0, 3); 10551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 10571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 10591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct pvr2_board { 10611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int (*init)(void); 10621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds void (*exit)(void); 10631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char name[16]; 10646d7120a713300283a8b73e7d86cd1bab8b9d1971Paul Mundt} board_driver[] __refdata = { 10651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_SH_DREAMCAST 10661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { pvr2fb_dc_init, pvr2fb_dc_exit, "Sega DC PVR2" }, 10671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 10681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_PCI 10691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { pvr2fb_pci_init, pvr2fb_pci_exit, "PCI PVR2" }, 10701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 10711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 0, }, 10721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 10731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1074e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundtstatic int __init pvr2fb_init(void) 10751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 10761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i, ret = -ENODEV; 10771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int size; 10781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef MODULE 10801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *option = NULL; 10811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fb_get_options("pvr2fb", &option)) 10831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ENODEV; 10841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr2fb_setup(option); 10851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 10861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size = sizeof(struct fb_info) + sizeof(struct pvr2fb_par) + 16 * sizeof(u32); 10871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10889cd1c67434544b1d9a4fb4a4cdec15608167a233Antonino A. Daplas fb_info = framebuffer_alloc(sizeof(struct pvr2fb_par), NULL); 10899cd1c67434544b1d9a4fb4a4cdec15608167a233Antonino A. Daplas 10901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!fb_info) { 10911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "Failed to allocate memory for fb_info\n"); 10921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ENOMEM; 10931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 10941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10969cd1c67434544b1d9a4fb4a4cdec15608167a233Antonino A. Daplas currentpar = fb_info->par; 10971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1098e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt for (i = 0; i < ARRAY_SIZE(board_driver); i++) { 1099e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt struct pvr2_board *pvr_board = board_driver + i; 11001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!pvr_board->init) 11021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; 11031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = pvr_board->init(); 11051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ret != 0) { 11071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "pvr2fb: Failed init of %s device\n", 11081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr_board->name); 11099cd1c67434544b1d9a4fb4a4cdec15608167a233Antonino A. Daplas framebuffer_release(fb_info); 11101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 11111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 11121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 11131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ret; 11151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 11161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __exit pvr2fb_exit(void) 11181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 11191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i; 11201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1121e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt for (i = 0; i < ARRAY_SIZE(board_driver); i++) { 1122e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt struct pvr2_board *pvr_board = board_driver + i; 11231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (pvr_board->exit) 11251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds pvr_board->exit(); 11261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1127e9705a77f50c1fd52356f4f0e515455273aae416Paul Mundt 11281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_SH_STORE_QUEUES 11291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sq_unmap(pvr2fb_map); 11301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 11311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unregister_framebuffer(fb_info); 11339cd1c67434544b1d9a4fb4a4cdec15608167a233Antonino A. Daplas framebuffer_release(fb_info); 11341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 11351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_init(pvr2fb_init); 11371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_exit(pvr2fb_exit); 11381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, M. R. Brown <mrbrown@0xd6.org>"); 11401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_DESCRIPTION("Framebuffer driver for NEC PowerVR 2 based graphics boards"); 11411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL"); 1142