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