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/config.h>
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/string.h>
25 #include <linux/tty.h>
26 #include <linux/slab.h>
27 #include <linux/vmalloc.h>
28 #include <linux/delay.h>
29 #include <linux/interrupt.h>
31 #include <linux/console.h>
32 #include <linux/selection.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
36 #include <asm/uaccess.h>
38 #if defined(CONFIG_PPC)
39 #include <linux/nvram.h>
41 #include <asm/pci-bridge.h>
42 #include <video/macmodes.h>
45 #include <video/fbcon.h>
46 #include <video/fbcon-cfb8.h>
47 #include <video/fbcon-cfb16.h>
48 #include <video/fbcon-cfb24.h>
49 #include <video/fbcon-cfb32.h>
52 #define eieio() /* Enforce In-order Execution of I/O */
55 /* TwinTurbo (Cosmo) registers */
62 DP_OCTL = 5, /* 0x14 */
66 BLTCTL = 10, /* 0x28 */
68 /* Scan Timing Generator Registers */
81 STGCTL = 24, /* 0x60 */
83 /* Screen Refresh Generator Registers */
88 SRGCTL = 29, /* 0x74 */
90 /* RAM Refresh Generator Registers */
91 RRCIV = 30, /* 0x78 */
95 /* System Registers */
99 SSTATUS = 36, /* 0x90 */
113 /* IBM 624 RAMDAC Direct Registers */
125 /* IBM 624 RAMDAC Indirect Registers */
127 CLKCTL = 0x02, /* (0x01) Miscellaneous Clock Control */
128 SYNCCTL = 0x03, /* (0x00) Sync Control */
129 HSYNCPOS = 0x04, /* (0x00) Horizontal Sync Position */
130 PWRMNGMT = 0x05, /* (0x00) Power Management */
131 DACOP = 0x06, /* (0x02) DAC Operation */
132 PALETCTL = 0x07, /* (0x00) Palette Control */
133 SYSCLKCTL = 0x08, /* (0x01) System Clock Control */
134 PIXFMT = 0x0a, /* () Pixel Format [bpp >> 3 + 2] */
135 BPP8 = 0x0b, /* () 8 Bits/Pixel Control */
136 BPP16 = 0x0c, /* () 16 Bits/Pixel Control [bit 1=1 for 565] */
137 BPP24 = 0x0d, /* () 24 Bits/Pixel Control */
138 BPP32 = 0x0e, /* () 32 Bits/Pixel Control */
139 PIXCTL1 = 0x10, /* (0x05) Pixel PLL Control 1 */
140 PIXCTL2 = 0x11, /* (0x00) Pixel PLL Control 2 */
141 SYSCLKN = 0x15, /* () System Clock N (System PLL Reference Divider) */
142 SYSCLKM = 0x16, /* () System Clock M (System PLL VCO Divider) */
143 SYSCLKP = 0x17, /* () System Clock P */
144 SYSCLKC = 0x18, /* () System Clock C */
146 * Dot clock rate is 20MHz * (m + 1) / ((n + 1) * (p ? 2 * p : 1)
147 * c is charge pump bias which depends on the VCO frequency
149 PIXM0 = 0x20, /* () Pixel M 0 */
150 PIXN0 = 0x21, /* () Pixel N 0 */
151 PIXP0 = 0x22, /* () Pixel P 0 */
152 PIXC0 = 0x23, /* () Pixel C 0 */
153 CURSCTL = 0x30, /* (0x00) Cursor Control */
154 CURSXLO = 0x31, /* () Cursor X position, low 8 bits */
155 CURSXHI = 0x32, /* () Cursor X position, high 8 bits */
156 CURSYLO = 0x33, /* () Cursor Y position, low 8 bits */
157 CURSYHI = 0x34, /* () Cursor Y position, high 8 bits */
158 CURSHOTX = 0x35, /* () Cursor Hot Spot X */
159 CURSHOTY = 0x36, /* () Cursor Hot Spot Y */
160 CURSACCTL = 0x37, /* () Advanced Cursor Control Enable */
161 CURSACATTR = 0x38, /* () Advanced Cursor Attribute */
162 CURS1R = 0x40, /* () Cursor 1 Red */
163 CURS1G = 0x41, /* () Cursor 1 Green */
164 CURS1B = 0x42, /* () Cursor 1 Blue */
165 CURS2R = 0x43, /* () Cursor 2 Red */
166 CURS2G = 0x44, /* () Cursor 2 Green */
167 CURS2B = 0x45, /* () Cursor 2 Blue */
168 CURS3R = 0x46, /* () Cursor 3 Red */
169 CURS3G = 0x47, /* () Cursor 3 Green */
170 CURS3B = 0x48, /* () Cursor 3 Blue */
171 BORDR = 0x60, /* () Border Color Red */
172 BORDG = 0x61, /* () Border Color Green */
173 BORDB = 0x62, /* () Border Color Blue */
174 MISCTL1 = 0x70, /* (0x00) Miscellaneous Control 1 */
175 MISCTL2 = 0x71, /* (0x00) Miscellaneous Control 2 */
176 MISCTL3 = 0x72, /* (0x00) Miscellaneous Control 3 */
177 KEYCTL = 0x78 /* (0x00) Key Control/DB Operation */
180 /* TI TVP 3030 RAMDAC Direct Registers */
182 TVPADDRW = 0x00, /* 0 Palette/Cursor RAM Write Address/Index */
183 TVPPDATA = 0x04, /* 1 Palette Data RAM Data */
184 TVPPMASK = 0x08, /* 2 Pixel Read-Mask */
185 TVPPADRR = 0x0c, /* 3 Palette/Cursor RAM Read Address */
186 TVPCADRW = 0x10, /* 4 Cursor/Overscan Color Write Address */
187 TVPCDATA = 0x14, /* 5 Cursor/Overscan Color Data */
189 TVPCADRR = 0x1c, /* 7 Cursor/Overscan Color Read Address */
191 TVPDCCTL = 0x24, /* 9 Direct Cursor Control */
192 TVPIDATA = 0x28, /* 10 Index Data */
193 TVPCRDAT = 0x2c, /* 11 Cursor RAM Data */
194 TVPCXPOL = 0x30, /* 12 Cursor-Position X LSB */
195 TVPCXPOH = 0x34, /* 13 Cursor-Position X MSB */
196 TVPCYPOL = 0x38, /* 14 Cursor-Position Y LSB */
197 TVPCYPOH = 0x3c, /* 15 Cursor-Position Y MSB */
200 /* TI TVP 3030 RAMDAC Indirect Registers */
202 TVPIRREV = 0x01, /* Silicon Revision [RO] */
203 TVPIRICC = 0x06, /* Indirect Cursor Control (0x00) */
204 TVPIRBRC = 0x07, /* Byte Router Control (0xe4) */
205 TVPIRLAC = 0x0f, /* Latch Control (0x06) */
206 TVPIRTCC = 0x18, /* True Color Control (0x80) */
207 TVPIRMXC = 0x19, /* Multiplex Control (0x98) */
208 TVPIRCLS = 0x1a, /* Clock Selection (0x07) */
209 TVPIRPPG = 0x1c, /* Palette Page (0x00) */
210 TVPIRGEC = 0x1d, /* General Control (0x00) */
211 TVPIRMIC = 0x1e, /* Miscellaneous Control (0x00) */
212 TVPIRPLA = 0x2c, /* PLL Address */
213 TVPIRPPD = 0x2d, /* Pixel Clock PLL Data */
214 TVPIRMPD = 0x2e, /* Memory Clock PLL Data */
215 TVPIRLPD = 0x2f, /* Loop Clock PLL Data */
216 TVPIRCKL = 0x30, /* Color-Key Overlay Low */
217 TVPIRCKH = 0x31, /* Color-Key Overlay High */
218 TVPIRCRL = 0x32, /* Color-Key Red Low */
219 TVPIRCRH = 0x33, /* Color-Key Red High */
220 TVPIRCGL = 0x34, /* Color-Key Green Low */
221 TVPIRCGH = 0x35, /* Color-Key Green High */
222 TVPIRCBL = 0x36, /* Color-Key Blue Low */
223 TVPIRCBH = 0x37, /* Color-Key Blue High */
224 TVPIRCKC = 0x38, /* Color-Key Control (0x00) */
225 TVPIRMLC = 0x39, /* MCLK/Loop Clock Control (0x18) */
226 TVPIRSEN = 0x3a, /* Sense Test (0x00) */
227 TVPIRTMD = 0x3b, /* Test Mode Data */
228 TVPIRRML = 0x3c, /* CRC Remainder LSB [RO] */
229 TVPIRRMM = 0x3d, /* CRC Remainder MSB [RO] */
230 TVPIRRMS = 0x3e, /* CRC Bit Select [WO] */
231 TVPIRDID = 0x3f, /* Device ID [RO] (0x30) */
232 TVPIRRES = 0xff /* Software Reset [WO] */
239 static struct initvalues ibm_initregs[] __initdata = {
249 * Note that colors in X are correct only if all video data is
250 * passed through the palette in the DAC. That is, "indirect
251 * color" must be configured. This is the case for the IBM DAC
252 * used in the 2MB and 4MB cards, at least.
267 { CURSACATTR, 0xa8 },
286 static struct initvalues tvp_initregs[] __initdata = {
319 struct imstt_regvals {
321 __u16 hes, heb, hsb, ht, ves, veb, vsb, vt, vil;
322 __u8 pclk_m, pclk_n, pclk_p;
323 /* Values of the tvp which change depending on colormode x resolution */
324 __u8 mlc[3]; /* Memory Loop Config 0x39 */
325 __u8 lckl_p[3]; /* P value of LCKL PLL */
328 struct imstt_cursor {
329 struct timer_list timer;
334 __u16 x, y, width, height;
337 struct fb_info_imstt {
339 struct fb_fix_screeninfo fix;
341 struct display_switch dispsw;
343 #ifdef FBCON_HAS_CFB16
346 #ifdef FBCON_HAS_CFB24
349 #ifdef FBCON_HAS_CFB32
354 __u8 red, green, blue;
356 struct imstt_regvals init;
357 struct imstt_cursor cursor;
358 unsigned long frame_buffer_phys;
359 unsigned long board_size;
361 unsigned long dc_regs_phys;
363 unsigned long cmap_regs_phys;
375 #define INIT_XRES 640
376 #define INIT_YRES 480
377 #define CURSOR_BLINK_RATE 20
378 #define CURSOR_DRAW_DELAY 2
380 static int currcon = 0;
381 static int inverse = 0;
382 static char fontname[40] __initdata = { 0 };
383 static char curblink __initdata = 1;
384 static char noaccel __initdata = 0;
385 #if defined(CONFIG_PPC)
386 static signed char init_vmode __initdata = VMODE_NVRAM;
387 static signed char init_cmode __initdata = CMODE_NVRAM;
390 static struct imstt_regvals tvp_reg_init_2 = {
392 0x0002, 0x0006, 0x0026, 0x0028, 0x0003, 0x0016, 0x0196, 0x0197, 0x0196,
394 { 0x3c, 0x3b, 0x39 }, { 0xf3, 0xf3, 0xf3 }
397 static struct imstt_regvals tvp_reg_init_6 = {
399 0x0004, 0x0009, 0x0031, 0x0036, 0x0003, 0x002a, 0x020a, 0x020d, 0x020a,
401 { 0x39, 0x39, 0x38 }, { 0xf3, 0xf3, 0xf3 }
404 static struct imstt_regvals tvp_reg_init_12 = {
406 0x0005, 0x000e, 0x0040, 0x0042, 0x0003, 0x018, 0x270, 0x271, 0x270,
408 { 0x3a, 0x39, 0x38 }, { 0xf3, 0xf3, 0xf3 }
411 static struct imstt_regvals tvp_reg_init_13 = {
413 0x0004, 0x0011, 0x0045, 0x0048, 0x0003, 0x002a, 0x029a, 0x029b, 0x0000,
415 { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
418 static struct imstt_regvals tvp_reg_init_17 = {
420 0x0006, 0x0210, 0x0250, 0x0053, 0x1003, 0x0021, 0x0321, 0x0324, 0x0000,
422 { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
425 static struct imstt_regvals tvp_reg_init_18 = {
427 0x0009, 0x0011, 0x059, 0x5b, 0x0003, 0x0031, 0x0397, 0x039a, 0x0000,
429 { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
432 static struct imstt_regvals tvp_reg_init_19 = {
434 0x0009, 0x0016, 0x0066, 0x0069, 0x0003, 0x0027, 0x03e7, 0x03e8, 0x03e7,
436 { 0x38, 0x38, 0x38 }, { 0xf3, 0xf2, 0xf1 }
439 static struct imstt_regvals tvp_reg_init_20 = {
441 0x0009, 0x0018, 0x0068, 0x006a, 0x0003, 0x0029, 0x0429, 0x042a, 0x0000,
443 { 0x38, 0x38, 0x38 }, { 0xf3, 0xf2, 0xf1 }
447 * PCI driver prototypes
449 static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
450 static void imsttfb_remove(struct pci_dev *pdev);
453 getclkMHz (struct fb_info_imstt *p)
455 __u32 clk_m, clk_n, clk_p;
457 clk_m = p->init.pclk_m;
458 clk_n = p->init.pclk_n;
459 clk_p = p->init.pclk_p;
461 return 20 * (clk_m + 1) / ((clk_n + 1) * (clk_p ? 2 * clk_p : 1));
465 setclkMHz (struct fb_info_imstt *p, __u32 MHz)
467 __u32 clk_m, clk_n, clk_p, x, stage, spilled;
469 clk_m = clk_n = clk_p = 0;
480 x = 20 * (clk_m + 1) / ((clk_n + 1) * (clk_p ? 2 * clk_p : 1));
486 } else if (spilled && x < MHz) {
491 p->init.pclk_m = clk_m;
492 p->init.pclk_n = clk_n;
493 p->init.pclk_p = clk_p;
496 static struct imstt_regvals *
497 compute_imstt_regvals_ibm (struct fb_info_imstt *p, int xres, int yres)
499 struct imstt_regvals *init = &p->init;
500 __u32 MHz, hes, heb, veb, htp, vtp;
504 hes = 0x0008; heb = 0x0012; veb = 0x002a; htp = 10; vtp = 2;
508 hes = 0x0005; heb = 0x0020; veb = 0x0028; htp = 8; vtp = 3;
509 MHz = 57 /* .27_ */ ;
512 hes = 0x000a; heb = 0x001c; veb = 0x0020; htp = 8; vtp = 3;
516 hes = 0x0012; heb = 0x0022; veb = 0x0031; htp = 4; vtp = 3;
517 MHz = 101 /* .6_ */ ;
520 hes = 0x0012; heb = 0x002f; veb = 0x0029; htp = 4; vtp = 1;
521 MHz = yres == 960 ? 126 : 135;
524 hes = 0x0018; heb = 0x0040; veb = 0x002a; htp = 4; vtp = 3;
535 init->hsb = init->heb + (xres >> 3);
536 init->ht = init->hsb + htp;
539 init->vsb = init->veb + yres;
540 init->vt = init->vsb + vtp;
541 init->vil = init->vsb;
548 static struct imstt_regvals *
549 compute_imstt_regvals_tvp (struct fb_info_imstt *p, int xres, int yres)
551 struct imstt_regvals *init;
555 init = &tvp_reg_init_2;
558 init = &tvp_reg_init_6;
561 init = &tvp_reg_init_12;
564 init = &tvp_reg_init_13;
567 init = &tvp_reg_init_17;
570 init = &tvp_reg_init_18;
573 init = yres == 960 ? &tvp_reg_init_19 : &tvp_reg_init_20;
583 static struct imstt_regvals *
584 compute_imstt_regvals (struct fb_info_imstt *p, u_int xres, u_int yres)
586 if (p->ramdac == IBM)
587 return compute_imstt_regvals_ibm(p, xres, yres);
589 return compute_imstt_regvals_tvp(p, xres, yres);
593 set_imstt_regvals_ibm (struct fb_info_imstt *p, u_int bpp)
595 struct imstt_regvals *init = &p->init;
596 __u8 pformat = (bpp >> 3) + 2;
598 p->cmap_regs[PIDXHI] = 0; eieio();
599 p->cmap_regs[PIDXLO] = PIXM0; eieio();
600 p->cmap_regs[PIDXDATA] = init->pclk_m; eieio();
601 p->cmap_regs[PIDXLO] = PIXN0; eieio();
602 p->cmap_regs[PIDXDATA] = init->pclk_n; eieio();
603 p->cmap_regs[PIDXLO] = PIXP0; eieio();
604 p->cmap_regs[PIDXDATA] = init->pclk_p; eieio();
605 p->cmap_regs[PIDXLO] = PIXC0; eieio();
606 p->cmap_regs[PIDXDATA] = 0x02; eieio();
608 p->cmap_regs[PIDXLO] = PIXFMT; eieio();
609 p->cmap_regs[PIDXDATA] = pformat; eieio();
613 set_imstt_regvals_tvp (struct fb_info_imstt *p, u_int bpp)
615 struct imstt_regvals *init = &p->init;
616 __u8 tcc, mxc, lckl_n, mic;
625 lckl_p = init->lckl_p[0];
632 lckl_p = init->lckl_p[1];
639 lckl_p = init->lckl_p[2];
646 lckl_p = init->lckl_p[2];
651 p->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
652 p->cmap_regs[TVPIDATA] = 0x00; eieio();
653 p->cmap_regs[TVPADDRW] = TVPIRPPD; eieio();
654 p->cmap_regs[TVPIDATA] = init->pclk_m; eieio();
655 p->cmap_regs[TVPADDRW] = TVPIRPPD; eieio();
656 p->cmap_regs[TVPIDATA] = init->pclk_n; eieio();
657 p->cmap_regs[TVPADDRW] = TVPIRPPD; eieio();
658 p->cmap_regs[TVPIDATA] = init->pclk_p; eieio();
660 p->cmap_regs[TVPADDRW] = TVPIRTCC; eieio();
661 p->cmap_regs[TVPIDATA] = tcc; eieio();
662 p->cmap_regs[TVPADDRW] = TVPIRMXC; eieio();
663 p->cmap_regs[TVPIDATA] = mxc; eieio();
664 p->cmap_regs[TVPADDRW] = TVPIRMIC; eieio();
665 p->cmap_regs[TVPIDATA] = mic; eieio();
667 p->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
668 p->cmap_regs[TVPIDATA] = 0x00; eieio();
669 p->cmap_regs[TVPADDRW] = TVPIRLPD; eieio();
670 p->cmap_regs[TVPIDATA] = lckl_n; eieio();
672 p->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
673 p->cmap_regs[TVPIDATA] = 0x15; eieio();
674 p->cmap_regs[TVPADDRW] = TVPIRMLC; eieio();
675 p->cmap_regs[TVPIDATA] = mlc; eieio();
677 p->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
678 p->cmap_regs[TVPIDATA] = 0x2a; eieio();
679 p->cmap_regs[TVPADDRW] = TVPIRLPD; eieio();
680 p->cmap_regs[TVPIDATA] = lckl_p; eieio();
684 set_imstt_regvals (struct fb_info_imstt *p, u_int bpp)
686 struct imstt_regvals *init = &p->init;
687 __u32 ctl, pitch, byteswap, scr;
689 if (p->ramdac == IBM)
690 set_imstt_regvals_ibm(p, bpp);
692 set_imstt_regvals_tvp(p, bpp);
695 * From what I (jsk) can gather poking around with MacsBug,
696 * bits 8 and 9 in the SCR register control endianness
697 * correction (byte swapping). These bits must be set according
698 * to the color depth as follows:
699 * Color depth Bit 9 Bit 8
700 * ========== ===== =====
708 pitch = init->pitch >> 2;
713 pitch = init->pitch >> 1;
718 pitch = init->pitch - (p->init.pitch >> 2);
727 if (p->ramdac == TVP)
730 out_le32(&p->dc_regs[HES], init->hes);
731 out_le32(&p->dc_regs[HEB], init->heb);
732 out_le32(&p->dc_regs[HSB], init->hsb);
733 out_le32(&p->dc_regs[HT], init->ht);
734 out_le32(&p->dc_regs[VES], init->ves);
735 out_le32(&p->dc_regs[VEB], init->veb);
736 out_le32(&p->dc_regs[VSB], init->vsb);
737 out_le32(&p->dc_regs[VT], init->vt);
738 out_le32(&p->dc_regs[VIL], init->vil);
739 out_le32(&p->dc_regs[HCIV], 1);
740 out_le32(&p->dc_regs[VCIV], 1);
741 out_le32(&p->dc_regs[TCDR], 4);
742 out_le32(&p->dc_regs[RRCIV], 1);
743 out_le32(&p->dc_regs[RRSC], 0x980);
744 out_le32(&p->dc_regs[RRCR], 0x11);
746 if (p->ramdac == IBM) {
747 out_le32(&p->dc_regs[HRIR], 0x0100);
748 out_le32(&p->dc_regs[CMR], 0x00ff);
749 out_le32(&p->dc_regs[SRGCTL], 0x0073);
751 out_le32(&p->dc_regs[HRIR], 0x0200);
752 out_le32(&p->dc_regs[CMR], 0x01ff);
753 out_le32(&p->dc_regs[SRGCTL], 0x0003);
756 switch (p->total_vram) {
758 scr = 0x059d | byteswap;
764 scr = 0x150dd | byteswap;
768 out_le32(&p->dc_regs[SCR], scr);
769 out_le32(&p->dc_regs[SPR], pitch);
770 out_le32(&p->dc_regs[STGCTL], ctl);
774 set_offset (struct display *disp, struct fb_info_imstt *p)
776 __u32 off = disp->var.yoffset * (disp->line_length >> 3)
777 + ((disp->var.xoffset * (disp->var.bits_per_pixel >> 3)) >> 3);
778 out_le32(&p->dc_regs[SSR], off);
782 set_555 (struct fb_info_imstt *p)
784 if (p->ramdac == IBM) {
785 p->cmap_regs[PIDXHI] = 0; eieio();
786 p->cmap_regs[PIDXLO] = BPP16; eieio();
787 p->cmap_regs[PIDXDATA] = 0x01; eieio();
789 p->cmap_regs[TVPADDRW] = TVPIRTCC; eieio();
790 p->cmap_regs[TVPIDATA] = 0x44; eieio();
795 set_565 (struct fb_info_imstt *p)
797 if (p->ramdac == IBM) {
798 p->cmap_regs[PIDXHI] = 0; eieio();
799 p->cmap_regs[PIDXLO] = BPP16; eieio();
800 p->cmap_regs[PIDXDATA] = 0x03; eieio();
802 p->cmap_regs[TVPADDRW] = TVPIRTCC; eieio();
803 p->cmap_regs[TVPIDATA] = 0x45; eieio();
808 imstt_set_cursor (struct fb_info_imstt *p, int on)
810 struct imstt_cursor *c = &p->cursor;
812 if (p->ramdac == IBM) {
813 p->cmap_regs[PIDXHI] = 0; eieio();
815 p->cmap_regs[PIDXLO] = CURSCTL; eieio();
816 p->cmap_regs[PIDXDATA] = 0x00; eieio();
818 p->cmap_regs[PIDXLO] = CURSXHI; eieio();
819 p->cmap_regs[PIDXDATA] = c->x >> 8; eieio();
820 p->cmap_regs[PIDXLO] = CURSXLO; eieio();
821 p->cmap_regs[PIDXDATA] = c->x & 0xff; eieio();
822 p->cmap_regs[PIDXLO] = CURSYHI; eieio();
823 p->cmap_regs[PIDXDATA] = c->y >> 8; eieio();
824 p->cmap_regs[PIDXLO] = CURSYLO; eieio();
825 p->cmap_regs[PIDXDATA] = c->y & 0xff; eieio();
826 p->cmap_regs[PIDXLO] = CURSCTL; eieio();
827 p->cmap_regs[PIDXDATA] = 0x02; eieio();
831 p->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
832 p->cmap_regs[TVPIDATA] = 0x00; eieio();
834 __u16 x = c->x + 0x40, y = c->y + 0x40;
836 p->cmap_regs[TVPCXPOH] = x >> 8; eieio();
837 p->cmap_regs[TVPCXPOL] = x & 0xff; eieio();
838 p->cmap_regs[TVPCYPOH] = y >> 8; eieio();
839 p->cmap_regs[TVPCYPOL] = y & 0xff; eieio();
840 p->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
841 p->cmap_regs[TVPIDATA] = 0x02; eieio();
847 imsttfbcon_cursor (struct display *disp, int mode, int x, int y)
849 struct fb_info_imstt *p = (struct fb_info_imstt *)disp->fb_info;
850 struct imstt_cursor *c = &p->cursor;
852 x *= fontwidth(disp);
853 y *= fontheight(disp);
855 if (c->x == x && c->y == y && (mode == CM_ERASE) == !c->enable)
860 imstt_set_cursor(p, 0);
861 c->x = x - disp->var.xoffset;
862 c->y = y - disp->var.yoffset;
871 imstt_set_cursor(p, c->on);
873 c->vbl_cnt = CURSOR_DRAW_DELAY;
880 imsttfbcon_set_font (struct display *disp, int width, int height)
882 struct fb_info_imstt *p = (struct fb_info_imstt *)disp->fb_info;
883 struct imstt_cursor *c = &p->cursor;
887 if (width > 32 || height > 32)
893 fgc = ~attr_bgcol_ec(disp, disp->conp);
895 if (p->ramdac == IBM) {
896 p->cmap_regs[PIDXHI] = 1; eieio();
897 for (x = 0; x < 0x100; x++) {
898 p->cmap_regs[PIDXLO] = x; eieio();
899 p->cmap_regs[PIDXDATA] = 0x00; eieio();
901 p->cmap_regs[PIDXHI] = 1; eieio();
902 for (y = 0; y < height; y++)
903 for (x = 0; x < width >> 2; x++) {
904 p->cmap_regs[PIDXLO] = x + y * 8; eieio();
905 p->cmap_regs[PIDXDATA] = 0xff; eieio();
907 p->cmap_regs[PIDXHI] = 0; eieio();
908 p->cmap_regs[PIDXLO] = CURS1R; eieio();
909 p->cmap_regs[PIDXDATA] = fgc; eieio();
910 p->cmap_regs[PIDXLO] = CURS1G; eieio();
911 p->cmap_regs[PIDXDATA] = fgc; eieio();
912 p->cmap_regs[PIDXLO] = CURS1B; eieio();
913 p->cmap_regs[PIDXDATA] = fgc; eieio();
914 p->cmap_regs[PIDXLO] = CURS2R; eieio();
915 p->cmap_regs[PIDXDATA] = fgc; eieio();
916 p->cmap_regs[PIDXLO] = CURS2G; eieio();
917 p->cmap_regs[PIDXDATA] = fgc; eieio();
918 p->cmap_regs[PIDXLO] = CURS2B; eieio();
919 p->cmap_regs[PIDXDATA] = fgc; eieio();
920 p->cmap_regs[PIDXLO] = CURS3R; eieio();
921 p->cmap_regs[PIDXDATA] = fgc; eieio();
922 p->cmap_regs[PIDXLO] = CURS3G; eieio();
923 p->cmap_regs[PIDXDATA] = fgc; eieio();
924 p->cmap_regs[PIDXLO] = CURS3B; eieio();
925 p->cmap_regs[PIDXDATA] = fgc; eieio();
927 p->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
928 p->cmap_regs[TVPIDATA] &= 0x03; eieio();
929 p->cmap_regs[TVPADDRW] = 0; eieio();
930 for (x = 0; x < 0x200; x++) {
931 p->cmap_regs[TVPCRDAT] = 0x00; eieio();
933 for (x = 0; x < 0x200; x++) {
934 p->cmap_regs[TVPCRDAT] = 0xff; eieio();
936 p->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
937 p->cmap_regs[TVPIDATA] &= 0x03; eieio();
938 for (y = 0; y < height; y++)
939 for (x = 0; x < width >> 3; x++) {
940 p->cmap_regs[TVPADDRW] = x + y * 8; eieio();
941 p->cmap_regs[TVPCRDAT] = 0xff; eieio();
943 p->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
944 p->cmap_regs[TVPIDATA] |= 0x08; eieio();
945 for (y = 0; y < height; y++)
946 for (x = 0; x < width >> 3; x++) {
947 p->cmap_regs[TVPADDRW] = x + y * 8; eieio();
948 p->cmap_regs[TVPCRDAT] = 0xff; eieio();
950 p->cmap_regs[TVPCADRW] = 0x00; eieio();
951 for (x = 0; x < 12; x++) {
952 p->cmap_regs[TVPCDATA] = fgc; eieio();
960 imstt_cursor_timer_handler (unsigned long dev_addr)
962 struct fb_info_imstt *p = (struct fb_info_imstt *)dev_addr;
963 struct imstt_cursor *c = &p->cursor;
968 if (c->vbl_cnt && --c->vbl_cnt == 0) {
970 imstt_set_cursor(p, c->on);
971 c->vbl_cnt = c->blink_rate;
975 c->timer.expires = jiffies + (HZ / 50);
976 add_timer(&c->timer);
980 imstt_cursor_init (struct fb_info_imstt *p)
982 struct imstt_cursor *c = &p->cursor;
984 imsttfbcon_set_font(&p->disp, fontwidth(&p->disp), fontheight(&p->disp));
990 c->vbl_cnt = CURSOR_DRAW_DELAY;
993 c->blink_rate = CURSOR_BLINK_RATE;
994 init_timer(&c->timer);
995 c->timer.expires = jiffies + (HZ / 50);
996 c->timer.data = (unsigned long)p;
997 c->timer.function = imstt_cursor_timer_handler;
998 add_timer(&c->timer);
1003 imsttfbcon_bmove (struct display *disp, int sy, int sx, int dy, int dx, int height, int width)
1005 struct fb_info_imstt *p = (struct fb_info_imstt *)disp->fb_info;
1006 __u32 Bpp, line_pitch,
1007 fb_offset_old, fb_offset_new,
1008 sp, dp_octl, cnt, bltctl;
1010 Bpp = disp->var.bits_per_pixel >> 3,
1012 sy *= fontheight(disp);
1013 sx *= fontwidth(disp);
1015 dy *= fontheight(disp);
1016 dx *= fontwidth(disp);
1018 height *= fontheight(disp);
1020 width *= fontwidth(disp);
1024 line_pitch = disp->line_length;
1026 sp = line_pitch << 16;
1032 sp |= -(line_pitch) & 0xffff;
1033 dp_octl = -(line_pitch) & 0xffff;
1036 dp_octl = line_pitch;
1042 cnt |= -(width) & 0xffff;
1046 fb_offset_old = sy * line_pitch + sx;
1047 fb_offset_new = dy * line_pitch + dx;
1049 while(in_le32(&p->dc_regs[SSTATUS]) & 0x80);
1050 out_le32(&p->dc_regs[S1SA], fb_offset_old);
1051 out_le32(&p->dc_regs[SP], sp);
1052 out_le32(&p->dc_regs[DSA], fb_offset_new);
1053 out_le32(&p->dc_regs[CNT], cnt);
1054 out_le32(&p->dc_regs[DP_OCTL], dp_octl);
1055 out_le32(&p->dc_regs[BLTCTL], bltctl);
1056 while(in_le32(&p->dc_regs[SSTATUS]) & 0x80);
1057 while(in_le32(&p->dc_regs[SSTATUS]) & 0x40);
1061 imsttfbcon_clear (struct vc_data *conp, struct display *disp,
1062 int sy, int sx, int height, int width)
1064 struct fb_info_imstt *p = (struct fb_info_imstt *)disp->fb_info;
1065 __u32 Bpp, line_pitch, bgc;
1067 bgc = attr_bgcol_ec(disp, conp);
1071 Bpp = disp->var.bits_per_pixel >> 3,
1072 line_pitch = disp->line_length;
1074 sy *= fontheight(disp);
1076 sx *= fontwidth(disp);
1078 height *= fontheight(disp);
1080 width *= fontwidth(disp);
1084 while(in_le32(&p->dc_regs[SSTATUS]) & 0x80);
1085 out_le32(&p->dc_regs[DSA], sy + sx);
1086 out_le32(&p->dc_regs[CNT], (height << 16) | width);
1087 out_le32(&p->dc_regs[DP_OCTL], line_pitch);
1088 out_le32(&p->dc_regs[BI], 0xffffffff);
1089 out_le32(&p->dc_regs[MBC], 0xffffffff);
1090 out_le32(&p->dc_regs[CLR], bgc);
1091 out_le32(&p->dc_regs[BLTCTL], 0x840); /* 0x200000 */
1092 while(in_le32(&p->dc_regs[SSTATUS]) & 0x80);
1093 while(in_le32(&p->dc_regs[SSTATUS]) & 0x40);
1097 imsttfbcon_revc (struct display *disp, int sx, int sy)
1099 struct fb_info_imstt *p = (struct fb_info_imstt *)disp->fb_info;
1100 __u32 Bpp, line_pitch, height, width;
1102 Bpp = disp->var.bits_per_pixel >> 3,
1103 line_pitch = disp->line_length;
1105 height = fontheight(disp);
1106 width = fontwidth(disp) * Bpp;
1113 while(in_le32(&p->dc_regs[SSTATUS]) & 0x80);
1114 out_le32(&p->dc_regs[DSA], sy + sx);
1115 out_le32(&p->dc_regs[S1SA], sy + sx);
1116 out_le32(&p->dc_regs[CNT], (height << 16) | width);
1117 out_le32(&p->dc_regs[DP_OCTL], line_pitch);
1118 out_le32(&p->dc_regs[SP], line_pitch);
1119 out_le32(&p->dc_regs[BLTCTL], 0x40005);
1120 while(in_le32(&p->dc_regs[SSTATUS]) & 0x80);
1121 while(in_le32(&p->dc_regs[SSTATUS]) & 0x40);
1124 #ifdef FBCON_HAS_CFB8
1125 static struct display_switch fbcon_imstt8 = {
1126 setup: fbcon_cfb8_setup,
1127 bmove: imsttfbcon_bmove,
1128 clear: imsttfbcon_clear,
1129 putc: fbcon_cfb8_putc,
1130 putcs: fbcon_cfb8_putcs,
1131 revc: imsttfbcon_revc,
1132 cursor: imsttfbcon_cursor,
1133 set_font: imsttfbcon_set_font,
1134 clear_margins: fbcon_cfb8_clear_margins,
1135 fontwidthmask: FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
1138 #ifdef FBCON_HAS_CFB16
1139 static struct display_switch fbcon_imstt16 = {
1140 setup: fbcon_cfb16_setup,
1141 bmove: imsttfbcon_bmove,
1142 clear: imsttfbcon_clear,
1143 putc: fbcon_cfb16_putc,
1144 putcs: fbcon_cfb16_putcs,
1145 revc: imsttfbcon_revc,
1146 cursor: imsttfbcon_cursor,
1147 set_font: imsttfbcon_set_font,
1148 clear_margins: fbcon_cfb16_clear_margins,
1149 fontwidthmask: FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
1152 #ifdef FBCON_HAS_CFB24
1153 static struct display_switch fbcon_imstt24 = {
1154 setup: fbcon_cfb24_setup,
1155 bmove: imsttfbcon_bmove,
1156 clear: imsttfbcon_clear,
1157 putc: fbcon_cfb24_putc,
1158 putcs: fbcon_cfb24_putcs,
1159 revc: imsttfbcon_revc,
1160 cursor: imsttfbcon_cursor,
1161 set_font: imsttfbcon_set_font,
1162 clear_margins: fbcon_cfb24_clear_margins,
1163 fontwidthmask: FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
1166 #ifdef FBCON_HAS_CFB32
1167 static struct display_switch fbcon_imstt32 = {
1168 setup: fbcon_cfb32_setup,
1169 bmove: imsttfbcon_bmove,
1170 clear: imsttfbcon_clear,
1171 putc: fbcon_cfb32_putc,
1172 putcs: fbcon_cfb32_putcs,
1173 revc: imsttfbcon_revc,
1174 cursor: imsttfbcon_cursor,
1175 set_font: imsttfbcon_set_font,
1176 clear_margins: fbcon_cfb32_clear_margins,
1177 fontwidthmask: FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
1181 #ifdef CONFIG_FB_COMPAT_XPMAC
1182 #include <asm/vc_ioctl.h>
1184 extern struct vc_mode display_info;
1185 extern struct fb_info *console_fb_info;
1188 set_display_info (struct display *disp)
1190 display_info.width = disp->var.xres;
1191 display_info.height = disp->var.yres;
1192 display_info.depth = disp->var.bits_per_pixel;
1193 display_info.pitch = disp->line_length;
1195 switch (disp->var.xres) {
1197 display_info.mode = 2;
1200 display_info.mode = 6;
1203 display_info.mode = 12;
1206 display_info.mode = 13;
1209 display_info.mode = 17;
1212 display_info.mode = 18;
1215 display_info.mode = disp->var.yres == 960 ? 19 : 20;
1218 display_info.mode = 0;
1224 imsttfb_getcolreg (u_int regno, u_int *red, u_int *green,
1225 u_int *blue, u_int *transp, struct fb_info *info)
1227 struct fb_info_imstt *p = (struct fb_info_imstt *)info;
1231 *red = (p->palette[regno].red << 8) | p->palette[regno].red;
1232 *green = (p->palette[regno].green << 8) | p->palette[regno].green;
1233 *blue = (p->palette[regno].blue << 8) | p->palette[regno].blue;
1240 imsttfb_setcolreg (u_int regno, u_int red, u_int green, u_int blue,
1241 u_int transp, struct fb_info *info)
1243 struct fb_info_imstt *p = (struct fb_info_imstt *)info;
1244 u_int bpp = fb_display[currcon].var.bits_per_pixel;
1253 p->palette[regno].red = red;
1254 p->palette[regno].green = green;
1255 p->palette[regno].blue = blue;
1257 /* PADDRW/PDATA are the same as TVPPADDRW/TVPPDATA */
1258 if (0 && bpp == 16) /* screws up X */
1259 p->cmap_regs[PADDRW] = regno << 3;
1261 p->cmap_regs[PADDRW] = regno;
1264 p->cmap_regs[PDATA] = red; eieio();
1265 p->cmap_regs[PDATA] = green; eieio();
1266 p->cmap_regs[PDATA] = blue; eieio();
1270 #ifdef FBCON_HAS_CFB16
1272 p->fbcon_cmap.cfb16[regno] = (regno << (fb_display[currcon].var.green.length == 5 ? 10 : 11)) | (regno << 5) | regno;
1275 #ifdef FBCON_HAS_CFB24
1277 p->fbcon_cmap.cfb24[regno] = (regno << 16) | (regno << 8) | regno;
1280 #ifdef FBCON_HAS_CFB32
1282 int i = (regno << 8) | regno;
1283 p->fbcon_cmap.cfb32[regno] = (i << 16) | i;
1293 do_install_cmap (int con, struct fb_info *info)
1295 if (fb_display[con].cmap.len)
1296 fb_set_cmap(&fb_display[con].cmap, 1, imsttfb_setcolreg, info);
1298 u_int size = fb_display[con].var.bits_per_pixel == 16 ? 32 : 256;
1299 fb_set_cmap(fb_default_cmap(size), 1, imsttfb_setcolreg, info);
1304 imsttfb_get_fix (struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
1306 struct fb_info_imstt *p = (struct fb_info_imstt *)info;
1307 struct fb_var_screeninfo *var = &fb_display[con].var;
1310 fix->visual = var->bits_per_pixel == 8 ? FB_VISUAL_PSEUDOCOLOR
1311 : FB_VISUAL_DIRECTCOLOR;
1312 fix->line_length = var->xres * (var->bits_per_pixel >> 3);
1318 imsttfb_get_var (struct fb_var_screeninfo *var, int con, struct fb_info *info)
1320 *var = fb_display[con].var;
1326 set_dispsw (struct display *disp, struct fb_info_imstt *p)
1328 u_int accel = disp->var.accel_flags & FB_ACCELF_TEXT;
1330 if (disp->conp && disp->conp->vc_sw && disp->conp->vc_sw->con_cursor)
1331 disp->conp->vc_sw->con_cursor(disp->conp, CM_ERASE);
1333 p->dispsw = fbcon_dummy;
1334 disp->dispsw = &p->dispsw;
1335 disp->dispsw_data = 0;
1336 switch (disp->var.bits_per_pixel) {
1338 disp->var.red.offset = 0;
1339 disp->var.red.length = 8;
1340 disp->var.green.offset = 0;
1341 disp->var.green.length = 8;
1342 disp->var.blue.offset = 0;
1343 disp->var.blue.length = 8;
1344 disp->var.transp.offset = 0;
1345 disp->var.transp.length = 0;
1346 #ifdef FBCON_HAS_CFB8
1347 p->dispsw = accel ? fbcon_imstt8 : fbcon_cfb8;
1350 case 16: /* RGB 555 or 565 */
1351 if (disp->var.green.length != 6)
1352 disp->var.red.offset = 10;
1353 disp->var.red.length = 5;
1354 disp->var.green.offset = 5;
1355 if (disp->var.green.length != 6)
1356 disp->var.green.length = 5;
1357 disp->var.blue.offset = 0;
1358 disp->var.blue.length = 5;
1359 disp->var.transp.offset = 0;
1360 disp->var.transp.length = 0;
1361 #ifdef FBCON_HAS_CFB16
1362 p->dispsw = accel ? fbcon_imstt16 : fbcon_cfb16;
1363 disp->dispsw_data = p->fbcon_cmap.cfb16;
1366 case 24: /* RGB 888 */
1367 disp->var.red.offset = 16;
1368 disp->var.red.length = 8;
1369 disp->var.green.offset = 8;
1370 disp->var.green.length = 8;
1371 disp->var.blue.offset = 0;
1372 disp->var.blue.length = 8;
1373 disp->var.transp.offset = 0;
1374 disp->var.transp.length = 0;
1375 #ifdef FBCON_HAS_CFB24
1376 p->dispsw = accel ? fbcon_imstt24 : fbcon_cfb24;
1377 disp->dispsw_data = p->fbcon_cmap.cfb24;
1380 case 32: /* RGBA 8888 */
1381 disp->var.red.offset = 16;
1382 disp->var.red.length = 8;
1383 disp->var.green.offset = 8;
1384 disp->var.green.length = 8;
1385 disp->var.blue.offset = 0;
1386 disp->var.blue.length = 8;
1387 disp->var.transp.offset = 24;
1388 disp->var.transp.length = 8;
1389 #ifdef FBCON_HAS_CFB32
1390 p->dispsw = accel ? fbcon_imstt32 : fbcon_cfb32;
1391 disp->dispsw_data = p->fbcon_cmap.cfb32;
1396 if (accel && p->ramdac != IBM) {
1397 p->dispsw.cursor = 0;
1398 p->dispsw.set_font = 0;
1401 #ifdef CONFIG_FB_COMPAT_XPMAC
1402 set_display_info(disp);
1407 set_disp (struct display *disp, struct fb_info_imstt *p)
1409 u_int accel = disp->var.accel_flags & FB_ACCELF_TEXT;
1411 disp->fb_info = &p->info;
1413 set_dispsw(disp, p);
1415 disp->visual = disp->var.bits_per_pixel == 8 ? FB_VISUAL_PSEUDOCOLOR
1416 : FB_VISUAL_DIRECTCOLOR;
1417 disp->screen_base = (__u8 *)p->frame_buffer;
1418 disp->visual = p->fix.visual;
1419 disp->type = p->fix.type;
1420 disp->type_aux = p->fix.type_aux;
1421 disp->line_length = disp->var.xres * (disp->var.bits_per_pixel >> 3);
1422 disp->can_soft_blank = 1;
1423 disp->inverse = inverse;
1425 disp->ywrapstep = 0;
1427 disp->scrollmode = SCROLL_YNOMOVE;
1428 if (disp->var.yres == disp->var.yres_virtual) {
1429 __u32 vram = (p->total_vram - (PAGE_SIZE << 2));
1430 disp->var.yres_virtual = ((vram << 3) / disp->var.bits_per_pixel) / disp->var.xres_virtual;
1431 if (disp->var.yres_virtual < disp->var.yres)
1432 disp->var.yres_virtual = disp->var.yres;
1435 disp->scrollmode = SCROLL_YREDRAW;
1438 disp->var.activate = 0;
1439 disp->var.red.msb_right = 0;
1440 disp->var.green.msb_right = 0;
1441 disp->var.blue.msb_right = 0;
1442 disp->var.transp.msb_right = 0;
1443 disp->var.height = -1;
1444 disp->var.width = -1;
1445 disp->var.vmode = FB_VMODE_NONINTERLACED;
1446 disp->var.left_margin = disp->var.right_margin = 16;
1447 disp->var.upper_margin = disp->var.lower_margin = 16;
1448 disp->var.hsync_len = disp->var.vsync_len = 8;
1452 imsttfb_set_var (struct fb_var_screeninfo *var, int con, struct fb_info *info)
1454 struct fb_info_imstt *p = (struct fb_info_imstt *)info;
1455 struct display *disp;
1456 u_int oldbpp, oldxres, oldyres, oldgreenlen, oldaccel;
1458 disp = &fb_display[con];
1460 if ((var->bits_per_pixel != 8 && var->bits_per_pixel != 16
1461 && var->bits_per_pixel != 24 && var->bits_per_pixel != 32)
1462 || var->xres_virtual < var->xres || var->yres_virtual < var->yres
1464 || (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
1467 if ((var->xres * var->yres) * (var->bits_per_pixel >> 3) > p->total_vram
1468 || (var->xres_virtual * var->yres_virtual) * (var->bits_per_pixel >> 3) > p->total_vram)
1471 if (!((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW))
1474 if (!compute_imstt_regvals(p, var->xres, var->yres))
1477 oldbpp = disp->var.bits_per_pixel;
1478 oldxres = disp->var.xres;
1479 oldyres = disp->var.yres;
1480 oldgreenlen = disp->var.green.length;
1481 oldaccel = disp->var.accel_flags;
1483 disp->var.bits_per_pixel = var->bits_per_pixel;
1484 disp->var.xres = var->xres;
1485 disp->var.yres = var->yres;
1486 disp->var.xres_virtual = var->xres_virtual;
1487 disp->var.yres_virtual = var->yres_virtual;
1488 disp->var.green.length = var->green.length;
1489 disp->var.accel_flags = var->accel_flags;
1493 if (info->changevar)
1494 (*info->changevar)(con);
1496 if (con == currcon) {
1497 if (oldgreenlen != disp->var.green.length) {
1498 if (disp->var.green.length == 6)
1503 if (oldxres != disp->var.xres || oldyres != disp->var.yres || oldbpp != disp->var.bits_per_pixel)
1504 set_imstt_regvals(p, disp->var.bits_per_pixel);
1507 disp->var.pixclock = 1000000 / getclkMHz(p);
1509 if (oldbpp != disp->var.bits_per_pixel) {
1510 int err = fb_alloc_cmap(&disp->cmap, 0, 0);
1513 do_install_cmap(con, info);
1521 imsttfb_pan_display (struct fb_var_screeninfo *var, int con, struct fb_info *info)
1523 struct fb_info_imstt *p = (struct fb_info_imstt *)info;
1524 struct display *disp = &fb_display[con];
1526 if (var->xoffset + disp->var.xres > disp->var.xres_virtual
1527 || var->yoffset + disp->var.yres > disp->var.yres_virtual)
1530 disp->var.xoffset = var->xoffset;
1531 disp->var.yoffset = var->yoffset;
1533 set_offset(disp, p);
1539 imsttfb_get_cmap (struct fb_cmap *cmap, int kspc, int con, struct fb_info *info)
1541 if (con == currcon) /* current console? */
1542 return fb_get_cmap(cmap, kspc, imsttfb_getcolreg, info);
1543 else if (fb_display[con].cmap.len) /* non default colormap? */
1544 fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
1546 u_int size = fb_display[con].var.bits_per_pixel == 16 ? 32 : 256;
1547 fb_copy_cmap(fb_default_cmap(size), cmap, kspc ? 0 : 2);
1554 imsttfb_set_cmap (struct fb_cmap *cmap, int kspc, int con, struct fb_info *info)
1558 if (!fb_display[con].cmap.len) { /* no colormap allocated? */
1559 int size = fb_display[con].var.bits_per_pixel == 16 ? 32 : 256;
1560 if ((err = fb_alloc_cmap(&fb_display[con].cmap, size, 0)))
1563 if (con == currcon) /* current console? */
1564 return fb_set_cmap(cmap, kspc, imsttfb_setcolreg, info);
1566 fb_copy_cmap(cmap, &fb_display[con].cmap, kspc ? 0 : 1);
1571 #define FBIMSTT_SETREG 0x545401
1572 #define FBIMSTT_GETREG 0x545402
1573 #define FBIMSTT_SETCMAPREG 0x545403
1574 #define FBIMSTT_GETCMAPREG 0x545404
1575 #define FBIMSTT_SETIDXREG 0x545405
1576 #define FBIMSTT_GETIDXREG 0x545406
1579 imsttfb_ioctl (struct inode *inode, struct file *file, u_int cmd,
1580 u_long arg, int con, struct fb_info *info)
1582 struct fb_info_imstt *p = (struct fb_info_imstt *)info;
1587 case FBIMSTT_SETREG:
1588 if (copy_from_user(reg, (void *)arg, 8) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
1590 out_le32(&p->dc_regs[reg[0]], reg[1]);
1592 case FBIMSTT_GETREG:
1593 if (copy_from_user(reg, (void *)arg, 4) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
1595 reg[1] = in_le32(&p->dc_regs[reg[0]]);
1596 if (copy_to_user((void *)(arg + 4), ®[1], 4))
1599 case FBIMSTT_SETCMAPREG:
1600 if (copy_from_user(reg, (void *)arg, 8) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
1602 out_le32(&((u_int *)p->cmap_regs)[reg[0]], reg[1]);
1604 case FBIMSTT_GETCMAPREG:
1605 if (copy_from_user(reg, (void *)arg, 4) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
1607 reg[1] = in_le32(&((u_int *)p->cmap_regs)[reg[0]]);
1608 if (copy_to_user((void *)(arg + 4), ®[1], 4))
1611 case FBIMSTT_SETIDXREG:
1612 if (copy_from_user(idx, (void *)arg, 2))
1614 p->cmap_regs[PIDXHI] = 0; eieio();
1615 p->cmap_regs[PIDXLO] = idx[0]; eieio();
1616 p->cmap_regs[PIDXDATA] = idx[1]; eieio();
1618 case FBIMSTT_GETIDXREG:
1619 if (copy_from_user(idx, (void *)arg, 1))
1621 p->cmap_regs[PIDXHI] = 0; eieio();
1622 p->cmap_regs[PIDXLO] = idx[0]; eieio();
1623 idx[1] = p->cmap_regs[PIDXDATA];
1624 if (copy_to_user((void *)(arg + 1), &idx[1], 1))
1628 return -ENOIOCTLCMD;
1632 static struct pci_device_id imsttfb_pci_tbl[] __devinitdata = {
1633 { PCI_VENDOR_ID_IMS, PCI_DEVICE_ID_IMS_TT128,
1634 PCI_ANY_ID, PCI_ANY_ID, 0, 0, IBM },
1635 { PCI_VENDOR_ID_IMS, PCI_DEVICE_ID_IMS_TT3D,
1636 PCI_ANY_ID, PCI_ANY_ID, 0, 0, TVP },
1640 MODULE_DEVICE_TABLE(pci, imsttfb_pci_tbl);
1642 static struct pci_driver imsttfb_pci_driver = {
1644 id_table: imsttfb_pci_tbl,
1645 probe: imsttfb_probe,
1646 remove: __devexit_p(imsttfb_remove),
1649 static struct fb_ops imsttfb_ops = {
1651 fb_get_fix: imsttfb_get_fix,
1652 fb_get_var: imsttfb_get_var,
1653 fb_set_var: imsttfb_set_var,
1654 fb_get_cmap: imsttfb_get_cmap,
1655 fb_set_cmap: imsttfb_set_cmap,
1656 fb_pan_display: imsttfb_pan_display,
1657 fb_ioctl: imsttfb_ioctl,
1661 imsttfbcon_switch (int con, struct fb_info *info)
1663 struct fb_info_imstt *p = (struct fb_info_imstt *)info;
1664 struct display *old = &fb_display[currcon], *new = &fb_display[con];
1667 fb_get_cmap(&old->cmap, 1, imsttfb_getcolreg, info);
1669 if (old->conp && old->conp->vc_sw && old->conp->vc_sw->con_cursor)
1670 old->conp->vc_sw->con_cursor(old->conp, CM_ERASE);
1674 if (old->var.xres != new->var.xres
1675 || old->var.yres != new->var.yres
1676 || old->var.bits_per_pixel != new->var.bits_per_pixel
1677 || old->var.green.length != new->var.green.length
1678 || old->var.accel_flags != new->var.accel_flags) {
1680 if (!compute_imstt_regvals(p, new->var.xres, new->var.yres))
1682 if (new->var.bits_per_pixel == 16) {
1683 if (new->var.green.length == 6)
1688 set_imstt_regvals(p, new->var.bits_per_pixel);
1692 imsttfbcon_set_font(new, fontwidth(new), fontheight(new));
1694 do_install_cmap(con, info);
1700 imsttfbcon_updatevar (int con, struct fb_info *info)
1702 struct fb_info_imstt *p = (struct fb_info_imstt *)info;
1703 struct display *disp = &fb_display[con];
1708 if (p->ramdac == IBM)
1709 imsttfbcon_cursor(disp, CM_ERASE, p->cursor.x, p->cursor.y);
1711 set_offset(disp, p);
1718 imsttfbcon_blank (int blank, struct fb_info *info)
1720 struct fb_info_imstt *p = (struct fb_info_imstt *)info;
1723 ctrl = in_le32(&p->dc_regs[STGCTL]);
1725 switch (blank - 1) {
1726 case VESA_NO_BLANKING:
1727 case VESA_POWERDOWN:
1728 ctrl &= ~0x00000380;
1729 if (p->ramdac == IBM) {
1730 p->cmap_regs[PIDXHI] = 0; eieio();
1731 p->cmap_regs[PIDXLO] = MISCTL2; eieio();
1732 p->cmap_regs[PIDXDATA] = 0x55; eieio();
1733 p->cmap_regs[PIDXLO] = MISCTL1; eieio();
1734 p->cmap_regs[PIDXDATA] = 0x11; eieio();
1735 p->cmap_regs[PIDXLO] = SYNCCTL; eieio();
1736 p->cmap_regs[PIDXDATA] = 0x0f; eieio();
1737 p->cmap_regs[PIDXLO] = PWRMNGMT;eieio();
1738 p->cmap_regs[PIDXDATA] = 0x1f; eieio();
1739 p->cmap_regs[PIDXLO] = CLKCTL; eieio();
1740 p->cmap_regs[PIDXDATA] = 0xc0;
1743 case VESA_VSYNC_SUSPEND:
1744 ctrl &= ~0x00000020;
1746 case VESA_HSYNC_SUSPEND:
1747 ctrl &= ~0x00000010;
1751 if (p->ramdac == IBM) {
1753 p->cmap_regs[PIDXHI] = 0; eieio();
1754 p->cmap_regs[PIDXLO] = CLKCTL; eieio();
1755 p->cmap_regs[PIDXDATA] = 0x01; eieio();
1756 p->cmap_regs[PIDXLO] = PWRMNGMT;eieio();
1757 p->cmap_regs[PIDXDATA] = 0x00; eieio();
1758 p->cmap_regs[PIDXLO] = SYNCCTL; eieio();
1759 p->cmap_regs[PIDXDATA] = 0x00; eieio();
1760 p->cmap_regs[PIDXLO] = MISCTL1; eieio();
1761 p->cmap_regs[PIDXDATA] = 0x01; eieio();
1762 p->cmap_regs[PIDXLO] = MISCTL2; eieio();
1763 p->cmap_regs[PIDXDATA] = 0x45; eieio();
1767 out_le32(&p->dc_regs[STGCTL], ctrl);
1771 init_imstt(struct fb_info_imstt *p)
1776 tmp = in_le32(&p->dc_regs[PRC]);
1777 if (p->ramdac == IBM)
1778 p->total_vram = (tmp & 0x0004) ? 0x400000 : 0x200000;
1780 p->total_vram = 0x800000;
1782 ip = (__u32 *)p->frame_buffer;
1783 end = (__u32 *)(p->frame_buffer + p->total_vram);
1787 /* initialize the card */
1788 tmp = in_le32(&p->dc_regs[STGCTL]);
1789 out_le32(&p->dc_regs[STGCTL], tmp & ~0x1);
1790 out_le32(&p->dc_regs[SSR], 0);
1792 /* set default values for DAC registers */
1793 if (p->ramdac == IBM) {
1794 p->cmap_regs[PPMASK] = 0xff; eieio();
1795 p->cmap_regs[PIDXHI] = 0; eieio();
1796 for (i = 0; i < sizeof(ibm_initregs) / sizeof(*ibm_initregs); i++) {
1797 p->cmap_regs[PIDXLO] = ibm_initregs[i].addr; eieio();
1798 p->cmap_regs[PIDXDATA] = ibm_initregs[i].value; eieio();
1801 for (i = 0; i < sizeof(tvp_initregs) / sizeof(*tvp_initregs); i++) {
1802 p->cmap_regs[TVPADDRW] = tvp_initregs[i].addr; eieio();
1803 p->cmap_regs[TVPIDATA] = tvp_initregs[i].value; eieio();
1807 #ifdef CONFIG_ALL_PPC
1809 int vmode = init_vmode, cmode = init_cmode;
1812 /* Attempt to read vmode/cmode from NVRAM */
1813 if (vmode == VMODE_NVRAM)
1814 vmode = nvram_read_byte(NV_VMODE);
1815 if (cmode == CMODE_NVRAM)
1816 cmode = nvram_read_byte(NV_CMODE);
1818 /* If we didn't get something from NVRAM, pick a
1821 if (vmode <= 0 || vmode > VMODE_MAX)
1822 vmode = VMODE_640_480_67;
1823 if (cmode < CMODE_8 || cmode > CMODE_32)
1826 if (mac_vmode_to_var(vmode, cmode, &p->disp.var)) {
1827 p->disp.var.xres = p->disp.var.xres_virtual = INIT_XRES;
1828 p->disp.var.yres = p->disp.var.yres_virtual = INIT_YRES;
1829 p->disp.var.bits_per_pixel = INIT_BPP;
1833 p->disp.var.xres = p->disp.var.xres_virtual = INIT_XRES;
1834 p->disp.var.yres = p->disp.var.yres_virtual = INIT_YRES;
1835 p->disp.var.bits_per_pixel = INIT_BPP;
1838 if ((p->disp.var.xres * p->disp.var.yres) * (p->disp.var.bits_per_pixel >> 3) > p->total_vram
1839 || !(compute_imstt_regvals(p, p->disp.var.xres, p->disp.var.yres))) {
1840 printk("imsttfb: %ux%ux%u not supported\n", p->disp.var.xres, p->disp.var.yres, p->disp.var.bits_per_pixel);
1845 sprintf(p->fix.id, "IMS TT (%s)", p->ramdac == IBM ? "IBM" : "TVP");
1846 p->fix.smem_start = p->frame_buffer_phys;
1847 p->fix.smem_len = p->total_vram;
1848 p->fix.mmio_start = p->dc_regs_phys;
1849 p->fix.mmio_len = 0x1000;
1850 p->fix.accel = FB_ACCEL_IMS_TWINTURBO;
1851 p->fix.type = FB_TYPE_PACKED_PIXELS;
1852 p->fix.visual = p->disp.var.bits_per_pixel == 8 ? FB_VISUAL_PSEUDOCOLOR
1853 : FB_VISUAL_DIRECTCOLOR;
1854 p->fix.line_length = p->disp.var.xres * (p->disp.var.bits_per_pixel >> 3);
1855 p->fix.xpanstep = 8;
1856 p->fix.ypanstep = 1;
1857 p->fix.ywrapstep = 0;
1859 p->disp.var.accel_flags = noaccel ? 0 : FB_ACCELF_TEXT;
1860 set_disp(&p->disp, p);
1862 if (!noaccel && p->ramdac == IBM)
1863 imstt_cursor_init(p);
1864 if (p->disp.var.green.length == 6)
1868 set_imstt_regvals(p, p->disp.var.bits_per_pixel);
1870 p->disp.var.pixclock = 1000000 / getclkMHz(p);
1872 strcpy(p->info.modename, p->fix.id);
1873 strcpy(p->info.fontname, fontname);
1875 p->info.fbops = &imsttfb_ops;
1876 p->info.disp = &p->disp;
1877 p->info.changevar = 0;
1878 p->info.switch_con = &imsttfbcon_switch;
1879 p->info.updatevar = &imsttfbcon_updatevar;
1880 p->info.blank = &imsttfbcon_blank;
1881 p->info.flags = FBINFO_FLAG_DEFAULT;
1883 for (i = 0; i < 16; i++) {
1884 u_int j = color_table[i];
1885 p->palette[i].red = default_red[j];
1886 p->palette[i].green = default_grn[j];
1887 p->palette[i].blue = default_blu[j];
1890 if (register_framebuffer(&p->info) < 0) {
1895 i = GET_FB_IDX(p->info.node);
1896 tmp = (in_le32(&p->dc_regs[SSTATUS]) & 0x0f00) >> 8;
1897 printk("fb%u: %s frame buffer; %uMB vram; chip version %u\n",
1898 i, p->fix.id, p->total_vram >> 20, tmp);
1900 #ifdef CONFIG_FB_COMPAT_XPMAC
1901 strncpy(display_info.name, "IMS,tt128mb", sizeof(display_info.name));
1902 display_info.fb_address = p->frame_buffer_phys;
1903 display_info.cmap_adr_address = p->cmap_regs_phys + PADDRW;
1904 display_info.cmap_data_address = p->cmap_regs_phys + PDATA;
1905 display_info.disp_reg_address = p->dc_regs_phys;
1906 if (!console_fb_info)
1907 console_fb_info = &p->info;
1908 #endif /* CONFIG_FB_COMPAT_XPMAC */
1911 static int __devinit
1912 imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1914 struct fb_info_imstt *p;
1915 unsigned long addr, size;
1917 addr = pci_resource_start (pdev, 0);
1918 size = pci_resource_len (pdev, 0);
1920 p = kmalloc(sizeof(struct fb_info_imstt), GFP_KERNEL);
1923 printk(KERN_ERR "imsttfb: Can't allocate memory\n");
1927 memset(p, 0, sizeof(struct fb_info_imstt));
1929 if (!request_mem_region(addr, size, "imsttfb")) {
1930 printk(KERN_ERR "imsttfb: Can't reserve memory region\n");
1935 switch (pdev->device) {
1936 case PCI_DEVICE_ID_IMS_TT128: /* IMS,tt128mbA */
1939 case PCI_DEVICE_ID_IMS_TT3D: /* IMS,tt3d */
1943 printk(KERN_INFO "imsttfb: Device 0x%lx unknown, "
1944 "contact maintainer.\n", pdev->device);
1948 p->frame_buffer_phys = addr;
1949 p->board_size = size;
1950 p->frame_buffer = (__u8 *)ioremap(addr, p->ramdac == IBM ? 0x400000 : 0x800000);
1951 p->dc_regs_phys = addr + 0x800000;
1952 p->dc_regs = (__u32 *)ioremap(addr + 0x800000, 0x1000);
1953 p->cmap_regs_phys = addr + 0x840000;
1954 p->cmap_regs = (__u8 *)ioremap(addr + 0x840000, 0x1000);
1958 pci_set_drvdata(pdev, p);
1963 static void __devexit
1964 imsttfb_remove(struct pci_dev *pdev)
1966 struct fb_info_imstt *p = pci_get_drvdata(pdev);
1968 unregister_framebuffer(&p->info);
1969 iounmap(p->cmap_regs);
1970 iounmap(p->dc_regs);
1971 iounmap(p->frame_buffer);
1972 release_mem_region(p->frame_buffer_phys, p->board_size);
1978 imsttfb_setup(char *options)
1982 if (!options || !*options)
1985 while ((this_opt = strsep(&options, ",")) != NULL) {
1986 if (!strncmp(this_opt, "font:", 5)) {
1991 for (i = 0; i < sizeof(fontname) - 1; i++)
1992 if (!*p || *p == ' ' || *p == ',')
1994 memcpy(fontname, this_opt + 5, i);
1996 } else if (!strncmp(this_opt, "noblink", 7)) {
1998 } else if (!strncmp(this_opt, "noaccel", 7)) {
2000 } else if (!strncmp(this_opt, "inverse", 7)) {
2004 #if defined(CONFIG_PPC)
2005 else if (!strncmp(this_opt, "vmode:", 6)) {
2006 int vmode = simple_strtoul(this_opt+6, NULL, 0);
2007 if (vmode > 0 && vmode <= VMODE_MAX)
2009 } else if (!strncmp(this_opt, "cmode:", 6)) {
2010 int cmode = simple_strtoul(this_opt+6, NULL, 0);
2014 init_cmode = CMODE_8;
2019 init_cmode = CMODE_16;
2024 init_cmode = CMODE_32;
2035 int __init imsttfb_init(void)
2037 return pci_module_init(&imsttfb_pci_driver);
2040 static void __exit imsttfb_exit(void)
2042 pci_unregister_driver(&imsttfb_pci_driver);
2046 MODULE_LICENSE("GPL");
2047 module_init(imsttfb_init);
2049 module_exit(imsttfb_exit);