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 |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 44 | #define DPRINTK(a, b...) \ |
Harvey Harrison | 5ae1217 | 2008-04-28 02:15:47 -0700 | [diff] [blame] | 45 | printk(KERN_DEBUG "pm3fb: %s: " a, __func__ , ## b) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 46 | #else |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 47 | #define DPRINTK(a, b...) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 48 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Krzysztof Helt | b0a318e | 2007-10-16 01:28:31 -0700 | [diff] [blame] | 50 | #define PM3_PIXMAP_SIZE (2048 * 4) |
| 51 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 52 | /* |
| 53 | * Driver data |
| 54 | */ |
Krzysztof Helt | 1d677a6 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 55 | static int hwcursor = 1; |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 56 | static char *mode_option; |
| 57 | static bool noaccel; |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 58 | static bool nomtrr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 60 | /* |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 61 | * This structure defines the hardware state of the graphics card. Normally |
| 62 | * you place this in a header file in linux/include/video. This file usually |
| 63 | * also includes register information. That allows other driver subsystems |
| 64 | * and userland applications the ability to use the same header file to |
| 65 | * avoid duplicate work and easy porting of software. |
| 66 | */ |
| 67 | struct pm3_par { |
| 68 | unsigned char __iomem *v_regs;/* virtual address of p_regs */ |
| 69 | u32 video; /* video flags before blanking */ |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 70 | u32 base; /* screen base in 128 bits unit */ |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 71 | u32 palette[16]; |
Luis R. Rodriguez | 26e2506 | 2015-04-21 13:16:34 -0700 | [diff] [blame] | 72 | int wc_cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 75 | /* |
| 76 | * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo |
| 77 | * if we don't use modedb. If we do use modedb see pm3fb_init how to use it |
| 78 | * to get a fb_var_screeninfo. Otherwise define a default var as well. |
| 79 | */ |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 80 | static struct fb_fix_screeninfo pm3fb_fix = { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 81 | .id = "Permedia3", |
| 82 | .type = FB_TYPE_PACKED_PIXELS, |
| 83 | .visual = FB_VISUAL_PSEUDOCOLOR, |
| 84 | .xpanstep = 1, |
| 85 | .ypanstep = 1, |
| 86 | .ywrapstep = 0, |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 87 | .accel = FB_ACCEL_3DLABS_PERMEDIA3, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /* |
| 91 | * Utility functions |
| 92 | */ |
| 93 | |
| 94 | static inline u32 PM3_READ_REG(struct pm3_par *par, s32 off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 96 | return fb_readl(par->v_regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 99 | 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] | 100 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 101 | fb_writel(v, par->v_regs + off); |
| 102 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 104 | static inline void PM3_WAIT(struct pm3_par *par, u32 n) |
| 105 | { |
Krzysztof Helt | deea62d | 2007-10-16 01:29:27 -0700 | [diff] [blame] | 106 | while (PM3_READ_REG(par, PM3InFIFOSpace) < n) |
| 107 | cpu_relax(); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 110 | 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] | 111 | { |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 112 | PM3_WAIT(par, 3); |
| 113 | PM3_WRITE_REG(par, PM3RD_IndexHigh, (r >> 8) & 0xff); |
| 114 | PM3_WRITE_REG(par, PM3RD_IndexLow, r & 0xff); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 115 | wmb(); |
| 116 | PM3_WRITE_REG(par, PM3RD_IndexedData, v); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 117 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 120 | static inline void pm3fb_set_color(struct pm3_par *par, unsigned char regno, |
| 121 | unsigned char r, unsigned char g, unsigned char b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 123 | PM3_WAIT(par, 4); |
| 124 | PM3_WRITE_REG(par, PM3RD_PaletteWriteAddress, regno); |
| 125 | wmb(); |
| 126 | PM3_WRITE_REG(par, PM3RD_PaletteData, r); |
| 127 | wmb(); |
| 128 | PM3_WRITE_REG(par, PM3RD_PaletteData, g); |
| 129 | wmb(); |
| 130 | PM3_WRITE_REG(par, PM3RD_PaletteData, b); |
| 131 | wmb(); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static void pm3fb_clear_colormap(struct pm3_par *par, |
| 135 | unsigned char r, unsigned char g, unsigned char b) |
| 136 | { |
| 137 | int i; |
| 138 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 139 | for (i = 0; i < 256 ; i++) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 140 | pm3fb_set_color(par, i, r, g, b); |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 144 | /* Calculating various clock parameters */ |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 145 | static void pm3fb_calculate_clock(unsigned long reqclock, |
| 146 | unsigned char *prescale, |
| 147 | unsigned char *feedback, |
| 148 | unsigned char *postscale) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
| 150 | int f, pre, post; |
| 151 | unsigned long freq; |
| 152 | long freqerr = 1000; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 153 | long currerr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | for (f = 1; f < 256; f++) { |
| 156 | for (pre = 1; pre < 256; pre++) { |
| 157 | for (post = 0; post < 5; post++) { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 158 | freq = ((2*PM3_REF_CLOCK * f) >> post) / pre; |
| 159 | currerr = (reqclock > freq) |
| 160 | ? reqclock - freq |
| 161 | : freq - reqclock; |
| 162 | if (currerr < freqerr) { |
| 163 | freqerr = currerr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | *feedback = f; |
| 165 | *prescale = pre; |
| 166 | *postscale = post; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | } |
| 170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 173 | static inline int pm3fb_depth(const struct fb_var_screeninfo *var) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 175 | if (var->bits_per_pixel == 16) |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 176 | return var->red.length + var->green.length |
| 177 | + var->blue.length; |
| 178 | |
| 179 | return var->bits_per_pixel; |
| 180 | } |
| 181 | |
| 182 | static inline int pm3fb_shift_bpp(unsigned bpp, int v) |
| 183 | { |
| 184 | switch (bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | case 8: |
| 186 | return (v >> 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | case 16: |
| 188 | return (v >> 3); |
| 189 | case 32: |
| 190 | return (v >> 2); |
| 191 | } |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 192 | DPRINTK("Unsupported depth %u\n", bpp); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 193 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 196 | /* acceleration */ |
| 197 | static int pm3fb_sync(struct fb_info *info) |
| 198 | { |
| 199 | struct pm3_par *par = info->par; |
| 200 | |
| 201 | PM3_WAIT(par, 2); |
| 202 | PM3_WRITE_REG(par, PM3FilterMode, PM3FilterModeSync); |
| 203 | PM3_WRITE_REG(par, PM3Sync, 0); |
| 204 | mb(); |
| 205 | do { |
Krzysztof Helt | deea62d | 2007-10-16 01:29:27 -0700 | [diff] [blame] | 206 | while ((PM3_READ_REG(par, PM3OutFIFOWords)) == 0) |
| 207 | cpu_relax(); |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 208 | } while ((PM3_READ_REG(par, PM3OutputFifo)) != PM3Sync_Tag); |
| 209 | |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | static void pm3fb_init_engine(struct fb_info *info) |
| 214 | { |
| 215 | struct pm3_par *par = info->par; |
| 216 | const u32 width = (info->var.xres_virtual + 7) & ~7; |
| 217 | |
| 218 | PM3_WAIT(par, 50); |
| 219 | PM3_WRITE_REG(par, PM3FilterMode, PM3FilterModeSync); |
| 220 | PM3_WRITE_REG(par, PM3StatisticMode, 0x0); |
| 221 | PM3_WRITE_REG(par, PM3DeltaMode, 0x0); |
| 222 | PM3_WRITE_REG(par, PM3RasterizerMode, 0x0); |
| 223 | PM3_WRITE_REG(par, PM3ScissorMode, 0x0); |
| 224 | PM3_WRITE_REG(par, PM3LineStippleMode, 0x0); |
| 225 | PM3_WRITE_REG(par, PM3AreaStippleMode, 0x0); |
| 226 | PM3_WRITE_REG(par, PM3GIDMode, 0x0); |
| 227 | PM3_WRITE_REG(par, PM3DepthMode, 0x0); |
| 228 | PM3_WRITE_REG(par, PM3StencilMode, 0x0); |
| 229 | PM3_WRITE_REG(par, PM3StencilData, 0x0); |
| 230 | PM3_WRITE_REG(par, PM3ColorDDAMode, 0x0); |
| 231 | PM3_WRITE_REG(par, PM3TextureCoordMode, 0x0); |
| 232 | PM3_WRITE_REG(par, PM3TextureIndexMode0, 0x0); |
| 233 | PM3_WRITE_REG(par, PM3TextureIndexMode1, 0x0); |
| 234 | PM3_WRITE_REG(par, PM3TextureReadMode, 0x0); |
| 235 | PM3_WRITE_REG(par, PM3LUTMode, 0x0); |
| 236 | PM3_WRITE_REG(par, PM3TextureFilterMode, 0x0); |
| 237 | PM3_WRITE_REG(par, PM3TextureCompositeMode, 0x0); |
| 238 | PM3_WRITE_REG(par, PM3TextureApplicationMode, 0x0); |
| 239 | PM3_WRITE_REG(par, PM3TextureCompositeColorMode1, 0x0); |
| 240 | PM3_WRITE_REG(par, PM3TextureCompositeAlphaMode1, 0x0); |
| 241 | PM3_WRITE_REG(par, PM3TextureCompositeColorMode0, 0x0); |
| 242 | PM3_WRITE_REG(par, PM3TextureCompositeAlphaMode0, 0x0); |
| 243 | PM3_WRITE_REG(par, PM3FogMode, 0x0); |
| 244 | PM3_WRITE_REG(par, PM3ChromaTestMode, 0x0); |
| 245 | PM3_WRITE_REG(par, PM3AlphaTestMode, 0x0); |
| 246 | PM3_WRITE_REG(par, PM3AntialiasMode, 0x0); |
| 247 | PM3_WRITE_REG(par, PM3YUVMode, 0x0); |
| 248 | PM3_WRITE_REG(par, PM3AlphaBlendColorMode, 0x0); |
| 249 | PM3_WRITE_REG(par, PM3AlphaBlendAlphaMode, 0x0); |
| 250 | PM3_WRITE_REG(par, PM3DitherMode, 0x0); |
| 251 | PM3_WRITE_REG(par, PM3LogicalOpMode, 0x0); |
| 252 | PM3_WRITE_REG(par, PM3RouterMode, 0x0); |
| 253 | PM3_WRITE_REG(par, PM3Window, 0x0); |
| 254 | |
| 255 | PM3_WRITE_REG(par, PM3Config2D, 0x0); |
| 256 | |
| 257 | PM3_WRITE_REG(par, PM3SpanColorMask, 0xffffffff); |
| 258 | |
| 259 | PM3_WRITE_REG(par, PM3XBias, 0x0); |
| 260 | PM3_WRITE_REG(par, PM3YBias, 0x0); |
| 261 | PM3_WRITE_REG(par, PM3DeltaControl, 0x0); |
| 262 | |
| 263 | PM3_WRITE_REG(par, PM3BitMaskPattern, 0xffffffff); |
| 264 | |
| 265 | PM3_WRITE_REG(par, PM3FBDestReadEnables, |
| 266 | PM3FBDestReadEnables_E(0xff) | |
| 267 | PM3FBDestReadEnables_R(0xff) | |
| 268 | PM3FBDestReadEnables_ReferenceAlpha(0xff)); |
| 269 | PM3_WRITE_REG(par, PM3FBDestReadBufferAddr0, 0x0); |
| 270 | PM3_WRITE_REG(par, PM3FBDestReadBufferOffset0, 0x0); |
| 271 | PM3_WRITE_REG(par, PM3FBDestReadBufferWidth0, |
| 272 | PM3FBDestReadBufferWidth_Width(width)); |
| 273 | |
| 274 | PM3_WRITE_REG(par, PM3FBDestReadMode, |
| 275 | PM3FBDestReadMode_ReadEnable | |
| 276 | PM3FBDestReadMode_Enable0); |
| 277 | PM3_WRITE_REG(par, PM3FBSourceReadBufferAddr, 0x0); |
| 278 | PM3_WRITE_REG(par, PM3FBSourceReadBufferOffset, 0x0); |
| 279 | PM3_WRITE_REG(par, PM3FBSourceReadBufferWidth, |
| 280 | PM3FBSourceReadBufferWidth_Width(width)); |
| 281 | PM3_WRITE_REG(par, PM3FBSourceReadMode, |
| 282 | PM3FBSourceReadMode_Blocking | |
| 283 | PM3FBSourceReadMode_ReadEnable); |
| 284 | |
| 285 | PM3_WAIT(par, 2); |
| 286 | { |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 287 | /* invert bits in bitmask */ |
| 288 | unsigned long rm = 1 | (3 << 7); |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 289 | switch (info->var.bits_per_pixel) { |
| 290 | case 8: |
| 291 | PM3_WRITE_REG(par, PM3PixelSize, |
| 292 | PM3PixelSize_GLOBAL_8BIT); |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 293 | #ifdef __BIG_ENDIAN |
| 294 | rm |= 3 << 15; |
| 295 | #endif |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 296 | break; |
| 297 | case 16: |
| 298 | PM3_WRITE_REG(par, PM3PixelSize, |
| 299 | PM3PixelSize_GLOBAL_16BIT); |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 300 | #ifdef __BIG_ENDIAN |
| 301 | rm |= 2 << 15; |
| 302 | #endif |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 303 | break; |
| 304 | case 32: |
| 305 | PM3_WRITE_REG(par, PM3PixelSize, |
| 306 | PM3PixelSize_GLOBAL_32BIT); |
| 307 | break; |
| 308 | default: |
| 309 | DPRINTK(1, "Unsupported depth %d\n", |
| 310 | info->var.bits_per_pixel); |
| 311 | break; |
| 312 | } |
| 313 | PM3_WRITE_REG(par, PM3RasterizerMode, rm); |
| 314 | } |
| 315 | |
| 316 | PM3_WAIT(par, 20); |
| 317 | PM3_WRITE_REG(par, PM3FBSoftwareWriteMask, 0xffffffff); |
| 318 | PM3_WRITE_REG(par, PM3FBHardwareWriteMask, 0xffffffff); |
| 319 | PM3_WRITE_REG(par, PM3FBWriteMode, |
| 320 | PM3FBWriteMode_WriteEnable | |
| 321 | PM3FBWriteMode_OpaqueSpan | |
| 322 | PM3FBWriteMode_Enable0); |
| 323 | PM3_WRITE_REG(par, PM3FBWriteBufferAddr0, 0x0); |
| 324 | PM3_WRITE_REG(par, PM3FBWriteBufferOffset0, 0x0); |
| 325 | PM3_WRITE_REG(par, PM3FBWriteBufferWidth0, |
| 326 | PM3FBWriteBufferWidth_Width(width)); |
| 327 | |
| 328 | PM3_WRITE_REG(par, PM3SizeOfFramebuffer, 0x0); |
| 329 | { |
| 330 | /* size in lines of FB */ |
| 331 | unsigned long sofb = info->screen_size / |
| 332 | info->fix.line_length; |
| 333 | if (sofb > 4095) |
| 334 | PM3_WRITE_REG(par, PM3SizeOfFramebuffer, 4095); |
| 335 | else |
| 336 | PM3_WRITE_REG(par, PM3SizeOfFramebuffer, sofb); |
| 337 | |
| 338 | switch (info->var.bits_per_pixel) { |
| 339 | case 8: |
| 340 | PM3_WRITE_REG(par, PM3DitherMode, |
| 341 | (1 << 10) | (2 << 3)); |
| 342 | break; |
| 343 | case 16: |
| 344 | PM3_WRITE_REG(par, PM3DitherMode, |
| 345 | (1 << 10) | (1 << 3)); |
| 346 | break; |
| 347 | case 32: |
| 348 | PM3_WRITE_REG(par, PM3DitherMode, |
| 349 | (1 << 10) | (0 << 3)); |
| 350 | break; |
| 351 | default: |
| 352 | DPRINTK(1, "Unsupported depth %d\n", |
| 353 | info->current_par->depth); |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | PM3_WRITE_REG(par, PM3dXDom, 0x0); |
| 359 | PM3_WRITE_REG(par, PM3dXSub, 0x0); |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 360 | PM3_WRITE_REG(par, PM3dY, 1 << 16); |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 361 | PM3_WRITE_REG(par, PM3StartXDom, 0x0); |
| 362 | PM3_WRITE_REG(par, PM3StartXSub, 0x0); |
| 363 | PM3_WRITE_REG(par, PM3StartY, 0x0); |
| 364 | PM3_WRITE_REG(par, PM3Count, 0x0); |
| 365 | |
| 366 | /* Disable LocalBuffer. better safe than sorry */ |
| 367 | PM3_WRITE_REG(par, PM3LBDestReadMode, 0x0); |
| 368 | PM3_WRITE_REG(par, PM3LBDestReadEnables, 0x0); |
| 369 | PM3_WRITE_REG(par, PM3LBSourceReadMode, 0x0); |
| 370 | PM3_WRITE_REG(par, PM3LBWriteMode, 0x0); |
| 371 | |
| 372 | pm3fb_sync(info); |
| 373 | } |
| 374 | |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 375 | static void pm3fb_fillrect(struct fb_info *info, |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 376 | const struct fb_fillrect *region) |
| 377 | { |
| 378 | struct pm3_par *par = info->par; |
| 379 | struct fb_fillrect modded; |
| 380 | int vxres, vyres; |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 381 | int rop; |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 382 | u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ? |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 383 | ((u32 *)info->pseudo_palette)[region->color] : region->color; |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 384 | |
| 385 | if (info->state != FBINFO_STATE_RUNNING) |
| 386 | return; |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 387 | if (info->flags & FBINFO_HWACCEL_DISABLED) { |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 388 | cfb_fillrect(info, region); |
| 389 | return; |
| 390 | } |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 391 | if (region->rop == ROP_COPY ) |
| 392 | rop = PM3Config2D_ForegroundROP(0x3); /* GXcopy */ |
| 393 | else |
| 394 | rop = PM3Config2D_ForegroundROP(0x6) | /* GXxor */ |
| 395 | PM3Config2D_FBDestReadEnable; |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 396 | |
| 397 | vxres = info->var.xres_virtual; |
| 398 | vyres = info->var.yres_virtual; |
| 399 | |
| 400 | memcpy(&modded, region, sizeof(struct fb_fillrect)); |
| 401 | |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 402 | if (!modded.width || !modded.height || |
| 403 | modded.dx >= vxres || modded.dy >= vyres) |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 404 | return; |
| 405 | |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 406 | if (modded.dx + modded.width > vxres) |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 407 | modded.width = vxres - modded.dx; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 408 | if (modded.dy + modded.height > vyres) |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 409 | modded.height = vyres - modded.dy; |
| 410 | |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 411 | if (info->var.bits_per_pixel == 8) |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 412 | color |= color << 8; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 413 | if (info->var.bits_per_pixel <= 16) |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 414 | color |= color << 16; |
| 415 | |
| 416 | PM3_WAIT(par, 4); |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 417 | /* ROP Ox3 is GXcopy */ |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 418 | PM3_WRITE_REG(par, PM3Config2D, |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 419 | PM3Config2D_UseConstantSource | |
| 420 | PM3Config2D_ForegroundROPEnable | |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 421 | rop | |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 422 | PM3Config2D_FBWriteEnable); |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 423 | |
| 424 | PM3_WRITE_REG(par, PM3ForegroundColor, color); |
| 425 | |
| 426 | PM3_WRITE_REG(par, PM3RectanglePosition, |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 427 | PM3RectanglePosition_XOffset(modded.dx) | |
| 428 | PM3RectanglePosition_YOffset(modded.dy)); |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 429 | |
| 430 | PM3_WRITE_REG(par, PM3Render2D, |
| 431 | PM3Render2D_XPositive | |
| 432 | PM3Render2D_YPositive | |
| 433 | PM3Render2D_Operation_Normal | |
| 434 | PM3Render2D_SpanOperation | |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 435 | PM3Render2D_Width(modded.width) | |
| 436 | PM3Render2D_Height(modded.height)); |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 437 | } |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 438 | |
| 439 | static void pm3fb_copyarea(struct fb_info *info, |
| 440 | const struct fb_copyarea *area) |
| 441 | { |
| 442 | struct pm3_par *par = info->par; |
| 443 | struct fb_copyarea modded; |
| 444 | u32 vxres, vyres; |
| 445 | int x_align, o_x, o_y; |
| 446 | |
| 447 | if (info->state != FBINFO_STATE_RUNNING) |
| 448 | return; |
| 449 | if (info->flags & FBINFO_HWACCEL_DISABLED) { |
| 450 | cfb_copyarea(info, area); |
| 451 | return; |
| 452 | } |
| 453 | |
| 454 | memcpy(&modded, area, sizeof(struct fb_copyarea)); |
| 455 | |
| 456 | vxres = info->var.xres_virtual; |
| 457 | vyres = info->var.yres_virtual; |
| 458 | |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 459 | if (!modded.width || !modded.height || |
| 460 | modded.sx >= vxres || modded.sy >= vyres || |
| 461 | modded.dx >= vxres || modded.dy >= vyres) |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 462 | return; |
| 463 | |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 464 | if (modded.sx + modded.width > vxres) |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 465 | modded.width = vxres - modded.sx; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 466 | if (modded.dx + modded.width > vxres) |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 467 | modded.width = vxres - modded.dx; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 468 | if (modded.sy + modded.height > vyres) |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 469 | modded.height = vyres - modded.sy; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 470 | if (modded.dy + modded.height > vyres) |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 471 | modded.height = vyres - modded.dy; |
| 472 | |
| 473 | o_x = modded.sx - modded.dx; /*(sx > dx ) ? (sx - dx) : (dx - sx); */ |
| 474 | o_y = modded.sy - modded.dy; /*(sy > dy ) ? (sy - dy) : (dy - sy); */ |
| 475 | |
| 476 | x_align = (modded.sx & 0x1f); |
| 477 | |
| 478 | PM3_WAIT(par, 6); |
| 479 | |
| 480 | PM3_WRITE_REG(par, PM3Config2D, |
| 481 | PM3Config2D_UserScissorEnable | |
| 482 | PM3Config2D_ForegroundROPEnable | |
| 483 | PM3Config2D_Blocking | |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 484 | PM3Config2D_ForegroundROP(0x3) | /* Ox3 is GXcopy */ |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 485 | PM3Config2D_FBWriteEnable); |
| 486 | |
| 487 | PM3_WRITE_REG(par, PM3ScissorMinXY, |
| 488 | ((modded.dy & 0x0fff) << 16) | (modded.dx & 0x0fff)); |
| 489 | PM3_WRITE_REG(par, PM3ScissorMaxXY, |
| 490 | (((modded.dy + modded.height) & 0x0fff) << 16) | |
| 491 | ((modded.dx + modded.width) & 0x0fff)); |
| 492 | |
| 493 | PM3_WRITE_REG(par, PM3FBSourceReadBufferOffset, |
| 494 | PM3FBSourceReadBufferOffset_XOffset(o_x) | |
| 495 | PM3FBSourceReadBufferOffset_YOffset(o_y)); |
| 496 | |
| 497 | PM3_WRITE_REG(par, PM3RectanglePosition, |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 498 | PM3RectanglePosition_XOffset(modded.dx - x_align) | |
| 499 | PM3RectanglePosition_YOffset(modded.dy)); |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 500 | |
| 501 | PM3_WRITE_REG(par, PM3Render2D, |
| 502 | ((modded.sx > modded.dx) ? PM3Render2D_XPositive : 0) | |
| 503 | ((modded.sy > modded.dy) ? PM3Render2D_YPositive : 0) | |
| 504 | PM3Render2D_Operation_Normal | |
| 505 | PM3Render2D_SpanOperation | |
| 506 | PM3Render2D_FBSourceReadEnable | |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 507 | PM3Render2D_Width(modded.width + x_align) | |
| 508 | PM3Render2D_Height(modded.height)); |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static void pm3fb_imageblit(struct fb_info *info, const struct fb_image *image) |
| 512 | { |
| 513 | struct pm3_par *par = info->par; |
| 514 | u32 height = image->height; |
| 515 | u32 fgx, bgx; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 516 | const u32 *src = (const u32 *)image->data; |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 517 | |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 518 | if (info->state != FBINFO_STATE_RUNNING) |
| 519 | return; |
| 520 | if (info->flags & FBINFO_HWACCEL_DISABLED) { |
| 521 | cfb_imageblit(info, image); |
| 522 | return; |
| 523 | } |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 524 | switch (info->fix.visual) { |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 525 | case FB_VISUAL_PSEUDOCOLOR: |
| 526 | fgx = image->fg_color; |
| 527 | bgx = image->bg_color; |
| 528 | break; |
| 529 | case FB_VISUAL_TRUECOLOR: |
| 530 | default: |
| 531 | fgx = par->palette[image->fg_color]; |
| 532 | bgx = par->palette[image->bg_color]; |
| 533 | break; |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 534 | } |
Hannes Eder | 7654532 | 2009-01-06 14:42:33 -0800 | [diff] [blame] | 535 | if (image->depth != 1) { |
| 536 | cfb_imageblit(info, image); |
| 537 | return; |
| 538 | } |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 539 | |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 540 | if (info->var.bits_per_pixel == 8) { |
| 541 | fgx |= fgx << 8; |
| 542 | bgx |= bgx << 8; |
| 543 | } |
| 544 | if (info->var.bits_per_pixel <= 16) { |
| 545 | fgx |= fgx << 16; |
| 546 | bgx |= bgx << 16; |
| 547 | } |
| 548 | |
Krzysztof Helt | b0a318e | 2007-10-16 01:28:31 -0700 | [diff] [blame] | 549 | PM3_WAIT(par, 7); |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 550 | |
| 551 | PM3_WRITE_REG(par, PM3ForegroundColor, fgx); |
| 552 | PM3_WRITE_REG(par, PM3BackgroundColor, bgx); |
| 553 | |
| 554 | /* ROP Ox3 is GXcopy */ |
| 555 | PM3_WRITE_REG(par, PM3Config2D, |
Krzysztof Helt | b0a318e | 2007-10-16 01:28:31 -0700 | [diff] [blame] | 556 | PM3Config2D_UserScissorEnable | |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 557 | PM3Config2D_UseConstantSource | |
| 558 | PM3Config2D_ForegroundROPEnable | |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 559 | PM3Config2D_ForegroundROP(0x3) | |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 560 | PM3Config2D_OpaqueSpan | |
| 561 | PM3Config2D_FBWriteEnable); |
Krzysztof Helt | b0a318e | 2007-10-16 01:28:31 -0700 | [diff] [blame] | 562 | PM3_WRITE_REG(par, PM3ScissorMinXY, |
| 563 | ((image->dy & 0x0fff) << 16) | (image->dx & 0x0fff)); |
| 564 | PM3_WRITE_REG(par, PM3ScissorMaxXY, |
| 565 | (((image->dy + image->height) & 0x0fff) << 16) | |
| 566 | ((image->dx + image->width) & 0x0fff)); |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 567 | PM3_WRITE_REG(par, PM3RectanglePosition, |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 568 | PM3RectanglePosition_XOffset(image->dx) | |
| 569 | PM3RectanglePosition_YOffset(image->dy)); |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 570 | PM3_WRITE_REG(par, PM3Render2D, |
| 571 | PM3Render2D_XPositive | |
| 572 | PM3Render2D_YPositive | |
| 573 | PM3Render2D_Operation_SyncOnBitMask | |
| 574 | PM3Render2D_SpanOperation | |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 575 | PM3Render2D_Width(image->width) | |
| 576 | PM3Render2D_Height(image->height)); |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 577 | |
| 578 | |
| 579 | while (height--) { |
Krzysztof Helt | c79ba28 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 580 | int width = ((image->width + 7) >> 3) |
| 581 | + info->pixmap.scan_align - 1; |
Krzysztof Helt | b0a318e | 2007-10-16 01:28:31 -0700 | [diff] [blame] | 582 | width >>= 2; |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 583 | |
| 584 | while (width >= PM3_FIFO_SIZE) { |
| 585 | int i = PM3_FIFO_SIZE - 1; |
| 586 | |
| 587 | PM3_WAIT(par, PM3_FIFO_SIZE); |
| 588 | while (i--) { |
| 589 | PM3_WRITE_REG(par, PM3BitMaskPattern, *src); |
| 590 | src++; |
| 591 | } |
| 592 | width -= PM3_FIFO_SIZE - 1; |
| 593 | } |
| 594 | |
| 595 | PM3_WAIT(par, width + 1); |
| 596 | while (width--) { |
| 597 | PM3_WRITE_REG(par, PM3BitMaskPattern, *src); |
| 598 | src++; |
| 599 | } |
| 600 | } |
| 601 | } |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 602 | /* end of acceleration functions */ |
| 603 | |
Krzysztof Helt | 1d677a6 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 604 | /* |
| 605 | * Hardware Cursor support. |
| 606 | */ |
| 607 | static const u8 cursor_bits_lookup[16] = { |
| 608 | 0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54, |
| 609 | 0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55 |
| 610 | }; |
| 611 | |
| 612 | static int pm3fb_cursor(struct fb_info *info, struct fb_cursor *cursor) |
| 613 | { |
| 614 | struct pm3_par *par = info->par; |
| 615 | u8 mode; |
| 616 | |
| 617 | if (!hwcursor) |
| 618 | return -EINVAL; /* just to force soft_cursor() call */ |
| 619 | |
| 620 | /* Too large of a cursor or wrong bpp :-( */ |
| 621 | if (cursor->image.width > 64 || |
| 622 | cursor->image.height > 64 || |
| 623 | cursor->image.depth > 1) |
| 624 | return -EINVAL; |
| 625 | |
| 626 | mode = PM3RD_CursorMode_TYPE_X; |
| 627 | if (cursor->enable) |
| 628 | mode |= PM3RD_CursorMode_CURSOR_ENABLE; |
| 629 | |
| 630 | PM3_WRITE_DAC_REG(par, PM3RD_CursorMode, mode); |
| 631 | |
| 632 | /* |
| 633 | * If the cursor is not be changed this means either we want the |
| 634 | * current cursor state (if enable is set) or we want to query what |
| 635 | * we can do with the cursor (if enable is not set) |
| 636 | */ |
| 637 | if (!cursor->set) |
| 638 | return 0; |
| 639 | |
| 640 | if (cursor->set & FB_CUR_SETPOS) { |
| 641 | int x = cursor->image.dx - info->var.xoffset; |
| 642 | int y = cursor->image.dy - info->var.yoffset; |
| 643 | |
| 644 | PM3_WRITE_DAC_REG(par, PM3RD_CursorXLow, x & 0xff); |
| 645 | PM3_WRITE_DAC_REG(par, PM3RD_CursorXHigh, (x >> 8) & 0xf); |
| 646 | PM3_WRITE_DAC_REG(par, PM3RD_CursorYLow, y & 0xff); |
| 647 | PM3_WRITE_DAC_REG(par, PM3RD_CursorYHigh, (y >> 8) & 0xf); |
| 648 | } |
| 649 | |
| 650 | if (cursor->set & FB_CUR_SETHOT) { |
| 651 | PM3_WRITE_DAC_REG(par, PM3RD_CursorHotSpotX, |
| 652 | cursor->hot.x & 0x3f); |
| 653 | PM3_WRITE_DAC_REG(par, PM3RD_CursorHotSpotY, |
| 654 | cursor->hot.y & 0x3f); |
| 655 | } |
| 656 | |
| 657 | if (cursor->set & FB_CUR_SETCMAP) { |
| 658 | u32 fg_idx = cursor->image.fg_color; |
| 659 | u32 bg_idx = cursor->image.bg_color; |
| 660 | struct fb_cmap cmap = info->cmap; |
| 661 | |
| 662 | /* the X11 driver says one should use these color registers */ |
| 663 | PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(39), |
| 664 | cmap.red[fg_idx] >> 8 ); |
| 665 | PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(40), |
| 666 | cmap.green[fg_idx] >> 8 ); |
| 667 | PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(41), |
| 668 | cmap.blue[fg_idx] >> 8 ); |
| 669 | |
| 670 | PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(42), |
| 671 | cmap.red[bg_idx] >> 8 ); |
| 672 | PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(43), |
| 673 | cmap.green[bg_idx] >> 8 ); |
| 674 | PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(44), |
| 675 | cmap.blue[bg_idx] >> 8 ); |
| 676 | } |
| 677 | |
| 678 | if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) { |
| 679 | u8 *bitmap = (u8 *)cursor->image.data; |
| 680 | u8 *mask = (u8 *)cursor->mask; |
| 681 | int i; |
| 682 | int pos = PM3RD_CursorPattern(0); |
| 683 | |
| 684 | for (i = 0; i < cursor->image.height; i++) { |
| 685 | int j = (cursor->image.width + 7) >> 3; |
| 686 | int k = 8 - j; |
| 687 | |
| 688 | for (; j > 0; j--) { |
| 689 | u8 data = *bitmap ^ *mask; |
| 690 | |
| 691 | if (cursor->rop == ROP_COPY) |
| 692 | data = *mask & *bitmap; |
| 693 | /* Upper 4 bits of bitmap data */ |
| 694 | PM3_WRITE_DAC_REG(par, pos++, |
| 695 | cursor_bits_lookup[data >> 4] | |
| 696 | (cursor_bits_lookup[*mask >> 4] << 1)); |
| 697 | /* Lower 4 bits of bitmap */ |
| 698 | PM3_WRITE_DAC_REG(par, pos++, |
| 699 | cursor_bits_lookup[data & 0xf] | |
| 700 | (cursor_bits_lookup[*mask & 0xf] << 1)); |
| 701 | bitmap++; |
| 702 | mask++; |
| 703 | } |
| 704 | for (; k > 0; k--) { |
| 705 | PM3_WRITE_DAC_REG(par, pos++, 0); |
| 706 | PM3_WRITE_DAC_REG(par, pos++, 0); |
| 707 | } |
| 708 | } |
| 709 | while (pos < PM3RD_CursorPattern(1024)) |
| 710 | PM3_WRITE_DAC_REG(par, pos++, 0); |
| 711 | } |
| 712 | return 0; |
| 713 | } |
| 714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | /* write the mode to registers */ |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 716 | static void pm3fb_write_mode(struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 718 | struct pm3_par *par = info->par; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 719 | char tempsync = 0x00; |
| 720 | char tempmisc = 0x00; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 721 | const u32 hsstart = info->var.right_margin; |
| 722 | const u32 hsend = hsstart + info->var.hsync_len; |
| 723 | const u32 hbend = hsend + info->var.left_margin; |
| 724 | const u32 xres = (info->var.xres + 31) & ~31; |
| 725 | const u32 htotal = xres + hbend; |
| 726 | const u32 vsstart = info->var.lower_margin; |
| 727 | const u32 vsend = vsstart + info->var.vsync_len; |
| 728 | const u32 vbend = vsend + info->var.upper_margin; |
| 729 | const u32 vtotal = info->var.yres + vbend; |
| 730 | const u32 width = (info->var.xres_virtual + 7) & ~7; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 731 | const unsigned bpp = info->var.bits_per_pixel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 733 | PM3_WAIT(par, 20); |
| 734 | PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xffffffff); |
| 735 | PM3_WRITE_REG(par, PM3Aperture0, 0x00000000); |
| 736 | PM3_WRITE_REG(par, PM3Aperture1, 0x00000000); |
| 737 | PM3_WRITE_REG(par, PM3FIFODis, 0x00000007); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 739 | PM3_WRITE_REG(par, PM3HTotal, |
| 740 | pm3fb_shift_bpp(bpp, htotal - 1)); |
| 741 | PM3_WRITE_REG(par, PM3HsEnd, |
| 742 | pm3fb_shift_bpp(bpp, hsend)); |
| 743 | PM3_WRITE_REG(par, PM3HsStart, |
| 744 | pm3fb_shift_bpp(bpp, hsstart)); |
| 745 | PM3_WRITE_REG(par, PM3HbEnd, |
| 746 | pm3fb_shift_bpp(bpp, hbend)); |
| 747 | PM3_WRITE_REG(par, PM3HgEnd, |
| 748 | pm3fb_shift_bpp(bpp, hbend)); |
| 749 | PM3_WRITE_REG(par, PM3ScreenStride, |
| 750 | pm3fb_shift_bpp(bpp, width)); |
| 751 | PM3_WRITE_REG(par, PM3VTotal, vtotal - 1); |
| 752 | PM3_WRITE_REG(par, PM3VsEnd, vsend - 1); |
| 753 | PM3_WRITE_REG(par, PM3VsStart, vsstart - 1); |
| 754 | PM3_WRITE_REG(par, PM3VbEnd, vbend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 756 | switch (bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | case 8: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 758 | PM3_WRITE_REG(par, PM3ByAperture1Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | PM3ByApertureMode_PIXELSIZE_8BIT); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 760 | PM3_WRITE_REG(par, PM3ByAperture2Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | PM3ByApertureMode_PIXELSIZE_8BIT); |
| 762 | break; |
| 763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | case 16: |
| 765 | #ifndef __BIG_ENDIAN |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 766 | PM3_WRITE_REG(par, PM3ByAperture1Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | PM3ByApertureMode_PIXELSIZE_16BIT); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 768 | PM3_WRITE_REG(par, PM3ByAperture2Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | PM3ByApertureMode_PIXELSIZE_16BIT); |
| 770 | #else |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 771 | PM3_WRITE_REG(par, PM3ByAperture1Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | PM3ByApertureMode_PIXELSIZE_16BIT | |
| 773 | PM3ByApertureMode_BYTESWAP_BADC); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 774 | PM3_WRITE_REG(par, PM3ByAperture2Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | PM3ByApertureMode_PIXELSIZE_16BIT | |
| 776 | PM3ByApertureMode_BYTESWAP_BADC); |
| 777 | #endif /* ! __BIG_ENDIAN */ |
| 778 | break; |
| 779 | |
| 780 | case 32: |
| 781 | #ifndef __BIG_ENDIAN |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 782 | PM3_WRITE_REG(par, PM3ByAperture1Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | PM3ByApertureMode_PIXELSIZE_32BIT); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 784 | PM3_WRITE_REG(par, PM3ByAperture2Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | PM3ByApertureMode_PIXELSIZE_32BIT); |
| 786 | #else |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 787 | PM3_WRITE_REG(par, PM3ByAperture1Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | PM3ByApertureMode_PIXELSIZE_32BIT | |
| 789 | PM3ByApertureMode_BYTESWAP_DCBA); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 790 | PM3_WRITE_REG(par, PM3ByAperture2Mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | PM3ByApertureMode_PIXELSIZE_32BIT | |
| 792 | PM3ByApertureMode_BYTESWAP_DCBA); |
| 793 | #endif /* ! __BIG_ENDIAN */ |
| 794 | break; |
| 795 | |
| 796 | default: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 797 | DPRINTK("Unsupported depth %d\n", bpp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | break; |
| 799 | } |
| 800 | |
| 801 | /* |
| 802 | * Oxygen VX1 - it appears that setting PM3VideoControl and |
| 803 | * then PM3RD_SyncControl to the same SYNC settings undoes |
| 804 | * any net change - they seem to xor together. Only set the |
| 805 | * sync options in PM3RD_SyncControl. --rmk |
| 806 | */ |
| 807 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 808 | unsigned int video = par->video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
| 810 | video &= ~(PM3VideoControl_HSYNC_MASK | |
| 811 | PM3VideoControl_VSYNC_MASK); |
| 812 | video |= PM3VideoControl_HSYNC_ACTIVE_HIGH | |
| 813 | PM3VideoControl_VSYNC_ACTIVE_HIGH; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 814 | PM3_WRITE_REG(par, PM3VideoControl, video); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 816 | PM3_WRITE_REG(par, PM3VClkCtl, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 817 | (PM3_READ_REG(par, PM3VClkCtl) & 0xFFFFFFFC)); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 818 | PM3_WRITE_REG(par, PM3ScreenBase, par->base); |
| 819 | PM3_WRITE_REG(par, PM3ChipConfig, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 820 | (PM3_READ_REG(par, PM3ChipConfig) & 0xFFFFFFFD)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 822 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 824 | unsigned char uninitialized_var(m); /* ClkPreScale */ |
| 825 | unsigned char uninitialized_var(n); /* ClkFeedBackScale */ |
| 826 | unsigned char uninitialized_var(p); /* ClkPostScale */ |
| 827 | unsigned long pixclock = PICOS2KHZ(info->var.pixclock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 829 | (void)pm3fb_calculate_clock(pixclock, &m, &n, &p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 831 | DPRINTK("Pixclock: %ld, Pre: %d, Feedback: %d, Post: %d\n", |
| 832 | pixclock, (int) m, (int) n, (int) p); |
| 833 | |
| 834 | PM3_WRITE_DAC_REG(par, PM3RD_DClk0PreScale, m); |
| 835 | PM3_WRITE_DAC_REG(par, PM3RD_DClk0FeedbackScale, n); |
| 836 | PM3_WRITE_DAC_REG(par, PM3RD_DClk0PostScale, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } |
| 838 | /* |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 839 | PM3_WRITE_DAC_REG(par, PM3RD_IndexControl, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | */ |
| 841 | /* |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 842 | PM3_SLOW_WRITE_REG(par, PM3RD_IndexControl, 0x00); |
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 | if ((par->video & PM3VideoControl_HSYNC_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | PM3VideoControl_HSYNC_ACTIVE_HIGH) |
| 846 | tempsync |= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 847 | if ((par->video & PM3VideoControl_VSYNC_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | PM3VideoControl_VSYNC_ACTIVE_HIGH) |
| 849 | tempsync |= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 851 | PM3_WRITE_DAC_REG(par, PM3RD_SyncControl, tempsync); |
| 852 | DPRINTK("PM3RD_SyncControl: %d\n", tempsync); |
| 853 | |
| 854 | PM3_WRITE_DAC_REG(par, PM3RD_DACControl, 0x00); |
| 855 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 856 | switch (pm3fb_depth(&info->var)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | case 8: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 858 | PM3_WRITE_DAC_REG(par, PM3RD_PixelSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | PM3RD_PixelSize_8_BIT_PIXELS); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 860 | PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | PM3RD_ColorFormat_CI8_COLOR | |
| 862 | PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW); |
| 863 | tempmisc |= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; |
| 864 | break; |
| 865 | case 12: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 866 | PM3_WRITE_DAC_REG(par, PM3RD_PixelSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | PM3RD_PixelSize_16_BIT_PIXELS); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 868 | PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | PM3RD_ColorFormat_4444_COLOR | |
| 870 | PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW | |
| 871 | PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE); |
| 872 | tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | |
| 873 | PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 874 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | case 15: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 876 | PM3_WRITE_DAC_REG(par, PM3RD_PixelSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | PM3RD_PixelSize_16_BIT_PIXELS); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 878 | PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | PM3RD_ColorFormat_5551_FRONT_COLOR | |
| 880 | PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW | |
| 881 | PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE); |
| 882 | tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | |
| 883 | PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 884 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | case 16: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 886 | PM3_WRITE_DAC_REG(par, PM3RD_PixelSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | PM3RD_PixelSize_16_BIT_PIXELS); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 888 | PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | PM3RD_ColorFormat_565_FRONT_COLOR | |
| 890 | PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW | |
| 891 | PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE); |
| 892 | tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | |
| 893 | PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; |
| 894 | break; |
| 895 | case 32: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 896 | PM3_WRITE_DAC_REG(par, PM3RD_PixelSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | PM3RD_PixelSize_32_BIT_PIXELS); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 898 | PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | PM3RD_ColorFormat_8888_COLOR | |
| 900 | PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW); |
| 901 | tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | |
| 902 | PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; |
| 903 | break; |
| 904 | } |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 905 | PM3_WRITE_DAC_REG(par, PM3RD_MiscControl, tempmisc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 908 | /* |
| 909 | * hardware independent functions |
| 910 | */ |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 911 | 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] | 912 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 913 | u32 lpitch; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 914 | unsigned bpp = var->red.length + var->green.length |
| 915 | + var->blue.length + var->transp.length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 917 | if (bpp != var->bits_per_pixel) { |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 918 | /* set predefined mode for bits_per_pixel settings */ |
| 919 | |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 920 | switch (var->bits_per_pixel) { |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 921 | case 8: |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 922 | var->red.length = 8; |
| 923 | var->green.length = 8; |
| 924 | var->blue.length = 8; |
| 925 | var->red.offset = 0; |
| 926 | var->green.offset = 0; |
| 927 | var->blue.offset = 0; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 928 | var->transp.offset = 0; |
| 929 | var->transp.length = 0; |
| 930 | break; |
| 931 | case 16: |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 932 | var->red.length = 5; |
| 933 | var->blue.length = 5; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 934 | var->green.length = 6; |
| 935 | var->transp.length = 0; |
| 936 | break; |
| 937 | case 32: |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 938 | var->red.length = 8; |
| 939 | var->green.length = 8; |
| 940 | var->blue.length = 8; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 941 | var->transp.length = 8; |
| 942 | break; |
| 943 | default: |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 944 | DPRINTK("depth not supported: %u\n", |
| 945 | var->bits_per_pixel); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 946 | return -EINVAL; |
| 947 | } |
| 948 | } |
| 949 | /* it is assumed BGRA order */ |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 950 | if (var->bits_per_pixel > 8 ) { |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 951 | var->blue.offset = 0; |
| 952 | var->green.offset = var->blue.length; |
| 953 | var->red.offset = var->green.offset + var->green.length; |
| 954 | var->transp.offset = var->red.offset + var->red.length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | } |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 956 | var->height = -1; |
| 957 | var->width = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 959 | if (var->xres != var->xres_virtual) { |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 960 | DPRINTK("virtual x resolution != " |
| 961 | "physical x resolution not supported\n"); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 962 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 965 | if (var->yres > var->yres_virtual) { |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 966 | DPRINTK("virtual y resolution < " |
| 967 | "physical y resolution not possible\n"); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 968 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | } |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 970 | |
| 971 | if (var->xoffset) { |
| 972 | DPRINTK("xoffset not supported\n"); |
| 973 | return -EINVAL; |
| 974 | } |
| 975 | |
| 976 | if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) { |
| 977 | DPRINTK("interlace not supported\n"); |
| 978 | return -EINVAL; |
| 979 | } |
| 980 | |
| 981 | var->xres = (var->xres + 31) & ~31; /* could sometimes be 8 */ |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 982 | lpitch = var->xres * ((var->bits_per_pixel + 7) >> 3); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 983 | |
| 984 | if (var->xres < 200 || var->xres > 2048) { |
| 985 | DPRINTK("width not supported: %u\n", var->xres); |
| 986 | return -EINVAL; |
| 987 | } |
| 988 | |
| 989 | if (var->yres < 200 || var->yres > 4095) { |
| 990 | DPRINTK("height not supported: %u\n", var->yres); |
| 991 | return -EINVAL; |
| 992 | } |
| 993 | |
| 994 | if (lpitch * var->yres_virtual > info->fix.smem_len) { |
| 995 | DPRINTK("no memory for screen (%ux%ux%u)\n", |
| 996 | var->xres, var->yres_virtual, var->bits_per_pixel); |
| 997 | return -EINVAL; |
| 998 | } |
| 999 | |
| 1000 | if (PICOS2KHZ(var->pixclock) > PM3_MAX_PIXCLOCK) { |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1001 | DPRINTK("pixclock too high (%ldKHz)\n", |
| 1002 | PICOS2KHZ(var->pixclock)); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1003 | return -EINVAL; |
| 1004 | } |
| 1005 | |
| 1006 | var->accel_flags = 0; /* Can't mmap if this is on */ |
| 1007 | |
| 1008 | DPRINTK("Checking graphics mode at %dx%d depth %d\n", |
| 1009 | var->xres, var->yres, var->bits_per_pixel); |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | static int pm3fb_set_par(struct fb_info *info) |
| 1014 | { |
| 1015 | struct pm3_par *par = info->par; |
| 1016 | const u32 xres = (info->var.xres + 31) & ~31; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1017 | const unsigned bpp = info->var.bits_per_pixel; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1018 | |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1019 | par->base = pm3fb_shift_bpp(bpp, (info->var.yoffset * xres) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1020 | + info->var.xoffset); |
| 1021 | par->video = 0; |
| 1022 | |
| 1023 | if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) |
| 1024 | par->video |= PM3VideoControl_HSYNC_ACTIVE_HIGH; |
| 1025 | else |
| 1026 | par->video |= PM3VideoControl_HSYNC_ACTIVE_LOW; |
| 1027 | |
| 1028 | if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) |
| 1029 | par->video |= PM3VideoControl_VSYNC_ACTIVE_HIGH; |
| 1030 | else |
| 1031 | par->video |= PM3VideoControl_VSYNC_ACTIVE_LOW; |
| 1032 | |
| 1033 | if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) |
| 1034 | par->video |= PM3VideoControl_LINE_DOUBLE_ON; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1035 | |
Krzysztof Helt | 0bd327e | 2007-06-01 00:47:09 -0700 | [diff] [blame] | 1036 | if ((info->var.activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1037 | par->video |= PM3VideoControl_ENABLE; |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 1038 | else |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1039 | DPRINTK("PM3Video disabled\n"); |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 1040 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1041 | switch (bpp) { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1042 | case 8: |
| 1043 | par->video |= PM3VideoControl_PIXELSIZE_8BIT; |
| 1044 | break; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1045 | case 16: |
| 1046 | par->video |= PM3VideoControl_PIXELSIZE_16BIT; |
| 1047 | break; |
| 1048 | case 32: |
| 1049 | par->video |= PM3VideoControl_PIXELSIZE_32BIT; |
| 1050 | break; |
| 1051 | default: |
| 1052 | DPRINTK("Unsupported depth\n"); |
| 1053 | break; |
| 1054 | } |
| 1055 | |
| 1056 | info->fix.visual = |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1057 | (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 1058 | info->fix.line_length = ((info->var.xres_virtual + 7) >> 3) * bpp; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1059 | |
| 1060 | /* pm3fb_clear_memory(info, 0);*/ |
| 1061 | pm3fb_clear_colormap(par, 0, 0, 0); |
Krzysztof Helt | f259ebb | 2007-10-16 01:28:31 -0700 | [diff] [blame] | 1062 | PM3_WRITE_DAC_REG(par, PM3RD_CursorMode, 0); |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 1063 | pm3fb_init_engine(info); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1064 | pm3fb_write_mode(info); |
| 1065 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 1069 | unsigned blue, unsigned transp, |
| 1070 | struct fb_info *info) |
| 1071 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1072 | struct pm3_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1074 | if (regno >= 256) /* no. of hw registers */ |
| 1075 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1077 | /* grayscale works only partially under directcolor */ |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1078 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ |
| 1079 | if (info->var.grayscale) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1080 | red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1081 | |
| 1082 | /* Directcolor: |
| 1083 | * var->{color}.offset contains start of bitfield |
| 1084 | * var->{color}.length contains length of bitfield |
| 1085 | * {hardwarespecific} contains width of DAC |
| 1086 | * pseudo_palette[X] is programmed to (X << red.offset) | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1087 | * (X << green.offset) | |
| 1088 | * (X << blue.offset) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1089 | * RAMDAC[X] is programmed to (red, green, blue) |
| 1090 | * color depth = SUM(var->{color}.length) |
| 1091 | * |
| 1092 | * Pseudocolor: |
| 1093 | * var->{color}.offset is 0 |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1094 | * var->{color}.length contains width of DAC or the number |
| 1095 | * of unique colors available (color depth) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1096 | * pseudo_palette is not used |
| 1097 | * RAMDAC[X] is programmed to (red, green, blue) |
| 1098 | * color depth = var->{color}.length |
| 1099 | */ |
| 1100 | |
| 1101 | /* |
| 1102 | * This is the point where the color is converted to something that |
| 1103 | * is acceptable by the hardware. |
| 1104 | */ |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1105 | #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF - (val)) >> 16) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1106 | red = CNVT_TOHW(red, info->var.red.length); |
| 1107 | green = CNVT_TOHW(green, info->var.green.length); |
| 1108 | blue = CNVT_TOHW(blue, info->var.blue.length); |
| 1109 | transp = CNVT_TOHW(transp, info->var.transp.length); |
| 1110 | #undef CNVT_TOHW |
| 1111 | |
| 1112 | if (info->fix.visual == FB_VISUAL_TRUECOLOR || |
| 1113 | info->fix.visual == FB_VISUAL_DIRECTCOLOR) { |
| 1114 | u32 v; |
| 1115 | |
| 1116 | if (regno >= 16) |
| 1117 | return -EINVAL; |
| 1118 | |
| 1119 | v = (red << info->var.red.offset) | |
| 1120 | (green << info->var.green.offset) | |
| 1121 | (blue << info->var.blue.offset) | |
| 1122 | (transp << info->var.transp.offset); |
| 1123 | |
| 1124 | switch (info->var.bits_per_pixel) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | case 8: |
| 1126 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | case 16: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | case 32: |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1129 | ((u32 *)(info->pseudo_palette))[regno] = v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | break; |
| 1131 | } |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1132 | return 0; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1133 | } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1134 | pm3fb_set_color(par, regno, red, green, blue); |
| 1135 | |
| 1136 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1139 | static int pm3fb_pan_display(struct fb_var_screeninfo *var, |
| 1140 | struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1142 | struct pm3_par *par = info->par; |
Laurent Pinchart | 1fdb518 | 2011-06-14 09:24:56 +0000 | [diff] [blame] | 1143 | const u32 xres = (info->var.xres + 31) & ~31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | |
Laurent Pinchart | 1fdb518 | 2011-06-14 09:24:56 +0000 | [diff] [blame] | 1145 | par->base = pm3fb_shift_bpp(info->var.bits_per_pixel, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1146 | (var->yoffset * xres) |
| 1147 | + var->xoffset); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1148 | PM3_WAIT(par, 1); |
| 1149 | PM3_WRITE_REG(par, PM3ScreenBase, par->base); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1150 | return 0; |
| 1151 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1153 | static int pm3fb_blank(int blank_mode, struct fb_info *info) |
| 1154 | { |
| 1155 | struct pm3_par *par = info->par; |
| 1156 | u32 video = par->video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | |
| 1158 | /* |
| 1159 | * Oxygen VX1 - it appears that setting PM3VideoControl and |
| 1160 | * then PM3RD_SyncControl to the same SYNC settings undoes |
| 1161 | * any net change - they seem to xor together. Only set the |
| 1162 | * sync options in PM3RD_SyncControl. --rmk |
| 1163 | */ |
| 1164 | video &= ~(PM3VideoControl_HSYNC_MASK | |
| 1165 | PM3VideoControl_VSYNC_MASK); |
| 1166 | video |= PM3VideoControl_HSYNC_ACTIVE_HIGH | |
| 1167 | PM3VideoControl_VSYNC_ACTIVE_HIGH; |
| 1168 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1169 | switch (blank_mode) { |
| 1170 | case FB_BLANK_UNBLANK: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1171 | video |= PM3VideoControl_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | break; |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1173 | case FB_BLANK_NORMAL: |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 1174 | video &= ~PM3VideoControl_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | break; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1176 | case FB_BLANK_HSYNC_SUSPEND: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1177 | video &= ~(PM3VideoControl_HSYNC_MASK | |
| 1178 | PM3VideoControl_BLANK_ACTIVE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | break; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1180 | case FB_BLANK_VSYNC_SUSPEND: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1181 | video &= ~(PM3VideoControl_VSYNC_MASK | |
| 1182 | PM3VideoControl_BLANK_ACTIVE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | break; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1184 | case FB_BLANK_POWERDOWN: |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1185 | video &= ~(PM3VideoControl_HSYNC_MASK | |
| 1186 | PM3VideoControl_VSYNC_MASK | |
| 1187 | PM3VideoControl_BLANK_ACTIVE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | default: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1190 | DPRINTK("Unsupported blanking %d\n", blank_mode); |
| 1191 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1194 | PM3_WAIT(par, 1); |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1195 | PM3_WRITE_REG(par, PM3VideoControl, video); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | return 0; |
| 1197 | } |
| 1198 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1199 | /* |
| 1200 | * Frame buffer operations |
| 1201 | */ |
| 1202 | |
| 1203 | static struct fb_ops pm3fb_ops = { |
| 1204 | .owner = THIS_MODULE, |
| 1205 | .fb_check_var = pm3fb_check_var, |
| 1206 | .fb_set_par = pm3fb_set_par, |
| 1207 | .fb_setcolreg = pm3fb_setcolreg, |
| 1208 | .fb_pan_display = pm3fb_pan_display, |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 1209 | .fb_fillrect = pm3fb_fillrect, |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 1210 | .fb_copyarea = pm3fb_copyarea, |
| 1211 | .fb_imageblit = pm3fb_imageblit, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1212 | .fb_blank = pm3fb_blank, |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 1213 | .fb_sync = pm3fb_sync, |
Krzysztof Helt | 1d677a6 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 1214 | .fb_cursor = pm3fb_cursor, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1215 | }; |
| 1216 | |
| 1217 | /* ------------------------------------------------------------------------- */ |
| 1218 | |
| 1219 | /* |
| 1220 | * Initialization |
| 1221 | */ |
| 1222 | |
| 1223 | /* mmio register are already mapped when this function is called */ |
| 1224 | /* the pm3fb_fix.smem_start is also set */ |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 1225 | static unsigned long pm3fb_size_memory(struct pm3_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | { |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1227 | unsigned long memsize = 0; |
| 1228 | unsigned long tempBypass, i, temp1, temp2; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1229 | unsigned char __iomem *screen_mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1231 | pm3fb_fix.smem_len = 64 * 1024l * 1024; /* request full aperture size */ |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1232 | /* Linear frame buffer - request region and map it. */ |
| 1233 | if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len, |
| 1234 | "pm3fb smem")) { |
| 1235 | printk(KERN_WARNING "pm3fb: Can't reserve smem.\n"); |
| 1236 | return 0; |
| 1237 | } |
| 1238 | screen_mem = |
| 1239 | ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 1240 | if (!screen_mem) { |
| 1241 | printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n"); |
| 1242 | release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 1243 | return 0; |
| 1244 | } |
| 1245 | |
| 1246 | /* TODO: card-specific stuff, *before* accessing *any* FB memory */ |
| 1247 | /* For Appian Jeronimo 2000 board second head */ |
| 1248 | |
| 1249 | tempBypass = PM3_READ_REG(par, PM3MemBypassWriteMask); |
| 1250 | |
| 1251 | DPRINTK("PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass); |
| 1252 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1253 | PM3_WAIT(par, 1); |
| 1254 | PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xFFFFFFFF); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1255 | |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1256 | /* pm3 split up memory, replicates, and do a lot of |
| 1257 | * nasty stuff IMHO ;-) |
| 1258 | */ |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1259 | for (i = 0; i < 32; i++) { |
| 1260 | fb_writel(i * 0x00345678, |
| 1261 | (screen_mem + (i * 1048576))); |
| 1262 | mb(); |
| 1263 | temp1 = fb_readl((screen_mem + (i * 1048576))); |
| 1264 | |
| 1265 | /* Let's check for wrapover, write will fail at 16MB boundary */ |
| 1266 | if (temp1 == (i * 0x00345678)) |
| 1267 | memsize = i; |
| 1268 | else |
| 1269 | break; |
| 1270 | } |
| 1271 | |
| 1272 | DPRINTK("First detect pass already got %ld MB\n", memsize + 1); |
| 1273 | |
| 1274 | if (memsize + 1 == i) { |
| 1275 | for (i = 0; i < 32; i++) { |
| 1276 | /* Clear first 32MB ; 0 is 0, no need to byteswap */ |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1277 | writel(0x0000000, (screen_mem + (i * 1048576))); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1278 | } |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1279 | wmb(); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1280 | |
| 1281 | for (i = 32; i < 64; i++) { |
| 1282 | fb_writel(i * 0x00345678, |
| 1283 | (screen_mem + (i * 1048576))); |
| 1284 | mb(); |
| 1285 | temp1 = |
| 1286 | fb_readl((screen_mem + (i * 1048576))); |
| 1287 | temp2 = |
| 1288 | fb_readl((screen_mem + ((i - 32) * 1048576))); |
| 1289 | /* different value, different RAM... */ |
| 1290 | if ((temp1 == (i * 0x00345678)) && (temp2 == 0)) |
| 1291 | memsize = i; |
| 1292 | else |
| 1293 | break; |
| 1294 | } |
| 1295 | } |
| 1296 | DPRINTK("Second detect pass got %ld MB\n", memsize + 1); |
| 1297 | |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1298 | PM3_WAIT(par, 1); |
| 1299 | PM3_WRITE_REG(par, PM3MemBypassWriteMask, tempBypass); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1300 | |
| 1301 | iounmap(screen_mem); |
| 1302 | release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 1303 | memsize = 1048576 * (memsize + 1); |
| 1304 | |
| 1305 | DPRINTK("Returning 0x%08lx bytes\n", memsize); |
| 1306 | |
| 1307 | return memsize; |
| 1308 | } |
| 1309 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 1310 | static int pm3fb_probe(struct pci_dev *dev, const struct pci_device_id *ent) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1311 | { |
| 1312 | struct fb_info *info; |
| 1313 | struct pm3_par *par; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1314 | struct device *device = &dev->dev; /* for pci drivers */ |
| 1315 | int err; |
| 1316 | int retval = -ENXIO; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1317 | |
| 1318 | err = pci_enable_device(dev); |
| 1319 | if (err) { |
| 1320 | printk(KERN_WARNING "pm3fb: Can't enable PCI dev: %d\n", err); |
| 1321 | return err; |
| 1322 | } |
| 1323 | /* |
| 1324 | * Dynamically allocate info and par |
| 1325 | */ |
| 1326 | info = framebuffer_alloc(sizeof(struct pm3_par), device); |
| 1327 | |
| 1328 | if (!info) |
| 1329 | return -ENOMEM; |
| 1330 | par = info->par; |
| 1331 | |
| 1332 | /* |
| 1333 | * Here we set the screen_base to the virtual memory address |
| 1334 | * for the framebuffer. |
| 1335 | */ |
| 1336 | pm3fb_fix.mmio_start = pci_resource_start(dev, 0); |
| 1337 | pm3fb_fix.mmio_len = PM3_REGS_SIZE; |
Krzysztof Helt | c79ba28 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 1338 | #if defined(__BIG_ENDIAN) |
| 1339 | pm3fb_fix.mmio_start += PM3_REGS_SIZE; |
| 1340 | DPRINTK("Adjusting register base for big-endian.\n"); |
| 1341 | #endif |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1342 | |
| 1343 | /* Registers - request region and map it. */ |
| 1344 | if (!request_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len, |
| 1345 | "pm3fb regbase")) { |
| 1346 | printk(KERN_WARNING "pm3fb: Can't reserve regbase.\n"); |
| 1347 | goto err_exit_neither; |
| 1348 | } |
| 1349 | par->v_regs = |
| 1350 | ioremap_nocache(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len); |
| 1351 | if (!par->v_regs) { |
| 1352 | printk(KERN_WARNING "pm3fb: Can't remap %s register area.\n", |
| 1353 | pm3fb_fix.id); |
| 1354 | release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len); |
| 1355 | goto err_exit_neither; |
| 1356 | } |
| 1357 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1358 | /* Linear frame buffer - request region and map it. */ |
| 1359 | pm3fb_fix.smem_start = pci_resource_start(dev, 1); |
| 1360 | pm3fb_fix.smem_len = pm3fb_size_memory(par); |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1361 | if (!pm3fb_fix.smem_len) { |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1362 | printk(KERN_WARNING "pm3fb: Can't find memory on board.\n"); |
| 1363 | goto err_exit_mmio; |
| 1364 | } |
| 1365 | if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len, |
| 1366 | "pm3fb smem")) { |
| 1367 | printk(KERN_WARNING "pm3fb: Can't reserve smem.\n"); |
| 1368 | goto err_exit_mmio; |
| 1369 | } |
Luis R. Rodriguez | 26e2506 | 2015-04-21 13:16:34 -0700 | [diff] [blame] | 1370 | info->screen_base = ioremap_wc(pm3fb_fix.smem_start, |
| 1371 | pm3fb_fix.smem_len); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1372 | if (!info->screen_base) { |
| 1373 | printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n"); |
| 1374 | release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 1375 | goto err_exit_mmio; |
| 1376 | } |
| 1377 | info->screen_size = pm3fb_fix.smem_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1379 | if (!nomtrr) |
Luis R. Rodriguez | 26e2506 | 2015-04-21 13:16:34 -0700 | [diff] [blame] | 1380 | par->wc_cookie = arch_phys_wc_add(pm3fb_fix.smem_start, |
| 1381 | pm3fb_fix.smem_len); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1382 | info->fbops = &pm3fb_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1384 | par->video = PM3_READ_REG(par, PM3VideoControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1386 | info->fix = pm3fb_fix; |
| 1387 | info->pseudo_palette = par->palette; |
Krzysztof Helt | a58d67c | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 1388 | info->flags = FBINFO_DEFAULT | |
Krzysztof Helt | c79ba28 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 1389 | FBINFO_HWACCEL_XPAN | |
| 1390 | FBINFO_HWACCEL_YPAN | |
Krzysztof Helt | e7f76df | 2007-10-16 01:28:29 -0700 | [diff] [blame] | 1391 | FBINFO_HWACCEL_COPYAREA | |
| 1392 | FBINFO_HWACCEL_IMAGEBLIT | |
| 1393 | FBINFO_HWACCEL_FILLRECT; |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1394 | |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1395 | if (noaccel) { |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1396 | printk(KERN_DEBUG "disabling acceleration\n"); |
| 1397 | info->flags |= FBINFO_HWACCEL_DISABLED; |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1398 | } |
Krzysztof Helt | b0a318e | 2007-10-16 01:28:31 -0700 | [diff] [blame] | 1399 | info->pixmap.addr = kmalloc(PM3_PIXMAP_SIZE, GFP_KERNEL); |
| 1400 | if (!info->pixmap.addr) { |
| 1401 | retval = -ENOMEM; |
| 1402 | goto err_exit_pixmap; |
| 1403 | } |
| 1404 | info->pixmap.size = PM3_PIXMAP_SIZE; |
| 1405 | info->pixmap.buf_align = 4; |
| 1406 | info->pixmap.scan_align = 4; |
| 1407 | info->pixmap.access_align = 32; |
| 1408 | info->pixmap.flags = FB_PIXMAP_SYSTEM; |
| 1409 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1410 | /* |
| 1411 | * This should give a reasonable default video mode. The following is |
| 1412 | * done when we can set a video mode. |
| 1413 | */ |
| 1414 | if (!mode_option) |
| 1415 | mode_option = "640x480@60"; |
| 1416 | |
| 1417 | retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8); |
| 1418 | |
| 1419 | if (!retval || retval == 4) { |
| 1420 | retval = -EINVAL; |
| 1421 | goto err_exit_both; |
| 1422 | } |
| 1423 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1424 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { |
| 1425 | retval = -ENOMEM; |
| 1426 | goto err_exit_both; |
| 1427 | } |
| 1428 | |
| 1429 | /* |
| 1430 | * For drivers that can... |
| 1431 | */ |
| 1432 | pm3fb_check_var(&info->var, info); |
| 1433 | |
| 1434 | if (register_framebuffer(info) < 0) { |
| 1435 | retval = -EINVAL; |
| 1436 | goto err_exit_all; |
| 1437 | } |
Joe Perches | 31b6780 | 2013-09-19 18:35:55 -0700 | [diff] [blame] | 1438 | fb_info(info, "%s frame buffer device\n", info->fix.id); |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1439 | pci_set_drvdata(dev, info); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1440 | return 0; |
| 1441 | |
| 1442 | err_exit_all: |
| 1443 | fb_dealloc_cmap(&info->cmap); |
| 1444 | err_exit_both: |
Krzysztof Helt | b0a318e | 2007-10-16 01:28:31 -0700 | [diff] [blame] | 1445 | kfree(info->pixmap.addr); |
| 1446 | err_exit_pixmap: |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1447 | iounmap(info->screen_base); |
| 1448 | release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len); |
| 1449 | err_exit_mmio: |
| 1450 | iounmap(par->v_regs); |
| 1451 | release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len); |
| 1452 | err_exit_neither: |
| 1453 | framebuffer_release(info); |
| 1454 | return retval; |
| 1455 | } |
| 1456 | |
| 1457 | /* |
| 1458 | * Cleanup |
| 1459 | */ |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 1460 | static void pm3fb_remove(struct pci_dev *dev) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1461 | { |
| 1462 | struct fb_info *info = pci_get_drvdata(dev); |
| 1463 | |
| 1464 | if (info) { |
| 1465 | struct fb_fix_screeninfo *fix = &info->fix; |
| 1466 | struct pm3_par *par = info->par; |
| 1467 | |
| 1468 | unregister_framebuffer(info); |
| 1469 | fb_dealloc_cmap(&info->cmap); |
| 1470 | |
Luis R. Rodriguez | 26e2506 | 2015-04-21 13:16:34 -0700 | [diff] [blame] | 1471 | arch_phys_wc_del(par->wc_cookie); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1472 | iounmap(info->screen_base); |
| 1473 | release_mem_region(fix->smem_start, fix->smem_len); |
| 1474 | iounmap(par->v_regs); |
| 1475 | release_mem_region(fix->mmio_start, fix->mmio_len); |
| 1476 | |
Krzysztof Helt | b0a318e | 2007-10-16 01:28:31 -0700 | [diff] [blame] | 1477 | kfree(info->pixmap.addr); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1478 | framebuffer_release(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | } |
| 1480 | } |
| 1481 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1482 | static struct pci_device_id pm3fb_id_table[] = { |
| 1483 | { PCI_VENDOR_ID_3DLABS, 0x0a, |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1484 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1485 | { 0, } |
| 1486 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1488 | /* For PCI drivers */ |
| 1489 | static struct pci_driver pm3fb_driver = { |
| 1490 | .name = "pm3fb", |
| 1491 | .id_table = pm3fb_id_table, |
| 1492 | .probe = pm3fb_probe, |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 1493 | .remove = pm3fb_remove, |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1494 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1496 | MODULE_DEVICE_TABLE(pci, pm3fb_id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1498 | #ifndef MODULE |
| 1499 | /* |
| 1500 | * Setup |
| 1501 | */ |
| 1502 | |
| 1503 | /* |
| 1504 | * Only necessary if your driver takes special options, |
| 1505 | * otherwise we fall back on the generic fb_setup(). |
| 1506 | */ |
| 1507 | static int __init pm3fb_setup(char *options) |
| 1508 | { |
| 1509 | char *this_opt; |
| 1510 | |
Joe Perches | 75e1b6a | 2011-06-23 22:35:19 +0000 | [diff] [blame] | 1511 | /* Parse user specified options (`video=pm3fb:') */ |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1512 | if (!options || !*options) |
| 1513 | return 0; |
| 1514 | |
| 1515 | while ((this_opt = strsep(&options, ",")) != NULL) { |
| 1516 | if (!*this_opt) |
| 1517 | continue; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1518 | else if (!strncmp(this_opt, "noaccel", 7)) |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1519 | noaccel = 1; |
Krzysztof Helt | 1d677a6 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 1520 | else if (!strncmp(this_opt, "hwcursor=", 9)) |
| 1521 | hwcursor = simple_strtoul(this_opt + 9, NULL, 0); |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1522 | else if (!strncmp(this_opt, "nomtrr", 6)) |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1523 | nomtrr = 1; |
Krzysztof Helt | 57bac0f | 2007-10-16 01:28:51 -0700 | [diff] [blame] | 1524 | else |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1525 | mode_option = this_opt; |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1526 | } |
| 1527 | return 0; |
| 1528 | } |
| 1529 | #endif /* MODULE */ |
| 1530 | |
Adrian Bunk | b309c05 | 2007-07-17 04:05:46 -0700 | [diff] [blame] | 1531 | static int __init pm3fb_init(void) |
Krzysztof Helt | 2686ba8 | 2007-05-23 13:57:48 -0700 | [diff] [blame] | 1532 | { |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1533 | /* |
| 1534 | * For kernel boot options (in 'video=pm3fb:<options>' format) |
| 1535 | */ |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1536 | #ifndef MODULE |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1537 | char *option = NULL; |
| 1538 | |
| 1539 | if (fb_get_options("pm3fb", &option)) |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1540 | return -ENODEV; |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1541 | pm3fb_setup(option); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1542 | #endif |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1543 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1544 | return pci_register_driver(&pm3fb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1547 | #ifdef MODULE |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1548 | static void __exit pm3fb_exit(void) |
| 1549 | { |
| 1550 | pci_unregister_driver(&pm3fb_driver); |
| 1551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1553 | module_exit(pm3fb_exit); |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1554 | #endif |
| 1555 | module_init(pm3fb_init); |
| 1556 | |
Krzysztof Helt | 4e65c61 | 2008-04-28 02:15:07 -0700 | [diff] [blame] | 1557 | module_param(mode_option, charp, 0); |
| 1558 | MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'"); |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1559 | module_param(noaccel, bool, 0); |
| 1560 | MODULE_PARM_DESC(noaccel, "Disable acceleration"); |
Krzysztof Helt | 1d677a6 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 1561 | module_param(hwcursor, int, 0644); |
| 1562 | MODULE_PARM_DESC(hwcursor, "Enable hardware cursor " |
| 1563 | "(1=enable, 0=disable, default=1)"); |
Krzysztof Helt | d5383fc | 2007-10-16 01:28:33 -0700 | [diff] [blame] | 1564 | module_param(nomtrr, bool, 0); |
| 1565 | MODULE_PARM_DESC(nomtrr, "Disable MTRR support (0 or 1=disabled) (default=0)"); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1566 | |
Krzysztof Helt | 0ddf784 | 2007-10-16 01:28:32 -0700 | [diff] [blame] | 1567 | MODULE_DESCRIPTION("Permedia3 framebuffer device driver"); |
Krzysztof Helt | f23a06f | 2007-05-10 22:23:25 -0700 | [diff] [blame] | 1568 | MODULE_LICENSE("GPL"); |