blob: fb91b641aefe06caf16d0c488d352a3b74c789f7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/video/pm3fb.c -- 3DLabs Permedia3 frame buffer device
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07003 *
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 Torvalds1da177e2005-04-16 15:20:36 -07009 * Based on code written by:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070010 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 * Based on linux/drivers/video/skeletonfb.c:
14 * Copyright (C) 1997 Geert Uytterhoeven
15 * Based on linux/driver/video/pm2fb.c:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070016 * Copyright (C) 1998-1999 Ilario Nardinocchi (nardinoc@CS.UniBO.IT)
17 * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 *
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 Torvalds1da177e2005-04-16 15:20:36 -070023 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#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 Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/fb.h>
33#include <linux/init.h>
34#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <video/pm3fb.h>
37
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070038#if !defined(CONFIG_PCI)
39#error "Only generic PCI cards supported."
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#endif
41
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070042#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 Torvalds1da177e2005-04-16 15:20:36 -070048
Krzysztof Heltb0a318e2007-10-16 01:28:31 -070049#define PM3_PIXMAP_SIZE (2048 * 4)
50
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070051/*
52 * Driver data
53 */
54static char *mode_option __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070056/*
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070057 * This structure defines the hardware state of the graphics card. Normally
58 * you place this in a header file in linux/include/video. This file usually
59 * also includes register information. That allows other driver subsystems
60 * and userland applications the ability to use the same header file to
61 * avoid duplicate work and easy porting of software.
62 */
63struct pm3_par {
64 unsigned char __iomem *v_regs;/* virtual address of p_regs */
65 u32 video; /* video flags before blanking */
66 u32 base; /* screen base (xoffset+yoffset) in 128 bits unit */
Krzysztof Helt2686ba82007-05-23 13:57:48 -070067 u32 palette[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -070068};
69
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070070/*
71 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
72 * if we don't use modedb. If we do use modedb see pm3fb_init how to use it
73 * to get a fb_var_screeninfo. Otherwise define a default var as well.
74 */
75static struct fb_fix_screeninfo pm3fb_fix __devinitdata = {
76 .id = "Permedia3",
77 .type = FB_TYPE_PACKED_PIXELS,
78 .visual = FB_VISUAL_PSEUDOCOLOR,
79 .xpanstep = 1,
80 .ypanstep = 1,
81 .ywrapstep = 0,
Krzysztof Helta58d67c2007-07-17 04:05:46 -070082 .accel = FB_ACCEL_3DLABS_PERMEDIA3,
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070083};
84
85/*
86 * Utility functions
87 */
88
89static inline u32 PM3_READ_REG(struct pm3_par *par, s32 off)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070091 return fb_readl(par->v_regs + off);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070094static inline void PM3_WRITE_REG(struct pm3_par *par, s32 off, u32 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070096 fb_writel(v, par->v_regs + off);
97}
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070099static inline void PM3_WAIT(struct pm3_par *par, u32 n)
100{
101 while (PM3_READ_REG(par, PM3InFIFOSpace) < n);
102}
103
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700104static inline void PM3_WRITE_DAC_REG(struct pm3_par *par, unsigned r, u8 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700106 PM3_WAIT(par, 3);
107 PM3_WRITE_REG(par, PM3RD_IndexHigh, (r >> 8) & 0xff);
108 PM3_WRITE_REG(par, PM3RD_IndexLow, r & 0xff);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700109 wmb();
110 PM3_WRITE_REG(par, PM3RD_IndexedData, v);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700111 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700114static inline void pm3fb_set_color(struct pm3_par *par, unsigned char regno,
115 unsigned char r, unsigned char g, unsigned char b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700117 PM3_WAIT(par, 4);
118 PM3_WRITE_REG(par, PM3RD_PaletteWriteAddress, regno);
119 wmb();
120 PM3_WRITE_REG(par, PM3RD_PaletteData, r);
121 wmb();
122 PM3_WRITE_REG(par, PM3RD_PaletteData, g);
123 wmb();
124 PM3_WRITE_REG(par, PM3RD_PaletteData, b);
125 wmb();
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700126}
127
128static void pm3fb_clear_colormap(struct pm3_par *par,
129 unsigned char r, unsigned char g, unsigned char b)
130{
131 int i;
132
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700133 for (i = 0; i < 256 ; i++)
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700134 pm3fb_set_color(par, i, r, g, b);
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
138/* Calculating various clock parameter */
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700139static void pm3fb_calculate_clock(unsigned long reqclock,
140 unsigned char *prescale,
141 unsigned char *feedback,
142 unsigned char *postscale)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
144 int f, pre, post;
145 unsigned long freq;
146 long freqerr = 1000;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700147 long currerr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 for (f = 1; f < 256; f++) {
150 for (pre = 1; pre < 256; pre++) {
151 for (post = 0; post < 5; post++) {
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700152 freq = ((2*PM3_REF_CLOCK * f) >> post) / pre;
153 currerr = (reqclock > freq)
154 ? reqclock - freq
155 : freq - reqclock;
156 if (currerr < freqerr) {
157 freqerr = currerr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 *feedback = f;
159 *prescale = pre;
160 *postscale = post;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162 }
163 }
164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700167static inline int pm3fb_depth(const struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700169 if ( var->bits_per_pixel == 16 )
170 return var->red.length + var->green.length
171 + var->blue.length;
172
173 return var->bits_per_pixel;
174}
175
176static inline int pm3fb_shift_bpp(unsigned bpp, int v)
177{
178 switch (bpp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 case 8:
180 return (v >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 case 16:
182 return (v >> 3);
183 case 32:
184 return (v >> 2);
185 }
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700186 DPRINTK("Unsupported depth %u\n", bpp);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700187 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188}
189
Krzysztof Helta58d67c2007-07-17 04:05:46 -0700190/* acceleration */
191static int pm3fb_sync(struct fb_info *info)
192{
193 struct pm3_par *par = info->par;
194
195 PM3_WAIT(par, 2);
196 PM3_WRITE_REG(par, PM3FilterMode, PM3FilterModeSync);
197 PM3_WRITE_REG(par, PM3Sync, 0);
198 mb();
199 do {
200 while ((PM3_READ_REG(par, PM3OutFIFOWords)) == 0);
201 rmb();
202 } while ((PM3_READ_REG(par, PM3OutputFifo)) != PM3Sync_Tag);
203
204 return 0;
205}
206
207static void pm3fb_init_engine(struct fb_info *info)
208{
209 struct pm3_par *par = info->par;
210 const u32 width = (info->var.xres_virtual + 7) & ~7;
211
212 PM3_WAIT(par, 50);
213 PM3_WRITE_REG(par, PM3FilterMode, PM3FilterModeSync);
214 PM3_WRITE_REG(par, PM3StatisticMode, 0x0);
215 PM3_WRITE_REG(par, PM3DeltaMode, 0x0);
216 PM3_WRITE_REG(par, PM3RasterizerMode, 0x0);
217 PM3_WRITE_REG(par, PM3ScissorMode, 0x0);
218 PM3_WRITE_REG(par, PM3LineStippleMode, 0x0);
219 PM3_WRITE_REG(par, PM3AreaStippleMode, 0x0);
220 PM3_WRITE_REG(par, PM3GIDMode, 0x0);
221 PM3_WRITE_REG(par, PM3DepthMode, 0x0);
222 PM3_WRITE_REG(par, PM3StencilMode, 0x0);
223 PM3_WRITE_REG(par, PM3StencilData, 0x0);
224 PM3_WRITE_REG(par, PM3ColorDDAMode, 0x0);
225 PM3_WRITE_REG(par, PM3TextureCoordMode, 0x0);
226 PM3_WRITE_REG(par, PM3TextureIndexMode0, 0x0);
227 PM3_WRITE_REG(par, PM3TextureIndexMode1, 0x0);
228 PM3_WRITE_REG(par, PM3TextureReadMode, 0x0);
229 PM3_WRITE_REG(par, PM3LUTMode, 0x0);
230 PM3_WRITE_REG(par, PM3TextureFilterMode, 0x0);
231 PM3_WRITE_REG(par, PM3TextureCompositeMode, 0x0);
232 PM3_WRITE_REG(par, PM3TextureApplicationMode, 0x0);
233 PM3_WRITE_REG(par, PM3TextureCompositeColorMode1, 0x0);
234 PM3_WRITE_REG(par, PM3TextureCompositeAlphaMode1, 0x0);
235 PM3_WRITE_REG(par, PM3TextureCompositeColorMode0, 0x0);
236 PM3_WRITE_REG(par, PM3TextureCompositeAlphaMode0, 0x0);
237 PM3_WRITE_REG(par, PM3FogMode, 0x0);
238 PM3_WRITE_REG(par, PM3ChromaTestMode, 0x0);
239 PM3_WRITE_REG(par, PM3AlphaTestMode, 0x0);
240 PM3_WRITE_REG(par, PM3AntialiasMode, 0x0);
241 PM3_WRITE_REG(par, PM3YUVMode, 0x0);
242 PM3_WRITE_REG(par, PM3AlphaBlendColorMode, 0x0);
243 PM3_WRITE_REG(par, PM3AlphaBlendAlphaMode, 0x0);
244 PM3_WRITE_REG(par, PM3DitherMode, 0x0);
245 PM3_WRITE_REG(par, PM3LogicalOpMode, 0x0);
246 PM3_WRITE_REG(par, PM3RouterMode, 0x0);
247 PM3_WRITE_REG(par, PM3Window, 0x0);
248
249 PM3_WRITE_REG(par, PM3Config2D, 0x0);
250
251 PM3_WRITE_REG(par, PM3SpanColorMask, 0xffffffff);
252
253 PM3_WRITE_REG(par, PM3XBias, 0x0);
254 PM3_WRITE_REG(par, PM3YBias, 0x0);
255 PM3_WRITE_REG(par, PM3DeltaControl, 0x0);
256
257 PM3_WRITE_REG(par, PM3BitMaskPattern, 0xffffffff);
258
259 PM3_WRITE_REG(par, PM3FBDestReadEnables,
260 PM3FBDestReadEnables_E(0xff) |
261 PM3FBDestReadEnables_R(0xff) |
262 PM3FBDestReadEnables_ReferenceAlpha(0xff));
263 PM3_WRITE_REG(par, PM3FBDestReadBufferAddr0, 0x0);
264 PM3_WRITE_REG(par, PM3FBDestReadBufferOffset0, 0x0);
265 PM3_WRITE_REG(par, PM3FBDestReadBufferWidth0,
266 PM3FBDestReadBufferWidth_Width(width));
267
268 PM3_WRITE_REG(par, PM3FBDestReadMode,
269 PM3FBDestReadMode_ReadEnable |
270 PM3FBDestReadMode_Enable0);
271 PM3_WRITE_REG(par, PM3FBSourceReadBufferAddr, 0x0);
272 PM3_WRITE_REG(par, PM3FBSourceReadBufferOffset, 0x0);
273 PM3_WRITE_REG(par, PM3FBSourceReadBufferWidth,
274 PM3FBSourceReadBufferWidth_Width(width));
275 PM3_WRITE_REG(par, PM3FBSourceReadMode,
276 PM3FBSourceReadMode_Blocking |
277 PM3FBSourceReadMode_ReadEnable);
278
279 PM3_WAIT(par, 2);
280 {
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700281 /* invert bits in bitmask */
282 unsigned long rm = 1 | (3 << 7);
Krzysztof Helta58d67c2007-07-17 04:05:46 -0700283 switch (info->var.bits_per_pixel) {
284 case 8:
285 PM3_WRITE_REG(par, PM3PixelSize,
286 PM3PixelSize_GLOBAL_8BIT);
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700287#ifdef __BIG_ENDIAN
288 rm |= 3 << 15;
289#endif
Krzysztof Helta58d67c2007-07-17 04:05:46 -0700290 break;
291 case 16:
292 PM3_WRITE_REG(par, PM3PixelSize,
293 PM3PixelSize_GLOBAL_16BIT);
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700294#ifdef __BIG_ENDIAN
295 rm |= 2 << 15;
296#endif
Krzysztof Helta58d67c2007-07-17 04:05:46 -0700297 break;
298 case 32:
299 PM3_WRITE_REG(par, PM3PixelSize,
300 PM3PixelSize_GLOBAL_32BIT);
301 break;
302 default:
303 DPRINTK(1, "Unsupported depth %d\n",
304 info->var.bits_per_pixel);
305 break;
306 }
307 PM3_WRITE_REG(par, PM3RasterizerMode, rm);
308 }
309
310 PM3_WAIT(par, 20);
311 PM3_WRITE_REG(par, PM3FBSoftwareWriteMask, 0xffffffff);
312 PM3_WRITE_REG(par, PM3FBHardwareWriteMask, 0xffffffff);
313 PM3_WRITE_REG(par, PM3FBWriteMode,
314 PM3FBWriteMode_WriteEnable |
315 PM3FBWriteMode_OpaqueSpan |
316 PM3FBWriteMode_Enable0);
317 PM3_WRITE_REG(par, PM3FBWriteBufferAddr0, 0x0);
318 PM3_WRITE_REG(par, PM3FBWriteBufferOffset0, 0x0);
319 PM3_WRITE_REG(par, PM3FBWriteBufferWidth0,
320 PM3FBWriteBufferWidth_Width(width));
321
322 PM3_WRITE_REG(par, PM3SizeOfFramebuffer, 0x0);
323 {
324 /* size in lines of FB */
325 unsigned long sofb = info->screen_size /
326 info->fix.line_length;
327 if (sofb > 4095)
328 PM3_WRITE_REG(par, PM3SizeOfFramebuffer, 4095);
329 else
330 PM3_WRITE_REG(par, PM3SizeOfFramebuffer, sofb);
331
332 switch (info->var.bits_per_pixel) {
333 case 8:
334 PM3_WRITE_REG(par, PM3DitherMode,
335 (1 << 10) | (2 << 3));
336 break;
337 case 16:
338 PM3_WRITE_REG(par, PM3DitherMode,
339 (1 << 10) | (1 << 3));
340 break;
341 case 32:
342 PM3_WRITE_REG(par, PM3DitherMode,
343 (1 << 10) | (0 << 3));
344 break;
345 default:
346 DPRINTK(1, "Unsupported depth %d\n",
347 info->current_par->depth);
348 break;
349 }
350 }
351
352 PM3_WRITE_REG(par, PM3dXDom, 0x0);
353 PM3_WRITE_REG(par, PM3dXSub, 0x0);
354 PM3_WRITE_REG(par, PM3dY, (1 << 16));
355 PM3_WRITE_REG(par, PM3StartXDom, 0x0);
356 PM3_WRITE_REG(par, PM3StartXSub, 0x0);
357 PM3_WRITE_REG(par, PM3StartY, 0x0);
358 PM3_WRITE_REG(par, PM3Count, 0x0);
359
360/* Disable LocalBuffer. better safe than sorry */
361 PM3_WRITE_REG(par, PM3LBDestReadMode, 0x0);
362 PM3_WRITE_REG(par, PM3LBDestReadEnables, 0x0);
363 PM3_WRITE_REG(par, PM3LBSourceReadMode, 0x0);
364 PM3_WRITE_REG(par, PM3LBWriteMode, 0x0);
365
366 pm3fb_sync(info);
367}
368
369static void pm3fb_fillrect (struct fb_info *info,
370 const struct fb_fillrect *region)
371{
372 struct pm3_par *par = info->par;
373 struct fb_fillrect modded;
374 int vxres, vyres;
375 u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
376 ((u32*)info->pseudo_palette)[region->color] : region->color;
377
378 if (info->state != FBINFO_STATE_RUNNING)
379 return;
380 if ((info->flags & FBINFO_HWACCEL_DISABLED) ||
381 region->rop != ROP_COPY ) {
382 cfb_fillrect(info, region);
383 return;
384 }
385
386 vxres = info->var.xres_virtual;
387 vyres = info->var.yres_virtual;
388
389 memcpy(&modded, region, sizeof(struct fb_fillrect));
390
391 if(!modded.width || !modded.height ||
392 modded.dx >= vxres || modded.dy >= vyres)
393 return;
394
395 if(modded.dx + modded.width > vxres)
396 modded.width = vxres - modded.dx;
397 if(modded.dy + modded.height > vyres)
398 modded.height = vyres - modded.dy;
399
400 if(info->var.bits_per_pixel == 8)
401 color |= color << 8;
402 if(info->var.bits_per_pixel <= 16)
403 color |= color << 16;
404
405 PM3_WAIT(par, 4);
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700406 /* ROP Ox3 is GXcopy */
Krzysztof Helta58d67c2007-07-17 04:05:46 -0700407 PM3_WRITE_REG(par, PM3Config2D,
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700408 PM3Config2D_UseConstantSource |
409 PM3Config2D_ForegroundROPEnable |
410 (PM3Config2D_ForegroundROP(0x3)) |
411 PM3Config2D_FBWriteEnable);
Krzysztof Helta58d67c2007-07-17 04:05:46 -0700412
413 PM3_WRITE_REG(par, PM3ForegroundColor, color);
414
415 PM3_WRITE_REG(par, PM3RectanglePosition,
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700416 (PM3RectanglePosition_XOffset(modded.dx)) |
417 (PM3RectanglePosition_YOffset(modded.dy)));
Krzysztof Helta58d67c2007-07-17 04:05:46 -0700418
419 PM3_WRITE_REG(par, PM3Render2D,
420 PM3Render2D_XPositive |
421 PM3Render2D_YPositive |
422 PM3Render2D_Operation_Normal |
423 PM3Render2D_SpanOperation |
424 (PM3Render2D_Width(modded.width)) |
425 (PM3Render2D_Height(modded.height)));
426}
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700427
428static void pm3fb_copyarea(struct fb_info *info,
429 const struct fb_copyarea *area)
430{
431 struct pm3_par *par = info->par;
432 struct fb_copyarea modded;
433 u32 vxres, vyres;
434 int x_align, o_x, o_y;
435
436 if (info->state != FBINFO_STATE_RUNNING)
437 return;
438 if (info->flags & FBINFO_HWACCEL_DISABLED) {
439 cfb_copyarea(info, area);
440 return;
441 }
442
443 memcpy(&modded, area, sizeof(struct fb_copyarea));
444
445 vxres = info->var.xres_virtual;
446 vyres = info->var.yres_virtual;
447
448 if(!modded.width || !modded.height ||
449 modded.sx >= vxres || modded.sy >= vyres ||
450 modded.dx >= vxres || modded.dy >= vyres)
451 return;
452
453 if(modded.sx + modded.width > vxres)
454 modded.width = vxres - modded.sx;
455 if(modded.dx + modded.width > vxres)
456 modded.width = vxres - modded.dx;
457 if(modded.sy + modded.height > vyres)
458 modded.height = vyres - modded.sy;
459 if(modded.dy + modded.height > vyres)
460 modded.height = vyres - modded.dy;
461
462 o_x = modded.sx - modded.dx; /*(sx > dx ) ? (sx - dx) : (dx - sx); */
463 o_y = modded.sy - modded.dy; /*(sy > dy ) ? (sy - dy) : (dy - sy); */
464
465 x_align = (modded.sx & 0x1f);
466
467 PM3_WAIT(par, 6);
468
469 PM3_WRITE_REG(par, PM3Config2D,
470 PM3Config2D_UserScissorEnable |
471 PM3Config2D_ForegroundROPEnable |
472 PM3Config2D_Blocking |
473 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
474 PM3Config2D_FBWriteEnable);
475
476 PM3_WRITE_REG(par, PM3ScissorMinXY,
477 ((modded.dy & 0x0fff) << 16) | (modded.dx & 0x0fff));
478 PM3_WRITE_REG(par, PM3ScissorMaxXY,
479 (((modded.dy + modded.height) & 0x0fff) << 16) |
480 ((modded.dx + modded.width) & 0x0fff));
481
482 PM3_WRITE_REG(par, PM3FBSourceReadBufferOffset,
483 PM3FBSourceReadBufferOffset_XOffset(o_x) |
484 PM3FBSourceReadBufferOffset_YOffset(o_y));
485
486 PM3_WRITE_REG(par, PM3RectanglePosition,
487 (PM3RectanglePosition_XOffset(modded.dx - x_align)) |
488 (PM3RectanglePosition_YOffset(modded.dy)));
489
490 PM3_WRITE_REG(par, PM3Render2D,
491 ((modded.sx > modded.dx) ? PM3Render2D_XPositive : 0) |
492 ((modded.sy > modded.dy) ? PM3Render2D_YPositive : 0) |
493 PM3Render2D_Operation_Normal |
494 PM3Render2D_SpanOperation |
495 PM3Render2D_FBSourceReadEnable |
496 (PM3Render2D_Width(modded.width + x_align)) |
497 (PM3Render2D_Height(modded.height)));
498}
499
500static void pm3fb_imageblit(struct fb_info *info, const struct fb_image *image)
501{
502 struct pm3_par *par = info->par;
503 u32 height = image->height;
504 u32 fgx, bgx;
505 const u32 *src = (const u32*)image->data;
506
507 switch (info->fix.visual) {
508 case FB_VISUAL_PSEUDOCOLOR:
509 fgx = image->fg_color;
510 bgx = image->bg_color;
511 break;
512 case FB_VISUAL_TRUECOLOR:
513 default:
514 fgx = par->palette[image->fg_color];
515 bgx = par->palette[image->bg_color];
516 break;
517 }
Krzysztof Heltb0a318e2007-10-16 01:28:31 -0700518 if (image->depth != 1) {
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700519 return cfb_imageblit(info, image);
520 }
521 if (info->var.bits_per_pixel == 8) {
522 fgx |= fgx << 8;
523 bgx |= bgx << 8;
524 }
525 if (info->var.bits_per_pixel <= 16) {
526 fgx |= fgx << 16;
527 bgx |= bgx << 16;
528 }
529
Krzysztof Heltb0a318e2007-10-16 01:28:31 -0700530 PM3_WAIT(par, 7);
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700531
532 PM3_WRITE_REG(par, PM3ForegroundColor, fgx);
533 PM3_WRITE_REG(par, PM3BackgroundColor, bgx);
534
535 /* ROP Ox3 is GXcopy */
536 PM3_WRITE_REG(par, PM3Config2D,
Krzysztof Heltb0a318e2007-10-16 01:28:31 -0700537 PM3Config2D_UserScissorEnable |
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700538 PM3Config2D_UseConstantSource |
539 PM3Config2D_ForegroundROPEnable |
540 (PM3Config2D_ForegroundROP(0x3)) |
541 PM3Config2D_OpaqueSpan |
542 PM3Config2D_FBWriteEnable);
Krzysztof Heltb0a318e2007-10-16 01:28:31 -0700543 PM3_WRITE_REG(par, PM3ScissorMinXY,
544 ((image->dy & 0x0fff) << 16) | (image->dx & 0x0fff));
545 PM3_WRITE_REG(par, PM3ScissorMaxXY,
546 (((image->dy + image->height) & 0x0fff) << 16) |
547 ((image->dx + image->width) & 0x0fff));
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700548 PM3_WRITE_REG(par, PM3RectanglePosition,
549 (PM3RectanglePosition_XOffset(image->dx)) |
550 (PM3RectanglePosition_YOffset(image->dy)));
551 PM3_WRITE_REG(par, PM3Render2D,
552 PM3Render2D_XPositive |
553 PM3Render2D_YPositive |
554 PM3Render2D_Operation_SyncOnBitMask |
555 PM3Render2D_SpanOperation |
556 (PM3Render2D_Width(image->width)) |
557 (PM3Render2D_Height(image->height)));
558
559
560 while (height--) {
Krzysztof Heltc79ba282007-10-16 01:28:32 -0700561 int width = ((image->width + 7) >> 3)
562 + info->pixmap.scan_align - 1;
Krzysztof Heltb0a318e2007-10-16 01:28:31 -0700563 width >>= 2;
Krzysztof Helte7f76df2007-10-16 01:28:29 -0700564
565 while (width >= PM3_FIFO_SIZE) {
566 int i = PM3_FIFO_SIZE - 1;
567
568 PM3_WAIT(par, PM3_FIFO_SIZE);
569 while (i--) {
570 PM3_WRITE_REG(par, PM3BitMaskPattern, *src);
571 src++;
572 }
573 width -= PM3_FIFO_SIZE - 1;
574 }
575
576 PM3_WAIT(par, width + 1);
577 while (width--) {
578 PM3_WRITE_REG(par, PM3BitMaskPattern, *src);
579 src++;
580 }
581 }
582}
Krzysztof Helta58d67c2007-07-17 04:05:46 -0700583/* end of acceleration functions */
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585/* write the mode to registers */
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700586static void pm3fb_write_mode(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700588 struct pm3_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 char tempsync = 0x00, tempmisc = 0x00;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700590 const u32 hsstart = info->var.right_margin;
591 const u32 hsend = hsstart + info->var.hsync_len;
592 const u32 hbend = hsend + info->var.left_margin;
593 const u32 xres = (info->var.xres + 31) & ~31;
594 const u32 htotal = xres + hbend;
595 const u32 vsstart = info->var.lower_margin;
596 const u32 vsend = vsstart + info->var.vsync_len;
597 const u32 vbend = vsend + info->var.upper_margin;
598 const u32 vtotal = info->var.yres + vbend;
599 const u32 width = (info->var.xres_virtual + 7) & ~7;
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700600 const unsigned bpp = info->var.bits_per_pixel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700602 PM3_WAIT(par, 20);
603 PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xffffffff);
604 PM3_WRITE_REG(par, PM3Aperture0, 0x00000000);
605 PM3_WRITE_REG(par, PM3Aperture1, 0x00000000);
606 PM3_WRITE_REG(par, PM3FIFODis, 0x00000007);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700608 PM3_WRITE_REG(par, PM3HTotal,
609 pm3fb_shift_bpp(bpp, htotal - 1));
610 PM3_WRITE_REG(par, PM3HsEnd,
611 pm3fb_shift_bpp(bpp, hsend));
612 PM3_WRITE_REG(par, PM3HsStart,
613 pm3fb_shift_bpp(bpp, hsstart));
614 PM3_WRITE_REG(par, PM3HbEnd,
615 pm3fb_shift_bpp(bpp, hbend));
616 PM3_WRITE_REG(par, PM3HgEnd,
617 pm3fb_shift_bpp(bpp, hbend));
618 PM3_WRITE_REG(par, PM3ScreenStride,
619 pm3fb_shift_bpp(bpp, width));
620 PM3_WRITE_REG(par, PM3VTotal, vtotal - 1);
621 PM3_WRITE_REG(par, PM3VsEnd, vsend - 1);
622 PM3_WRITE_REG(par, PM3VsStart, vsstart - 1);
623 PM3_WRITE_REG(par, PM3VbEnd, vbend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700625 switch (bpp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 case 8:
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700627 PM3_WRITE_REG(par, PM3ByAperture1Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 PM3ByApertureMode_PIXELSIZE_8BIT);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700629 PM3_WRITE_REG(par, PM3ByAperture2Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 PM3ByApertureMode_PIXELSIZE_8BIT);
631 break;
632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 case 16:
634#ifndef __BIG_ENDIAN
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700635 PM3_WRITE_REG(par, PM3ByAperture1Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 PM3ByApertureMode_PIXELSIZE_16BIT);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700637 PM3_WRITE_REG(par, PM3ByAperture2Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 PM3ByApertureMode_PIXELSIZE_16BIT);
639#else
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700640 PM3_WRITE_REG(par, PM3ByAperture1Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 PM3ByApertureMode_PIXELSIZE_16BIT |
642 PM3ByApertureMode_BYTESWAP_BADC);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700643 PM3_WRITE_REG(par, PM3ByAperture2Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 PM3ByApertureMode_PIXELSIZE_16BIT |
645 PM3ByApertureMode_BYTESWAP_BADC);
646#endif /* ! __BIG_ENDIAN */
647 break;
648
649 case 32:
650#ifndef __BIG_ENDIAN
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700651 PM3_WRITE_REG(par, PM3ByAperture1Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 PM3ByApertureMode_PIXELSIZE_32BIT);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700653 PM3_WRITE_REG(par, PM3ByAperture2Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 PM3ByApertureMode_PIXELSIZE_32BIT);
655#else
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700656 PM3_WRITE_REG(par, PM3ByAperture1Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 PM3ByApertureMode_PIXELSIZE_32BIT |
658 PM3ByApertureMode_BYTESWAP_DCBA);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700659 PM3_WRITE_REG(par, PM3ByAperture2Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 PM3ByApertureMode_PIXELSIZE_32BIT |
661 PM3ByApertureMode_BYTESWAP_DCBA);
662#endif /* ! __BIG_ENDIAN */
663 break;
664
665 default:
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700666 DPRINTK("Unsupported depth %d\n", bpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 break;
668 }
669
670 /*
671 * Oxygen VX1 - it appears that setting PM3VideoControl and
672 * then PM3RD_SyncControl to the same SYNC settings undoes
673 * any net change - they seem to xor together. Only set the
674 * sync options in PM3RD_SyncControl. --rmk
675 */
676 {
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700677 unsigned int video = par->video;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679 video &= ~(PM3VideoControl_HSYNC_MASK |
680 PM3VideoControl_VSYNC_MASK);
681 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
682 PM3VideoControl_VSYNC_ACTIVE_HIGH;
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700683 PM3_WRITE_REG(par, PM3VideoControl, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700685 PM3_WRITE_REG(par, PM3VClkCtl,
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700686 (PM3_READ_REG(par, PM3VClkCtl) & 0xFFFFFFFC));
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700687 PM3_WRITE_REG(par, PM3ScreenBase, par->base);
688 PM3_WRITE_REG(par, PM3ChipConfig,
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700689 (PM3_READ_REG(par, PM3ChipConfig) & 0xFFFFFFFD));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700691 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 {
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700693 unsigned char uninitialized_var(m); /* ClkPreScale */
694 unsigned char uninitialized_var(n); /* ClkFeedBackScale */
695 unsigned char uninitialized_var(p); /* ClkPostScale */
696 unsigned long pixclock = PICOS2KHZ(info->var.pixclock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700698 (void)pm3fb_calculate_clock(pixclock, &m, &n, &p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700700 DPRINTK("Pixclock: %ld, Pre: %d, Feedback: %d, Post: %d\n",
701 pixclock, (int) m, (int) n, (int) p);
702
703 PM3_WRITE_DAC_REG(par, PM3RD_DClk0PreScale, m);
704 PM3_WRITE_DAC_REG(par, PM3RD_DClk0FeedbackScale, n);
705 PM3_WRITE_DAC_REG(par, PM3RD_DClk0PostScale, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 }
707 /*
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700708 PM3_WRITE_DAC_REG(par, PM3RD_IndexControl, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 */
710 /*
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700711 PM3_SLOW_WRITE_REG(par, PM3RD_IndexControl, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 */
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700713 if ((par->video & PM3VideoControl_HSYNC_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 PM3VideoControl_HSYNC_ACTIVE_HIGH)
715 tempsync |= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700716 if ((par->video & PM3VideoControl_VSYNC_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 PM3VideoControl_VSYNC_ACTIVE_HIGH)
718 tempsync |= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700720 PM3_WRITE_DAC_REG(par, PM3RD_SyncControl, tempsync);
721 DPRINTK("PM3RD_SyncControl: %d\n", tempsync);
722
723 PM3_WRITE_DAC_REG(par, PM3RD_DACControl, 0x00);
724
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700725 switch (pm3fb_depth(&info->var)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 case 8:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700727 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 PM3RD_PixelSize_8_BIT_PIXELS);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700729 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 PM3RD_ColorFormat_CI8_COLOR |
731 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
732 tempmisc |= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
733 break;
734 case 12:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700735 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 PM3RD_PixelSize_16_BIT_PIXELS);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700737 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 PM3RD_ColorFormat_4444_COLOR |
739 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
740 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
741 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
742 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700743 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 case 15:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700745 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 PM3RD_PixelSize_16_BIT_PIXELS);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700747 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 PM3RD_ColorFormat_5551_FRONT_COLOR |
749 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
750 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
751 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
752 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700753 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 case 16:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700755 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 PM3RD_PixelSize_16_BIT_PIXELS);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700757 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 PM3RD_ColorFormat_565_FRONT_COLOR |
759 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
760 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
761 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
762 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
763 break;
764 case 32:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700765 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 PM3RD_PixelSize_32_BIT_PIXELS);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700767 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 PM3RD_ColorFormat_8888_COLOR |
769 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
770 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
771 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
772 break;
773 }
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700774 PM3_WRITE_DAC_REG(par, PM3RD_MiscControl, tempmisc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700777/*
778 * hardware independent functions
779 */
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700780static int pm3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700782 u32 lpitch;
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700783 unsigned bpp = var->red.length + var->green.length
784 + var->blue.length + var->transp.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700786 if ( bpp != var->bits_per_pixel ) {
787 /* set predefined mode for bits_per_pixel settings */
788
789 switch(var->bits_per_pixel) {
790 case 8:
791 var->red.length = var->green.length = var->blue.length = 8;
792 var->red.offset = var->green.offset = var->blue.offset = 0;
793 var->transp.offset = 0;
794 var->transp.length = 0;
795 break;
796 case 16:
797 var->red.length = var->blue.length = 5;
798 var->green.length = 6;
799 var->transp.length = 0;
800 break;
801 case 32:
802 var->red.length = var->green.length = var->blue.length = 8;
803 var->transp.length = 8;
804 break;
805 default:
806 DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
807 return -EINVAL;
808 }
809 }
810 /* it is assumed BGRA order */
811 if (var->bits_per_pixel > 8 )
812 {
813 var->blue.offset = 0;
814 var->green.offset = var->blue.length;
815 var->red.offset = var->green.offset + var->green.length;
816 var->transp.offset = var->red.offset + var->red.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 var->height = var->width = -1;
819
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700820 if (var->xres != var->xres_virtual) {
821 DPRINTK("virtual x resolution != physical x resolution not supported\n");
822 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700825 if (var->yres > var->yres_virtual) {
826 DPRINTK("virtual y resolution < physical y resolution not possible\n");
827 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700829
830 if (var->xoffset) {
831 DPRINTK("xoffset not supported\n");
832 return -EINVAL;
833 }
834
835 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
836 DPRINTK("interlace not supported\n");
837 return -EINVAL;
838 }
839
840 var->xres = (var->xres + 31) & ~31; /* could sometimes be 8 */
841 lpitch = var->xres * ((var->bits_per_pixel + 7)>>3);
842
843 if (var->xres < 200 || var->xres > 2048) {
844 DPRINTK("width not supported: %u\n", var->xres);
845 return -EINVAL;
846 }
847
848 if (var->yres < 200 || var->yres > 4095) {
849 DPRINTK("height not supported: %u\n", var->yres);
850 return -EINVAL;
851 }
852
853 if (lpitch * var->yres_virtual > info->fix.smem_len) {
854 DPRINTK("no memory for screen (%ux%ux%u)\n",
855 var->xres, var->yres_virtual, var->bits_per_pixel);
856 return -EINVAL;
857 }
858
859 if (PICOS2KHZ(var->pixclock) > PM3_MAX_PIXCLOCK) {
860 DPRINTK("pixclock too high (%ldKHz)\n", PICOS2KHZ(var->pixclock));
861 return -EINVAL;
862 }
863
864 var->accel_flags = 0; /* Can't mmap if this is on */
865
866 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
867 var->xres, var->yres, var->bits_per_pixel);
868 return 0;
869}
870
871static int pm3fb_set_par(struct fb_info *info)
872{
873 struct pm3_par *par = info->par;
874 const u32 xres = (info->var.xres + 31) & ~31;
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700875 const unsigned bpp = info->var.bits_per_pixel;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700876
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700877 par->base = pm3fb_shift_bpp(bpp,(info->var.yoffset * xres)
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700878 + info->var.xoffset);
879 par->video = 0;
880
881 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
882 par->video |= PM3VideoControl_HSYNC_ACTIVE_HIGH;
883 else
884 par->video |= PM3VideoControl_HSYNC_ACTIVE_LOW;
885
886 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
887 par->video |= PM3VideoControl_VSYNC_ACTIVE_HIGH;
888 else
889 par->video |= PM3VideoControl_VSYNC_ACTIVE_LOW;
890
891 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
892 par->video |= PM3VideoControl_LINE_DOUBLE_ON;
893 else
894 par->video |= PM3VideoControl_LINE_DOUBLE_OFF;
895
Krzysztof Helt0bd327e2007-06-01 00:47:09 -0700896 if ((info->var.activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW)
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700897 par->video |= PM3VideoControl_ENABLE;
898 else {
Krzysztof Heltf259ebb2007-10-16 01:28:31 -0700899 par->video &= ~PM3VideoControl_ENABLE;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700900 DPRINTK("PM3Video disabled\n");
901 }
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700902 switch (bpp) {
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700903 case 8:
904 par->video |= PM3VideoControl_PIXELSIZE_8BIT;
905 break;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700906 case 16:
907 par->video |= PM3VideoControl_PIXELSIZE_16BIT;
908 break;
909 case 32:
910 par->video |= PM3VideoControl_PIXELSIZE_32BIT;
911 break;
912 default:
913 DPRINTK("Unsupported depth\n");
914 break;
915 }
916
917 info->fix.visual =
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700918 (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700919 info->fix.line_length = ((info->var.xres_virtual + 7) & ~7)
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700920 * bpp / 8;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700921
922/* pm3fb_clear_memory(info, 0);*/
923 pm3fb_clear_colormap(par, 0, 0, 0);
Krzysztof Heltf259ebb2007-10-16 01:28:31 -0700924 PM3_WRITE_DAC_REG(par, PM3RD_CursorMode, 0);
Krzysztof Helta58d67c2007-07-17 04:05:46 -0700925 pm3fb_init_engine(info);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700926 pm3fb_write_mode(info);
927 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928}
929
930static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green,
931 unsigned blue, unsigned transp,
932 struct fb_info *info)
933{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700934 struct pm3_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700936 if (regno >= 256) /* no. of hw registers */
937 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700939 /* grayscale works only partially under directcolor */
940 if (info->var.grayscale) {
941 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
942 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
943 }
944
945 /* Directcolor:
946 * var->{color}.offset contains start of bitfield
947 * var->{color}.length contains length of bitfield
948 * {hardwarespecific} contains width of DAC
949 * pseudo_palette[X] is programmed to (X << red.offset) |
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700950 * (X << green.offset) |
951 * (X << blue.offset)
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700952 * RAMDAC[X] is programmed to (red, green, blue)
953 * color depth = SUM(var->{color}.length)
954 *
955 * Pseudocolor:
956 * var->{color}.offset is 0
957 * var->{color}.length contains width of DAC or the number of unique
958 * colors available (color depth)
959 * pseudo_palette is not used
960 * RAMDAC[X] is programmed to (red, green, blue)
961 * color depth = var->{color}.length
962 */
963
964 /*
965 * This is the point where the color is converted to something that
966 * is acceptable by the hardware.
967 */
968#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
969 red = CNVT_TOHW(red, info->var.red.length);
970 green = CNVT_TOHW(green, info->var.green.length);
971 blue = CNVT_TOHW(blue, info->var.blue.length);
972 transp = CNVT_TOHW(transp, info->var.transp.length);
973#undef CNVT_TOHW
974
975 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
976 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
977 u32 v;
978
979 if (regno >= 16)
980 return -EINVAL;
981
982 v = (red << info->var.red.offset) |
983 (green << info->var.green.offset) |
984 (blue << info->var.blue.offset) |
985 (transp << info->var.transp.offset);
986
987 switch (info->var.bits_per_pixel) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 case 8:
989 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 case 16:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 case 32:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700992 ((u32*)(info->pseudo_palette))[regno] = v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 break;
994 }
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700995 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 }
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700997 else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
998 pm3fb_set_color(par, regno, red, green, blue);
999
1000 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001}
1002
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001003static int pm3fb_pan_display(struct fb_var_screeninfo *var,
1004 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001006 struct pm3_par *par = info->par;
1007 const u32 xres = (var->xres + 31) & ~31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001009 par->base = pm3fb_shift_bpp(var->bits_per_pixel,
1010 (var->yoffset * xres)
1011 + var->xoffset);
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001012 PM3_WAIT(par, 1);
1013 PM3_WRITE_REG(par, PM3ScreenBase, par->base);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001014 return 0;
1015}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001017static int pm3fb_blank(int blank_mode, struct fb_info *info)
1018{
1019 struct pm3_par *par = info->par;
1020 u32 video = par->video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
1022 /*
1023 * Oxygen VX1 - it appears that setting PM3VideoControl and
1024 * then PM3RD_SyncControl to the same SYNC settings undoes
1025 * any net change - they seem to xor together. Only set the
1026 * sync options in PM3RD_SyncControl. --rmk
1027 */
1028 video &= ~(PM3VideoControl_HSYNC_MASK |
1029 PM3VideoControl_VSYNC_MASK);
1030 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
1031 PM3VideoControl_VSYNC_ACTIVE_HIGH;
1032
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001033 switch (blank_mode) {
1034 case FB_BLANK_UNBLANK:
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001035 video |= PM3VideoControl_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 break;
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001037 case FB_BLANK_NORMAL:
1038 video &= ~(PM3VideoControl_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 break;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001040 case FB_BLANK_HSYNC_SUSPEND:
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001041 video &= ~(PM3VideoControl_HSYNC_MASK |
1042 PM3VideoControl_BLANK_ACTIVE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 break;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001044 case FB_BLANK_VSYNC_SUSPEND:
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001045 video &= ~(PM3VideoControl_VSYNC_MASK |
1046 PM3VideoControl_BLANK_ACTIVE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 break;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001048 case FB_BLANK_POWERDOWN:
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001049 video &= ~(PM3VideoControl_HSYNC_MASK |
1050 PM3VideoControl_VSYNC_MASK |
1051 PM3VideoControl_BLANK_ACTIVE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 default:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001054 DPRINTK("Unsupported blanking %d\n", blank_mode);
1055 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 }
1057
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001058 PM3_WAIT(par, 1);
1059 PM3_WRITE_REG(par,PM3VideoControl, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 return 0;
1061}
1062
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001063 /*
1064 * Frame buffer operations
1065 */
1066
1067static struct fb_ops pm3fb_ops = {
1068 .owner = THIS_MODULE,
1069 .fb_check_var = pm3fb_check_var,
1070 .fb_set_par = pm3fb_set_par,
1071 .fb_setcolreg = pm3fb_setcolreg,
1072 .fb_pan_display = pm3fb_pan_display,
Krzysztof Helta58d67c2007-07-17 04:05:46 -07001073 .fb_fillrect = pm3fb_fillrect,
Krzysztof Helte7f76df2007-10-16 01:28:29 -07001074 .fb_copyarea = pm3fb_copyarea,
1075 .fb_imageblit = pm3fb_imageblit,
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001076 .fb_blank = pm3fb_blank,
Krzysztof Helta58d67c2007-07-17 04:05:46 -07001077 .fb_sync = pm3fb_sync,
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001078};
1079
1080/* ------------------------------------------------------------------------- */
1081
1082 /*
1083 * Initialization
1084 */
1085
1086/* mmio register are already mapped when this function is called */
1087/* the pm3fb_fix.smem_start is also set */
1088static unsigned long pm3fb_size_memory(struct pm3_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001090 unsigned long memsize = 0, tempBypass, i, temp1, temp2;
1091 unsigned char __iomem *screen_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001093 pm3fb_fix.smem_len = 64 * 1024l * 1024; /* request full aperture size */
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001094 /* Linear frame buffer - request region and map it. */
1095 if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
1096 "pm3fb smem")) {
1097 printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
1098 return 0;
1099 }
1100 screen_mem =
1101 ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
1102 if (!screen_mem) {
1103 printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
1104 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
1105 return 0;
1106 }
1107
1108 /* TODO: card-specific stuff, *before* accessing *any* FB memory */
1109 /* For Appian Jeronimo 2000 board second head */
1110
1111 tempBypass = PM3_READ_REG(par, PM3MemBypassWriteMask);
1112
1113 DPRINTK("PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass);
1114
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001115 PM3_WAIT(par, 1);
1116 PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xFFFFFFFF);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001117
1118 /* pm3 split up memory, replicates, and do a lot of nasty stuff IMHO ;-) */
1119 for (i = 0; i < 32; i++) {
1120 fb_writel(i * 0x00345678,
1121 (screen_mem + (i * 1048576)));
1122 mb();
1123 temp1 = fb_readl((screen_mem + (i * 1048576)));
1124
1125 /* Let's check for wrapover, write will fail at 16MB boundary */
1126 if (temp1 == (i * 0x00345678))
1127 memsize = i;
1128 else
1129 break;
1130 }
1131
1132 DPRINTK("First detect pass already got %ld MB\n", memsize + 1);
1133
1134 if (memsize + 1 == i) {
1135 for (i = 0; i < 32; i++) {
1136 /* Clear first 32MB ; 0 is 0, no need to byteswap */
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001137 writel(0x0000000, (screen_mem + (i * 1048576)));
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001138 }
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001139 wmb();
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001140
1141 for (i = 32; i < 64; i++) {
1142 fb_writel(i * 0x00345678,
1143 (screen_mem + (i * 1048576)));
1144 mb();
1145 temp1 =
1146 fb_readl((screen_mem + (i * 1048576)));
1147 temp2 =
1148 fb_readl((screen_mem + ((i - 32) * 1048576)));
1149 /* different value, different RAM... */
1150 if ((temp1 == (i * 0x00345678)) && (temp2 == 0))
1151 memsize = i;
1152 else
1153 break;
1154 }
1155 }
1156 DPRINTK("Second detect pass got %ld MB\n", memsize + 1);
1157
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001158 PM3_WAIT(par, 1);
1159 PM3_WRITE_REG(par, PM3MemBypassWriteMask, tempBypass);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001160
1161 iounmap(screen_mem);
1162 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
1163 memsize = 1048576 * (memsize + 1);
1164
1165 DPRINTK("Returning 0x%08lx bytes\n", memsize);
1166
1167 return memsize;
1168}
1169
1170static int __devinit pm3fb_probe(struct pci_dev *dev,
1171 const struct pci_device_id *ent)
1172{
1173 struct fb_info *info;
1174 struct pm3_par *par;
1175 struct device* device = &dev->dev; /* for pci drivers */
1176 int err, retval = -ENXIO;
1177
1178 err = pci_enable_device(dev);
1179 if (err) {
1180 printk(KERN_WARNING "pm3fb: Can't enable PCI dev: %d\n", err);
1181 return err;
1182 }
1183 /*
1184 * Dynamically allocate info and par
1185 */
1186 info = framebuffer_alloc(sizeof(struct pm3_par), device);
1187
1188 if (!info)
1189 return -ENOMEM;
1190 par = info->par;
1191
1192 /*
1193 * Here we set the screen_base to the virtual memory address
1194 * for the framebuffer.
1195 */
1196 pm3fb_fix.mmio_start = pci_resource_start(dev, 0);
1197 pm3fb_fix.mmio_len = PM3_REGS_SIZE;
Krzysztof Heltc79ba282007-10-16 01:28:32 -07001198#if defined(__BIG_ENDIAN)
1199 pm3fb_fix.mmio_start += PM3_REGS_SIZE;
1200 DPRINTK("Adjusting register base for big-endian.\n");
1201#endif
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001202
1203 /* Registers - request region and map it. */
1204 if (!request_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len,
1205 "pm3fb regbase")) {
1206 printk(KERN_WARNING "pm3fb: Can't reserve regbase.\n");
1207 goto err_exit_neither;
1208 }
1209 par->v_regs =
1210 ioremap_nocache(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
1211 if (!par->v_regs) {
1212 printk(KERN_WARNING "pm3fb: Can't remap %s register area.\n",
1213 pm3fb_fix.id);
1214 release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
1215 goto err_exit_neither;
1216 }
1217
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001218 /* Linear frame buffer - request region and map it. */
1219 pm3fb_fix.smem_start = pci_resource_start(dev, 1);
1220 pm3fb_fix.smem_len = pm3fb_size_memory(par);
1221 if (!pm3fb_fix.smem_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 {
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001223 printk(KERN_WARNING "pm3fb: Can't find memory on board.\n");
1224 goto err_exit_mmio;
1225 }
1226 if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
1227 "pm3fb smem")) {
1228 printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
1229 goto err_exit_mmio;
1230 }
1231 info->screen_base =
1232 ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
1233 if (!info->screen_base) {
1234 printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
1235 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
1236 goto err_exit_mmio;
1237 }
1238 info->screen_size = pm3fb_fix.smem_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001240 info->fbops = &pm3fb_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001242 par->video = PM3_READ_REG(par, PM3VideoControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001244 info->fix = pm3fb_fix;
1245 info->pseudo_palette = par->palette;
Krzysztof Helta58d67c2007-07-17 04:05:46 -07001246 info->flags = FBINFO_DEFAULT |
Krzysztof Heltc79ba282007-10-16 01:28:32 -07001247 FBINFO_HWACCEL_XPAN |
1248 FBINFO_HWACCEL_YPAN |
Krzysztof Helte7f76df2007-10-16 01:28:29 -07001249 FBINFO_HWACCEL_COPYAREA |
1250 FBINFO_HWACCEL_IMAGEBLIT |
1251 FBINFO_HWACCEL_FILLRECT;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001252
Krzysztof Heltb0a318e2007-10-16 01:28:31 -07001253 info->pixmap.addr = kmalloc(PM3_PIXMAP_SIZE, GFP_KERNEL);
1254 if (!info->pixmap.addr) {
1255 retval = -ENOMEM;
1256 goto err_exit_pixmap;
1257 }
1258 info->pixmap.size = PM3_PIXMAP_SIZE;
1259 info->pixmap.buf_align = 4;
1260 info->pixmap.scan_align = 4;
1261 info->pixmap.access_align = 32;
1262 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1263
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001264 /*
1265 * This should give a reasonable default video mode. The following is
1266 * done when we can set a video mode.
1267 */
1268 if (!mode_option)
1269 mode_option = "640x480@60";
1270
1271 retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
1272
1273 if (!retval || retval == 4) {
1274 retval = -EINVAL;
1275 goto err_exit_both;
1276 }
1277
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001278 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
1279 retval = -ENOMEM;
1280 goto err_exit_both;
1281 }
1282
1283 /*
1284 * For drivers that can...
1285 */
1286 pm3fb_check_var(&info->var, info);
1287
1288 if (register_framebuffer(info) < 0) {
1289 retval = -EINVAL;
1290 goto err_exit_all;
1291 }
1292 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
1293 info->fix.id);
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001294 pci_set_drvdata(dev, info);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001295 return 0;
1296
1297 err_exit_all:
1298 fb_dealloc_cmap(&info->cmap);
1299 err_exit_both:
Krzysztof Heltb0a318e2007-10-16 01:28:31 -07001300 kfree(info->pixmap.addr);
1301 err_exit_pixmap:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001302 iounmap(info->screen_base);
1303 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
1304 err_exit_mmio:
1305 iounmap(par->v_regs);
1306 release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
1307 err_exit_neither:
1308 framebuffer_release(info);
1309 return retval;
1310}
1311
1312 /*
1313 * Cleanup
1314 */
1315static void __devexit pm3fb_remove(struct pci_dev *dev)
1316{
1317 struct fb_info *info = pci_get_drvdata(dev);
1318
1319 if (info) {
1320 struct fb_fix_screeninfo *fix = &info->fix;
1321 struct pm3_par *par = info->par;
1322
1323 unregister_framebuffer(info);
1324 fb_dealloc_cmap(&info->cmap);
1325
1326 iounmap(info->screen_base);
1327 release_mem_region(fix->smem_start, fix->smem_len);
1328 iounmap(par->v_regs);
1329 release_mem_region(fix->mmio_start, fix->mmio_len);
1330
1331 pci_set_drvdata(dev, NULL);
Krzysztof Heltb0a318e2007-10-16 01:28:31 -07001332 kfree(info->pixmap.addr);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001333 framebuffer_release(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 }
1335}
1336
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001337static struct pci_device_id pm3fb_id_table[] = {
1338 { PCI_VENDOR_ID_3DLABS, 0x0a,
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001339 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001340 { 0, }
1341};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001343/* For PCI drivers */
1344static struct pci_driver pm3fb_driver = {
1345 .name = "pm3fb",
1346 .id_table = pm3fb_id_table,
1347 .probe = pm3fb_probe,
1348 .remove = __devexit_p(pm3fb_remove),
1349};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001351MODULE_DEVICE_TABLE(pci, pm3fb_id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Adrian Bunkb309c052007-07-17 04:05:46 -07001353static int __init pm3fb_init(void)
Krzysztof Helt2686ba82007-05-23 13:57:48 -07001354{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001355#ifndef MODULE
Adrian Bunkb309c052007-07-17 04:05:46 -07001356 if (fb_get_options("pm3fb", NULL))
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001357 return -ENODEV;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001358#endif
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001359 return pci_register_driver(&pm3fb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360}
1361
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001362static void __exit pm3fb_exit(void)
1363{
1364 pci_unregister_driver(&pm3fb_driver);
1365}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Krzysztof Heltf23a06f2007-05-10 22:23:25 -07001367module_init(pm3fb_init);
1368module_exit(pm3fb_exit);
1369
1370MODULE_LICENSE("GPL");