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/module.h>
20 #include <linux/kernel.h>
21 #include <linux/errno.h>
22 #include <linux/string.h>
24 #include <linux/slab.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)
35 #include <linux/nvram.h>
37 #include <asm/pci-bridge.h>
42 #define eieio() /* Enforce In-order Execution of I/O */
45 /* TwinTurbo (Cosmo) registers */
52 DP_OCTL = 5, /* 0x14 */
56 BLTCTL = 10, /* 0x28 */
58 /* Scan Timing Generator Registers */
71 STGCTL = 24, /* 0x60 */
73 /* Screen Refresh Generator Registers */
78 SRGCTL = 29, /* 0x74 */
80 /* RAM Refresh Generator Registers */
81 RRCIV = 30, /* 0x78 */
85 /* System Registers */
89 SSTATUS = 36, /* 0x90 */
103 /* IBM 624 RAMDAC Direct Registers */
115 /* IBM 624 RAMDAC Indirect Registers */
117 CLKCTL = 0x02, /* (0x01) Miscellaneous Clock Control */
118 SYNCCTL = 0x03, /* (0x00) Sync Control */
119 HSYNCPOS = 0x04, /* (0x00) Horizontal Sync Position */
120 PWRMNGMT = 0x05, /* (0x00) Power Management */
121 DACOP = 0x06, /* (0x02) DAC Operation */
122 PALETCTL = 0x07, /* (0x00) Palette Control */
123 SYSCLKCTL = 0x08, /* (0x01) System Clock Control */
124 PIXFMT = 0x0a, /* () Pixel Format [bpp >> 3 + 2] */
125 BPP8 = 0x0b, /* () 8 Bits/Pixel Control */
126 BPP16 = 0x0c, /* () 16 Bits/Pixel Control [bit 1=1 for 565] */
127 BPP24 = 0x0d, /* () 24 Bits/Pixel Control */
128 BPP32 = 0x0e, /* () 32 Bits/Pixel Control */
129 PIXCTL1 = 0x10, /* (0x05) Pixel PLL Control 1 */
130 PIXCTL2 = 0x11, /* (0x00) Pixel PLL Control 2 */
131 SYSCLKN = 0x15, /* () System Clock N (System PLL Reference Divider) */
132 SYSCLKM = 0x16, /* () System Clock M (System PLL VCO Divider) */
133 SYSCLKP = 0x17, /* () System Clock P */
134 SYSCLKC = 0x18, /* () System Clock C */
136 * Dot clock rate is 20MHz * (m + 1) / ((n + 1) * (p ? 2 * p : 1)
137 * c is charge pump bias which depends on the VCO frequency
139 PIXM0 = 0x20, /* () Pixel M 0 */
140 PIXN0 = 0x21, /* () Pixel N 0 */
141 PIXP0 = 0x22, /* () Pixel P 0 */
142 PIXC0 = 0x23, /* () Pixel C 0 */
143 CURSCTL = 0x30, /* (0x00) Cursor Control */
144 CURSXLO = 0x31, /* () Cursor X position, low 8 bits */
145 CURSXHI = 0x32, /* () Cursor X position, high 8 bits */
146 CURSYLO = 0x33, /* () Cursor Y position, low 8 bits */
147 CURSYHI = 0x34, /* () Cursor Y position, high 8 bits */
148 CURSHOTX = 0x35, /* () Cursor Hot Spot X */
149 CURSHOTY = 0x36, /* () Cursor Hot Spot Y */
150 CURSACCTL = 0x37, /* () Advanced Cursor Control Enable */
151 CURSACATTR = 0x38, /* () Advanced Cursor Attribute */
152 CURS1R = 0x40, /* () Cursor 1 Red */
153 CURS1G = 0x41, /* () Cursor 1 Green */
154 CURS1B = 0x42, /* () Cursor 1 Blue */
155 CURS2R = 0x43, /* () Cursor 2 Red */
156 CURS2G = 0x44, /* () Cursor 2 Green */
157 CURS2B = 0x45, /* () Cursor 2 Blue */
158 CURS3R = 0x46, /* () Cursor 3 Red */
159 CURS3G = 0x47, /* () Cursor 3 Green */
160 CURS3B = 0x48, /* () Cursor 3 Blue */
161 BORDR = 0x60, /* () Border Color Red */
162 BORDG = 0x61, /* () Border Color Green */
163 BORDB = 0x62, /* () Border Color Blue */
164 MISCTL1 = 0x70, /* (0x00) Miscellaneous Control 1 */
165 MISCTL2 = 0x71, /* (0x00) Miscellaneous Control 2 */
166 MISCTL3 = 0x72, /* (0x00) Miscellaneous Control 3 */
167 KEYCTL = 0x78 /* (0x00) Key Control/DB Operation */
170 /* TI TVP 3030 RAMDAC Direct Registers */
172 TVPADDRW = 0x00, /* 0 Palette/Cursor RAM Write Address/Index */
173 TVPPDATA = 0x04, /* 1 Palette Data RAM Data */
174 TVPPMASK = 0x08, /* 2 Pixel Read-Mask */
175 TVPPADRR = 0x0c, /* 3 Palette/Cursor RAM Read Address */
176 TVPCADRW = 0x10, /* 4 Cursor/Overscan Color Write Address */
177 TVPCDATA = 0x14, /* 5 Cursor/Overscan Color Data */
179 TVPCADRR = 0x1c, /* 7 Cursor/Overscan Color Read Address */
181 TVPDCCTL = 0x24, /* 9 Direct Cursor Control */
182 TVPIDATA = 0x28, /* 10 Index Data */
183 TVPCRDAT = 0x2c, /* 11 Cursor RAM Data */
184 TVPCXPOL = 0x30, /* 12 Cursor-Position X LSB */
185 TVPCXPOH = 0x34, /* 13 Cursor-Position X MSB */
186 TVPCYPOL = 0x38, /* 14 Cursor-Position Y LSB */
187 TVPCYPOH = 0x3c, /* 15 Cursor-Position Y MSB */
190 /* TI TVP 3030 RAMDAC Indirect Registers */
192 TVPIRREV = 0x01, /* Silicon Revision [RO] */
193 TVPIRICC = 0x06, /* Indirect Cursor Control (0x00) */
194 TVPIRBRC = 0x07, /* Byte Router Control (0xe4) */
195 TVPIRLAC = 0x0f, /* Latch Control (0x06) */
196 TVPIRTCC = 0x18, /* True Color Control (0x80) */
197 TVPIRMXC = 0x19, /* Multiplex Control (0x98) */
198 TVPIRCLS = 0x1a, /* Clock Selection (0x07) */
199 TVPIRPPG = 0x1c, /* Palette Page (0x00) */
200 TVPIRGEC = 0x1d, /* General Control (0x00) */
201 TVPIRMIC = 0x1e, /* Miscellaneous Control (0x00) */
202 TVPIRPLA = 0x2c, /* PLL Address */
203 TVPIRPPD = 0x2d, /* Pixel Clock PLL Data */
204 TVPIRMPD = 0x2e, /* Memory Clock PLL Data */
205 TVPIRLPD = 0x2f, /* Loop Clock PLL Data */
206 TVPIRCKL = 0x30, /* Color-Key Overlay Low */
207 TVPIRCKH = 0x31, /* Color-Key Overlay High */
208 TVPIRCRL = 0x32, /* Color-Key Red Low */
209 TVPIRCRH = 0x33, /* Color-Key Red High */
210 TVPIRCGL = 0x34, /* Color-Key Green Low */
211 TVPIRCGH = 0x35, /* Color-Key Green High */
212 TVPIRCBL = 0x36, /* Color-Key Blue Low */
213 TVPIRCBH = 0x37, /* Color-Key Blue High */
214 TVPIRCKC = 0x38, /* Color-Key Control (0x00) */
215 TVPIRMLC = 0x39, /* MCLK/Loop Clock Control (0x18) */
216 TVPIRSEN = 0x3a, /* Sense Test (0x00) */
217 TVPIRTMD = 0x3b, /* Test Mode Data */
218 TVPIRRML = 0x3c, /* CRC Remainder LSB [RO] */
219 TVPIRRMM = 0x3d, /* CRC Remainder MSB [RO] */
220 TVPIRRMS = 0x3e, /* CRC Bit Select [WO] */
221 TVPIRDID = 0x3f, /* Device ID [RO] (0x30) */
222 TVPIRRES = 0xff /* Software Reset [WO] */
229 static struct initvalues ibm_initregs[] __devinitdata = {
239 * Note that colors in X are correct only if all video data is
240 * passed through the palette in the DAC. That is, "indirect
241 * color" must be configured. This is the case for the IBM DAC
242 * used in the 2MB and 4MB cards, at least.
257 { CURSACATTR, 0xa8 },
276 static struct initvalues tvp_initregs[] __devinitdata = {
309 struct imstt_regvals {
311 __u16 hes, heb, hsb, ht, ves, veb, vsb, vt, vil;
312 __u8 pclk_m, pclk_n, pclk_p;
313 /* Values of the tvp which change depending on colormode x resolution */
314 __u8 mlc[3]; /* Memory Loop Config 0x39 */
315 __u8 lckl_p[3]; /* P value of LCKL PLL */
319 struct imstt_regvals init;
320 __u32 __iomem *dc_regs;
321 unsigned long cmap_regs_phys;
332 #define USE_NV_MODES 1
334 #define INIT_XRES 640
335 #define INIT_YRES 480
337 static int inverse = 0;
338 static char fontname[40] __initdata = { 0 };
339 #if defined(CONFIG_PPC)
340 static signed char init_vmode __devinitdata = -1, init_cmode __devinitdata = -1;
343 static struct imstt_regvals tvp_reg_init_2 = {
345 0x0002, 0x0006, 0x0026, 0x0028, 0x0003, 0x0016, 0x0196, 0x0197, 0x0196,
347 { 0x3c, 0x3b, 0x39 }, { 0xf3, 0xf3, 0xf3 }
350 static struct imstt_regvals tvp_reg_init_6 = {
352 0x0004, 0x0009, 0x0031, 0x0036, 0x0003, 0x002a, 0x020a, 0x020d, 0x020a,
354 { 0x39, 0x39, 0x38 }, { 0xf3, 0xf3, 0xf3 }
357 static struct imstt_regvals tvp_reg_init_12 = {
359 0x0005, 0x000e, 0x0040, 0x0042, 0x0003, 0x018, 0x270, 0x271, 0x270,
361 { 0x3a, 0x39, 0x38 }, { 0xf3, 0xf3, 0xf3 }
364 static struct imstt_regvals tvp_reg_init_13 = {
366 0x0004, 0x0011, 0x0045, 0x0048, 0x0003, 0x002a, 0x029a, 0x029b, 0x0000,
368 { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
371 static struct imstt_regvals tvp_reg_init_17 = {
373 0x0006, 0x0210, 0x0250, 0x0053, 0x1003, 0x0021, 0x0321, 0x0324, 0x0000,
375 { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
378 static struct imstt_regvals tvp_reg_init_18 = {
380 0x0009, 0x0011, 0x059, 0x5b, 0x0003, 0x0031, 0x0397, 0x039a, 0x0000,
382 { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
385 static struct imstt_regvals tvp_reg_init_19 = {
387 0x0009, 0x0016, 0x0066, 0x0069, 0x0003, 0x0027, 0x03e7, 0x03e8, 0x03e7,
389 { 0x38, 0x38, 0x38 }, { 0xf3, 0xf2, 0xf1 }
392 static struct imstt_regvals tvp_reg_init_20 = {
394 0x0009, 0x0018, 0x0068, 0x006a, 0x0003, 0x0029, 0x0429, 0x042a, 0x0000,
396 { 0x38, 0x38, 0x38 }, { 0xf3, 0xf2, 0xf1 }
400 * PCI driver prototypes
402 static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
403 static void imsttfb_remove(struct pci_dev *pdev);
408 static inline u32 read_reg_le32(volatile u32 __iomem *base, int regindex)
411 return in_le32(base + regindex);
413 return readl(base + regindex);
417 static inline void write_reg_le32(volatile u32 __iomem *base, int regindex, u32 val)
420 out_le32(base + regindex, val);
422 writel(val, base + regindex);
427 getclkMHz(struct imstt_par *par)
429 __u32 clk_m, clk_n, clk_p;
431 clk_m = par->init.pclk_m;
432 clk_n = par->init.pclk_n;
433 clk_p = par->init.pclk_p;
435 return 20 * (clk_m + 1) / ((clk_n + 1) * (clk_p ? 2 * clk_p : 1));
439 setclkMHz(struct imstt_par *par, __u32 MHz)
441 __u32 clk_m, clk_n, x, stage, spilled;
454 x = 20 * (clk_m + 1) / (clk_n + 1);
460 } else if (spilled && x < MHz) {
465 par->init.pclk_m = clk_m;
466 par->init.pclk_n = clk_n;
467 par->init.pclk_p = 0;
470 static struct imstt_regvals *
471 compute_imstt_regvals_ibm(struct imstt_par *par, int xres, int yres)
473 struct imstt_regvals *init = &par->init;
474 __u32 MHz, hes, heb, veb, htp, vtp;
478 hes = 0x0008; heb = 0x0012; veb = 0x002a; htp = 10; vtp = 2;
482 hes = 0x0005; heb = 0x0020; veb = 0x0028; htp = 8; vtp = 3;
483 MHz = 57 /* .27_ */ ;
486 hes = 0x000a; heb = 0x001c; veb = 0x0020; htp = 8; vtp = 3;
490 hes = 0x0012; heb = 0x0022; veb = 0x0031; htp = 4; vtp = 3;
491 MHz = 101 /* .6_ */ ;
494 hes = 0x0012; heb = 0x002f; veb = 0x0029; htp = 4; vtp = 1;
495 MHz = yres == 960 ? 126 : 135;
498 hes = 0x0018; heb = 0x0040; veb = 0x002a; htp = 4; vtp = 3;
509 init->hsb = init->heb + (xres >> 3);
510 init->ht = init->hsb + htp;
513 init->vsb = init->veb + yres;
514 init->vt = init->vsb + vtp;
515 init->vil = init->vsb;
521 static struct imstt_regvals *
522 compute_imstt_regvals_tvp(struct imstt_par *par, int xres, int yres)
524 struct imstt_regvals *init;
528 init = &tvp_reg_init_2;
531 init = &tvp_reg_init_6;
534 init = &tvp_reg_init_12;
537 init = &tvp_reg_init_13;
540 init = &tvp_reg_init_17;
543 init = &tvp_reg_init_18;
546 init = yres == 960 ? &tvp_reg_init_19 : &tvp_reg_init_20;
555 static struct imstt_regvals *
556 compute_imstt_regvals (struct imstt_par *par, u_int xres, u_int yres)
558 if (par->ramdac == IBM)
559 return compute_imstt_regvals_ibm(par, xres, yres);
561 return compute_imstt_regvals_tvp(par, xres, yres);
565 set_imstt_regvals_ibm (struct imstt_par *par, u_int bpp)
567 struct imstt_regvals *init = &par->init;
568 __u8 pformat = (bpp >> 3) + 2;
570 par->cmap_regs[PIDXHI] = 0; eieio();
571 par->cmap_regs[PIDXLO] = PIXM0; eieio();
572 par->cmap_regs[PIDXDATA] = init->pclk_m;eieio();
573 par->cmap_regs[PIDXLO] = PIXN0; eieio();
574 par->cmap_regs[PIDXDATA] = init->pclk_n;eieio();
575 par->cmap_regs[PIDXLO] = PIXP0; eieio();
576 par->cmap_regs[PIDXDATA] = init->pclk_p;eieio();
577 par->cmap_regs[PIDXLO] = PIXC0; eieio();
578 par->cmap_regs[PIDXDATA] = 0x02; eieio();
580 par->cmap_regs[PIDXLO] = PIXFMT; eieio();
581 par->cmap_regs[PIDXDATA] = pformat; eieio();
585 set_imstt_regvals_tvp (struct imstt_par *par, u_int bpp)
587 struct imstt_regvals *init = &par->init;
588 __u8 tcc, mxc, lckl_n, mic;
598 lckl_p = init->lckl_p[0];
605 lckl_p = init->lckl_p[1];
612 lckl_p = init->lckl_p[2];
619 lckl_p = init->lckl_p[2];
624 par->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
625 par->cmap_regs[TVPIDATA] = 0x00; eieio();
626 par->cmap_regs[TVPADDRW] = TVPIRPPD; eieio();
627 par->cmap_regs[TVPIDATA] = init->pclk_m; eieio();
628 par->cmap_regs[TVPADDRW] = TVPIRPPD; eieio();
629 par->cmap_regs[TVPIDATA] = init->pclk_n; eieio();
630 par->cmap_regs[TVPADDRW] = TVPIRPPD; eieio();
631 par->cmap_regs[TVPIDATA] = init->pclk_p; eieio();
633 par->cmap_regs[TVPADDRW] = TVPIRTCC; eieio();
634 par->cmap_regs[TVPIDATA] = tcc; eieio();
635 par->cmap_regs[TVPADDRW] = TVPIRMXC; eieio();
636 par->cmap_regs[TVPIDATA] = mxc; eieio();
637 par->cmap_regs[TVPADDRW] = TVPIRMIC; eieio();
638 par->cmap_regs[TVPIDATA] = mic; eieio();
640 par->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
641 par->cmap_regs[TVPIDATA] = 0x00; eieio();
642 par->cmap_regs[TVPADDRW] = TVPIRLPD; eieio();
643 par->cmap_regs[TVPIDATA] = lckl_n; eieio();
645 par->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
646 par->cmap_regs[TVPIDATA] = 0x15; eieio();
647 par->cmap_regs[TVPADDRW] = TVPIRMLC; eieio();
648 par->cmap_regs[TVPIDATA] = mlc; eieio();
650 par->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
651 par->cmap_regs[TVPIDATA] = 0x2a; eieio();
652 par->cmap_regs[TVPADDRW] = TVPIRLPD; eieio();
653 par->cmap_regs[TVPIDATA] = lckl_p; eieio();
657 set_imstt_regvals (struct fb_info *info, u_int bpp)
659 struct imstt_par *par = info->par;
660 struct imstt_regvals *init = &par->init;
661 __u32 ctl, pitch, byteswap, scr;
663 if (par->ramdac == IBM)
664 set_imstt_regvals_ibm(par, bpp);
666 set_imstt_regvals_tvp(par, bpp);
669 * From what I (jsk) can gather poking around with MacsBug,
670 * bits 8 and 9 in the SCR register control endianness
671 * correction (byte swapping). These bits must be set according
672 * to the color depth as follows:
673 * Color depth Bit 9 Bit 8
674 * ========== ===== =====
683 pitch = init->pitch >> 2;
688 pitch = init->pitch >> 1;
693 pitch = init->pitch - (init->pitch >> 2);
702 if (par->ramdac == TVP)
705 write_reg_le32(par->dc_regs, HES, init->hes);
706 write_reg_le32(par->dc_regs, HEB, init->heb);
707 write_reg_le32(par->dc_regs, HSB, init->hsb);
708 write_reg_le32(par->dc_regs, HT, init->ht);
709 write_reg_le32(par->dc_regs, VES, init->ves);
710 write_reg_le32(par->dc_regs, VEB, init->veb);
711 write_reg_le32(par->dc_regs, VSB, init->vsb);
712 write_reg_le32(par->dc_regs, VT, init->vt);
713 write_reg_le32(par->dc_regs, VIL, init->vil);
714 write_reg_le32(par->dc_regs, HCIV, 1);
715 write_reg_le32(par->dc_regs, VCIV, 1);
716 write_reg_le32(par->dc_regs, TCDR, 4);
717 write_reg_le32(par->dc_regs, RRCIV, 1);
718 write_reg_le32(par->dc_regs, RRSC, 0x980);
719 write_reg_le32(par->dc_regs, RRCR, 0x11);
721 if (par->ramdac == IBM) {
722 write_reg_le32(par->dc_regs, HRIR, 0x0100);
723 write_reg_le32(par->dc_regs, CMR, 0x00ff);
724 write_reg_le32(par->dc_regs, SRGCTL, 0x0073);
726 write_reg_le32(par->dc_regs, HRIR, 0x0200);
727 write_reg_le32(par->dc_regs, CMR, 0x01ff);
728 write_reg_le32(par->dc_regs, SRGCTL, 0x0003);
731 switch (info->fix.smem_len) {
733 scr = 0x059d | byteswap;
739 scr = 0x150dd | byteswap;
743 write_reg_le32(par->dc_regs, SCR, scr);
744 write_reg_le32(par->dc_regs, SPR, pitch);
745 write_reg_le32(par->dc_regs, STGCTL, ctl);
749 set_offset (struct fb_var_screeninfo *var, struct fb_info *info)
751 struct imstt_par *par = info->par;
752 __u32 off = var->yoffset * (info->fix.line_length >> 3)
753 + ((var->xoffset * (var->bits_per_pixel >> 3)) >> 3);
754 write_reg_le32(par->dc_regs, SSR, off);
758 set_555 (struct imstt_par *par)
760 if (par->ramdac == IBM) {
761 par->cmap_regs[PIDXHI] = 0; eieio();
762 par->cmap_regs[PIDXLO] = BPP16; eieio();
763 par->cmap_regs[PIDXDATA] = 0x01; eieio();
765 par->cmap_regs[TVPADDRW] = TVPIRTCC; eieio();
766 par->cmap_regs[TVPIDATA] = 0x44; eieio();
771 set_565 (struct imstt_par *par)
773 if (par->ramdac == IBM) {
774 par->cmap_regs[PIDXHI] = 0; eieio();
775 par->cmap_regs[PIDXLO] = BPP16; eieio();
776 par->cmap_regs[PIDXDATA] = 0x03; eieio();
778 par->cmap_regs[TVPADDRW] = TVPIRTCC; eieio();
779 par->cmap_regs[TVPIDATA] = 0x45; eieio();
784 imsttfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
786 if ((var->bits_per_pixel != 8 && var->bits_per_pixel != 16
787 && var->bits_per_pixel != 24 && var->bits_per_pixel != 32)
788 || var->xres_virtual < var->xres || var->yres_virtual < var->yres
790 || (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
793 if ((var->xres * var->yres) * (var->bits_per_pixel >> 3) > info->fix.smem_len
794 || (var->xres_virtual * var->yres_virtual) * (var->bits_per_pixel >> 3) > info->fix.smem_len)
797 switch (var->bits_per_pixel) {
801 var->green.offset = 0;
802 var->green.length = 8;
803 var->blue.offset = 0;
804 var->blue.length = 8;
805 var->transp.offset = 0;
806 var->transp.length = 0;
808 case 16: /* RGB 555 or 565 */
809 if (var->green.length != 6)
810 var->red.offset = 10;
812 var->green.offset = 5;
813 if (var->green.length != 6)
814 var->green.length = 5;
815 var->blue.offset = 0;
816 var->blue.length = 5;
817 var->transp.offset = 0;
818 var->transp.length = 0;
820 case 24: /* RGB 888 */
821 var->red.offset = 16;
823 var->green.offset = 8;
824 var->green.length = 8;
825 var->blue.offset = 0;
826 var->blue.length = 8;
827 var->transp.offset = 0;
828 var->transp.length = 0;
830 case 32: /* RGBA 8888 */
831 var->red.offset = 16;
833 var->green.offset = 8;
834 var->green.length = 8;
835 var->blue.offset = 0;
836 var->blue.length = 8;
837 var->transp.offset = 24;
838 var->transp.length = 8;
842 if (var->yres == var->yres_virtual) {
843 __u32 vram = (info->fix.smem_len - (PAGE_SIZE << 2));
844 var->yres_virtual = ((vram << 3) / var->bits_per_pixel) / var->xres_virtual;
845 if (var->yres_virtual < var->yres)
846 var->yres_virtual = var->yres;
849 var->red.msb_right = 0;
850 var->green.msb_right = 0;
851 var->blue.msb_right = 0;
852 var->transp.msb_right = 0;
855 var->vmode = FB_VMODE_NONINTERLACED;
856 var->left_margin = var->right_margin = 16;
857 var->upper_margin = var->lower_margin = 16;
858 var->hsync_len = var->vsync_len = 8;
863 imsttfb_set_par(struct fb_info *info)
865 struct imstt_par *par = info->par;
867 if (!compute_imstt_regvals(par, info->var.xres, info->var.yres))
870 if (info->var.green.length == 6)
874 set_imstt_regvals(info, info->var.bits_per_pixel);
875 info->var.pixclock = 1000000 / getclkMHz(par);
880 imsttfb_setcolreg (u_int regno, u_int red, u_int green, u_int blue,
881 u_int transp, struct fb_info *info)
883 struct imstt_par *par = info->par;
884 u_int bpp = info->var.bits_per_pixel;
893 /* PADDRW/PDATA are the same as TVPPADDRW/TVPPDATA */
894 if (0 && bpp == 16) /* screws up X */
895 par->cmap_regs[PADDRW] = regno << 3;
897 par->cmap_regs[PADDRW] = regno;
900 par->cmap_regs[PDATA] = red; eieio();
901 par->cmap_regs[PDATA] = green; eieio();
902 par->cmap_regs[PDATA] = blue; eieio();
907 par->palette[regno] =
908 (regno << (info->var.green.length ==
909 5 ? 10 : 11)) | (regno << 5) | regno;
912 par->palette[regno] =
913 (regno << 16) | (regno << 8) | regno;
916 int i = (regno << 8) | regno;
917 par->palette[regno] = (i << 16) |i;
925 imsttfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
927 if (var->xoffset + info->var.xres > info->var.xres_virtual
928 || var->yoffset + info->var.yres > info->var.yres_virtual)
931 info->var.xoffset = var->xoffset;
932 info->var.yoffset = var->yoffset;
933 set_offset(var, info);
938 imsttfb_blank(int blank, struct fb_info *info)
940 struct imstt_par *par = info->par;
943 ctrl = read_reg_le32(par->dc_regs, STGCTL);
946 case FB_BLANK_NORMAL:
947 case FB_BLANK_POWERDOWN:
949 if (par->ramdac == IBM) {
950 par->cmap_regs[PIDXHI] = 0; eieio();
951 par->cmap_regs[PIDXLO] = MISCTL2; eieio();
952 par->cmap_regs[PIDXDATA] = 0x55; eieio();
953 par->cmap_regs[PIDXLO] = MISCTL1; eieio();
954 par->cmap_regs[PIDXDATA] = 0x11; eieio();
955 par->cmap_regs[PIDXLO] = SYNCCTL; eieio();
956 par->cmap_regs[PIDXDATA] = 0x0f; eieio();
957 par->cmap_regs[PIDXLO] = PWRMNGMT; eieio();
958 par->cmap_regs[PIDXDATA] = 0x1f; eieio();
959 par->cmap_regs[PIDXLO] = CLKCTL; eieio();
960 par->cmap_regs[PIDXDATA] = 0xc0;
963 case FB_BLANK_VSYNC_SUSPEND:
966 case FB_BLANK_HSYNC_SUSPEND:
971 if (par->ramdac == IBM) {
973 par->cmap_regs[PIDXHI] = 0; eieio();
974 par->cmap_regs[PIDXLO] = CLKCTL; eieio();
975 par->cmap_regs[PIDXDATA] = 0x01; eieio();
976 par->cmap_regs[PIDXLO] = PWRMNGMT; eieio();
977 par->cmap_regs[PIDXDATA] = 0x00; eieio();
978 par->cmap_regs[PIDXLO] = SYNCCTL; eieio();
979 par->cmap_regs[PIDXDATA] = 0x00; eieio();
980 par->cmap_regs[PIDXLO] = MISCTL1; eieio();
981 par->cmap_regs[PIDXDATA] = 0x01; eieio();
982 par->cmap_regs[PIDXLO] = MISCTL2; eieio();
983 par->cmap_regs[PIDXDATA] = 0x45; eieio();
987 write_reg_le32(par->dc_regs, STGCTL, ctrl);
992 imsttfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
994 struct imstt_par *par = info->par;
995 __u32 Bpp, line_pitch, bgc, dx, dy, width, height;
1001 Bpp = info->var.bits_per_pixel >> 3,
1002 line_pitch = info->fix.line_length;
1004 dy = rect->dy * line_pitch;
1005 dx = rect->dx * Bpp;
1006 height = rect->height;
1008 width = rect->width * Bpp;
1011 if (rect->rop == ROP_COPY) {
1012 while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
1013 write_reg_le32(par->dc_regs, DSA, dy + dx);
1014 write_reg_le32(par->dc_regs, CNT, (height << 16) | width);
1015 write_reg_le32(par->dc_regs, DP_OCTL, line_pitch);
1016 write_reg_le32(par->dc_regs, BI, 0xffffffff);
1017 write_reg_le32(par->dc_regs, MBC, 0xffffffff);
1018 write_reg_le32(par->dc_regs, CLR, bgc);
1019 write_reg_le32(par->dc_regs, BLTCTL, 0x840); /* 0x200000 */
1020 while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
1021 while(read_reg_le32(par->dc_regs, SSTATUS) & 0x40);
1023 while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
1024 write_reg_le32(par->dc_regs, DSA, dy + dx);
1025 write_reg_le32(par->dc_regs, S1SA, dy + dx);
1026 write_reg_le32(par->dc_regs, CNT, (height << 16) | width);
1027 write_reg_le32(par->dc_regs, DP_OCTL, line_pitch);
1028 write_reg_le32(par->dc_regs, SP, line_pitch);
1029 write_reg_le32(par->dc_regs, BLTCTL, 0x40005);
1030 while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
1031 while(read_reg_le32(par->dc_regs, SSTATUS) & 0x40);
1036 imsttfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
1038 struct imstt_par *par = info->par;
1039 __u32 Bpp, line_pitch, fb_offset_old, fb_offset_new, sp, dp_octl;
1040 __u32 cnt, bltctl, sx, sy, dx, dy, height, width;
1042 Bpp = info->var.bits_per_pixel >> 3,
1044 sx = area->sx * Bpp;
1046 dx = area->dx * Bpp;
1048 height = area->height;
1050 width = area->width * Bpp;
1053 line_pitch = info->fix.line_length;
1055 sp = line_pitch << 16;
1061 sp |= -(line_pitch) & 0xffff;
1062 dp_octl = -(line_pitch) & 0xffff;
1065 dp_octl = line_pitch;
1071 cnt |= -(width) & 0xffff;
1075 fb_offset_old = sy * line_pitch + sx;
1076 fb_offset_new = dy * line_pitch + dx;
1078 while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
1079 write_reg_le32(par->dc_regs, S1SA, fb_offset_old);
1080 write_reg_le32(par->dc_regs, SP, sp);
1081 write_reg_le32(par->dc_regs, DSA, fb_offset_new);
1082 write_reg_le32(par->dc_regs, CNT, cnt);
1083 write_reg_le32(par->dc_regs, DP_OCTL, dp_octl);
1084 write_reg_le32(par->dc_regs, BLTCTL, bltctl);
1085 while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
1086 while(read_reg_le32(par->dc_regs, SSTATUS) & 0x40);
1091 imsttfb_load_cursor_image(struct imstt_par *par, int width, int height, __u8 fgc)
1095 if (width > 32 || height > 32)
1098 if (par->ramdac == IBM) {
1099 par->cmap_regs[PIDXHI] = 1; eieio();
1100 for (x = 0; x < 0x100; x++) {
1101 par->cmap_regs[PIDXLO] = x; eieio();
1102 par->cmap_regs[PIDXDATA] = 0x00; eieio();
1104 par->cmap_regs[PIDXHI] = 1; eieio();
1105 for (y = 0; y < height; y++)
1106 for (x = 0; x < width >> 2; x++) {
1107 par->cmap_regs[PIDXLO] = x + y * 8; eieio();
1108 par->cmap_regs[PIDXDATA] = 0xff; eieio();
1110 par->cmap_regs[PIDXHI] = 0; eieio();
1111 par->cmap_regs[PIDXLO] = CURS1R; eieio();
1112 par->cmap_regs[PIDXDATA] = fgc; eieio();
1113 par->cmap_regs[PIDXLO] = CURS1G; eieio();
1114 par->cmap_regs[PIDXDATA] = fgc; eieio();
1115 par->cmap_regs[PIDXLO] = CURS1B; eieio();
1116 par->cmap_regs[PIDXDATA] = fgc; eieio();
1117 par->cmap_regs[PIDXLO] = CURS2R; eieio();
1118 par->cmap_regs[PIDXDATA] = fgc; eieio();
1119 par->cmap_regs[PIDXLO] = CURS2G; eieio();
1120 par->cmap_regs[PIDXDATA] = fgc; eieio();
1121 par->cmap_regs[PIDXLO] = CURS2B; eieio();
1122 par->cmap_regs[PIDXDATA] = fgc; eieio();
1123 par->cmap_regs[PIDXLO] = CURS3R; eieio();
1124 par->cmap_regs[PIDXDATA] = fgc; eieio();
1125 par->cmap_regs[PIDXLO] = CURS3G; eieio();
1126 par->cmap_regs[PIDXDATA] = fgc; eieio();
1127 par->cmap_regs[PIDXLO] = CURS3B; eieio();
1128 par->cmap_regs[PIDXDATA] = fgc; eieio();
1130 par->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
1131 par->cmap_regs[TVPIDATA] &= 0x03; eieio();
1132 par->cmap_regs[TVPADDRW] = 0; eieio();
1133 for (x = 0; x < 0x200; x++) {
1134 par->cmap_regs[TVPCRDAT] = 0x00; eieio();
1136 for (x = 0; x < 0x200; x++) {
1137 par->cmap_regs[TVPCRDAT] = 0xff; eieio();
1139 par->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
1140 par->cmap_regs[TVPIDATA] &= 0x03; eieio();
1141 for (y = 0; y < height; y++)
1142 for (x = 0; x < width >> 3; x++) {
1143 par->cmap_regs[TVPADDRW] = x + y * 8; eieio();
1144 par->cmap_regs[TVPCRDAT] = 0xff; eieio();
1146 par->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
1147 par->cmap_regs[TVPIDATA] |= 0x08; eieio();
1148 for (y = 0; y < height; y++)
1149 for (x = 0; x < width >> 3; x++) {
1150 par->cmap_regs[TVPADDRW] = x + y * 8; eieio();
1151 par->cmap_regs[TVPCRDAT] = 0xff; eieio();
1153 par->cmap_regs[TVPCADRW] = 0x00; eieio();
1154 for (x = 0; x < 12; x++) {
1155 par->cmap_regs[TVPCDATA] = fgc;
1163 imstt_set_cursor(struct imstt_par *par, struct fb_image *d, int on)
1165 if (par->ramdac == IBM) {
1166 par->cmap_regs[PIDXHI] = 0; eieio();
1168 par->cmap_regs[PIDXLO] = CURSCTL; eieio();
1169 par->cmap_regs[PIDXDATA] = 0x00; eieio();
1171 par->cmap_regs[PIDXLO] = CURSXHI; eieio();
1172 par->cmap_regs[PIDXDATA] = d->dx >> 8; eieio();
1173 par->cmap_regs[PIDXLO] = CURSXLO; eieio();
1174 par->cmap_regs[PIDXDATA] = d->dx & 0xff;eieio();
1175 par->cmap_regs[PIDXLO] = CURSYHI; eieio();
1176 par->cmap_regs[PIDXDATA] = d->dy >> 8; eieio();
1177 par->cmap_regs[PIDXLO] = CURSYLO; eieio();
1178 par->cmap_regs[PIDXDATA] = d->dy & 0xff;eieio();
1179 par->cmap_regs[PIDXLO] = CURSCTL; eieio();
1180 par->cmap_regs[PIDXDATA] = 0x02; eieio();
1184 par->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
1185 par->cmap_regs[TVPIDATA] = 0x00; eieio();
1187 __u16 x = d->dx + 0x40, y = d->dy + 0x40;
1189 par->cmap_regs[TVPCXPOH] = x >> 8; eieio();
1190 par->cmap_regs[TVPCXPOL] = x & 0xff; eieio();
1191 par->cmap_regs[TVPCYPOH] = y >> 8; eieio();
1192 par->cmap_regs[TVPCYPOL] = y & 0xff; eieio();
1193 par->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
1194 par->cmap_regs[TVPIDATA] = 0x02; eieio();
1200 imsttfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1202 struct imstt_par *par = info->par;
1203 u32 flags = cursor->set, fg, bg, xx, yy;
1205 if (cursor->dest == NULL && cursor->rop == ROP_XOR)
1208 imstt_set_cursor(info, cursor, 0);
1210 if (flags & FB_CUR_SETPOS) {
1211 xx = cursor->image.dx - info->var.xoffset;
1212 yy = cursor->image.dy - info->var.yoffset;
1215 if (flags & FB_CUR_SETSIZE) {
1218 if (flags & (FB_CUR_SETSHAPE | FB_CUR_SETCMAP)) {
1219 int fg_idx = cursor->image.fg_color;
1220 int width = (cursor->image.width+7)/8;
1221 u8 *dat = (u8 *) cursor->image.data;
1222 u8 *dst = (u8 *) cursor->dest;
1223 u8 *msk = (u8 *) cursor->mask;
1225 switch (cursor->rop) {
1227 for (i = 0; i < cursor->image.height; i++) {
1228 for (j = 0; j < width; j++) {
1229 d_idx = i * MAX_CURS/8 + j;
1230 data[d_idx] = byte_rev[dat[s_idx] ^
1232 mask[d_idx] = byte_rev[msk[s_idx]];
1239 for (i = 0; i < cursor->image.height; i++) {
1240 for (j = 0; j < width; j++) {
1241 d_idx = i * MAX_CURS/8 + j;
1242 data[d_idx] = byte_rev[dat[s_idx]];
1243 mask[d_idx] = byte_rev[msk[s_idx]];
1250 fg = ((info->cmap.red[fg_idx] & 0xf8) << 7) |
1251 ((info->cmap.green[fg_idx] & 0xf8) << 2) |
1252 ((info->cmap.blue[fg_idx] & 0xf8) >> 3) | 1 << 15;
1254 imsttfb_load_cursor_image(par, xx, yy, fgc);
1257 imstt_set_cursor(info, cursor, 1);
1262 #define FBIMSTT_SETREG 0x545401
1263 #define FBIMSTT_GETREG 0x545402
1264 #define FBIMSTT_SETCMAPREG 0x545403
1265 #define FBIMSTT_GETCMAPREG 0x545404
1266 #define FBIMSTT_SETIDXREG 0x545405
1267 #define FBIMSTT_GETIDXREG 0x545406
1270 imsttfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
1272 struct imstt_par *par = info->par;
1273 void __user *argp = (void __user *)arg;
1278 case FBIMSTT_SETREG:
1279 if (copy_from_user(reg, argp, 8) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
1281 write_reg_le32(par->dc_regs, reg[0], reg[1]);
1283 case FBIMSTT_GETREG:
1284 if (copy_from_user(reg, argp, 4) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
1286 reg[1] = read_reg_le32(par->dc_regs, reg[0]);
1287 if (copy_to_user((void __user *)(arg + 4), ®[1], 4))
1290 case FBIMSTT_SETCMAPREG:
1291 if (copy_from_user(reg, argp, 8) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
1293 write_reg_le32(((u_int __iomem *)par->cmap_regs), reg[0], reg[1]);
1295 case FBIMSTT_GETCMAPREG:
1296 if (copy_from_user(reg, argp, 4) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
1298 reg[1] = read_reg_le32(((u_int __iomem *)par->cmap_regs), reg[0]);
1299 if (copy_to_user((void __user *)(arg + 4), ®[1], 4))
1302 case FBIMSTT_SETIDXREG:
1303 if (copy_from_user(idx, argp, 2))
1305 par->cmap_regs[PIDXHI] = 0; eieio();
1306 par->cmap_regs[PIDXLO] = idx[0]; eieio();
1307 par->cmap_regs[PIDXDATA] = idx[1]; eieio();
1309 case FBIMSTT_GETIDXREG:
1310 if (copy_from_user(idx, argp, 1))
1312 par->cmap_regs[PIDXHI] = 0; eieio();
1313 par->cmap_regs[PIDXLO] = idx[0]; eieio();
1314 idx[1] = par->cmap_regs[PIDXDATA];
1315 if (copy_to_user((void __user *)(arg + 1), &idx[1], 1))
1319 return -ENOIOCTLCMD;
1323 static struct pci_device_id imsttfb_pci_tbl[] = {
1324 { PCI_VENDOR_ID_IMS, PCI_DEVICE_ID_IMS_TT128,
1325 PCI_ANY_ID, PCI_ANY_ID, 0, 0, IBM },
1326 { PCI_VENDOR_ID_IMS, PCI_DEVICE_ID_IMS_TT3D,
1327 PCI_ANY_ID, PCI_ANY_ID, 0, 0, TVP },
1331 MODULE_DEVICE_TABLE(pci, imsttfb_pci_tbl);
1333 static struct pci_driver imsttfb_pci_driver = {
1335 .id_table = imsttfb_pci_tbl,
1336 .probe = imsttfb_probe,
1337 .remove = __devexit_p(imsttfb_remove),
1340 static struct fb_ops imsttfb_ops = {
1341 .owner = THIS_MODULE,
1342 .fb_check_var = imsttfb_check_var,
1343 .fb_set_par = imsttfb_set_par,
1344 .fb_setcolreg = imsttfb_setcolreg,
1345 .fb_pan_display = imsttfb_pan_display,
1346 .fb_blank = imsttfb_blank,
1347 .fb_fillrect = imsttfb_fillrect,
1348 .fb_copyarea = imsttfb_copyarea,
1349 .fb_imageblit = cfb_imageblit,
1350 .fb_ioctl = imsttfb_ioctl,
1353 static void __devinit
1354 init_imstt(struct fb_info *info)
1356 struct imstt_par *par = info->par;
1357 __u32 i, tmp, *ip, *end;
1359 tmp = read_reg_le32(par->dc_regs, PRC);
1360 if (par->ramdac == IBM)
1361 info->fix.smem_len = (tmp & 0x0004) ? 0x400000 : 0x200000;
1363 info->fix.smem_len = 0x800000;
1365 ip = (__u32 *)info->screen_base;
1366 end = (__u32 *)(info->screen_base + info->fix.smem_len);
1370 /* initialize the card */
1371 tmp = read_reg_le32(par->dc_regs, STGCTL);
1372 write_reg_le32(par->dc_regs, STGCTL, tmp & ~0x1);
1373 write_reg_le32(par->dc_regs, SSR, 0);
1375 /* set default values for DAC registers */
1376 if (par->ramdac == IBM) {
1377 par->cmap_regs[PPMASK] = 0xff;
1379 par->cmap_regs[PIDXHI] = 0;
1381 for (i = 0; i < ARRAY_SIZE(ibm_initregs); i++) {
1382 par->cmap_regs[PIDXLO] = ibm_initregs[i].addr;
1384 par->cmap_regs[PIDXDATA] = ibm_initregs[i].value;
1388 for (i = 0; i < ARRAY_SIZE(tvp_initregs); i++) {
1389 par->cmap_regs[TVPADDRW] = tvp_initregs[i].addr;
1391 par->cmap_regs[TVPIDATA] = tvp_initregs[i].value;
1396 #if USE_NV_MODES && defined(CONFIG_PPC32)
1398 int vmode = init_vmode, cmode = init_cmode;
1401 vmode = nvram_read_byte(NV_VMODE);
1402 if (vmode <= 0 || vmode > VMODE_MAX)
1403 vmode = VMODE_640_480_67;
1406 cmode = nvram_read_byte(NV_CMODE);
1407 if (cmode < CMODE_8 || cmode > CMODE_32)
1410 if (mac_vmode_to_var(vmode, cmode, &info->var)) {
1411 info->var.xres = info->var.xres_virtual = INIT_XRES;
1412 info->var.yres = info->var.yres_virtual = INIT_YRES;
1413 info->var.bits_per_pixel = INIT_BPP;
1417 info->var.xres = info->var.xres_virtual = INIT_XRES;
1418 info->var.yres = info->var.yres_virtual = INIT_YRES;
1419 info->var.bits_per_pixel = INIT_BPP;
1422 if ((info->var.xres * info->var.yres) * (info->var.bits_per_pixel >> 3) > info->fix.smem_len
1423 || !(compute_imstt_regvals(par, info->var.xres, info->var.yres))) {
1424 printk("imsttfb: %ux%ux%u not supported\n", info->var.xres, info->var.yres, info->var.bits_per_pixel);
1425 framebuffer_release(info);
1429 sprintf(info->fix.id, "IMS TT (%s)", par->ramdac == IBM ? "IBM" : "TVP");
1430 info->fix.mmio_len = 0x1000;
1431 info->fix.accel = FB_ACCEL_IMS_TWINTURBO;
1432 info->fix.type = FB_TYPE_PACKED_PIXELS;
1433 info->fix.visual = info->var.bits_per_pixel == 8 ? FB_VISUAL_PSEUDOCOLOR
1434 : FB_VISUAL_DIRECTCOLOR;
1435 info->fix.line_length = info->var.xres * (info->var.bits_per_pixel >> 3);
1436 info->fix.xpanstep = 8;
1437 info->fix.ypanstep = 1;
1438 info->fix.ywrapstep = 0;
1440 info->var.accel_flags = FB_ACCELF_TEXT;
1442 // if (par->ramdac == IBM)
1443 // imstt_cursor_init(info);
1444 if (info->var.green.length == 6)
1448 set_imstt_regvals(info, info->var.bits_per_pixel);
1450 info->var.pixclock = 1000000 / getclkMHz(par);
1452 info->fbops = &imsttfb_ops;
1453 info->flags = FBINFO_DEFAULT |
1454 FBINFO_HWACCEL_COPYAREA |
1455 FBINFO_HWACCEL_FILLRECT |
1456 FBINFO_HWACCEL_YPAN;
1458 fb_alloc_cmap(&info->cmap, 0, 0);
1460 if (register_framebuffer(info) < 0) {
1461 framebuffer_release(info);
1465 tmp = (read_reg_le32(par->dc_regs, SSTATUS) & 0x0f00) >> 8;
1466 printk("fb%u: %s frame buffer; %uMB vram; chip version %u\n",
1467 info->node, info->fix.id, info->fix.smem_len >> 20, tmp);
1470 static int __devinit
1471 imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1473 unsigned long addr, size;
1474 struct imstt_par *par;
1475 struct fb_info *info;
1476 #ifdef CONFIG_PPC_OF
1477 struct device_node *dp;
1479 dp = pci_device_to_OF_node(pdev);
1481 printk(KERN_INFO "%s: OF name %s\n",__func__, dp->name);
1483 printk(KERN_ERR "imsttfb: no OF node for pci device\n");
1484 #endif /* CONFIG_PPC_OF */
1486 info = framebuffer_alloc(sizeof(struct imstt_par), &pdev->dev);
1489 printk(KERN_ERR "imsttfb: Can't allocate memory\n");
1495 addr = pci_resource_start (pdev, 0);
1496 size = pci_resource_len (pdev, 0);
1498 if (!request_mem_region(addr, size, "imsttfb")) {
1499 printk(KERN_ERR "imsttfb: Can't reserve memory region\n");
1500 framebuffer_release(info);
1504 switch (pdev->device) {
1505 case PCI_DEVICE_ID_IMS_TT128: /* IMS,tt128mbA */
1507 #ifdef CONFIG_PPC_OF
1508 if (dp && ((strcmp(dp->name, "IMS,tt128mb8") == 0) ||
1509 (strcmp(dp->name, "IMS,tt128mb8A") == 0)))
1511 #endif /* CONFIG_PPC_OF */
1513 case PCI_DEVICE_ID_IMS_TT3D: /* IMS,tt3d */
1517 printk(KERN_INFO "imsttfb: Device 0x%x unknown, "
1518 "contact maintainer.\n", pdev->device);
1519 release_mem_region(addr, size);
1520 framebuffer_release(info);
1524 info->fix.smem_start = addr;
1525 info->screen_base = (__u8 *)ioremap(addr, par->ramdac == IBM ?
1526 0x400000 : 0x800000);
1527 info->fix.mmio_start = addr + 0x800000;
1528 par->dc_regs = ioremap(addr + 0x800000, 0x1000);
1529 par->cmap_regs_phys = addr + 0x840000;
1530 par->cmap_regs = (__u8 *)ioremap(addr + 0x840000, 0x1000);
1531 info->pseudo_palette = par->palette;
1534 pci_set_drvdata(pdev, info);
1538 static void __devexit
1539 imsttfb_remove(struct pci_dev *pdev)
1541 struct fb_info *info = pci_get_drvdata(pdev);
1542 struct imstt_par *par = info->par;
1543 int size = pci_resource_len(pdev, 0);
1545 unregister_framebuffer(info);
1546 iounmap(par->cmap_regs);
1547 iounmap(par->dc_regs);
1548 iounmap(info->screen_base);
1549 release_mem_region(info->fix.smem_start, size);
1550 framebuffer_release(info);
1555 imsttfb_setup(char *options)
1559 if (!options || !*options)
1562 while ((this_opt = strsep(&options, ",")) != NULL) {
1563 if (!strncmp(this_opt, "font:", 5)) {
1568 for (i = 0; i < sizeof(fontname) - 1; i++)
1569 if (!*p || *p == ' ' || *p == ',')
1571 memcpy(fontname, this_opt + 5, i);
1573 } else if (!strncmp(this_opt, "inverse", 7)) {
1577 #if defined(CONFIG_PPC)
1578 else if (!strncmp(this_opt, "vmode:", 6)) {
1579 int vmode = simple_strtoul(this_opt+6, NULL, 0);
1580 if (vmode > 0 && vmode <= VMODE_MAX)
1582 } else if (!strncmp(this_opt, "cmode:", 6)) {
1583 int cmode = simple_strtoul(this_opt+6, NULL, 0);
1587 init_cmode = CMODE_8;
1592 init_cmode = CMODE_16;
1597 init_cmode = CMODE_32;
1608 static int __init imsttfb_init(void)
1611 char *option = NULL;
1613 if (fb_get_options("imsttfb", &option))
1616 imsttfb_setup(option);
1618 return pci_register_driver(&imsttfb_pci_driver);
1621 static void __exit imsttfb_exit(void)
1623 pci_unregister_driver(&imsttfb_pci_driver);
1626 MODULE_LICENSE("GPL");
1628 module_init(imsttfb_init);
1629 module_exit(imsttfb_exit);