Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Frame buffer driver for Trident Blade and Image series |
| 3 | * |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 4 | * Copyright 2001, 2002 - Jani Monoses <jani@iv.ro> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * |
| 7 | * CREDITS:(in order of appearance) |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 8 | * skeletonfb.c by Geert Uytterhoeven and other fb code in drivers/video |
| 9 | * Special thanks ;) to Mattia Crivellini <tia@mclink.it> |
| 10 | * much inspired by the XFree86 4.x Trident driver sources |
| 11 | * by Alan Hourihane the FreeVGA project |
| 12 | * Francesco Salvestrini <salvestrini@users.sf.net> XP support, |
| 13 | * code, suggestions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * TODO: |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 15 | * timing value tweaking so it looks good on every monitor in every mode |
| 16 | * TGUI acceleration |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | #include <linux/fb.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/pci.h> |
| 23 | |
| 24 | #include <linux/delay.h> |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 25 | #include <video/vga.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <video/trident.h> |
| 27 | |
Krzysztof Helt | 122e8ad | 2008-07-23 21:30:52 -0700 | [diff] [blame] | 28 | #define VERSION "0.7.9-NEWAPI" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | struct tridentfb_par { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 31 | void __iomem *io_virt; /* iospace virtual memory address */ |
Krzysztof Helt | ea8ee55 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 32 | u32 pseudo_pal[16]; |
Krzysztof Helt | 122e8ad | 2008-07-23 21:30:52 -0700 | [diff] [blame] | 33 | int chip_id; |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 34 | int flatpanel; |
Krzysztof Helt | d9cad04 | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 35 | void (*init_accel) (struct tridentfb_par *, int, int); |
| 36 | void (*wait_engine) (struct tridentfb_par *); |
| 37 | void (*fill_rect) |
| 38 | (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32); |
| 39 | void (*copy_rect) |
| 40 | (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 43 | static unsigned char eng_oper; /* engine operation... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | static struct fb_ops tridentfb_ops; |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | static struct fb_fix_screeninfo tridentfb_fix = { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 47 | .id = "Trident", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | .type = FB_TYPE_PACKED_PIXELS, |
| 49 | .ypanstep = 1, |
| 50 | .visual = FB_VISUAL_PSEUDOCOLOR, |
| 51 | .accel = FB_ACCEL_NONE, |
| 52 | }; |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /* defaults which are normally overriden by user values */ |
| 55 | |
| 56 | /* video mode */ |
Krzysztof Helt | 07f41e4 | 2008-04-28 02:15:06 -0700 | [diff] [blame] | 57 | static char *mode_option __devinitdata = "640x480"; |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 58 | static int bpp __devinitdata = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 60 | static int noaccel __devinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | static int center; |
| 63 | static int stretch; |
| 64 | |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 65 | static int fp __devinitdata; |
| 66 | static int crt __devinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 68 | static int memsize __devinitdata; |
| 69 | static int memdiff __devinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static int nativex; |
| 71 | |
Krzysztof Helt | 07f41e4 | 2008-04-28 02:15:06 -0700 | [diff] [blame] | 72 | module_param(mode_option, charp, 0); |
| 73 | MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'"); |
Krzysztof Helt | 9e3f0ca | 2008-04-28 02:15:10 -0700 | [diff] [blame] | 74 | module_param_named(mode, mode_option, charp, 0); |
| 75 | MODULE_PARM_DESC(mode, "Initial video mode e.g. '648x480-8@60' (deprecated)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | module_param(bpp, int, 0); |
| 77 | module_param(center, int, 0); |
| 78 | module_param(stretch, int, 0); |
| 79 | module_param(noaccel, int, 0); |
| 80 | module_param(memsize, int, 0); |
| 81 | module_param(memdiff, int, 0); |
| 82 | module_param(nativex, int, 0); |
| 83 | module_param(fp, int, 0); |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 84 | MODULE_PARM_DESC(fp, "Define if flatpanel is connected"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | module_param(crt, int, 0); |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 86 | MODULE_PARM_DESC(crt, "Define if CRT is connected"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Krzysztof Helt | 6bdf103 | 2008-07-23 21:30:56 -0700 | [diff] [blame] | 88 | static int is_oldclock(int id) |
| 89 | { |
Krzysztof Helt | a0d9225 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 90 | return (id == TGUI9440) || |
| 91 | (id == TGUI9660) || |
Krzysztof Helt | 0e73a47 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 92 | (id == CYBER9320); |
| 93 | } |
| 94 | |
| 95 | static int is_oldprotect(int id) |
| 96 | { |
Krzysztof Helt | a0d9225 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 97 | return (id == TGUI9440) || |
| 98 | (id == TGUI9660) || |
Krzysztof Helt | 0e73a47 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 99 | (id == PROVIDIA9685) || |
| 100 | (id == CYBER9320) || |
| 101 | (id == CYBER9382) || |
| 102 | (id == CYBER9385); |
Krzysztof Helt | 6bdf103 | 2008-07-23 21:30:56 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Krzysztof Helt | e0759a5 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 105 | static int is_blade(int id) |
| 106 | { |
| 107 | return (id == BLADE3D) || |
| 108 | (id == CYBERBLADEE4) || |
| 109 | (id == CYBERBLADEi7) || |
| 110 | (id == CYBERBLADEi7D) || |
| 111 | (id == CYBERBLADEi1) || |
| 112 | (id == CYBERBLADEi1D) || |
| 113 | (id == CYBERBLADEAi1) || |
| 114 | (id == CYBERBLADEAi1D); |
| 115 | } |
| 116 | |
| 117 | static int is_xp(int id) |
| 118 | { |
| 119 | return (id == CYBERBLADEXPAi1) || |
| 120 | (id == CYBERBLADEXPm8) || |
| 121 | (id == CYBERBLADEXPm16); |
| 122 | } |
| 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | static int is3Dchip(int id) |
| 125 | { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 126 | return ((id == BLADE3D) || (id == CYBERBLADEE4) || |
| 127 | (id == CYBERBLADEi7) || (id == CYBERBLADEi7D) || |
| 128 | (id == CYBER9397) || (id == CYBER9397DVD) || |
| 129 | (id == CYBER9520) || (id == CYBER9525DVD) || |
| 130 | (id == IMAGE975) || (id == IMAGE985) || |
| 131 | (id == CYBERBLADEi1) || (id == CYBERBLADEi1D) || |
| 132 | (id == CYBERBLADEAi1) || (id == CYBERBLADEAi1D) || |
| 133 | (id == CYBERBLADEXPm8) || (id == CYBERBLADEXPm16) || |
| 134 | (id == CYBERBLADEXPAi1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static int iscyber(int id) |
| 138 | { |
| 139 | switch (id) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 140 | case CYBER9388: |
| 141 | case CYBER9382: |
| 142 | case CYBER9385: |
| 143 | case CYBER9397: |
| 144 | case CYBER9397DVD: |
| 145 | case CYBER9520: |
| 146 | case CYBER9525DVD: |
| 147 | case CYBERBLADEE4: |
| 148 | case CYBERBLADEi7D: |
| 149 | case CYBERBLADEi1: |
| 150 | case CYBERBLADEi1D: |
| 151 | case CYBERBLADEAi1: |
| 152 | case CYBERBLADEAi1D: |
| 153 | case CYBERBLADEXPAi1: |
| 154 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 156 | case CYBER9320: |
| 157 | case TGUI9660: |
Krzysztof Helt | 0e73a47 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 158 | case PROVIDIA9685: |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 159 | case IMAGE975: |
| 160 | case IMAGE985: |
| 161 | case BLADE3D: |
| 162 | case CYBERBLADEi7: /* VIA MPV4 integrated version */ |
| 163 | |
| 164 | default: |
| 165 | /* case CYBERBLDAEXPm8: Strange */ |
| 166 | /* case CYBERBLDAEXPm16: Strange */ |
| 167 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 171 | static inline void t_outb(struct tridentfb_par *p, u8 val, u16 reg) |
| 172 | { |
| 173 | fb_writeb(val, p->io_virt + reg); |
| 174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 176 | static inline u8 t_inb(struct tridentfb_par *p, u16 reg) |
| 177 | { |
| 178 | return fb_readb(p->io_virt + reg); |
| 179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 181 | static inline void writemmr(struct tridentfb_par *par, u16 r, u32 v) |
| 182 | { |
| 183 | fb_writel(v, par->io_virt + r); |
| 184 | } |
| 185 | |
| 186 | static inline u32 readmmr(struct tridentfb_par *par, u16 r) |
| 187 | { |
| 188 | return fb_readl(par->io_virt + r); |
| 189 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | /* |
| 192 | * Blade specific acceleration. |
| 193 | */ |
| 194 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 195 | #define point(x, y) ((y) << 16 | (x)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | #define STA 0x2120 |
| 197 | #define CMD 0x2144 |
| 198 | #define ROP 0x2148 |
| 199 | #define CLR 0x2160 |
| 200 | #define SR1 0x2100 |
| 201 | #define SR2 0x2104 |
| 202 | #define DR1 0x2108 |
| 203 | #define DR2 0x210C |
| 204 | |
| 205 | #define ROP_S 0xCC |
| 206 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 207 | static void blade_init_accel(struct tridentfb_par *par, int pitch, int bpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 209 | int v1 = (pitch >> 3) << 20; |
| 210 | int tmp = 0, v2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | switch (bpp) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 212 | case 8: |
| 213 | tmp = 0; |
| 214 | break; |
| 215 | case 15: |
| 216 | tmp = 5; |
| 217 | break; |
| 218 | case 16: |
| 219 | tmp = 1; |
| 220 | break; |
| 221 | case 24: |
| 222 | case 32: |
| 223 | tmp = 2; |
| 224 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 226 | v2 = v1 | (tmp << 29); |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 227 | writemmr(par, 0x21C0, v2); |
| 228 | writemmr(par, 0x21C4, v2); |
| 229 | writemmr(par, 0x21B8, v2); |
| 230 | writemmr(par, 0x21BC, v2); |
| 231 | writemmr(par, 0x21D0, v1); |
| 232 | writemmr(par, 0x21D4, v1); |
| 233 | writemmr(par, 0x21C8, v1); |
| 234 | writemmr(par, 0x21CC, v1); |
| 235 | writemmr(par, 0x216C, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 238 | static void blade_wait_engine(struct tridentfb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 240 | while (readmmr(par, STA) & 0xFA800000) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 243 | static void blade_fill_rect(struct tridentfb_par *par, |
| 244 | u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 246 | writemmr(par, CLR, c); |
| 247 | writemmr(par, ROP, rop ? 0x66 : ROP_S); |
| 248 | writemmr(par, CMD, 0x20000000 | 1 << 19 | 1 << 4 | 2 << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 250 | writemmr(par, DR1, point(x, y)); |
| 251 | writemmr(par, DR2, point(x + w - 1, y + h - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 254 | static void blade_copy_rect(struct tridentfb_par *par, |
| 255 | u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 257 | u32 s1, s2, d1, d2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | int direction = 2; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 259 | s1 = point(x1, y1); |
| 260 | s2 = point(x1 + w - 1, y1 + h - 1); |
| 261 | d1 = point(x2, y2); |
| 262 | d2 = point(x2 + w - 1, y2 + h - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | if ((y1 > y2) || ((y1 == y2) && (x1 > x2))) |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 265 | direction = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 267 | writemmr(par, ROP, ROP_S); |
| 268 | writemmr(par, CMD, 0xE0000000 | 1 << 19 | 1 << 4 | 1 << 2 | direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 270 | writemmr(par, SR1, direction ? s2 : s1); |
| 271 | writemmr(par, SR2, direction ? s1 : s2); |
| 272 | writemmr(par, DR1, direction ? d2 : d1); |
| 273 | writemmr(par, DR2, direction ? d1 : d2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* |
| 277 | * BladeXP specific acceleration functions |
| 278 | */ |
| 279 | |
| 280 | #define ROP_P 0xF0 |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 281 | #define masked_point(x, y) ((y & 0xffff)<<16|(x & 0xffff)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 283 | static void xp_init_accel(struct tridentfb_par *par, int pitch, int bpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 285 | int tmp = 0, v1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | unsigned char x = 0; |
| 287 | |
| 288 | switch (bpp) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 289 | case 8: |
| 290 | x = 0; |
| 291 | break; |
| 292 | case 16: |
| 293 | x = 1; |
| 294 | break; |
| 295 | case 24: |
| 296 | x = 3; |
| 297 | break; |
| 298 | case 32: |
| 299 | x = 2; |
| 300 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | switch (pitch << (bpp >> 3)) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 304 | case 8192: |
| 305 | case 512: |
| 306 | x |= 0x00; |
| 307 | break; |
| 308 | case 1024: |
| 309 | x |= 0x04; |
| 310 | break; |
| 311 | case 2048: |
| 312 | x |= 0x08; |
| 313 | break; |
| 314 | case 4096: |
| 315 | x |= 0x0C; |
| 316 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 319 | t_outb(par, x, 0x2125); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
| 321 | eng_oper = x | 0x40; |
| 322 | |
| 323 | switch (bpp) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 324 | case 8: |
| 325 | tmp = 18; |
| 326 | break; |
| 327 | case 15: |
| 328 | case 16: |
| 329 | tmp = 19; |
| 330 | break; |
| 331 | case 24: |
| 332 | case 32: |
| 333 | tmp = 20; |
| 334 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | v1 = pitch << tmp; |
| 338 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 339 | writemmr(par, 0x2154, v1); |
| 340 | writemmr(par, 0x2150, v1); |
| 341 | t_outb(par, 3, 0x2126); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 344 | static void xp_wait_engine(struct tridentfb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
| 346 | int busy; |
| 347 | int count, timeout; |
| 348 | |
| 349 | count = 0; |
| 350 | timeout = 0; |
| 351 | for (;;) { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 352 | busy = t_inb(par, STA) & 0x80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (busy != 0x80) |
| 354 | return; |
| 355 | count++; |
| 356 | if (count == 10000000) { |
| 357 | /* Timeout */ |
| 358 | count = 9990000; |
| 359 | timeout++; |
| 360 | if (timeout == 8) { |
| 361 | /* Reset engine */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 362 | t_outb(par, 0x00, 0x2120); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | return; |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 369 | static void xp_fill_rect(struct tridentfb_par *par, |
| 370 | u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 372 | writemmr(par, 0x2127, ROP_P); |
| 373 | writemmr(par, 0x2158, c); |
| 374 | writemmr(par, 0x2128, 0x4000); |
| 375 | writemmr(par, 0x2140, masked_point(h, w)); |
| 376 | writemmr(par, 0x2138, masked_point(y, x)); |
| 377 | t_outb(par, 0x01, 0x2124); |
| 378 | t_outb(par, eng_oper, 0x2125); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 381 | static void xp_copy_rect(struct tridentfb_par *par, |
| 382 | u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
| 384 | int direction; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 385 | u32 x1_tmp, x2_tmp, y1_tmp, y2_tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
| 387 | direction = 0x0004; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | if ((x1 < x2) && (y1 == y2)) { |
| 390 | direction |= 0x0200; |
| 391 | x1_tmp = x1 + w - 1; |
| 392 | x2_tmp = x2 + w - 1; |
| 393 | } else { |
| 394 | x1_tmp = x1; |
| 395 | x2_tmp = x2; |
| 396 | } |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | if (y1 < y2) { |
| 399 | direction |= 0x0100; |
| 400 | y1_tmp = y1 + h - 1; |
| 401 | y2_tmp = y2 + h - 1; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 402 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | y1_tmp = y1; |
| 404 | y2_tmp = y2; |
| 405 | } |
| 406 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 407 | writemmr(par, 0x2128, direction); |
| 408 | t_outb(par, ROP_S, 0x2127); |
| 409 | writemmr(par, 0x213C, masked_point(y1_tmp, x1_tmp)); |
| 410 | writemmr(par, 0x2138, masked_point(y2_tmp, x2_tmp)); |
| 411 | writemmr(par, 0x2140, masked_point(h, w)); |
| 412 | t_outb(par, 0x01, 0x2124); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | /* |
| 416 | * Image specific acceleration functions |
| 417 | */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 418 | static void image_init_accel(struct tridentfb_par *par, int pitch, int bpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
| 420 | int tmp = 0; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 421 | switch (bpp) { |
| 422 | case 8: |
| 423 | tmp = 0; |
| 424 | break; |
| 425 | case 15: |
| 426 | tmp = 5; |
| 427 | break; |
| 428 | case 16: |
| 429 | tmp = 1; |
| 430 | break; |
| 431 | case 24: |
| 432 | case 32: |
| 433 | tmp = 2; |
| 434 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 436 | writemmr(par, 0x2120, 0xF0000000); |
| 437 | writemmr(par, 0x2120, 0x40000000 | tmp); |
| 438 | writemmr(par, 0x2120, 0x80000000); |
| 439 | writemmr(par, 0x2144, 0x00000000); |
| 440 | writemmr(par, 0x2148, 0x00000000); |
| 441 | writemmr(par, 0x2150, 0x00000000); |
| 442 | writemmr(par, 0x2154, 0x00000000); |
| 443 | writemmr(par, 0x2120, 0x60000000 | (pitch << 16) | pitch); |
| 444 | writemmr(par, 0x216C, 0x00000000); |
| 445 | writemmr(par, 0x2170, 0x00000000); |
| 446 | writemmr(par, 0x217C, 0x00000000); |
| 447 | writemmr(par, 0x2120, 0x10000000); |
| 448 | writemmr(par, 0x2130, (2047 << 16) | 2047); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 451 | static void image_wait_engine(struct tridentfb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 453 | while (readmmr(par, 0x2164) & 0xF0000000) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 456 | static void image_fill_rect(struct tridentfb_par *par, |
| 457 | u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 459 | writemmr(par, 0x2120, 0x80000000); |
| 460 | writemmr(par, 0x2120, 0x90000000 | ROP_S); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 462 | writemmr(par, 0x2144, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 464 | writemmr(par, DR1, point(x, y)); |
| 465 | writemmr(par, DR2, point(x + w - 1, y + h - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 467 | writemmr(par, 0x2124, 0x80000000 | 3 << 22 | 1 << 10 | 1 << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 470 | static void image_copy_rect(struct tridentfb_par *par, |
| 471 | u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 473 | u32 s1, s2, d1, d2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | int direction = 2; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 475 | s1 = point(x1, y1); |
| 476 | s2 = point(x1 + w - 1, y1 + h - 1); |
| 477 | d1 = point(x2, y2); |
| 478 | d2 = point(x2 + w - 1, y2 + h - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 480 | if ((y1 > y2) || ((y1 == y2) && (x1 > x2))) |
| 481 | direction = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 483 | writemmr(par, 0x2120, 0x80000000); |
| 484 | writemmr(par, 0x2120, 0x90000000 | ROP_S); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 486 | writemmr(par, SR1, direction ? s2 : s1); |
| 487 | writemmr(par, SR2, direction ? s1 : s2); |
| 488 | writemmr(par, DR1, direction ? d2 : d1); |
| 489 | writemmr(par, DR2, direction ? d1 : d2); |
| 490 | writemmr(par, 0x2124, |
| 491 | 0x80000000 | 1 << 22 | 1 << 10 | 1 << 7 | direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | /* |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 495 | * TGUI 9440/96XX acceleration |
| 496 | */ |
| 497 | |
| 498 | static void tgui_init_accel(struct tridentfb_par *par, int pitch, int bpp) |
| 499 | { |
| 500 | unsigned char x = 0; |
| 501 | |
| 502 | /* disable clipping */ |
| 503 | writemmr(par, 0x2148, 0); |
| 504 | writemmr(par, 0x214C, point(4095, 2047)); |
| 505 | |
| 506 | switch (bpp) { |
| 507 | case 8: |
| 508 | x = 0; |
| 509 | break; |
| 510 | case 16: |
| 511 | x = 1; |
| 512 | break; |
| 513 | case 24: |
| 514 | x = 3; |
| 515 | break; |
| 516 | case 32: |
| 517 | x = 2; |
| 518 | break; |
| 519 | } |
| 520 | |
| 521 | switch ((pitch * bpp) / 8) { |
| 522 | case 8192: |
| 523 | case 512: |
| 524 | x |= 0x00; |
| 525 | break; |
| 526 | case 1024: |
| 527 | x |= 0x04; |
| 528 | break; |
| 529 | case 2048: |
| 530 | x |= 0x08; |
| 531 | break; |
| 532 | case 4096: |
| 533 | x |= 0x0C; |
| 534 | break; |
| 535 | } |
| 536 | |
| 537 | fb_writew(x, par->io_virt + 0x2122); |
| 538 | } |
| 539 | |
| 540 | static void tgui_fill_rect(struct tridentfb_par *par, |
| 541 | u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop) |
| 542 | { |
| 543 | t_outb(par, ROP_P, 0x2127); |
| 544 | writemmr(par, 0x212c, c); |
| 545 | writemmr(par, 0x2128, 0x4020); |
| 546 | writemmr(par, 0x2140, point(w - 1, h - 1)); |
| 547 | writemmr(par, 0x2138, point(x, y)); |
| 548 | t_outb(par, 1, 0x2124); |
| 549 | } |
| 550 | |
| 551 | static void tgui_copy_rect(struct tridentfb_par *par, |
| 552 | u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h) |
| 553 | { |
| 554 | int flags = 0; |
| 555 | u16 x1_tmp, x2_tmp, y1_tmp, y2_tmp; |
| 556 | |
| 557 | if ((x1 < x2) && (y1 == y2)) { |
| 558 | flags |= 0x0200; |
| 559 | x1_tmp = x1 + w - 1; |
| 560 | x2_tmp = x2 + w - 1; |
| 561 | } else { |
| 562 | x1_tmp = x1; |
| 563 | x2_tmp = x2; |
| 564 | } |
| 565 | |
| 566 | if (y1 < y2) { |
| 567 | flags |= 0x0100; |
| 568 | y1_tmp = y1 + h - 1; |
| 569 | y2_tmp = y2 + h - 1; |
| 570 | } else { |
| 571 | y1_tmp = y1; |
| 572 | y2_tmp = y2; |
| 573 | } |
| 574 | |
| 575 | writemmr(par, 0x2128, 0x4 | flags); |
| 576 | t_outb(par, ROP_S, 0x2127); |
| 577 | writemmr(par, 0x213C, point(x1_tmp, y1_tmp)); |
| 578 | writemmr(par, 0x2138, point(x2_tmp, y2_tmp)); |
| 579 | writemmr(par, 0x2140, point(w - 1, h - 1)); |
| 580 | t_outb(par, 1, 0x2124); |
| 581 | } |
| 582 | |
| 583 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | * Accel functions called by the upper layers |
| 585 | */ |
| 586 | #ifdef CONFIG_FB_TRIDENT_ACCEL |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 587 | static void tridentfb_fillrect(struct fb_info *info, |
| 588 | const struct fb_fillrect *fr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 590 | struct tridentfb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | int bpp = info->var.bits_per_pixel; |
Antonino A. Daplas | 8dad46c | 2005-08-01 23:46:44 +0800 | [diff] [blame] | 592 | int col = 0; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | switch (bpp) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 595 | default: |
| 596 | case 8: |
| 597 | col |= fr->color; |
| 598 | col |= col << 8; |
| 599 | col |= col << 16; |
| 600 | break; |
| 601 | case 16: |
| 602 | col = ((u32 *)(info->pseudo_palette))[fr->color]; |
| 603 | break; |
| 604 | case 32: |
| 605 | col = ((u32 *)(info->pseudo_palette))[fr->color]; |
| 606 | break; |
| 607 | } |
| 608 | |
Krzysztof Helt | d9cad04 | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 609 | par->fill_rect(par, fr->dx, fr->dy, fr->width, |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 610 | fr->height, col, fr->rop); |
Krzysztof Helt | d9cad04 | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 611 | par->wait_engine(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 613 | static void tridentfb_copyarea(struct fb_info *info, |
| 614 | const struct fb_copyarea *ca) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 616 | struct tridentfb_par *par = info->par; |
| 617 | |
Krzysztof Helt | d9cad04 | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 618 | par->copy_rect(par, ca->sx, ca->sy, ca->dx, ca->dy, |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 619 | ca->width, ca->height); |
Krzysztof Helt | d9cad04 | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 620 | par->wait_engine(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | #endif /* CONFIG_FB_TRIDENT_ACCEL */ |
| 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | /* |
| 625 | * Hardware access functions |
| 626 | */ |
| 627 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 628 | static inline unsigned char read3X4(struct tridentfb_par *par, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 630 | return vga_mm_rcrt(par->io_virt, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 633 | static inline void write3X4(struct tridentfb_par *par, int reg, |
| 634 | unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 636 | vga_mm_wcrt(par->io_virt, reg, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 639 | static inline unsigned char read3CE(struct tridentfb_par *par, |
| 640 | unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 642 | return vga_mm_rgfx(par->io_virt, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 645 | static inline void writeAttr(struct tridentfb_par *par, int reg, |
| 646 | unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 648 | fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */ |
| 649 | vga_mm_wattr(par->io_virt, reg, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 652 | static inline void write3CE(struct tridentfb_par *par, int reg, |
| 653 | unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 655 | vga_mm_wgfx(par->io_virt, reg, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 658 | static void enable_mmio(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | { |
| 660 | /* Goto New Mode */ |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 661 | vga_io_rseq(0x0B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
| 663 | /* Unprotect registers */ |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 664 | vga_io_wseq(NewMode1, 0x80); |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | /* Enable MMIO */ |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 667 | outb(PCIReg, 0x3D4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | outb(inb(0x3D5) | 0x01, 0x3D5); |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 669 | } |
| 670 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 671 | static void disable_mmio(struct tridentfb_par *par) |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 672 | { |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 673 | /* Goto New Mode */ |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 674 | vga_mm_rseq(par->io_virt, 0x0B); |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 675 | |
| 676 | /* Unprotect registers */ |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 677 | vga_mm_wseq(par->io_virt, NewMode1, 0x80); |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 678 | |
| 679 | /* Disable MMIO */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 680 | t_outb(par, PCIReg, 0x3D4); |
| 681 | t_outb(par, t_inb(par, 0x3D5) & ~0x01, 0x3D5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 684 | static void crtc_unlock(struct tridentfb_par *par) |
| 685 | { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 686 | write3X4(par, VGA_CRTC_V_SYNC_END, |
| 687 | read3X4(par, VGA_CRTC_V_SYNC_END) & 0x7F); |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 688 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | /* Return flat panel's maximum x resolution */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 691 | static int __devinit get_nativex(struct tridentfb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 693 | int x, y, tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | if (nativex) |
| 696 | return nativex; |
| 697 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 698 | tmp = (read3CE(par, VertStretch) >> 4) & 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
| 700 | switch (tmp) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 701 | case 0: |
| 702 | x = 1280; y = 1024; |
| 703 | break; |
| 704 | case 2: |
| 705 | x = 1024; y = 768; |
| 706 | break; |
| 707 | case 3: |
| 708 | x = 800; y = 600; |
| 709 | break; |
| 710 | case 4: |
| 711 | x = 1400; y = 1050; |
| 712 | break; |
| 713 | case 1: |
| 714 | default: |
| 715 | x = 640; y = 480; |
| 716 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | output("%dx%d flat panel found\n", x, y); |
| 720 | return x; |
| 721 | } |
| 722 | |
| 723 | /* Set pitch */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 724 | static void set_lwidth(struct tridentfb_par *par, int width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 726 | write3X4(par, VGA_CRTC_OFFSET, width & 0xFF); |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 727 | write3X4(par, AddColReg, |
| 728 | (read3X4(par, AddColReg) & 0xCF) | ((width & 0x300) >> 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | /* For resolutions smaller than FP resolution stretch */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 732 | static void screen_stretch(struct tridentfb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | { |
Krzysztof Helt | 122e8ad | 2008-07-23 21:30:52 -0700 | [diff] [blame] | 734 | if (par->chip_id != CYBERBLADEXPAi1) |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 735 | write3CE(par, BiosReg, 0); |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 736 | else |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 737 | write3CE(par, BiosReg, 8); |
| 738 | write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 1); |
| 739 | write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | /* For resolutions smaller than FP resolution center */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 743 | static void screen_center(struct tridentfb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 745 | write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 0x80); |
| 746 | write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /* Address of first shown pixel in display memory */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 750 | static void set_screen_start(struct tridentfb_par *par, int base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 752 | u8 tmp; |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 753 | write3X4(par, VGA_CRTC_START_LO, base & 0xFF); |
| 754 | write3X4(par, VGA_CRTC_START_HI, (base & 0xFF00) >> 8); |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 755 | tmp = read3X4(par, CRTCModuleTest) & 0xDF; |
| 756 | write3X4(par, CRTCModuleTest, tmp | ((base & 0x10000) >> 11)); |
| 757 | tmp = read3X4(par, CRTHiOrd) & 0xF8; |
| 758 | write3X4(par, CRTHiOrd, tmp | ((base & 0xE0000) >> 17)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | /* Set dotclock frequency */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 762 | static void set_vclk(struct tridentfb_par *par, unsigned long freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 764 | int m, n, k; |
Krzysztof Helt | 6bdf103 | 2008-07-23 21:30:56 -0700 | [diff] [blame] | 765 | unsigned long fi, d, di; |
| 766 | unsigned char best_m = 0, best_n = 0, best_k = 0; |
| 767 | unsigned char hi, lo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
Krzysztof Helt | 3f275ea | 2008-05-12 14:02:11 -0700 | [diff] [blame] | 769 | d = 20000; |
Krzysztof Helt | 6bdf103 | 2008-07-23 21:30:56 -0700 | [diff] [blame] | 770 | for (k = 1; k >= 0; k--) |
| 771 | for (m = 0; m < 32; m++) |
| 772 | for (n = 0; n < 122; n++) { |
Krzysztof Helt | 3f275ea | 2008-05-12 14:02:11 -0700 | [diff] [blame] | 773 | fi = ((14318l * (n + 8)) / (m + 2)) >> k; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 774 | if ((di = abs(fi - freq)) < d) { |
| 775 | d = di; |
Krzysztof Helt | 6bdf103 | 2008-07-23 21:30:56 -0700 | [diff] [blame] | 776 | best_n = n; |
| 777 | best_m = m; |
| 778 | best_k = k; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 779 | } |
Krzysztof Helt | 3f275ea | 2008-05-12 14:02:11 -0700 | [diff] [blame] | 780 | if (fi > freq) |
| 781 | break; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 782 | } |
Krzysztof Helt | 6bdf103 | 2008-07-23 21:30:56 -0700 | [diff] [blame] | 783 | |
| 784 | if (is_oldclock(par->chip_id)) { |
| 785 | lo = best_n | (best_m << 7); |
| 786 | hi = (best_m >> 1) | (best_k << 4); |
| 787 | } else { |
| 788 | lo = best_n; |
| 789 | hi = best_m | (best_k << 6); |
| 790 | } |
| 791 | |
Krzysztof Helt | 122e8ad | 2008-07-23 21:30:52 -0700 | [diff] [blame] | 792 | if (is3Dchip(par->chip_id)) { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 793 | vga_mm_wseq(par->io_virt, ClockHigh, hi); |
| 794 | vga_mm_wseq(par->io_virt, ClockLow, lo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | } else { |
Krzysztof Helt | c1724fe | 2008-07-23 21:30:56 -0700 | [diff] [blame] | 796 | t_outb(par, lo, 0x43C8); |
| 797 | t_outb(par, hi, 0x43C9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 799 | debug("VCLK = %X %X\n", hi, lo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | /* Set number of lines for flat panels*/ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 803 | static void set_number_of_lines(struct tridentfb_par *par, int lines) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 805 | int tmp = read3CE(par, CyberEnhance) & 0x8F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | if (lines > 1024) |
| 807 | tmp |= 0x50; |
| 808 | else if (lines > 768) |
| 809 | tmp |= 0x30; |
| 810 | else if (lines > 600) |
| 811 | tmp |= 0x20; |
| 812 | else if (lines > 480) |
| 813 | tmp |= 0x10; |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 814 | write3CE(par, CyberEnhance, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /* |
| 818 | * If we see that FP is active we assume we have one. |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 819 | * Otherwise we have a CRT display. User can override. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | */ |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 821 | static int __devinit is_flatpanel(struct tridentfb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
| 823 | if (fp) |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 824 | return 1; |
Krzysztof Helt | 122e8ad | 2008-07-23 21:30:52 -0700 | [diff] [blame] | 825 | if (crt || !iscyber(par->chip_id)) |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 826 | return 0; |
| 827 | return (read3CE(par, FPConfig) & 0x10) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | /* Try detecting the video memory size */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 831 | static unsigned int __devinit get_memsize(struct tridentfb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | { |
| 833 | unsigned char tmp, tmp2; |
| 834 | unsigned int k; |
| 835 | |
| 836 | /* If memory size provided by user */ |
| 837 | if (memsize) |
| 838 | k = memsize * Kb; |
| 839 | else |
Krzysztof Helt | 122e8ad | 2008-07-23 21:30:52 -0700 | [diff] [blame] | 840 | switch (par->chip_id) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 841 | case CYBER9525DVD: |
| 842 | k = 2560 * Kb; |
| 843 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | default: |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 845 | tmp = read3X4(par, SPR) & 0x0F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | switch (tmp) { |
| 847 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 848 | case 0x01: |
Krzysztof Helt | b614ce8 | 2008-03-10 11:43:37 -0700 | [diff] [blame] | 849 | k = 512 * Kb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | break; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 851 | case 0x02: |
| 852 | k = 6 * Mb; /* XP */ |
| 853 | break; |
| 854 | case 0x03: |
| 855 | k = 1 * Mb; |
| 856 | break; |
| 857 | case 0x04: |
| 858 | k = 8 * Mb; |
| 859 | break; |
| 860 | case 0x06: |
| 861 | k = 10 * Mb; /* XP */ |
| 862 | break; |
| 863 | case 0x07: |
| 864 | k = 2 * Mb; |
| 865 | break; |
| 866 | case 0x08: |
| 867 | k = 12 * Mb; /* XP */ |
| 868 | break; |
| 869 | case 0x0A: |
| 870 | k = 14 * Mb; /* XP */ |
| 871 | break; |
| 872 | case 0x0C: |
| 873 | k = 16 * Mb; /* XP */ |
| 874 | break; |
| 875 | case 0x0E: /* XP */ |
| 876 | |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 877 | tmp2 = vga_mm_rseq(par->io_virt, 0xC1); |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 878 | switch (tmp2) { |
| 879 | case 0x00: |
| 880 | k = 20 * Mb; |
| 881 | break; |
| 882 | case 0x01: |
| 883 | k = 24 * Mb; |
| 884 | break; |
| 885 | case 0x10: |
| 886 | k = 28 * Mb; |
| 887 | break; |
| 888 | case 0x11: |
| 889 | k = 32 * Mb; |
| 890 | break; |
| 891 | default: |
| 892 | k = 1 * Mb; |
| 893 | break; |
| 894 | } |
| 895 | break; |
| 896 | |
| 897 | case 0x0F: |
| 898 | k = 4 * Mb; |
| 899 | break; |
| 900 | default: |
| 901 | k = 1 * Mb; |
| 902 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 904 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
| 906 | k -= memdiff * Kb; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 907 | output("framebuffer size = %d Kb\n", k / Kb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | return k; |
| 909 | } |
| 910 | |
| 911 | /* See if we can handle the video mode described in var */ |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 912 | static int tridentfb_check_var(struct fb_var_screeninfo *var, |
| 913 | struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | { |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 915 | struct tridentfb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | int bpp = var->bits_per_pixel; |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 917 | int line_length; |
Krzysztof Helt | 74a933f | 2008-07-23 21:31:00 -0700 | [diff] [blame] | 918 | int ramdac = 230000; /* 230MHz for most 3D chips */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | debug("enter\n"); |
| 920 | |
| 921 | /* check color depth */ |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 922 | if (bpp == 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | bpp = var->bits_per_pixel = 32; |
Krzysztof Helt | 54f019e | 2008-07-23 21:31:01 -0700 | [diff] [blame] | 924 | if (par->chip_id == TGUI9440 && bpp == 32) |
| 925 | return -EINVAL; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 926 | /* check whether resolution fits on panel and in memory */ |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 927 | if (par->flatpanel && nativex && var->xres > nativex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | return -EINVAL; |
Krzysztof Helt | 74a933f | 2008-07-23 21:31:00 -0700 | [diff] [blame] | 929 | /* various resolution checks */ |
| 930 | var->xres = (var->xres + 7) & ~0x7; |
| 931 | if (var->xres != var->xres_virtual) |
| 932 | var->xres_virtual = var->xres; |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 933 | line_length = var->xres_virtual * bpp / 8; |
| 934 | #ifdef CONFIG_FB_TRIDENT_ACCEL |
| 935 | if (!is3Dchip(par->chip_id)) { |
| 936 | /* acceleration requires line length to be power of 2 */ |
| 937 | if (line_length <= 512) |
| 938 | var->xres_virtual = 512 * 8 / bpp; |
| 939 | else if (line_length <= 1024) |
| 940 | var->xres_virtual = 1024 * 8 / bpp; |
| 941 | else if (line_length <= 2048) |
| 942 | var->xres_virtual = 2048 * 8 / bpp; |
| 943 | else if (line_length <= 4096) |
| 944 | var->xres_virtual = 4096 * 8 / bpp; |
| 945 | else if (line_length <= 8192) |
| 946 | var->xres_virtual = 8192 * 8 / bpp; |
| 947 | |
| 948 | line_length = var->xres_virtual * bpp / 8; |
| 949 | } |
| 950 | #endif |
Krzysztof Helt | 74a933f | 2008-07-23 21:31:00 -0700 | [diff] [blame] | 951 | if (var->yres > var->yres_virtual) |
| 952 | var->yres_virtual = var->yres; |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 953 | if (line_length * var->yres_virtual > info->fix.smem_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | return -EINVAL; |
| 955 | |
| 956 | switch (bpp) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 957 | case 8: |
| 958 | var->red.offset = 0; |
| 959 | var->green.offset = 0; |
| 960 | var->blue.offset = 0; |
| 961 | var->red.length = 6; |
| 962 | var->green.length = 6; |
| 963 | var->blue.length = 6; |
| 964 | break; |
| 965 | case 16: |
| 966 | var->red.offset = 11; |
| 967 | var->green.offset = 5; |
| 968 | var->blue.offset = 0; |
| 969 | var->red.length = 5; |
| 970 | var->green.length = 6; |
| 971 | var->blue.length = 5; |
| 972 | break; |
| 973 | case 32: |
| 974 | var->red.offset = 16; |
| 975 | var->green.offset = 8; |
| 976 | var->blue.offset = 0; |
| 977 | var->red.length = 8; |
| 978 | var->green.length = 8; |
| 979 | var->blue.length = 8; |
| 980 | break; |
| 981 | default: |
| 982 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } |
Krzysztof Helt | 74a933f | 2008-07-23 21:31:00 -0700 | [diff] [blame] | 984 | |
| 985 | if (is_xp(par->chip_id)) |
| 986 | ramdac = 350000; |
| 987 | |
| 988 | switch (par->chip_id) { |
| 989 | case TGUI9440: |
Krzysztof Helt | 54f019e | 2008-07-23 21:31:01 -0700 | [diff] [blame] | 990 | ramdac = (bpp >= 16) ? 45000 : 90000; |
Krzysztof Helt | 74a933f | 2008-07-23 21:31:00 -0700 | [diff] [blame] | 991 | break; |
| 992 | case CYBER9320: |
| 993 | case TGUI9660: |
| 994 | ramdac = 135000; |
| 995 | break; |
| 996 | case PROVIDIA9685: |
| 997 | case CYBER9388: |
| 998 | case CYBER9382: |
| 999 | case CYBER9385: |
| 1000 | ramdac = 170000; |
| 1001 | break; |
| 1002 | } |
| 1003 | |
| 1004 | /* The clock is doubled for 32 bpp */ |
| 1005 | if (bpp == 32) |
| 1006 | ramdac /= 2; |
| 1007 | |
| 1008 | if (PICOS2KHZ(var->pixclock) > ramdac) |
| 1009 | return -EINVAL; |
| 1010 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | debug("exit\n"); |
| 1012 | |
| 1013 | return 0; |
| 1014 | |
| 1015 | } |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | /* Pan the display */ |
| 1018 | static int tridentfb_pan_display(struct fb_var_screeninfo *var, |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1019 | struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | { |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1021 | struct tridentfb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | unsigned int offset; |
| 1023 | |
| 1024 | debug("enter\n"); |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 1025 | offset = (var->xoffset + (var->yoffset * var->xres_virtual)) |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1026 | * var->bits_per_pixel / 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | info->var.xoffset = var->xoffset; |
| 1028 | info->var.yoffset = var->yoffset; |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1029 | set_screen_start(par, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | debug("exit\n"); |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1034 | static void shadowmode_on(struct tridentfb_par *par) |
| 1035 | { |
| 1036 | write3CE(par, CyberControl, read3CE(par, CyberControl) | 0x81); |
| 1037 | } |
| 1038 | |
| 1039 | static void shadowmode_off(struct tridentfb_par *par) |
| 1040 | { |
| 1041 | write3CE(par, CyberControl, read3CE(par, CyberControl) & 0x7E); |
| 1042 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
| 1044 | /* Set the hardware to the requested video mode */ |
| 1045 | static int tridentfb_set_par(struct fb_info *info) |
| 1046 | { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1047 | struct tridentfb_par *par = (struct tridentfb_par *)(info->par); |
| 1048 | u32 htotal, hdispend, hsyncstart, hsyncend, hblankstart, hblankend; |
| 1049 | u32 vtotal, vdispend, vsyncstart, vsyncend, vblankstart, vblankend; |
| 1050 | struct fb_var_screeninfo *var = &info->var; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | int bpp = var->bits_per_pixel; |
| 1052 | unsigned char tmp; |
Krzysztof Helt | 3f275ea | 2008-05-12 14:02:11 -0700 | [diff] [blame] | 1053 | unsigned long vclk; |
| 1054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | debug("enter\n"); |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1056 | hdispend = var->xres / 8 - 1; |
Krzysztof Helt | 7f762d2 | 2008-07-23 21:30:55 -0700 | [diff] [blame] | 1057 | hsyncstart = (var->xres + var->right_margin) / 8 - 1; |
| 1058 | hsyncend = (var->xres + var->right_margin + var->hsync_len) / 8 - 1; |
| 1059 | htotal = (var->xres + var->left_margin + var->right_margin + |
| 1060 | var->hsync_len) / 8 - 5; |
Krzysztof Helt | 0e73a47 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 1061 | hblankstart = hdispend + 1; |
Krzysztof Helt | 7f762d2 | 2008-07-23 21:30:55 -0700 | [diff] [blame] | 1062 | hblankend = htotal + 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | vdispend = var->yres - 1; |
| 1065 | vsyncstart = var->yres + var->lower_margin; |
Krzysztof Helt | 7f762d2 | 2008-07-23 21:30:55 -0700 | [diff] [blame] | 1066 | vsyncend = vsyncstart + var->vsync_len; |
| 1067 | vtotal = var->upper_margin + vsyncend - 2; |
Krzysztof Helt | 0e73a47 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 1068 | vblankstart = vdispend + 1; |
Krzysztof Helt | 7f762d2 | 2008-07-23 21:30:55 -0700 | [diff] [blame] | 1069 | vblankend = vtotal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1071 | crtc_unlock(par); |
| 1072 | write3CE(par, CyberControl, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 1074 | if (par->flatpanel && var->xres < nativex) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | /* |
| 1076 | * on flat panels with native size larger |
| 1077 | * than requested resolution decide whether |
| 1078 | * we stretch or center |
| 1079 | */ |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1080 | t_outb(par, 0xEB, VGA_MIS_W); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1082 | shadowmode_on(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1084 | if (center) |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1085 | screen_center(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | else if (stretch) |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1087 | screen_stretch(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
| 1089 | } else { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1090 | t_outb(par, 0x2B, VGA_MIS_W); |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1091 | write3CE(par, CyberControl, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | /* vertical timing values */ |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1095 | write3X4(par, VGA_CRTC_V_TOTAL, vtotal & 0xFF); |
| 1096 | write3X4(par, VGA_CRTC_V_DISP_END, vdispend & 0xFF); |
| 1097 | write3X4(par, VGA_CRTC_V_SYNC_START, vsyncstart & 0xFF); |
| 1098 | write3X4(par, VGA_CRTC_V_SYNC_END, (vsyncend & 0x0F)); |
| 1099 | write3X4(par, VGA_CRTC_V_BLANK_START, vblankstart & 0xFF); |
Krzysztof Helt | 7f762d2 | 2008-07-23 21:30:55 -0700 | [diff] [blame] | 1100 | write3X4(par, VGA_CRTC_V_BLANK_END, vblankend & 0xFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
| 1102 | /* horizontal timing values */ |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1103 | write3X4(par, VGA_CRTC_H_TOTAL, htotal & 0xFF); |
| 1104 | write3X4(par, VGA_CRTC_H_DISP, hdispend & 0xFF); |
| 1105 | write3X4(par, VGA_CRTC_H_SYNC_START, hsyncstart & 0xFF); |
| 1106 | write3X4(par, VGA_CRTC_H_SYNC_END, |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1107 | (hsyncend & 0x1F) | ((hblankend & 0x20) << 2)); |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1108 | write3X4(par, VGA_CRTC_H_BLANK_START, hblankstart & 0xFF); |
Krzysztof Helt | 7f762d2 | 2008-07-23 21:30:55 -0700 | [diff] [blame] | 1109 | write3X4(par, VGA_CRTC_H_BLANK_END, hblankend & 0x1F); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
| 1111 | /* higher bits of vertical timing values */ |
| 1112 | tmp = 0x10; |
| 1113 | if (vtotal & 0x100) tmp |= 0x01; |
| 1114 | if (vdispend & 0x100) tmp |= 0x02; |
| 1115 | if (vsyncstart & 0x100) tmp |= 0x04; |
| 1116 | if (vblankstart & 0x100) tmp |= 0x08; |
| 1117 | |
| 1118 | if (vtotal & 0x200) tmp |= 0x20; |
| 1119 | if (vdispend & 0x200) tmp |= 0x40; |
| 1120 | if (vsyncstart & 0x200) tmp |= 0x80; |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1121 | write3X4(par, VGA_CRTC_OVERFLOW, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | |
Krzysztof Helt | 7f762d2 | 2008-07-23 21:30:55 -0700 | [diff] [blame] | 1123 | tmp = read3X4(par, CRTHiOrd) & 0x07; |
| 1124 | tmp |= 0x08; /* line compare bit 10 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | if (vtotal & 0x400) tmp |= 0x80; |
| 1126 | if (vblankstart & 0x400) tmp |= 0x40; |
| 1127 | if (vsyncstart & 0x400) tmp |= 0x20; |
| 1128 | if (vdispend & 0x400) tmp |= 0x10; |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1129 | write3X4(par, CRTHiOrd, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
Krzysztof Helt | 7f762d2 | 2008-07-23 21:30:55 -0700 | [diff] [blame] | 1131 | tmp = (htotal >> 8) & 0x01; |
| 1132 | tmp |= (hdispend >> 7) & 0x02; |
| 1133 | tmp |= (hsyncstart >> 5) & 0x08; |
| 1134 | tmp |= (hblankstart >> 4) & 0x10; |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1135 | write3X4(par, HorizOverflow, tmp); |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | tmp = 0x40; |
| 1138 | if (vblankstart & 0x200) tmp |= 0x20; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1139 | //FIXME if (info->var.vmode & FB_VMODE_DOUBLE) tmp |= 0x80; /* double scan for 200 line modes */ |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1140 | write3X4(par, VGA_CRTC_MAX_SCAN, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1142 | write3X4(par, VGA_CRTC_LINE_COMPARE, 0xFF); |
| 1143 | write3X4(par, VGA_CRTC_PRESET_ROW, 0); |
| 1144 | write3X4(par, VGA_CRTC_MODE, 0xC3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1146 | write3X4(par, LinearAddReg, 0x20); /* enable linear addressing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1148 | tmp = (info->var.vmode & FB_VMODE_INTERLACED) ? 0x84 : 0x80; |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1149 | /* enable access extended memory */ |
| 1150 | write3X4(par, CRTCModuleTest, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1152 | /* enable GE for text acceleration */ |
| 1153 | write3X4(par, GraphEngReg, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1155 | #ifdef CONFIG_FB_TRIDENT_ACCEL |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 1156 | par->init_accel(par, info->var.xres_virtual, bpp); |
Antonino A. Daplas | 8dad46c | 2005-08-01 23:46:44 +0800 | [diff] [blame] | 1157 | #endif |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | switch (bpp) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1160 | case 8: |
| 1161 | tmp = 0x00; |
| 1162 | break; |
| 1163 | case 16: |
| 1164 | tmp = 0x05; |
| 1165 | break; |
| 1166 | case 24: |
| 1167 | tmp = 0x29; |
| 1168 | break; |
| 1169 | case 32: |
| 1170 | tmp = 0x09; |
| 1171 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1174 | write3X4(par, PixelBusReg, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | |
Krzysztof Helt | 0e73a47 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 1176 | tmp = read3X4(par, DRAMControl); |
| 1177 | if (!is_oldprotect(par->chip_id)) |
| 1178 | tmp |= 0x10; |
Krzysztof Helt | 122e8ad | 2008-07-23 21:30:52 -0700 | [diff] [blame] | 1179 | if (iscyber(par->chip_id)) |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1180 | tmp |= 0x20; |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1181 | write3X4(par, DRAMControl, tmp); /* both IO, linear enable */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1183 | write3X4(par, InterfaceSel, read3X4(par, InterfaceSel) | 0x40); |
Krzysztof Helt | 0e73a47 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 1184 | if (!is_xp(par->chip_id)) |
| 1185 | write3X4(par, Performance, read3X4(par, Performance) | 0x10); |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1186 | /* MMIO & PCI read and write burst enable */ |
Krzysztof Helt | a0d9225 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 1187 | if (par->chip_id != TGUI9440) |
| 1188 | write3X4(par, PCIReg, read3X4(par, PCIReg) | 0x06); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1190 | vga_mm_wseq(par->io_virt, 0, 3); |
| 1191 | vga_mm_wseq(par->io_virt, 1, 1); /* set char clock 8 dots wide */ |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1192 | /* enable 4 maps because needed in chain4 mode */ |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1193 | vga_mm_wseq(par->io_virt, 2, 0x0F); |
| 1194 | vga_mm_wseq(par->io_virt, 3, 0); |
| 1195 | vga_mm_wseq(par->io_virt, 4, 0x0E); /* memory mode enable bitmaps ?? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | |
Krzysztof Helt | 54f019e | 2008-07-23 21:31:01 -0700 | [diff] [blame] | 1197 | /* convert from picoseconds to kHz */ |
| 1198 | vclk = PICOS2KHZ(info->var.pixclock); |
| 1199 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1200 | /* divide clock by 2 if 32bpp chain4 mode display and CPU path */ |
Krzysztof Helt | 65e93e0 | 2008-07-23 21:31:00 -0700 | [diff] [blame] | 1201 | tmp = read3CE(par, MiscExtFunc) & 0xF0; |
Krzysztof Helt | 54f019e | 2008-07-23 21:31:01 -0700 | [diff] [blame] | 1202 | if (bpp == 32 || (par->chip_id == TGUI9440 && bpp == 16)) { |
Krzysztof Helt | 65e93e0 | 2008-07-23 21:31:00 -0700 | [diff] [blame] | 1203 | tmp |= 8; |
Krzysztof Helt | 54f019e | 2008-07-23 21:31:01 -0700 | [diff] [blame] | 1204 | vclk *= 2; |
| 1205 | } |
| 1206 | set_vclk(par, vclk); |
Krzysztof Helt | 65e93e0 | 2008-07-23 21:31:00 -0700 | [diff] [blame] | 1207 | write3CE(par, MiscExtFunc, tmp | 0x12); |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1208 | write3CE(par, 0x5, 0x40); /* no CGA compat, allow 256 col */ |
| 1209 | write3CE(par, 0x6, 0x05); /* graphics mode */ |
| 1210 | write3CE(par, 0x7, 0x0F); /* planes? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
Krzysztof Helt | 122e8ad | 2008-07-23 21:30:52 -0700 | [diff] [blame] | 1212 | if (par->chip_id == CYBERBLADEXPAi1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | /* This fixes snow-effect in 32 bpp */ |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1214 | write3X4(par, VGA_CRTC_H_SYNC_START, 0x84); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1217 | /* graphics mode and support 256 color modes */ |
| 1218 | writeAttr(par, 0x10, 0x41); |
| 1219 | writeAttr(par, 0x12, 0x0F); /* planes */ |
| 1220 | writeAttr(par, 0x13, 0); /* horizontal pel panning */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1222 | /* colors */ |
| 1223 | for (tmp = 0; tmp < 0x10; tmp++) |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1224 | writeAttr(par, tmp, tmp); |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1225 | fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */ |
| 1226 | t_outb(par, 0x20, VGA_ATT_W); /* enable attr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
| 1228 | switch (bpp) { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1229 | case 8: |
| 1230 | tmp = 0; |
| 1231 | break; |
| 1232 | case 15: |
| 1233 | tmp = 0x10; |
| 1234 | break; |
| 1235 | case 16: |
| 1236 | tmp = 0x30; |
| 1237 | break; |
| 1238 | case 24: |
| 1239 | case 32: |
| 1240 | tmp = 0xD0; |
| 1241 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1244 | t_inb(par, VGA_PEL_IW); |
| 1245 | t_inb(par, VGA_PEL_MSK); |
| 1246 | t_inb(par, VGA_PEL_MSK); |
| 1247 | t_inb(par, VGA_PEL_MSK); |
| 1248 | t_inb(par, VGA_PEL_MSK); |
| 1249 | t_outb(par, tmp, VGA_PEL_MSK); |
| 1250 | t_inb(par, VGA_PEL_IW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 1252 | if (par->flatpanel) |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1253 | set_number_of_lines(par, info->var.yres); |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 1254 | info->fix.line_length = info->var.xres_virtual * bpp / 8; |
| 1255 | set_lwidth(par, info->fix.line_length / 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | info->fix.visual = (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1257 | info->cmap.len = (bpp == 8) ? 256 : 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | debug("exit\n"); |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
| 1262 | /* Set one color register */ |
| 1263 | static int tridentfb_setcolreg(unsigned regno, unsigned red, unsigned green, |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1264 | unsigned blue, unsigned transp, |
| 1265 | struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | { |
| 1267 | int bpp = info->var.bits_per_pixel; |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1268 | struct tridentfb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | |
| 1270 | if (regno >= info->cmap.len) |
| 1271 | return 1; |
| 1272 | |
Antonino A. Daplas | 973d9ab | 2007-07-17 04:05:41 -0700 | [diff] [blame] | 1273 | if (bpp == 8) { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1274 | t_outb(par, 0xFF, VGA_PEL_MSK); |
| 1275 | t_outb(par, regno, VGA_PEL_IW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1277 | t_outb(par, red >> 10, VGA_PEL_D); |
| 1278 | t_outb(par, green >> 10, VGA_PEL_D); |
| 1279 | t_outb(par, blue >> 10, VGA_PEL_D); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
Antonino A. Daplas | 973d9ab | 2007-07-17 04:05:41 -0700 | [diff] [blame] | 1281 | } else if (regno < 16) { |
| 1282 | if (bpp == 16) { /* RGB 565 */ |
| 1283 | u32 col; |
Antonino A. Daplas | 8dad46c | 2005-08-01 23:46:44 +0800 | [diff] [blame] | 1284 | |
Antonino A. Daplas | 973d9ab | 2007-07-17 04:05:41 -0700 | [diff] [blame] | 1285 | col = (red & 0xF800) | ((green & 0xFC00) >> 5) | |
| 1286 | ((blue & 0xF800) >> 11); |
| 1287 | col |= col << 16; |
| 1288 | ((u32 *)(info->pseudo_palette))[regno] = col; |
| 1289 | } else if (bpp == 32) /* ARGB 8888 */ |
| 1290 | ((u32*)info->pseudo_palette)[regno] = |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1291 | ((transp & 0xFF00) << 16) | |
| 1292 | ((red & 0xFF00) << 8) | |
Antonino A. Daplas | 973d9ab | 2007-07-17 04:05:41 -0700 | [diff] [blame] | 1293 | ((green & 0xFF00)) | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1294 | ((blue & 0xFF00) >> 8); |
Antonino A. Daplas | 973d9ab | 2007-07-17 04:05:41 -0700 | [diff] [blame] | 1295 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1297 | /* debug("exit\n"); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | return 0; |
| 1299 | } |
| 1300 | |
| 1301 | /* Try blanking the screen.For flat panels it does nothing */ |
| 1302 | static int tridentfb_blank(int blank_mode, struct fb_info *info) |
| 1303 | { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1304 | unsigned char PMCont, DPMSCont; |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1305 | struct tridentfb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | |
| 1307 | debug("enter\n"); |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 1308 | if (par->flatpanel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | return 0; |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1310 | t_outb(par, 0x04, 0x83C8); /* Read DPMS Control */ |
| 1311 | PMCont = t_inb(par, 0x83C6) & 0xFC; |
| 1312 | DPMSCont = read3CE(par, PowerStatus) & 0xFC; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1313 | switch (blank_mode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | case FB_BLANK_UNBLANK: |
| 1315 | /* Screen: On, HSync: On, VSync: On */ |
| 1316 | case FB_BLANK_NORMAL: |
| 1317 | /* Screen: Off, HSync: On, VSync: On */ |
| 1318 | PMCont |= 0x03; |
| 1319 | DPMSCont |= 0x00; |
| 1320 | break; |
| 1321 | case FB_BLANK_HSYNC_SUSPEND: |
| 1322 | /* Screen: Off, HSync: Off, VSync: On */ |
| 1323 | PMCont |= 0x02; |
| 1324 | DPMSCont |= 0x01; |
| 1325 | break; |
| 1326 | case FB_BLANK_VSYNC_SUSPEND: |
| 1327 | /* Screen: Off, HSync: On, VSync: Off */ |
| 1328 | PMCont |= 0x02; |
| 1329 | DPMSCont |= 0x02; |
| 1330 | break; |
| 1331 | case FB_BLANK_POWERDOWN: |
| 1332 | /* Screen: Off, HSync: Off, VSync: Off */ |
| 1333 | PMCont |= 0x00; |
| 1334 | DPMSCont |= 0x03; |
| 1335 | break; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1336 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | |
Krzysztof Helt | 306fa6f | 2008-07-23 21:30:50 -0700 | [diff] [blame] | 1338 | write3CE(par, PowerStatus, DPMSCont); |
| 1339 | t_outb(par, 4, 0x83C8); |
| 1340 | t_outb(par, PMCont, 0x83C6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | |
| 1342 | debug("exit\n"); |
| 1343 | |
| 1344 | /* let fbcon do a softblank for us */ |
| 1345 | return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0; |
| 1346 | } |
| 1347 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1348 | static struct fb_ops tridentfb_ops = { |
| 1349 | .owner = THIS_MODULE, |
| 1350 | .fb_setcolreg = tridentfb_setcolreg, |
| 1351 | .fb_pan_display = tridentfb_pan_display, |
| 1352 | .fb_blank = tridentfb_blank, |
| 1353 | .fb_check_var = tridentfb_check_var, |
| 1354 | .fb_set_par = tridentfb_set_par, |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 1355 | #ifdef CONFIG_FB_TRIDENT_ACCEL |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1356 | .fb_fillrect = tridentfb_fillrect, |
| 1357 | .fb_copyarea = tridentfb_copyarea, |
| 1358 | .fb_imageblit = cfb_imageblit, |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 1359 | #endif |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1360 | }; |
| 1361 | |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1362 | static int __devinit trident_pci_probe(struct pci_dev *dev, |
| 1363 | const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | { |
| 1365 | int err; |
| 1366 | unsigned char revision; |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1367 | struct fb_info *info; |
| 1368 | struct tridentfb_par *default_par; |
Krzysztof Helt | 122e8ad | 2008-07-23 21:30:52 -0700 | [diff] [blame] | 1369 | int defaultaccel; |
| 1370 | int chip3D; |
| 1371 | int chip_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
| 1373 | err = pci_enable_device(dev); |
| 1374 | if (err) |
| 1375 | return err; |
| 1376 | |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1377 | info = framebuffer_alloc(sizeof(struct tridentfb_par), &dev->dev); |
| 1378 | if (!info) |
| 1379 | return -ENOMEM; |
| 1380 | default_par = info->par; |
| 1381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | chip_id = id->device; |
| 1383 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1384 | if (chip_id == CYBERBLADEi1) |
Knut Petersen | 9fa68ea | 2005-09-09 13:04:56 -0700 | [diff] [blame] | 1385 | output("*** Please do use cyblafb, Cyberblade/i1 support " |
| 1386 | "will soon be removed from tridentfb!\n"); |
| 1387 | |
| 1388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | /* If PCI id is 0x9660 then further detect chip type */ |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | if (chip_id == TGUI9660) { |
Krzysztof Helt | 10172ed | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1392 | revision = vga_io_rseq(RevisionID); |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | switch (revision) { |
Krzysztof Helt | 0e73a47 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 1395 | case 0x21: |
| 1396 | chip_id = PROVIDIA9685; |
| 1397 | break; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1398 | case 0x22: |
| 1399 | case 0x23: |
| 1400 | chip_id = CYBER9397; |
| 1401 | break; |
| 1402 | case 0x2A: |
| 1403 | chip_id = CYBER9397DVD; |
| 1404 | break; |
| 1405 | case 0x30: |
| 1406 | case 0x33: |
| 1407 | case 0x34: |
| 1408 | case 0x35: |
| 1409 | case 0x38: |
| 1410 | case 0x3A: |
| 1411 | case 0xB3: |
| 1412 | chip_id = CYBER9385; |
| 1413 | break; |
| 1414 | case 0x40 ... 0x43: |
| 1415 | chip_id = CYBER9382; |
| 1416 | break; |
| 1417 | case 0x4A: |
| 1418 | chip_id = CYBER9388; |
| 1419 | break; |
| 1420 | default: |
| 1421 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | chip3D = is3Dchip(chip_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | |
| 1427 | if (is_xp(chip_id)) { |
Krzysztof Helt | d9cad04 | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1428 | default_par->init_accel = xp_init_accel; |
| 1429 | default_par->wait_engine = xp_wait_engine; |
| 1430 | default_par->fill_rect = xp_fill_rect; |
| 1431 | default_par->copy_rect = xp_copy_rect; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1432 | } else if (is_blade(chip_id)) { |
Krzysztof Helt | d9cad04 | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1433 | default_par->init_accel = blade_init_accel; |
| 1434 | default_par->wait_engine = blade_wait_engine; |
| 1435 | default_par->fill_rect = blade_fill_rect; |
| 1436 | default_par->copy_rect = blade_copy_rect; |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 1437 | } else if (chip3D) { /* 3DImage family left */ |
Krzysztof Helt | d9cad04 | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1438 | default_par->init_accel = image_init_accel; |
| 1439 | default_par->wait_engine = image_wait_engine; |
| 1440 | default_par->fill_rect = image_fill_rect; |
| 1441 | default_par->copy_rect = image_copy_rect; |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 1442 | } else { /* TGUI 9440/96XX family */ |
| 1443 | default_par->init_accel = tgui_init_accel; |
| 1444 | default_par->wait_engine = xp_wait_engine; |
| 1445 | default_par->fill_rect = tgui_fill_rect; |
| 1446 | default_par->copy_rect = tgui_copy_rect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Krzysztof Helt | 122e8ad | 2008-07-23 21:30:52 -0700 | [diff] [blame] | 1449 | default_par->chip_id = chip_id; |
| 1450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | /* acceleration is on by default for 3D chips */ |
| 1452 | defaultaccel = chip3D && !noaccel; |
| 1453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | /* setup MMIO region */ |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1455 | tridentfb_fix.mmio_start = pci_resource_start(dev, 1); |
| 1456 | tridentfb_fix.mmio_len = chip3D ? 0x20000 : 0x10000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | |
| 1458 | if (!request_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len, "tridentfb")) { |
| 1459 | debug("request_region failed!\n"); |
Krzysztof Helt | 3876ae8 | 2008-07-23 21:30:57 -0700 | [diff] [blame] | 1460 | framebuffer_release(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | return -1; |
| 1462 | } |
| 1463 | |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1464 | default_par->io_virt = ioremap_nocache(tridentfb_fix.mmio_start, |
| 1465 | tridentfb_fix.mmio_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1467 | if (!default_par->io_virt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | debug("ioremap failed\n"); |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1469 | err = -1; |
| 1470 | goto out_unmap1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | } |
| 1472 | |
Krzysztof Helt | bcac2d5 | 2008-07-23 21:31:01 -0700 | [diff] [blame^] | 1473 | enable_mmio(); |
| 1474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | /* setup framebuffer memory */ |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1476 | tridentfb_fix.smem_start = pci_resource_start(dev, 0); |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1477 | tridentfb_fix.smem_len = get_memsize(default_par); |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | if (!request_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len, "tridentfb")) { |
| 1480 | debug("request_mem_region failed!\n"); |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1481 | disable_mmio(info->par); |
Amol Lad | a02f640 | 2006-12-08 02:40:03 -0800 | [diff] [blame] | 1482 | err = -1; |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1483 | goto out_unmap1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1486 | info->screen_base = ioremap_nocache(tridentfb_fix.smem_start, |
| 1487 | tridentfb_fix.smem_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1489 | if (!info->screen_base) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | debug("ioremap failed\n"); |
Amol Lad | a02f640 | 2006-12-08 02:40:03 -0800 | [diff] [blame] | 1491 | err = -1; |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1492 | goto out_unmap2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | output("%s board found\n", pci_name(dev)); |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 1496 | default_par->flatpanel = is_flatpanel(default_par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 1498 | if (default_par->flatpanel) |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1499 | nativex = get_nativex(default_par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1501 | info->fix = tridentfb_fix; |
| 1502 | info->fbops = &tridentfb_ops; |
Krzysztof Helt | aa0aa8a | 2008-07-23 21:30:59 -0700 | [diff] [blame] | 1503 | info->pseudo_palette = default_par->pseudo_pal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1505 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | #ifdef CONFIG_FB_TRIDENT_ACCEL |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1507 | info->flags |= FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | #endif |
Krzysztof Helt | ea8ee55 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1509 | if (!fb_find_mode(&info->var, info, |
Krzysztof Helt | 07f41e4 | 2008-04-28 02:15:06 -0700 | [diff] [blame] | 1510 | mode_option, NULL, 0, NULL, bpp)) { |
Amol Lad | a02f640 | 2006-12-08 02:40:03 -0800 | [diff] [blame] | 1511 | err = -EINVAL; |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1512 | goto out_unmap2; |
Amol Lad | a02f640 | 2006-12-08 02:40:03 -0800 | [diff] [blame] | 1513 | } |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1514 | err = fb_alloc_cmap(&info->cmap, 256, 0); |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1515 | if (err < 0) |
| 1516 | goto out_unmap2; |
| 1517 | |
Krzysztof Helt | d9cad04 | 2008-07-23 21:30:54 -0700 | [diff] [blame] | 1518 | if (defaultaccel && default_par->init_accel) |
Krzysztof Helt | ea8ee55 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1519 | info->var.accel_flags |= FB_ACCELF_TEXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | else |
Krzysztof Helt | ea8ee55 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1521 | info->var.accel_flags &= ~FB_ACCELF_TEXT; |
| 1522 | info->var.activate |= FB_ACTIVATE_NOW; |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1523 | info->device = &dev->dev; |
| 1524 | if (register_framebuffer(info) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | printk(KERN_ERR "tridentfb: could not register Trident framebuffer\n"); |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1526 | fb_dealloc_cmap(&info->cmap); |
Amol Lad | a02f640 | 2006-12-08 02:40:03 -0800 | [diff] [blame] | 1527 | err = -EINVAL; |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1528 | goto out_unmap2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | } |
| 1530 | output("fb%d: %s frame buffer device %dx%d-%dbpp\n", |
Krzysztof Helt | ea8ee55 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1531 | info->node, info->fix.id, info->var.xres, |
| 1532 | info->var.yres, info->var.bits_per_pixel); |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1533 | |
| 1534 | pci_set_drvdata(dev, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | return 0; |
Amol Lad | a02f640 | 2006-12-08 02:40:03 -0800 | [diff] [blame] | 1536 | |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1537 | out_unmap2: |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1538 | if (info->screen_base) |
| 1539 | iounmap(info->screen_base); |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1540 | release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len); |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1541 | disable_mmio(info->par); |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1542 | out_unmap1: |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1543 | if (default_par->io_virt) |
| 1544 | iounmap(default_par->io_virt); |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1545 | release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len); |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1546 | framebuffer_release(info); |
Amol Lad | a02f640 | 2006-12-08 02:40:03 -0800 | [diff] [blame] | 1547 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1550 | static void __devexit trident_pci_remove(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | { |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1552 | struct fb_info *info = pci_get_drvdata(dev); |
| 1553 | struct tridentfb_par *par = info->par; |
| 1554 | |
| 1555 | unregister_framebuffer(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | iounmap(par->io_virt); |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1557 | iounmap(info->screen_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len); |
Krzysztof Helt | e8ed857 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 1559 | release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len); |
Krzysztof Helt | e09ed09 | 2008-07-23 21:30:51 -0700 | [diff] [blame] | 1560 | pci_set_drvdata(dev, NULL); |
| 1561 | framebuffer_release(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | /* List of boards that we are trying to support */ |
| 1565 | static struct pci_device_id trident_devices[] = { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1566 | {PCI_VENDOR_ID_TRIDENT, BLADE3D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1567 | {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1568 | {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1569 | {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1570 | {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1571 | {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1572 | {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1573 | {PCI_VENDOR_ID_TRIDENT, CYBERBLADEE4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
Krzysztof Helt | a0d9225 | 2008-07-23 21:30:58 -0700 | [diff] [blame] | 1574 | {PCI_VENDOR_ID_TRIDENT, TGUI9440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1575 | {PCI_VENDOR_ID_TRIDENT, TGUI9660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1576 | {PCI_VENDOR_ID_TRIDENT, IMAGE975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1577 | {PCI_VENDOR_ID_TRIDENT, IMAGE985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1578 | {PCI_VENDOR_ID_TRIDENT, CYBER9320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1579 | {PCI_VENDOR_ID_TRIDENT, CYBER9388, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1580 | {PCI_VENDOR_ID_TRIDENT, CYBER9520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1581 | {PCI_VENDOR_ID_TRIDENT, CYBER9525DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1582 | {PCI_VENDOR_ID_TRIDENT, CYBER9397, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1583 | {PCI_VENDOR_ID_TRIDENT, CYBER9397DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1584 | {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1585 | {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 1586 | {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm16, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | {0,} |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1588 | }; |
| 1589 | |
| 1590 | MODULE_DEVICE_TABLE(pci, trident_devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | |
| 1592 | static struct pci_driver tridentfb_pci_driver = { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1593 | .name = "tridentfb", |
| 1594 | .id_table = trident_devices, |
| 1595 | .probe = trident_pci_probe, |
| 1596 | .remove = __devexit_p(trident_pci_remove) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | }; |
| 1598 | |
| 1599 | /* |
| 1600 | * Parse user specified options (`video=trident:') |
| 1601 | * example: |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1602 | * video=trident:800x600,bpp=16,noaccel |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | */ |
| 1604 | #ifndef MODULE |
Krzysztof Helt | 07f41e4 | 2008-04-28 02:15:06 -0700 | [diff] [blame] | 1605 | static int __init tridentfb_setup(char *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | { |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1607 | char *opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | if (!options || !*options) |
| 1609 | return 0; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1610 | while ((opt = strsep(&options, ",")) != NULL) { |
| 1611 | if (!*opt) |
| 1612 | continue; |
| 1613 | if (!strncmp(opt, "noaccel", 7)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | noaccel = 1; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1615 | else if (!strncmp(opt, "fp", 2)) |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 1616 | fp = 1; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1617 | else if (!strncmp(opt, "crt", 3)) |
Krzysztof Helt | 6eed8e1 | 2008-07-23 21:30:53 -0700 | [diff] [blame] | 1618 | fp = 0; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1619 | else if (!strncmp(opt, "bpp=", 4)) |
| 1620 | bpp = simple_strtoul(opt + 4, NULL, 0); |
| 1621 | else if (!strncmp(opt, "center", 6)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | center = 1; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1623 | else if (!strncmp(opt, "stretch", 7)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | stretch = 1; |
Krzysztof Helt | 245a2c2 | 2007-10-16 01:28:42 -0700 | [diff] [blame] | 1625 | else if (!strncmp(opt, "memsize=", 8)) |
| 1626 | memsize = simple_strtoul(opt + 8, NULL, 0); |
| 1627 | else if (!strncmp(opt, "memdiff=", 8)) |
| 1628 | memdiff = simple_strtoul(opt + 8, NULL, 0); |
| 1629 | else if (!strncmp(opt, "nativex=", 8)) |
| 1630 | nativex = simple_strtoul(opt + 8, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | else |
Krzysztof Helt | 07f41e4 | 2008-04-28 02:15:06 -0700 | [diff] [blame] | 1632 | mode_option = opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | } |
| 1634 | return 0; |
| 1635 | } |
| 1636 | #endif |
| 1637 | |
| 1638 | static int __init tridentfb_init(void) |
| 1639 | { |
| 1640 | #ifndef MODULE |
| 1641 | char *option = NULL; |
| 1642 | |
| 1643 | if (fb_get_options("tridentfb", &option)) |
| 1644 | return -ENODEV; |
| 1645 | tridentfb_setup(option); |
| 1646 | #endif |
| 1647 | output("Trident framebuffer %s initializing\n", VERSION); |
| 1648 | return pci_register_driver(&tridentfb_pci_driver); |
| 1649 | } |
| 1650 | |
| 1651 | static void __exit tridentfb_exit(void) |
| 1652 | { |
| 1653 | pci_unregister_driver(&tridentfb_pci_driver); |
| 1654 | } |
| 1655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | module_init(tridentfb_init); |
| 1657 | module_exit(tridentfb_exit); |
| 1658 | |
| 1659 | MODULE_AUTHOR("Jani Monoses <jani@iv.ro>"); |
| 1660 | MODULE_DESCRIPTION("Framebuffer driver for Trident cards"); |
| 1661 | MODULE_LICENSE("GPL"); |
| 1662 | |