Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/pm3fb.c -- 3DLabs Permedia3 frame buffer device |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2001 Romain Dolbeau <romain@dolbeau.org>. |
| 5 | * |
| 6 | * Ported to 2.6 kernel on 1 May 2007 by Krzysztof Helt <krzysztof.h1@wp.pl> |
| 7 | * based on pm2fb.c |
| 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Based on code written by: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 10 | * Sven Luther, <luther@dpt-info.u-strasbg.fr> |
| 11 | * Alan Hourihane, <alanh@fairlite.demon.co.uk> |
| 12 | * Russell King, <rmk@arm.linux.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * Based on linux/drivers/video/skeletonfb.c: |
| 14 | * Copyright (C) 1997 Geert Uytterhoeven |
| 15 | * Based on linux/driver/video/pm2fb.c: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 16 | * Copyright (C) 1998-1999 Ilario Nardinocchi (nardinoc@CS.UniBO.IT) |
| 17 | * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * |
| 19 | * This file is subject to the terms and conditions of the GNU General Public |
| 20 | * License. See the file COPYING in the main directory of this archive for |
| 21 | * more details. |
| 22 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | */ |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/string.h> |
| 29 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/fb.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <video/pm3fb.h> |
| 37 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 38 | #if !defined(CONFIG_PCI) |
| 39 | #error "Only generic PCI cards supported." |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #endif |
| 41 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 42 | #undef PM3FB_MASTER_DEBUG |
| 43 | #ifdef PM3FB_MASTER_DEBUG |
| 44 | #define DPRINTK(a,b...) printk(KERN_DEBUG "pm3fb: %s: " a, __FUNCTION__ , ## b) |
| 45 | #else |
| 46 | #define DPRINTK(a,b...) |
| 47 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 49 | /* |
| 50 | * Driver data |
| 51 | */ |
| 52 | static char *mode_option __devinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 54 | /* |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 55 | * This structure defines the hardware state of the graphics card. Normally |
| 56 | * you place this in a header file in linux/include/video. This file usually |
| 57 | * also includes register information. That allows other driver subsystems |
| 58 | * and userland applications the ability to use the same header file to |
| 59 | * avoid duplicate work and easy porting of software. |
| 60 | */ |
| 61 | struct pm3_par { |
| 62 | unsigned char __iomem *v_regs;/* virtual address of p_regs */ |
| 63 | u32 video; /* video flags before blanking */ |
| 64 | u32 base; /* screen base (xoffset+yoffset) in 128 bits unit */ |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 65 | u32 palette[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 68 | /* |
| 69 | * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo |
| 70 | * if we don't use modedb. If we do use modedb see pm3fb_init how to use it |
| 71 | * to get a fb_var_screeninfo. Otherwise define a default var as well. |
| 72 | */ |
| 73 | static struct fb_fix_screeninfo pm3fb_fix __devinitdata = { |
| 74 | .id = "Permedia3", |
| 75 | .type = FB_TYPE_PACKED_PIXELS, |
| 76 | .visual = FB_VISUAL_PSEUDOCOLOR, |
| 77 | .xpanstep = 1, |
| 78 | .ypanstep = 1, |
| 79 | .ywrapstep = 0, |
| 80 | .accel = FB_ACCEL_NONE, |
| 81 | }; |
| 82 | |
| 83 | /* |
| 84 | * Utility functions |
| 85 | */ |
| 86 | |
| 87 | static inline u32 PM3_READ_REG(struct pm3_par *par, s32 off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 89 | return fb_readl(par->v_regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 92 | static inline void PM3_WRITE_REG(struct pm3_par *par, s32 off, u32 v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 94 | fb_writel(v, par->v_regs + off); |
| 95 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 97 | static inline void PM3_WAIT(struct pm3_par *par, u32 n) |
| 98 | { |
| 99 | while (PM3_READ_REG(par, PM3InFIFOSpace) < n); |
| 100 | } |
| 101 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 102 | static inline void PM3_WRITE_DAC_REG(struct pm3_par *par, unsigned r, u8 v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 104 | PM3_WAIT(par, 3); |
| 105 | PM3_WRITE_REG(par, PM3RD_IndexHigh, (r >> 8) & 0xff); |
| 106 | PM3_WRITE_REG(par, PM3RD_IndexLow, r & 0xff); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 107 | wmb(); |
| 108 | PM3_WRITE_REG(par, PM3RD_IndexedData, v); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 109 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 112 | static inline void pm3fb_set_color(struct pm3_par *par, unsigned char regno, |
| 113 | unsigned char r, unsigned char g, unsigned char b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 115 | PM3_WAIT(par, 4); |
| 116 | PM3_WRITE_REG(par, PM3RD_PaletteWriteAddress, regno); |
| 117 | wmb(); |
| 118 | PM3_WRITE_REG(par, PM3RD_PaletteData, r); |
| 119 | wmb(); |
| 120 | PM3_WRITE_REG(par, PM3RD_PaletteData, g); |
| 121 | wmb(); |
| 122 | PM3_WRITE_REG(par, PM3RD_PaletteData, b); |
| 123 | wmb(); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void pm3fb_clear_colormap(struct pm3_par *par, |
| 127 | unsigned char r, unsigned char g, unsigned char b) |
| 128 | { |
| 129 | int i; |
| 130 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 131 | for (i = 0; i < 256 ; i++) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 132 | pm3fb_set_color(par, i, r, g, b); |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* Calculating various clock parameter */ |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 137 | static void pm3fb_calculate_clock(unsigned long reqclock, |
| 138 | unsigned char *prescale, |
| 139 | unsigned char *feedback, |
| 140 | unsigned char *postscale) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
| 142 | int f, pre, post; |
| 143 | unsigned long freq; |
| 144 | long freqerr = 1000; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 145 | long currerr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | for (f = 1; f < 256; f++) { |
| 148 | for (pre = 1; pre < 256; pre++) { |
| 149 | for (post = 0; post < 5; post++) { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 150 | freq = ((2*PM3_REF_CLOCK * f) >> post) / pre; |
| 151 | currerr = (reqclock > freq) |
| 152 | ? reqclock - freq |
| 153 | : freq - reqclock; |
| 154 | if (currerr < freqerr) { |
| 155 | freqerr = currerr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | *feedback = f; |
| 157 | *prescale = pre; |
| 158 | *postscale = post; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | } |
| 162 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 165 | static inline int pm3fb_depth(const struct fb_var_screeninfo *var) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 167 | if ( var->bits_per_pixel == 16 ) |
| 168 | return var->red.length + var->green.length |
| 169 | + var->blue.length; |
| 170 | |
| 171 | return var->bits_per_pixel; |
| 172 | } |
| 173 | |
| 174 | static inline int pm3fb_shift_bpp(unsigned bpp, int v) |
| 175 | { |
| 176 | switch (bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | case 8: |
| 178 | return (v >> 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | case 16: |
| 180 | return (v >> 3); |
| 181 | case 32: |
| 182 | return (v >> 2); |
| 183 | } |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 184 | DPRINTK("Unsupported depth %u\n", bpp); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 185 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /* write the mode to registers */ |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 189 | static void pm3fb_write_mode(struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 191 | struct pm3_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | char tempsync = 0x00, tempmisc = 0x00; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 193 | const u32 hsstart = info->var.right_margin; |
| 194 | const u32 hsend = hsstart + info->var.hsync_len; |
| 195 | const u32 hbend = hsend + info->var.left_margin; |
| 196 | const u32 xres = (info->var.xres + 31) & ~31; |
| 197 | const u32 htotal = xres + hbend; |
| 198 | const u32 vsstart = info->var.lower_margin; |
| 199 | const u32 vsend = vsstart + info->var.vsync_len; |
| 200 | const u32 vbend = vsend + info->var.upper_margin; |
| 201 | const u32 vtotal = info->var.yres + vbend; |
| 202 | const u32 width = (info->var.xres_virtual + 7) & ~7; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 203 | const unsigned bpp = info->var.bits_per_pixel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 205 | PM3_WAIT(par, 20); |
| 206 | PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xffffffff); |
| 207 | PM3_WRITE_REG(par, PM3Aperture0, 0x00000000); |
| 208 | PM3_WRITE_REG(par, PM3Aperture1, 0x00000000); |
| 209 | PM3_WRITE_REG(par, PM3FIFODis, 0x00000007); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 211 | PM3_WRITE_REG(par, PM3HTotal, |
| 212 | pm3fb_shift_bpp(bpp, htotal - 1)); |
| 213 | PM3_WRITE_REG(par, PM3HsEnd, |
| 214 | pm3fb_shift_bpp(bpp, hsend)); |
| 215 | PM3_WRITE_REG(par, PM3HsStart, |
| 216 | pm3fb_shift_bpp(bpp, hsstart)); |
| 217 | PM3_WRITE_REG(par, PM3HbEnd, |
| 218 | pm3fb_shift_bpp(bpp, hbend)); |
| 219 | PM3_WRITE_REG(par, PM3HgEnd, |
| 220 | pm3fb_shift_bpp(bpp, hbend)); |
| 221 | PM3_WRITE_REG(par, PM3ScreenStride, |
| 222 | pm3fb_shift_bpp(bpp, width)); |
| 223 | PM3_WRITE_REG(par, PM3VTotal, vtotal - 1); |
| 224 | PM3_WRITE_REG(par, PM3VsEnd, vsend - 1); |
| 225 | PM3_WRITE_REG(par, PM3VsStart, vsstart - 1); |
| 226 | PM3_WRITE_REG(par, PM3VbEnd, vbend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 228 | switch (bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | case 8: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 230 | PM3_WRITE_REG(par, PM3ByAperture1Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | PM3ByApertureMode_PIXELSIZE_8BIT); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 232 | PM3_WRITE_REG(par, PM3ByAperture2Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | PM3ByApertureMode_PIXELSIZE_8BIT); |
| 234 | break; |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | case 16: |
| 237 | #ifndef __BIG_ENDIAN |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 238 | PM3_WRITE_REG(par, PM3ByAperture1Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | PM3ByApertureMode_PIXELSIZE_16BIT); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 240 | PM3_WRITE_REG(par, PM3ByAperture2Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | PM3ByApertureMode_PIXELSIZE_16BIT); |
| 242 | #else |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 243 | PM3_WRITE_REG(par, PM3ByAperture1Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | PM3ByApertureMode_PIXELSIZE_16BIT | |
| 245 | PM3ByApertureMode_BYTESWAP_BADC); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 246 | PM3_WRITE_REG(par, PM3ByAperture2Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | PM3ByApertureMode_PIXELSIZE_16BIT | |
| 248 | PM3ByApertureMode_BYTESWAP_BADC); |
| 249 | #endif /* ! __BIG_ENDIAN */ |
| 250 | break; |
| 251 | |
| 252 | case 32: |
| 253 | #ifndef __BIG_ENDIAN |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 254 | PM3_WRITE_REG(par, PM3ByAperture1Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | PM3ByApertureMode_PIXELSIZE_32BIT); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 256 | PM3_WRITE_REG(par, PM3ByAperture2Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | PM3ByApertureMode_PIXELSIZE_32BIT); |
| 258 | #else |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 259 | PM3_WRITE_REG(par, PM3ByAperture1Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | PM3ByApertureMode_PIXELSIZE_32BIT | |
| 261 | PM3ByApertureMode_BYTESWAP_DCBA); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 262 | PM3_WRITE_REG(par, PM3ByAperture2Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | PM3ByApertureMode_PIXELSIZE_32BIT | |
| 264 | PM3ByApertureMode_BYTESWAP_DCBA); |
| 265 | #endif /* ! __BIG_ENDIAN */ |
| 266 | break; |
| 267 | |
| 268 | default: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 269 | DPRINTK("Unsupported depth %d\n", bpp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | break; |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | * Oxygen VX1 - it appears that setting PM3VideoControl and |
| 275 | * then PM3RD_SyncControl to the same SYNC settings undoes |
| 276 | * any net change - they seem to xor together. Only set the |
| 277 | * sync options in PM3RD_SyncControl. --rmk |
| 278 | */ |
| 279 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 280 | unsigned int video = par->video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | video &= ~(PM3VideoControl_HSYNC_MASK | |
| 283 | PM3VideoControl_VSYNC_MASK); |
| 284 | video |= PM3VideoControl_HSYNC_ACTIVE_HIGH | |
| 285 | PM3VideoControl_VSYNC_ACTIVE_HIGH; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 286 | PM3_WRITE_REG(par, PM3VideoControl, video); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 288 | PM3_WRITE_REG(par, PM3VClkCtl, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 289 | (PM3_READ_REG(par, PM3VClkCtl) & 0xFFFFFFFC)); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 290 | PM3_WRITE_REG(par, PM3ScreenBase, par->base); |
| 291 | PM3_WRITE_REG(par, PM3ChipConfig, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 292 | (PM3_READ_REG(par, PM3ChipConfig) & 0xFFFFFFFD)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 294 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 296 | unsigned char uninitialized_var(m); /* ClkPreScale */ |
| 297 | unsigned char uninitialized_var(n); /* ClkFeedBackScale */ |
| 298 | unsigned char uninitialized_var(p); /* ClkPostScale */ |
| 299 | unsigned long pixclock = PICOS2KHZ(info->var.pixclock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 301 | (void)pm3fb_calculate_clock(pixclock, &m, &n, &p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 303 | DPRINTK("Pixclock: %ld, Pre: %d, Feedback: %d, Post: %d\n", |
| 304 | pixclock, (int) m, (int) n, (int) p); |
| 305 | |
| 306 | PM3_WRITE_DAC_REG(par, PM3RD_DClk0PreScale, m); |
| 307 | PM3_WRITE_DAC_REG(par, PM3RD_DClk0FeedbackScale, n); |
| 308 | PM3_WRITE_DAC_REG(par, PM3RD_DClk0PostScale, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | /* |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 311 | PM3_WRITE_DAC_REG(par, PM3RD_IndexControl, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | */ |
| 313 | /* |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 314 | PM3_SLOW_WRITE_REG(par, PM3RD_IndexControl, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | */ |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 316 | if ((par->video & PM3VideoControl_HSYNC_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | PM3VideoControl_HSYNC_ACTIVE_HIGH) |
| 318 | tempsync |= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 319 | if ((par->video & PM3VideoControl_VSYNC_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | PM3VideoControl_VSYNC_ACTIVE_HIGH) |
| 321 | tempsync |= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 323 | PM3_WRITE_DAC_REG(par, PM3RD_SyncControl, tempsync); |
| 324 | DPRINTK("PM3RD_SyncControl: %d\n", tempsync); |
| 325 | |
| 326 | PM3_WRITE_DAC_REG(par, PM3RD_DACControl, 0x00); |
| 327 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 328 | switch (pm3fb_depth(&info->var)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | case 8: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 330 | PM3_WRITE_DAC_REG(par, PM3RD_PixelSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | PM3RD_PixelSize_8_BIT_PIXELS); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 332 | PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | PM3RD_ColorFormat_CI8_COLOR | |
| 334 | PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW); |
| 335 | tempmisc |= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; |
| 336 | break; |
| 337 | case 12: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 338 | PM3_WRITE_DAC_REG(par, PM3RD_PixelSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | PM3RD_PixelSize_16_BIT_PIXELS); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 340 | PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | PM3RD_ColorFormat_4444_COLOR | |
| 342 | PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW | |
| 343 | PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE); |
| 344 | tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | |
| 345 | PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 346 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | case 15: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 348 | PM3_WRITE_DAC_REG(par, PM3RD_PixelSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | PM3RD_PixelSize_16_BIT_PIXELS); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 350 | PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | PM3RD_ColorFormat_5551_FRONT_COLOR | |
| 352 | PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW | |
| 353 | PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE); |
| 354 | tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | |
| 355 | PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 356 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | case 16: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 358 | PM3_WRITE_DAC_REG(par, PM3RD_PixelSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | PM3RD_PixelSize_16_BIT_PIXELS); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 360 | PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | PM3RD_ColorFormat_565_FRONT_COLOR | |
| 362 | PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW | |
| 363 | PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE); |
| 364 | tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | |
| 365 | PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; |
| 366 | break; |
| 367 | case 32: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 368 | PM3_WRITE_DAC_REG(par, PM3RD_PixelSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | PM3RD_PixelSize_32_BIT_PIXELS); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 370 | PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | PM3RD_ColorFormat_8888_COLOR | |
| 372 | PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW); |
| 373 | tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | |
| 374 | PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; |
| 375 | break; |
| 376 | } |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 377 | PM3_WRITE_DAC_REG(par, PM3RD_MiscControl, tempmisc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 380 | /* |
| 381 | * hardware independent functions |
| 382 | */ |
| 383 | int pm3fb_init(void); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 384 | |
| 385 | static int pm3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 387 | u32 lpitch; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 388 | unsigned bpp = var->red.length + var->green.length |
| 389 | + var->blue.length + var->transp.length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 391 | if ( bpp != var->bits_per_pixel ) { |
| 392 | /* set predefined mode for bits_per_pixel settings */ |
| 393 | |
| 394 | switch(var->bits_per_pixel) { |
| 395 | case 8: |
| 396 | var->red.length = var->green.length = var->blue.length = 8; |
| 397 | var->red.offset = var->green.offset = var->blue.offset = 0; |
| 398 | var->transp.offset = 0; |
| 399 | var->transp.length = 0; |
| 400 | break; |
| 401 | case 16: |
| 402 | var->red.length = var->blue.length = 5; |
| 403 | var->green.length = 6; |
| 404 | var->transp.length = 0; |
| 405 | break; |
| 406 | case 32: |
| 407 | var->red.length = var->green.length = var->blue.length = 8; |
| 408 | var->transp.length = 8; |
| 409 | break; |
| 410 | default: |
| 411 | DPRINTK("depth not supported: %u\n", var->bits_per_pixel); |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | } |
| 415 | /* it is assumed BGRA order */ |
| 416 | if (var->bits_per_pixel > 8 ) |
| 417 | { |
| 418 | var->blue.offset = 0; |
| 419 | var->green.offset = var->blue.length; |
| 420 | var->red.offset = var->green.offset + var->green.length; |
| 421 | var->transp.offset = var->red.offset + var->red.length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | var->height = var->width = -1; |
| 424 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 425 | if (var->xres != var->xres_virtual) { |
| 426 | DPRINTK("virtual x resolution != physical x resolution not supported\n"); |
| 427 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 430 | if (var->yres > var->yres_virtual) { |
| 431 | DPRINTK("virtual y resolution < physical y resolution not possible\n"); |
| 432 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 434 | |
| 435 | if (var->xoffset) { |
| 436 | DPRINTK("xoffset not supported\n"); |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | |
| 440 | if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) { |
| 441 | DPRINTK("interlace not supported\n"); |
| 442 | return -EINVAL; |
| 443 | } |
| 444 | |
| 445 | var->xres = (var->xres + 31) & ~31; /* could sometimes be 8 */ |
| 446 | lpitch = var->xres * ((var->bits_per_pixel + 7)>>3); |
| 447 | |
| 448 | if (var->xres < 200 || var->xres > 2048) { |
| 449 | DPRINTK("width not supported: %u\n", var->xres); |
| 450 | return -EINVAL; |
| 451 | } |
| 452 | |
| 453 | if (var->yres < 200 || var->yres > 4095) { |
| 454 | DPRINTK("height not supported: %u\n", var->yres); |
| 455 | return -EINVAL; |
| 456 | } |
| 457 | |
| 458 | if (lpitch * var->yres_virtual > info->fix.smem_len) { |
| 459 | DPRINTK("no memory for screen (%ux%ux%u)\n", |
| 460 | var->xres, var->yres_virtual, var->bits_per_pixel); |
| 461 | return -EINVAL; |
| 462 | } |
| 463 | |
| 464 | if (PICOS2KHZ(var->pixclock) > PM3_MAX_PIXCLOCK) { |
| 465 | DPRINTK("pixclock too high (%ldKHz)\n", PICOS2KHZ(var->pixclock)); |
| 466 | return -EINVAL; |
| 467 | } |
| 468 | |
| 469 | var->accel_flags = 0; /* Can't mmap if this is on */ |
| 470 | |
| 471 | DPRINTK("Checking graphics mode at %dx%d depth %d\n", |
| 472 | var->xres, var->yres, var->bits_per_pixel); |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | static int pm3fb_set_par(struct fb_info *info) |
| 477 | { |
| 478 | struct pm3_par *par = info->par; |
| 479 | const u32 xres = (info->var.xres + 31) & ~31; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 480 | const unsigned bpp = info->var.bits_per_pixel; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 481 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 482 | par->base = pm3fb_shift_bpp(bpp,(info->var.yoffset * xres) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 483 | + info->var.xoffset); |
| 484 | par->video = 0; |
| 485 | |
| 486 | if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) |
| 487 | par->video |= PM3VideoControl_HSYNC_ACTIVE_HIGH; |
| 488 | else |
| 489 | par->video |= PM3VideoControl_HSYNC_ACTIVE_LOW; |
| 490 | |
| 491 | if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) |
| 492 | par->video |= PM3VideoControl_VSYNC_ACTIVE_HIGH; |
| 493 | else |
| 494 | par->video |= PM3VideoControl_VSYNC_ACTIVE_LOW; |
| 495 | |
| 496 | if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) |
| 497 | par->video |= PM3VideoControl_LINE_DOUBLE_ON; |
| 498 | else |
| 499 | par->video |= PM3VideoControl_LINE_DOUBLE_OFF; |
| 500 | |
| 501 | if (info->var.activate == FB_ACTIVATE_NOW) |
| 502 | par->video |= PM3VideoControl_ENABLE; |
| 503 | else { |
| 504 | par->video |= PM3VideoControl_DISABLE; |
| 505 | DPRINTK("PM3Video disabled\n"); |
| 506 | } |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 507 | switch (bpp) { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 508 | case 8: |
| 509 | par->video |= PM3VideoControl_PIXELSIZE_8BIT; |
| 510 | break; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 511 | case 16: |
| 512 | par->video |= PM3VideoControl_PIXELSIZE_16BIT; |
| 513 | break; |
| 514 | case 32: |
| 515 | par->video |= PM3VideoControl_PIXELSIZE_32BIT; |
| 516 | break; |
| 517 | default: |
| 518 | DPRINTK("Unsupported depth\n"); |
| 519 | break; |
| 520 | } |
| 521 | |
| 522 | info->fix.visual = |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 523 | (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 524 | info->fix.line_length = ((info->var.xres_virtual + 7) & ~7) |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 525 | * bpp / 8; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 526 | |
| 527 | /* pm3fb_clear_memory(info, 0);*/ |
| 528 | pm3fb_clear_colormap(par, 0, 0, 0); |
| 529 | PM3_WRITE_DAC_REG(par, PM3RD_CursorMode, |
| 530 | PM3RD_CursorMode_CURSOR_DISABLE); |
| 531 | pm3fb_write_mode(info); |
| 532 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 536 | unsigned blue, unsigned transp, |
| 537 | struct fb_info *info) |
| 538 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 539 | struct pm3_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 541 | if (regno >= 256) /* no. of hw registers */ |
| 542 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 544 | /* grayscale works only partially under directcolor */ |
| 545 | if (info->var.grayscale) { |
| 546 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ |
| 547 | red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; |
| 548 | } |
| 549 | |
| 550 | /* Directcolor: |
| 551 | * var->{color}.offset contains start of bitfield |
| 552 | * var->{color}.length contains length of bitfield |
| 553 | * {hardwarespecific} contains width of DAC |
| 554 | * pseudo_palette[X] is programmed to (X << red.offset) | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 555 | * (X << green.offset) | |
| 556 | * (X << blue.offset) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 557 | * RAMDAC[X] is programmed to (red, green, blue) |
| 558 | * color depth = SUM(var->{color}.length) |
| 559 | * |
| 560 | * Pseudocolor: |
| 561 | * var->{color}.offset is 0 |
| 562 | * var->{color}.length contains width of DAC or the number of unique |
| 563 | * colors available (color depth) |
| 564 | * pseudo_palette is not used |
| 565 | * RAMDAC[X] is programmed to (red, green, blue) |
| 566 | * color depth = var->{color}.length |
| 567 | */ |
| 568 | |
| 569 | /* |
| 570 | * This is the point where the color is converted to something that |
| 571 | * is acceptable by the hardware. |
| 572 | */ |
| 573 | #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16) |
| 574 | red = CNVT_TOHW(red, info->var.red.length); |
| 575 | green = CNVT_TOHW(green, info->var.green.length); |
| 576 | blue = CNVT_TOHW(blue, info->var.blue.length); |
| 577 | transp = CNVT_TOHW(transp, info->var.transp.length); |
| 578 | #undef CNVT_TOHW |
| 579 | |
| 580 | if (info->fix.visual == FB_VISUAL_TRUECOLOR || |
| 581 | info->fix.visual == FB_VISUAL_DIRECTCOLOR) { |
| 582 | u32 v; |
| 583 | |
| 584 | if (regno >= 16) |
| 585 | return -EINVAL; |
| 586 | |
| 587 | v = (red << info->var.red.offset) | |
| 588 | (green << info->var.green.offset) | |
| 589 | (blue << info->var.blue.offset) | |
| 590 | (transp << info->var.transp.offset); |
| 591 | |
| 592 | switch (info->var.bits_per_pixel) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | case 8: |
| 594 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | case 16: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | case 32: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 597 | ((u32*)(info->pseudo_palette))[regno] = v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | break; |
| 599 | } |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 600 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | } |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 602 | else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) |
| 603 | pm3fb_set_color(par, regno, red, green, blue); |
| 604 | |
| 605 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 608 | static int pm3fb_pan_display(struct fb_var_screeninfo *var, |
| 609 | struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 611 | struct pm3_par *par = info->par; |
| 612 | const u32 xres = (var->xres + 31) & ~31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 614 | par->base = pm3fb_shift_bpp(var->bits_per_pixel, |
| 615 | (var->yoffset * xres) |
| 616 | + var->xoffset); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 617 | PM3_WAIT(par, 1); |
| 618 | PM3_WRITE_REG(par, PM3ScreenBase, par->base); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 619 | return 0; |
| 620 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 622 | static int pm3fb_blank(int blank_mode, struct fb_info *info) |
| 623 | { |
| 624 | struct pm3_par *par = info->par; |
| 625 | u32 video = par->video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
| 627 | /* |
| 628 | * Oxygen VX1 - it appears that setting PM3VideoControl and |
| 629 | * then PM3RD_SyncControl to the same SYNC settings undoes |
| 630 | * any net change - they seem to xor together. Only set the |
| 631 | * sync options in PM3RD_SyncControl. --rmk |
| 632 | */ |
| 633 | video &= ~(PM3VideoControl_HSYNC_MASK | |
| 634 | PM3VideoControl_VSYNC_MASK); |
| 635 | video |= PM3VideoControl_HSYNC_ACTIVE_HIGH | |
| 636 | PM3VideoControl_VSYNC_ACTIVE_HIGH; |
| 637 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 638 | switch (blank_mode) { |
| 639 | case FB_BLANK_UNBLANK: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 640 | video |= PM3VideoControl_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | break; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 642 | case FB_BLANK_NORMAL: |
| 643 | video &= ~(PM3VideoControl_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | break; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 645 | case FB_BLANK_HSYNC_SUSPEND: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 646 | video &= ~(PM3VideoControl_HSYNC_MASK | |
| 647 | PM3VideoControl_BLANK_ACTIVE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | break; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 649 | case FB_BLANK_VSYNC_SUSPEND: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 650 | video &= ~(PM3VideoControl_VSYNC_MASK | |
| 651 | PM3VideoControl_BLANK_ACTIVE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | break; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 653 | case FB_BLANK_POWERDOWN: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 654 | video &= ~(PM3VideoControl_HSYNC_MASK | |
| 655 | PM3VideoControl_VSYNC_MASK | |
| 656 | PM3VideoControl_BLANK_ACTIVE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | default: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 659 | DPRINTK("Unsupported blanking %d\n", blank_mode); |
| 660 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 663 | PM3_WAIT(par, 1); |
| 664 | PM3_WRITE_REG(par,PM3VideoControl, video); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | return 0; |
| 666 | } |
| 667 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 668 | /* |
| 669 | * Frame buffer operations |
| 670 | */ |
| 671 | |
| 672 | static struct fb_ops pm3fb_ops = { |
| 673 | .owner = THIS_MODULE, |
| 674 | .fb_check_var = pm3fb_check_var, |
| 675 | .fb_set_par = pm3fb_set_par, |
| 676 | .fb_setcolreg = pm3fb_setcolreg, |
| 677 | .fb_pan_display = pm3fb_pan_display, |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 678 | .fb_fillrect = cfb_fillrect, |
| 679 | .fb_copyarea = cfb_copyarea, |
| 680 | .fb_imageblit = cfb_imageblit, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 681 | .fb_blank = pm3fb_blank, |
| 682 | }; |
| 683 | |
| 684 | /* ------------------------------------------------------------------------- */ |
| 685 | |
| 686 | /* |
| 687 | * Initialization |
| 688 | */ |
| 689 | |
| 690 | /* mmio register are already mapped when this function is called */ |
| 691 | /* the pm3fb_fix.smem_start is also set */ |
| 692 | static unsigned long pm3fb_size_memory(struct pm3_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 694 | unsigned long memsize = 0, tempBypass, i, temp1, temp2; |
| 695 | unsigned char __iomem *screen_mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 697 | pm3fb_fix.smem_len = 64 * 1024l * 1024; /* request full aperture size */ |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 698 | /* Linear frame buffer - request region and map it. */ |
| 699 | if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len, |
| 700 | "pm3fb smem")) { |
| 701 | printk(KERN_WARNING "pm3fb: Can't reserve smem.\n"); |
| 702 | return 0; |
| 703 | } |
| 704 | screen_mem = |
| 705 | ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 706 | if (!screen_mem) { |
| 707 | printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n"); |
| 708 | release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | /* TODO: card-specific stuff, *before* accessing *any* FB memory */ |
| 713 | /* For Appian Jeronimo 2000 board second head */ |
| 714 | |
| 715 | tempBypass = PM3_READ_REG(par, PM3MemBypassWriteMask); |
| 716 | |
| 717 | DPRINTK("PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass); |
| 718 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 719 | PM3_WAIT(par, 1); |
| 720 | PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xFFFFFFFF); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 721 | |
| 722 | /* pm3 split up memory, replicates, and do a lot of nasty stuff IMHO ;-) */ |
| 723 | for (i = 0; i < 32; i++) { |
| 724 | fb_writel(i * 0x00345678, |
| 725 | (screen_mem + (i * 1048576))); |
| 726 | mb(); |
| 727 | temp1 = fb_readl((screen_mem + (i * 1048576))); |
| 728 | |
| 729 | /* Let's check for wrapover, write will fail at 16MB boundary */ |
| 730 | if (temp1 == (i * 0x00345678)) |
| 731 | memsize = i; |
| 732 | else |
| 733 | break; |
| 734 | } |
| 735 | |
| 736 | DPRINTK("First detect pass already got %ld MB\n", memsize + 1); |
| 737 | |
| 738 | if (memsize + 1 == i) { |
| 739 | for (i = 0; i < 32; i++) { |
| 740 | /* Clear first 32MB ; 0 is 0, no need to byteswap */ |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 741 | writel(0x0000000, (screen_mem + (i * 1048576))); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 742 | } |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 743 | wmb(); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 744 | |
| 745 | for (i = 32; i < 64; i++) { |
| 746 | fb_writel(i * 0x00345678, |
| 747 | (screen_mem + (i * 1048576))); |
| 748 | mb(); |
| 749 | temp1 = |
| 750 | fb_readl((screen_mem + (i * 1048576))); |
| 751 | temp2 = |
| 752 | fb_readl((screen_mem + ((i - 32) * 1048576))); |
| 753 | /* different value, different RAM... */ |
| 754 | if ((temp1 == (i * 0x00345678)) && (temp2 == 0)) |
| 755 | memsize = i; |
| 756 | else |
| 757 | break; |
| 758 | } |
| 759 | } |
| 760 | DPRINTK("Second detect pass got %ld MB\n", memsize + 1); |
| 761 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 762 | PM3_WAIT(par, 1); |
| 763 | PM3_WRITE_REG(par, PM3MemBypassWriteMask, tempBypass); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 764 | |
| 765 | iounmap(screen_mem); |
| 766 | release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 767 | memsize = 1048576 * (memsize + 1); |
| 768 | |
| 769 | DPRINTK("Returning 0x%08lx bytes\n", memsize); |
| 770 | |
| 771 | return memsize; |
| 772 | } |
| 773 | |
| 774 | static int __devinit pm3fb_probe(struct pci_dev *dev, |
| 775 | const struct pci_device_id *ent) |
| 776 | { |
| 777 | struct fb_info *info; |
| 778 | struct pm3_par *par; |
| 779 | struct device* device = &dev->dev; /* for pci drivers */ |
| 780 | int err, retval = -ENXIO; |
| 781 | |
| 782 | err = pci_enable_device(dev); |
| 783 | if (err) { |
| 784 | printk(KERN_WARNING "pm3fb: Can't enable PCI dev: %d\n", err); |
| 785 | return err; |
| 786 | } |
| 787 | /* |
| 788 | * Dynamically allocate info and par |
| 789 | */ |
| 790 | info = framebuffer_alloc(sizeof(struct pm3_par), device); |
| 791 | |
| 792 | if (!info) |
| 793 | return -ENOMEM; |
| 794 | par = info->par; |
| 795 | |
| 796 | /* |
| 797 | * Here we set the screen_base to the virtual memory address |
| 798 | * for the framebuffer. |
| 799 | */ |
| 800 | pm3fb_fix.mmio_start = pci_resource_start(dev, 0); |
| 801 | pm3fb_fix.mmio_len = PM3_REGS_SIZE; |
| 802 | |
| 803 | /* Registers - request region and map it. */ |
| 804 | if (!request_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len, |
| 805 | "pm3fb regbase")) { |
| 806 | printk(KERN_WARNING "pm3fb: Can't reserve regbase.\n"); |
| 807 | goto err_exit_neither; |
| 808 | } |
| 809 | par->v_regs = |
| 810 | ioremap_nocache(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len); |
| 811 | if (!par->v_regs) { |
| 812 | printk(KERN_WARNING "pm3fb: Can't remap %s register area.\n", |
| 813 | pm3fb_fix.id); |
| 814 | release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len); |
| 815 | goto err_exit_neither; |
| 816 | } |
| 817 | |
| 818 | #if defined(__BIG_ENDIAN) |
| 819 | pm3fb_fix.mmio_start += PM3_REGS_SIZE; |
| 820 | DPRINTK("Adjusting register base for big-endian.\n"); |
| 821 | #endif |
| 822 | /* Linear frame buffer - request region and map it. */ |
| 823 | pm3fb_fix.smem_start = pci_resource_start(dev, 1); |
| 824 | pm3fb_fix.smem_len = pm3fb_size_memory(par); |
| 825 | if (!pm3fb_fix.smem_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 827 | printk(KERN_WARNING "pm3fb: Can't find memory on board.\n"); |
| 828 | goto err_exit_mmio; |
| 829 | } |
| 830 | if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len, |
| 831 | "pm3fb smem")) { |
| 832 | printk(KERN_WARNING "pm3fb: Can't reserve smem.\n"); |
| 833 | goto err_exit_mmio; |
| 834 | } |
| 835 | info->screen_base = |
| 836 | ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 837 | if (!info->screen_base) { |
| 838 | printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n"); |
| 839 | release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 840 | goto err_exit_mmio; |
| 841 | } |
| 842 | info->screen_size = pm3fb_fix.smem_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 844 | info->fbops = &pm3fb_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 846 | par->video = PM3_READ_REG(par, PM3VideoControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 848 | info->fix = pm3fb_fix; |
| 849 | info->pseudo_palette = par->palette; |
| 850 | info->flags = FBINFO_DEFAULT;/* | FBINFO_HWACCEL_YPAN;*/ |
| 851 | |
| 852 | /* |
| 853 | * This should give a reasonable default video mode. The following is |
| 854 | * done when we can set a video mode. |
| 855 | */ |
| 856 | if (!mode_option) |
| 857 | mode_option = "640x480@60"; |
| 858 | |
| 859 | retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8); |
| 860 | |
| 861 | if (!retval || retval == 4) { |
| 862 | retval = -EINVAL; |
| 863 | goto err_exit_both; |
| 864 | } |
| 865 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 866 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { |
| 867 | retval = -ENOMEM; |
| 868 | goto err_exit_both; |
| 869 | } |
| 870 | |
| 871 | /* |
| 872 | * For drivers that can... |
| 873 | */ |
| 874 | pm3fb_check_var(&info->var, info); |
| 875 | |
| 876 | if (register_framebuffer(info) < 0) { |
| 877 | retval = -EINVAL; |
| 878 | goto err_exit_all; |
| 879 | } |
| 880 | printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, |
| 881 | info->fix.id); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 882 | pci_set_drvdata(dev, info); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 883 | return 0; |
| 884 | |
| 885 | err_exit_all: |
| 886 | fb_dealloc_cmap(&info->cmap); |
| 887 | err_exit_both: |
| 888 | iounmap(info->screen_base); |
| 889 | release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 890 | err_exit_mmio: |
| 891 | iounmap(par->v_regs); |
| 892 | release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len); |
| 893 | err_exit_neither: |
| 894 | framebuffer_release(info); |
| 895 | return retval; |
| 896 | } |
| 897 | |
| 898 | /* |
| 899 | * Cleanup |
| 900 | */ |
| 901 | static void __devexit pm3fb_remove(struct pci_dev *dev) |
| 902 | { |
| 903 | struct fb_info *info = pci_get_drvdata(dev); |
| 904 | |
| 905 | if (info) { |
| 906 | struct fb_fix_screeninfo *fix = &info->fix; |
| 907 | struct pm3_par *par = info->par; |
| 908 | |
| 909 | unregister_framebuffer(info); |
| 910 | fb_dealloc_cmap(&info->cmap); |
| 911 | |
| 912 | iounmap(info->screen_base); |
| 913 | release_mem_region(fix->smem_start, fix->smem_len); |
| 914 | iounmap(par->v_regs); |
| 915 | release_mem_region(fix->mmio_start, fix->mmio_len); |
| 916 | |
| 917 | pci_set_drvdata(dev, NULL); |
| 918 | framebuffer_release(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 922 | static struct pci_device_id pm3fb_id_table[] = { |
| 923 | { PCI_VENDOR_ID_3DLABS, 0x0a, |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 924 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 925 | { 0, } |
| 926 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 928 | /* For PCI drivers */ |
| 929 | static struct pci_driver pm3fb_driver = { |
| 930 | .name = "pm3fb", |
| 931 | .id_table = pm3fb_id_table, |
| 932 | .probe = pm3fb_probe, |
| 933 | .remove = __devexit_p(pm3fb_remove), |
| 934 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 936 | MODULE_DEVICE_TABLE(pci, pm3fb_id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame^] | 938 | #ifndef MODULE |
| 939 | /* |
| 940 | * Setup |
| 941 | */ |
| 942 | |
| 943 | /* |
| 944 | * Only necessary if your driver takes special options, |
| 945 | * otherwise we fall back on the generic fb_setup(). |
| 946 | */ |
| 947 | static int __init pm3fb_setup(char *options) |
| 948 | { |
| 949 | /* Parse user speficied options (`video=pm3fb:') */ |
| 950 | return 0; |
| 951 | } |
| 952 | #endif /* MODULE */ |
| 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | int __init pm3fb_init(void) |
| 955 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 956 | /* |
| 957 | * For kernel boot options (in 'video=pm3fb:<options>' format) |
| 958 | */ |
| 959 | #ifndef MODULE |
| 960 | char *option = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 962 | if (fb_get_options("pm3fb", &option)) |
| 963 | return -ENODEV; |
| 964 | pm3fb_setup(option); |
| 965 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 967 | return pci_register_driver(&pm3fb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 970 | static void __exit pm3fb_exit(void) |
| 971 | { |
| 972 | pci_unregister_driver(&pm3fb_driver); |
| 973 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 975 | module_init(pm3fb_init); |
| 976 | module_exit(pm3fb_exit); |
| 977 | |
| 978 | MODULE_LICENSE("GPL"); |