Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Permedia2 framebuffer driver. | |
3 | * | |
4 | * 2.5/2.6 driver: | |
5 | * Copyright (c) 2003 Jim Hague (jim.hague@acm.org) | |
6 | * | |
7 | * based on 2.4 driver: | |
8 | * Copyright (c) 1998-2000 Ilario Nardinocchi (nardinoc@CS.UniBO.IT) | |
9 | * Copyright (c) 1999 Jakub Jelinek (jakub@redhat.com) | |
10 | * | |
11 | * and additional input from James Simmon's port of Hannu Mallat's tdfx | |
12 | * driver. | |
13 | * | |
45f169ec | 14 | * I have a Creative Graphics Blaster Exxtreme card - pm2fb on x86. I |
1da177e4 LT |
15 | * have no access to other pm2fb implementations. Sparc (and thus |
16 | * hopefully other big-endian) devices now work, thanks to a lot of | |
17 | * testing work by Ron Murray. I have no access to CVision hardware, | |
18 | * and therefore for now I am omitting the CVision code. | |
19 | * | |
20 | * Multiple boards support has been on the TODO list for ages. | |
21 | * Don't expect this to change. | |
22 | * | |
23 | * This file is subject to the terms and conditions of the GNU General Public | |
24 | * License. See the file COPYING in the main directory of this archive for | |
25 | * more details. | |
26 | * | |
2f7bb99f | 27 | * |
1da177e4 LT |
28 | */ |
29 | ||
1da177e4 LT |
30 | #include <linux/module.h> |
31 | #include <linux/moduleparam.h> | |
32 | #include <linux/kernel.h> | |
33 | #include <linux/errno.h> | |
34 | #include <linux/string.h> | |
35 | #include <linux/mm.h> | |
1da177e4 LT |
36 | #include <linux/slab.h> |
37 | #include <linux/delay.h> | |
38 | #include <linux/fb.h> | |
39 | #include <linux/init.h> | |
40 | #include <linux/pci.h> | |
d5383fcc KH |
41 | #ifdef CONFIG_MTRR |
42 | #include <asm/mtrr.h> | |
43 | #endif | |
1da177e4 LT |
44 | |
45 | #include <video/permedia2.h> | |
46 | #include <video/cvisionppc.h> | |
47 | ||
48 | #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN) | |
49 | #error "The endianness of the target host has not been defined." | |
50 | #endif | |
51 | ||
52 | #if !defined(CONFIG_PCI) | |
53 | #error "Only generic PCI cards supported." | |
54 | #endif | |
55 | ||
56 | #undef PM2FB_MASTER_DEBUG | |
57 | #ifdef PM2FB_MASTER_DEBUG | |
3843faa2 KH |
58 | #define DPRINTK(a, b...) \ |
59 | printk(KERN_DEBUG "pm2fb: %s: " a, __FUNCTION__ , ## b) | |
1da177e4 | 60 | #else |
3843faa2 | 61 | #define DPRINTK(a, b...) |
1da177e4 LT |
62 | #endif |
63 | ||
91b3a6f4 KH |
64 | #define PM2_PIXMAP_SIZE (1600 * 4) |
65 | ||
1da177e4 | 66 | /* |
2f7bb99f | 67 | * Driver data |
1da177e4 | 68 | */ |
8f5d050a | 69 | static int hwcursor; |
3843faa2 | 70 | static char *mode __devinitdata; |
1da177e4 LT |
71 | |
72 | /* | |
73 | * The XFree GLINT driver will (I think to implement hardware cursor | |
74 | * support on TVP4010 and similar where there is no RAMDAC - see | |
75 | * comment in set_video) always request +ve sync regardless of what | |
76 | * the mode requires. This screws me because I have a Sun | |
77 | * fixed-frequency monitor which absolutely has to have -ve sync. So | |
78 | * these flags allow the user to specify that requests for +ve sync | |
79 | * should be silently turned in -ve sync. | |
80 | */ | |
c16c556e DJ |
81 | static int lowhsync; |
82 | static int lowvsync; | |
d5383fcc KH |
83 | static int noaccel __devinitdata; |
84 | /* mtrr option */ | |
85 | #ifdef CONFIG_MTRR | |
86 | static int nomtrr __devinitdata; | |
87 | #endif | |
1da177e4 LT |
88 | |
89 | /* | |
90 | * The hardware state of the graphics card that isn't part of the | |
91 | * screeninfo. | |
92 | */ | |
93 | struct pm2fb_par | |
94 | { | |
95 | pm2type_t type; /* Board type */ | |
1da177e4 | 96 | unsigned char __iomem *v_regs;/* virtual address of p_regs */ |
2f7bb99f | 97 | u32 memclock; /* memclock */ |
1da177e4 LT |
98 | u32 video; /* video flags before blanking */ |
99 | u32 mem_config; /* MemConfig reg at probe */ | |
100 | u32 mem_control; /* MemControl reg at probe */ | |
101 | u32 boot_address; /* BootAddress reg at probe */ | |
2f7bb99f | 102 | u32 palette[16]; |
d5383fcc | 103 | int mtrr_handle; |
1da177e4 LT |
104 | }; |
105 | ||
106 | /* | |
107 | * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo | |
108 | * if we don't use modedb. | |
109 | */ | |
110 | static struct fb_fix_screeninfo pm2fb_fix __devinitdata = { | |
2f7bb99f | 111 | .id = "", |
1da177e4 LT |
112 | .type = FB_TYPE_PACKED_PIXELS, |
113 | .visual = FB_VISUAL_PSEUDOCOLOR, | |
114 | .xpanstep = 1, | |
115 | .ypanstep = 1, | |
2f7bb99f | 116 | .ywrapstep = 0, |
87a7cc68 | 117 | .accel = FB_ACCEL_3DLABS_PERMEDIA2, |
1da177e4 LT |
118 | }; |
119 | ||
120 | /* | |
121 | * Default video mode. In case the modedb doesn't work. | |
122 | */ | |
123 | static struct fb_var_screeninfo pm2fb_var __devinitdata = { | |
124 | /* "640x480, 8 bpp @ 60 Hz */ | |
2f7bb99f KH |
125 | .xres = 640, |
126 | .yres = 480, | |
127 | .xres_virtual = 640, | |
128 | .yres_virtual = 480, | |
129 | .bits_per_pixel = 8, | |
130 | .red = {0, 8, 0}, | |
131 | .blue = {0, 8, 0}, | |
132 | .green = {0, 8, 0}, | |
133 | .activate = FB_ACTIVATE_NOW, | |
134 | .height = -1, | |
135 | .width = -1, | |
136 | .accel_flags = 0, | |
137 | .pixclock = 39721, | |
138 | .left_margin = 40, | |
139 | .right_margin = 24, | |
140 | .upper_margin = 32, | |
141 | .lower_margin = 11, | |
142 | .hsync_len = 96, | |
143 | .vsync_len = 2, | |
144 | .vmode = FB_VMODE_NONINTERLACED | |
1da177e4 LT |
145 | }; |
146 | ||
147 | /* | |
148 | * Utility functions | |
149 | */ | |
150 | ||
3843faa2 | 151 | static inline u32 pm2_RD(struct pm2fb_par *p, s32 off) |
1da177e4 | 152 | { |
45f169ec | 153 | return fb_readl(p->v_regs + off); |
1da177e4 LT |
154 | } |
155 | ||
3843faa2 | 156 | static inline void pm2_WR(struct pm2fb_par *p, s32 off, u32 v) |
1da177e4 | 157 | { |
45f169ec | 158 | fb_writel(v, p->v_regs + off); |
1da177e4 LT |
159 | } |
160 | ||
3843faa2 | 161 | static inline u32 pm2_RDAC_RD(struct pm2fb_par *p, s32 idx) |
1da177e4 | 162 | { |
45f169ec | 163 | pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx); |
1da177e4 | 164 | mb(); |
45f169ec KH |
165 | return pm2_RD(p, PM2R_RD_INDEXED_DATA); |
166 | } | |
167 | ||
3843faa2 | 168 | static inline u32 pm2v_RDAC_RD(struct pm2fb_par *p, s32 idx) |
45f169ec KH |
169 | { |
170 | pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff); | |
171 | mb(); | |
172 | return pm2_RD(p, PM2VR_RD_INDEXED_DATA); | |
1da177e4 LT |
173 | } |
174 | ||
3843faa2 | 175 | static inline void pm2_RDAC_WR(struct pm2fb_par *p, s32 idx, u32 v) |
1da177e4 | 176 | { |
45f169ec | 177 | pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx); |
11d1a62c | 178 | wmb(); |
45f169ec | 179 | pm2_WR(p, PM2R_RD_INDEXED_DATA, v); |
11d1a62c | 180 | wmb(); |
1da177e4 LT |
181 | } |
182 | ||
3843faa2 | 183 | static inline void pm2v_RDAC_WR(struct pm2fb_par *p, s32 idx, u32 v) |
1da177e4 LT |
184 | { |
185 | pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff); | |
11d1a62c | 186 | wmb(); |
1da177e4 | 187 | pm2_WR(p, PM2VR_RD_INDEXED_DATA, v); |
11d1a62c | 188 | wmb(); |
1da177e4 LT |
189 | } |
190 | ||
191 | #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT | |
2f7bb99f | 192 | #define WAIT_FIFO(p, a) |
1da177e4 | 193 | #else |
3843faa2 | 194 | static inline void WAIT_FIFO(struct pm2fb_par *p, u32 a) |
1da177e4 | 195 | { |
3843faa2 | 196 | while (pm2_RD(p, PM2R_IN_FIFO_SPACE) < a); |
1da177e4 LT |
197 | mb(); |
198 | } | |
199 | #endif | |
200 | ||
201 | /* | |
202 | * partial products for the supported horizontal resolutions. | |
203 | */ | |
2f7bb99f | 204 | #define PACKPP(p0, p1, p2) (((p2) << 6) | ((p1) << 3) | (p0)) |
1da177e4 LT |
205 | static const struct { |
206 | u16 width; | |
207 | u16 pp; | |
208 | } pp_table[] = { | |
209 | { 32, PACKPP(1, 0, 0) }, { 64, PACKPP(1, 1, 0) }, | |
210 | { 96, PACKPP(1, 1, 1) }, { 128, PACKPP(2, 1, 1) }, | |
211 | { 160, PACKPP(2, 2, 1) }, { 192, PACKPP(2, 2, 2) }, | |
212 | { 224, PACKPP(3, 2, 1) }, { 256, PACKPP(3, 2, 2) }, | |
213 | { 288, PACKPP(3, 3, 1) }, { 320, PACKPP(3, 3, 2) }, | |
214 | { 384, PACKPP(3, 3, 3) }, { 416, PACKPP(4, 3, 1) }, | |
215 | { 448, PACKPP(4, 3, 2) }, { 512, PACKPP(4, 3, 3) }, | |
216 | { 544, PACKPP(4, 4, 1) }, { 576, PACKPP(4, 4, 2) }, | |
217 | { 640, PACKPP(4, 4, 3) }, { 768, PACKPP(4, 4, 4) }, | |
218 | { 800, PACKPP(5, 4, 1) }, { 832, PACKPP(5, 4, 2) }, | |
219 | { 896, PACKPP(5, 4, 3) }, { 1024, PACKPP(5, 4, 4) }, | |
220 | { 1056, PACKPP(5, 5, 1) }, { 1088, PACKPP(5, 5, 2) }, | |
221 | { 1152, PACKPP(5, 5, 3) }, { 1280, PACKPP(5, 5, 4) }, | |
222 | { 1536, PACKPP(5, 5, 5) }, { 1568, PACKPP(6, 5, 1) }, | |
223 | { 1600, PACKPP(6, 5, 2) }, { 1664, PACKPP(6, 5, 3) }, | |
224 | { 1792, PACKPP(6, 5, 4) }, { 2048, PACKPP(6, 5, 5) }, | |
225 | { 0, 0 } }; | |
226 | ||
227 | static u32 partprod(u32 xres) | |
228 | { | |
229 | int i; | |
230 | ||
231 | for (i = 0; pp_table[i].width && pp_table[i].width != xres; i++) | |
232 | ; | |
45f169ec | 233 | if (pp_table[i].width == 0) |
1da177e4 LT |
234 | DPRINTK("invalid width %u\n", xres); |
235 | return pp_table[i].pp; | |
236 | } | |
237 | ||
238 | static u32 to3264(u32 timing, int bpp, int is64) | |
239 | { | |
240 | switch (bpp) { | |
45f169ec KH |
241 | case 24: |
242 | timing *= 3; | |
1da177e4 | 243 | case 8: |
45f169ec | 244 | timing >>= 1; |
1da177e4 | 245 | case 16: |
45f169ec | 246 | timing >>= 1; |
1da177e4 | 247 | case 32: |
1da177e4 LT |
248 | break; |
249 | } | |
45f169ec KH |
250 | if (is64) |
251 | timing >>= 1; | |
1da177e4 LT |
252 | return timing; |
253 | } | |
254 | ||
3843faa2 KH |
255 | static void pm2_mnp(u32 clk, unsigned char *mm, unsigned char *nn, |
256 | unsigned char *pp) | |
1da177e4 LT |
257 | { |
258 | unsigned char m; | |
259 | unsigned char n; | |
260 | unsigned char p; | |
261 | u32 f; | |
262 | s32 curr; | |
263 | s32 delta = 100000; | |
264 | ||
265 | *mm = *nn = *pp = 0; | |
266 | for (n = 2; n < 15; n++) { | |
267 | for (m = 2; m; m++) { | |
268 | f = PM2_REFERENCE_CLOCK * m / n; | |
269 | if (f >= 150000 && f <= 300000) { | |
45f169ec KH |
270 | for (p = 0; p < 5; p++, f >>= 1) { |
271 | curr = (clk > f) ? clk - f : f - clk; | |
272 | if (curr < delta) { | |
273 | delta = curr; | |
274 | *mm = m; | |
275 | *nn = n; | |
276 | *pp = p; | |
1da177e4 LT |
277 | } |
278 | } | |
279 | } | |
280 | } | |
281 | } | |
282 | } | |
283 | ||
3843faa2 KH |
284 | static void pm2v_mnp(u32 clk, unsigned char *mm, unsigned char *nn, |
285 | unsigned char *pp) | |
1da177e4 LT |
286 | { |
287 | unsigned char m; | |
288 | unsigned char n; | |
289 | unsigned char p; | |
290 | u32 f; | |
291 | s32 delta = 1000; | |
292 | ||
293 | *mm = *nn = *pp = 0; | |
45f169ec | 294 | for (m = 1; m < 128; m++) { |
d4a96b53 | 295 | for (n = 2 * m + 1; n; n++) { |
45f169ec KH |
296 | for (p = 0; p < 2; p++) { |
297 | f = (PM2_REFERENCE_CLOCK >> (p + 1)) * n / m; | |
298 | if (clk > f - delta && clk < f + delta) { | |
299 | delta = (clk > f) ? clk - f : f - clk; | |
300 | *mm = m; | |
301 | *nn = n; | |
302 | *pp = p; | |
1da177e4 LT |
303 | } |
304 | } | |
305 | } | |
306 | } | |
307 | } | |
308 | ||
3843faa2 KH |
309 | static void clear_palette(struct pm2fb_par *p) |
310 | { | |
45f169ec | 311 | int i = 256; |
1da177e4 LT |
312 | |
313 | WAIT_FIFO(p, 1); | |
314 | pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, 0); | |
315 | wmb(); | |
316 | while (i--) { | |
317 | WAIT_FIFO(p, 3); | |
318 | pm2_WR(p, PM2R_RD_PALETTE_DATA, 0); | |
319 | pm2_WR(p, PM2R_RD_PALETTE_DATA, 0); | |
320 | pm2_WR(p, PM2R_RD_PALETTE_DATA, 0); | |
321 | } | |
322 | } | |
323 | ||
3843faa2 | 324 | static void reset_card(struct pm2fb_par *p) |
1da177e4 LT |
325 | { |
326 | if (p->type == PM2_TYPE_PERMEDIA2V) | |
327 | pm2_WR(p, PM2VR_RD_INDEX_HIGH, 0); | |
328 | pm2_WR(p, PM2R_RESET_STATUS, 0); | |
329 | mb(); | |
330 | while (pm2_RD(p, PM2R_RESET_STATUS) & PM2F_BEING_RESET) | |
331 | ; | |
332 | mb(); | |
333 | #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT | |
334 | DPRINTK("FIFO disconnect enabled\n"); | |
335 | pm2_WR(p, PM2R_FIFO_DISCON, 1); | |
336 | mb(); | |
337 | #endif | |
338 | ||
339 | /* Restore stashed memory config information from probe */ | |
340 | WAIT_FIFO(p, 3); | |
341 | pm2_WR(p, PM2R_MEM_CONTROL, p->mem_control); | |
342 | pm2_WR(p, PM2R_BOOT_ADDRESS, p->boot_address); | |
343 | wmb(); | |
344 | pm2_WR(p, PM2R_MEM_CONFIG, p->mem_config); | |
345 | } | |
346 | ||
3843faa2 | 347 | static void reset_config(struct pm2fb_par *p) |
1da177e4 | 348 | { |
138a451c | 349 | WAIT_FIFO(p, 53); |
2f7bb99f | 350 | pm2_WR(p, PM2R_CHIP_CONFIG, pm2_RD(p, PM2R_CHIP_CONFIG) & |
45f169ec | 351 | ~(PM2F_VGA_ENABLE | PM2F_VGA_FIXED)); |
1da177e4 LT |
352 | pm2_WR(p, PM2R_BYPASS_WRITE_MASK, ~(0L)); |
353 | pm2_WR(p, PM2R_FRAMEBUFFER_WRITE_MASK, ~(0L)); | |
354 | pm2_WR(p, PM2R_FIFO_CONTROL, 0); | |
355 | pm2_WR(p, PM2R_APERTURE_ONE, 0); | |
356 | pm2_WR(p, PM2R_APERTURE_TWO, 0); | |
357 | pm2_WR(p, PM2R_RASTERIZER_MODE, 0); | |
358 | pm2_WR(p, PM2R_DELTA_MODE, PM2F_DELTA_ORDER_RGB); | |
359 | pm2_WR(p, PM2R_LB_READ_FORMAT, 0); | |
2f7bb99f | 360 | pm2_WR(p, PM2R_LB_WRITE_FORMAT, 0); |
1da177e4 LT |
361 | pm2_WR(p, PM2R_LB_READ_MODE, 0); |
362 | pm2_WR(p, PM2R_LB_SOURCE_OFFSET, 0); | |
363 | pm2_WR(p, PM2R_FB_SOURCE_OFFSET, 0); | |
364 | pm2_WR(p, PM2R_FB_PIXEL_OFFSET, 0); | |
365 | pm2_WR(p, PM2R_FB_WINDOW_BASE, 0); | |
366 | pm2_WR(p, PM2R_LB_WINDOW_BASE, 0); | |
367 | pm2_WR(p, PM2R_FB_SOFT_WRITE_MASK, ~(0L)); | |
368 | pm2_WR(p, PM2R_FB_HARD_WRITE_MASK, ~(0L)); | |
369 | pm2_WR(p, PM2R_FB_READ_PIXEL, 0); | |
370 | pm2_WR(p, PM2R_DITHER_MODE, 0); | |
371 | pm2_WR(p, PM2R_AREA_STIPPLE_MODE, 0); | |
372 | pm2_WR(p, PM2R_DEPTH_MODE, 0); | |
373 | pm2_WR(p, PM2R_STENCIL_MODE, 0); | |
374 | pm2_WR(p, PM2R_TEXTURE_ADDRESS_MODE, 0); | |
375 | pm2_WR(p, PM2R_TEXTURE_READ_MODE, 0); | |
376 | pm2_WR(p, PM2R_TEXEL_LUT_MODE, 0); | |
377 | pm2_WR(p, PM2R_YUV_MODE, 0); | |
378 | pm2_WR(p, PM2R_COLOR_DDA_MODE, 0); | |
379 | pm2_WR(p, PM2R_TEXTURE_COLOR_MODE, 0); | |
380 | pm2_WR(p, PM2R_FOG_MODE, 0); | |
381 | pm2_WR(p, PM2R_ALPHA_BLEND_MODE, 0); | |
382 | pm2_WR(p, PM2R_LOGICAL_OP_MODE, 0); | |
383 | pm2_WR(p, PM2R_STATISTICS_MODE, 0); | |
384 | pm2_WR(p, PM2R_SCISSOR_MODE, 0); | |
385 | pm2_WR(p, PM2R_FILTER_MODE, PM2F_SYNCHRONIZATION); | |
138a451c | 386 | pm2_WR(p, PM2R_RD_PIXEL_MASK, 0xff); |
1da177e4 LT |
387 | switch (p->type) { |
388 | case PM2_TYPE_PERMEDIA2: | |
389 | pm2_RDAC_WR(p, PM2I_RD_MODE_CONTROL, 0); /* no overlay */ | |
390 | pm2_RDAC_WR(p, PM2I_RD_CURSOR_CONTROL, 0); | |
391 | pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, PM2F_RD_PALETTE_WIDTH_8); | |
45f169ec KH |
392 | pm2_RDAC_WR(p, PM2I_RD_COLOR_KEY_CONTROL, 0); |
393 | pm2_RDAC_WR(p, PM2I_RD_OVERLAY_KEY, 0); | |
394 | pm2_RDAC_WR(p, PM2I_RD_RED_KEY, 0); | |
395 | pm2_RDAC_WR(p, PM2I_RD_GREEN_KEY, 0); | |
396 | pm2_RDAC_WR(p, PM2I_RD_BLUE_KEY, 0); | |
1da177e4 LT |
397 | break; |
398 | case PM2_TYPE_PERMEDIA2V: | |
399 | pm2v_RDAC_WR(p, PM2VI_RD_MISC_CONTROL, 1); /* 8bit */ | |
400 | break; | |
401 | } | |
1da177e4 LT |
402 | } |
403 | ||
3843faa2 | 404 | static void set_aperture(struct pm2fb_par *p, u32 depth) |
1da177e4 LT |
405 | { |
406 | /* | |
407 | * The hardware is little-endian. When used in big-endian | |
408 | * hosts, the on-chip aperture settings are used where | |
409 | * possible to translate from host to card byte order. | |
410 | */ | |
45f169ec | 411 | WAIT_FIFO(p, 2); |
1da177e4 LT |
412 | #ifdef __LITTLE_ENDIAN |
413 | pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD); | |
414 | #else | |
415 | switch (depth) { | |
416 | case 24: /* RGB->BGR */ | |
417 | /* | |
418 | * We can't use the aperture to translate host to | |
419 | * card byte order here, so we switch to BGR mode | |
420 | * in pm2fb_set_par(). | |
421 | */ | |
422 | case 8: /* B->B */ | |
423 | pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD); | |
424 | break; | |
425 | case 16: /* HL->LH */ | |
426 | pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_HALFWORDSWAP); | |
427 | break; | |
428 | case 32: /* RGBA->ABGR */ | |
429 | pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_BYTESWAP); | |
430 | break; | |
431 | } | |
432 | #endif | |
433 | ||
3843faa2 | 434 | /* We don't use aperture two, so this may be superflous */ |
1da177e4 LT |
435 | pm2_WR(p, PM2R_APERTURE_TWO, PM2F_APERTURE_STANDARD); |
436 | } | |
437 | ||
3843faa2 | 438 | static void set_color(struct pm2fb_par *p, unsigned char regno, |
1da177e4 LT |
439 | unsigned char r, unsigned char g, unsigned char b) |
440 | { | |
441 | WAIT_FIFO(p, 4); | |
442 | pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, regno); | |
443 | wmb(); | |
444 | pm2_WR(p, PM2R_RD_PALETTE_DATA, r); | |
445 | wmb(); | |
446 | pm2_WR(p, PM2R_RD_PALETTE_DATA, g); | |
447 | wmb(); | |
448 | pm2_WR(p, PM2R_RD_PALETTE_DATA, b); | |
449 | } | |
450 | ||
3843faa2 | 451 | static void set_memclock(struct pm2fb_par *par, u32 clk) |
1da177e4 LT |
452 | { |
453 | int i; | |
454 | unsigned char m, n, p; | |
455 | ||
e5d809d7 KH |
456 | switch (par->type) { |
457 | case PM2_TYPE_PERMEDIA2V: | |
458 | pm2v_mnp(clk/2, &m, &n, &p); | |
45f169ec | 459 | WAIT_FIFO(par, 12); |
e5d809d7 KH |
460 | pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_MCLK_CONTROL >> 8); |
461 | pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 0); | |
e5d809d7 KH |
462 | pm2v_RDAC_WR(par, PM2VI_RD_MCLK_PRESCALE, m); |
463 | pm2v_RDAC_WR(par, PM2VI_RD_MCLK_FEEDBACK, n); | |
464 | pm2v_RDAC_WR(par, PM2VI_RD_MCLK_POSTSCALE, p); | |
e5d809d7 KH |
465 | pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 1); |
466 | rmb(); | |
45f169ec KH |
467 | for (i = 256; i; i--) |
468 | if (pm2v_RDAC_RD(par, PM2VI_RD_MCLK_CONTROL) & 2) | |
469 | break; | |
e5d809d7 KH |
470 | pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0); |
471 | break; | |
472 | case PM2_TYPE_PERMEDIA2: | |
473 | pm2_mnp(clk, &m, &n, &p); | |
474 | WAIT_FIFO(par, 10); | |
475 | pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 6); | |
e5d809d7 KH |
476 | pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_1, m); |
477 | pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_2, n); | |
e5d809d7 | 478 | pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 8|p); |
e5d809d7 KH |
479 | pm2_RDAC_RD(par, PM2I_RD_MEMORY_CLOCK_STATUS); |
480 | rmb(); | |
45f169ec KH |
481 | for (i = 256; i; i--) |
482 | if (pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED) | |
483 | break; | |
e5d809d7 KH |
484 | break; |
485 | } | |
1da177e4 LT |
486 | } |
487 | ||
3843faa2 | 488 | static void set_pixclock(struct pm2fb_par *par, u32 clk) |
1da177e4 LT |
489 | { |
490 | int i; | |
491 | unsigned char m, n, p; | |
492 | ||
493 | switch (par->type) { | |
494 | case PM2_TYPE_PERMEDIA2: | |
495 | pm2_mnp(clk, &m, &n, &p); | |
45f169ec | 496 | WAIT_FIFO(par, 10); |
1da177e4 | 497 | pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 0); |
1da177e4 LT |
498 | pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A1, m); |
499 | pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A2, n); | |
1da177e4 | 500 | pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 8|p); |
1da177e4 LT |
501 | pm2_RDAC_RD(par, PM2I_RD_PIXEL_CLOCK_STATUS); |
502 | rmb(); | |
45f169ec KH |
503 | for (i = 256; i; i--) |
504 | if (pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED) | |
505 | break; | |
1da177e4 LT |
506 | break; |
507 | case PM2_TYPE_PERMEDIA2V: | |
508 | pm2v_mnp(clk/2, &m, &n, &p); | |
509 | WAIT_FIFO(par, 8); | |
510 | pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CLK0_PRESCALE >> 8); | |
511 | pm2v_RDAC_WR(par, PM2VI_RD_CLK0_PRESCALE, m); | |
512 | pm2v_RDAC_WR(par, PM2VI_RD_CLK0_FEEDBACK, n); | |
513 | pm2v_RDAC_WR(par, PM2VI_RD_CLK0_POSTSCALE, p); | |
514 | pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0); | |
515 | break; | |
516 | } | |
517 | } | |
518 | ||
3843faa2 KH |
519 | static void set_video(struct pm2fb_par *p, u32 video) |
520 | { | |
1da177e4 | 521 | u32 tmp; |
45f169ec | 522 | u32 vsync = video; |
1da177e4 LT |
523 | |
524 | DPRINTK("video = 0x%x\n", video); | |
2f7bb99f | 525 | |
1da177e4 LT |
526 | /* |
527 | * The hardware cursor needs +vsync to recognise vert retrace. | |
528 | * We may not be using the hardware cursor, but the X Glint | |
529 | * driver may well. So always set +hsync/+vsync and then set | |
530 | * the RAMDAC to invert the sync if necessary. | |
531 | */ | |
45f169ec KH |
532 | vsync &= ~(PM2F_HSYNC_MASK | PM2F_VSYNC_MASK); |
533 | vsync |= PM2F_HSYNC_ACT_HIGH | PM2F_VSYNC_ACT_HIGH; | |
1da177e4 | 534 | |
138a451c | 535 | WAIT_FIFO(p, 3); |
1da177e4 LT |
536 | pm2_WR(p, PM2R_VIDEO_CONTROL, vsync); |
537 | ||
538 | switch (p->type) { | |
539 | case PM2_TYPE_PERMEDIA2: | |
540 | tmp = PM2F_RD_PALETTE_WIDTH_8; | |
541 | if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW) | |
542 | tmp |= 4; /* invert hsync */ | |
543 | if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW) | |
544 | tmp |= 8; /* invert vsync */ | |
545 | pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, tmp); | |
546 | break; | |
547 | case PM2_TYPE_PERMEDIA2V: | |
548 | tmp = 0; | |
549 | if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW) | |
550 | tmp |= 1; /* invert hsync */ | |
551 | if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW) | |
552 | tmp |= 4; /* invert vsync */ | |
553 | pm2v_RDAC_WR(p, PM2VI_RD_SYNC_CONTROL, tmp); | |
1da177e4 LT |
554 | break; |
555 | } | |
556 | } | |
557 | ||
558 | /* | |
2f7bb99f KH |
559 | * pm2fb_check_var - Optional function. Validates a var passed in. |
560 | * @var: frame buffer variable screen structure | |
561 | * @info: frame buffer structure that represents a single frame buffer | |
1da177e4 LT |
562 | * |
563 | * Checks to see if the hardware supports the state requested by | |
564 | * var passed in. | |
565 | * | |
566 | * Returns negative errno on error, or zero on success. | |
567 | */ | |
568 | static int pm2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) | |
569 | { | |
570 | u32 lpitch; | |
571 | ||
572 | if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 && | |
573 | var->bits_per_pixel != 24 && var->bits_per_pixel != 32) { | |
574 | DPRINTK("depth not supported: %u\n", var->bits_per_pixel); | |
575 | return -EINVAL; | |
576 | } | |
577 | ||
578 | if (var->xres != var->xres_virtual) { | |
3843faa2 KH |
579 | DPRINTK("virtual x resolution != " |
580 | "physical x resolution not supported\n"); | |
1da177e4 LT |
581 | return -EINVAL; |
582 | } | |
583 | ||
584 | if (var->yres > var->yres_virtual) { | |
3843faa2 KH |
585 | DPRINTK("virtual y resolution < " |
586 | "physical y resolution not possible\n"); | |
1da177e4 LT |
587 | return -EINVAL; |
588 | } | |
589 | ||
590 | if (var->xoffset) { | |
591 | DPRINTK("xoffset not supported\n"); | |
592 | return -EINVAL; | |
593 | } | |
594 | ||
595 | if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) { | |
596 | DPRINTK("interlace not supported\n"); | |
597 | return -EINVAL; | |
598 | } | |
599 | ||
600 | var->xres = (var->xres + 15) & ~15; /* could sometimes be 8 */ | |
45f169ec | 601 | lpitch = var->xres * ((var->bits_per_pixel + 7) >> 3); |
2f7bb99f | 602 | |
1da177e4 LT |
603 | if (var->xres < 320 || var->xres > 1600) { |
604 | DPRINTK("width not supported: %u\n", var->xres); | |
605 | return -EINVAL; | |
606 | } | |
2f7bb99f | 607 | |
1da177e4 LT |
608 | if (var->yres < 200 || var->yres > 1200) { |
609 | DPRINTK("height not supported: %u\n", var->yres); | |
610 | return -EINVAL; | |
611 | } | |
2f7bb99f | 612 | |
1da177e4 LT |
613 | if (lpitch * var->yres_virtual > info->fix.smem_len) { |
614 | DPRINTK("no memory for screen (%ux%ux%u)\n", | |
615 | var->xres, var->yres_virtual, var->bits_per_pixel); | |
616 | return -EINVAL; | |
617 | } | |
2f7bb99f | 618 | |
1da177e4 | 619 | if (PICOS2KHZ(var->pixclock) > PM2_MAX_PIXCLOCK) { |
3843faa2 KH |
620 | DPRINTK("pixclock too high (%ldKHz)\n", |
621 | PICOS2KHZ(var->pixclock)); | |
1da177e4 LT |
622 | return -EINVAL; |
623 | } | |
624 | ||
76c7d3ff | 625 | var->transp.offset = 0; |
626 | var->transp.length = 0; | |
3843faa2 | 627 | switch (var->bits_per_pixel) { |
1da177e4 | 628 | case 8: |
3843faa2 KH |
629 | var->red.length = 8; |
630 | var->green.length = 8; | |
631 | var->blue.length = 8; | |
1da177e4 LT |
632 | break; |
633 | case 16: | |
634 | var->red.offset = 11; | |
635 | var->red.length = 5; | |
636 | var->green.offset = 5; | |
637 | var->green.length = 6; | |
638 | var->blue.offset = 0; | |
639 | var->blue.length = 5; | |
640 | break; | |
641 | case 32: | |
642 | var->transp.offset = 24; | |
643 | var->transp.length = 8; | |
644 | var->red.offset = 16; | |
645 | var->green.offset = 8; | |
646 | var->blue.offset = 0; | |
3843faa2 KH |
647 | var->red.length = 8; |
648 | var->green.length = 8; | |
649 | var->blue.length = 8; | |
1da177e4 LT |
650 | break; |
651 | case 24: | |
652 | #ifdef __BIG_ENDIAN | |
653 | var->red.offset = 0; | |
654 | var->blue.offset = 16; | |
655 | #else | |
656 | var->red.offset = 16; | |
657 | var->blue.offset = 0; | |
658 | #endif | |
659 | var->green.offset = 8; | |
3843faa2 KH |
660 | var->red.length = 8; |
661 | var->green.length = 8; | |
662 | var->blue.length = 8; | |
1da177e4 LT |
663 | break; |
664 | } | |
3843faa2 KH |
665 | var->height = -1; |
666 | var->width = -1; | |
2f7bb99f | 667 | |
1da177e4 | 668 | var->accel_flags = 0; /* Can't mmap if this is on */ |
2f7bb99f | 669 | |
1da177e4 LT |
670 | DPRINTK("Checking graphics mode at %dx%d depth %d\n", |
671 | var->xres, var->yres, var->bits_per_pixel); | |
672 | return 0; | |
673 | } | |
674 | ||
675 | /** | |
2f7bb99f KH |
676 | * pm2fb_set_par - Alters the hardware state. |
677 | * @info: frame buffer structure that represents a single frame buffer | |
1da177e4 LT |
678 | * |
679 | * Using the fb_var_screeninfo in fb_info we set the resolution of the | |
680 | * this particular framebuffer. | |
681 | */ | |
682 | static int pm2fb_set_par(struct fb_info *info) | |
683 | { | |
6772a2ee | 684 | struct pm2fb_par *par = info->par; |
1da177e4 | 685 | u32 pixclock; |
45f169ec KH |
686 | u32 width = (info->var.xres_virtual + 7) & ~7; |
687 | u32 height = info->var.yres_virtual; | |
688 | u32 depth = (info->var.bits_per_pixel + 7) & ~7; | |
1da177e4 LT |
689 | u32 hsstart, hsend, hbend, htotal; |
690 | u32 vsstart, vsend, vbend, vtotal; | |
691 | u32 stride; | |
692 | u32 base; | |
693 | u32 video = 0; | |
694 | u32 clrmode = PM2F_RD_COLOR_MODE_RGB | PM2F_RD_GUI_ACTIVE; | |
695 | u32 txtmap = 0; | |
696 | u32 pixsize = 0; | |
697 | u32 clrformat = 0; | |
138a451c | 698 | u32 misc = 1; /* 8-bit DAC */ |
45f169ec | 699 | u32 xres = (info->var.xres + 31) & ~31; |
1da177e4 LT |
700 | int data64; |
701 | ||
702 | reset_card(par); | |
703 | reset_config(par); | |
704 | clear_palette(par); | |
45f169ec | 705 | if (par->memclock) |
1da177e4 | 706 | set_memclock(par, par->memclock); |
2f7bb99f | 707 | |
1da177e4 LT |
708 | depth = (depth > 32) ? 32 : depth; |
709 | data64 = depth > 8 || par->type == PM2_TYPE_PERMEDIA2V; | |
710 | ||
1da177e4 LT |
711 | pixclock = PICOS2KHZ(info->var.pixclock); |
712 | if (pixclock > PM2_MAX_PIXCLOCK) { | |
713 | DPRINTK("pixclock too high (%uKHz)\n", pixclock); | |
714 | return -EINVAL; | |
715 | } | |
2f7bb99f | 716 | |
1da177e4 LT |
717 | hsstart = to3264(info->var.right_margin, depth, data64); |
718 | hsend = hsstart + to3264(info->var.hsync_len, depth, data64); | |
719 | hbend = hsend + to3264(info->var.left_margin, depth, data64); | |
720 | htotal = to3264(xres, depth, data64) + hbend - 1; | |
721 | vsstart = (info->var.lower_margin) | |
722 | ? info->var.lower_margin - 1 | |
723 | : 0; /* FIXME! */ | |
724 | vsend = info->var.lower_margin + info->var.vsync_len - 1; | |
3843faa2 KH |
725 | vbend = info->var.lower_margin + info->var.vsync_len + |
726 | info->var.upper_margin; | |
1da177e4 LT |
727 | vtotal = info->var.yres + vbend - 1; |
728 | stride = to3264(width, depth, 1); | |
729 | base = to3264(info->var.yoffset * xres + info->var.xoffset, depth, 1); | |
730 | if (data64) | |
731 | video |= PM2F_DATA_64_ENABLE; | |
2f7bb99f | 732 | |
1da177e4 LT |
733 | if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) { |
734 | if (lowhsync) { | |
735 | DPRINTK("ignoring +hsync, using -hsync.\n"); | |
736 | video |= PM2F_HSYNC_ACT_LOW; | |
737 | } else | |
738 | video |= PM2F_HSYNC_ACT_HIGH; | |
3843faa2 | 739 | } else |
1da177e4 | 740 | video |= PM2F_HSYNC_ACT_LOW; |
3843faa2 | 741 | |
1da177e4 LT |
742 | if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) { |
743 | if (lowvsync) { | |
744 | DPRINTK("ignoring +vsync, using -vsync.\n"); | |
745 | video |= PM2F_VSYNC_ACT_LOW; | |
746 | } else | |
747 | video |= PM2F_VSYNC_ACT_HIGH; | |
3843faa2 | 748 | } else |
1da177e4 | 749 | video |= PM2F_VSYNC_ACT_LOW; |
3843faa2 | 750 | |
45f169ec | 751 | if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) { |
1da177e4 LT |
752 | DPRINTK("interlaced not supported\n"); |
753 | return -EINVAL; | |
754 | } | |
45f169ec | 755 | if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) |
1da177e4 | 756 | video |= PM2F_LINE_DOUBLE; |
45f169ec | 757 | if ((info->var.activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) |
1da177e4 LT |
758 | video |= PM2F_VIDEO_ENABLE; |
759 | par->video = video; | |
760 | ||
761 | info->fix.visual = | |
762 | (depth == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; | |
763 | info->fix.line_length = info->var.xres * depth / 8; | |
764 | info->cmap.len = 256; | |
765 | ||
766 | /* | |
767 | * Settings calculated. Now write them out. | |
768 | */ | |
769 | if (par->type == PM2_TYPE_PERMEDIA2V) { | |
770 | WAIT_FIFO(par, 1); | |
771 | pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0); | |
772 | } | |
2f7bb99f | 773 | |
1da177e4 | 774 | set_aperture(par, depth); |
2f7bb99f | 775 | |
1da177e4 LT |
776 | mb(); |
777 | WAIT_FIFO(par, 19); | |
1da177e4 LT |
778 | switch (depth) { |
779 | case 8: | |
780 | pm2_WR(par, PM2R_FB_READ_PIXEL, 0); | |
138a451c | 781 | clrformat = 0x2e; |
1da177e4 LT |
782 | break; |
783 | case 16: | |
784 | pm2_WR(par, PM2R_FB_READ_PIXEL, 1); | |
785 | clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB565; | |
786 | txtmap = PM2F_TEXTEL_SIZE_16; | |
787 | pixsize = 1; | |
788 | clrformat = 0x70; | |
138a451c | 789 | misc |= 8; |
1da177e4 LT |
790 | break; |
791 | case 32: | |
792 | pm2_WR(par, PM2R_FB_READ_PIXEL, 2); | |
793 | clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGBA8888; | |
794 | txtmap = PM2F_TEXTEL_SIZE_32; | |
795 | pixsize = 2; | |
796 | clrformat = 0x20; | |
138a451c | 797 | misc |= 8; |
1da177e4 LT |
798 | break; |
799 | case 24: | |
800 | pm2_WR(par, PM2R_FB_READ_PIXEL, 4); | |
801 | clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB888; | |
802 | txtmap = PM2F_TEXTEL_SIZE_24; | |
803 | pixsize = 4; | |
804 | clrformat = 0x20; | |
138a451c | 805 | misc |= 8; |
1da177e4 LT |
806 | break; |
807 | } | |
808 | pm2_WR(par, PM2R_FB_WRITE_MODE, PM2F_FB_WRITE_ENABLE); | |
809 | pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres)); | |
810 | pm2_WR(par, PM2R_LB_READ_MODE, partprod(xres)); | |
811 | pm2_WR(par, PM2R_TEXTURE_MAP_FORMAT, txtmap | partprod(xres)); | |
812 | pm2_WR(par, PM2R_H_TOTAL, htotal); | |
813 | pm2_WR(par, PM2R_HS_START, hsstart); | |
814 | pm2_WR(par, PM2R_HS_END, hsend); | |
815 | pm2_WR(par, PM2R_HG_END, hbend); | |
816 | pm2_WR(par, PM2R_HB_END, hbend); | |
817 | pm2_WR(par, PM2R_V_TOTAL, vtotal); | |
818 | pm2_WR(par, PM2R_VS_START, vsstart); | |
819 | pm2_WR(par, PM2R_VS_END, vsend); | |
820 | pm2_WR(par, PM2R_VB_END, vbend); | |
821 | pm2_WR(par, PM2R_SCREEN_STRIDE, stride); | |
822 | wmb(); | |
823 | pm2_WR(par, PM2R_WINDOW_ORIGIN, 0); | |
824 | pm2_WR(par, PM2R_SCREEN_SIZE, (height << 16) | width); | |
825 | pm2_WR(par, PM2R_SCISSOR_MODE, PM2F_SCREEN_SCISSOR_ENABLE); | |
826 | wmb(); | |
827 | pm2_WR(par, PM2R_SCREEN_BASE, base); | |
828 | wmb(); | |
829 | set_video(par, video); | |
138a451c | 830 | WAIT_FIFO(par, 10); |
1da177e4 LT |
831 | switch (par->type) { |
832 | case PM2_TYPE_PERMEDIA2: | |
833 | pm2_RDAC_WR(par, PM2I_RD_COLOR_MODE, clrmode); | |
45f169ec | 834 | pm2_RDAC_WR(par, PM2I_RD_COLOR_KEY_CONTROL, |
3843faa2 | 835 | (depth == 8) ? 0 : PM2F_COLOR_KEY_TEST_OFF); |
1da177e4 LT |
836 | break; |
837 | case PM2_TYPE_PERMEDIA2V: | |
138a451c | 838 | pm2v_RDAC_WR(par, PM2VI_RD_DAC_CONTROL, 0); |
1da177e4 LT |
839 | pm2v_RDAC_WR(par, PM2VI_RD_PIXEL_SIZE, pixsize); |
840 | pm2v_RDAC_WR(par, PM2VI_RD_COLOR_FORMAT, clrformat); | |
138a451c KH |
841 | pm2v_RDAC_WR(par, PM2VI_RD_MISC_CONTROL, misc); |
842 | pm2v_RDAC_WR(par, PM2VI_RD_OVERLAY_KEY, 0); | |
1da177e4 LT |
843 | break; |
844 | } | |
845 | set_pixclock(par, pixclock); | |
846 | DPRINTK("Setting graphics mode at %dx%d depth %d\n", | |
847 | info->var.xres, info->var.yres, info->var.bits_per_pixel); | |
2f7bb99f | 848 | return 0; |
1da177e4 LT |
849 | } |
850 | ||
851 | /** | |
2f7bb99f KH |
852 | * pm2fb_setcolreg - Sets a color register. |
853 | * @regno: boolean, 0 copy local, 1 get_user() function | |
854 | * @red: frame buffer colormap structure | |
855 | * @green: The green value which can be up to 16 bits wide | |
1da177e4 | 856 | * @blue: The blue value which can be up to 16 bits wide. |
2f7bb99f KH |
857 | * @transp: If supported the alpha value which can be up to 16 bits wide. |
858 | * @info: frame buffer info structure | |
859 | * | |
860 | * Set a single color register. The values supplied have a 16 bit | |
861 | * magnitude which needs to be scaled in this function for the hardware. | |
1da177e4 | 862 | * Pretty much a direct lift from tdfxfb.c. |
2f7bb99f | 863 | * |
1da177e4 LT |
864 | * Returns negative errno on error, or zero on success. |
865 | */ | |
866 | static int pm2fb_setcolreg(unsigned regno, unsigned red, unsigned green, | |
867 | unsigned blue, unsigned transp, | |
868 | struct fb_info *info) | |
869 | { | |
6772a2ee | 870 | struct pm2fb_par *par = info->par; |
1da177e4 LT |
871 | |
872 | if (regno >= info->cmap.len) /* no. of hw registers */ | |
138a451c | 873 | return -EINVAL; |
1da177e4 LT |
874 | /* |
875 | * Program hardware... do anything you want with transp | |
876 | */ | |
877 | ||
878 | /* grayscale works only partially under directcolor */ | |
3843faa2 KH |
879 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ |
880 | if (info->var.grayscale) | |
1da177e4 | 881 | red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; |
1da177e4 LT |
882 | |
883 | /* Directcolor: | |
884 | * var->{color}.offset contains start of bitfield | |
885 | * var->{color}.length contains length of bitfield | |
886 | * {hardwarespecific} contains width of DAC | |
887 | * cmap[X] is programmed to | |
888 | * (X << red.offset) | (X << green.offset) | (X << blue.offset) | |
889 | * RAMDAC[X] is programmed to (red, green, blue) | |
890 | * | |
891 | * Pseudocolor: | |
892 | * uses offset = 0 && length = DAC register width. | |
893 | * var->{color}.offset is 0 | |
894 | * var->{color}.length contains widht of DAC | |
895 | * cmap is not used | |
896 | * DAC[X] is programmed to (red, green, blue) | |
897 | * Truecolor: | |
898 | * does not use RAMDAC (usually has 3 of them). | |
899 | * var->{color}.offset contains start of bitfield | |
900 | * var->{color}.length contains length of bitfield | |
901 | * cmap is programmed to | |
902 | * (red << red.offset) | (green << green.offset) | | |
903 | * (blue << blue.offset) | (transp << transp.offset) | |
904 | * RAMDAC does not exist | |
905 | */ | |
2f7bb99f | 906 | #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF -(val)) >> 16) |
1da177e4 LT |
907 | switch (info->fix.visual) { |
908 | case FB_VISUAL_TRUECOLOR: | |
909 | case FB_VISUAL_PSEUDOCOLOR: | |
910 | red = CNVT_TOHW(red, info->var.red.length); | |
911 | green = CNVT_TOHW(green, info->var.green.length); | |
912 | blue = CNVT_TOHW(blue, info->var.blue.length); | |
913 | transp = CNVT_TOHW(transp, info->var.transp.length); | |
914 | break; | |
915 | case FB_VISUAL_DIRECTCOLOR: | |
2f7bb99f KH |
916 | /* example here assumes 8 bit DAC. Might be different |
917 | * for your hardware */ | |
918 | red = CNVT_TOHW(red, 8); | |
1da177e4 LT |
919 | green = CNVT_TOHW(green, 8); |
920 | blue = CNVT_TOHW(blue, 8); | |
921 | /* hey, there is bug in transp handling... */ | |
922 | transp = CNVT_TOHW(transp, 8); | |
923 | break; | |
924 | } | |
925 | #undef CNVT_TOHW | |
926 | /* Truecolor has hardware independent palette */ | |
927 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { | |
928 | u32 v; | |
929 | ||
930 | if (regno >= 16) | |
138a451c | 931 | return -EINVAL; |
1da177e4 LT |
932 | |
933 | v = (red << info->var.red.offset) | | |
934 | (green << info->var.green.offset) | | |
935 | (blue << info->var.blue.offset) | | |
936 | (transp << info->var.transp.offset); | |
937 | ||
938 | switch (info->var.bits_per_pixel) { | |
939 | case 8: | |
2f7bb99f KH |
940 | break; |
941 | case 16: | |
1da177e4 | 942 | case 24: |
2f7bb99f KH |
943 | case 32: |
944 | par->palette[regno] = v; | |
1da177e4 LT |
945 | break; |
946 | } | |
947 | return 0; | |
3843faa2 | 948 | } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) |
1da177e4 LT |
949 | set_color(par, regno, red, green, blue); |
950 | ||
951 | return 0; | |
952 | } | |
953 | ||
954 | /** | |
2f7bb99f KH |
955 | * pm2fb_pan_display - Pans the display. |
956 | * @var: frame buffer variable screen structure | |
957 | * @info: frame buffer structure that represents a single frame buffer | |
1da177e4 LT |
958 | * |
959 | * Pan (or wrap, depending on the `vmode' field) the display using the | |
2f7bb99f KH |
960 | * `xoffset' and `yoffset' fields of the `var' structure. |
961 | * If the values don't fit, return -EINVAL. | |
1da177e4 | 962 | * |
2f7bb99f | 963 | * Returns negative errno on error, or zero on success. |
1da177e4 LT |
964 | * |
965 | */ | |
966 | static int pm2fb_pan_display(struct fb_var_screeninfo *var, | |
967 | struct fb_info *info) | |
968 | { | |
6772a2ee | 969 | struct pm2fb_par *p = info->par; |
1da177e4 | 970 | u32 base; |
45f169ec KH |
971 | u32 depth = (var->bits_per_pixel + 7) & ~7; |
972 | u32 xres = (var->xres + 31) & ~31; | |
1da177e4 | 973 | |
1da177e4 LT |
974 | depth = (depth > 32) ? 32 : depth; |
975 | base = to3264(var->yoffset * xres + var->xoffset, depth, 1); | |
976 | WAIT_FIFO(p, 1); | |
2f7bb99f | 977 | pm2_WR(p, PM2R_SCREEN_BASE, base); |
1da177e4 LT |
978 | return 0; |
979 | } | |
980 | ||
981 | /** | |
2f7bb99f KH |
982 | * pm2fb_blank - Blanks the display. |
983 | * @blank_mode: the blank mode we want. | |
984 | * @info: frame buffer structure that represents a single frame buffer | |
1da177e4 | 985 | * |
2f7bb99f KH |
986 | * Blank the screen if blank_mode != 0, else unblank. Return 0 if |
987 | * blanking succeeded, != 0 if un-/blanking failed due to e.g. a | |
988 | * video mode which doesn't support it. Implements VESA suspend | |
989 | * and powerdown modes on hardware that supports disabling hsync/vsync: | |
990 | * blank_mode == 2: suspend vsync | |
991 | * blank_mode == 3: suspend hsync | |
992 | * blank_mode == 4: powerdown | |
1da177e4 | 993 | * |
2f7bb99f | 994 | * Returns negative errno on error, or zero on success. |
1da177e4 LT |
995 | * |
996 | */ | |
997 | static int pm2fb_blank(int blank_mode, struct fb_info *info) | |
998 | { | |
6772a2ee | 999 | struct pm2fb_par *par = info->par; |
1da177e4 LT |
1000 | u32 video = par->video; |
1001 | ||
1002 | DPRINTK("blank_mode %d\n", blank_mode); | |
1003 | ||
1004 | switch (blank_mode) { | |
1005 | case FB_BLANK_UNBLANK: | |
1006 | /* Screen: On */ | |
1007 | video |= PM2F_VIDEO_ENABLE; | |
1008 | break; | |
1009 | case FB_BLANK_NORMAL: | |
1010 | /* Screen: Off */ | |
1011 | video &= ~PM2F_VIDEO_ENABLE; | |
1012 | break; | |
1013 | case FB_BLANK_VSYNC_SUSPEND: | |
1014 | /* VSync: Off */ | |
45f169ec | 1015 | video &= ~(PM2F_VSYNC_MASK | PM2F_BLANK_LOW); |
1da177e4 LT |
1016 | break; |
1017 | case FB_BLANK_HSYNC_SUSPEND: | |
1018 | /* HSync: Off */ | |
45f169ec | 1019 | video &= ~(PM2F_HSYNC_MASK | PM2F_BLANK_LOW); |
1da177e4 LT |
1020 | break; |
1021 | case FB_BLANK_POWERDOWN: | |
1022 | /* HSync: Off, VSync: Off */ | |
3843faa2 | 1023 | video &= ~(PM2F_VSYNC_MASK | PM2F_HSYNC_MASK | PM2F_BLANK_LOW); |
1da177e4 LT |
1024 | break; |
1025 | } | |
1026 | set_video(par, video); | |
1027 | return 0; | |
1028 | } | |
1029 | ||
03b9ae4b AD |
1030 | static int pm2fb_sync(struct fb_info *info) |
1031 | { | |
1032 | struct pm2fb_par *par = info->par; | |
1033 | ||
1034 | WAIT_FIFO(par, 1); | |
1035 | pm2_WR(par, PM2R_SYNC, 0); | |
1036 | mb(); | |
1037 | do { | |
1038 | while (pm2_RD(par, PM2R_OUT_FIFO_WORDS) == 0) | |
1039 | udelay(10); | |
1040 | rmb(); | |
1041 | } while (pm2_RD(par, PM2R_OUT_FIFO) != PM2TAG(PM2R_SYNC)); | |
1042 | ||
1043 | return 0; | |
1044 | } | |
1045 | ||
3843faa2 | 1046 | static void pm2fb_fillrect(struct fb_info *info, |
87a7cc68 KH |
1047 | const struct fb_fillrect *region) |
1048 | { | |
3843faa2 | 1049 | struct pm2fb_par *par = info->par; |
87a7cc68 KH |
1050 | struct fb_fillrect modded; |
1051 | int vxres, vyres; | |
1052 | u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ? | |
3843faa2 | 1053 | ((u32 *)info->pseudo_palette)[region->color] : region->color; |
87a7cc68 KH |
1054 | |
1055 | if (info->state != FBINFO_STATE_RUNNING) | |
1056 | return; | |
1057 | if ((info->flags & FBINFO_HWACCEL_DISABLED) || | |
1058 | region->rop != ROP_COPY ) { | |
1059 | cfb_fillrect(info, region); | |
1060 | return; | |
1061 | } | |
1062 | ||
1063 | vxres = info->var.xres_virtual; | |
1064 | vyres = info->var.yres_virtual; | |
1065 | ||
1066 | memcpy(&modded, region, sizeof(struct fb_fillrect)); | |
1067 | ||
45f169ec KH |
1068 | if (!modded.width || !modded.height || |
1069 | modded.dx >= vxres || modded.dy >= vyres) | |
87a7cc68 KH |
1070 | return; |
1071 | ||
45f169ec | 1072 | if (modded.dx + modded.width > vxres) |
87a7cc68 | 1073 | modded.width = vxres - modded.dx; |
45f169ec | 1074 | if (modded.dy + modded.height > vyres) |
87a7cc68 KH |
1075 | modded.height = vyres - modded.dy; |
1076 | ||
45f169ec | 1077 | if (info->var.bits_per_pixel == 8) |
87a7cc68 | 1078 | color |= color << 8; |
45f169ec | 1079 | if (info->var.bits_per_pixel <= 16) |
87a7cc68 KH |
1080 | color |= color << 16; |
1081 | ||
45f169ec KH |
1082 | WAIT_FIFO(par, 3); |
1083 | pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE); | |
1084 | pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (modded.dy << 16) | modded.dx); | |
1085 | pm2_WR(par, PM2R_RECTANGLE_SIZE, (modded.height << 16) | modded.width); | |
1086 | if (info->var.bits_per_pixel != 24) { | |
1087 | WAIT_FIFO(par, 2); | |
1088 | pm2_WR(par, PM2R_FB_BLOCK_COLOR, color); | |
1089 | wmb(); | |
1090 | pm2_WR(par, PM2R_RENDER, | |
1091 | PM2F_RENDER_RECTANGLE | PM2F_RENDER_FASTFILL); | |
1092 | } else { | |
30dcc909 KH |
1093 | WAIT_FIFO(par, 4); |
1094 | pm2_WR(par, PM2R_COLOR_DDA_MODE, 1); | |
1095 | pm2_WR(par, PM2R_CONSTANT_COLOR, color); | |
1096 | wmb(); | |
1097 | pm2_WR(par, PM2R_RENDER, | |
3843faa2 KH |
1098 | PM2F_RENDER_RECTANGLE | |
1099 | PM2F_INCREASE_X | PM2F_INCREASE_Y ); | |
30dcc909 | 1100 | pm2_WR(par, PM2R_COLOR_DDA_MODE, 0); |
45f169ec | 1101 | } |
87a7cc68 KH |
1102 | } |
1103 | ||
1104 | static void pm2fb_copyarea(struct fb_info *info, | |
1105 | const struct fb_copyarea *area) | |
1106 | { | |
45f169ec | 1107 | struct pm2fb_par *par = info->par; |
87a7cc68 KH |
1108 | struct fb_copyarea modded; |
1109 | u32 vxres, vyres; | |
1110 | ||
1111 | if (info->state != FBINFO_STATE_RUNNING) | |
1112 | return; | |
1113 | if (info->flags & FBINFO_HWACCEL_DISABLED) { | |
1114 | cfb_copyarea(info, area); | |
1115 | return; | |
1116 | } | |
1117 | ||
1118 | memcpy(&modded, area, sizeof(struct fb_copyarea)); | |
1119 | ||
1120 | vxres = info->var.xres_virtual; | |
1121 | vyres = info->var.yres_virtual; | |
1122 | ||
45f169ec KH |
1123 | if (!modded.width || !modded.height || |
1124 | modded.sx >= vxres || modded.sy >= vyres || | |
1125 | modded.dx >= vxres || modded.dy >= vyres) | |
87a7cc68 KH |
1126 | return; |
1127 | ||
45f169ec | 1128 | if (modded.sx + modded.width > vxres) |
87a7cc68 | 1129 | modded.width = vxres - modded.sx; |
45f169ec | 1130 | if (modded.dx + modded.width > vxres) |
87a7cc68 | 1131 | modded.width = vxres - modded.dx; |
45f169ec | 1132 | if (modded.sy + modded.height > vyres) |
87a7cc68 | 1133 | modded.height = vyres - modded.sy; |
45f169ec | 1134 | if (modded.dy + modded.height > vyres) |
87a7cc68 KH |
1135 | modded.height = vyres - modded.dy; |
1136 | ||
45f169ec KH |
1137 | WAIT_FIFO(par, 5); |
1138 | pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE | | |
1139 | PM2F_CONFIG_FB_READ_SOURCE_ENABLE); | |
1140 | pm2_WR(par, PM2R_FB_SOURCE_DELTA, | |
3843faa2 KH |
1141 | ((modded.sy - modded.dy) & 0xfff) << 16 | |
1142 | ((modded.sx - modded.dx) & 0xfff)); | |
45f169ec KH |
1143 | pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (modded.dy << 16) | modded.dx); |
1144 | pm2_WR(par, PM2R_RECTANGLE_SIZE, (modded.height << 16) | modded.width); | |
1145 | wmb(); | |
1146 | pm2_WR(par, PM2R_RENDER, PM2F_RENDER_RECTANGLE | | |
3843faa2 KH |
1147 | (modded.dx < modded.sx ? PM2F_INCREASE_X : 0) | |
1148 | (modded.dy < modded.sy ? PM2F_INCREASE_Y : 0)); | |
87a7cc68 KH |
1149 | } |
1150 | ||
91b3a6f4 KH |
1151 | static void pm2fb_imageblit(struct fb_info *info, const struct fb_image *image) |
1152 | { | |
1153 | struct pm2fb_par *par = info->par; | |
1154 | u32 height = image->height; | |
1155 | u32 fgx, bgx; | |
3843faa2 | 1156 | const u32 *src = (const u32 *)image->data; |
91b3a6f4 KH |
1157 | u32 xres = (info->var.xres + 31) & ~31; |
1158 | ||
1159 | if (info->state != FBINFO_STATE_RUNNING) | |
1160 | return; | |
1161 | if (info->flags & FBINFO_HWACCEL_DISABLED || image->depth != 1) { | |
1162 | cfb_imageblit(info, image); | |
1163 | return; | |
1164 | } | |
1165 | switch (info->fix.visual) { | |
45f169ec KH |
1166 | case FB_VISUAL_PSEUDOCOLOR: |
1167 | fgx = image->fg_color; | |
1168 | bgx = image->bg_color; | |
1169 | break; | |
1170 | case FB_VISUAL_TRUECOLOR: | |
1171 | default: | |
1172 | fgx = par->palette[image->fg_color]; | |
1173 | bgx = par->palette[image->bg_color]; | |
1174 | break; | |
91b3a6f4 KH |
1175 | } |
1176 | if (info->var.bits_per_pixel == 8) { | |
1177 | fgx |= fgx << 8; | |
1178 | bgx |= bgx << 8; | |
1179 | } | |
1180 | if (info->var.bits_per_pixel <= 16) { | |
1181 | fgx |= fgx << 16; | |
1182 | bgx |= bgx << 16; | |
1183 | } | |
1184 | ||
1185 | WAIT_FIFO(par, 13); | |
1186 | pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres)); | |
1187 | pm2_WR(par, PM2R_SCISSOR_MIN_XY, | |
1188 | ((image->dy & 0xfff) << 16) | (image->dx & 0x0fff)); | |
1189 | pm2_WR(par, PM2R_SCISSOR_MAX_XY, | |
1190 | (((image->dy + image->height) & 0x0fff) << 16) | | |
1191 | ((image->dx + image->width) & 0x0fff)); | |
1192 | pm2_WR(par, PM2R_SCISSOR_MODE, 1); | |
1193 | /* GXcopy & UNIT_ENABLE */ | |
45f169ec | 1194 | pm2_WR(par, PM2R_LOGICAL_OP_MODE, (0x3 << 1) | 1); |
91b3a6f4 KH |
1195 | pm2_WR(par, PM2R_RECTANGLE_ORIGIN, |
1196 | ((image->dy & 0xfff) << 16) | (image->dx & 0x0fff)); | |
1197 | pm2_WR(par, PM2R_RECTANGLE_SIZE, | |
1198 | ((image->height & 0x0fff) << 16) | | |
1199 | ((image->width) & 0x0fff)); | |
1200 | if (info->var.bits_per_pixel == 24) { | |
1201 | pm2_WR(par, PM2R_COLOR_DDA_MODE, 1); | |
1202 | /* clear area */ | |
1203 | pm2_WR(par, PM2R_CONSTANT_COLOR, bgx); | |
1204 | pm2_WR(par, PM2R_RENDER, | |
1205 | PM2F_RENDER_RECTANGLE | | |
45f169ec | 1206 | PM2F_INCREASE_X | PM2F_INCREASE_Y); |
91b3a6f4 KH |
1207 | /* BitMapPackEachScanline & invert bits and byte order*/ |
1208 | /* force background */ | |
45f169ec | 1209 | pm2_WR(par, PM2R_RASTERIZER_MODE, (1 << 9) | 1 | (3 << 7)); |
91b3a6f4 KH |
1210 | pm2_WR(par, PM2R_CONSTANT_COLOR, fgx); |
1211 | pm2_WR(par, PM2R_RENDER, | |
1212 | PM2F_RENDER_RECTANGLE | | |
1213 | PM2F_INCREASE_X | PM2F_INCREASE_Y | | |
1214 | PM2F_RENDER_SYNC_ON_BIT_MASK); | |
1215 | } else { | |
1216 | pm2_WR(par, PM2R_COLOR_DDA_MODE, 0); | |
1217 | /* clear area */ | |
1218 | pm2_WR(par, PM2R_FB_BLOCK_COLOR, bgx); | |
1219 | pm2_WR(par, PM2R_RENDER, | |
1220 | PM2F_RENDER_RECTANGLE | | |
1221 | PM2F_RENDER_FASTFILL | | |
45f169ec | 1222 | PM2F_INCREASE_X | PM2F_INCREASE_Y); |
91b3a6f4 | 1223 | /* invert bits and byte order*/ |
45f169ec | 1224 | pm2_WR(par, PM2R_RASTERIZER_MODE, 1 | (3 << 7)); |
91b3a6f4 KH |
1225 | pm2_WR(par, PM2R_FB_BLOCK_COLOR, fgx); |
1226 | pm2_WR(par, PM2R_RENDER, | |
1227 | PM2F_RENDER_RECTANGLE | | |
1228 | PM2F_INCREASE_X | PM2F_INCREASE_Y | | |
1229 | PM2F_RENDER_FASTFILL | | |
1230 | PM2F_RENDER_SYNC_ON_BIT_MASK); | |
1231 | } | |
1232 | ||
1233 | while (height--) { | |
1234 | int width = ((image->width + 7) >> 3) | |
1235 | + info->pixmap.scan_align - 1; | |
1236 | width >>= 2; | |
1237 | WAIT_FIFO(par, width); | |
1238 | while (width--) { | |
1239 | pm2_WR(par, PM2R_BIT_MASK_PATTERN, *src); | |
1240 | src++; | |
1241 | } | |
1242 | } | |
1243 | WAIT_FIFO(par, 3); | |
1244 | pm2_WR(par, PM2R_RASTERIZER_MODE, 0); | |
1245 | pm2_WR(par, PM2R_COLOR_DDA_MODE, 0); | |
1246 | pm2_WR(par, PM2R_SCISSOR_MODE, 0); | |
1247 | } | |
1248 | ||
8f5d050a KH |
1249 | /* |
1250 | * Hardware cursor support. | |
1251 | */ | |
1252 | static const u8 cursor_bits_lookup[16] = { | |
1253 | 0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54, | |
1254 | 0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55 | |
1255 | }; | |
1256 | ||
1257 | static int pm2vfb_cursor(struct fb_info *info, struct fb_cursor *cursor) | |
1258 | { | |
1259 | struct pm2fb_par *par = info->par; | |
2a36f9c4 | 1260 | u8 mode = PM2F_CURSORMODE_TYPE_X; |
8f5d050a | 1261 | |
8f5d050a KH |
1262 | if (cursor->enable) |
1263 | mode |= PM2F_CURSORMODE_CURSOR_ENABLE; | |
1264 | ||
1265 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_MODE, mode); | |
1266 | ||
1267 | /* | |
1268 | * If the cursor is not be changed this means either we want the | |
1269 | * current cursor state (if enable is set) or we want to query what | |
1270 | * we can do with the cursor (if enable is not set) | |
1271 | */ | |
1272 | if (!cursor->set) | |
1273 | return 0; | |
1274 | ||
1275 | if (cursor->set & FB_CUR_SETPOS) { | |
1276 | int x = cursor->image.dx - info->var.xoffset; | |
1277 | int y = cursor->image.dy - info->var.yoffset; | |
1278 | ||
1279 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_LOW, x & 0xff); | |
1280 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_HIGH, (x >> 8) & 0xf); | |
1281 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_LOW, y & 0xff); | |
1282 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_HIGH, (y >> 8) & 0xf); | |
1283 | } | |
1284 | ||
1285 | if (cursor->set & FB_CUR_SETHOT) { | |
1286 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_HOT, | |
1287 | cursor->hot.x & 0x3f); | |
1288 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_HOT, | |
1289 | cursor->hot.y & 0x3f); | |
1290 | } | |
1291 | ||
1292 | if (cursor->set & FB_CUR_SETCMAP) { | |
1293 | u32 fg_idx = cursor->image.fg_color; | |
1294 | u32 bg_idx = cursor->image.bg_color; | |
1295 | struct fb_cmap cmap = info->cmap; | |
1296 | ||
1297 | /* the X11 driver says one should use these color registers */ | |
1298 | pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CURSOR_PALETTE >> 8); | |
1299 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 0, | |
1300 | cmap.red[bg_idx] >> 8 ); | |
1301 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 1, | |
1302 | cmap.green[bg_idx] >> 8 ); | |
1303 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 2, | |
1304 | cmap.blue[bg_idx] >> 8 ); | |
1305 | ||
1306 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 3, | |
1307 | cmap.red[fg_idx] >> 8 ); | |
1308 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 4, | |
1309 | cmap.green[fg_idx] >> 8 ); | |
1310 | pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 5, | |
1311 | cmap.blue[fg_idx] >> 8 ); | |
1312 | pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0); | |
1313 | } | |
1314 | ||
1315 | if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) { | |
1316 | u8 *bitmap = (u8 *)cursor->image.data; | |
1317 | u8 *mask = (u8 *)cursor->mask; | |
1318 | int i; | |
1319 | int pos = PM2VI_RD_CURSOR_PATTERN; | |
1320 | ||
1321 | for (i = 0; i < cursor->image.height; i++) { | |
1322 | int j = (cursor->image.width + 7) >> 3; | |
1323 | int k = 8 - j; | |
1324 | ||
1325 | pm2_WR(par, PM2VR_RD_INDEX_HIGH, pos >> 8); | |
1326 | ||
1327 | for (; j > 0; j--) { | |
1328 | u8 data = *bitmap ^ *mask; | |
1329 | ||
1330 | if (cursor->rop == ROP_COPY) | |
1331 | data = *mask & *bitmap; | |
1332 | /* Upper 4 bits of bitmap data */ | |
1333 | pm2v_RDAC_WR(par, pos++, | |
1334 | cursor_bits_lookup[data >> 4] | | |
1335 | (cursor_bits_lookup[*mask >> 4] << 1)); | |
1336 | /* Lower 4 bits of bitmap */ | |
1337 | pm2v_RDAC_WR(par, pos++, | |
1338 | cursor_bits_lookup[data & 0xf] | | |
1339 | (cursor_bits_lookup[*mask & 0xf] << 1)); | |
1340 | bitmap++; | |
1341 | mask++; | |
1342 | } | |
1343 | for (; k > 0; k--) { | |
1344 | pm2v_RDAC_WR(par, pos++, 0); | |
1345 | pm2v_RDAC_WR(par, pos++, 0); | |
1346 | } | |
1347 | } | |
1348 | ||
1349 | while (pos < (1024 + PM2VI_RD_CURSOR_PATTERN)) { | |
1350 | pm2_WR(par, PM2VR_RD_INDEX_HIGH, pos >> 8); | |
1351 | pm2v_RDAC_WR(par, pos++, 0); | |
1352 | } | |
1353 | ||
1354 | pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0); | |
1355 | } | |
1356 | return 0; | |
1357 | } | |
1358 | ||
1359 | static int pm2fb_cursor(struct fb_info *info, struct fb_cursor *cursor) | |
1360 | { | |
1361 | struct pm2fb_par *par = info->par; | |
2a36f9c4 KH |
1362 | u8 mode; |
1363 | ||
1364 | if (!hwcursor) | |
1365 | return -EINVAL; /* just to force soft_cursor() call */ | |
1366 | ||
1367 | /* Too large of a cursor or wrong bpp :-( */ | |
1368 | if (cursor->image.width > 64 || | |
1369 | cursor->image.height > 64 || | |
1370 | cursor->image.depth > 1) | |
1371 | return -EINVAL; | |
8f5d050a KH |
1372 | |
1373 | if (par->type == PM2_TYPE_PERMEDIA2V) | |
1374 | return pm2vfb_cursor(info, cursor); | |
1375 | ||
2a36f9c4 KH |
1376 | mode = 0; |
1377 | if (cursor->enable) | |
1378 | mode = 0x43; | |
1379 | ||
1380 | pm2_RDAC_WR(par, PM2I_RD_CURSOR_CONTROL, mode); | |
1381 | ||
1382 | /* | |
1383 | * If the cursor is not be changed this means either we want the | |
1384 | * current cursor state (if enable is set) or we want to query what | |
1385 | * we can do with the cursor (if enable is not set) | |
1386 | */ | |
1387 | if (!cursor->set) | |
1388 | return 0; | |
1389 | ||
1390 | if (cursor->set & FB_CUR_SETPOS) { | |
1391 | int x, y; | |
1392 | ||
1393 | x = cursor->image.dx + 63; | |
1394 | y = cursor->image.dy + 63; | |
1395 | WAIT_FIFO(par, 4); | |
1396 | pm2_WR(par, PM2R_RD_CURSOR_X_LSB, x & 0xff); | |
1397 | pm2_WR(par, PM2R_RD_CURSOR_X_MSB, (x >> 8) & 0x7); | |
1398 | pm2_WR(par, PM2R_RD_CURSOR_Y_LSB, y & 0xff); | |
1399 | pm2_WR(par, PM2R_RD_CURSOR_Y_MSB, (y >> 8) & 0x7); | |
1400 | } | |
1401 | ||
1402 | if (cursor->set & FB_CUR_SETCMAP) { | |
1403 | u32 fg_idx = cursor->image.fg_color; | |
1404 | u32 bg_idx = cursor->image.bg_color; | |
1405 | ||
1406 | WAIT_FIFO(par, 7); | |
1407 | pm2_WR(par, PM2R_RD_CURSOR_COLOR_ADDRESS, 1); | |
1408 | pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA, | |
1409 | info->cmap.red[bg_idx] >> 8); | |
1410 | pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA, | |
1411 | info->cmap.green[bg_idx] >> 8); | |
1412 | pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA, | |
1413 | info->cmap.blue[bg_idx] >> 8); | |
1414 | ||
1415 | pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA, | |
1416 | info->cmap.red[fg_idx] >> 8); | |
1417 | pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA, | |
1418 | info->cmap.green[fg_idx] >> 8); | |
1419 | pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA, | |
1420 | info->cmap.blue[fg_idx] >> 8); | |
1421 | } | |
1422 | ||
1423 | if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) { | |
1424 | u8 *bitmap = (u8 *)cursor->image.data; | |
1425 | u8 *mask = (u8 *)cursor->mask; | |
1426 | int i; | |
1427 | ||
1428 | WAIT_FIFO(par, 1); | |
1429 | pm2_WR(par, PM2R_RD_PALETTE_WRITE_ADDRESS, 0); | |
1430 | ||
1431 | for (i = 0; i < cursor->image.height; i++) { | |
1432 | int j = (cursor->image.width + 7) >> 3; | |
1433 | int k = 8 - j; | |
1434 | ||
1435 | WAIT_FIFO(par, 8); | |
1436 | for (; j > 0; j--) { | |
1437 | u8 data = *bitmap ^ *mask; | |
1438 | ||
1439 | if (cursor->rop == ROP_COPY) | |
1440 | data = *mask & *bitmap; | |
1441 | /* bitmap data */ | |
1442 | pm2_WR(par, PM2R_RD_CURSOR_DATA, data); | |
1443 | bitmap++; | |
1444 | mask++; | |
1445 | } | |
1446 | for (; k > 0; k--) | |
1447 | pm2_WR(par, PM2R_RD_CURSOR_DATA, 0); | |
1448 | } | |
1449 | for (; i < 64; i++) { | |
1450 | int j = 8; | |
1451 | WAIT_FIFO(par, 8); | |
1452 | while (j-- > 0) | |
1453 | pm2_WR(par, PM2R_RD_CURSOR_DATA, 0); | |
1454 | } | |
1455 | ||
1456 | mask = (u8 *)cursor->mask; | |
1457 | for (i = 0; i < cursor->image.height; i++) { | |
1458 | int j = (cursor->image.width + 7) >> 3; | |
1459 | int k = 8 - j; | |
1460 | ||
1461 | WAIT_FIFO(par, 8); | |
1462 | for (; j > 0; j--) { | |
1463 | /* mask */ | |
1464 | pm2_WR(par, PM2R_RD_CURSOR_DATA, *mask); | |
1465 | mask++; | |
1466 | } | |
1467 | for (; k > 0; k--) | |
1468 | pm2_WR(par, PM2R_RD_CURSOR_DATA, 0); | |
1469 | } | |
1470 | for (; i < 64; i++) { | |
1471 | int j = 8; | |
1472 | WAIT_FIFO(par, 8); | |
1473 | while (j-- > 0) | |
1474 | pm2_WR(par, PM2R_RD_CURSOR_DATA, 0); | |
1475 | } | |
1476 | } | |
1477 | return 0; | |
8f5d050a KH |
1478 | } |
1479 | ||
1da177e4 LT |
1480 | /* ------------ Hardware Independent Functions ------------ */ |
1481 | ||
1482 | /* | |
1483 | * Frame buffer operations | |
1484 | */ | |
1485 | ||
1486 | static struct fb_ops pm2fb_ops = { | |
1487 | .owner = THIS_MODULE, | |
1488 | .fb_check_var = pm2fb_check_var, | |
1489 | .fb_set_par = pm2fb_set_par, | |
1490 | .fb_setcolreg = pm2fb_setcolreg, | |
1491 | .fb_blank = pm2fb_blank, | |
1492 | .fb_pan_display = pm2fb_pan_display, | |
87a7cc68 KH |
1493 | .fb_fillrect = pm2fb_fillrect, |
1494 | .fb_copyarea = pm2fb_copyarea, | |
91b3a6f4 | 1495 | .fb_imageblit = pm2fb_imageblit, |
03b9ae4b | 1496 | .fb_sync = pm2fb_sync, |
8f5d050a | 1497 | .fb_cursor = pm2fb_cursor, |
1da177e4 LT |
1498 | }; |
1499 | ||
1500 | /* | |
1501 | * PCI stuff | |
1502 | */ | |
1503 | ||
1504 | ||
1505 | /** | |
1506 | * Device initialisation | |
1507 | * | |
1508 | * Initialise and allocate resource for PCI device. | |
1509 | * | |
1510 | * @param pdev PCI device. | |
1511 | * @param id PCI device ID. | |
1512 | */ | |
1513 | static int __devinit pm2fb_probe(struct pci_dev *pdev, | |
1514 | const struct pci_device_id *id) | |
1515 | { | |
1516 | struct pm2fb_par *default_par; | |
1517 | struct fb_info *info; | |
3843faa2 KH |
1518 | int err; |
1519 | int retval = -ENXIO; | |
1da177e4 LT |
1520 | |
1521 | err = pci_enable_device(pdev); | |
45f169ec | 1522 | if (err) { |
1da177e4 LT |
1523 | printk(KERN_WARNING "pm2fb: Can't enable pdev: %d\n", err); |
1524 | return err; | |
1525 | } | |
1526 | ||
6772a2ee | 1527 | info = framebuffer_alloc(sizeof(struct pm2fb_par), &pdev->dev); |
45f169ec | 1528 | if (!info) |
1da177e4 | 1529 | return -ENOMEM; |
6772a2ee | 1530 | default_par = info->par; |
1da177e4 LT |
1531 | |
1532 | switch (pdev->device) { | |
1533 | case PCI_DEVICE_ID_TI_TVP4020: | |
1534 | strcpy(pm2fb_fix.id, "TVP4020"); | |
1535 | default_par->type = PM2_TYPE_PERMEDIA2; | |
1536 | break; | |
1537 | case PCI_DEVICE_ID_3DLABS_PERMEDIA2: | |
1538 | strcpy(pm2fb_fix.id, "Permedia2"); | |
1539 | default_par->type = PM2_TYPE_PERMEDIA2; | |
1540 | break; | |
1541 | case PCI_DEVICE_ID_3DLABS_PERMEDIA2V: | |
1542 | strcpy(pm2fb_fix.id, "Permedia2v"); | |
1543 | default_par->type = PM2_TYPE_PERMEDIA2V; | |
1544 | break; | |
1545 | } | |
1546 | ||
1547 | pm2fb_fix.mmio_start = pci_resource_start(pdev, 0); | |
1548 | pm2fb_fix.mmio_len = PM2_REGS_SIZE; | |
1549 | ||
1550 | #if defined(__BIG_ENDIAN) | |
1551 | /* | |
1552 | * PM2 has a 64k register file, mapped twice in 128k. Lower | |
1553 | * map is little-endian, upper map is big-endian. | |
1554 | */ | |
1555 | pm2fb_fix.mmio_start += PM2_REGS_SIZE; | |
1556 | DPRINTK("Adjusting register base for big-endian.\n"); | |
1557 | #endif | |
1558 | DPRINTK("Register base at 0x%lx\n", pm2fb_fix.mmio_start); | |
2f7bb99f | 1559 | |
1da177e4 | 1560 | /* Registers - request region and map it. */ |
45f169ec KH |
1561 | if (!request_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len, |
1562 | "pm2fb regbase")) { | |
1da177e4 LT |
1563 | printk(KERN_WARNING "pm2fb: Can't reserve regbase.\n"); |
1564 | goto err_exit_neither; | |
1565 | } | |
1566 | default_par->v_regs = | |
1567 | ioremap_nocache(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len); | |
45f169ec | 1568 | if (!default_par->v_regs) { |
1da177e4 LT |
1569 | printk(KERN_WARNING "pm2fb: Can't remap %s register area.\n", |
1570 | pm2fb_fix.id); | |
1571 | release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len); | |
1572 | goto err_exit_neither; | |
1573 | } | |
1574 | ||
1575 | /* Stash away memory register info for use when we reset the board */ | |
1576 | default_par->mem_control = pm2_RD(default_par, PM2R_MEM_CONTROL); | |
1577 | default_par->boot_address = pm2_RD(default_par, PM2R_BOOT_ADDRESS); | |
1578 | default_par->mem_config = pm2_RD(default_par, PM2R_MEM_CONFIG); | |
1579 | DPRINTK("MemControl 0x%x BootAddress 0x%x MemConfig 0x%x\n", | |
1580 | default_par->mem_control, default_par->boot_address, | |
1581 | default_par->mem_config); | |
1582 | ||
45f169ec | 1583 | if (default_par->mem_control == 0 && |
9127fa28 | 1584 | default_par->boot_address == 0x31 && |
f1c15f93 | 1585 | default_par->mem_config == 0x259fffff) { |
9a31f0f7 | 1586 | default_par->memclock = CVPPC_MEMCLOCK; |
45f169ec KH |
1587 | default_par->mem_control = 0; |
1588 | default_par->boot_address = 0x20; | |
1589 | default_par->mem_config = 0xe6002021; | |
f1c15f93 KH |
1590 | if (pdev->subsystem_vendor == 0x1048 && |
1591 | pdev->subsystem_device == 0x0a31) { | |
3843faa2 KH |
1592 | DPRINTK("subsystem_vendor: %04x, " |
1593 | "subsystem_device: %04x\n", | |
f1c15f93 | 1594 | pdev->subsystem_vendor, pdev->subsystem_device); |
3843faa2 KH |
1595 | DPRINTK("We have not been initialized by VGA BIOS and " |
1596 | "are running on an Elsa Winner 2000 Office\n"); | |
f1c15f93 | 1597 | DPRINTK("Initializing card timings manually...\n"); |
138a451c | 1598 | default_par->memclock = 100000; |
f1c15f93 KH |
1599 | } |
1600 | if (pdev->subsystem_vendor == 0x3d3d && | |
1601 | pdev->subsystem_device == 0x0100) { | |
3843faa2 KH |
1602 | DPRINTK("subsystem_vendor: %04x, " |
1603 | "subsystem_device: %04x\n", | |
f1c15f93 | 1604 | pdev->subsystem_vendor, pdev->subsystem_device); |
3843faa2 KH |
1605 | DPRINTK("We have not been initialized by VGA BIOS and " |
1606 | "are running on an 3dlabs reference board\n"); | |
f1c15f93 | 1607 | DPRINTK("Initializing card timings manually...\n"); |
45f169ec | 1608 | default_par->memclock = 74894; |
f1c15f93 | 1609 | } |
9127fa28 PDS |
1610 | } |
1611 | ||
1da177e4 | 1612 | /* Now work out how big lfb is going to be. */ |
3843faa2 | 1613 | switch (default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) { |
1da177e4 | 1614 | case PM2F_MEM_BANKS_1: |
45f169ec | 1615 | pm2fb_fix.smem_len = 0x200000; |
1da177e4 LT |
1616 | break; |
1617 | case PM2F_MEM_BANKS_2: | |
45f169ec | 1618 | pm2fb_fix.smem_len = 0x400000; |
1da177e4 LT |
1619 | break; |
1620 | case PM2F_MEM_BANKS_3: | |
45f169ec | 1621 | pm2fb_fix.smem_len = 0x600000; |
1da177e4 LT |
1622 | break; |
1623 | case PM2F_MEM_BANKS_4: | |
45f169ec | 1624 | pm2fb_fix.smem_len = 0x800000; |
1da177e4 LT |
1625 | break; |
1626 | } | |
1da177e4 | 1627 | pm2fb_fix.smem_start = pci_resource_start(pdev, 1); |
1da177e4 LT |
1628 | |
1629 | /* Linear frame buffer - request region and map it. */ | |
45f169ec KH |
1630 | if (!request_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len, |
1631 | "pm2fb smem")) { | |
1da177e4 LT |
1632 | printk(KERN_WARNING "pm2fb: Can't reserve smem.\n"); |
1633 | goto err_exit_mmio; | |
1634 | } | |
4560daaf | 1635 | info->screen_base = |
1da177e4 | 1636 | ioremap_nocache(pm2fb_fix.smem_start, pm2fb_fix.smem_len); |
45f169ec | 1637 | if (!info->screen_base) { |
1da177e4 LT |
1638 | printk(KERN_WARNING "pm2fb: Can't ioremap smem area.\n"); |
1639 | release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len); | |
1640 | goto err_exit_mmio; | |
1641 | } | |
1642 | ||
d5383fcc KH |
1643 | #ifdef CONFIG_MTRR |
1644 | default_par->mtrr_handle = -1; | |
1645 | if (!nomtrr) | |
1646 | default_par->mtrr_handle = | |
1647 | mtrr_add(pm2fb_fix.smem_start, | |
1648 | pm2fb_fix.smem_len, | |
1649 | MTRR_TYPE_WRCOMB, 1); | |
1650 | #endif | |
1651 | ||
1da177e4 | 1652 | info->fbops = &pm2fb_ops; |
2f7bb99f | 1653 | info->fix = pm2fb_fix; |
6772a2ee | 1654 | info->pseudo_palette = default_par->palette; |
1da177e4 | 1655 | info->flags = FBINFO_DEFAULT | |
2f7bb99f KH |
1656 | FBINFO_HWACCEL_YPAN | |
1657 | FBINFO_HWACCEL_COPYAREA | | |
91b3a6f4 | 1658 | FBINFO_HWACCEL_IMAGEBLIT | |
2f7bb99f | 1659 | FBINFO_HWACCEL_FILLRECT; |
1da177e4 | 1660 | |
91b3a6f4 KH |
1661 | info->pixmap.addr = kmalloc(PM2_PIXMAP_SIZE, GFP_KERNEL); |
1662 | if (!info->pixmap.addr) { | |
3843faa2 | 1663 | retval = -ENOMEM; |
91b3a6f4 KH |
1664 | goto err_exit_pixmap; |
1665 | } | |
1666 | info->pixmap.size = PM2_PIXMAP_SIZE; | |
1667 | info->pixmap.buf_align = 4; | |
1668 | info->pixmap.scan_align = 4; | |
1669 | info->pixmap.access_align = 32; | |
1670 | info->pixmap.flags = FB_PIXMAP_SYSTEM; | |
1671 | ||
d5383fcc | 1672 | if (noaccel) { |
91b3a6f4 KH |
1673 | printk(KERN_DEBUG "disabling acceleration\n"); |
1674 | info->flags |= FBINFO_HWACCEL_DISABLED; | |
1675 | info->pixmap.scan_align = 1; | |
d5383fcc KH |
1676 | } |
1677 | ||
1da177e4 LT |
1678 | if (!mode) |
1679 | mode = "640x480@60"; | |
2f7bb99f KH |
1680 | |
1681 | err = fb_find_mode(&info->var, info, mode, NULL, 0, NULL, 8); | |
1da177e4 LT |
1682 | if (!err || err == 4) |
1683 | info->var = pm2fb_var; | |
1684 | ||
1685 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) | |
435d56fc | 1686 | goto err_exit_both; |
1da177e4 LT |
1687 | |
1688 | if (register_framebuffer(info) < 0) | |
435d56fc | 1689 | goto err_exit_all; |
1da177e4 LT |
1690 | |
1691 | printk(KERN_INFO "fb%d: %s frame buffer device, memory = %dK.\n", | |
4560daaf | 1692 | info->node, info->fix.id, pm2fb_fix.smem_len / 1024); |
1da177e4 LT |
1693 | |
1694 | /* | |
1695 | * Our driver data | |
1696 | */ | |
1697 | pci_set_drvdata(pdev, info); | |
1698 | ||
1699 | return 0; | |
1700 | ||
1701 | err_exit_all: | |
2f7bb99f KH |
1702 | fb_dealloc_cmap(&info->cmap); |
1703 | err_exit_both: | |
91b3a6f4 KH |
1704 | kfree(info->pixmap.addr); |
1705 | err_exit_pixmap: | |
1da177e4 LT |
1706 | iounmap(info->screen_base); |
1707 | release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len); | |
1708 | err_exit_mmio: | |
1709 | iounmap(default_par->v_regs); | |
1710 | release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len); | |
1711 | err_exit_neither: | |
1712 | framebuffer_release(info); | |
3843faa2 | 1713 | return retval; |
1da177e4 LT |
1714 | } |
1715 | ||
1716 | /** | |
1717 | * Device removal. | |
1718 | * | |
1719 | * Release all device resources. | |
1720 | * | |
1721 | * @param pdev PCI device to clean up. | |
1722 | */ | |
1723 | static void __devexit pm2fb_remove(struct pci_dev *pdev) | |
1724 | { | |
3843faa2 KH |
1725 | struct fb_info *info = pci_get_drvdata(pdev); |
1726 | struct fb_fix_screeninfo *fix = &info->fix; | |
1da177e4 LT |
1727 | struct pm2fb_par *par = info->par; |
1728 | ||
1729 | unregister_framebuffer(info); | |
2f7bb99f | 1730 | |
d5383fcc KH |
1731 | #ifdef CONFIG_MTRR |
1732 | if (par->mtrr_handle >= 0) | |
1733 | mtrr_del(par->mtrr_handle, info->fix.smem_start, | |
1734 | info->fix.smem_len); | |
1735 | #endif /* CONFIG_MTRR */ | |
1da177e4 LT |
1736 | iounmap(info->screen_base); |
1737 | release_mem_region(fix->smem_start, fix->smem_len); | |
1738 | iounmap(par->v_regs); | |
1739 | release_mem_region(fix->mmio_start, fix->mmio_len); | |
1740 | ||
1741 | pci_set_drvdata(pdev, NULL); | |
3843faa2 | 1742 | kfree(info->pixmap.addr); |
1da177e4 LT |
1743 | kfree(info); |
1744 | } | |
1745 | ||
1746 | static struct pci_device_id pm2fb_id_table[] = { | |
1747 | { PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TVP4020, | |
138a451c | 1748 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
1da177e4 | 1749 | { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2, |
138a451c | 1750 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
f1c15f93 | 1751 | { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V, |
138a451c | 1752 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
1da177e4 LT |
1753 | { 0, } |
1754 | }; | |
1755 | ||
1756 | static struct pci_driver pm2fb_driver = { | |
1757 | .name = "pm2fb", | |
2f7bb99f KH |
1758 | .id_table = pm2fb_id_table, |
1759 | .probe = pm2fb_probe, | |
1760 | .remove = __devexit_p(pm2fb_remove), | |
1da177e4 LT |
1761 | }; |
1762 | ||
1763 | MODULE_DEVICE_TABLE(pci, pm2fb_id_table); | |
1764 | ||
1765 | ||
1766 | #ifndef MODULE | |
1767 | /** | |
1768 | * Parse user speficied options. | |
1769 | * | |
1770 | * This is, comma-separated options following `video=pm2fb:'. | |
1771 | */ | |
1772 | static int __init pm2fb_setup(char *options) | |
1773 | { | |
3843faa2 | 1774 | char *this_opt; |
1da177e4 LT |
1775 | |
1776 | if (!options || !*options) | |
1777 | return 0; | |
1778 | ||
2f7bb99f | 1779 | while ((this_opt = strsep(&options, ",")) != NULL) { |
1da177e4 LT |
1780 | if (!*this_opt) |
1781 | continue; | |
3843faa2 | 1782 | if (!strcmp(this_opt, "lowhsync")) |
1da177e4 | 1783 | lowhsync = 1; |
3843faa2 | 1784 | else if (!strcmp(this_opt, "lowvsync")) |
1da177e4 | 1785 | lowvsync = 1; |
8f5d050a KH |
1786 | else if (!strncmp(this_opt, "hwcursor=", 9)) |
1787 | hwcursor = simple_strtoul(this_opt + 9, NULL, 0); | |
d5383fcc | 1788 | #ifdef CONFIG_MTRR |
3843faa2 | 1789 | else if (!strncmp(this_opt, "nomtrr", 6)) |
d5383fcc KH |
1790 | nomtrr = 1; |
1791 | #endif | |
3843faa2 | 1792 | else if (!strncmp(this_opt, "noaccel", 7)) |
d5383fcc | 1793 | noaccel = 1; |
3843faa2 | 1794 | else |
1da177e4 | 1795 | mode = this_opt; |
1da177e4 LT |
1796 | } |
1797 | return 0; | |
1798 | } | |
1799 | #endif | |
1800 | ||
1801 | ||
1802 | static int __init pm2fb_init(void) | |
1803 | { | |
1804 | #ifndef MODULE | |
1805 | char *option = NULL; | |
1806 | ||
1807 | if (fb_get_options("pm2fb", &option)) | |
1808 | return -ENODEV; | |
1809 | pm2fb_setup(option); | |
1810 | #endif | |
1811 | ||
1812 | return pci_register_driver(&pm2fb_driver); | |
1813 | } | |
1814 | ||
1815 | module_init(pm2fb_init); | |
1816 | ||
1817 | #ifdef MODULE | |
1818 | /* | |
1819 | * Cleanup | |
1820 | */ | |
1821 | ||
1822 | static void __exit pm2fb_exit(void) | |
1823 | { | |
1824 | pci_unregister_driver(&pm2fb_driver); | |
1825 | } | |
1826 | #endif | |
1827 | ||
1828 | #ifdef MODULE | |
1829 | module_exit(pm2fb_exit); | |
1830 | ||
1831 | module_param(mode, charp, 0); | |
1832 | MODULE_PARM_DESC(mode, "Preferred video mode e.g. '648x480-8@60'"); | |
1833 | module_param(lowhsync, bool, 0); | |
1834 | MODULE_PARM_DESC(lowhsync, "Force horizontal sync low regardless of mode"); | |
1835 | module_param(lowvsync, bool, 0); | |
1836 | MODULE_PARM_DESC(lowvsync, "Force vertical sync low regardless of mode"); | |
d5383fcc KH |
1837 | module_param(noaccel, bool, 0); |
1838 | MODULE_PARM_DESC(noaccel, "Disable acceleration"); | |
8f5d050a KH |
1839 | module_param(hwcursor, int, 0644); |
1840 | MODULE_PARM_DESC(hwcursor, "Enable hardware cursor " | |
1841 | "(1=enable, 0=disable, default=0)"); | |
d5383fcc KH |
1842 | #ifdef CONFIG_MTRR |
1843 | module_param(nomtrr, bool, 0); | |
1844 | MODULE_PARM_DESC(nomtrr, "Disable MTRR support (0 or 1=disabled) (default=0)"); | |
1845 | #endif | |
1da177e4 LT |
1846 | |
1847 | MODULE_AUTHOR("Jim Hague <jim.hague@acm.org>"); | |
1848 | MODULE_DESCRIPTION("Permedia2 framebuffer device driver"); | |
1849 | MODULE_LICENSE("GPL"); | |
1850 | #endif |