blob: 616a0c08e30c2f3f014e982203a495b477246e88 [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 Heltf23a06f2007-05-10 22:23:25 -070049/*
50 * Driver data
51 */
52static char *mode_option __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070054/*
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070055 * This structure defines the hardware state of the graphics card. Normally
56 * you place this in a header file in linux/include/video. This file usually
57 * also includes register information. That allows other driver subsystems
58 * and userland applications the ability to use the same header file to
59 * avoid duplicate work and easy porting of software.
60 */
61struct pm3_par {
62 unsigned char __iomem *v_regs;/* virtual address of p_regs */
63 u32 video; /* video flags before blanking */
64 u32 base; /* screen base (xoffset+yoffset) in 128 bits unit */
Krzysztof Helt2686ba82007-05-23 13:57:48 -070065 u32 palette[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -070066};
67
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070068/*
69 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
70 * if we don't use modedb. If we do use modedb see pm3fb_init how to use it
71 * to get a fb_var_screeninfo. Otherwise define a default var as well.
72 */
73static struct fb_fix_screeninfo pm3fb_fix __devinitdata = {
74 .id = "Permedia3",
75 .type = FB_TYPE_PACKED_PIXELS,
76 .visual = FB_VISUAL_PSEUDOCOLOR,
77 .xpanstep = 1,
78 .ypanstep = 1,
79 .ywrapstep = 0,
80 .accel = FB_ACCEL_NONE,
81};
82
83/*
84 * Utility functions
85 */
86
87static inline u32 PM3_READ_REG(struct pm3_par *par, s32 off)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070089 return fb_readl(par->v_regs + off);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070092static inline void PM3_WRITE_REG(struct pm3_par *par, s32 off, u32 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070094 fb_writel(v, par->v_regs + off);
95}
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Krzysztof Heltf23a06f2007-05-10 22:23:25 -070097static inline void PM3_WAIT(struct pm3_par *par, u32 n)
98{
99 while (PM3_READ_REG(par, PM3InFIFOSpace) < n);
100}
101
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700102static inline void PM3_WRITE_DAC_REG(struct pm3_par *par, unsigned r, u8 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700104 PM3_WAIT(par, 3);
105 PM3_WRITE_REG(par, PM3RD_IndexHigh, (r >> 8) & 0xff);
106 PM3_WRITE_REG(par, PM3RD_IndexLow, r & 0xff);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700107 wmb();
108 PM3_WRITE_REG(par, PM3RD_IndexedData, v);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700109 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700112static inline void pm3fb_set_color(struct pm3_par *par, unsigned char regno,
113 unsigned char r, unsigned char g, unsigned char b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700115 PM3_WAIT(par, 4);
116 PM3_WRITE_REG(par, PM3RD_PaletteWriteAddress, regno);
117 wmb();
118 PM3_WRITE_REG(par, PM3RD_PaletteData, r);
119 wmb();
120 PM3_WRITE_REG(par, PM3RD_PaletteData, g);
121 wmb();
122 PM3_WRITE_REG(par, PM3RD_PaletteData, b);
123 wmb();
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700124}
125
126static void pm3fb_clear_colormap(struct pm3_par *par,
127 unsigned char r, unsigned char g, unsigned char b)
128{
129 int i;
130
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700131 for (i = 0; i < 256 ; i++)
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700132 pm3fb_set_color(par, i, r, g, b);
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
136/* Calculating various clock parameter */
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700137static void pm3fb_calculate_clock(unsigned long reqclock,
138 unsigned char *prescale,
139 unsigned char *feedback,
140 unsigned char *postscale)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
142 int f, pre, post;
143 unsigned long freq;
144 long freqerr = 1000;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700145 long currerr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147 for (f = 1; f < 256; f++) {
148 for (pre = 1; pre < 256; pre++) {
149 for (post = 0; post < 5; post++) {
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700150 freq = ((2*PM3_REF_CLOCK * f) >> post) / pre;
151 currerr = (reqclock > freq)
152 ? reqclock - freq
153 : freq - reqclock;
154 if (currerr < freqerr) {
155 freqerr = currerr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 *feedback = f;
157 *prescale = pre;
158 *postscale = post;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160 }
161 }
162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700165static inline int pm3fb_depth(const struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700167 if ( var->bits_per_pixel == 16 )
168 return var->red.length + var->green.length
169 + var->blue.length;
170
171 return var->bits_per_pixel;
172}
173
174static inline int pm3fb_shift_bpp(unsigned bpp, int v)
175{
176 switch (bpp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 case 8:
178 return (v >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 case 16:
180 return (v >> 3);
181 case 32:
182 return (v >> 2);
183 }
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700184 DPRINTK("Unsupported depth %u\n", bpp);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700185 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}
187
188/* write the mode to registers */
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700189static void pm3fb_write_mode(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700191 struct pm3_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 char tempsync = 0x00, tempmisc = 0x00;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700193 const u32 hsstart = info->var.right_margin;
194 const u32 hsend = hsstart + info->var.hsync_len;
195 const u32 hbend = hsend + info->var.left_margin;
196 const u32 xres = (info->var.xres + 31) & ~31;
197 const u32 htotal = xres + hbend;
198 const u32 vsstart = info->var.lower_margin;
199 const u32 vsend = vsstart + info->var.vsync_len;
200 const u32 vbend = vsend + info->var.upper_margin;
201 const u32 vtotal = info->var.yres + vbend;
202 const u32 width = (info->var.xres_virtual + 7) & ~7;
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700203 const unsigned bpp = info->var.bits_per_pixel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700205 PM3_WAIT(par, 20);
206 PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xffffffff);
207 PM3_WRITE_REG(par, PM3Aperture0, 0x00000000);
208 PM3_WRITE_REG(par, PM3Aperture1, 0x00000000);
209 PM3_WRITE_REG(par, PM3FIFODis, 0x00000007);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700211 PM3_WRITE_REG(par, PM3HTotal,
212 pm3fb_shift_bpp(bpp, htotal - 1));
213 PM3_WRITE_REG(par, PM3HsEnd,
214 pm3fb_shift_bpp(bpp, hsend));
215 PM3_WRITE_REG(par, PM3HsStart,
216 pm3fb_shift_bpp(bpp, hsstart));
217 PM3_WRITE_REG(par, PM3HbEnd,
218 pm3fb_shift_bpp(bpp, hbend));
219 PM3_WRITE_REG(par, PM3HgEnd,
220 pm3fb_shift_bpp(bpp, hbend));
221 PM3_WRITE_REG(par, PM3ScreenStride,
222 pm3fb_shift_bpp(bpp, width));
223 PM3_WRITE_REG(par, PM3VTotal, vtotal - 1);
224 PM3_WRITE_REG(par, PM3VsEnd, vsend - 1);
225 PM3_WRITE_REG(par, PM3VsStart, vsstart - 1);
226 PM3_WRITE_REG(par, PM3VbEnd, vbend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700228 switch (bpp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 case 8:
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700230 PM3_WRITE_REG(par, PM3ByAperture1Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 PM3ByApertureMode_PIXELSIZE_8BIT);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700232 PM3_WRITE_REG(par, PM3ByAperture2Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 PM3ByApertureMode_PIXELSIZE_8BIT);
234 break;
235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 case 16:
237#ifndef __BIG_ENDIAN
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700238 PM3_WRITE_REG(par, PM3ByAperture1Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 PM3ByApertureMode_PIXELSIZE_16BIT);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700240 PM3_WRITE_REG(par, PM3ByAperture2Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 PM3ByApertureMode_PIXELSIZE_16BIT);
242#else
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700243 PM3_WRITE_REG(par, PM3ByAperture1Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 PM3ByApertureMode_PIXELSIZE_16BIT |
245 PM3ByApertureMode_BYTESWAP_BADC);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700246 PM3_WRITE_REG(par, PM3ByAperture2Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 PM3ByApertureMode_PIXELSIZE_16BIT |
248 PM3ByApertureMode_BYTESWAP_BADC);
249#endif /* ! __BIG_ENDIAN */
250 break;
251
252 case 32:
253#ifndef __BIG_ENDIAN
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700254 PM3_WRITE_REG(par, PM3ByAperture1Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 PM3ByApertureMode_PIXELSIZE_32BIT);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700256 PM3_WRITE_REG(par, PM3ByAperture2Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 PM3ByApertureMode_PIXELSIZE_32BIT);
258#else
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700259 PM3_WRITE_REG(par, PM3ByAperture1Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 PM3ByApertureMode_PIXELSIZE_32BIT |
261 PM3ByApertureMode_BYTESWAP_DCBA);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700262 PM3_WRITE_REG(par, PM3ByAperture2Mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 PM3ByApertureMode_PIXELSIZE_32BIT |
264 PM3ByApertureMode_BYTESWAP_DCBA);
265#endif /* ! __BIG_ENDIAN */
266 break;
267
268 default:
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700269 DPRINTK("Unsupported depth %d\n", bpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 break;
271 }
272
273 /*
274 * Oxygen VX1 - it appears that setting PM3VideoControl and
275 * then PM3RD_SyncControl to the same SYNC settings undoes
276 * any net change - they seem to xor together. Only set the
277 * sync options in PM3RD_SyncControl. --rmk
278 */
279 {
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700280 unsigned int video = par->video;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282 video &= ~(PM3VideoControl_HSYNC_MASK |
283 PM3VideoControl_VSYNC_MASK);
284 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
285 PM3VideoControl_VSYNC_ACTIVE_HIGH;
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700286 PM3_WRITE_REG(par, PM3VideoControl, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 }
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700288 PM3_WRITE_REG(par, PM3VClkCtl,
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700289 (PM3_READ_REG(par, PM3VClkCtl) & 0xFFFFFFFC));
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700290 PM3_WRITE_REG(par, PM3ScreenBase, par->base);
291 PM3_WRITE_REG(par, PM3ChipConfig,
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700292 (PM3_READ_REG(par, PM3ChipConfig) & 0xFFFFFFFD));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700294 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 {
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700296 unsigned char uninitialized_var(m); /* ClkPreScale */
297 unsigned char uninitialized_var(n); /* ClkFeedBackScale */
298 unsigned char uninitialized_var(p); /* ClkPostScale */
299 unsigned long pixclock = PICOS2KHZ(info->var.pixclock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700301 (void)pm3fb_calculate_clock(pixclock, &m, &n, &p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700303 DPRINTK("Pixclock: %ld, Pre: %d, Feedback: %d, Post: %d\n",
304 pixclock, (int) m, (int) n, (int) p);
305
306 PM3_WRITE_DAC_REG(par, PM3RD_DClk0PreScale, m);
307 PM3_WRITE_DAC_REG(par, PM3RD_DClk0FeedbackScale, n);
308 PM3_WRITE_DAC_REG(par, PM3RD_DClk0PostScale, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
310 /*
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700311 PM3_WRITE_DAC_REG(par, PM3RD_IndexControl, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 */
313 /*
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700314 PM3_SLOW_WRITE_REG(par, PM3RD_IndexControl, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 */
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700316 if ((par->video & PM3VideoControl_HSYNC_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 PM3VideoControl_HSYNC_ACTIVE_HIGH)
318 tempsync |= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700319 if ((par->video & PM3VideoControl_VSYNC_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 PM3VideoControl_VSYNC_ACTIVE_HIGH)
321 tempsync |= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700323 PM3_WRITE_DAC_REG(par, PM3RD_SyncControl, tempsync);
324 DPRINTK("PM3RD_SyncControl: %d\n", tempsync);
325
326 PM3_WRITE_DAC_REG(par, PM3RD_DACControl, 0x00);
327
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700328 switch (pm3fb_depth(&info->var)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 case 8:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700330 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 PM3RD_PixelSize_8_BIT_PIXELS);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700332 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 PM3RD_ColorFormat_CI8_COLOR |
334 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
335 tempmisc |= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
336 break;
337 case 12:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700338 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 PM3RD_PixelSize_16_BIT_PIXELS);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700340 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 PM3RD_ColorFormat_4444_COLOR |
342 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
343 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
344 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
345 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700346 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 case 15:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700348 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 PM3RD_PixelSize_16_BIT_PIXELS);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700350 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 PM3RD_ColorFormat_5551_FRONT_COLOR |
352 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
353 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
354 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
355 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700356 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 case 16:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700358 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 PM3RD_PixelSize_16_BIT_PIXELS);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700360 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 PM3RD_ColorFormat_565_FRONT_COLOR |
362 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
363 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
364 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
365 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
366 break;
367 case 32:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700368 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 PM3RD_PixelSize_32_BIT_PIXELS);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700370 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 PM3RD_ColorFormat_8888_COLOR |
372 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
373 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
374 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
375 break;
376 }
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700377 PM3_WRITE_DAC_REG(par, PM3RD_MiscControl, tempmisc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700380/*
381 * hardware independent functions
382 */
383int pm3fb_init(void);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700384
385static int pm3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700387 u32 lpitch;
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700388 unsigned bpp = var->red.length + var->green.length
389 + var->blue.length + var->transp.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700391 if ( bpp != var->bits_per_pixel ) {
392 /* set predefined mode for bits_per_pixel settings */
393
394 switch(var->bits_per_pixel) {
395 case 8:
396 var->red.length = var->green.length = var->blue.length = 8;
397 var->red.offset = var->green.offset = var->blue.offset = 0;
398 var->transp.offset = 0;
399 var->transp.length = 0;
400 break;
401 case 16:
402 var->red.length = var->blue.length = 5;
403 var->green.length = 6;
404 var->transp.length = 0;
405 break;
406 case 32:
407 var->red.length = var->green.length = var->blue.length = 8;
408 var->transp.length = 8;
409 break;
410 default:
411 DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
412 return -EINVAL;
413 }
414 }
415 /* it is assumed BGRA order */
416 if (var->bits_per_pixel > 8 )
417 {
418 var->blue.offset = 0;
419 var->green.offset = var->blue.length;
420 var->red.offset = var->green.offset + var->green.length;
421 var->transp.offset = var->red.offset + var->red.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 var->height = var->width = -1;
424
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700425 if (var->xres != var->xres_virtual) {
426 DPRINTK("virtual x resolution != physical x resolution not supported\n");
427 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700430 if (var->yres > var->yres_virtual) {
431 DPRINTK("virtual y resolution < physical y resolution not possible\n");
432 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 }
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700434
435 if (var->xoffset) {
436 DPRINTK("xoffset not supported\n");
437 return -EINVAL;
438 }
439
440 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
441 DPRINTK("interlace not supported\n");
442 return -EINVAL;
443 }
444
445 var->xres = (var->xres + 31) & ~31; /* could sometimes be 8 */
446 lpitch = var->xres * ((var->bits_per_pixel + 7)>>3);
447
448 if (var->xres < 200 || var->xres > 2048) {
449 DPRINTK("width not supported: %u\n", var->xres);
450 return -EINVAL;
451 }
452
453 if (var->yres < 200 || var->yres > 4095) {
454 DPRINTK("height not supported: %u\n", var->yres);
455 return -EINVAL;
456 }
457
458 if (lpitch * var->yres_virtual > info->fix.smem_len) {
459 DPRINTK("no memory for screen (%ux%ux%u)\n",
460 var->xres, var->yres_virtual, var->bits_per_pixel);
461 return -EINVAL;
462 }
463
464 if (PICOS2KHZ(var->pixclock) > PM3_MAX_PIXCLOCK) {
465 DPRINTK("pixclock too high (%ldKHz)\n", PICOS2KHZ(var->pixclock));
466 return -EINVAL;
467 }
468
469 var->accel_flags = 0; /* Can't mmap if this is on */
470
471 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
472 var->xres, var->yres, var->bits_per_pixel);
473 return 0;
474}
475
476static int pm3fb_set_par(struct fb_info *info)
477{
478 struct pm3_par *par = info->par;
479 const u32 xres = (info->var.xres + 31) & ~31;
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700480 const unsigned bpp = info->var.bits_per_pixel;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700481
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700482 par->base = pm3fb_shift_bpp(bpp,(info->var.yoffset * xres)
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700483 + info->var.xoffset);
484 par->video = 0;
485
486 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
487 par->video |= PM3VideoControl_HSYNC_ACTIVE_HIGH;
488 else
489 par->video |= PM3VideoControl_HSYNC_ACTIVE_LOW;
490
491 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
492 par->video |= PM3VideoControl_VSYNC_ACTIVE_HIGH;
493 else
494 par->video |= PM3VideoControl_VSYNC_ACTIVE_LOW;
495
496 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
497 par->video |= PM3VideoControl_LINE_DOUBLE_ON;
498 else
499 par->video |= PM3VideoControl_LINE_DOUBLE_OFF;
500
501 if (info->var.activate == FB_ACTIVATE_NOW)
502 par->video |= PM3VideoControl_ENABLE;
503 else {
504 par->video |= PM3VideoControl_DISABLE;
505 DPRINTK("PM3Video disabled\n");
506 }
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700507 switch (bpp) {
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700508 case 8:
509 par->video |= PM3VideoControl_PIXELSIZE_8BIT;
510 break;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700511 case 16:
512 par->video |= PM3VideoControl_PIXELSIZE_16BIT;
513 break;
514 case 32:
515 par->video |= PM3VideoControl_PIXELSIZE_32BIT;
516 break;
517 default:
518 DPRINTK("Unsupported depth\n");
519 break;
520 }
521
522 info->fix.visual =
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700523 (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700524 info->fix.line_length = ((info->var.xres_virtual + 7) & ~7)
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700525 * bpp / 8;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700526
527/* pm3fb_clear_memory(info, 0);*/
528 pm3fb_clear_colormap(par, 0, 0, 0);
529 PM3_WRITE_DAC_REG(par, PM3RD_CursorMode,
530 PM3RD_CursorMode_CURSOR_DISABLE);
531 pm3fb_write_mode(info);
532 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533}
534
535static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green,
536 unsigned blue, unsigned transp,
537 struct fb_info *info)
538{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700539 struct pm3_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700541 if (regno >= 256) /* no. of hw registers */
542 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700544 /* grayscale works only partially under directcolor */
545 if (info->var.grayscale) {
546 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
547 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
548 }
549
550 /* Directcolor:
551 * var->{color}.offset contains start of bitfield
552 * var->{color}.length contains length of bitfield
553 * {hardwarespecific} contains width of DAC
554 * pseudo_palette[X] is programmed to (X << red.offset) |
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700555 * (X << green.offset) |
556 * (X << blue.offset)
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700557 * RAMDAC[X] is programmed to (red, green, blue)
558 * color depth = SUM(var->{color}.length)
559 *
560 * Pseudocolor:
561 * var->{color}.offset is 0
562 * var->{color}.length contains width of DAC or the number of unique
563 * colors available (color depth)
564 * pseudo_palette is not used
565 * RAMDAC[X] is programmed to (red, green, blue)
566 * color depth = var->{color}.length
567 */
568
569 /*
570 * This is the point where the color is converted to something that
571 * is acceptable by the hardware.
572 */
573#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
574 red = CNVT_TOHW(red, info->var.red.length);
575 green = CNVT_TOHW(green, info->var.green.length);
576 blue = CNVT_TOHW(blue, info->var.blue.length);
577 transp = CNVT_TOHW(transp, info->var.transp.length);
578#undef CNVT_TOHW
579
580 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
581 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
582 u32 v;
583
584 if (regno >= 16)
585 return -EINVAL;
586
587 v = (red << info->var.red.offset) |
588 (green << info->var.green.offset) |
589 (blue << info->var.blue.offset) |
590 (transp << info->var.transp.offset);
591
592 switch (info->var.bits_per_pixel) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 case 8:
594 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 case 16:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 case 32:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700597 ((u32*)(info->pseudo_palette))[regno] = v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 break;
599 }
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700600 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700602 else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
603 pm3fb_set_color(par, regno, red, green, blue);
604
605 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606}
607
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700608static int pm3fb_pan_display(struct fb_var_screeninfo *var,
609 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700611 struct pm3_par *par = info->par;
612 const u32 xres = (var->xres + 31) & ~31;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700614 par->base = pm3fb_shift_bpp(var->bits_per_pixel,
615 (var->yoffset * xres)
616 + var->xoffset);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700617 PM3_WAIT(par, 1);
618 PM3_WRITE_REG(par, PM3ScreenBase, par->base);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700619 return 0;
620}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700622static int pm3fb_blank(int blank_mode, struct fb_info *info)
623{
624 struct pm3_par *par = info->par;
625 u32 video = par->video;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 /*
628 * Oxygen VX1 - it appears that setting PM3VideoControl and
629 * then PM3RD_SyncControl to the same SYNC settings undoes
630 * any net change - they seem to xor together. Only set the
631 * sync options in PM3RD_SyncControl. --rmk
632 */
633 video &= ~(PM3VideoControl_HSYNC_MASK |
634 PM3VideoControl_VSYNC_MASK);
635 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
636 PM3VideoControl_VSYNC_ACTIVE_HIGH;
637
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700638 switch (blank_mode) {
639 case FB_BLANK_UNBLANK:
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700640 video |= PM3VideoControl_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 break;
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700642 case FB_BLANK_NORMAL:
643 video &= ~(PM3VideoControl_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 break;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700645 case FB_BLANK_HSYNC_SUSPEND:
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700646 video &= ~(PM3VideoControl_HSYNC_MASK |
647 PM3VideoControl_BLANK_ACTIVE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 break;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700649 case FB_BLANK_VSYNC_SUSPEND:
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700650 video &= ~(PM3VideoControl_VSYNC_MASK |
651 PM3VideoControl_BLANK_ACTIVE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 break;
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700653 case FB_BLANK_POWERDOWN:
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700654 video &= ~(PM3VideoControl_HSYNC_MASK |
655 PM3VideoControl_VSYNC_MASK |
656 PM3VideoControl_BLANK_ACTIVE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 default:
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700659 DPRINTK("Unsupported blanking %d\n", blank_mode);
660 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 }
662
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700663 PM3_WAIT(par, 1);
664 PM3_WRITE_REG(par,PM3VideoControl, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 return 0;
666}
667
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700668 /*
669 * Frame buffer operations
670 */
671
672static struct fb_ops pm3fb_ops = {
673 .owner = THIS_MODULE,
674 .fb_check_var = pm3fb_check_var,
675 .fb_set_par = pm3fb_set_par,
676 .fb_setcolreg = pm3fb_setcolreg,
677 .fb_pan_display = pm3fb_pan_display,
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700678 .fb_fillrect = cfb_fillrect,
679 .fb_copyarea = cfb_copyarea,
680 .fb_imageblit = cfb_imageblit,
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700681 .fb_blank = pm3fb_blank,
682};
683
684/* ------------------------------------------------------------------------- */
685
686 /*
687 * Initialization
688 */
689
690/* mmio register are already mapped when this function is called */
691/* the pm3fb_fix.smem_start is also set */
692static unsigned long pm3fb_size_memory(struct pm3_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700694 unsigned long memsize = 0, tempBypass, i, temp1, temp2;
695 unsigned char __iomem *screen_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700697 pm3fb_fix.smem_len = 64 * 1024l * 1024; /* request full aperture size */
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700698 /* Linear frame buffer - request region and map it. */
699 if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
700 "pm3fb smem")) {
701 printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
702 return 0;
703 }
704 screen_mem =
705 ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
706 if (!screen_mem) {
707 printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
708 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
709 return 0;
710 }
711
712 /* TODO: card-specific stuff, *before* accessing *any* FB memory */
713 /* For Appian Jeronimo 2000 board second head */
714
715 tempBypass = PM3_READ_REG(par, PM3MemBypassWriteMask);
716
717 DPRINTK("PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass);
718
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700719 PM3_WAIT(par, 1);
720 PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xFFFFFFFF);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700721
722 /* pm3 split up memory, replicates, and do a lot of nasty stuff IMHO ;-) */
723 for (i = 0; i < 32; i++) {
724 fb_writel(i * 0x00345678,
725 (screen_mem + (i * 1048576)));
726 mb();
727 temp1 = fb_readl((screen_mem + (i * 1048576)));
728
729 /* Let's check for wrapover, write will fail at 16MB boundary */
730 if (temp1 == (i * 0x00345678))
731 memsize = i;
732 else
733 break;
734 }
735
736 DPRINTK("First detect pass already got %ld MB\n", memsize + 1);
737
738 if (memsize + 1 == i) {
739 for (i = 0; i < 32; i++) {
740 /* Clear first 32MB ; 0 is 0, no need to byteswap */
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700741 writel(0x0000000, (screen_mem + (i * 1048576)));
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700742 }
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700743 wmb();
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700744
745 for (i = 32; i < 64; i++) {
746 fb_writel(i * 0x00345678,
747 (screen_mem + (i * 1048576)));
748 mb();
749 temp1 =
750 fb_readl((screen_mem + (i * 1048576)));
751 temp2 =
752 fb_readl((screen_mem + ((i - 32) * 1048576)));
753 /* different value, different RAM... */
754 if ((temp1 == (i * 0x00345678)) && (temp2 == 0))
755 memsize = i;
756 else
757 break;
758 }
759 }
760 DPRINTK("Second detect pass got %ld MB\n", memsize + 1);
761
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700762 PM3_WAIT(par, 1);
763 PM3_WRITE_REG(par, PM3MemBypassWriteMask, tempBypass);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700764
765 iounmap(screen_mem);
766 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
767 memsize = 1048576 * (memsize + 1);
768
769 DPRINTK("Returning 0x%08lx bytes\n", memsize);
770
771 return memsize;
772}
773
774static int __devinit pm3fb_probe(struct pci_dev *dev,
775 const struct pci_device_id *ent)
776{
777 struct fb_info *info;
778 struct pm3_par *par;
779 struct device* device = &dev->dev; /* for pci drivers */
780 int err, retval = -ENXIO;
781
782 err = pci_enable_device(dev);
783 if (err) {
784 printk(KERN_WARNING "pm3fb: Can't enable PCI dev: %d\n", err);
785 return err;
786 }
787 /*
788 * Dynamically allocate info and par
789 */
790 info = framebuffer_alloc(sizeof(struct pm3_par), device);
791
792 if (!info)
793 return -ENOMEM;
794 par = info->par;
795
796 /*
797 * Here we set the screen_base to the virtual memory address
798 * for the framebuffer.
799 */
800 pm3fb_fix.mmio_start = pci_resource_start(dev, 0);
801 pm3fb_fix.mmio_len = PM3_REGS_SIZE;
802
803 /* Registers - request region and map it. */
804 if (!request_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len,
805 "pm3fb regbase")) {
806 printk(KERN_WARNING "pm3fb: Can't reserve regbase.\n");
807 goto err_exit_neither;
808 }
809 par->v_regs =
810 ioremap_nocache(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
811 if (!par->v_regs) {
812 printk(KERN_WARNING "pm3fb: Can't remap %s register area.\n",
813 pm3fb_fix.id);
814 release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
815 goto err_exit_neither;
816 }
817
818#if defined(__BIG_ENDIAN)
819 pm3fb_fix.mmio_start += PM3_REGS_SIZE;
820 DPRINTK("Adjusting register base for big-endian.\n");
821#endif
822 /* Linear frame buffer - request region and map it. */
823 pm3fb_fix.smem_start = pci_resource_start(dev, 1);
824 pm3fb_fix.smem_len = pm3fb_size_memory(par);
825 if (!pm3fb_fix.smem_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 {
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700827 printk(KERN_WARNING "pm3fb: Can't find memory on board.\n");
828 goto err_exit_mmio;
829 }
830 if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
831 "pm3fb smem")) {
832 printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
833 goto err_exit_mmio;
834 }
835 info->screen_base =
836 ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
837 if (!info->screen_base) {
838 printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
839 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
840 goto err_exit_mmio;
841 }
842 info->screen_size = pm3fb_fix.smem_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700844 info->fbops = &pm3fb_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700846 par->video = PM3_READ_REG(par, PM3VideoControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700848 info->fix = pm3fb_fix;
849 info->pseudo_palette = par->palette;
850 info->flags = FBINFO_DEFAULT;/* | FBINFO_HWACCEL_YPAN;*/
851
852 /*
853 * This should give a reasonable default video mode. The following is
854 * done when we can set a video mode.
855 */
856 if (!mode_option)
857 mode_option = "640x480@60";
858
859 retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
860
861 if (!retval || retval == 4) {
862 retval = -EINVAL;
863 goto err_exit_both;
864 }
865
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700866 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
867 retval = -ENOMEM;
868 goto err_exit_both;
869 }
870
871 /*
872 * For drivers that can...
873 */
874 pm3fb_check_var(&info->var, info);
875
876 if (register_framebuffer(info) < 0) {
877 retval = -EINVAL;
878 goto err_exit_all;
879 }
880 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
881 info->fix.id);
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700882 pci_set_drvdata(dev, info);
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700883 return 0;
884
885 err_exit_all:
886 fb_dealloc_cmap(&info->cmap);
887 err_exit_both:
888 iounmap(info->screen_base);
889 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
890 err_exit_mmio:
891 iounmap(par->v_regs);
892 release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
893 err_exit_neither:
894 framebuffer_release(info);
895 return retval;
896}
897
898 /*
899 * Cleanup
900 */
901static void __devexit pm3fb_remove(struct pci_dev *dev)
902{
903 struct fb_info *info = pci_get_drvdata(dev);
904
905 if (info) {
906 struct fb_fix_screeninfo *fix = &info->fix;
907 struct pm3_par *par = info->par;
908
909 unregister_framebuffer(info);
910 fb_dealloc_cmap(&info->cmap);
911
912 iounmap(info->screen_base);
913 release_mem_region(fix->smem_start, fix->smem_len);
914 iounmap(par->v_regs);
915 release_mem_region(fix->mmio_start, fix->mmio_len);
916
917 pci_set_drvdata(dev, NULL);
918 framebuffer_release(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
920}
921
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700922static struct pci_device_id pm3fb_id_table[] = {
923 { PCI_VENDOR_ID_3DLABS, 0x0a,
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700924 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700925 { 0, }
926};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700928/* For PCI drivers */
929static struct pci_driver pm3fb_driver = {
930 .name = "pm3fb",
931 .id_table = pm3fb_id_table,
932 .probe = pm3fb_probe,
933 .remove = __devexit_p(pm3fb_remove),
934};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700936MODULE_DEVICE_TABLE(pci, pm3fb_id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Krzysztof Helt2686ba82007-05-23 13:57:48 -0700938#ifndef MODULE
939 /*
940 * Setup
941 */
942
943/*
944 * Only necessary if your driver takes special options,
945 * otherwise we fall back on the generic fb_setup().
946 */
947static int __init pm3fb_setup(char *options)
948{
949 /* Parse user speficied options (`video=pm3fb:') */
950 return 0;
951}
952#endif /* MODULE */
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954int __init pm3fb_init(void)
955{
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700956 /*
957 * For kernel boot options (in 'video=pm3fb:<options>' format)
958 */
959#ifndef MODULE
960 char *option = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700962 if (fb_get_options("pm3fb", &option))
963 return -ENODEV;
964 pm3fb_setup(option);
965#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700967 return pci_register_driver(&pm3fb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968}
969
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700970static void __exit pm3fb_exit(void)
971{
972 pci_unregister_driver(&pm3fb_driver);
973}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Krzysztof Heltf23a06f2007-05-10 22:23:25 -0700975module_init(pm3fb_init);
976module_exit(pm3fb_exit);
977
978MODULE_LICENSE("GPL");