blob: aa8d28880912dc571cdfe7763a8edd2223a28065 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Krzysztof Helt45f169e2007-10-16 01:28:34 -070014 * I have a Creative Graphics Blaster Exxtreme card - pm2fb on x86. I
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * 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 *
Krzysztof Helt2f7bb992007-07-17 04:05:31 -070027 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 */
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/slab.h>
37#include <linux/delay.h>
38#include <linux/fb.h>
39#include <linux/init.h>
40#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <video/permedia2.h>
42#include <video/cvisionppc.h>
43
44#if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
45#error "The endianness of the target host has not been defined."
46#endif
47
48#if !defined(CONFIG_PCI)
49#error "Only generic PCI cards supported."
50#endif
51
52#undef PM2FB_MASTER_DEBUG
53#ifdef PM2FB_MASTER_DEBUG
Krzysztof Helt3843faa2007-10-16 01:28:50 -070054#define DPRINTK(a, b...) \
Harvey Harrison5ae12172008-04-28 02:15:47 -070055 printk(KERN_DEBUG "pm2fb: %s: " a, __func__ , ## b)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#else
Krzysztof Helt3843faa2007-10-16 01:28:50 -070057#define DPRINTK(a, b...)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#endif
59
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -070060#define PM2_PIXMAP_SIZE (1600 * 4)
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*
Krzysztof Helt2f7bb992007-07-17 04:05:31 -070063 * Driver data
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 */
Krzysztof Helt1ddc28d2007-10-16 01:29:16 -070065static int hwcursor = 1;
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -080066static char *mode_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/*
69 * The XFree GLINT driver will (I think to implement hardware cursor
70 * support on TVP4010 and similar where there is no RAMDAC - see
71 * comment in set_video) always request +ve sync regardless of what
72 * the mode requires. This screws me because I have a Sun
73 * fixed-frequency monitor which absolutely has to have -ve sync. So
74 * these flags allow the user to specify that requests for +ve sync
75 * should be silently turned in -ve sync.
76 */
Rusty Russell90ab5ee2012-01-13 09:32:20 +103077static bool lowhsync;
78static bool lowvsync;
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -080079static bool noaccel;
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -080080static bool nomtrr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/*
83 * The hardware state of the graphics card that isn't part of the
84 * screeninfo.
85 */
86struct pm2fb_par
87{
88 pm2type_t type; /* Board type */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 unsigned char __iomem *v_regs;/* virtual address of p_regs */
Krzysztof Helt2f7bb992007-07-17 04:05:31 -070090 u32 memclock; /* memclock */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 u32 video; /* video flags before blanking */
92 u32 mem_config; /* MemConfig reg at probe */
93 u32 mem_control; /* MemControl reg at probe */
94 u32 boot_address; /* BootAddress reg at probe */
Krzysztof Helt2f7bb992007-07-17 04:05:31 -070095 u32 palette[16];
Luis R. Rodriguezf8f05cd2015-04-21 13:16:33 -070096 int wc_cookie;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
99/*
100 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
101 * if we don't use modedb.
102 */
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800103static struct fb_fix_screeninfo pm2fb_fix = {
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700104 .id = "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 .type = FB_TYPE_PACKED_PIXELS,
106 .visual = FB_VISUAL_PSEUDOCOLOR,
107 .xpanstep = 1,
108 .ypanstep = 1,
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700109 .ywrapstep = 0,
Krzysztof Helt87a7cc62007-05-08 00:40:02 -0700110 .accel = FB_ACCEL_3DLABS_PERMEDIA2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
113/*
114 * Default video mode. In case the modedb doesn't work.
115 */
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800116static struct fb_var_screeninfo pm2fb_var = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 /* "640x480, 8 bpp @ 60 Hz */
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700118 .xres = 640,
119 .yres = 480,
120 .xres_virtual = 640,
121 .yres_virtual = 480,
122 .bits_per_pixel = 8,
123 .red = {0, 8, 0},
124 .blue = {0, 8, 0},
125 .green = {0, 8, 0},
126 .activate = FB_ACTIVATE_NOW,
127 .height = -1,
128 .width = -1,
129 .accel_flags = 0,
130 .pixclock = 39721,
131 .left_margin = 40,
132 .right_margin = 24,
133 .upper_margin = 32,
134 .lower_margin = 11,
135 .hsync_len = 96,
136 .vsync_len = 2,
137 .vmode = FB_VMODE_NONINTERLACED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138};
139
140/*
141 * Utility functions
142 */
143
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700144static inline u32 pm2_RD(struct pm2fb_par *p, s32 off)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700146 return fb_readl(p->v_regs + off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700149static inline void pm2_WR(struct pm2fb_par *p, s32 off, u32 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700151 fb_writel(v, p->v_regs + off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700154static inline u32 pm2_RDAC_RD(struct pm2fb_par *p, s32 idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700156 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 mb();
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700158 return pm2_RD(p, PM2R_RD_INDEXED_DATA);
159}
160
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700161static inline u32 pm2v_RDAC_RD(struct pm2fb_par *p, s32 idx)
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700162{
163 pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
164 mb();
165 return pm2_RD(p, PM2VR_RD_INDEXED_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}
167
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700168static inline void pm2_RDAC_WR(struct pm2fb_par *p, s32 idx, u32 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700170 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx);
Krzysztof Helt11d1a622007-05-23 13:57:47 -0700171 wmb();
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700172 pm2_WR(p, PM2R_RD_INDEXED_DATA, v);
Krzysztof Helt11d1a622007-05-23 13:57:47 -0700173 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700176static inline void pm2v_RDAC_WR(struct pm2fb_par *p, s32 idx, u32 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
178 pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
Krzysztof Helt11d1a622007-05-23 13:57:47 -0700179 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 pm2_WR(p, PM2VR_RD_INDEXED_DATA, v);
Krzysztof Helt11d1a622007-05-23 13:57:47 -0700181 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
183
184#ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700185#define WAIT_FIFO(p, a)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186#else
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700187static inline void WAIT_FIFO(struct pm2fb_par *p, u32 a)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
Krzysztof Helt6416ad72007-10-16 01:29:27 -0700189 while (pm2_RD(p, PM2R_IN_FIFO_SPACE) < a)
190 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
192#endif
193
194/*
195 * partial products for the supported horizontal resolutions.
196 */
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700197#define PACKPP(p0, p1, p2) (((p2) << 6) | ((p1) << 3) | (p0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198static const struct {
199 u16 width;
200 u16 pp;
201} pp_table[] = {
202 { 32, PACKPP(1, 0, 0) }, { 64, PACKPP(1, 1, 0) },
203 { 96, PACKPP(1, 1, 1) }, { 128, PACKPP(2, 1, 1) },
204 { 160, PACKPP(2, 2, 1) }, { 192, PACKPP(2, 2, 2) },
205 { 224, PACKPP(3, 2, 1) }, { 256, PACKPP(3, 2, 2) },
206 { 288, PACKPP(3, 3, 1) }, { 320, PACKPP(3, 3, 2) },
207 { 384, PACKPP(3, 3, 3) }, { 416, PACKPP(4, 3, 1) },
208 { 448, PACKPP(4, 3, 2) }, { 512, PACKPP(4, 3, 3) },
209 { 544, PACKPP(4, 4, 1) }, { 576, PACKPP(4, 4, 2) },
210 { 640, PACKPP(4, 4, 3) }, { 768, PACKPP(4, 4, 4) },
211 { 800, PACKPP(5, 4, 1) }, { 832, PACKPP(5, 4, 2) },
212 { 896, PACKPP(5, 4, 3) }, { 1024, PACKPP(5, 4, 4) },
213 { 1056, PACKPP(5, 5, 1) }, { 1088, PACKPP(5, 5, 2) },
214 { 1152, PACKPP(5, 5, 3) }, { 1280, PACKPP(5, 5, 4) },
215 { 1536, PACKPP(5, 5, 5) }, { 1568, PACKPP(6, 5, 1) },
216 { 1600, PACKPP(6, 5, 2) }, { 1664, PACKPP(6, 5, 3) },
217 { 1792, PACKPP(6, 5, 4) }, { 2048, PACKPP(6, 5, 5) },
218 { 0, 0 } };
219
220static u32 partprod(u32 xres)
221{
222 int i;
223
224 for (i = 0; pp_table[i].width && pp_table[i].width != xres; i++)
225 ;
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700226 if (pp_table[i].width == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 DPRINTK("invalid width %u\n", xres);
228 return pp_table[i].pp;
229}
230
231static u32 to3264(u32 timing, int bpp, int is64)
232{
233 switch (bpp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 case 24:
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700235 timing *= 3;
236 case 8:
237 timing >>= 1;
238 case 16:
239 timing >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 case 32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 break;
242 }
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700243 if (is64)
244 timing >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 return timing;
246}
247
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700248static void pm2_mnp(u32 clk, unsigned char *mm, unsigned char *nn,
249 unsigned char *pp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
251 unsigned char m;
252 unsigned char n;
253 unsigned char p;
254 u32 f;
255 s32 curr;
256 s32 delta = 100000;
257
258 *mm = *nn = *pp = 0;
259 for (n = 2; n < 15; n++) {
260 for (m = 2; m; m++) {
261 f = PM2_REFERENCE_CLOCK * m / n;
262 if (f >= 150000 && f <= 300000) {
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700263 for (p = 0; p < 5; p++, f >>= 1) {
264 curr = (clk > f) ? clk - f : f - clk;
265 if (curr < delta) {
266 delta = curr;
267 *mm = m;
268 *nn = n;
269 *pp = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271 }
272 }
273 }
274 }
275}
276
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700277static void pm2v_mnp(u32 clk, unsigned char *mm, unsigned char *nn,
278 unsigned char *pp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
280 unsigned char m;
281 unsigned char n;
282 unsigned char p;
283 u32 f;
284 s32 delta = 1000;
285
286 *mm = *nn = *pp = 0;
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700287 for (m = 1; m < 128; m++) {
Krzysztof Heltd4a96b52007-05-08 00:39:33 -0700288 for (n = 2 * m + 1; n; n++) {
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700289 for (p = 0; p < 2; p++) {
290 f = (PM2_REFERENCE_CLOCK >> (p + 1)) * n / m;
291 if (clk > f - delta && clk < f + delta) {
292 delta = (clk > f) ? clk - f : f - clk;
293 *mm = m;
294 *nn = n;
295 *pp = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 }
297 }
298 }
299 }
300}
301
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700302static void clear_palette(struct pm2fb_par *p)
303{
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700304 int i = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 WAIT_FIFO(p, 1);
307 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, 0);
308 wmb();
309 while (i--) {
310 WAIT_FIFO(p, 3);
311 pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
312 pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
313 pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
314 }
315}
316
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700317static void reset_card(struct pm2fb_par *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
319 if (p->type == PM2_TYPE_PERMEDIA2V)
320 pm2_WR(p, PM2VR_RD_INDEX_HIGH, 0);
321 pm2_WR(p, PM2R_RESET_STATUS, 0);
322 mb();
323 while (pm2_RD(p, PM2R_RESET_STATUS) & PM2F_BEING_RESET)
Krzysztof Helt6416ad72007-10-16 01:29:27 -0700324 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 mb();
326#ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
327 DPRINTK("FIFO disconnect enabled\n");
328 pm2_WR(p, PM2R_FIFO_DISCON, 1);
329 mb();
330#endif
331
332 /* Restore stashed memory config information from probe */
333 WAIT_FIFO(p, 3);
334 pm2_WR(p, PM2R_MEM_CONTROL, p->mem_control);
335 pm2_WR(p, PM2R_BOOT_ADDRESS, p->boot_address);
336 wmb();
337 pm2_WR(p, PM2R_MEM_CONFIG, p->mem_config);
338}
339
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700340static void reset_config(struct pm2fb_par *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Krzysztof Helt138a4512007-10-16 01:28:36 -0700342 WAIT_FIFO(p, 53);
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700343 pm2_WR(p, PM2R_CHIP_CONFIG, pm2_RD(p, PM2R_CHIP_CONFIG) &
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700344 ~(PM2F_VGA_ENABLE | PM2F_VGA_FIXED));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 pm2_WR(p, PM2R_BYPASS_WRITE_MASK, ~(0L));
346 pm2_WR(p, PM2R_FRAMEBUFFER_WRITE_MASK, ~(0L));
347 pm2_WR(p, PM2R_FIFO_CONTROL, 0);
348 pm2_WR(p, PM2R_APERTURE_ONE, 0);
349 pm2_WR(p, PM2R_APERTURE_TWO, 0);
350 pm2_WR(p, PM2R_RASTERIZER_MODE, 0);
351 pm2_WR(p, PM2R_DELTA_MODE, PM2F_DELTA_ORDER_RGB);
352 pm2_WR(p, PM2R_LB_READ_FORMAT, 0);
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700353 pm2_WR(p, PM2R_LB_WRITE_FORMAT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 pm2_WR(p, PM2R_LB_READ_MODE, 0);
355 pm2_WR(p, PM2R_LB_SOURCE_OFFSET, 0);
356 pm2_WR(p, PM2R_FB_SOURCE_OFFSET, 0);
357 pm2_WR(p, PM2R_FB_PIXEL_OFFSET, 0);
358 pm2_WR(p, PM2R_FB_WINDOW_BASE, 0);
359 pm2_WR(p, PM2R_LB_WINDOW_BASE, 0);
360 pm2_WR(p, PM2R_FB_SOFT_WRITE_MASK, ~(0L));
361 pm2_WR(p, PM2R_FB_HARD_WRITE_MASK, ~(0L));
362 pm2_WR(p, PM2R_FB_READ_PIXEL, 0);
363 pm2_WR(p, PM2R_DITHER_MODE, 0);
364 pm2_WR(p, PM2R_AREA_STIPPLE_MODE, 0);
365 pm2_WR(p, PM2R_DEPTH_MODE, 0);
366 pm2_WR(p, PM2R_STENCIL_MODE, 0);
367 pm2_WR(p, PM2R_TEXTURE_ADDRESS_MODE, 0);
368 pm2_WR(p, PM2R_TEXTURE_READ_MODE, 0);
369 pm2_WR(p, PM2R_TEXEL_LUT_MODE, 0);
370 pm2_WR(p, PM2R_YUV_MODE, 0);
371 pm2_WR(p, PM2R_COLOR_DDA_MODE, 0);
372 pm2_WR(p, PM2R_TEXTURE_COLOR_MODE, 0);
373 pm2_WR(p, PM2R_FOG_MODE, 0);
374 pm2_WR(p, PM2R_ALPHA_BLEND_MODE, 0);
375 pm2_WR(p, PM2R_LOGICAL_OP_MODE, 0);
376 pm2_WR(p, PM2R_STATISTICS_MODE, 0);
377 pm2_WR(p, PM2R_SCISSOR_MODE, 0);
378 pm2_WR(p, PM2R_FILTER_MODE, PM2F_SYNCHRONIZATION);
Krzysztof Helt138a4512007-10-16 01:28:36 -0700379 pm2_WR(p, PM2R_RD_PIXEL_MASK, 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 switch (p->type) {
381 case PM2_TYPE_PERMEDIA2:
382 pm2_RDAC_WR(p, PM2I_RD_MODE_CONTROL, 0); /* no overlay */
383 pm2_RDAC_WR(p, PM2I_RD_CURSOR_CONTROL, 0);
384 pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, PM2F_RD_PALETTE_WIDTH_8);
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700385 pm2_RDAC_WR(p, PM2I_RD_COLOR_KEY_CONTROL, 0);
386 pm2_RDAC_WR(p, PM2I_RD_OVERLAY_KEY, 0);
387 pm2_RDAC_WR(p, PM2I_RD_RED_KEY, 0);
388 pm2_RDAC_WR(p, PM2I_RD_GREEN_KEY, 0);
389 pm2_RDAC_WR(p, PM2I_RD_BLUE_KEY, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 break;
391 case PM2_TYPE_PERMEDIA2V:
392 pm2v_RDAC_WR(p, PM2VI_RD_MISC_CONTROL, 1); /* 8bit */
393 break;
394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395}
396
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700397static void set_aperture(struct pm2fb_par *p, u32 depth)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
399 /*
400 * The hardware is little-endian. When used in big-endian
401 * hosts, the on-chip aperture settings are used where
402 * possible to translate from host to card byte order.
403 */
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700404 WAIT_FIFO(p, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#ifdef __LITTLE_ENDIAN
406 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD);
407#else
408 switch (depth) {
409 case 24: /* RGB->BGR */
410 /*
411 * We can't use the aperture to translate host to
412 * card byte order here, so we switch to BGR mode
413 * in pm2fb_set_par().
414 */
415 case 8: /* B->B */
416 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD);
417 break;
418 case 16: /* HL->LH */
419 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_HALFWORDSWAP);
420 break;
421 case 32: /* RGBA->ABGR */
422 pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_BYTESWAP);
423 break;
424 }
425#endif
426
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700427 /* We don't use aperture two, so this may be superflous */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 pm2_WR(p, PM2R_APERTURE_TWO, PM2F_APERTURE_STANDARD);
429}
430
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700431static void set_color(struct pm2fb_par *p, unsigned char regno,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 unsigned char r, unsigned char g, unsigned char b)
433{
434 WAIT_FIFO(p, 4);
435 pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, regno);
436 wmb();
437 pm2_WR(p, PM2R_RD_PALETTE_DATA, r);
438 wmb();
439 pm2_WR(p, PM2R_RD_PALETTE_DATA, g);
440 wmb();
441 pm2_WR(p, PM2R_RD_PALETTE_DATA, b);
442}
443
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700444static void set_memclock(struct pm2fb_par *par, u32 clk)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
446 int i;
447 unsigned char m, n, p;
448
Krzysztof Helte5d809d2007-05-08 00:39:32 -0700449 switch (par->type) {
450 case PM2_TYPE_PERMEDIA2V:
451 pm2v_mnp(clk/2, &m, &n, &p);
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700452 WAIT_FIFO(par, 12);
Krzysztof Helte5d809d2007-05-08 00:39:32 -0700453 pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_MCLK_CONTROL >> 8);
454 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 0);
Krzysztof Helte5d809d2007-05-08 00:39:32 -0700455 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_PRESCALE, m);
456 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_FEEDBACK, n);
457 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_POSTSCALE, p);
Krzysztof Helte5d809d2007-05-08 00:39:32 -0700458 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 1);
459 rmb();
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700460 for (i = 256; i; i--)
461 if (pm2v_RDAC_RD(par, PM2VI_RD_MCLK_CONTROL) & 2)
462 break;
Krzysztof Helte5d809d2007-05-08 00:39:32 -0700463 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
464 break;
465 case PM2_TYPE_PERMEDIA2:
466 pm2_mnp(clk, &m, &n, &p);
467 WAIT_FIFO(par, 10);
468 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 6);
Krzysztof Helte5d809d2007-05-08 00:39:32 -0700469 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_1, m);
470 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_2, n);
Krzysztof Helte5d809d2007-05-08 00:39:32 -0700471 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 8|p);
Krzysztof Helte5d809d2007-05-08 00:39:32 -0700472 pm2_RDAC_RD(par, PM2I_RD_MEMORY_CLOCK_STATUS);
473 rmb();
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700474 for (i = 256; i; i--)
475 if (pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED)
476 break;
Krzysztof Helte5d809d2007-05-08 00:39:32 -0700477 break;
478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700481static void set_pixclock(struct pm2fb_par *par, u32 clk)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
483 int i;
484 unsigned char m, n, p;
485
486 switch (par->type) {
487 case PM2_TYPE_PERMEDIA2:
488 pm2_mnp(clk, &m, &n, &p);
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700489 WAIT_FIFO(par, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A1, m);
492 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A2, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 8|p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 pm2_RDAC_RD(par, PM2I_RD_PIXEL_CLOCK_STATUS);
495 rmb();
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700496 for (i = 256; i; i--)
497 if (pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED)
498 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 break;
500 case PM2_TYPE_PERMEDIA2V:
501 pm2v_mnp(clk/2, &m, &n, &p);
502 WAIT_FIFO(par, 8);
503 pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CLK0_PRESCALE >> 8);
504 pm2v_RDAC_WR(par, PM2VI_RD_CLK0_PRESCALE, m);
505 pm2v_RDAC_WR(par, PM2VI_RD_CLK0_FEEDBACK, n);
506 pm2v_RDAC_WR(par, PM2VI_RD_CLK0_POSTSCALE, p);
507 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
508 break;
509 }
510}
511
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700512static void set_video(struct pm2fb_par *p, u32 video)
513{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 u32 tmp;
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700515 u32 vsync = video;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 DPRINTK("video = 0x%x\n", video);
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 /*
520 * The hardware cursor needs +vsync to recognise vert retrace.
521 * We may not be using the hardware cursor, but the X Glint
522 * driver may well. So always set +hsync/+vsync and then set
523 * the RAMDAC to invert the sync if necessary.
524 */
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700525 vsync &= ~(PM2F_HSYNC_MASK | PM2F_VSYNC_MASK);
526 vsync |= PM2F_HSYNC_ACT_HIGH | PM2F_VSYNC_ACT_HIGH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Krzysztof Helt138a4512007-10-16 01:28:36 -0700528 WAIT_FIFO(p, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 pm2_WR(p, PM2R_VIDEO_CONTROL, vsync);
530
531 switch (p->type) {
532 case PM2_TYPE_PERMEDIA2:
533 tmp = PM2F_RD_PALETTE_WIDTH_8;
534 if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW)
535 tmp |= 4; /* invert hsync */
536 if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW)
537 tmp |= 8; /* invert vsync */
538 pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, tmp);
539 break;
540 case PM2_TYPE_PERMEDIA2V:
541 tmp = 0;
542 if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW)
543 tmp |= 1; /* invert hsync */
544 if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW)
545 tmp |= 4; /* invert vsync */
546 pm2v_RDAC_WR(p, PM2VI_RD_SYNC_CONTROL, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 break;
548 }
549}
550
551/*
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700552 * pm2fb_check_var - Optional function. Validates a var passed in.
553 * @var: frame buffer variable screen structure
554 * @info: frame buffer structure that represents a single frame buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 *
556 * Checks to see if the hardware supports the state requested by
557 * var passed in.
558 *
559 * Returns negative errno on error, or zero on success.
560 */
561static int pm2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
562{
563 u32 lpitch;
564
565 if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 &&
566 var->bits_per_pixel != 24 && var->bits_per_pixel != 32) {
567 DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
568 return -EINVAL;
569 }
570
571 if (var->xres != var->xres_virtual) {
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700572 DPRINTK("virtual x resolution != "
573 "physical x resolution not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 return -EINVAL;
575 }
576
577 if (var->yres > var->yres_virtual) {
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700578 DPRINTK("virtual y resolution < "
579 "physical y resolution not possible\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 return -EINVAL;
581 }
582
Krzysztof Helt1ddc28d2007-10-16 01:29:16 -0700583 /* permedia cannot blit over 2048 */
584 if (var->yres_virtual > 2047) {
585 var->yres_virtual = 2047;
586 }
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 if (var->xoffset) {
589 DPRINTK("xoffset not supported\n");
590 return -EINVAL;
591 }
592
593 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
594 DPRINTK("interlace not supported\n");
595 return -EINVAL;
596 }
597
598 var->xres = (var->xres + 15) & ~15; /* could sometimes be 8 */
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700599 lpitch = var->xres * ((var->bits_per_pixel + 7) >> 3);
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 if (var->xres < 320 || var->xres > 1600) {
602 DPRINTK("width not supported: %u\n", var->xres);
603 return -EINVAL;
604 }
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 if (var->yres < 200 || var->yres > 1200) {
607 DPRINTK("height not supported: %u\n", var->yres);
608 return -EINVAL;
609 }
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 if (lpitch * var->yres_virtual > info->fix.smem_len) {
612 DPRINTK("no memory for screen (%ux%ux%u)\n",
613 var->xres, var->yres_virtual, var->bits_per_pixel);
614 return -EINVAL;
615 }
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 if (PICOS2KHZ(var->pixclock) > PM2_MAX_PIXCLOCK) {
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700618 DPRINTK("pixclock too high (%ldKHz)\n",
619 PICOS2KHZ(var->pixclock));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 return -EINVAL;
621 }
622
krzysztof.h1@wp.pl76c7d3f2007-05-08 00:39:56 -0700623 var->transp.offset = 0;
624 var->transp.length = 0;
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700625 switch (var->bits_per_pixel) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 case 8:
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700627 var->red.length = 8;
628 var->green.length = 8;
629 var->blue.length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 break;
631 case 16:
632 var->red.offset = 11;
633 var->red.length = 5;
634 var->green.offset = 5;
635 var->green.length = 6;
636 var->blue.offset = 0;
637 var->blue.length = 5;
638 break;
639 case 32:
640 var->transp.offset = 24;
641 var->transp.length = 8;
642 var->red.offset = 16;
643 var->green.offset = 8;
644 var->blue.offset = 0;
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700645 var->red.length = 8;
646 var->green.length = 8;
647 var->blue.length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 break;
649 case 24:
650#ifdef __BIG_ENDIAN
651 var->red.offset = 0;
652 var->blue.offset = 16;
653#else
654 var->red.offset = 16;
655 var->blue.offset = 0;
656#endif
657 var->green.offset = 8;
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700658 var->red.length = 8;
659 var->green.length = 8;
660 var->blue.length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 break;
662 }
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700663 var->height = -1;
664 var->width = -1;
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 var->accel_flags = 0; /* Can't mmap if this is on */
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
669 var->xres, var->yres, var->bits_per_pixel);
670 return 0;
671}
672
673/**
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700674 * pm2fb_set_par - Alters the hardware state.
675 * @info: frame buffer structure that represents a single frame buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 *
677 * Using the fb_var_screeninfo in fb_info we set the resolution of the
678 * this particular framebuffer.
679 */
680static int pm2fb_set_par(struct fb_info *info)
681{
Antonino A. Daplas6772a2e2006-01-09 20:53:10 -0800682 struct pm2fb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 u32 pixclock;
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700684 u32 width = (info->var.xres_virtual + 7) & ~7;
685 u32 height = info->var.yres_virtual;
686 u32 depth = (info->var.bits_per_pixel + 7) & ~7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 u32 hsstart, hsend, hbend, htotal;
688 u32 vsstart, vsend, vbend, vtotal;
689 u32 stride;
690 u32 base;
691 u32 video = 0;
692 u32 clrmode = PM2F_RD_COLOR_MODE_RGB | PM2F_RD_GUI_ACTIVE;
693 u32 txtmap = 0;
694 u32 pixsize = 0;
695 u32 clrformat = 0;
Krzysztof Helt138a4512007-10-16 01:28:36 -0700696 u32 misc = 1; /* 8-bit DAC */
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700697 u32 xres = (info->var.xres + 31) & ~31;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 int data64;
699
700 reset_card(par);
701 reset_config(par);
702 clear_palette(par);
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700703 if (par->memclock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 set_memclock(par, par->memclock);
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700705
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 depth = (depth > 32) ? 32 : depth;
707 data64 = depth > 8 || par->type == PM2_TYPE_PERMEDIA2V;
708
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 pixclock = PICOS2KHZ(info->var.pixclock);
710 if (pixclock > PM2_MAX_PIXCLOCK) {
711 DPRINTK("pixclock too high (%uKHz)\n", pixclock);
712 return -EINVAL;
713 }
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 hsstart = to3264(info->var.right_margin, depth, data64);
716 hsend = hsstart + to3264(info->var.hsync_len, depth, data64);
717 hbend = hsend + to3264(info->var.left_margin, depth, data64);
718 htotal = to3264(xres, depth, data64) + hbend - 1;
719 vsstart = (info->var.lower_margin)
720 ? info->var.lower_margin - 1
721 : 0; /* FIXME! */
722 vsend = info->var.lower_margin + info->var.vsync_len - 1;
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700723 vbend = info->var.lower_margin + info->var.vsync_len +
724 info->var.upper_margin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 vtotal = info->var.yres + vbend - 1;
726 stride = to3264(width, depth, 1);
727 base = to3264(info->var.yoffset * xres + info->var.xoffset, depth, 1);
728 if (data64)
729 video |= PM2F_DATA_64_ENABLE;
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) {
732 if (lowhsync) {
733 DPRINTK("ignoring +hsync, using -hsync.\n");
734 video |= PM2F_HSYNC_ACT_LOW;
735 } else
736 video |= PM2F_HSYNC_ACT_HIGH;
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700737 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 video |= PM2F_HSYNC_ACT_LOW;
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) {
741 if (lowvsync) {
742 DPRINTK("ignoring +vsync, using -vsync.\n");
743 video |= PM2F_VSYNC_ACT_LOW;
744 } else
745 video |= PM2F_VSYNC_ACT_HIGH;
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700746 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 video |= PM2F_VSYNC_ACT_LOW;
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700748
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700749 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 DPRINTK("interlaced not supported\n");
751 return -EINVAL;
752 }
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700753 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 video |= PM2F_LINE_DOUBLE;
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700755 if ((info->var.activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 video |= PM2F_VIDEO_ENABLE;
757 par->video = video;
758
759 info->fix.visual =
760 (depth == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
761 info->fix.line_length = info->var.xres * depth / 8;
762 info->cmap.len = 256;
763
764 /*
765 * Settings calculated. Now write them out.
766 */
767 if (par->type == PM2_TYPE_PERMEDIA2V) {
768 WAIT_FIFO(par, 1);
769 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
770 }
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 set_aperture(par, depth);
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 mb();
775 WAIT_FIFO(par, 19);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 switch (depth) {
777 case 8:
778 pm2_WR(par, PM2R_FB_READ_PIXEL, 0);
Krzysztof Helt138a4512007-10-16 01:28:36 -0700779 clrformat = 0x2e;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 break;
781 case 16:
782 pm2_WR(par, PM2R_FB_READ_PIXEL, 1);
783 clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB565;
784 txtmap = PM2F_TEXTEL_SIZE_16;
785 pixsize = 1;
786 clrformat = 0x70;
Krzysztof Helt138a4512007-10-16 01:28:36 -0700787 misc |= 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 break;
789 case 32:
790 pm2_WR(par, PM2R_FB_READ_PIXEL, 2);
791 clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGBA8888;
792 txtmap = PM2F_TEXTEL_SIZE_32;
793 pixsize = 2;
794 clrformat = 0x20;
Krzysztof Helt138a4512007-10-16 01:28:36 -0700795 misc |= 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 break;
797 case 24:
798 pm2_WR(par, PM2R_FB_READ_PIXEL, 4);
799 clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB888;
800 txtmap = PM2F_TEXTEL_SIZE_24;
801 pixsize = 4;
802 clrformat = 0x20;
Krzysztof Helt138a4512007-10-16 01:28:36 -0700803 misc |= 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 break;
805 }
806 pm2_WR(par, PM2R_FB_WRITE_MODE, PM2F_FB_WRITE_ENABLE);
807 pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres));
808 pm2_WR(par, PM2R_LB_READ_MODE, partprod(xres));
809 pm2_WR(par, PM2R_TEXTURE_MAP_FORMAT, txtmap | partprod(xres));
810 pm2_WR(par, PM2R_H_TOTAL, htotal);
811 pm2_WR(par, PM2R_HS_START, hsstart);
812 pm2_WR(par, PM2R_HS_END, hsend);
813 pm2_WR(par, PM2R_HG_END, hbend);
814 pm2_WR(par, PM2R_HB_END, hbend);
815 pm2_WR(par, PM2R_V_TOTAL, vtotal);
816 pm2_WR(par, PM2R_VS_START, vsstart);
817 pm2_WR(par, PM2R_VS_END, vsend);
818 pm2_WR(par, PM2R_VB_END, vbend);
819 pm2_WR(par, PM2R_SCREEN_STRIDE, stride);
820 wmb();
821 pm2_WR(par, PM2R_WINDOW_ORIGIN, 0);
822 pm2_WR(par, PM2R_SCREEN_SIZE, (height << 16) | width);
823 pm2_WR(par, PM2R_SCISSOR_MODE, PM2F_SCREEN_SCISSOR_ENABLE);
824 wmb();
825 pm2_WR(par, PM2R_SCREEN_BASE, base);
826 wmb();
827 set_video(par, video);
Krzysztof Helt138a4512007-10-16 01:28:36 -0700828 WAIT_FIFO(par, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 switch (par->type) {
830 case PM2_TYPE_PERMEDIA2:
831 pm2_RDAC_WR(par, PM2I_RD_COLOR_MODE, clrmode);
Krzysztof Helt45f169e2007-10-16 01:28:34 -0700832 pm2_RDAC_WR(par, PM2I_RD_COLOR_KEY_CONTROL,
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700833 (depth == 8) ? 0 : PM2F_COLOR_KEY_TEST_OFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 break;
835 case PM2_TYPE_PERMEDIA2V:
Krzysztof Helt138a4512007-10-16 01:28:36 -0700836 pm2v_RDAC_WR(par, PM2VI_RD_DAC_CONTROL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 pm2v_RDAC_WR(par, PM2VI_RD_PIXEL_SIZE, pixsize);
838 pm2v_RDAC_WR(par, PM2VI_RD_COLOR_FORMAT, clrformat);
Krzysztof Helt138a4512007-10-16 01:28:36 -0700839 pm2v_RDAC_WR(par, PM2VI_RD_MISC_CONTROL, misc);
840 pm2v_RDAC_WR(par, PM2VI_RD_OVERLAY_KEY, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 break;
842 }
843 set_pixclock(par, pixclock);
844 DPRINTK("Setting graphics mode at %dx%d depth %d\n",
845 info->var.xres, info->var.yres, info->var.bits_per_pixel);
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700846 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
849/**
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700850 * pm2fb_setcolreg - Sets a color register.
851 * @regno: boolean, 0 copy local, 1 get_user() function
852 * @red: frame buffer colormap structure
853 * @green: The green value which can be up to 16 bits wide
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 * @blue: The blue value which can be up to 16 bits wide.
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700855 * @transp: If supported the alpha value which can be up to 16 bits wide.
856 * @info: frame buffer info structure
857 *
858 * Set a single color register. The values supplied have a 16 bit
859 * magnitude which needs to be scaled in this function for the hardware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 * Pretty much a direct lift from tdfxfb.c.
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700861 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 * Returns negative errno on error, or zero on success.
863 */
864static int pm2fb_setcolreg(unsigned regno, unsigned red, unsigned green,
865 unsigned blue, unsigned transp,
866 struct fb_info *info)
867{
Antonino A. Daplas6772a2e2006-01-09 20:53:10 -0800868 struct pm2fb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870 if (regno >= info->cmap.len) /* no. of hw registers */
Krzysztof Helt138a4512007-10-16 01:28:36 -0700871 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 /*
873 * Program hardware... do anything you want with transp
874 */
875
876 /* grayscale works only partially under directcolor */
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700877 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
878 if (info->var.grayscale)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881 /* Directcolor:
882 * var->{color}.offset contains start of bitfield
883 * var->{color}.length contains length of bitfield
884 * {hardwarespecific} contains width of DAC
885 * cmap[X] is programmed to
886 * (X << red.offset) | (X << green.offset) | (X << blue.offset)
887 * RAMDAC[X] is programmed to (red, green, blue)
888 *
889 * Pseudocolor:
890 * uses offset = 0 && length = DAC register width.
891 * var->{color}.offset is 0
Daniel Mack551e3782010-01-28 16:11:51 +0800892 * var->{color}.length contains width of DAC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 * cmap is not used
894 * DAC[X] is programmed to (red, green, blue)
895 * Truecolor:
896 * does not use RAMDAC (usually has 3 of them).
897 * var->{color}.offset contains start of bitfield
898 * var->{color}.length contains length of bitfield
899 * cmap is programmed to
900 * (red << red.offset) | (green << green.offset) |
901 * (blue << blue.offset) | (transp << transp.offset)
902 * RAMDAC does not exist
903 */
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700904#define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF -(val)) >> 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 switch (info->fix.visual) {
906 case FB_VISUAL_TRUECOLOR:
907 case FB_VISUAL_PSEUDOCOLOR:
908 red = CNVT_TOHW(red, info->var.red.length);
909 green = CNVT_TOHW(green, info->var.green.length);
910 blue = CNVT_TOHW(blue, info->var.blue.length);
911 transp = CNVT_TOHW(transp, info->var.transp.length);
912 break;
913 case FB_VISUAL_DIRECTCOLOR:
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700914 /* example here assumes 8 bit DAC. Might be different
915 * for your hardware */
916 red = CNVT_TOHW(red, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 green = CNVT_TOHW(green, 8);
918 blue = CNVT_TOHW(blue, 8);
919 /* hey, there is bug in transp handling... */
920 transp = CNVT_TOHW(transp, 8);
921 break;
922 }
923#undef CNVT_TOHW
924 /* Truecolor has hardware independent palette */
925 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
926 u32 v;
927
928 if (regno >= 16)
Krzysztof Helt138a4512007-10-16 01:28:36 -0700929 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931 v = (red << info->var.red.offset) |
932 (green << info->var.green.offset) |
933 (blue << info->var.blue.offset) |
934 (transp << info->var.transp.offset);
935
936 switch (info->var.bits_per_pixel) {
937 case 8:
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700938 break;
939 case 16:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 case 24:
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700941 case 32:
942 par->palette[regno] = v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 break;
944 }
945 return 0;
Krzysztof Helt3843faa2007-10-16 01:28:50 -0700946 } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 set_color(par, regno, red, green, blue);
948
949 return 0;
950}
951
952/**
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700953 * pm2fb_pan_display - Pans the display.
954 * @var: frame buffer variable screen structure
955 * @info: frame buffer structure that represents a single frame buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 *
957 * Pan (or wrap, depending on the `vmode' field) the display using the
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700958 * `xoffset' and `yoffset' fields of the `var' structure.
959 * If the values don't fit, return -EINVAL.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 *
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700961 * Returns negative errno on error, or zero on success.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 *
963 */
964static int pm2fb_pan_display(struct fb_var_screeninfo *var,
965 struct fb_info *info)
966{
Antonino A. Daplas6772a2e2006-01-09 20:53:10 -0800967 struct pm2fb_par *p = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 u32 base;
Laurent Pinchartdf9306d2011-06-14 09:24:55 +0000969 u32 depth = (info->var.bits_per_pixel + 7) & ~7;
970 u32 xres = (info->var.xres + 31) & ~31;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 depth = (depth > 32) ? 32 : depth;
973 base = to3264(var->yoffset * xres + var->xoffset, depth, 1);
974 WAIT_FIFO(p, 1);
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700975 pm2_WR(p, PM2R_SCREEN_BASE, base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 return 0;
977}
978
979/**
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700980 * pm2fb_blank - Blanks the display.
981 * @blank_mode: the blank mode we want.
982 * @info: frame buffer structure that represents a single frame buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 *
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700984 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
985 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
986 * video mode which doesn't support it. Implements VESA suspend
987 * and powerdown modes on hardware that supports disabling hsync/vsync:
988 * blank_mode == 2: suspend vsync
989 * blank_mode == 3: suspend hsync
990 * blank_mode == 4: powerdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 *
Krzysztof Helt2f7bb992007-07-17 04:05:31 -0700992 * Returns negative errno on error, or zero on success.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 *
994 */
995static int pm2fb_blank(int blank_mode, struct fb_info *info)
996{
Antonino A. Daplas6772a2e2006-01-09 20:53:10 -0800997 struct pm2fb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 u32 video = par->video;
999
1000 DPRINTK("blank_mode %d\n", blank_mode);
1001
1002 switch (blank_mode) {
1003 case FB_BLANK_UNBLANK:
1004 /* Screen: On */
1005 video |= PM2F_VIDEO_ENABLE;
1006 break;
1007 case FB_BLANK_NORMAL:
1008 /* Screen: Off */
1009 video &= ~PM2F_VIDEO_ENABLE;
1010 break;
1011 case FB_BLANK_VSYNC_SUSPEND:
1012 /* VSync: Off */
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001013 video &= ~(PM2F_VSYNC_MASK | PM2F_BLANK_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 break;
1015 case FB_BLANK_HSYNC_SUSPEND:
1016 /* HSync: Off */
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001017 video &= ~(PM2F_HSYNC_MASK | PM2F_BLANK_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 break;
1019 case FB_BLANK_POWERDOWN:
1020 /* HSync: Off, VSync: Off */
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001021 video &= ~(PM2F_VSYNC_MASK | PM2F_HSYNC_MASK | PM2F_BLANK_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 break;
1023 }
1024 set_video(par, video);
1025 return 0;
1026}
1027
Antonino A. Daplas03b9ae42007-05-10 22:23:29 -07001028static int pm2fb_sync(struct fb_info *info)
1029{
1030 struct pm2fb_par *par = info->par;
1031
1032 WAIT_FIFO(par, 1);
1033 pm2_WR(par, PM2R_SYNC, 0);
1034 mb();
1035 do {
1036 while (pm2_RD(par, PM2R_OUT_FIFO_WORDS) == 0)
Krzysztof Helt6416ad72007-10-16 01:29:27 -07001037 cpu_relax();
Antonino A. Daplas03b9ae42007-05-10 22:23:29 -07001038 } while (pm2_RD(par, PM2R_OUT_FIFO) != PM2TAG(PM2R_SYNC));
1039
1040 return 0;
1041}
1042
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001043static void pm2fb_fillrect(struct fb_info *info,
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001044 const struct fb_fillrect *region)
1045{
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001046 struct pm2fb_par *par = info->par;
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001047 struct fb_fillrect modded;
1048 int vxres, vyres;
1049 u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001050 ((u32 *)info->pseudo_palette)[region->color] : region->color;
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001051
1052 if (info->state != FBINFO_STATE_RUNNING)
1053 return;
1054 if ((info->flags & FBINFO_HWACCEL_DISABLED) ||
1055 region->rop != ROP_COPY ) {
1056 cfb_fillrect(info, region);
1057 return;
1058 }
1059
1060 vxres = info->var.xres_virtual;
1061 vyres = info->var.yres_virtual;
1062
1063 memcpy(&modded, region, sizeof(struct fb_fillrect));
1064
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001065 if (!modded.width || !modded.height ||
1066 modded.dx >= vxres || modded.dy >= vyres)
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001067 return;
1068
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001069 if (modded.dx + modded.width > vxres)
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001070 modded.width = vxres - modded.dx;
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001071 if (modded.dy + modded.height > vyres)
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001072 modded.height = vyres - modded.dy;
1073
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001074 if (info->var.bits_per_pixel == 8)
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001075 color |= color << 8;
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001076 if (info->var.bits_per_pixel <= 16)
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001077 color |= color << 16;
1078
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001079 WAIT_FIFO(par, 3);
1080 pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE);
1081 pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (modded.dy << 16) | modded.dx);
1082 pm2_WR(par, PM2R_RECTANGLE_SIZE, (modded.height << 16) | modded.width);
1083 if (info->var.bits_per_pixel != 24) {
1084 WAIT_FIFO(par, 2);
1085 pm2_WR(par, PM2R_FB_BLOCK_COLOR, color);
1086 wmb();
1087 pm2_WR(par, PM2R_RENDER,
1088 PM2F_RENDER_RECTANGLE | PM2F_RENDER_FASTFILL);
1089 } else {
Krzysztof Helt30dcc902007-10-16 01:28:36 -07001090 WAIT_FIFO(par, 4);
1091 pm2_WR(par, PM2R_COLOR_DDA_MODE, 1);
1092 pm2_WR(par, PM2R_CONSTANT_COLOR, color);
1093 wmb();
1094 pm2_WR(par, PM2R_RENDER,
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001095 PM2F_RENDER_RECTANGLE |
1096 PM2F_INCREASE_X | PM2F_INCREASE_Y );
Krzysztof Helt30dcc902007-10-16 01:28:36 -07001097 pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001098 }
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001099}
1100
1101static void pm2fb_copyarea(struct fb_info *info,
1102 const struct fb_copyarea *area)
1103{
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001104 struct pm2fb_par *par = info->par;
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001105 struct fb_copyarea modded;
1106 u32 vxres, vyres;
1107
1108 if (info->state != FBINFO_STATE_RUNNING)
1109 return;
1110 if (info->flags & FBINFO_HWACCEL_DISABLED) {
1111 cfb_copyarea(info, area);
1112 return;
1113 }
1114
1115 memcpy(&modded, area, sizeof(struct fb_copyarea));
1116
1117 vxres = info->var.xres_virtual;
1118 vyres = info->var.yres_virtual;
1119
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001120 if (!modded.width || !modded.height ||
1121 modded.sx >= vxres || modded.sy >= vyres ||
1122 modded.dx >= vxres || modded.dy >= vyres)
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001123 return;
1124
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001125 if (modded.sx + modded.width > vxres)
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001126 modded.width = vxres - modded.sx;
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001127 if (modded.dx + modded.width > vxres)
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001128 modded.width = vxres - modded.dx;
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001129 if (modded.sy + modded.height > vyres)
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001130 modded.height = vyres - modded.sy;
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001131 if (modded.dy + modded.height > vyres)
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001132 modded.height = vyres - modded.dy;
1133
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001134 WAIT_FIFO(par, 5);
1135 pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE |
1136 PM2F_CONFIG_FB_READ_SOURCE_ENABLE);
1137 pm2_WR(par, PM2R_FB_SOURCE_DELTA,
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001138 ((modded.sy - modded.dy) & 0xfff) << 16 |
1139 ((modded.sx - modded.dx) & 0xfff));
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001140 pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (modded.dy << 16) | modded.dx);
1141 pm2_WR(par, PM2R_RECTANGLE_SIZE, (modded.height << 16) | modded.width);
1142 wmb();
1143 pm2_WR(par, PM2R_RENDER, PM2F_RENDER_RECTANGLE |
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001144 (modded.dx < modded.sx ? PM2F_INCREASE_X : 0) |
1145 (modded.dy < modded.sy ? PM2F_INCREASE_Y : 0));
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001146}
1147
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001148static void pm2fb_imageblit(struct fb_info *info, const struct fb_image *image)
1149{
1150 struct pm2fb_par *par = info->par;
1151 u32 height = image->height;
1152 u32 fgx, bgx;
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001153 const u32 *src = (const u32 *)image->data;
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001154 u32 xres = (info->var.xres + 31) & ~31;
Krzysztof Heltbc9c6a12008-02-06 01:39:37 -08001155 int raster_mode = 1; /* invert bits */
1156
1157#ifdef __LITTLE_ENDIAN
1158 raster_mode |= 3 << 7; /* reverse byte order */
1159#endif
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001160
1161 if (info->state != FBINFO_STATE_RUNNING)
1162 return;
1163 if (info->flags & FBINFO_HWACCEL_DISABLED || image->depth != 1) {
1164 cfb_imageblit(info, image);
1165 return;
1166 }
1167 switch (info->fix.visual) {
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001168 case FB_VISUAL_PSEUDOCOLOR:
1169 fgx = image->fg_color;
1170 bgx = image->bg_color;
1171 break;
1172 case FB_VISUAL_TRUECOLOR:
1173 default:
1174 fgx = par->palette[image->fg_color];
1175 bgx = par->palette[image->bg_color];
1176 break;
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001177 }
1178 if (info->var.bits_per_pixel == 8) {
1179 fgx |= fgx << 8;
1180 bgx |= bgx << 8;
1181 }
1182 if (info->var.bits_per_pixel <= 16) {
1183 fgx |= fgx << 16;
1184 bgx |= bgx << 16;
1185 }
1186
1187 WAIT_FIFO(par, 13);
1188 pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres));
1189 pm2_WR(par, PM2R_SCISSOR_MIN_XY,
1190 ((image->dy & 0xfff) << 16) | (image->dx & 0x0fff));
1191 pm2_WR(par, PM2R_SCISSOR_MAX_XY,
1192 (((image->dy + image->height) & 0x0fff) << 16) |
1193 ((image->dx + image->width) & 0x0fff));
1194 pm2_WR(par, PM2R_SCISSOR_MODE, 1);
1195 /* GXcopy & UNIT_ENABLE */
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001196 pm2_WR(par, PM2R_LOGICAL_OP_MODE, (0x3 << 1) | 1);
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001197 pm2_WR(par, PM2R_RECTANGLE_ORIGIN,
1198 ((image->dy & 0xfff) << 16) | (image->dx & 0x0fff));
1199 pm2_WR(par, PM2R_RECTANGLE_SIZE,
1200 ((image->height & 0x0fff) << 16) |
1201 ((image->width) & 0x0fff));
1202 if (info->var.bits_per_pixel == 24) {
1203 pm2_WR(par, PM2R_COLOR_DDA_MODE, 1);
1204 /* clear area */
1205 pm2_WR(par, PM2R_CONSTANT_COLOR, bgx);
1206 pm2_WR(par, PM2R_RENDER,
1207 PM2F_RENDER_RECTANGLE |
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001208 PM2F_INCREASE_X | PM2F_INCREASE_Y);
Krzysztof Heltbc9c6a12008-02-06 01:39:37 -08001209 /* BitMapPackEachScanline */
1210 pm2_WR(par, PM2R_RASTERIZER_MODE, raster_mode | (1 << 9));
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001211 pm2_WR(par, PM2R_CONSTANT_COLOR, fgx);
1212 pm2_WR(par, PM2R_RENDER,
1213 PM2F_RENDER_RECTANGLE |
1214 PM2F_INCREASE_X | PM2F_INCREASE_Y |
1215 PM2F_RENDER_SYNC_ON_BIT_MASK);
1216 } else {
1217 pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);
1218 /* clear area */
1219 pm2_WR(par, PM2R_FB_BLOCK_COLOR, bgx);
1220 pm2_WR(par, PM2R_RENDER,
1221 PM2F_RENDER_RECTANGLE |
1222 PM2F_RENDER_FASTFILL |
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001223 PM2F_INCREASE_X | PM2F_INCREASE_Y);
Krzysztof Heltbc9c6a12008-02-06 01:39:37 -08001224 pm2_WR(par, PM2R_RASTERIZER_MODE, raster_mode);
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001225 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
Krzysztof Helt8f5d0502007-10-16 01:28:53 -07001249/*
1250 * Hardware cursor support.
1251 */
1252static 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
1257static int pm2vfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1258{
1259 struct pm2fb_par *par = info->par;
Krzysztof Helt2a36f9c2007-10-16 01:29:16 -07001260 u8 mode = PM2F_CURSORMODE_TYPE_X;
Krzysztof Helt1ddc28d2007-10-16 01:29:16 -07001261 int x = cursor->image.dx - info->var.xoffset;
1262 int y = cursor->image.dy - info->var.yoffset;
Krzysztof Helt8f5d0502007-10-16 01:28:53 -07001263
Krzysztof Helt8f5d0502007-10-16 01:28:53 -07001264 if (cursor->enable)
1265 mode |= PM2F_CURSORMODE_CURSOR_ENABLE;
1266
1267 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_MODE, mode);
1268
Krzysztof Helt1ddc28d2007-10-16 01:29:16 -07001269 if (!cursor->enable)
1270 x = 2047; /* push it outside display */
1271 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_LOW, x & 0xff);
1272 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_HIGH, (x >> 8) & 0xf);
1273 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_LOW, y & 0xff);
1274 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_HIGH, (y >> 8) & 0xf);
1275
Krzysztof Helt8f5d0502007-10-16 01:28:53 -07001276 /*
1277 * If the cursor is not be changed this means either we want the
1278 * current cursor state (if enable is set) or we want to query what
1279 * we can do with the cursor (if enable is not set)
1280 */
1281 if (!cursor->set)
1282 return 0;
1283
Krzysztof Helt8f5d0502007-10-16 01:28:53 -07001284 if (cursor->set & FB_CUR_SETHOT) {
1285 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_HOT,
1286 cursor->hot.x & 0x3f);
1287 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_HOT,
1288 cursor->hot.y & 0x3f);
1289 }
1290
1291 if (cursor->set & FB_CUR_SETCMAP) {
1292 u32 fg_idx = cursor->image.fg_color;
1293 u32 bg_idx = cursor->image.bg_color;
1294 struct fb_cmap cmap = info->cmap;
1295
1296 /* the X11 driver says one should use these color registers */
1297 pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CURSOR_PALETTE >> 8);
1298 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 0,
1299 cmap.red[bg_idx] >> 8 );
1300 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 1,
1301 cmap.green[bg_idx] >> 8 );
1302 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 2,
1303 cmap.blue[bg_idx] >> 8 );
1304
1305 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 3,
1306 cmap.red[fg_idx] >> 8 );
1307 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 4,
1308 cmap.green[fg_idx] >> 8 );
1309 pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 5,
1310 cmap.blue[fg_idx] >> 8 );
1311 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
1312 }
1313
1314 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1315 u8 *bitmap = (u8 *)cursor->image.data;
1316 u8 *mask = (u8 *)cursor->mask;
1317 int i;
1318 int pos = PM2VI_RD_CURSOR_PATTERN;
1319
1320 for (i = 0; i < cursor->image.height; i++) {
1321 int j = (cursor->image.width + 7) >> 3;
1322 int k = 8 - j;
1323
1324 pm2_WR(par, PM2VR_RD_INDEX_HIGH, pos >> 8);
1325
1326 for (; j > 0; j--) {
1327 u8 data = *bitmap ^ *mask;
1328
1329 if (cursor->rop == ROP_COPY)
1330 data = *mask & *bitmap;
1331 /* Upper 4 bits of bitmap data */
1332 pm2v_RDAC_WR(par, pos++,
1333 cursor_bits_lookup[data >> 4] |
1334 (cursor_bits_lookup[*mask >> 4] << 1));
1335 /* Lower 4 bits of bitmap */
1336 pm2v_RDAC_WR(par, pos++,
1337 cursor_bits_lookup[data & 0xf] |
1338 (cursor_bits_lookup[*mask & 0xf] << 1));
1339 bitmap++;
1340 mask++;
1341 }
1342 for (; k > 0; k--) {
1343 pm2v_RDAC_WR(par, pos++, 0);
1344 pm2v_RDAC_WR(par, pos++, 0);
1345 }
1346 }
1347
1348 while (pos < (1024 + PM2VI_RD_CURSOR_PATTERN)) {
1349 pm2_WR(par, PM2VR_RD_INDEX_HIGH, pos >> 8);
1350 pm2v_RDAC_WR(par, pos++, 0);
1351 }
1352
1353 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
1354 }
1355 return 0;
1356}
1357
1358static int pm2fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1359{
1360 struct pm2fb_par *par = info->par;
Krzysztof Helt2a36f9c2007-10-16 01:29:16 -07001361 u8 mode;
1362
1363 if (!hwcursor)
1364 return -EINVAL; /* just to force soft_cursor() call */
1365
1366 /* Too large of a cursor or wrong bpp :-( */
1367 if (cursor->image.width > 64 ||
1368 cursor->image.height > 64 ||
1369 cursor->image.depth > 1)
1370 return -EINVAL;
Krzysztof Helt8f5d0502007-10-16 01:28:53 -07001371
1372 if (par->type == PM2_TYPE_PERMEDIA2V)
1373 return pm2vfb_cursor(info, cursor);
1374
Krzysztof Helt1ddc28d2007-10-16 01:29:16 -07001375 mode = 0x40;
Krzysztof Helt2a36f9c2007-10-16 01:29:16 -07001376 if (cursor->enable)
1377 mode = 0x43;
1378
1379 pm2_RDAC_WR(par, PM2I_RD_CURSOR_CONTROL, mode);
1380
1381 /*
1382 * If the cursor is not be changed this means either we want the
1383 * current cursor state (if enable is set) or we want to query what
1384 * we can do with the cursor (if enable is not set)
1385 */
1386 if (!cursor->set)
1387 return 0;
1388
1389 if (cursor->set & FB_CUR_SETPOS) {
Krzysztof Helt1ddc28d2007-10-16 01:29:16 -07001390 int x = cursor->image.dx - info->var.xoffset + 63;
1391 int y = cursor->image.dy - info->var.yoffset + 63;
Krzysztof Helt2a36f9c2007-10-16 01:29:16 -07001392
Krzysztof Helt2a36f9c2007-10-16 01:29:16 -07001393 WAIT_FIFO(par, 4);
1394 pm2_WR(par, PM2R_RD_CURSOR_X_LSB, x & 0xff);
1395 pm2_WR(par, PM2R_RD_CURSOR_X_MSB, (x >> 8) & 0x7);
1396 pm2_WR(par, PM2R_RD_CURSOR_Y_LSB, y & 0xff);
1397 pm2_WR(par, PM2R_RD_CURSOR_Y_MSB, (y >> 8) & 0x7);
1398 }
1399
1400 if (cursor->set & FB_CUR_SETCMAP) {
1401 u32 fg_idx = cursor->image.fg_color;
1402 u32 bg_idx = cursor->image.bg_color;
1403
1404 WAIT_FIFO(par, 7);
1405 pm2_WR(par, PM2R_RD_CURSOR_COLOR_ADDRESS, 1);
1406 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1407 info->cmap.red[bg_idx] >> 8);
1408 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1409 info->cmap.green[bg_idx] >> 8);
1410 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1411 info->cmap.blue[bg_idx] >> 8);
1412
1413 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1414 info->cmap.red[fg_idx] >> 8);
1415 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1416 info->cmap.green[fg_idx] >> 8);
1417 pm2_WR(par, PM2R_RD_CURSOR_COLOR_DATA,
1418 info->cmap.blue[fg_idx] >> 8);
1419 }
1420
1421 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1422 u8 *bitmap = (u8 *)cursor->image.data;
1423 u8 *mask = (u8 *)cursor->mask;
1424 int i;
1425
1426 WAIT_FIFO(par, 1);
1427 pm2_WR(par, PM2R_RD_PALETTE_WRITE_ADDRESS, 0);
1428
1429 for (i = 0; i < cursor->image.height; i++) {
1430 int j = (cursor->image.width + 7) >> 3;
1431 int k = 8 - j;
1432
1433 WAIT_FIFO(par, 8);
1434 for (; j > 0; j--) {
1435 u8 data = *bitmap ^ *mask;
1436
1437 if (cursor->rop == ROP_COPY)
1438 data = *mask & *bitmap;
1439 /* bitmap data */
1440 pm2_WR(par, PM2R_RD_CURSOR_DATA, data);
1441 bitmap++;
1442 mask++;
1443 }
1444 for (; k > 0; k--)
1445 pm2_WR(par, PM2R_RD_CURSOR_DATA, 0);
1446 }
1447 for (; i < 64; i++) {
1448 int j = 8;
1449 WAIT_FIFO(par, 8);
1450 while (j-- > 0)
1451 pm2_WR(par, PM2R_RD_CURSOR_DATA, 0);
1452 }
1453
1454 mask = (u8 *)cursor->mask;
1455 for (i = 0; i < cursor->image.height; i++) {
1456 int j = (cursor->image.width + 7) >> 3;
1457 int k = 8 - j;
1458
1459 WAIT_FIFO(par, 8);
1460 for (; j > 0; j--) {
1461 /* mask */
1462 pm2_WR(par, PM2R_RD_CURSOR_DATA, *mask);
1463 mask++;
1464 }
1465 for (; k > 0; k--)
1466 pm2_WR(par, PM2R_RD_CURSOR_DATA, 0);
1467 }
1468 for (; i < 64; i++) {
1469 int j = 8;
1470 WAIT_FIFO(par, 8);
1471 while (j-- > 0)
1472 pm2_WR(par, PM2R_RD_CURSOR_DATA, 0);
1473 }
1474 }
1475 return 0;
Krzysztof Helt8f5d0502007-10-16 01:28:53 -07001476}
1477
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478/* ------------ Hardware Independent Functions ------------ */
1479
1480/*
1481 * Frame buffer operations
1482 */
1483
1484static struct fb_ops pm2fb_ops = {
1485 .owner = THIS_MODULE,
1486 .fb_check_var = pm2fb_check_var,
1487 .fb_set_par = pm2fb_set_par,
1488 .fb_setcolreg = pm2fb_setcolreg,
1489 .fb_blank = pm2fb_blank,
1490 .fb_pan_display = pm2fb_pan_display,
Krzysztof Helt87a7cc62007-05-08 00:40:02 -07001491 .fb_fillrect = pm2fb_fillrect,
1492 .fb_copyarea = pm2fb_copyarea,
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001493 .fb_imageblit = pm2fb_imageblit,
Antonino A. Daplas03b9ae42007-05-10 22:23:29 -07001494 .fb_sync = pm2fb_sync,
Krzysztof Helt8f5d0502007-10-16 01:28:53 -07001495 .fb_cursor = pm2fb_cursor,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496};
1497
1498/*
1499 * PCI stuff
1500 */
1501
1502
1503/**
1504 * Device initialisation
1505 *
1506 * Initialise and allocate resource for PCI device.
1507 *
1508 * @param pdev PCI device.
1509 * @param id PCI device ID.
1510 */
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -08001511static int pm2fb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512{
1513 struct pm2fb_par *default_par;
1514 struct fb_info *info;
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001515 int err;
1516 int retval = -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
1518 err = pci_enable_device(pdev);
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001519 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 printk(KERN_WARNING "pm2fb: Can't enable pdev: %d\n", err);
1521 return err;
1522 }
1523
Antonino A. Daplas6772a2e2006-01-09 20:53:10 -08001524 info = framebuffer_alloc(sizeof(struct pm2fb_par), &pdev->dev);
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001525 if (!info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 return -ENOMEM;
Antonino A. Daplas6772a2e2006-01-09 20:53:10 -08001527 default_par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 switch (pdev->device) {
1530 case PCI_DEVICE_ID_TI_TVP4020:
1531 strcpy(pm2fb_fix.id, "TVP4020");
1532 default_par->type = PM2_TYPE_PERMEDIA2;
1533 break;
1534 case PCI_DEVICE_ID_3DLABS_PERMEDIA2:
1535 strcpy(pm2fb_fix.id, "Permedia2");
1536 default_par->type = PM2_TYPE_PERMEDIA2;
1537 break;
1538 case PCI_DEVICE_ID_3DLABS_PERMEDIA2V:
1539 strcpy(pm2fb_fix.id, "Permedia2v");
1540 default_par->type = PM2_TYPE_PERMEDIA2V;
1541 break;
1542 }
1543
1544 pm2fb_fix.mmio_start = pci_resource_start(pdev, 0);
1545 pm2fb_fix.mmio_len = PM2_REGS_SIZE;
1546
1547#if defined(__BIG_ENDIAN)
1548 /*
1549 * PM2 has a 64k register file, mapped twice in 128k. Lower
1550 * map is little-endian, upper map is big-endian.
1551 */
1552 pm2fb_fix.mmio_start += PM2_REGS_SIZE;
1553 DPRINTK("Adjusting register base for big-endian.\n");
1554#endif
1555 DPRINTK("Register base at 0x%lx\n", pm2fb_fix.mmio_start);
Krzysztof Helt2f7bb992007-07-17 04:05:31 -07001556
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 /* Registers - request region and map it. */
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001558 if (!request_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len,
1559 "pm2fb regbase")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 printk(KERN_WARNING "pm2fb: Can't reserve regbase.\n");
1561 goto err_exit_neither;
1562 }
1563 default_par->v_regs =
1564 ioremap_nocache(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001565 if (!default_par->v_regs) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 printk(KERN_WARNING "pm2fb: Can't remap %s register area.\n",
1567 pm2fb_fix.id);
1568 release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
1569 goto err_exit_neither;
1570 }
1571
1572 /* Stash away memory register info for use when we reset the board */
1573 default_par->mem_control = pm2_RD(default_par, PM2R_MEM_CONTROL);
1574 default_par->boot_address = pm2_RD(default_par, PM2R_BOOT_ADDRESS);
1575 default_par->mem_config = pm2_RD(default_par, PM2R_MEM_CONFIG);
1576 DPRINTK("MemControl 0x%x BootAddress 0x%x MemConfig 0x%x\n",
1577 default_par->mem_control, default_par->boot_address,
1578 default_par->mem_config);
1579
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001580 if (default_par->mem_control == 0 &&
Peter 'p2' De Schrijver9127fa22005-11-07 01:00:42 -08001581 default_par->boot_address == 0x31 &&
Krzysztof Heltf1c15f92007-05-08 00:39:30 -07001582 default_par->mem_config == 0x259fffff) {
Krzysztof Helt9a31f0f2007-05-08 00:39:57 -07001583 default_par->memclock = CVPPC_MEMCLOCK;
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001584 default_par->mem_control = 0;
1585 default_par->boot_address = 0x20;
1586 default_par->mem_config = 0xe6002021;
Krzysztof Heltf1c15f92007-05-08 00:39:30 -07001587 if (pdev->subsystem_vendor == 0x1048 &&
1588 pdev->subsystem_device == 0x0a31) {
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001589 DPRINTK("subsystem_vendor: %04x, "
1590 "subsystem_device: %04x\n",
Krzysztof Heltf1c15f92007-05-08 00:39:30 -07001591 pdev->subsystem_vendor, pdev->subsystem_device);
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001592 DPRINTK("We have not been initialized by VGA BIOS and "
1593 "are running on an Elsa Winner 2000 Office\n");
Krzysztof Heltf1c15f92007-05-08 00:39:30 -07001594 DPRINTK("Initializing card timings manually...\n");
Krzysztof Helt138a4512007-10-16 01:28:36 -07001595 default_par->memclock = 100000;
Krzysztof Heltf1c15f92007-05-08 00:39:30 -07001596 }
1597 if (pdev->subsystem_vendor == 0x3d3d &&
1598 pdev->subsystem_device == 0x0100) {
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001599 DPRINTK("subsystem_vendor: %04x, "
1600 "subsystem_device: %04x\n",
Krzysztof Heltf1c15f92007-05-08 00:39:30 -07001601 pdev->subsystem_vendor, pdev->subsystem_device);
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001602 DPRINTK("We have not been initialized by VGA BIOS and "
1603 "are running on an 3dlabs reference board\n");
Krzysztof Heltf1c15f92007-05-08 00:39:30 -07001604 DPRINTK("Initializing card timings manually...\n");
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001605 default_par->memclock = 74894;
Krzysztof Heltf1c15f92007-05-08 00:39:30 -07001606 }
Peter 'p2' De Schrijver9127fa22005-11-07 01:00:42 -08001607 }
1608
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 /* Now work out how big lfb is going to be. */
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001610 switch (default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 case PM2F_MEM_BANKS_1:
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001612 pm2fb_fix.smem_len = 0x200000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 break;
1614 case PM2F_MEM_BANKS_2:
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001615 pm2fb_fix.smem_len = 0x400000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 break;
1617 case PM2F_MEM_BANKS_3:
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001618 pm2fb_fix.smem_len = 0x600000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 break;
1620 case PM2F_MEM_BANKS_4:
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001621 pm2fb_fix.smem_len = 0x800000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 break;
1623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 pm2fb_fix.smem_start = pci_resource_start(pdev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
1626 /* Linear frame buffer - request region and map it. */
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001627 if (!request_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len,
1628 "pm2fb smem")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 printk(KERN_WARNING "pm2fb: Can't reserve smem.\n");
1630 goto err_exit_mmio;
1631 }
Krzysztof Helt4560daa2007-05-08 00:40:12 -07001632 info->screen_base =
Luis R. Rodriguezf8f05cd2015-04-21 13:16:33 -07001633 ioremap_wc(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
Krzysztof Helt45f169e2007-10-16 01:28:34 -07001634 if (!info->screen_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 printk(KERN_WARNING "pm2fb: Can't ioremap smem area.\n");
1636 release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
1637 goto err_exit_mmio;
1638 }
1639
Krzysztof Heltd5383fc2007-10-16 01:28:33 -07001640 if (!nomtrr)
Luis R. Rodriguezf8f05cd2015-04-21 13:16:33 -07001641 default_par->wc_cookie = arch_phys_wc_add(pm2fb_fix.smem_start,
1642 pm2fb_fix.smem_len);
Krzysztof Heltd5383fc2007-10-16 01:28:33 -07001643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 info->fbops = &pm2fb_ops;
Krzysztof Helt2f7bb992007-07-17 04:05:31 -07001645 info->fix = pm2fb_fix;
Antonino A. Daplas6772a2e2006-01-09 20:53:10 -08001646 info->pseudo_palette = default_par->palette;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 info->flags = FBINFO_DEFAULT |
Krzysztof Helt2f7bb992007-07-17 04:05:31 -07001648 FBINFO_HWACCEL_YPAN |
1649 FBINFO_HWACCEL_COPYAREA |
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001650 FBINFO_HWACCEL_IMAGEBLIT |
Krzysztof Helt2f7bb992007-07-17 04:05:31 -07001651 FBINFO_HWACCEL_FILLRECT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001653 info->pixmap.addr = kmalloc(PM2_PIXMAP_SIZE, GFP_KERNEL);
1654 if (!info->pixmap.addr) {
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001655 retval = -ENOMEM;
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001656 goto err_exit_pixmap;
1657 }
1658 info->pixmap.size = PM2_PIXMAP_SIZE;
1659 info->pixmap.buf_align = 4;
1660 info->pixmap.scan_align = 4;
1661 info->pixmap.access_align = 32;
1662 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1663
Krzysztof Heltd5383fc2007-10-16 01:28:33 -07001664 if (noaccel) {
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001665 printk(KERN_DEBUG "disabling acceleration\n");
1666 info->flags |= FBINFO_HWACCEL_DISABLED;
1667 info->pixmap.scan_align = 1;
Krzysztof Heltd5383fc2007-10-16 01:28:33 -07001668 }
1669
Krzysztof Helt5eb81e802008-04-28 02:15:05 -07001670 if (!mode_option)
1671 mode_option = "640x480@60";
Krzysztof Helt2f7bb992007-07-17 04:05:31 -07001672
Krzysztof Helt5eb81e802008-04-28 02:15:05 -07001673 err = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 if (!err || err == 4)
1675 info->var = pm2fb_var;
1676
Krzysztof Helt2ae09f02008-04-28 02:14:51 -07001677 retval = fb_alloc_cmap(&info->cmap, 256, 0);
1678 if (retval < 0)
Krzysztof Helt435d56f2007-05-08 00:40:16 -07001679 goto err_exit_both;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Krzysztof Helt2ae09f02008-04-28 02:14:51 -07001681 retval = register_framebuffer(info);
1682 if (retval < 0)
Krzysztof Helt435d56f2007-05-08 00:40:16 -07001683 goto err_exit_all;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Joe Perches31b67802013-09-19 18:35:55 -07001685 fb_info(info, "%s frame buffer device, memory = %dK\n",
1686 info->fix.id, pm2fb_fix.smem_len / 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
1688 /*
1689 * Our driver data
1690 */
1691 pci_set_drvdata(pdev, info);
1692
1693 return 0;
1694
1695 err_exit_all:
Krzysztof Helt2f7bb992007-07-17 04:05:31 -07001696 fb_dealloc_cmap(&info->cmap);
1697 err_exit_both:
Krzysztof Helt91b3a6f2007-10-16 01:28:34 -07001698 kfree(info->pixmap.addr);
1699 err_exit_pixmap:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 iounmap(info->screen_base);
1701 release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
1702 err_exit_mmio:
1703 iounmap(default_par->v_regs);
1704 release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
1705 err_exit_neither:
1706 framebuffer_release(info);
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001707 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
1709
1710/**
1711 * Device removal.
1712 *
1713 * Release all device resources.
1714 *
1715 * @param pdev PCI device to clean up.
1716 */
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -08001717static void pm2fb_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718{
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001719 struct fb_info *info = pci_get_drvdata(pdev);
1720 struct fb_fix_screeninfo *fix = &info->fix;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 struct pm2fb_par *par = info->par;
1722
1723 unregister_framebuffer(info);
Luis R. Rodriguezf8f05cd2015-04-21 13:16:33 -07001724 arch_phys_wc_del(par->wc_cookie);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 iounmap(info->screen_base);
1726 release_mem_region(fix->smem_start, fix->smem_len);
1727 iounmap(par->v_regs);
1728 release_mem_region(fix->mmio_start, fix->mmio_len);
1729
Krzysztof Helt27aa0692008-08-20 14:09:11 -07001730 fb_dealloc_cmap(&info->cmap);
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001731 kfree(info->pixmap.addr);
Krzysztof Helt491bcc92009-06-16 15:34:36 -07001732 framebuffer_release(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733}
1734
1735static struct pci_device_id pm2fb_id_table[] = {
1736 { PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TVP4020,
Krzysztof Helt138a4512007-10-16 01:28:36 -07001737 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2,
Krzysztof Helt138a4512007-10-16 01:28:36 -07001739 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V,
Krzysztof Helt138a4512007-10-16 01:28:36 -07001741 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 { 0, }
1743};
1744
1745static struct pci_driver pm2fb_driver = {
1746 .name = "pm2fb",
Krzysztof Helt2f7bb992007-07-17 04:05:31 -07001747 .id_table = pm2fb_id_table,
1748 .probe = pm2fb_probe,
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -08001749 .remove = pm2fb_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750};
1751
1752MODULE_DEVICE_TABLE(pci, pm2fb_id_table);
1753
1754
1755#ifndef MODULE
1756/**
Joe Perches75e1b6a2011-06-23 22:35:19 +00001757 * Parse user specified options.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 *
1759 * This is, comma-separated options following `video=pm2fb:'.
1760 */
1761static int __init pm2fb_setup(char *options)
1762{
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001763 char *this_opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
1765 if (!options || !*options)
1766 return 0;
1767
Krzysztof Helt2f7bb992007-07-17 04:05:31 -07001768 while ((this_opt = strsep(&options, ",")) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 if (!*this_opt)
1770 continue;
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001771 if (!strcmp(this_opt, "lowhsync"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 lowhsync = 1;
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001773 else if (!strcmp(this_opt, "lowvsync"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 lowvsync = 1;
Krzysztof Helt8f5d0502007-10-16 01:28:53 -07001775 else if (!strncmp(this_opt, "hwcursor=", 9))
1776 hwcursor = simple_strtoul(this_opt + 9, NULL, 0);
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001777 else if (!strncmp(this_opt, "nomtrr", 6))
Krzysztof Heltd5383fc2007-10-16 01:28:33 -07001778 nomtrr = 1;
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001779 else if (!strncmp(this_opt, "noaccel", 7))
Krzysztof Heltd5383fc2007-10-16 01:28:33 -07001780 noaccel = 1;
Krzysztof Helt3843faa2007-10-16 01:28:50 -07001781 else
Krzysztof Helt5eb81e802008-04-28 02:15:05 -07001782 mode_option = this_opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 }
1784 return 0;
1785}
1786#endif
1787
1788
1789static int __init pm2fb_init(void)
1790{
1791#ifndef MODULE
1792 char *option = NULL;
1793
1794 if (fb_get_options("pm2fb", &option))
1795 return -ENODEV;
1796 pm2fb_setup(option);
1797#endif
1798
1799 return pci_register_driver(&pm2fb_driver);
1800}
1801
1802module_init(pm2fb_init);
1803
1804#ifdef MODULE
1805/*
1806 * Cleanup
1807 */
1808
1809static void __exit pm2fb_exit(void)
1810{
1811 pci_unregister_driver(&pm2fb_driver);
1812}
1813#endif
1814
1815#ifdef MODULE
1816module_exit(pm2fb_exit);
1817
Krzysztof Helt5eb81e802008-04-28 02:15:05 -07001818module_param(mode_option, charp, 0);
1819MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
Krzysztof Helt9e3f0ca2008-04-28 02:15:10 -07001820module_param_named(mode, mode_option, charp, 0);
1821MODULE_PARM_DESC(mode, "Initial video mode e.g. '648x480-8@60' (deprecated)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822module_param(lowhsync, bool, 0);
1823MODULE_PARM_DESC(lowhsync, "Force horizontal sync low regardless of mode");
1824module_param(lowvsync, bool, 0);
1825MODULE_PARM_DESC(lowvsync, "Force vertical sync low regardless of mode");
Krzysztof Heltd5383fc2007-10-16 01:28:33 -07001826module_param(noaccel, bool, 0);
1827MODULE_PARM_DESC(noaccel, "Disable acceleration");
Krzysztof Helt8f5d0502007-10-16 01:28:53 -07001828module_param(hwcursor, int, 0644);
1829MODULE_PARM_DESC(hwcursor, "Enable hardware cursor "
Krzysztof Helt1ddc28d2007-10-16 01:29:16 -07001830 "(1=enable, 0=disable, default=1)");
Krzysztof Heltd5383fc2007-10-16 01:28:33 -07001831module_param(nomtrr, bool, 0);
1832MODULE_PARM_DESC(nomtrr, "Disable MTRR support (0 or 1=disabled) (default=0)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
1834MODULE_AUTHOR("Jim Hague <jim.hague@acm.org>");
1835MODULE_DESCRIPTION("Permedia2 framebuffer device driver");
1836MODULE_LICENSE("GPL");
1837#endif