blob: 87d2aafa92fec10d46dff216e3cec8e2e1886084 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/video/cyber2000fb.c
3 *
4 * Copyright (C) 1998-2002 Russell King
5 *
6 * MIPS and 50xx clock support
7 * Copyright (C) 2001 Bradley D. LaRonde <brad@ltc.com>
8 *
9 * 32 bit support, text color and panning fixes for modes != 8 bit
10 * Copyright (C) 2002 Denis Oliver Kropp <dok@directfb.org>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 * Integraphics CyberPro 2000, 2010 and 5000 frame buffer device
17 *
18 * Based on cyberfb.c.
19 *
20 * Note that we now use the new fbcon fix, var and cmap scheme. We do
21 * still have to check which console is the currently displayed one
22 * however, especially for the colourmap stuff.
23 *
24 * We also use the new hotplug PCI subsystem. I'm not sure if there
25 * are any such cards, but I'm erring on the side of caution. We don't
26 * want to go pop just because someone does have one.
27 *
28 * Note that this doesn't work fully in the case of multiple CyberPro
29 * cards with grabbers. We currently can only attach to the first
30 * CyberPro card found.
31 *
32 * When we're in truecolour mode, we power down the LUT RAM as a power
33 * saving feature. Also, when we enter any of the powersaving modes
34 * (except soft blanking) we power down the RAMDACs. This saves about
35 * 1W, which is roughly 8% of the power consumption of a NetWinder
36 * (which, incidentally, is about the same saving as a 2.5in hard disk
37 * entering standby mode.)
38 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/module.h>
40#include <linux/kernel.h>
41#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/slab.h>
45#include <linux/delay.h>
46#include <linux/fb.h>
47#include <linux/pci.h>
48#include <linux/init.h>
Russell King99730222009-03-25 10:21:35 +000049#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Ondrej Zarye5dedf82010-08-11 21:48:03 +020051#include <linux/i2c.h>
52#include <linux/i2c-algo-bit.h>
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include <asm/pgtable.h>
55#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#ifdef __arm__
58#include <asm/mach-types.h>
59#endif
60
61#include "cyber2000fb.h"
62
63struct cfb_info {
64 struct fb_info fb;
65 struct display_switch *dispsw;
66 struct display *display;
67 struct pci_dev *dev;
Krzysztof Helt532237e2007-10-18 23:40:28 -070068 unsigned char __iomem *region;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 unsigned char __iomem *regs;
70 u_int id;
71 int func_use_count;
72 u_long ref_ps;
73
74 /*
75 * Clock divisors
76 */
77 u_int divisors[4];
78
79 struct {
80 u8 red, green, blue;
81 } palette[NR_PALETTE];
82
83 u_char mem_ctl1;
84 u_char mem_ctl2;
85 u_char mclk_mult;
86 u_char mclk_div;
87 /*
88 * RAMDAC control register is both of these or'ed together
89 */
90 u_char ramdac_ctrl;
91 u_char ramdac_powerdown;
Russell Kingeca02b02005-05-03 12:23:56 +010092
93 u32 pseudo_palette[16];
Ondrej Zarye5dedf82010-08-11 21:48:03 +020094#ifdef CONFIG_FB_CYBER2000_DDC
95 bool ddc_registered;
96 struct i2c_adapter ddc_adapter;
97 struct i2c_algo_bit_data ddc_algo;
98 spinlock_t reg_b0_lock;
99#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100};
101
102static char *default_font = "Acorn8x8";
103module_param(default_font, charp, 0);
104MODULE_PARM_DESC(default_font, "Default font name");
105
106/*
107 * Our access methods.
108 */
Krzysztof Helt532237e2007-10-18 23:40:28 -0700109#define cyber2000fb_writel(val, reg, cfb) writel(val, (cfb)->regs + (reg))
110#define cyber2000fb_writew(val, reg, cfb) writew(val, (cfb)->regs + (reg))
111#define cyber2000fb_writeb(val, reg, cfb) writeb(val, (cfb)->regs + (reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Krzysztof Helt532237e2007-10-18 23:40:28 -0700113#define cyber2000fb_readb(reg, cfb) readb((cfb)->regs + (reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115static inline void
116cyber2000_crtcw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
117{
118 cyber2000fb_writew((reg & 255) | val << 8, 0x3d4, cfb);
119}
120
121static inline void
122cyber2000_grphw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
123{
124 cyber2000fb_writew((reg & 255) | val << 8, 0x3ce, cfb);
125}
126
127static inline unsigned int
128cyber2000_grphr(unsigned int reg, struct cfb_info *cfb)
129{
130 cyber2000fb_writeb(reg, 0x3ce, cfb);
131 return cyber2000fb_readb(0x3cf, cfb);
132}
133
134static inline void
135cyber2000_attrw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
136{
137 cyber2000fb_readb(0x3da, cfb);
138 cyber2000fb_writeb(reg, 0x3c0, cfb);
139 cyber2000fb_readb(0x3c1, cfb);
140 cyber2000fb_writeb(val, 0x3c0, cfb);
141}
142
143static inline void
144cyber2000_seqw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
145{
146 cyber2000fb_writew((reg & 255) | val << 8, 0x3c4, cfb);
147}
148
149/* -------------------- Hardware specific routines ------------------------- */
150
151/*
152 * Hardware Cyber2000 Acceleration
153 */
154static void
155cyber2000fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
156{
157 struct cfb_info *cfb = (struct cfb_info *)info;
158 unsigned long dst, col;
159
160 if (!(cfb->fb.var.accel_flags & FB_ACCELF_TEXT)) {
161 cfb_fillrect(info, rect);
162 return;
163 }
164
165 cyber2000fb_writeb(0, CO_REG_CONTROL, cfb);
166 cyber2000fb_writew(rect->width - 1, CO_REG_PIXWIDTH, cfb);
167 cyber2000fb_writew(rect->height - 1, CO_REG_PIXHEIGHT, cfb);
168
169 col = rect->color;
170 if (cfb->fb.var.bits_per_pixel > 8)
171 col = ((u32 *)cfb->fb.pseudo_palette)[col];
172 cyber2000fb_writel(col, CO_REG_FGCOLOUR, cfb);
173
174 dst = rect->dx + rect->dy * cfb->fb.var.xres_virtual;
175 if (cfb->fb.var.bits_per_pixel == 24) {
176 cyber2000fb_writeb(dst, CO_REG_X_PHASE, cfb);
177 dst *= 3;
178 }
179
180 cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb);
181 cyber2000fb_writeb(CO_FG_MIX_SRC, CO_REG_FGMIX, cfb);
182 cyber2000fb_writew(CO_CMD_L_PATTERN_FGCOL, CO_REG_CMD_L, cfb);
183 cyber2000fb_writew(CO_CMD_H_BLITTER, CO_REG_CMD_H, cfb);
184}
185
186static void
187cyber2000fb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
188{
189 struct cfb_info *cfb = (struct cfb_info *)info;
190 unsigned int cmd = CO_CMD_L_PATTERN_FGCOL;
191 unsigned long src, dst;
192
193 if (!(cfb->fb.var.accel_flags & FB_ACCELF_TEXT)) {
194 cfb_copyarea(info, region);
195 return;
196 }
197
198 cyber2000fb_writeb(0, CO_REG_CONTROL, cfb);
199 cyber2000fb_writew(region->width - 1, CO_REG_PIXWIDTH, cfb);
200 cyber2000fb_writew(region->height - 1, CO_REG_PIXHEIGHT, cfb);
201
202 src = region->sx + region->sy * cfb->fb.var.xres_virtual;
203 dst = region->dx + region->dy * cfb->fb.var.xres_virtual;
204
205 if (region->sx < region->dx) {
206 src += region->width - 1;
207 dst += region->width - 1;
208 cmd |= CO_CMD_L_INC_LEFT;
209 }
210
211 if (region->sy < region->dy) {
212 src += (region->height - 1) * cfb->fb.var.xres_virtual;
213 dst += (region->height - 1) * cfb->fb.var.xres_virtual;
214 cmd |= CO_CMD_L_INC_UP;
215 }
216
217 if (cfb->fb.var.bits_per_pixel == 24) {
218 cyber2000fb_writeb(dst, CO_REG_X_PHASE, cfb);
219 src *= 3;
220 dst *= 3;
221 }
222 cyber2000fb_writel(src, CO_REG_SRC1_PTR, cfb);
223 cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb);
224 cyber2000fb_writew(CO_FG_MIX_SRC, CO_REG_FGMIX, cfb);
225 cyber2000fb_writew(cmd, CO_REG_CMD_L, cfb);
226 cyber2000fb_writew(CO_CMD_H_FGSRCMAP | CO_CMD_H_BLITTER,
227 CO_REG_CMD_H, cfb);
228}
229
230static void
231cyber2000fb_imageblit(struct fb_info *info, const struct fb_image *image)
232{
Krzysztof Helt532237e2007-10-18 23:40:28 -0700233 cfb_imageblit(info, image);
234 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236
237static int cyber2000fb_sync(struct fb_info *info)
238{
239 struct cfb_info *cfb = (struct cfb_info *)info;
240 int count = 100000;
241
242 if (!(cfb->fb.var.accel_flags & FB_ACCELF_TEXT))
243 return 0;
244
245 while (cyber2000fb_readb(CO_REG_CONTROL, cfb) & CO_CTRL_BUSY) {
246 if (!count--) {
247 debug_printf("accel_wait timed out\n");
248 cyber2000fb_writeb(0, CO_REG_CONTROL, cfb);
249 break;
250 }
251 udelay(1);
252 }
253 return 0;
254}
255
256/*
257 * ===========================================================================
258 */
259
260static inline u32 convert_bitfield(u_int val, struct fb_bitfield *bf)
261{
262 u_int mask = (1 << bf->length) - 1;
263
264 return (val >> (16 - bf->length) & mask) << bf->offset;
265}
266
267/*
268 * Set a single color register. Return != 0 for invalid regno.
269 */
270static int
271cyber2000fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
272 u_int transp, struct fb_info *info)
273{
274 struct cfb_info *cfb = (struct cfb_info *)info;
275 struct fb_var_screeninfo *var = &cfb->fb.var;
276 u32 pseudo_val;
277 int ret = 1;
278
279 switch (cfb->fb.fix.visual) {
280 default:
281 return 1;
282
283 /*
284 * Pseudocolour:
Krzysztof Helt532237e2007-10-18 23:40:28 -0700285 * 8 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 * pixel --/--+--/--> red lut --> red dac
Krzysztof Helt532237e2007-10-18 23:40:28 -0700287 * | 8
288 * +--/--> green lut --> green dac
289 * | 8
290 * +--/--> blue lut --> blue dac
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 */
292 case FB_VISUAL_PSEUDOCOLOR:
293 if (regno >= NR_PALETTE)
294 return 1;
295
296 red >>= 8;
297 green >>= 8;
298 blue >>= 8;
299
Krzysztof Helt532237e2007-10-18 23:40:28 -0700300 cfb->palette[regno].red = red;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 cfb->palette[regno].green = green;
Krzysztof Helt532237e2007-10-18 23:40:28 -0700302 cfb->palette[regno].blue = blue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 cyber2000fb_writeb(regno, 0x3c8, cfb);
305 cyber2000fb_writeb(red, 0x3c9, cfb);
306 cyber2000fb_writeb(green, 0x3c9, cfb);
307 cyber2000fb_writeb(blue, 0x3c9, cfb);
308 return 0;
309
310 /*
311 * Direct colour:
Krzysztof Helt532237e2007-10-18 23:40:28 -0700312 * n rl
313 * pixel --/--+--/--> red lut --> red dac
314 * | gl
315 * +--/--> green lut --> green dac
316 * | bl
317 * +--/--> blue lut --> blue dac
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 * n = bpp, rl = red length, gl = green length, bl = blue length
319 */
320 case FB_VISUAL_DIRECTCOLOR:
321 red >>= 8;
322 green >>= 8;
323 blue >>= 8;
324
325 if (var->green.length == 6 && regno < 64) {
326 cfb->palette[regno << 2].green = green;
327
328 /*
329 * The 6 bits of the green component are applied
330 * to the high 6 bits of the LUT.
331 */
332 cyber2000fb_writeb(regno << 2, 0x3c8, cfb);
Krzysztof Helt532237e2007-10-18 23:40:28 -0700333 cyber2000fb_writeb(cfb->palette[regno >> 1].red,
334 0x3c9, cfb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 cyber2000fb_writeb(green, 0x3c9, cfb);
Krzysztof Helt532237e2007-10-18 23:40:28 -0700336 cyber2000fb_writeb(cfb->palette[regno >> 1].blue,
337 0x3c9, cfb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 green = cfb->palette[regno << 3].green;
340
341 ret = 0;
342 }
343
344 if (var->green.length >= 5 && regno < 32) {
Krzysztof Helt532237e2007-10-18 23:40:28 -0700345 cfb->palette[regno << 3].red = red;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 cfb->palette[regno << 3].green = green;
Krzysztof Helt532237e2007-10-18 23:40:28 -0700347 cfb->palette[regno << 3].blue = blue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 /*
350 * The 5 bits of each colour component are
351 * applied to the high 5 bits of the LUT.
352 */
353 cyber2000fb_writeb(regno << 3, 0x3c8, cfb);
354 cyber2000fb_writeb(red, 0x3c9, cfb);
355 cyber2000fb_writeb(green, 0x3c9, cfb);
356 cyber2000fb_writeb(blue, 0x3c9, cfb);
357 ret = 0;
358 }
359
360 if (var->green.length == 4 && regno < 16) {
Krzysztof Helt532237e2007-10-18 23:40:28 -0700361 cfb->palette[regno << 4].red = red;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 cfb->palette[regno << 4].green = green;
Krzysztof Helt532237e2007-10-18 23:40:28 -0700363 cfb->palette[regno << 4].blue = blue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365 /*
366 * The 5 bits of each colour component are
367 * applied to the high 5 bits of the LUT.
368 */
369 cyber2000fb_writeb(regno << 4, 0x3c8, cfb);
370 cyber2000fb_writeb(red, 0x3c9, cfb);
371 cyber2000fb_writeb(green, 0x3c9, cfb);
372 cyber2000fb_writeb(blue, 0x3c9, cfb);
373 ret = 0;
374 }
375
376 /*
377 * Since this is only used for the first 16 colours, we
378 * don't have to care about overflowing for regno >= 32
379 */
380 pseudo_val = regno << var->red.offset |
381 regno << var->green.offset |
382 regno << var->blue.offset;
383 break;
384
385 /*
386 * True colour:
Krzysztof Helt532237e2007-10-18 23:40:28 -0700387 * n rl
388 * pixel --/--+--/--> red dac
389 * | gl
390 * +--/--> green dac
391 * | bl
392 * +--/--> blue dac
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 * n = bpp, rl = red length, gl = green length, bl = blue length
394 */
395 case FB_VISUAL_TRUECOLOR:
396 pseudo_val = convert_bitfield(transp ^ 0xffff, &var->transp);
397 pseudo_val |= convert_bitfield(red, &var->red);
398 pseudo_val |= convert_bitfield(green, &var->green);
399 pseudo_val |= convert_bitfield(blue, &var->blue);
Ondrej Zarye76df4d2010-07-29 22:40:54 +0200400 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 break;
402 }
403
404 /*
405 * Now set our pseudo palette for the CFB16/24/32 drivers.
406 */
407 if (regno < 16)
408 ((u32 *)cfb->fb.pseudo_palette)[regno] = pseudo_val;
409
410 return ret;
411}
412
413struct par_info {
414 /*
415 * Hardware
416 */
417 u_char clock_mult;
418 u_char clock_div;
419 u_char extseqmisc;
420 u_char co_pixfmt;
421 u_char crtc_ofl;
422 u_char crtc[19];
423 u_int width;
424 u_int pitch;
425 u_int fetch;
426
427 /*
428 * Other
429 */
430 u_char ramdac;
431};
432
433static const u_char crtc_idx[] = {
434 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
435 0x08, 0x09,
436 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18
437};
438
439static void cyber2000fb_write_ramdac_ctrl(struct cfb_info *cfb)
440{
441 unsigned int i;
442 unsigned int val = cfb->ramdac_ctrl | cfb->ramdac_powerdown;
443
444 cyber2000fb_writeb(0x56, 0x3ce, cfb);
445 i = cyber2000fb_readb(0x3cf, cfb);
446 cyber2000fb_writeb(i | 4, 0x3cf, cfb);
447 cyber2000fb_writeb(val, 0x3c6, cfb);
448 cyber2000fb_writeb(i, 0x3cf, cfb);
Ondrej Zary00b47032010-07-29 22:32:20 +0200449 /* prevent card lock-up observed on x86 with CyberPro 2000 */
450 cyber2000fb_readb(0x3cf, cfb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451}
452
453static void cyber2000fb_set_timing(struct cfb_info *cfb, struct par_info *hw)
454{
455 u_int i;
456
457 /*
458 * Blank palette
459 */
460 for (i = 0; i < NR_PALETTE; i++) {
461 cyber2000fb_writeb(i, 0x3c8, cfb);
462 cyber2000fb_writeb(0, 0x3c9, cfb);
463 cyber2000fb_writeb(0, 0x3c9, cfb);
464 cyber2000fb_writeb(0, 0x3c9, cfb);
465 }
466
467 cyber2000fb_writeb(0xef, 0x3c2, cfb);
468 cyber2000_crtcw(0x11, 0x0b, cfb);
469 cyber2000_attrw(0x11, 0x00, cfb);
470
471 cyber2000_seqw(0x00, 0x01, cfb);
472 cyber2000_seqw(0x01, 0x01, cfb);
473 cyber2000_seqw(0x02, 0x0f, cfb);
474 cyber2000_seqw(0x03, 0x00, cfb);
475 cyber2000_seqw(0x04, 0x0e, cfb);
476 cyber2000_seqw(0x00, 0x03, cfb);
477
478 for (i = 0; i < sizeof(crtc_idx); i++)
479 cyber2000_crtcw(crtc_idx[i], hw->crtc[i], cfb);
480
481 for (i = 0x0a; i < 0x10; i++)
482 cyber2000_crtcw(i, 0, cfb);
483
484 cyber2000_grphw(EXT_CRT_VRTOFL, hw->crtc_ofl, cfb);
485 cyber2000_grphw(0x00, 0x00, cfb);
486 cyber2000_grphw(0x01, 0x00, cfb);
487 cyber2000_grphw(0x02, 0x00, cfb);
488 cyber2000_grphw(0x03, 0x00, cfb);
489 cyber2000_grphw(0x04, 0x00, cfb);
490 cyber2000_grphw(0x05, 0x60, cfb);
491 cyber2000_grphw(0x06, 0x05, cfb);
492 cyber2000_grphw(0x07, 0x0f, cfb);
493 cyber2000_grphw(0x08, 0xff, cfb);
494
495 /* Attribute controller registers */
496 for (i = 0; i < 16; i++)
497 cyber2000_attrw(i, i, cfb);
498
499 cyber2000_attrw(0x10, 0x01, cfb);
500 cyber2000_attrw(0x11, 0x00, cfb);
501 cyber2000_attrw(0x12, 0x0f, cfb);
502 cyber2000_attrw(0x13, 0x00, cfb);
503 cyber2000_attrw(0x14, 0x00, cfb);
504
505 /* PLL registers */
Ondrej Zarye5dedf82010-08-11 21:48:03 +0200506#ifdef CONFIG_FB_CYBER2000_DDC
507 spin_lock(&cfb->reg_b0_lock);
508#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 cyber2000_grphw(EXT_DCLK_MULT, hw->clock_mult, cfb);
Krzysztof Helt532237e2007-10-18 23:40:28 -0700510 cyber2000_grphw(EXT_DCLK_DIV, hw->clock_div, cfb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 cyber2000_grphw(EXT_MCLK_MULT, cfb->mclk_mult, cfb);
Krzysztof Helt532237e2007-10-18 23:40:28 -0700512 cyber2000_grphw(EXT_MCLK_DIV, cfb->mclk_div, cfb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 cyber2000_grphw(0x90, 0x01, cfb);
514 cyber2000_grphw(0xb9, 0x80, cfb);
515 cyber2000_grphw(0xb9, 0x00, cfb);
Ondrej Zarye5dedf82010-08-11 21:48:03 +0200516#ifdef CONFIG_FB_CYBER2000_DDC
517 spin_unlock(&cfb->reg_b0_lock);
518#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 cfb->ramdac_ctrl = hw->ramdac;
521 cyber2000fb_write_ramdac_ctrl(cfb);
522
523 cyber2000fb_writeb(0x20, 0x3c0, cfb);
524 cyber2000fb_writeb(0xff, 0x3c6, cfb);
525
526 cyber2000_grphw(0x14, hw->fetch, cfb);
527 cyber2000_grphw(0x15, ((hw->fetch >> 8) & 0x03) |
528 ((hw->pitch >> 4) & 0x30), cfb);
529 cyber2000_grphw(EXT_SEQ_MISC, hw->extseqmisc, cfb);
530
531 /*
532 * Set up accelerator registers
533 */
Krzysztof Helt532237e2007-10-18 23:40:28 -0700534 cyber2000fb_writew(hw->width, CO_REG_SRC_WIDTH, cfb);
535 cyber2000fb_writew(hw->width, CO_REG_DEST_WIDTH, cfb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 cyber2000fb_writeb(hw->co_pixfmt, CO_REG_PIXFMT, cfb);
537}
538
539static inline int
540cyber2000fb_update_start(struct cfb_info *cfb, struct fb_var_screeninfo *var)
541{
542 u_int base = var->yoffset * var->xres_virtual + var->xoffset;
543
544 base *= var->bits_per_pixel;
545
546 /*
547 * Convert to bytes and shift two extra bits because DAC
548 * can only start on 4 byte aligned data.
549 */
550 base >>= 5;
551
552 if (base >= 1 << 20)
553 return -EINVAL;
554
555 cyber2000_grphw(0x10, base >> 16 | 0x10, cfb);
556 cyber2000_crtcw(0x0c, base >> 8, cfb);
557 cyber2000_crtcw(0x0d, base, cfb);
558
559 return 0;
560}
561
562static int
563cyber2000fb_decode_crtc(struct par_info *hw, struct cfb_info *cfb,
564 struct fb_var_screeninfo *var)
565{
566 u_int Htotal, Hblankend, Hsyncend;
567 u_int Vtotal, Vdispend, Vblankstart, Vblankend, Vsyncstart, Vsyncend;
Krzysztof Helt532237e2007-10-18 23:40:28 -0700568#define ENCODE_BIT(v, b1, m, b2) ((((v) >> (b1)) & (m)) << (b2))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 hw->crtc[13] = hw->pitch;
571 hw->crtc[17] = 0xe3;
572 hw->crtc[14] = 0;
573 hw->crtc[8] = 0;
574
Krzysztof Helt532237e2007-10-18 23:40:28 -0700575 Htotal = var->xres + var->right_margin +
576 var->hsync_len + var->left_margin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 if (Htotal > 2080)
579 return -EINVAL;
580
581 hw->crtc[0] = (Htotal >> 3) - 5;
582 hw->crtc[1] = (var->xres >> 3) - 1;
583 hw->crtc[2] = var->xres >> 3;
584 hw->crtc[4] = (var->xres + var->right_margin) >> 3;
585
Krzysztof Helt532237e2007-10-18 23:40:28 -0700586 Hblankend = (Htotal - 4 * 8) >> 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Jiri Slaby87d06132007-10-18 23:40:27 -0700588 hw->crtc[3] = ENCODE_BIT(Hblankend, 0, 0x1f, 0) |
589 ENCODE_BIT(1, 0, 0x01, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 Hsyncend = (var->xres + var->right_margin + var->hsync_len) >> 3;
592
Jiri Slaby87d06132007-10-18 23:40:27 -0700593 hw->crtc[5] = ENCODE_BIT(Hsyncend, 0, 0x1f, 0) |
594 ENCODE_BIT(Hblankend, 5, 0x01, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 Vdispend = var->yres - 1;
597 Vsyncstart = var->yres + var->lower_margin;
598 Vsyncend = var->yres + var->lower_margin + var->vsync_len;
599 Vtotal = var->yres + var->lower_margin + var->vsync_len +
600 var->upper_margin - 2;
601
602 if (Vtotal > 2047)
603 return -EINVAL;
604
605 Vblankstart = var->yres + 6;
606 Vblankend = Vtotal - 10;
607
608 hw->crtc[6] = Vtotal;
Jiri Slaby87d06132007-10-18 23:40:27 -0700609 hw->crtc[7] = ENCODE_BIT(Vtotal, 8, 0x01, 0) |
610 ENCODE_BIT(Vdispend, 8, 0x01, 1) |
611 ENCODE_BIT(Vsyncstart, 8, 0x01, 2) |
Krzysztof Helt532237e2007-10-18 23:40:28 -0700612 ENCODE_BIT(Vblankstart, 8, 0x01, 3) |
Jiri Slaby87d06132007-10-18 23:40:27 -0700613 ENCODE_BIT(1, 0, 0x01, 4) |
Krzysztof Helt532237e2007-10-18 23:40:28 -0700614 ENCODE_BIT(Vtotal, 9, 0x01, 5) |
Jiri Slaby87d06132007-10-18 23:40:27 -0700615 ENCODE_BIT(Vdispend, 9, 0x01, 6) |
616 ENCODE_BIT(Vsyncstart, 9, 0x01, 7);
617 hw->crtc[9] = ENCODE_BIT(0, 0, 0x1f, 0) |
Krzysztof Helt532237e2007-10-18 23:40:28 -0700618 ENCODE_BIT(Vblankstart, 9, 0x01, 5) |
Jiri Slaby87d06132007-10-18 23:40:27 -0700619 ENCODE_BIT(1, 0, 0x01, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 hw->crtc[10] = Vsyncstart;
Jiri Slaby87d06132007-10-18 23:40:27 -0700621 hw->crtc[11] = ENCODE_BIT(Vsyncend, 0, 0x0f, 0) |
622 ENCODE_BIT(1, 0, 0x01, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 hw->crtc[12] = Vdispend;
624 hw->crtc[15] = Vblankstart;
625 hw->crtc[16] = Vblankend;
626 hw->crtc[18] = 0xff;
627
628 /*
629 * overflow - graphics reg 0x11
630 * 0=VTOTAL:10 1=VDEND:10 2=VRSTART:10 3=VBSTART:10
631 * 4=LINECOMP:10 5-IVIDEO 6=FIXCNT
632 */
633 hw->crtc_ofl =
Krzysztof Helt532237e2007-10-18 23:40:28 -0700634 ENCODE_BIT(Vtotal, 10, 0x01, 0) |
635 ENCODE_BIT(Vdispend, 10, 0x01, 1) |
636 ENCODE_BIT(Vsyncstart, 10, 0x01, 2) |
637 ENCODE_BIT(Vblankstart, 10, 0x01, 3) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 EXT_CRT_VRTOFL_LINECOMP10;
639
640 /* woody: set the interlaced bit... */
641 /* FIXME: what about doublescan? */
642 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
643 hw->crtc_ofl |= EXT_CRT_VRTOFL_INTERLACE;
644
645 return 0;
646}
647
648/*
649 * The following was discovered by a good monitor, bit twiddling, theorising
650 * and but mostly luck. Strangely, it looks like everyone elses' PLL!
651 *
652 * Clock registers:
653 * fclock = fpll / div2
654 * fpll = fref * mult / div1
655 * where:
656 * fref = 14.318MHz (69842ps)
657 * mult = reg0xb0.7:0
658 * div1 = (reg0xb1.5:0 + 1)
659 * div2 = 2^(reg0xb1.7:6)
660 * fpll should be between 115 and 260 MHz
661 * (8696ps and 3846ps)
662 */
663static int
664cyber2000fb_decode_clock(struct par_info *hw, struct cfb_info *cfb,
665 struct fb_var_screeninfo *var)
666{
667 u_long pll_ps = var->pixclock;
668 const u_long ref_ps = cfb->ref_ps;
669 u_int div2, t_div1, best_div1, best_mult;
670 int best_diff;
671 int vco;
672
673 /*
674 * Step 1:
675 * find div2 such that 115MHz < fpll < 260MHz
676 * and 0 <= div2 < 4
677 */
678 for (div2 = 0; div2 < 4; div2++) {
679 u_long new_pll;
680
681 new_pll = pll_ps / cfb->divisors[div2];
682 if (8696 > new_pll && new_pll > 3846) {
683 pll_ps = new_pll;
684 break;
685 }
686 }
687
688 if (div2 == 4)
689 return -EINVAL;
690
691 /*
692 * Step 2:
693 * Given pll_ps and ref_ps, find:
694 * pll_ps * 0.995 < pll_ps_calc < pll_ps * 1.005
695 * where { 1 < best_div1 < 32, 1 < best_mult < 256 }
696 * pll_ps_calc = best_div1 / (ref_ps * best_mult)
697 */
698 best_diff = 0x7fffffff;
Russell Kingfcd3c772011-01-28 21:03:43 +0000699 best_mult = 2;
700 best_div1 = 32;
701 for (t_div1 = 2; t_div1 < 32; t_div1 += 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 u_int rr, t_mult, t_pll_ps;
703 int diff;
704
705 /*
706 * Find the multiplier for this divisor
707 */
708 rr = ref_ps * t_div1;
709 t_mult = (rr + pll_ps / 2) / pll_ps;
710
711 /*
712 * Is the multiplier within the correct range?
713 */
714 if (t_mult > 256 || t_mult < 2)
715 continue;
716
717 /*
718 * Calculate the actual clock period from this multiplier
719 * and divisor, and estimate the error.
720 */
721 t_pll_ps = (rr + t_mult / 2) / t_mult;
722 diff = pll_ps - t_pll_ps;
723 if (diff < 0)
724 diff = -diff;
725
726 if (diff < best_diff) {
727 best_diff = diff;
728 best_mult = t_mult;
729 best_div1 = t_div1;
730 }
731
732 /*
733 * If we hit an exact value, there is no point in continuing.
734 */
735 if (diff == 0)
736 break;
737 }
738
739 /*
740 * Step 3:
741 * combine values
742 */
743 hw->clock_mult = best_mult - 1;
744 hw->clock_div = div2 << 6 | (best_div1 - 1);
745
746 vco = ref_ps * best_div1 / best_mult;
747 if ((ref_ps == 40690) && (vco < 5556))
748 /* Set VFSEL when VCO > 180MHz (5.556 ps). */
749 hw->clock_div |= EXT_DCLK_DIV_VFSEL;
750
751 return 0;
752}
753
754/*
755 * Set the User Defined Part of the Display
756 */
757static int
758cyber2000fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
759{
760 struct cfb_info *cfb = (struct cfb_info *)info;
761 struct par_info hw;
762 unsigned int mem;
763 int err;
764
765 var->transp.msb_right = 0;
766 var->red.msb_right = 0;
767 var->green.msb_right = 0;
768 var->blue.msb_right = 0;
Krzysztof Helt532237e2007-10-18 23:40:28 -0700769 var->transp.offset = 0;
770 var->transp.length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772 switch (var->bits_per_pixel) {
773 case 8: /* PSEUDOCOLOUR, 256 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 var->red.offset = 0;
775 var->red.length = 8;
776 var->green.offset = 0;
777 var->green.length = 8;
778 var->blue.offset = 0;
779 var->blue.length = 8;
780 break;
781
782 case 16:/* DIRECTCOLOUR, 64k or 32k */
783 switch (var->green.length) {
784 case 6: /* RGB565, 64k */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 var->red.offset = 11;
786 var->red.length = 5;
787 var->green.offset = 5;
788 var->green.length = 6;
789 var->blue.offset = 0;
790 var->blue.length = 5;
791 break;
792
793 default:
794 case 5: /* RGB555, 32k */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 var->red.offset = 10;
796 var->red.length = 5;
797 var->green.offset = 5;
798 var->green.length = 5;
799 var->blue.offset = 0;
800 var->blue.length = 5;
801 break;
802
803 case 4: /* RGB444, 4k + transparency? */
804 var->transp.offset = 12;
805 var->transp.length = 4;
806 var->red.offset = 8;
807 var->red.length = 4;
808 var->green.offset = 4;
809 var->green.length = 4;
810 var->blue.offset = 0;
811 var->blue.length = 4;
812 break;
813 }
814 break;
815
816 case 24:/* TRUECOLOUR, 16m */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 var->red.offset = 16;
818 var->red.length = 8;
819 var->green.offset = 8;
820 var->green.length = 8;
821 var->blue.offset = 0;
822 var->blue.length = 8;
823 break;
824
825 case 32:/* TRUECOLOUR, 16m */
826 var->transp.offset = 24;
827 var->transp.length = 8;
828 var->red.offset = 16;
829 var->red.length = 8;
830 var->green.offset = 8;
831 var->green.length = 8;
832 var->blue.offset = 0;
833 var->blue.length = 8;
834 break;
835
836 default:
837 return -EINVAL;
838 }
839
840 mem = var->xres_virtual * var->yres_virtual * (var->bits_per_pixel / 8);
841 if (mem > cfb->fb.fix.smem_len)
842 var->yres_virtual = cfb->fb.fix.smem_len * 8 /
Krzysztof Helt532237e2007-10-18 23:40:28 -0700843 (var->bits_per_pixel * var->xres_virtual);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 if (var->yres > var->yres_virtual)
846 var->yres = var->yres_virtual;
847 if (var->xres > var->xres_virtual)
848 var->xres = var->xres_virtual;
849
850 err = cyber2000fb_decode_clock(&hw, cfb, var);
851 if (err)
852 return err;
853
854 err = cyber2000fb_decode_crtc(&hw, cfb, var);
855 if (err)
856 return err;
857
858 return 0;
859}
860
861static int cyber2000fb_set_par(struct fb_info *info)
862{
863 struct cfb_info *cfb = (struct cfb_info *)info;
864 struct fb_var_screeninfo *var = &cfb->fb.var;
865 struct par_info hw;
866 unsigned int mem;
867
868 hw.width = var->xres_virtual;
869 hw.ramdac = RAMDAC_VREFEN | RAMDAC_DAC8BIT;
870
871 switch (var->bits_per_pixel) {
872 case 8:
873 hw.co_pixfmt = CO_PIXFMT_8BPP;
874 hw.pitch = hw.width >> 3;
875 hw.extseqmisc = EXT_SEQ_MISC_8;
876 break;
877
878 case 16:
879 hw.co_pixfmt = CO_PIXFMT_16BPP;
880 hw.pitch = hw.width >> 2;
881
882 switch (var->green.length) {
883 case 6: /* RGB565, 64k */
884 hw.extseqmisc = EXT_SEQ_MISC_16_RGB565;
885 break;
886 case 5: /* RGB555, 32k */
887 hw.extseqmisc = EXT_SEQ_MISC_16_RGB555;
888 break;
889 case 4: /* RGB444, 4k + transparency? */
890 hw.extseqmisc = EXT_SEQ_MISC_16_RGB444;
891 break;
892 default:
893 BUG();
894 }
Jan Rinzec2ec21c2007-11-08 21:51:05 +0100895 break;
896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 case 24:/* TRUECOLOUR, 16m */
898 hw.co_pixfmt = CO_PIXFMT_24BPP;
899 hw.width *= 3;
900 hw.pitch = hw.width >> 3;
901 hw.ramdac |= (RAMDAC_BYPASS | RAMDAC_RAMPWRDN);
902 hw.extseqmisc = EXT_SEQ_MISC_24_RGB888;
903 break;
904
905 case 32:/* TRUECOLOUR, 16m */
906 hw.co_pixfmt = CO_PIXFMT_32BPP;
907 hw.pitch = hw.width >> 1;
908 hw.ramdac |= (RAMDAC_BYPASS | RAMDAC_RAMPWRDN);
909 hw.extseqmisc = EXT_SEQ_MISC_32;
910 break;
911
912 default:
913 BUG();
914 }
915
916 /*
917 * Sigh, this is absolutely disgusting, but caused by
918 * the way the fbcon developers want to separate out
919 * the "checking" and the "setting" of the video mode.
920 *
921 * If the mode is not suitable for the hardware here,
922 * we can't prevent it being set by returning an error.
923 *
924 * In theory, since NetWinders contain just one VGA card,
925 * we should never end up hitting this problem.
926 */
927 BUG_ON(cyber2000fb_decode_clock(&hw, cfb, var) != 0);
928 BUG_ON(cyber2000fb_decode_crtc(&hw, cfb, var) != 0);
929
930 hw.width -= 1;
931 hw.fetch = hw.pitch;
932 if (!(cfb->mem_ctl2 & MEM_CTL2_64BIT))
933 hw.fetch <<= 1;
934 hw.fetch += 1;
935
Krzysztof Helt532237e2007-10-18 23:40:28 -0700936 cfb->fb.fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 /*
939 * Same here - if the size of the video mode exceeds the
940 * available RAM, we can't prevent this mode being set.
941 *
942 * In theory, since NetWinders contain just one VGA card,
943 * we should never end up hitting this problem.
944 */
945 mem = cfb->fb.fix.line_length * var->yres_virtual;
946 BUG_ON(mem > cfb->fb.fix.smem_len);
947
948 /*
949 * 8bpp displays are always pseudo colour. 16bpp and above
950 * are direct colour or true colour, depending on whether
951 * the RAMDAC palettes are bypassed. (Direct colour has
952 * palettes, true colour does not.)
953 */
954 if (var->bits_per_pixel == 8)
955 cfb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
956 else if (hw.ramdac & RAMDAC_BYPASS)
957 cfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
958 else
959 cfb->fb.fix.visual = FB_VISUAL_DIRECTCOLOR;
960
961 cyber2000fb_set_timing(cfb, &hw);
962 cyber2000fb_update_start(cfb, var);
963
964 return 0;
965}
966
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967/*
968 * Pan or Wrap the Display
969 */
970static int
971cyber2000fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
972{
973 struct cfb_info *cfb = (struct cfb_info *)info;
974
975 if (cyber2000fb_update_start(cfb, var))
976 return -EINVAL;
977
978 cfb->fb.var.xoffset = var->xoffset;
979 cfb->fb.var.yoffset = var->yoffset;
980
981 if (var->vmode & FB_VMODE_YWRAP) {
982 cfb->fb.var.vmode |= FB_VMODE_YWRAP;
983 } else {
984 cfb->fb.var.vmode &= ~FB_VMODE_YWRAP;
985 }
986
987 return 0;
988}
989
990/*
991 * (Un)Blank the display.
992 *
993 * Blank the screen if blank_mode != 0, else unblank. If
994 * blank == NULL then the caller blanks by setting the CLUT
995 * (Color Look Up Table) to all black. Return 0 if blanking
996 * succeeded, != 0 if un-/blanking failed due to e.g. a
997 * video mode which doesn't support it. Implements VESA
998 * suspend and powerdown modes on hardware that supports
999 * disabling hsync/vsync:
1000 * blank_mode == 2: suspend vsync
1001 * blank_mode == 3: suspend hsync
1002 * blank_mode == 4: powerdown
1003 *
1004 * wms...Enable VESA DMPS compatible powerdown mode
1005 * run "setterm -powersave powerdown" to take advantage
1006 */
1007static int cyber2000fb_blank(int blank, struct fb_info *info)
1008{
1009 struct cfb_info *cfb = (struct cfb_info *)info;
1010 unsigned int sync = 0;
1011 int i;
1012
1013 switch (blank) {
1014 case FB_BLANK_POWERDOWN: /* powerdown - both sync lines down */
1015 sync = EXT_SYNC_CTL_VS_0 | EXT_SYNC_CTL_HS_0;
Krzysztof Helt532237e2007-10-18 23:40:28 -07001016 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 case FB_BLANK_HSYNC_SUSPEND: /* hsync off */
1018 sync = EXT_SYNC_CTL_VS_NORMAL | EXT_SYNC_CTL_HS_0;
Krzysztof Helt532237e2007-10-18 23:40:28 -07001019 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 case FB_BLANK_VSYNC_SUSPEND: /* vsync off */
1021 sync = EXT_SYNC_CTL_VS_0 | EXT_SYNC_CTL_HS_NORMAL;
1022 break;
Krzysztof Helt532237e2007-10-18 23:40:28 -07001023 case FB_BLANK_NORMAL: /* soft blank */
1024 default: /* unblank */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 break;
1026 }
1027
1028 cyber2000_grphw(EXT_SYNC_CTL, sync, cfb);
1029
1030 if (blank <= 1) {
1031 /* turn on ramdacs */
Krzysztof Helt532237e2007-10-18 23:40:28 -07001032 cfb->ramdac_powerdown &= ~(RAMDAC_DACPWRDN | RAMDAC_BYPASS |
1033 RAMDAC_RAMPWRDN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 cyber2000fb_write_ramdac_ctrl(cfb);
1035 }
1036
1037 /*
1038 * Soft blank/unblank the display.
1039 */
1040 if (blank) { /* soft blank */
1041 for (i = 0; i < NR_PALETTE; i++) {
1042 cyber2000fb_writeb(i, 0x3c8, cfb);
1043 cyber2000fb_writeb(0, 0x3c9, cfb);
1044 cyber2000fb_writeb(0, 0x3c9, cfb);
1045 cyber2000fb_writeb(0, 0x3c9, cfb);
1046 }
1047 } else { /* unblank */
1048 for (i = 0; i < NR_PALETTE; i++) {
1049 cyber2000fb_writeb(i, 0x3c8, cfb);
1050 cyber2000fb_writeb(cfb->palette[i].red, 0x3c9, cfb);
1051 cyber2000fb_writeb(cfb->palette[i].green, 0x3c9, cfb);
1052 cyber2000fb_writeb(cfb->palette[i].blue, 0x3c9, cfb);
1053 }
1054 }
1055
1056 if (blank >= 2) {
1057 /* turn off ramdacs */
Krzysztof Helt532237e2007-10-18 23:40:28 -07001058 cfb->ramdac_powerdown |= RAMDAC_DACPWRDN | RAMDAC_BYPASS |
1059 RAMDAC_RAMPWRDN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 cyber2000fb_write_ramdac_ctrl(cfb);
1061 }
1062
1063 return 0;
1064}
1065
1066static struct fb_ops cyber2000fb_ops = {
1067 .owner = THIS_MODULE,
1068 .fb_check_var = cyber2000fb_check_var,
1069 .fb_set_par = cyber2000fb_set_par,
1070 .fb_setcolreg = cyber2000fb_setcolreg,
1071 .fb_blank = cyber2000fb_blank,
1072 .fb_pan_display = cyber2000fb_pan_display,
1073 .fb_fillrect = cyber2000fb_fillrect,
1074 .fb_copyarea = cyber2000fb_copyarea,
1075 .fb_imageblit = cyber2000fb_imageblit,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .fb_sync = cyber2000fb_sync,
1077};
1078
1079/*
1080 * This is the only "static" reference to the internal data structures
1081 * of this driver. It is here solely at the moment to support the other
1082 * CyberPro modules external to this driver.
1083 */
Krzysztof Helt532237e2007-10-18 23:40:28 -07001084static struct cfb_info *int_cfb_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
1086/*
1087 * Enable access to the extended registers
1088 */
1089void cyber2000fb_enable_extregs(struct cfb_info *cfb)
1090{
1091 cfb->func_use_count += 1;
1092
1093 if (cfb->func_use_count == 1) {
1094 int old;
1095
1096 old = cyber2000_grphr(EXT_FUNC_CTL, cfb);
1097 old |= EXT_FUNC_CTL_EXTREGENBL;
1098 cyber2000_grphw(EXT_FUNC_CTL, old, cfb);
1099 }
1100}
Krzysztof Helt532237e2007-10-18 23:40:28 -07001101EXPORT_SYMBOL(cyber2000fb_enable_extregs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103/*
1104 * Disable access to the extended registers
1105 */
1106void cyber2000fb_disable_extregs(struct cfb_info *cfb)
1107{
1108 if (cfb->func_use_count == 1) {
1109 int old;
1110
1111 old = cyber2000_grphr(EXT_FUNC_CTL, cfb);
1112 old &= ~EXT_FUNC_CTL_EXTREGENBL;
1113 cyber2000_grphw(EXT_FUNC_CTL, old, cfb);
1114 }
1115
1116 if (cfb->func_use_count == 0)
1117 printk(KERN_ERR "disable_extregs: count = 0\n");
1118 else
1119 cfb->func_use_count -= 1;
1120}
Krzysztof Helt532237e2007-10-18 23:40:28 -07001121EXPORT_SYMBOL(cyber2000fb_disable_extregs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123void cyber2000fb_get_fb_var(struct cfb_info *cfb, struct fb_var_screeninfo *var)
1124{
1125 memcpy(var, &cfb->fb.var, sizeof(struct fb_var_screeninfo));
1126}
Krzysztof Helt532237e2007-10-18 23:40:28 -07001127EXPORT_SYMBOL(cyber2000fb_get_fb_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129/*
1130 * Attach a capture/tv driver to the core CyberX0X0 driver.
1131 */
1132int cyber2000fb_attach(struct cyberpro_info *info, int idx)
1133{
1134 if (int_cfb_info != NULL) {
1135 info->dev = int_cfb_info->dev;
1136 info->regs = int_cfb_info->regs;
1137 info->fb = int_cfb_info->fb.screen_base;
1138 info->fb_size = int_cfb_info->fb.fix.smem_len;
1139 info->enable_extregs = cyber2000fb_enable_extregs;
1140 info->disable_extregs = cyber2000fb_disable_extregs;
Krzysztof Helt532237e2007-10-18 23:40:28 -07001141 info->info = int_cfb_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Krzysztof Helt532237e2007-10-18 23:40:28 -07001143 strlcpy(info->dev_name, int_cfb_info->fb.fix.id,
1144 sizeof(info->dev_name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 }
1146
1147 return int_cfb_info != NULL;
1148}
Krzysztof Helt532237e2007-10-18 23:40:28 -07001149EXPORT_SYMBOL(cyber2000fb_attach);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151/*
1152 * Detach a capture/tv driver from the core CyberX0X0 driver.
1153 */
1154void cyber2000fb_detach(int idx)
1155{
1156}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157EXPORT_SYMBOL(cyber2000fb_detach);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Ondrej Zarye5dedf82010-08-11 21:48:03 +02001159#ifdef CONFIG_FB_CYBER2000_DDC
1160
1161#define DDC_REG 0xb0
1162#define DDC_SCL_OUT (1 << 0)
1163#define DDC_SDA_OUT (1 << 4)
1164#define DDC_SCL_IN (1 << 2)
1165#define DDC_SDA_IN (1 << 6)
1166
1167static void cyber2000fb_enable_ddc(struct cfb_info *cfb)
1168{
1169 spin_lock(&cfb->reg_b0_lock);
1170 cyber2000fb_writew(0x1bf, 0x3ce, cfb);
1171}
1172
1173static void cyber2000fb_disable_ddc(struct cfb_info *cfb)
1174{
1175 cyber2000fb_writew(0x0bf, 0x3ce, cfb);
1176 spin_unlock(&cfb->reg_b0_lock);
1177}
1178
1179
1180static void cyber2000fb_ddc_setscl(void *data, int val)
1181{
1182 struct cfb_info *cfb = data;
1183 unsigned char reg;
1184
1185 cyber2000fb_enable_ddc(cfb);
1186 reg = cyber2000_grphr(DDC_REG, cfb);
1187 if (!val) /* bit is inverted */
1188 reg |= DDC_SCL_OUT;
1189 else
1190 reg &= ~DDC_SCL_OUT;
1191 cyber2000_grphw(DDC_REG, reg, cfb);
1192 cyber2000fb_disable_ddc(cfb);
1193}
1194
1195static void cyber2000fb_ddc_setsda(void *data, int val)
1196{
1197 struct cfb_info *cfb = data;
1198 unsigned char reg;
1199
1200 cyber2000fb_enable_ddc(cfb);
1201 reg = cyber2000_grphr(DDC_REG, cfb);
1202 if (!val) /* bit is inverted */
1203 reg |= DDC_SDA_OUT;
1204 else
1205 reg &= ~DDC_SDA_OUT;
1206 cyber2000_grphw(DDC_REG, reg, cfb);
1207 cyber2000fb_disable_ddc(cfb);
1208}
1209
1210static int cyber2000fb_ddc_getscl(void *data)
1211{
1212 struct cfb_info *cfb = data;
1213 int retval;
1214
1215 cyber2000fb_enable_ddc(cfb);
1216 retval = !!(cyber2000_grphr(DDC_REG, cfb) & DDC_SCL_IN);
1217 cyber2000fb_disable_ddc(cfb);
1218
1219 return retval;
1220}
1221
1222static int cyber2000fb_ddc_getsda(void *data)
1223{
1224 struct cfb_info *cfb = data;
1225 int retval;
1226
1227 cyber2000fb_enable_ddc(cfb);
1228 retval = !!(cyber2000_grphr(DDC_REG, cfb) & DDC_SDA_IN);
1229 cyber2000fb_disable_ddc(cfb);
1230
1231 return retval;
1232}
1233
1234static int __devinit cyber2000fb_setup_ddc_bus(struct cfb_info *cfb)
1235{
1236 spin_lock_init(&cfb->reg_b0_lock);
1237
1238 strlcpy(cfb->ddc_adapter.name, cfb->fb.fix.id,
1239 sizeof(cfb->ddc_adapter.name));
1240 cfb->ddc_adapter.owner = THIS_MODULE;
1241 cfb->ddc_adapter.class = I2C_CLASS_DDC;
1242 cfb->ddc_adapter.algo_data = &cfb->ddc_algo;
1243 cfb->ddc_adapter.dev.parent = &cfb->dev->dev;
1244 cfb->ddc_algo.setsda = cyber2000fb_ddc_setsda;
1245 cfb->ddc_algo.setscl = cyber2000fb_ddc_setscl;
1246 cfb->ddc_algo.getsda = cyber2000fb_ddc_getsda;
1247 cfb->ddc_algo.getscl = cyber2000fb_ddc_getscl;
1248 cfb->ddc_algo.udelay = 10;
1249 cfb->ddc_algo.timeout = 20;
1250 cfb->ddc_algo.data = cfb;
1251
1252 i2c_set_adapdata(&cfb->ddc_adapter, cfb);
1253
1254 return i2c_bit_add_bus(&cfb->ddc_adapter);
1255}
1256#endif /* CONFIG_FB_CYBER2000_DDC */
1257
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258/*
1259 * These parameters give
1260 * 640x480, hsync 31.5kHz, vsync 60Hz
1261 */
1262static struct fb_videomode __devinitdata cyber2000fb_default_mode = {
1263 .refresh = 60,
1264 .xres = 640,
1265 .yres = 480,
1266 .pixclock = 39722,
1267 .left_margin = 56,
1268 .right_margin = 16,
1269 .upper_margin = 34,
1270 .lower_margin = 9,
1271 .hsync_len = 88,
1272 .vsync_len = 2,
1273 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
1274 .vmode = FB_VMODE_NONINTERLACED
1275};
1276
1277static char igs_regs[] = {
1278 EXT_CRT_IRQ, 0,
1279 EXT_CRT_TEST, 0,
1280 EXT_SYNC_CTL, 0,
1281 EXT_SEG_WRITE_PTR, 0,
1282 EXT_SEG_READ_PTR, 0,
1283 EXT_BIU_MISC, EXT_BIU_MISC_LIN_ENABLE |
1284 EXT_BIU_MISC_COP_ENABLE |
1285 EXT_BIU_MISC_COP_BFC,
1286 EXT_FUNC_CTL, 0,
1287 CURS_H_START, 0,
1288 CURS_H_START + 1, 0,
1289 CURS_H_PRESET, 0,
1290 CURS_V_START, 0,
1291 CURS_V_START + 1, 0,
1292 CURS_V_PRESET, 0,
1293 CURS_CTL, 0,
1294 EXT_ATTRIB_CTL, EXT_ATTRIB_CTL_EXT,
1295 EXT_OVERSCAN_RED, 0,
1296 EXT_OVERSCAN_GREEN, 0,
1297 EXT_OVERSCAN_BLUE, 0,
1298
1299 /* some of these are questionable when we have a BIOS */
1300 EXT_MEM_CTL0, EXT_MEM_CTL0_7CLK |
1301 EXT_MEM_CTL0_RAS_1 |
1302 EXT_MEM_CTL0_MULTCAS,
1303 EXT_HIDDEN_CTL1, 0x30,
1304 EXT_FIFO_CTL, 0x0b,
1305 EXT_FIFO_CTL + 1, 0x17,
1306 0x76, 0x00,
1307 EXT_HIDDEN_CTL4, 0xc8
1308};
1309
1310/*
1311 * Initialise the CyberPro hardware. On the CyberPro5XXXX,
1312 * ensure that we're using the correct PLL (5XXX's may be
1313 * programmed to use an additional set of PLLs.)
1314 */
1315static void cyberpro_init_hw(struct cfb_info *cfb)
1316{
1317 int i;
1318
1319 for (i = 0; i < sizeof(igs_regs); i += 2)
Krzysztof Helt532237e2007-10-18 23:40:28 -07001320 cyber2000_grphw(igs_regs[i], igs_regs[i + 1], cfb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 if (cfb->id == ID_CYBERPRO_5000) {
1323 unsigned char val;
1324 cyber2000fb_writeb(0xba, 0x3ce, cfb);
1325 val = cyber2000fb_readb(0x3cf, cfb) & 0x80;
1326 cyber2000fb_writeb(val, 0x3cf, cfb);
1327 }
1328}
1329
Krzysztof Helt532237e2007-10-18 23:40:28 -07001330static struct cfb_info __devinit *cyberpro_alloc_fb_info(unsigned int id,
1331 char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332{
1333 struct cfb_info *cfb;
1334
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001335 cfb = kzalloc(sizeof(struct cfb_info), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 if (!cfb)
1337 return NULL;
1338
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
1340 cfb->id = id;
1341
1342 if (id == ID_CYBERPRO_5000)
Krzysztof Helt532237e2007-10-18 23:40:28 -07001343 cfb->ref_ps = 40690; /* 24.576 MHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 else
Krzysztof Helt532237e2007-10-18 23:40:28 -07001345 cfb->ref_ps = 69842; /* 14.31818 MHz (69841?) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
1347 cfb->divisors[0] = 1;
1348 cfb->divisors[1] = 2;
1349 cfb->divisors[2] = 4;
1350
1351 if (id == ID_CYBERPRO_2000)
1352 cfb->divisors[3] = 8;
1353 else
1354 cfb->divisors[3] = 6;
1355
1356 strcpy(cfb->fb.fix.id, name);
1357
1358 cfb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
1359 cfb->fb.fix.type_aux = 0;
1360 cfb->fb.fix.xpanstep = 0;
1361 cfb->fb.fix.ypanstep = 1;
1362 cfb->fb.fix.ywrapstep = 0;
1363
1364 switch (id) {
1365 case ID_IGA_1682:
1366 cfb->fb.fix.accel = 0;
1367 break;
1368
1369 case ID_CYBERPRO_2000:
1370 cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER2000;
1371 break;
1372
1373 case ID_CYBERPRO_2010:
1374 cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER2010;
1375 break;
1376
1377 case ID_CYBERPRO_5000:
1378 cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER5000;
1379 break;
1380 }
1381
1382 cfb->fb.var.nonstd = 0;
1383 cfb->fb.var.activate = FB_ACTIVATE_NOW;
1384 cfb->fb.var.height = -1;
1385 cfb->fb.var.width = -1;
1386 cfb->fb.var.accel_flags = FB_ACCELF_TEXT;
1387
1388 cfb->fb.fbops = &cyber2000fb_ops;
1389 cfb->fb.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
Russell Kingeca02b02005-05-03 12:23:56 +01001390 cfb->fb.pseudo_palette = cfb->pseudo_palette;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
1392 fb_alloc_cmap(&cfb->fb.cmap, NR_PALETTE, 0);
1393
1394 return cfb;
1395}
1396
Krzysztof Helt532237e2007-10-18 23:40:28 -07001397static void cyberpro_free_fb_info(struct cfb_info *cfb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398{
1399 if (cfb) {
1400 /*
1401 * Free the colourmap
1402 */
1403 fb_alloc_cmap(&cfb->fb.cmap, 0, 0);
1404
1405 kfree(cfb);
1406 }
1407}
1408
1409/*
1410 * Parse Cyber2000fb options. Usage:
1411 * video=cyber2000:font:fontname
1412 */
1413#ifndef MODULE
Krzysztof Helt532237e2007-10-18 23:40:28 -07001414static int cyber2000fb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
1416 char *opt;
1417
1418 if (!options || !*options)
1419 return 0;
1420
1421 while ((opt = strsep(&options, ",")) != NULL) {
1422 if (!*opt)
1423 continue;
1424
1425 if (strncmp(opt, "font:", 5) == 0) {
1426 static char default_font_storage[40];
1427
Krzysztof Helt532237e2007-10-18 23:40:28 -07001428 strlcpy(default_font_storage, opt + 5,
1429 sizeof(default_font_storage));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 default_font = default_font_storage;
1431 continue;
1432 }
1433
1434 printk(KERN_ERR "CyberPro20x0: unknown parameter: %s\n", opt);
1435 }
1436 return 0;
1437}
1438#endif /* MODULE */
1439
1440/*
1441 * The CyberPro chips can be placed on many different bus types.
1442 * This probe function is common to all bus types. The bus-specific
1443 * probe function is expected to have:
1444 * - enabled access to the linear memory region
1445 * - memory mapped access to the registers
1446 * - initialised mem_ctl1 and mem_ctl2 appropriately.
1447 */
1448static int __devinit cyberpro_common_probe(struct cfb_info *cfb)
1449{
1450 u_long smem_size;
1451 u_int h_sync, v_sync;
1452 int err;
1453
1454 cyberpro_init_hw(cfb);
1455
1456 /*
1457 * Get the video RAM size and width from the VGA register.
1458 * This should have been already initialised by the BIOS,
1459 * but if it's garbage, claim default 1MB VRAM (woody)
1460 */
1461 cfb->mem_ctl1 = cyber2000_grphr(EXT_MEM_CTL1, cfb);
1462 cfb->mem_ctl2 = cyber2000_grphr(EXT_MEM_CTL2, cfb);
1463
1464 /*
1465 * Determine the size of the memory.
1466 */
1467 switch (cfb->mem_ctl2 & MEM_CTL2_SIZE_MASK) {
Krzysztof Helt532237e2007-10-18 23:40:28 -07001468 case MEM_CTL2_SIZE_4MB:
1469 smem_size = 0x00400000;
1470 break;
1471 case MEM_CTL2_SIZE_2MB:
1472 smem_size = 0x00200000;
1473 break;
1474 case MEM_CTL2_SIZE_1MB:
1475 smem_size = 0x00100000;
1476 break;
1477 default:
1478 smem_size = 0x00100000;
1479 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 }
1481
1482 cfb->fb.fix.smem_len = smem_size;
1483 cfb->fb.fix.mmio_len = MMIO_SIZE;
1484 cfb->fb.screen_base = cfb->region;
1485
Ondrej Zarye5dedf82010-08-11 21:48:03 +02001486#ifdef CONFIG_FB_CYBER2000_DDC
1487 if (cyber2000fb_setup_ddc_bus(cfb) == 0)
1488 cfb->ddc_registered = true;
1489#endif
1490
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 err = -EINVAL;
1492 if (!fb_find_mode(&cfb->fb.var, &cfb->fb, NULL, NULL, 0,
Krzysztof Helt532237e2007-10-18 23:40:28 -07001493 &cyber2000fb_default_mode, 8)) {
1494 printk(KERN_ERR "%s: no valid mode found\n", cfb->fb.fix.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 goto failed;
1496 }
1497
1498 cfb->fb.var.yres_virtual = cfb->fb.fix.smem_len * 8 /
1499 (cfb->fb.var.bits_per_pixel * cfb->fb.var.xres_virtual);
1500
1501 if (cfb->fb.var.yres_virtual < cfb->fb.var.yres)
1502 cfb->fb.var.yres_virtual = cfb->fb.var.yres;
1503
Krzysztof Helt532237e2007-10-18 23:40:28 -07001504/* fb_set_var(&cfb->fb.var, -1, &cfb->fb); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
1506 /*
1507 * Calculate the hsync and vsync frequencies. Note that
1508 * we split the 1e12 constant up so that we can preserve
1509 * the precision and fit the results into 32-bit registers.
1510 * (1953125000 * 512 = 1e12)
1511 */
1512 h_sync = 1953125000 / cfb->fb.var.pixclock;
1513 h_sync = h_sync * 512 / (cfb->fb.var.xres + cfb->fb.var.left_margin +
1514 cfb->fb.var.right_margin + cfb->fb.var.hsync_len);
1515 v_sync = h_sync / (cfb->fb.var.yres + cfb->fb.var.upper_margin +
1516 cfb->fb.var.lower_margin + cfb->fb.var.vsync_len);
1517
1518 printk(KERN_INFO "%s: %dKiB VRAM, using %dx%d, %d.%03dkHz, %dHz\n",
1519 cfb->fb.fix.id, cfb->fb.fix.smem_len >> 10,
1520 cfb->fb.var.xres, cfb->fb.var.yres,
1521 h_sync / 1000, h_sync % 1000, v_sync);
1522
1523 if (cfb->dev)
1524 cfb->fb.device = &cfb->dev->dev;
1525 err = register_framebuffer(&cfb->fb);
1526
1527failed:
Ondrej Zarye5dedf82010-08-11 21:48:03 +02001528#ifdef CONFIG_FB_CYBER2000_DDC
1529 if (err && cfb->ddc_registered)
1530 i2c_del_adapter(&cfb->ddc_adapter);
1531#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 return err;
1533}
1534
1535static void cyberpro_common_resume(struct cfb_info *cfb)
1536{
1537 cyberpro_init_hw(cfb);
1538
1539 /*
1540 * Reprogram the MEM_CTL1 and MEM_CTL2 registers
1541 */
1542 cyber2000_grphw(EXT_MEM_CTL1, cfb->mem_ctl1, cfb);
1543 cyber2000_grphw(EXT_MEM_CTL2, cfb->mem_ctl2, cfb);
1544
1545 /*
1546 * Restore the old video mode and the palette.
1547 * We also need to tell fbcon to redraw the console.
1548 */
1549 cyber2000fb_set_par(&cfb->fb);
1550}
1551
1552#ifdef CONFIG_ARCH_SHARK
1553
Alexander Schulzeab184c2009-01-08 18:05:58 +01001554#include <mach/framebuffer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Krzysztof Helt532237e2007-10-18 23:40:28 -07001556static int __devinit cyberpro_vl_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
1558 struct cfb_info *cfb;
1559 int err = -ENOMEM;
1560
Krzysztof Helt532237e2007-10-18 23:40:28 -07001561 if (!request_mem_region(FB_START, FB_SIZE, "CyberPro2010"))
1562 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 cfb = cyberpro_alloc_fb_info(ID_CYBERPRO_2010, "CyberPro2010");
1565 if (!cfb)
1566 goto failed_release;
1567
1568 cfb->dev = NULL;
Krzysztof Helt532237e2007-10-18 23:40:28 -07001569 cfb->region = ioremap(FB_START, FB_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 if (!cfb->region)
1571 goto failed_ioremap;
1572
1573 cfb->regs = cfb->region + MMIO_OFFSET;
1574 cfb->fb.fix.mmio_start = FB_START + MMIO_OFFSET;
1575 cfb->fb.fix.smem_start = FB_START;
1576
1577 /*
1578 * Bring up the hardware. This is expected to enable access
1579 * to the linear memory region, and allow access to the memory
1580 * mapped registers. Also, mem_ctl1 and mem_ctl2 must be
1581 * initialised.
1582 */
1583 cyber2000fb_writeb(0x18, 0x46e8, cfb);
1584 cyber2000fb_writeb(0x01, 0x102, cfb);
1585 cyber2000fb_writeb(0x08, 0x46e8, cfb);
1586 cyber2000fb_writeb(EXT_BIU_MISC, 0x3ce, cfb);
1587 cyber2000fb_writeb(EXT_BIU_MISC_LIN_ENABLE, 0x3cf, cfb);
1588
1589 cfb->mclk_mult = 0xdb;
1590 cfb->mclk_div = 0x54;
1591
1592 err = cyberpro_common_probe(cfb);
1593 if (err)
1594 goto failed;
1595
1596 if (int_cfb_info == NULL)
1597 int_cfb_info = cfb;
1598
1599 return 0;
1600
1601failed:
1602 iounmap(cfb->region);
1603failed_ioremap:
1604 cyberpro_free_fb_info(cfb);
1605failed_release:
Krzysztof Helt532237e2007-10-18 23:40:28 -07001606 release_mem_region(FB_START, FB_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
1608 return err;
1609}
1610#endif /* CONFIG_ARCH_SHARK */
1611
1612/*
1613 * PCI specific support.
1614 */
1615#ifdef CONFIG_PCI
1616/*
1617 * We need to wake up the CyberPro, and make sure its in linear memory
1618 * mode. Unfortunately, this is specific to the platform and card that
1619 * we are running on.
1620 *
1621 * On x86 and ARM, should we be initialising the CyberPro first via the
1622 * IO registers, and then the MMIO registers to catch all cases? Can we
1623 * end up in the situation where the chip is in MMIO mode, but not awake
1624 * on an x86 system?
1625 */
1626static int cyberpro_pci_enable_mmio(struct cfb_info *cfb)
1627{
1628 unsigned char val;
1629
1630#if defined(__sparc_v9__)
1631#error "You lose, consult DaveM."
1632#elif defined(__sparc__)
1633 /*
1634 * SPARC does not have an "outb" instruction, so we generate
1635 * I/O cycles storing into a reserved memory space at
1636 * physical address 0x3000000
1637 */
Al Virocd030662005-12-15 09:18:10 +00001638 unsigned char __iomem *iop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
1640 iop = ioremap(0x3000000, 0x5000);
1641 if (iop == NULL) {
David S. Miller89b409f2008-12-08 01:00:08 -08001642 printk(KERN_ERR "iga5000: cannot map I/O\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 return -ENOMEM;
1644 }
1645
1646 writeb(0x18, iop + 0x46e8);
1647 writeb(0x01, iop + 0x102);
1648 writeb(0x08, iop + 0x46e8);
1649 writeb(EXT_BIU_MISC, iop + 0x3ce);
1650 writeb(EXT_BIU_MISC_LIN_ENABLE, iop + 0x3cf);
1651
Al Virocd030662005-12-15 09:18:10 +00001652 iounmap(iop);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653#else
1654 /*
1655 * Most other machine types are "normal", so
1656 * we use the standard IO-based wakeup.
1657 */
1658 outb(0x18, 0x46e8);
1659 outb(0x01, 0x102);
1660 outb(0x08, 0x46e8);
1661 outb(EXT_BIU_MISC, 0x3ce);
1662 outb(EXT_BIU_MISC_LIN_ENABLE, 0x3cf);
1663#endif
1664
1665 /*
1666 * Allow the CyberPro to accept PCI burst accesses
1667 */
Woody Suwalskicd792aa2007-02-12 00:55:00 -08001668 if (cfb->id == ID_CYBERPRO_2010) {
Krzysztof Helt532237e2007-10-18 23:40:28 -07001669 printk(KERN_INFO "%s: NOT enabling PCI bursts\n",
1670 cfb->fb.fix.id);
Woody Suwalskicd792aa2007-02-12 00:55:00 -08001671 } else {
1672 val = cyber2000_grphr(EXT_BUS_CTL, cfb);
1673 if (!(val & EXT_BUS_CTL_PCIBURST_WRITE)) {
1674 printk(KERN_INFO "%s: enabling PCI bursts\n",
1675 cfb->fb.fix.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
Woody Suwalskicd792aa2007-02-12 00:55:00 -08001677 val |= EXT_BUS_CTL_PCIBURST_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Woody Suwalskicd792aa2007-02-12 00:55:00 -08001679 if (cfb->id == ID_CYBERPRO_5000)
1680 val |= EXT_BUS_CTL_PCIBURST_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
Woody Suwalskicd792aa2007-02-12 00:55:00 -08001682 cyber2000_grphw(EXT_BUS_CTL, val, cfb);
1683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 }
1685
1686 return 0;
1687}
1688
1689static int __devinit
1690cyberpro_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
1691{
1692 struct cfb_info *cfb;
1693 char name[16];
1694 int err;
1695
1696 sprintf(name, "CyberPro%4X", id->device);
1697
1698 err = pci_enable_device(dev);
1699 if (err)
1700 return err;
1701
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 err = -ENOMEM;
1703 cfb = cyberpro_alloc_fb_info(id->driver_data, name);
1704 if (!cfb)
1705 goto failed_release;
1706
Russell Kinged5a35a2009-12-24 13:36:21 +00001707 err = pci_request_regions(dev, cfb->fb.fix.id);
1708 if (err)
1709 goto failed_regions;
1710
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 cfb->dev = dev;
Arjan van de Ven3c36aa52009-01-06 14:42:28 -08001712 cfb->region = pci_ioremap_bar(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 if (!cfb->region)
1714 goto failed_ioremap;
1715
1716 cfb->regs = cfb->region + MMIO_OFFSET;
1717 cfb->fb.fix.mmio_start = pci_resource_start(dev, 0) + MMIO_OFFSET;
1718 cfb->fb.fix.smem_start = pci_resource_start(dev, 0);
1719
1720 /*
1721 * Bring up the hardware. This is expected to enable access
1722 * to the linear memory region, and allow access to the memory
1723 * mapped registers. Also, mem_ctl1 and mem_ctl2 must be
1724 * initialised.
1725 */
1726 err = cyberpro_pci_enable_mmio(cfb);
1727 if (err)
1728 goto failed;
1729
1730 /*
1731 * Use MCLK from BIOS. FIXME: what about hotplug?
1732 */
1733 cfb->mclk_mult = cyber2000_grphr(EXT_MCLK_MULT, cfb);
1734 cfb->mclk_div = cyber2000_grphr(EXT_MCLK_DIV, cfb);
1735
1736#ifdef __arm__
1737 /*
1738 * MCLK on the NetWinder and the Shark is fixed at 75MHz
1739 */
1740 if (machine_is_netwinder()) {
1741 cfb->mclk_mult = 0xdb;
1742 cfb->mclk_div = 0x54;
1743 }
1744#endif
1745
1746 err = cyberpro_common_probe(cfb);
1747 if (err)
1748 goto failed;
1749
1750 /*
1751 * Our driver data
1752 */
1753 pci_set_drvdata(dev, cfb);
1754 if (int_cfb_info == NULL)
1755 int_cfb_info = cfb;
1756
1757 return 0;
1758
1759failed:
1760 iounmap(cfb->region);
1761failed_ioremap:
Russell Kinged5a35a2009-12-24 13:36:21 +00001762 pci_release_regions(dev);
1763failed_regions:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 cyberpro_free_fb_info(cfb);
1765failed_release:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 return err;
1767}
1768
1769static void __devexit cyberpro_pci_remove(struct pci_dev *dev)
1770{
1771 struct cfb_info *cfb = pci_get_drvdata(dev);
1772
1773 if (cfb) {
1774 /*
1775 * If unregister_framebuffer fails, then
1776 * we will be leaving hooks that could cause
1777 * oopsen laying around.
1778 */
1779 if (unregister_framebuffer(&cfb->fb))
1780 printk(KERN_WARNING "%s: danger Will Robinson, "
1781 "danger danger! Oopsen imminent!\n",
1782 cfb->fb.fix.id);
Ondrej Zarye5dedf82010-08-11 21:48:03 +02001783#ifdef CONFIG_FB_CYBER2000_DDC
1784 if (cfb->ddc_registered)
1785 i2c_del_adapter(&cfb->ddc_adapter);
1786#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 iounmap(cfb->region);
1788 cyberpro_free_fb_info(cfb);
1789
1790 /*
1791 * Ensure that the driver data is no longer
1792 * valid.
1793 */
1794 pci_set_drvdata(dev, NULL);
1795 if (cfb == int_cfb_info)
1796 int_cfb_info = NULL;
1797
1798 pci_release_regions(dev);
1799 }
1800}
1801
1802static int cyberpro_pci_suspend(struct pci_dev *dev, pm_message_t state)
1803{
1804 return 0;
1805}
1806
1807/*
1808 * Re-initialise the CyberPro hardware
1809 */
1810static int cyberpro_pci_resume(struct pci_dev *dev)
1811{
1812 struct cfb_info *cfb = pci_get_drvdata(dev);
1813
1814 if (cfb) {
1815 cyberpro_pci_enable_mmio(cfb);
1816 cyberpro_common_resume(cfb);
1817 }
1818
1819 return 0;
1820}
1821
1822static struct pci_device_id cyberpro_pci_table[] = {
Krzysztof Helt532237e2007-10-18 23:40:28 -07001823/* Not yet
1824 * { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_1682,
1825 * PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_IGA_1682 },
1826 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_2000,
1828 PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_2000 },
1829 { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_2010,
1830 PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_2010 },
1831 { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_5000,
1832 PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_5000 },
1833 { 0, }
1834};
1835
Krzysztof Helt532237e2007-10-18 23:40:28 -07001836MODULE_DEVICE_TABLE(pci, cyberpro_pci_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
1838static struct pci_driver cyberpro_driver = {
1839 .name = "CyberPro",
1840 .probe = cyberpro_pci_probe,
1841 .remove = __devexit_p(cyberpro_pci_remove),
1842 .suspend = cyberpro_pci_suspend,
1843 .resume = cyberpro_pci_resume,
1844 .id_table = cyberpro_pci_table
1845};
1846#endif
1847
1848/*
1849 * I don't think we can use the "module_init" stuff here because
1850 * the fbcon stuff may not be initialised yet. Hence the #ifdef
1851 * around module_init.
1852 *
1853 * Tony: "module_init" is now required
1854 */
1855static int __init cyber2000fb_init(void)
1856{
1857 int ret = -1, err;
1858
1859#ifndef MODULE
1860 char *option = NULL;
1861
1862 if (fb_get_options("cyber2000fb", &option))
1863 return -ENODEV;
1864 cyber2000fb_setup(option);
1865#endif
1866
1867#ifdef CONFIG_ARCH_SHARK
1868 err = cyberpro_vl_probe();
Rusty Russellab8e2eb2009-06-12 21:46:50 -06001869 if (!err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871#endif
1872#ifdef CONFIG_PCI
1873 err = pci_register_driver(&cyberpro_driver);
1874 if (!err)
1875 ret = 0;
1876#endif
1877
1878 return ret ? err : 0;
1879}
Rusty Russellab8e2eb2009-06-12 21:46:50 -06001880module_init(cyber2000fb_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
Rusty Russellab8e2eb2009-06-12 21:46:50 -06001882#ifndef CONFIG_ARCH_SHARK
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883static void __exit cyberpro_exit(void)
1884{
1885 pci_unregister_driver(&cyberpro_driver);
1886}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887module_exit(cyberpro_exit);
Rusty Russellab8e2eb2009-06-12 21:46:50 -06001888#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
1890MODULE_AUTHOR("Russell King");
1891MODULE_DESCRIPTION("CyberPro 2000, 2010 and 5000 framebuffer driver");
1892MODULE_LICENSE("GPL");