2 * drivers/video/imsttfb.c -- frame buffer device for IMS TwinTurbo
4 * This file is derived from the powermac console "imstt" driver:
5 * Copyright (C) 1997 Sigurdur Asgeirsson
6 * With additional hacking by Jeffrey Kuskin (jsk@mojave.stanford.edu)
7 * Modified by Danilo Beuche 1998
8 * Some register values added by Damien Doligez, INRIA Rocquencourt
9 * Various cleanups by Paul Mundt (lethal@chaoticdreams.org)
11 * This file was written by Ryan Nielsen (ran@krazynet.com)
12 * Most of the frame buffer device stuff was copied from atyfb.c
14 * This file is subject to the terms and conditions of the GNU General Public
15 * License. See the file COPYING in the main directory of this archive for
19 #include <linux/aperture.h>
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/string.h>
25 #include <linux/vmalloc.h>
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
29 #include <linux/init.h>
30 #include <linux/pci.h>
32 #include <linux/uaccess.h>
34 #if defined(CONFIG_PPC_PMAC)
35 #include <linux/nvram.h>
40 #define eieio() /* Enforce In-order Execution of I/O */
43 /* TwinTurbo (Cosmo) registers */
50 DP_OCTL
= 5, /* 0x14 */
54 BLTCTL
= 10, /* 0x28 */
56 /* Scan Timing Generator Registers */
69 STGCTL
= 24, /* 0x60 */
71 /* Screen Refresh Generator Registers */
76 SRGCTL
= 29, /* 0x74 */
78 /* RAM Refresh Generator Registers */
79 RRCIV
= 30, /* 0x78 */
83 /* System Registers */
87 SSTATUS
= 36, /* 0x90 */
101 /* IBM 624 RAMDAC Direct Registers */
113 /* IBM 624 RAMDAC Indirect Registers */
115 CLKCTL
= 0x02, /* (0x01) Miscellaneous Clock Control */
116 SYNCCTL
= 0x03, /* (0x00) Sync Control */
117 HSYNCPOS
= 0x04, /* (0x00) Horizontal Sync Position */
118 PWRMNGMT
= 0x05, /* (0x00) Power Management */
119 DACOP
= 0x06, /* (0x02) DAC Operation */
120 PALETCTL
= 0x07, /* (0x00) Palette Control */
121 SYSCLKCTL
= 0x08, /* (0x01) System Clock Control */
122 PIXFMT
= 0x0a, /* () Pixel Format [bpp >> 3 + 2] */
123 BPP8
= 0x0b, /* () 8 Bits/Pixel Control */
124 BPP16
= 0x0c, /* () 16 Bits/Pixel Control [bit 1=1 for 565] */
125 BPP24
= 0x0d, /* () 24 Bits/Pixel Control */
126 BPP32
= 0x0e, /* () 32 Bits/Pixel Control */
127 PIXCTL1
= 0x10, /* (0x05) Pixel PLL Control 1 */
128 PIXCTL2
= 0x11, /* (0x00) Pixel PLL Control 2 */
129 SYSCLKN
= 0x15, /* () System Clock N (System PLL Reference Divider) */
130 SYSCLKM
= 0x16, /* () System Clock M (System PLL VCO Divider) */
131 SYSCLKP
= 0x17, /* () System Clock P */
132 SYSCLKC
= 0x18, /* () System Clock C */
134 * Dot clock rate is 20MHz * (m + 1) / ((n + 1) * (p ? 2 * p : 1)
135 * c is charge pump bias which depends on the VCO frequency
137 PIXM0
= 0x20, /* () Pixel M 0 */
138 PIXN0
= 0x21, /* () Pixel N 0 */
139 PIXP0
= 0x22, /* () Pixel P 0 */
140 PIXC0
= 0x23, /* () Pixel C 0 */
141 CURSCTL
= 0x30, /* (0x00) Cursor Control */
142 CURSXLO
= 0x31, /* () Cursor X position, low 8 bits */
143 CURSXHI
= 0x32, /* () Cursor X position, high 8 bits */
144 CURSYLO
= 0x33, /* () Cursor Y position, low 8 bits */
145 CURSYHI
= 0x34, /* () Cursor Y position, high 8 bits */
146 CURSHOTX
= 0x35, /* () Cursor Hot Spot X */
147 CURSHOTY
= 0x36, /* () Cursor Hot Spot Y */
148 CURSACCTL
= 0x37, /* () Advanced Cursor Control Enable */
149 CURSACATTR
= 0x38, /* () Advanced Cursor Attribute */
150 CURS1R
= 0x40, /* () Cursor 1 Red */
151 CURS1G
= 0x41, /* () Cursor 1 Green */
152 CURS1B
= 0x42, /* () Cursor 1 Blue */
153 CURS2R
= 0x43, /* () Cursor 2 Red */
154 CURS2G
= 0x44, /* () Cursor 2 Green */
155 CURS2B
= 0x45, /* () Cursor 2 Blue */
156 CURS3R
= 0x46, /* () Cursor 3 Red */
157 CURS3G
= 0x47, /* () Cursor 3 Green */
158 CURS3B
= 0x48, /* () Cursor 3 Blue */
159 BORDR
= 0x60, /* () Border Color Red */
160 BORDG
= 0x61, /* () Border Color Green */
161 BORDB
= 0x62, /* () Border Color Blue */
162 MISCTL1
= 0x70, /* (0x00) Miscellaneous Control 1 */
163 MISCTL2
= 0x71, /* (0x00) Miscellaneous Control 2 */
164 MISCTL3
= 0x72, /* (0x00) Miscellaneous Control 3 */
165 KEYCTL
= 0x78 /* (0x00) Key Control/DB Operation */
168 /* TI TVP 3030 RAMDAC Direct Registers */
170 TVPADDRW
= 0x00, /* 0 Palette/Cursor RAM Write Address/Index */
171 TVPPDATA
= 0x04, /* 1 Palette Data RAM Data */
172 TVPPMASK
= 0x08, /* 2 Pixel Read-Mask */
173 TVPPADRR
= 0x0c, /* 3 Palette/Cursor RAM Read Address */
174 TVPCADRW
= 0x10, /* 4 Cursor/Overscan Color Write Address */
175 TVPCDATA
= 0x14, /* 5 Cursor/Overscan Color Data */
177 TVPCADRR
= 0x1c, /* 7 Cursor/Overscan Color Read Address */
179 TVPDCCTL
= 0x24, /* 9 Direct Cursor Control */
180 TVPIDATA
= 0x28, /* 10 Index Data */
181 TVPCRDAT
= 0x2c, /* 11 Cursor RAM Data */
182 TVPCXPOL
= 0x30, /* 12 Cursor-Position X LSB */
183 TVPCXPOH
= 0x34, /* 13 Cursor-Position X MSB */
184 TVPCYPOL
= 0x38, /* 14 Cursor-Position Y LSB */
185 TVPCYPOH
= 0x3c, /* 15 Cursor-Position Y MSB */
188 /* TI TVP 3030 RAMDAC Indirect Registers */
190 TVPIRREV
= 0x01, /* Silicon Revision [RO] */
191 TVPIRICC
= 0x06, /* Indirect Cursor Control (0x00) */
192 TVPIRBRC
= 0x07, /* Byte Router Control (0xe4) */
193 TVPIRLAC
= 0x0f, /* Latch Control (0x06) */
194 TVPIRTCC
= 0x18, /* True Color Control (0x80) */
195 TVPIRMXC
= 0x19, /* Multiplex Control (0x98) */
196 TVPIRCLS
= 0x1a, /* Clock Selection (0x07) */
197 TVPIRPPG
= 0x1c, /* Palette Page (0x00) */
198 TVPIRGEC
= 0x1d, /* General Control (0x00) */
199 TVPIRMIC
= 0x1e, /* Miscellaneous Control (0x00) */
200 TVPIRPLA
= 0x2c, /* PLL Address */
201 TVPIRPPD
= 0x2d, /* Pixel Clock PLL Data */
202 TVPIRMPD
= 0x2e, /* Memory Clock PLL Data */
203 TVPIRLPD
= 0x2f, /* Loop Clock PLL Data */
204 TVPIRCKL
= 0x30, /* Color-Key Overlay Low */
205 TVPIRCKH
= 0x31, /* Color-Key Overlay High */
206 TVPIRCRL
= 0x32, /* Color-Key Red Low */
207 TVPIRCRH
= 0x33, /* Color-Key Red High */
208 TVPIRCGL
= 0x34, /* Color-Key Green Low */
209 TVPIRCGH
= 0x35, /* Color-Key Green High */
210 TVPIRCBL
= 0x36, /* Color-Key Blue Low */
211 TVPIRCBH
= 0x37, /* Color-Key Blue High */
212 TVPIRCKC
= 0x38, /* Color-Key Control (0x00) */
213 TVPIRMLC
= 0x39, /* MCLK/Loop Clock Control (0x18) */
214 TVPIRSEN
= 0x3a, /* Sense Test (0x00) */
215 TVPIRTMD
= 0x3b, /* Test Mode Data */
216 TVPIRRML
= 0x3c, /* CRC Remainder LSB [RO] */
217 TVPIRRMM
= 0x3d, /* CRC Remainder MSB [RO] */
218 TVPIRRMS
= 0x3e, /* CRC Bit Select [WO] */
219 TVPIRDID
= 0x3f, /* Device ID [RO] (0x30) */
220 TVPIRRES
= 0xff /* Software Reset [WO] */
227 static struct initvalues ibm_initregs
[] = {
237 * Note that colors in X are correct only if all video data is
238 * passed through the palette in the DAC. That is, "indirect
239 * color" must be configured. This is the case for the IBM DAC
240 * used in the 2MB and 4MB cards, at least.
255 { CURSACATTR
, 0xa8 },
274 static struct initvalues tvp_initregs
[] = {
307 struct imstt_regvals
{
309 __u16 hes
, heb
, hsb
, ht
, ves
, veb
, vsb
, vt
, vil
;
310 __u8 pclk_m
, pclk_n
, pclk_p
;
311 /* Values of the tvp which change depending on colormode x resolution */
312 __u8 mlc
[3]; /* Memory Loop Config 0x39 */
313 __u8 lckl_p
[3]; /* P value of LCKL PLL */
317 struct imstt_regvals init
;
318 __u32 __iomem
*dc_regs
;
319 unsigned long cmap_regs_phys
;
331 #define INIT_XRES 640
332 #define INIT_YRES 480
334 static int inverse
= 0;
335 static char fontname
[40] __initdata
= { 0 };
336 #if defined(CONFIG_PPC_PMAC)
337 static signed char init_vmode
= -1, init_cmode
= -1;
340 static struct imstt_regvals tvp_reg_init_2
= {
342 0x0002, 0x0006, 0x0026, 0x0028, 0x0003, 0x0016, 0x0196, 0x0197, 0x0196,
344 { 0x3c, 0x3b, 0x39 }, { 0xf3, 0xf3, 0xf3 }
347 static struct imstt_regvals tvp_reg_init_6
= {
349 0x0004, 0x0009, 0x0031, 0x0036, 0x0003, 0x002a, 0x020a, 0x020d, 0x020a,
351 { 0x39, 0x39, 0x38 }, { 0xf3, 0xf3, 0xf3 }
354 static struct imstt_regvals tvp_reg_init_12
= {
356 0x0005, 0x000e, 0x0040, 0x0042, 0x0003, 0x018, 0x270, 0x271, 0x270,
358 { 0x3a, 0x39, 0x38 }, { 0xf3, 0xf3, 0xf3 }
361 static struct imstt_regvals tvp_reg_init_13
= {
363 0x0004, 0x0011, 0x0045, 0x0048, 0x0003, 0x002a, 0x029a, 0x029b, 0x0000,
365 { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
368 static struct imstt_regvals tvp_reg_init_17
= {
370 0x0006, 0x0210, 0x0250, 0x0053, 0x1003, 0x0021, 0x0321, 0x0324, 0x0000,
372 { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
375 static struct imstt_regvals tvp_reg_init_18
= {
377 0x0009, 0x0011, 0x059, 0x5b, 0x0003, 0x0031, 0x0397, 0x039a, 0x0000,
379 { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
382 static struct imstt_regvals tvp_reg_init_19
= {
384 0x0009, 0x0016, 0x0066, 0x0069, 0x0003, 0x0027, 0x03e7, 0x03e8, 0x03e7,
386 { 0x38, 0x38, 0x38 }, { 0xf3, 0xf2, 0xf1 }
389 static struct imstt_regvals tvp_reg_init_20
= {
391 0x0009, 0x0018, 0x0068, 0x006a, 0x0003, 0x0029, 0x0429, 0x042a, 0x0000,
393 { 0x38, 0x38, 0x38 }, { 0xf3, 0xf2, 0xf1 }
397 * PCI driver prototypes
399 static int imsttfb_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
400 static void imsttfb_remove(struct pci_dev
*pdev
);
405 static inline u32
read_reg_le32(volatile u32 __iomem
*base
, int regindex
)
408 return in_le32(base
+ regindex
);
410 return readl(base
+ regindex
);
414 static inline void write_reg_le32(volatile u32 __iomem
*base
, int regindex
, u32 val
)
417 out_le32(base
+ regindex
, val
);
419 writel(val
, base
+ regindex
);
424 getclkMHz(struct imstt_par
*par
)
426 __u32 clk_m
, clk_n
, clk_p
;
428 clk_m
= par
->init
.pclk_m
;
429 clk_n
= par
->init
.pclk_n
;
430 clk_p
= par
->init
.pclk_p
;
432 return 20 * (clk_m
+ 1) / ((clk_n
+ 1) * (clk_p
? 2 * clk_p
: 1));
436 setclkMHz(struct imstt_par
*par
, __u32 MHz
)
438 __u32 clk_m
, clk_n
, x
, stage
, spilled
;
451 x
= 20 * (clk_m
+ 1) / (clk_n
+ 1);
457 } else if (spilled
&& x
< MHz
) {
462 par
->init
.pclk_m
= clk_m
;
463 par
->init
.pclk_n
= clk_n
;
464 par
->init
.pclk_p
= 0;
467 static struct imstt_regvals
*
468 compute_imstt_regvals_ibm(struct imstt_par
*par
, int xres
, int yres
)
470 struct imstt_regvals
*init
= &par
->init
;
471 __u32 MHz
, hes
, heb
, veb
, htp
, vtp
;
475 hes
= 0x0008; heb
= 0x0012; veb
= 0x002a; htp
= 10; vtp
= 2;
479 hes
= 0x0005; heb
= 0x0020; veb
= 0x0028; htp
= 8; vtp
= 3;
480 MHz
= 57 /* .27_ */ ;
483 hes
= 0x000a; heb
= 0x001c; veb
= 0x0020; htp
= 8; vtp
= 3;
487 hes
= 0x0012; heb
= 0x0022; veb
= 0x0031; htp
= 4; vtp
= 3;
488 MHz
= 101 /* .6_ */ ;
491 hes
= 0x0012; heb
= 0x002f; veb
= 0x0029; htp
= 4; vtp
= 1;
492 MHz
= yres
== 960 ? 126 : 135;
495 hes
= 0x0018; heb
= 0x0040; veb
= 0x002a; htp
= 4; vtp
= 3;
506 init
->hsb
= init
->heb
+ (xres
>> 3);
507 init
->ht
= init
->hsb
+ htp
;
510 init
->vsb
= init
->veb
+ yres
;
511 init
->vt
= init
->vsb
+ vtp
;
512 init
->vil
= init
->vsb
;
518 static struct imstt_regvals
*
519 compute_imstt_regvals_tvp(struct imstt_par
*par
, int xres
, int yres
)
521 struct imstt_regvals
*init
;
525 init
= &tvp_reg_init_2
;
528 init
= &tvp_reg_init_6
;
531 init
= &tvp_reg_init_12
;
534 init
= &tvp_reg_init_13
;
537 init
= &tvp_reg_init_17
;
540 init
= &tvp_reg_init_18
;
543 init
= yres
== 960 ? &tvp_reg_init_19
: &tvp_reg_init_20
;
552 static struct imstt_regvals
*
553 compute_imstt_regvals (struct imstt_par
*par
, u_int xres
, u_int yres
)
555 if (par
->ramdac
== IBM
)
556 return compute_imstt_regvals_ibm(par
, xres
, yres
);
558 return compute_imstt_regvals_tvp(par
, xres
, yres
);
562 set_imstt_regvals_ibm (struct imstt_par
*par
, u_int bpp
)
564 struct imstt_regvals
*init
= &par
->init
;
565 __u8 pformat
= (bpp
>> 3) + 2;
567 par
->cmap_regs
[PIDXHI
] = 0; eieio();
568 par
->cmap_regs
[PIDXLO
] = PIXM0
; eieio();
569 par
->cmap_regs
[PIDXDATA
] = init
->pclk_m
;eieio();
570 par
->cmap_regs
[PIDXLO
] = PIXN0
; eieio();
571 par
->cmap_regs
[PIDXDATA
] = init
->pclk_n
;eieio();
572 par
->cmap_regs
[PIDXLO
] = PIXP0
; eieio();
573 par
->cmap_regs
[PIDXDATA
] = init
->pclk_p
;eieio();
574 par
->cmap_regs
[PIDXLO
] = PIXC0
; eieio();
575 par
->cmap_regs
[PIDXDATA
] = 0x02; eieio();
577 par
->cmap_regs
[PIDXLO
] = PIXFMT
; eieio();
578 par
->cmap_regs
[PIDXDATA
] = pformat
; eieio();
582 set_imstt_regvals_tvp (struct imstt_par
*par
, u_int bpp
)
584 struct imstt_regvals
*init
= &par
->init
;
585 __u8 tcc
, mxc
, lckl_n
, mic
;
595 lckl_p
= init
->lckl_p
[0];
602 lckl_p
= init
->lckl_p
[1];
609 lckl_p
= init
->lckl_p
[2];
616 lckl_p
= init
->lckl_p
[2];
621 par
->cmap_regs
[TVPADDRW
] = TVPIRPLA
; eieio();
622 par
->cmap_regs
[TVPIDATA
] = 0x00; eieio();
623 par
->cmap_regs
[TVPADDRW
] = TVPIRPPD
; eieio();
624 par
->cmap_regs
[TVPIDATA
] = init
->pclk_m
; eieio();
625 par
->cmap_regs
[TVPADDRW
] = TVPIRPPD
; eieio();
626 par
->cmap_regs
[TVPIDATA
] = init
->pclk_n
; eieio();
627 par
->cmap_regs
[TVPADDRW
] = TVPIRPPD
; eieio();
628 par
->cmap_regs
[TVPIDATA
] = init
->pclk_p
; eieio();
630 par
->cmap_regs
[TVPADDRW
] = TVPIRTCC
; eieio();
631 par
->cmap_regs
[TVPIDATA
] = tcc
; eieio();
632 par
->cmap_regs
[TVPADDRW
] = TVPIRMXC
; eieio();
633 par
->cmap_regs
[TVPIDATA
] = mxc
; eieio();
634 par
->cmap_regs
[TVPADDRW
] = TVPIRMIC
; eieio();
635 par
->cmap_regs
[TVPIDATA
] = mic
; eieio();
637 par
->cmap_regs
[TVPADDRW
] = TVPIRPLA
; eieio();
638 par
->cmap_regs
[TVPIDATA
] = 0x00; eieio();
639 par
->cmap_regs
[TVPADDRW
] = TVPIRLPD
; eieio();
640 par
->cmap_regs
[TVPIDATA
] = lckl_n
; eieio();
642 par
->cmap_regs
[TVPADDRW
] = TVPIRPLA
; eieio();
643 par
->cmap_regs
[TVPIDATA
] = 0x15; eieio();
644 par
->cmap_regs
[TVPADDRW
] = TVPIRMLC
; eieio();
645 par
->cmap_regs
[TVPIDATA
] = mlc
; eieio();
647 par
->cmap_regs
[TVPADDRW
] = TVPIRPLA
; eieio();
648 par
->cmap_regs
[TVPIDATA
] = 0x2a; eieio();
649 par
->cmap_regs
[TVPADDRW
] = TVPIRLPD
; eieio();
650 par
->cmap_regs
[TVPIDATA
] = lckl_p
; eieio();
654 set_imstt_regvals (struct fb_info
*info
, u_int bpp
)
656 struct imstt_par
*par
= info
->par
;
657 struct imstt_regvals
*init
= &par
->init
;
658 __u32 ctl
, pitch
, byteswap
, scr
;
660 if (par
->ramdac
== IBM
)
661 set_imstt_regvals_ibm(par
, bpp
);
663 set_imstt_regvals_tvp(par
, bpp
);
666 * From what I (jsk) can gather poking around with MacsBug,
667 * bits 8 and 9 in the SCR register control endianness
668 * correction (byte swapping). These bits must be set according
669 * to the color depth as follows:
670 * Color depth Bit 9 Bit 8
671 * ========== ===== =====
680 pitch
= init
->pitch
>> 2;
685 pitch
= init
->pitch
>> 1;
690 pitch
= init
->pitch
- (init
->pitch
>> 2);
699 if (par
->ramdac
== TVP
)
702 write_reg_le32(par
->dc_regs
, HES
, init
->hes
);
703 write_reg_le32(par
->dc_regs
, HEB
, init
->heb
);
704 write_reg_le32(par
->dc_regs
, HSB
, init
->hsb
);
705 write_reg_le32(par
->dc_regs
, HT
, init
->ht
);
706 write_reg_le32(par
->dc_regs
, VES
, init
->ves
);
707 write_reg_le32(par
->dc_regs
, VEB
, init
->veb
);
708 write_reg_le32(par
->dc_regs
, VSB
, init
->vsb
);
709 write_reg_le32(par
->dc_regs
, VT
, init
->vt
);
710 write_reg_le32(par
->dc_regs
, VIL
, init
->vil
);
711 write_reg_le32(par
->dc_regs
, HCIV
, 1);
712 write_reg_le32(par
->dc_regs
, VCIV
, 1);
713 write_reg_le32(par
->dc_regs
, TCDR
, 4);
714 write_reg_le32(par
->dc_regs
, RRCIV
, 1);
715 write_reg_le32(par
->dc_regs
, RRSC
, 0x980);
716 write_reg_le32(par
->dc_regs
, RRCR
, 0x11);
718 if (par
->ramdac
== IBM
) {
719 write_reg_le32(par
->dc_regs
, HRIR
, 0x0100);
720 write_reg_le32(par
->dc_regs
, CMR
, 0x00ff);
721 write_reg_le32(par
->dc_regs
, SRGCTL
, 0x0073);
723 write_reg_le32(par
->dc_regs
, HRIR
, 0x0200);
724 write_reg_le32(par
->dc_regs
, CMR
, 0x01ff);
725 write_reg_le32(par
->dc_regs
, SRGCTL
, 0x0003);
728 switch (info
->fix
.smem_len
) {
730 scr
= 0x059d | byteswap
;
736 scr
= 0x150dd | byteswap
;
740 write_reg_le32(par
->dc_regs
, SCR
, scr
);
741 write_reg_le32(par
->dc_regs
, SPR
, pitch
);
742 write_reg_le32(par
->dc_regs
, STGCTL
, ctl
);
746 set_offset (struct fb_var_screeninfo
*var
, struct fb_info
*info
)
748 struct imstt_par
*par
= info
->par
;
749 __u32 off
= var
->yoffset
* (info
->fix
.line_length
>> 3)
750 + ((var
->xoffset
* (info
->var
.bits_per_pixel
>> 3)) >> 3);
751 write_reg_le32(par
->dc_regs
, SSR
, off
);
755 set_555 (struct imstt_par
*par
)
757 if (par
->ramdac
== IBM
) {
758 par
->cmap_regs
[PIDXHI
] = 0; eieio();
759 par
->cmap_regs
[PIDXLO
] = BPP16
; eieio();
760 par
->cmap_regs
[PIDXDATA
] = 0x01; eieio();
762 par
->cmap_regs
[TVPADDRW
] = TVPIRTCC
; eieio();
763 par
->cmap_regs
[TVPIDATA
] = 0x44; eieio();
768 set_565 (struct imstt_par
*par
)
770 if (par
->ramdac
== IBM
) {
771 par
->cmap_regs
[PIDXHI
] = 0; eieio();
772 par
->cmap_regs
[PIDXLO
] = BPP16
; eieio();
773 par
->cmap_regs
[PIDXDATA
] = 0x03; eieio();
775 par
->cmap_regs
[TVPADDRW
] = TVPIRTCC
; eieio();
776 par
->cmap_regs
[TVPIDATA
] = 0x45; eieio();
781 imsttfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
783 if ((var
->bits_per_pixel
!= 8 && var
->bits_per_pixel
!= 16
784 && var
->bits_per_pixel
!= 24 && var
->bits_per_pixel
!= 32)
785 || var
->xres_virtual
< var
->xres
|| var
->yres_virtual
< var
->yres
787 || (var
->vmode
& FB_VMODE_MASK
) != FB_VMODE_NONINTERLACED
)
790 if ((var
->xres
* var
->yres
) * (var
->bits_per_pixel
>> 3) > info
->fix
.smem_len
791 || (var
->xres_virtual
* var
->yres_virtual
) * (var
->bits_per_pixel
>> 3) > info
->fix
.smem_len
)
794 switch (var
->bits_per_pixel
) {
798 var
->green
.offset
= 0;
799 var
->green
.length
= 8;
800 var
->blue
.offset
= 0;
801 var
->blue
.length
= 8;
802 var
->transp
.offset
= 0;
803 var
->transp
.length
= 0;
805 case 16: /* RGB 555 or 565 */
806 if (var
->green
.length
!= 6)
807 var
->red
.offset
= 10;
809 var
->green
.offset
= 5;
810 if (var
->green
.length
!= 6)
811 var
->green
.length
= 5;
812 var
->blue
.offset
= 0;
813 var
->blue
.length
= 5;
814 var
->transp
.offset
= 0;
815 var
->transp
.length
= 0;
817 case 24: /* RGB 888 */
818 var
->red
.offset
= 16;
820 var
->green
.offset
= 8;
821 var
->green
.length
= 8;
822 var
->blue
.offset
= 0;
823 var
->blue
.length
= 8;
824 var
->transp
.offset
= 0;
825 var
->transp
.length
= 0;
827 case 32: /* RGBA 8888 */
828 var
->red
.offset
= 16;
830 var
->green
.offset
= 8;
831 var
->green
.length
= 8;
832 var
->blue
.offset
= 0;
833 var
->blue
.length
= 8;
834 var
->transp
.offset
= 24;
835 var
->transp
.length
= 8;
839 if (var
->yres
== var
->yres_virtual
) {
840 __u32 vram
= (info
->fix
.smem_len
- (PAGE_SIZE
<< 2));
841 var
->yres_virtual
= ((vram
<< 3) / var
->bits_per_pixel
) / var
->xres_virtual
;
842 if (var
->yres_virtual
< var
->yres
)
843 var
->yres_virtual
= var
->yres
;
846 var
->red
.msb_right
= 0;
847 var
->green
.msb_right
= 0;
848 var
->blue
.msb_right
= 0;
849 var
->transp
.msb_right
= 0;
852 var
->vmode
= FB_VMODE_NONINTERLACED
;
853 var
->left_margin
= var
->right_margin
= 16;
854 var
->upper_margin
= var
->lower_margin
= 16;
855 var
->hsync_len
= var
->vsync_len
= 8;
860 imsttfb_set_par(struct fb_info
*info
)
862 struct imstt_par
*par
= info
->par
;
864 if (!compute_imstt_regvals(par
, info
->var
.xres
, info
->var
.yres
))
867 if (info
->var
.green
.length
== 6)
871 set_imstt_regvals(info
, info
->var
.bits_per_pixel
);
872 info
->var
.pixclock
= 1000000 / getclkMHz(par
);
877 imsttfb_setcolreg (u_int regno
, u_int red
, u_int green
, u_int blue
,
878 u_int transp
, struct fb_info
*info
)
880 struct imstt_par
*par
= info
->par
;
881 u_int bpp
= info
->var
.bits_per_pixel
;
890 /* PADDRW/PDATA are the same as TVPPADDRW/TVPPDATA */
891 if (0 && bpp
== 16) /* screws up X */
892 par
->cmap_regs
[PADDRW
] = regno
<< 3;
894 par
->cmap_regs
[PADDRW
] = regno
;
897 par
->cmap_regs
[PDATA
] = red
; eieio();
898 par
->cmap_regs
[PDATA
] = green
; eieio();
899 par
->cmap_regs
[PDATA
] = blue
; eieio();
904 par
->palette
[regno
] =
905 (regno
<< (info
->var
.green
.length
==
906 5 ? 10 : 11)) | (regno
<< 5) | regno
;
909 par
->palette
[regno
] =
910 (regno
<< 16) | (regno
<< 8) | regno
;
913 int i
= (regno
<< 8) | regno
;
914 par
->palette
[regno
] = (i
<< 16) |i
;
922 imsttfb_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
924 if (var
->xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
925 || var
->yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
928 info
->var
.xoffset
= var
->xoffset
;
929 info
->var
.yoffset
= var
->yoffset
;
930 set_offset(var
, info
);
935 imsttfb_blank(int blank
, struct fb_info
*info
)
937 struct imstt_par
*par
= info
->par
;
940 ctrl
= read_reg_le32(par
->dc_regs
, STGCTL
);
943 case FB_BLANK_NORMAL
:
944 case FB_BLANK_POWERDOWN
:
946 if (par
->ramdac
== IBM
) {
947 par
->cmap_regs
[PIDXHI
] = 0; eieio();
948 par
->cmap_regs
[PIDXLO
] = MISCTL2
; eieio();
949 par
->cmap_regs
[PIDXDATA
] = 0x55; eieio();
950 par
->cmap_regs
[PIDXLO
] = MISCTL1
; eieio();
951 par
->cmap_regs
[PIDXDATA
] = 0x11; eieio();
952 par
->cmap_regs
[PIDXLO
] = SYNCCTL
; eieio();
953 par
->cmap_regs
[PIDXDATA
] = 0x0f; eieio();
954 par
->cmap_regs
[PIDXLO
] = PWRMNGMT
; eieio();
955 par
->cmap_regs
[PIDXDATA
] = 0x1f; eieio();
956 par
->cmap_regs
[PIDXLO
] = CLKCTL
; eieio();
957 par
->cmap_regs
[PIDXDATA
] = 0xc0;
960 case FB_BLANK_VSYNC_SUSPEND
:
963 case FB_BLANK_HSYNC_SUSPEND
:
968 if (par
->ramdac
== IBM
) {
970 par
->cmap_regs
[PIDXHI
] = 0; eieio();
971 par
->cmap_regs
[PIDXLO
] = CLKCTL
; eieio();
972 par
->cmap_regs
[PIDXDATA
] = 0x01; eieio();
973 par
->cmap_regs
[PIDXLO
] = PWRMNGMT
; eieio();
974 par
->cmap_regs
[PIDXDATA
] = 0x00; eieio();
975 par
->cmap_regs
[PIDXLO
] = SYNCCTL
; eieio();
976 par
->cmap_regs
[PIDXDATA
] = 0x00; eieio();
977 par
->cmap_regs
[PIDXLO
] = MISCTL1
; eieio();
978 par
->cmap_regs
[PIDXDATA
] = 0x01; eieio();
979 par
->cmap_regs
[PIDXLO
] = MISCTL2
; eieio();
980 par
->cmap_regs
[PIDXDATA
] = 0x45; eieio();
984 write_reg_le32(par
->dc_regs
, STGCTL
, ctrl
);
989 imsttfb_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
991 struct imstt_par
*par
= info
->par
;
992 __u32 Bpp
, line_pitch
, bgc
, dx
, dy
, width
, height
;
998 Bpp
= info
->var
.bits_per_pixel
>> 3;
999 line_pitch
= info
->fix
.line_length
;
1001 dy
= rect
->dy
* line_pitch
;
1002 dx
= rect
->dx
* Bpp
;
1003 height
= rect
->height
;
1005 width
= rect
->width
* Bpp
;
1008 if (rect
->rop
== ROP_COPY
) {
1009 while(read_reg_le32(par
->dc_regs
, SSTATUS
) & 0x80);
1010 write_reg_le32(par
->dc_regs
, DSA
, dy
+ dx
);
1011 write_reg_le32(par
->dc_regs
, CNT
, (height
<< 16) | width
);
1012 write_reg_le32(par
->dc_regs
, DP_OCTL
, line_pitch
);
1013 write_reg_le32(par
->dc_regs
, BI
, 0xffffffff);
1014 write_reg_le32(par
->dc_regs
, MBC
, 0xffffffff);
1015 write_reg_le32(par
->dc_regs
, CLR
, bgc
);
1016 write_reg_le32(par
->dc_regs
, BLTCTL
, 0x840); /* 0x200000 */
1017 while(read_reg_le32(par
->dc_regs
, SSTATUS
) & 0x80);
1018 while(read_reg_le32(par
->dc_regs
, SSTATUS
) & 0x40);
1020 while(read_reg_le32(par
->dc_regs
, SSTATUS
) & 0x80);
1021 write_reg_le32(par
->dc_regs
, DSA
, dy
+ dx
);
1022 write_reg_le32(par
->dc_regs
, S1SA
, dy
+ dx
);
1023 write_reg_le32(par
->dc_regs
, CNT
, (height
<< 16) | width
);
1024 write_reg_le32(par
->dc_regs
, DP_OCTL
, line_pitch
);
1025 write_reg_le32(par
->dc_regs
, SP
, line_pitch
);
1026 write_reg_le32(par
->dc_regs
, BLTCTL
, 0x40005);
1027 while(read_reg_le32(par
->dc_regs
, SSTATUS
) & 0x80);
1028 while(read_reg_le32(par
->dc_regs
, SSTATUS
) & 0x40);
1033 imsttfb_copyarea(struct fb_info
*info
, const struct fb_copyarea
*area
)
1035 struct imstt_par
*par
= info
->par
;
1036 __u32 Bpp
, line_pitch
, fb_offset_old
, fb_offset_new
, sp
, dp_octl
;
1037 __u32 cnt
, bltctl
, sx
, sy
, dx
, dy
, height
, width
;
1039 Bpp
= info
->var
.bits_per_pixel
>> 3;
1041 sx
= area
->sx
* Bpp
;
1043 dx
= area
->dx
* Bpp
;
1045 height
= area
->height
;
1047 width
= area
->width
* Bpp
;
1050 line_pitch
= info
->fix
.line_length
;
1052 sp
= line_pitch
<< 16;
1058 sp
|= -(line_pitch
) & 0xffff;
1059 dp_octl
= -(line_pitch
) & 0xffff;
1062 dp_octl
= line_pitch
;
1068 cnt
|= -(width
) & 0xffff;
1072 fb_offset_old
= sy
* line_pitch
+ sx
;
1073 fb_offset_new
= dy
* line_pitch
+ dx
;
1075 while(read_reg_le32(par
->dc_regs
, SSTATUS
) & 0x80);
1076 write_reg_le32(par
->dc_regs
, S1SA
, fb_offset_old
);
1077 write_reg_le32(par
->dc_regs
, SP
, sp
);
1078 write_reg_le32(par
->dc_regs
, DSA
, fb_offset_new
);
1079 write_reg_le32(par
->dc_regs
, CNT
, cnt
);
1080 write_reg_le32(par
->dc_regs
, DP_OCTL
, dp_octl
);
1081 write_reg_le32(par
->dc_regs
, BLTCTL
, bltctl
);
1082 while(read_reg_le32(par
->dc_regs
, SSTATUS
) & 0x80);
1083 while(read_reg_le32(par
->dc_regs
, SSTATUS
) & 0x40);
1088 imsttfb_load_cursor_image(struct imstt_par
*par
, int width
, int height
, __u8 fgc
)
1092 if (width
> 32 || height
> 32)
1095 if (par
->ramdac
== IBM
) {
1096 par
->cmap_regs
[PIDXHI
] = 1; eieio();
1097 for (x
= 0; x
< 0x100; x
++) {
1098 par
->cmap_regs
[PIDXLO
] = x
; eieio();
1099 par
->cmap_regs
[PIDXDATA
] = 0x00; eieio();
1101 par
->cmap_regs
[PIDXHI
] = 1; eieio();
1102 for (y
= 0; y
< height
; y
++)
1103 for (x
= 0; x
< width
>> 2; x
++) {
1104 par
->cmap_regs
[PIDXLO
] = x
+ y
* 8; eieio();
1105 par
->cmap_regs
[PIDXDATA
] = 0xff; eieio();
1107 par
->cmap_regs
[PIDXHI
] = 0; eieio();
1108 par
->cmap_regs
[PIDXLO
] = CURS1R
; eieio();
1109 par
->cmap_regs
[PIDXDATA
] = fgc
; eieio();
1110 par
->cmap_regs
[PIDXLO
] = CURS1G
; eieio();
1111 par
->cmap_regs
[PIDXDATA
] = fgc
; eieio();
1112 par
->cmap_regs
[PIDXLO
] = CURS1B
; eieio();
1113 par
->cmap_regs
[PIDXDATA
] = fgc
; eieio();
1114 par
->cmap_regs
[PIDXLO
] = CURS2R
; eieio();
1115 par
->cmap_regs
[PIDXDATA
] = fgc
; eieio();
1116 par
->cmap_regs
[PIDXLO
] = CURS2G
; eieio();
1117 par
->cmap_regs
[PIDXDATA
] = fgc
; eieio();
1118 par
->cmap_regs
[PIDXLO
] = CURS2B
; eieio();
1119 par
->cmap_regs
[PIDXDATA
] = fgc
; eieio();
1120 par
->cmap_regs
[PIDXLO
] = CURS3R
; eieio();
1121 par
->cmap_regs
[PIDXDATA
] = fgc
; eieio();
1122 par
->cmap_regs
[PIDXLO
] = CURS3G
; eieio();
1123 par
->cmap_regs
[PIDXDATA
] = fgc
; eieio();
1124 par
->cmap_regs
[PIDXLO
] = CURS3B
; eieio();
1125 par
->cmap_regs
[PIDXDATA
] = fgc
; eieio();
1127 par
->cmap_regs
[TVPADDRW
] = TVPIRICC
; eieio();
1128 par
->cmap_regs
[TVPIDATA
] &= 0x03; eieio();
1129 par
->cmap_regs
[TVPADDRW
] = 0; eieio();
1130 for (x
= 0; x
< 0x200; x
++) {
1131 par
->cmap_regs
[TVPCRDAT
] = 0x00; eieio();
1133 for (x
= 0; x
< 0x200; x
++) {
1134 par
->cmap_regs
[TVPCRDAT
] = 0xff; eieio();
1136 par
->cmap_regs
[TVPADDRW
] = TVPIRICC
; eieio();
1137 par
->cmap_regs
[TVPIDATA
] &= 0x03; eieio();
1138 for (y
= 0; y
< height
; y
++)
1139 for (x
= 0; x
< width
>> 3; x
++) {
1140 par
->cmap_regs
[TVPADDRW
] = x
+ y
* 8; eieio();
1141 par
->cmap_regs
[TVPCRDAT
] = 0xff; eieio();
1143 par
->cmap_regs
[TVPADDRW
] = TVPIRICC
; eieio();
1144 par
->cmap_regs
[TVPIDATA
] |= 0x08; eieio();
1145 for (y
= 0; y
< height
; y
++)
1146 for (x
= 0; x
< width
>> 3; x
++) {
1147 par
->cmap_regs
[TVPADDRW
] = x
+ y
* 8; eieio();
1148 par
->cmap_regs
[TVPCRDAT
] = 0xff; eieio();
1150 par
->cmap_regs
[TVPCADRW
] = 0x00; eieio();
1151 for (x
= 0; x
< 12; x
++) {
1152 par
->cmap_regs
[TVPCDATA
] = fgc
;
1160 imstt_set_cursor(struct imstt_par
*par
, struct fb_image
*d
, int on
)
1162 if (par
->ramdac
== IBM
) {
1163 par
->cmap_regs
[PIDXHI
] = 0; eieio();
1165 par
->cmap_regs
[PIDXLO
] = CURSCTL
; eieio();
1166 par
->cmap_regs
[PIDXDATA
] = 0x00; eieio();
1168 par
->cmap_regs
[PIDXLO
] = CURSXHI
; eieio();
1169 par
->cmap_regs
[PIDXDATA
] = d
->dx
>> 8; eieio();
1170 par
->cmap_regs
[PIDXLO
] = CURSXLO
; eieio();
1171 par
->cmap_regs
[PIDXDATA
] = d
->dx
& 0xff;eieio();
1172 par
->cmap_regs
[PIDXLO
] = CURSYHI
; eieio();
1173 par
->cmap_regs
[PIDXDATA
] = d
->dy
>> 8; eieio();
1174 par
->cmap_regs
[PIDXLO
] = CURSYLO
; eieio();
1175 par
->cmap_regs
[PIDXDATA
] = d
->dy
& 0xff;eieio();
1176 par
->cmap_regs
[PIDXLO
] = CURSCTL
; eieio();
1177 par
->cmap_regs
[PIDXDATA
] = 0x02; eieio();
1181 par
->cmap_regs
[TVPADDRW
] = TVPIRICC
; eieio();
1182 par
->cmap_regs
[TVPIDATA
] = 0x00; eieio();
1184 __u16 x
= d
->dx
+ 0x40, y
= d
->dy
+ 0x40;
1186 par
->cmap_regs
[TVPCXPOH
] = x
>> 8; eieio();
1187 par
->cmap_regs
[TVPCXPOL
] = x
& 0xff; eieio();
1188 par
->cmap_regs
[TVPCYPOH
] = y
>> 8; eieio();
1189 par
->cmap_regs
[TVPCYPOL
] = y
& 0xff; eieio();
1190 par
->cmap_regs
[TVPADDRW
] = TVPIRICC
; eieio();
1191 par
->cmap_regs
[TVPIDATA
] = 0x02; eieio();
1197 imsttfb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
1199 struct imstt_par
*par
= info
->par
;
1200 u32 flags
= cursor
->set
, fg
, bg
, xx
, yy
;
1202 if (cursor
->dest
== NULL
&& cursor
->rop
== ROP_XOR
)
1205 imstt_set_cursor(info
, cursor
, 0);
1207 if (flags
& FB_CUR_SETPOS
) {
1208 xx
= cursor
->image
.dx
- info
->var
.xoffset
;
1209 yy
= cursor
->image
.dy
- info
->var
.yoffset
;
1212 if (flags
& FB_CUR_SETSIZE
) {
1215 if (flags
& (FB_CUR_SETSHAPE
| FB_CUR_SETCMAP
)) {
1216 int fg_idx
= cursor
->image
.fg_color
;
1217 int width
= (cursor
->image
.width
+7)/8;
1218 u8
*dat
= (u8
*) cursor
->image
.data
;
1219 u8
*dst
= (u8
*) cursor
->dest
;
1220 u8
*msk
= (u8
*) cursor
->mask
;
1222 switch (cursor
->rop
) {
1224 for (i
= 0; i
< cursor
->image
.height
; i
++) {
1225 for (j
= 0; j
< width
; j
++) {
1226 d_idx
= i
* MAX_CURS
/8 + j
;
1227 data
[d_idx
] = byte_rev
[dat
[s_idx
] ^
1229 mask
[d_idx
] = byte_rev
[msk
[s_idx
]];
1236 for (i
= 0; i
< cursor
->image
.height
; i
++) {
1237 for (j
= 0; j
< width
; j
++) {
1238 d_idx
= i
* MAX_CURS
/8 + j
;
1239 data
[d_idx
] = byte_rev
[dat
[s_idx
]];
1240 mask
[d_idx
] = byte_rev
[msk
[s_idx
]];
1247 fg
= ((info
->cmap
.red
[fg_idx
] & 0xf8) << 7) |
1248 ((info
->cmap
.green
[fg_idx
] & 0xf8) << 2) |
1249 ((info
->cmap
.blue
[fg_idx
] & 0xf8) >> 3) | 1 << 15;
1251 imsttfb_load_cursor_image(par
, xx
, yy
, fgc
);
1254 imstt_set_cursor(info
, cursor
, 1);
1259 #define FBIMSTT_SETREG 0x545401
1260 #define FBIMSTT_GETREG 0x545402
1261 #define FBIMSTT_SETCMAPREG 0x545403
1262 #define FBIMSTT_GETCMAPREG 0x545404
1263 #define FBIMSTT_SETIDXREG 0x545405
1264 #define FBIMSTT_GETIDXREG 0x545406
1267 imsttfb_ioctl(struct fb_info
*info
, u_int cmd
, u_long arg
)
1269 struct imstt_par
*par
= info
->par
;
1270 void __user
*argp
= (void __user
*)arg
;
1275 case FBIMSTT_SETREG
:
1276 if (copy_from_user(reg
, argp
, 8) || reg
[0] > (0x1000 - sizeof(reg
[0])) / sizeof(reg
[0]))
1278 write_reg_le32(par
->dc_regs
, reg
[0], reg
[1]);
1280 case FBIMSTT_GETREG
:
1281 if (copy_from_user(reg
, argp
, 4) || reg
[0] > (0x1000 - sizeof(reg
[0])) / sizeof(reg
[0]))
1283 reg
[1] = read_reg_le32(par
->dc_regs
, reg
[0]);
1284 if (copy_to_user((void __user
*)(arg
+ 4), ®
[1], 4))
1287 case FBIMSTT_SETCMAPREG
:
1288 if (copy_from_user(reg
, argp
, 8) || reg
[0] > (0x1000 - sizeof(reg
[0])) / sizeof(reg
[0]))
1290 write_reg_le32(((u_int __iomem
*)par
->cmap_regs
), reg
[0], reg
[1]);
1292 case FBIMSTT_GETCMAPREG
:
1293 if (copy_from_user(reg
, argp
, 4) || reg
[0] > (0x1000 - sizeof(reg
[0])) / sizeof(reg
[0]))
1295 reg
[1] = read_reg_le32(((u_int __iomem
*)par
->cmap_regs
), reg
[0]);
1296 if (copy_to_user((void __user
*)(arg
+ 4), ®
[1], 4))
1299 case FBIMSTT_SETIDXREG
:
1300 if (copy_from_user(idx
, argp
, 2))
1302 par
->cmap_regs
[PIDXHI
] = 0; eieio();
1303 par
->cmap_regs
[PIDXLO
] = idx
[0]; eieio();
1304 par
->cmap_regs
[PIDXDATA
] = idx
[1]; eieio();
1306 case FBIMSTT_GETIDXREG
:
1307 if (copy_from_user(idx
, argp
, 1))
1309 par
->cmap_regs
[PIDXHI
] = 0; eieio();
1310 par
->cmap_regs
[PIDXLO
] = idx
[0]; eieio();
1311 idx
[1] = par
->cmap_regs
[PIDXDATA
];
1312 if (copy_to_user((void __user
*)(arg
+ 1), &idx
[1], 1))
1316 return -ENOIOCTLCMD
;
1320 static const struct pci_device_id imsttfb_pci_tbl
[] = {
1321 { PCI_VENDOR_ID_IMS
, PCI_DEVICE_ID_IMS_TT128
,
1322 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, IBM
},
1323 { PCI_VENDOR_ID_IMS
, PCI_DEVICE_ID_IMS_TT3D
,
1324 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, TVP
},
1328 MODULE_DEVICE_TABLE(pci
, imsttfb_pci_tbl
);
1330 static struct pci_driver imsttfb_pci_driver
= {
1332 .id_table
= imsttfb_pci_tbl
,
1333 .probe
= imsttfb_probe
,
1334 .remove
= imsttfb_remove
,
1337 static const struct fb_ops imsttfb_ops
= {
1338 .owner
= THIS_MODULE
,
1339 __FB_DEFAULT_IOMEM_OPS_RDWR
,
1340 .fb_check_var
= imsttfb_check_var
,
1341 .fb_set_par
= imsttfb_set_par
,
1342 .fb_setcolreg
= imsttfb_setcolreg
,
1343 .fb_pan_display
= imsttfb_pan_display
,
1344 .fb_blank
= imsttfb_blank
,
1345 .fb_fillrect
= imsttfb_fillrect
,
1346 .fb_copyarea
= imsttfb_copyarea
,
1347 .fb_imageblit
= cfb_imageblit
,
1348 .fb_ioctl
= imsttfb_ioctl
,
1349 __FB_DEFAULT_IOMEM_OPS_MMAP
,
1352 static int init_imstt(struct fb_info
*info
)
1354 struct imstt_par
*par
= info
->par
;
1355 __u32 i
, tmp
, *ip
, *end
;
1357 tmp
= read_reg_le32(par
->dc_regs
, PRC
);
1358 if (par
->ramdac
== IBM
)
1359 info
->fix
.smem_len
= (tmp
& 0x0004) ? 0x400000 : 0x200000;
1361 info
->fix
.smem_len
= 0x800000;
1363 ip
= (__u32
*)info
->screen_base
;
1364 end
= (__u32
*)(info
->screen_base
+ info
->fix
.smem_len
);
1368 /* initialize the card */
1369 tmp
= read_reg_le32(par
->dc_regs
, STGCTL
);
1370 write_reg_le32(par
->dc_regs
, STGCTL
, tmp
& ~0x1);
1371 write_reg_le32(par
->dc_regs
, SSR
, 0);
1373 /* set default values for DAC registers */
1374 if (par
->ramdac
== IBM
) {
1375 par
->cmap_regs
[PPMASK
] = 0xff;
1377 par
->cmap_regs
[PIDXHI
] = 0;
1379 for (i
= 0; i
< ARRAY_SIZE(ibm_initregs
); i
++) {
1380 par
->cmap_regs
[PIDXLO
] = ibm_initregs
[i
].addr
;
1382 par
->cmap_regs
[PIDXDATA
] = ibm_initregs
[i
].value
;
1386 for (i
= 0; i
< ARRAY_SIZE(tvp_initregs
); i
++) {
1387 par
->cmap_regs
[TVPADDRW
] = tvp_initregs
[i
].addr
;
1389 par
->cmap_regs
[TVPIDATA
] = tvp_initregs
[i
].value
;
1394 #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32)
1395 if (IS_REACHABLE(CONFIG_NVRAM
) && machine_is(powermac
)) {
1396 int vmode
= init_vmode
, cmode
= init_cmode
;
1399 vmode
= nvram_read_byte(NV_VMODE
);
1400 if (vmode
<= 0 || vmode
> VMODE_MAX
)
1401 vmode
= VMODE_640_480_67
;
1404 cmode
= nvram_read_byte(NV_CMODE
);
1405 if (cmode
< CMODE_8
|| cmode
> CMODE_32
)
1408 if (mac_vmode_to_var(vmode
, cmode
, &info
->var
)) {
1409 info
->var
.xres
= info
->var
.xres_virtual
= INIT_XRES
;
1410 info
->var
.yres
= info
->var
.yres_virtual
= INIT_YRES
;
1411 info
->var
.bits_per_pixel
= INIT_BPP
;
1416 info
->var
.xres
= info
->var
.xres_virtual
= INIT_XRES
;
1417 info
->var
.yres
= info
->var
.yres_virtual
= INIT_YRES
;
1418 info
->var
.bits_per_pixel
= INIT_BPP
;
1421 if ((info
->var
.xres
* info
->var
.yres
) * (info
->var
.bits_per_pixel
>> 3) > info
->fix
.smem_len
1422 || !(compute_imstt_regvals(par
, info
->var
.xres
, info
->var
.yres
))) {
1423 printk("imsttfb: %ux%ux%u not supported\n", info
->var
.xres
, info
->var
.yres
, info
->var
.bits_per_pixel
);
1427 sprintf(info
->fix
.id
, "IMS TT (%s)", par
->ramdac
== IBM
? "IBM" : "TVP");
1428 info
->fix
.mmio_len
= 0x1000;
1429 info
->fix
.accel
= FB_ACCEL_IMS_TWINTURBO
;
1430 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1431 info
->fix
.visual
= info
->var
.bits_per_pixel
== 8 ? FB_VISUAL_PSEUDOCOLOR
1432 : FB_VISUAL_DIRECTCOLOR
;
1433 info
->fix
.line_length
= info
->var
.xres
* (info
->var
.bits_per_pixel
>> 3);
1434 info
->fix
.xpanstep
= 8;
1435 info
->fix
.ypanstep
= 1;
1436 info
->fix
.ywrapstep
= 0;
1438 info
->var
.accel_flags
= FB_ACCELF_TEXT
;
1440 // if (par->ramdac == IBM)
1441 // imstt_cursor_init(info);
1442 if (info
->var
.green
.length
== 6)
1446 set_imstt_regvals(info
, info
->var
.bits_per_pixel
);
1448 info
->var
.pixclock
= 1000000 / getclkMHz(par
);
1450 info
->fbops
= &imsttfb_ops
;
1451 info
->flags
= FBINFO_HWACCEL_COPYAREA
|
1452 FBINFO_HWACCEL_FILLRECT
|
1453 FBINFO_HWACCEL_YPAN
;
1455 if (fb_alloc_cmap(&info
->cmap
, 0, 0))
1458 if (register_framebuffer(info
) < 0) {
1459 fb_dealloc_cmap(&info
->cmap
);
1463 tmp
= (read_reg_le32(par
->dc_regs
, SSTATUS
) & 0x0f00) >> 8;
1464 fb_info(info
, "%s frame buffer; %uMB vram; chip version %u\n",
1465 info
->fix
.id
, info
->fix
.smem_len
>> 20, tmp
);
1469 static int imsttfb_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1471 unsigned long addr
, size
;
1472 struct imstt_par
*par
;
1473 struct fb_info
*info
;
1474 struct device_node
*dp
;
1477 ret
= aperture_remove_conflicting_pci_devices(pdev
, "imsttfb");
1482 dp
= pci_device_to_OF_node(pdev
);
1484 printk(KERN_INFO
"%s: OF name %pOFn\n",__func__
, dp
);
1485 else if (IS_ENABLED(CONFIG_OF
))
1486 printk(KERN_ERR
"imsttfb: no OF node for pci device\n");
1488 info
= framebuffer_alloc(sizeof(struct imstt_par
), &pdev
->dev
);
1494 addr
= pci_resource_start (pdev
, 0);
1495 size
= pci_resource_len (pdev
, 0);
1497 if (!request_mem_region(addr
, size
, "imsttfb")) {
1498 printk(KERN_ERR
"imsttfb: Can't reserve memory region\n");
1503 switch (pdev
->device
) {
1504 case PCI_DEVICE_ID_IMS_TT128
: /* IMS,tt128mbA */
1506 if (of_node_name_eq(dp
, "IMS,tt128mb8") ||
1507 of_node_name_eq(dp
, "IMS,tt128mb8A"))
1510 case PCI_DEVICE_ID_IMS_TT3D
: /* IMS,tt3d */
1514 printk(KERN_INFO
"imsttfb: Device 0x%x unknown, "
1515 "contact maintainer.\n", pdev
->device
);
1517 goto release_mem_region
;
1520 info
->fix
.smem_start
= addr
;
1521 info
->screen_base
= (__u8
*)ioremap(addr
, par
->ramdac
== IBM
?
1522 0x400000 : 0x800000);
1523 if (!info
->screen_base
)
1524 goto release_mem_region
;
1525 info
->fix
.mmio_start
= addr
+ 0x800000;
1526 par
->dc_regs
= ioremap(addr
+ 0x800000, 0x1000);
1528 goto unmap_screen_base
;
1529 par
->cmap_regs_phys
= addr
+ 0x840000;
1530 par
->cmap_regs
= (__u8
*)ioremap(addr
+ 0x840000, 0x1000);
1531 if (!par
->cmap_regs
)
1533 info
->pseudo_palette
= par
->palette
;
1534 ret
= init_imstt(info
);
1536 goto unmap_cmap_regs
;
1538 pci_set_drvdata(pdev
, info
);
1542 iounmap(par
->cmap_regs
);
1544 iounmap(par
->dc_regs
);
1546 iounmap(info
->screen_base
);
1548 release_mem_region(addr
, size
);
1550 framebuffer_release(info
);
1554 static void imsttfb_remove(struct pci_dev
*pdev
)
1556 struct fb_info
*info
= pci_get_drvdata(pdev
);
1557 struct imstt_par
*par
= info
->par
;
1558 int size
= pci_resource_len(pdev
, 0);
1560 unregister_framebuffer(info
);
1561 iounmap(par
->cmap_regs
);
1562 iounmap(par
->dc_regs
);
1563 iounmap(info
->screen_base
);
1564 release_mem_region(info
->fix
.smem_start
, size
);
1565 framebuffer_release(info
);
1570 imsttfb_setup(char *options
)
1574 if (!options
|| !*options
)
1577 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1578 if (!strncmp(this_opt
, "font:", 5)) {
1583 for (i
= 0; i
< sizeof(fontname
) - 1; i
++)
1584 if (!*p
|| *p
== ' ' || *p
== ',')
1586 memcpy(fontname
, this_opt
+ 5, i
);
1588 } else if (!strncmp(this_opt
, "inverse", 7)) {
1592 #if defined(CONFIG_PPC_PMAC)
1593 else if (!strncmp(this_opt
, "vmode:", 6)) {
1594 int vmode
= simple_strtoul(this_opt
+6, NULL
, 0);
1595 if (vmode
> 0 && vmode
<= VMODE_MAX
)
1597 } else if (!strncmp(this_opt
, "cmode:", 6)) {
1598 int cmode
= simple_strtoul(this_opt
+6, NULL
, 0);
1602 init_cmode
= CMODE_8
;
1607 init_cmode
= CMODE_16
;
1612 init_cmode
= CMODE_32
;
1623 static int __init
imsttfb_init(void)
1626 char *option
= NULL
;
1629 if (fb_modesetting_disabled("imsttfb"))
1633 if (fb_get_options("imsttfb", &option
))
1636 imsttfb_setup(option
);
1638 return pci_register_driver(&imsttfb_pci_driver
);
1641 static void __exit
imsttfb_exit(void)
1643 pci_unregister_driver(&imsttfb_pci_driver
);
1646 MODULE_LICENSE("GPL");
1648 module_init(imsttfb_init
);
1649 module_exit(imsttfb_exit
);