Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/s3fb.c -- Frame buffer device driver for S3 Trio/Virge |
| 3 | * |
| 4 | * Copyright (c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org> |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file COPYING in the main directory of this archive for |
| 8 | * more details. |
| 9 | * |
| 10 | * Code is based on David Boucher's viafb (http://davesdomain.org.uk/viafb/) |
| 11 | * which is based on the code of neofb. |
| 12 | */ |
| 13 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/mm.h> |
| 19 | #include <linux/tty.h> |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 20 | #include <linux/delay.h> |
| 21 | #include <linux/fb.h> |
| 22 | #include <linux/svga.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/pci.h> |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 25 | #include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */ |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 26 | #include <video/vga.h> |
| 27 | |
| 28 | #ifdef CONFIG_MTRR |
| 29 | #include <asm/mtrr.h> |
| 30 | #endif |
| 31 | |
| 32 | struct s3fb_info { |
| 33 | int chip, rev, mclk_freq; |
| 34 | int mtrr_reg; |
| 35 | struct vgastate state; |
| 36 | struct mutex open_lock; |
| 37 | unsigned int ref_count; |
| 38 | u32 pseudo_palette[16]; |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | /* ------------------------------------------------------------------------- */ |
| 43 | |
| 44 | static const struct svga_fb_format s3fb_formats[] = { |
| 45 | { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0, |
| 46 | FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 16}, |
Michal Januszewski | c26d7b2 | 2009-04-13 14:39:49 -0700 | [diff] [blame] | 47 | { 4, {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 0, |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 48 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16}, |
Michal Januszewski | c26d7b2 | 2009-04-13 14:39:49 -0700 | [diff] [blame] | 49 | { 4, {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 1, |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 50 | FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16}, |
Michal Januszewski | c26d7b2 | 2009-04-13 14:39:49 -0700 | [diff] [blame] | 51 | { 8, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 52 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 4, 8}, |
| 53 | {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0, |
| 54 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4}, |
| 55 | {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0, |
| 56 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4}, |
| 57 | {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, |
| 58 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2}, |
| 59 | {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, |
| 60 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2}, |
| 61 | SVGA_FORMAT_END |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | static const struct svga_pll s3_pll = {3, 129, 3, 33, 0, 3, |
Ondrej Zajicek | 249bdbb | 2007-05-08 00:39:24 -0700 | [diff] [blame] | 66 | 35000, 240000, 14318}; |
Ondrej Zary | 5694f9c | 2011-03-01 19:18:17 +0000 | [diff] [blame] | 67 | static const struct svga_pll s3_trio3d_pll = {3, 129, 3, 31, 0, 4, |
| 68 | 230000, 460000, 14318}; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 69 | |
| 70 | static const int s3_memsizes[] = {4096, 0, 3072, 8192, 2048, 6144, 1024, 512}; |
| 71 | |
| 72 | static const char * const s3_names[] = {"S3 Unknown", "S3 Trio32", "S3 Trio64", "S3 Trio64V+", |
| 73 | "S3 Trio64UV+", "S3 Trio64V2/DX", "S3 Trio64V2/GX", |
| 74 | "S3 Plato/PX", "S3 Aurora64VP", "S3 Virge", |
| 75 | "S3 Virge/VX", "S3 Virge/DX", "S3 Virge/GX", |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 76 | "S3 Virge/GX2", "S3 Virge/GX2P", "S3 Virge/GX2P", |
Ondrej Zary | 5694f9c | 2011-03-01 19:18:17 +0000 | [diff] [blame] | 77 | "S3 Trio3D/1X", "S3 Trio3D/2X", "S3 Trio3D/2X", |
| 78 | "S3 Trio3D"}; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 79 | |
| 80 | #define CHIP_UNKNOWN 0x00 |
| 81 | #define CHIP_732_TRIO32 0x01 |
| 82 | #define CHIP_764_TRIO64 0x02 |
| 83 | #define CHIP_765_TRIO64VP 0x03 |
| 84 | #define CHIP_767_TRIO64UVP 0x04 |
| 85 | #define CHIP_775_TRIO64V2_DX 0x05 |
| 86 | #define CHIP_785_TRIO64V2_GX 0x06 |
| 87 | #define CHIP_551_PLATO_PX 0x07 |
| 88 | #define CHIP_M65_AURORA64VP 0x08 |
| 89 | #define CHIP_325_VIRGE 0x09 |
| 90 | #define CHIP_988_VIRGE_VX 0x0A |
| 91 | #define CHIP_375_VIRGE_DX 0x0B |
| 92 | #define CHIP_385_VIRGE_GX 0x0C |
| 93 | #define CHIP_356_VIRGE_GX2 0x0D |
| 94 | #define CHIP_357_VIRGE_GX2P 0x0E |
| 95 | #define CHIP_359_VIRGE_GX2P 0x0F |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 96 | #define CHIP_360_TRIO3D_1X 0x10 |
| 97 | #define CHIP_362_TRIO3D_2X 0x11 |
| 98 | #define CHIP_368_TRIO3D_2X 0x12 |
Ondrej Zary | 5694f9c | 2011-03-01 19:18:17 +0000 | [diff] [blame] | 99 | #define CHIP_365_TRIO3D 0x13 |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 100 | |
| 101 | #define CHIP_XXX_TRIO 0x80 |
| 102 | #define CHIP_XXX_TRIO64V2_DXGX 0x81 |
| 103 | #define CHIP_XXX_VIRGE_DXGX 0x82 |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 104 | #define CHIP_36X_TRIO3D_1X_2X 0x83 |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 105 | |
| 106 | #define CHIP_UNDECIDED_FLAG 0x80 |
| 107 | #define CHIP_MASK 0xFF |
| 108 | |
| 109 | /* CRT timing register sets */ |
| 110 | |
| 111 | static const struct vga_regset s3_h_total_regs[] = {{0x00, 0, 7}, {0x5D, 0, 0}, VGA_REGSET_END}; |
| 112 | static const struct vga_regset s3_h_display_regs[] = {{0x01, 0, 7}, {0x5D, 1, 1}, VGA_REGSET_END}; |
| 113 | static const struct vga_regset s3_h_blank_start_regs[] = {{0x02, 0, 7}, {0x5D, 2, 2}, VGA_REGSET_END}; |
| 114 | static const struct vga_regset s3_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, VGA_REGSET_END}; |
| 115 | static const struct vga_regset s3_h_sync_start_regs[] = {{0x04, 0, 7}, {0x5D, 4, 4}, VGA_REGSET_END}; |
| 116 | static const struct vga_regset s3_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END}; |
| 117 | |
| 118 | static const struct vga_regset s3_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x5E, 0, 0}, VGA_REGSET_END}; |
| 119 | static const struct vga_regset s3_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x5E, 1, 1}, VGA_REGSET_END}; |
| 120 | static const struct vga_regset s3_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x5E, 2, 2}, VGA_REGSET_END}; |
| 121 | static const struct vga_regset s3_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END}; |
| 122 | static const struct vga_regset s3_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x5E, 4, 4}, VGA_REGSET_END}; |
| 123 | static const struct vga_regset s3_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END}; |
| 124 | |
| 125 | static const struct vga_regset s3_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, {0x5E, 6, 6}, VGA_REGSET_END}; |
| 126 | static const struct vga_regset s3_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x31, 4, 5}, {0x51, 0, 1}, VGA_REGSET_END}; |
| 127 | static const struct vga_regset s3_offset_regs[] = {{0x13, 0, 7}, {0x51, 4, 5}, VGA_REGSET_END}; /* set 0x43 bit 2 to 0 */ |
| 128 | |
| 129 | static const struct svga_timing_regs s3_timing_regs = { |
| 130 | s3_h_total_regs, s3_h_display_regs, s3_h_blank_start_regs, |
| 131 | s3_h_blank_end_regs, s3_h_sync_start_regs, s3_h_sync_end_regs, |
| 132 | s3_v_total_regs, s3_v_display_regs, s3_v_blank_start_regs, |
| 133 | s3_v_blank_end_regs, s3_v_sync_start_regs, s3_v_sync_end_regs, |
| 134 | }; |
| 135 | |
| 136 | |
| 137 | /* ------------------------------------------------------------------------- */ |
| 138 | |
| 139 | /* Module parameters */ |
| 140 | |
| 141 | |
Krzysztof Helt | a814054 | 2008-04-28 02:15:09 -0700 | [diff] [blame] | 142 | static char *mode_option __devinitdata = "640x480-8@60"; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 143 | |
| 144 | #ifdef CONFIG_MTRR |
Krzysztof Helt | a814054 | 2008-04-28 02:15:09 -0700 | [diff] [blame] | 145 | static int mtrr __devinitdata = 1; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 146 | #endif |
| 147 | |
| 148 | static int fasttext = 1; |
| 149 | |
| 150 | |
| 151 | MODULE_AUTHOR("(c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>"); |
| 152 | MODULE_LICENSE("GPL"); |
| 153 | MODULE_DESCRIPTION("fbdev driver for S3 Trio/Virge"); |
| 154 | |
Krzysztof Helt | a814054 | 2008-04-28 02:15:09 -0700 | [diff] [blame] | 155 | module_param(mode_option, charp, 0444); |
| 156 | MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)"); |
| 157 | module_param_named(mode, mode_option, charp, 0444); |
| 158 | MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)"); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 159 | |
| 160 | #ifdef CONFIG_MTRR |
| 161 | module_param(mtrr, int, 0444); |
| 162 | MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)"); |
| 163 | #endif |
| 164 | |
| 165 | module_param(fasttext, int, 0644); |
| 166 | MODULE_PARM_DESC(fasttext, "Enable S3 fast text mode (1=enable, 0=disable, default=1)"); |
| 167 | |
| 168 | |
| 169 | /* ------------------------------------------------------------------------- */ |
| 170 | |
| 171 | /* Set font in S3 fast text mode */ |
| 172 | |
| 173 | static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map) |
| 174 | { |
| 175 | const u8 *font = map->data; |
Antonino A. Daplas | 75814d8 | 2007-05-08 00:38:49 -0700 | [diff] [blame] | 176 | u8 __iomem *fb = (u8 __iomem *) info->screen_base; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 177 | int i, c; |
| 178 | |
| 179 | if ((map->width != 8) || (map->height != 16) || |
| 180 | (map->depth != 1) || (map->length != 256)) { |
| 181 | printk(KERN_ERR "fb%d: unsupported font parameters: width %d, height %d, depth %d, length %d\n", |
| 182 | info->node, map->width, map->height, map->depth, map->length); |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | fb += 2; |
| 187 | for (i = 0; i < map->height; i++) { |
| 188 | for (c = 0; c < map->length; c++) { |
Antonino A. Daplas | 75814d8 | 2007-05-08 00:38:49 -0700 | [diff] [blame] | 189 | fb_writeb(font[c * map->height + i], fb + c * 4); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 190 | } |
| 191 | fb += 1024; |
| 192 | } |
| 193 | } |
| 194 | |
David Miller | 55db092 | 2011-01-11 23:52:11 +0000 | [diff] [blame] | 195 | static void s3fb_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor) |
| 196 | { |
| 197 | struct s3fb_info *par = info->par; |
| 198 | |
| 199 | svga_tilecursor(par->state.vgabase, info, cursor); |
| 200 | } |
| 201 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 202 | static struct fb_tile_ops s3fb_tile_ops = { |
| 203 | .fb_settile = svga_settile, |
| 204 | .fb_tilecopy = svga_tilecopy, |
| 205 | .fb_tilefill = svga_tilefill, |
| 206 | .fb_tileblit = svga_tileblit, |
David Miller | 55db092 | 2011-01-11 23:52:11 +0000 | [diff] [blame] | 207 | .fb_tilecursor = s3fb_tilecursor, |
Ondrej Zajicek | 34ed25f | 2007-05-08 00:40:00 -0700 | [diff] [blame] | 208 | .fb_get_tilemax = svga_get_tilemax, |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | static struct fb_tile_ops s3fb_fast_tile_ops = { |
| 212 | .fb_settile = s3fb_settile_fast, |
| 213 | .fb_tilecopy = svga_tilecopy, |
| 214 | .fb_tilefill = svga_tilefill, |
| 215 | .fb_tileblit = svga_tileblit, |
David Miller | 55db092 | 2011-01-11 23:52:11 +0000 | [diff] [blame] | 216 | .fb_tilecursor = s3fb_tilecursor, |
Ondrej Zajicek | 34ed25f | 2007-05-08 00:40:00 -0700 | [diff] [blame] | 217 | .fb_get_tilemax = svga_get_tilemax, |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | |
| 221 | /* ------------------------------------------------------------------------- */ |
| 222 | |
| 223 | /* image data is MSB-first, fb structure is MSB-first too */ |
| 224 | static inline u32 expand_color(u32 c) |
| 225 | { |
| 226 | return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF; |
| 227 | } |
| 228 | |
| 229 | /* s3fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */ |
| 230 | static void s3fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image) |
| 231 | { |
| 232 | u32 fg = expand_color(image->fg_color); |
| 233 | u32 bg = expand_color(image->bg_color); |
| 234 | const u8 *src1, *src; |
| 235 | u8 __iomem *dst1; |
| 236 | u32 __iomem *dst; |
| 237 | u32 val; |
| 238 | int x, y; |
| 239 | |
| 240 | src1 = image->data; |
| 241 | dst1 = info->screen_base + (image->dy * info->fix.line_length) |
| 242 | + ((image->dx / 8) * 4); |
| 243 | |
| 244 | for (y = 0; y < image->height; y++) { |
| 245 | src = src1; |
| 246 | dst = (u32 __iomem *) dst1; |
| 247 | for (x = 0; x < image->width; x += 8) { |
| 248 | val = *(src++) * 0x01010101; |
| 249 | val = (val & fg) | (~val & bg); |
| 250 | fb_writel(val, dst++); |
| 251 | } |
| 252 | src1 += image->width / 8; |
| 253 | dst1 += info->fix.line_length; |
| 254 | } |
| 255 | |
| 256 | } |
| 257 | |
| 258 | /* s3fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */ |
| 259 | static void s3fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect) |
| 260 | { |
| 261 | u32 fg = expand_color(rect->color); |
| 262 | u8 __iomem *dst1; |
| 263 | u32 __iomem *dst; |
| 264 | int x, y; |
| 265 | |
| 266 | dst1 = info->screen_base + (rect->dy * info->fix.line_length) |
| 267 | + ((rect->dx / 8) * 4); |
| 268 | |
| 269 | for (y = 0; y < rect->height; y++) { |
| 270 | dst = (u32 __iomem *) dst1; |
| 271 | for (x = 0; x < rect->width; x += 8) { |
| 272 | fb_writel(fg, dst++); |
| 273 | } |
| 274 | dst1 += info->fix.line_length; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | |
| 279 | /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */ |
| 280 | static inline u32 expand_pixel(u32 c) |
| 281 | { |
| 282 | return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) | |
| 283 | ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF; |
| 284 | } |
| 285 | |
| 286 | /* s3fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */ |
| 287 | static void s3fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image) |
| 288 | { |
| 289 | u32 fg = image->fg_color * 0x11111111; |
| 290 | u32 bg = image->bg_color * 0x11111111; |
| 291 | const u8 *src1, *src; |
| 292 | u8 __iomem *dst1; |
| 293 | u32 __iomem *dst; |
| 294 | u32 val; |
| 295 | int x, y; |
| 296 | |
| 297 | src1 = image->data; |
| 298 | dst1 = info->screen_base + (image->dy * info->fix.line_length) |
| 299 | + ((image->dx / 8) * 4); |
| 300 | |
| 301 | for (y = 0; y < image->height; y++) { |
| 302 | src = src1; |
| 303 | dst = (u32 __iomem *) dst1; |
| 304 | for (x = 0; x < image->width; x += 8) { |
| 305 | val = expand_pixel(*(src++)); |
| 306 | val = (val & fg) | (~val & bg); |
| 307 | fb_writel(val, dst++); |
| 308 | } |
| 309 | src1 += image->width / 8; |
| 310 | dst1 += info->fix.line_length; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | static void s3fb_imageblit(struct fb_info *info, const struct fb_image *image) |
| 315 | { |
| 316 | if ((info->var.bits_per_pixel == 4) && (image->depth == 1) |
| 317 | && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) { |
| 318 | if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES) |
| 319 | s3fb_iplan_imageblit(info, image); |
| 320 | else |
| 321 | s3fb_cfb4_imageblit(info, image); |
| 322 | } else |
| 323 | cfb_imageblit(info, image); |
| 324 | } |
| 325 | |
| 326 | static void s3fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) |
| 327 | { |
| 328 | if ((info->var.bits_per_pixel == 4) |
| 329 | && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0) |
| 330 | && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)) |
| 331 | s3fb_iplan_fillrect(info, rect); |
| 332 | else |
| 333 | cfb_fillrect(info, rect); |
| 334 | } |
| 335 | |
| 336 | |
| 337 | |
| 338 | /* ------------------------------------------------------------------------- */ |
| 339 | |
| 340 | |
| 341 | static void s3_set_pixclock(struct fb_info *info, u32 pixclock) |
| 342 | { |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 343 | struct s3fb_info *par = info->par; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 344 | u16 m, n, r; |
| 345 | u8 regval; |
Ondrej Zajicek | 249bdbb | 2007-05-08 00:39:24 -0700 | [diff] [blame] | 346 | int rv; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 347 | |
Ondrej Zary | 5694f9c | 2011-03-01 19:18:17 +0000 | [diff] [blame] | 348 | rv = svga_compute_pll((par->chip == CHIP_365_TRIO3D) ? &s3_trio3d_pll : &s3_pll, |
| 349 | 1000000000 / pixclock, &m, &n, &r, info->node); |
Ondrej Zajicek | 249bdbb | 2007-05-08 00:39:24 -0700 | [diff] [blame] | 350 | if (rv < 0) { |
| 351 | printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node); |
| 352 | return; |
| 353 | } |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 354 | |
| 355 | /* Set VGA misc register */ |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 356 | regval = vga_r(par->state.vgabase, VGA_MIS_R); |
| 357 | vga_w(par->state.vgabase, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 358 | |
| 359 | /* Set S3 clock registers */ |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 360 | if (par->chip == CHIP_360_TRIO3D_1X || |
| 361 | par->chip == CHIP_362_TRIO3D_2X || |
| 362 | par->chip == CHIP_368_TRIO3D_2X) { |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 363 | vga_wseq(par->state.vgabase, 0x12, (n - 2) | ((r & 3) << 6)); /* n and two bits of r */ |
| 364 | vga_wseq(par->state.vgabase, 0x29, r >> 2); /* remaining highest bit of r */ |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 365 | } else |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 366 | vga_wseq(par->state.vgabase, 0x12, (n - 2) | (r << 5)); |
| 367 | vga_wseq(par->state.vgabase, 0x13, m - 2); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 368 | |
| 369 | udelay(1000); |
| 370 | |
| 371 | /* Activate clock - write 0, 1, 0 to seq/15 bit 5 */ |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 372 | regval = vga_rseq (par->state.vgabase, 0x15); /* | 0x80; */ |
| 373 | vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5)); |
| 374 | vga_wseq(par->state.vgabase, 0x15, regval | (1<<5)); |
| 375 | vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5)); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | |
| 379 | /* Open framebuffer */ |
| 380 | |
| 381 | static int s3fb_open(struct fb_info *info, int user) |
| 382 | { |
| 383 | struct s3fb_info *par = info->par; |
| 384 | |
| 385 | mutex_lock(&(par->open_lock)); |
| 386 | if (par->ref_count == 0) { |
David Miller | 3ff259f | 2011-01-11 23:53:53 +0000 | [diff] [blame] | 387 | void __iomem *vgabase = par->state.vgabase; |
| 388 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 389 | memset(&(par->state), 0, sizeof(struct vgastate)); |
David Miller | 3ff259f | 2011-01-11 23:53:53 +0000 | [diff] [blame] | 390 | par->state.vgabase = vgabase; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 391 | par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP; |
| 392 | par->state.num_crtc = 0x70; |
| 393 | par->state.num_seq = 0x20; |
| 394 | save_vga(&(par->state)); |
| 395 | } |
| 396 | |
| 397 | par->ref_count++; |
| 398 | mutex_unlock(&(par->open_lock)); |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | /* Close framebuffer */ |
| 404 | |
| 405 | static int s3fb_release(struct fb_info *info, int user) |
| 406 | { |
| 407 | struct s3fb_info *par = info->par; |
| 408 | |
| 409 | mutex_lock(&(par->open_lock)); |
| 410 | if (par->ref_count == 0) { |
| 411 | mutex_unlock(&(par->open_lock)); |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | |
| 415 | if (par->ref_count == 1) |
| 416 | restore_vga(&(par->state)); |
| 417 | |
| 418 | par->ref_count--; |
| 419 | mutex_unlock(&(par->open_lock)); |
| 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | /* Validate passed in var */ |
| 425 | |
| 426 | static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
| 427 | { |
| 428 | struct s3fb_info *par = info->par; |
| 429 | int rv, mem, step; |
Krzysztof Helt | c3ca34f | 2007-10-16 01:29:54 -0700 | [diff] [blame] | 430 | u16 m, n, r; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 431 | |
| 432 | /* Find appropriate format */ |
| 433 | rv = svga_match_format (s3fb_formats, var, NULL); |
Ondrej Zajicek | d4b766a0 | 2007-10-16 01:29:52 -0700 | [diff] [blame] | 434 | |
| 435 | /* 32bpp mode is not supported on VIRGE VX, |
| 436 | 24bpp is not supported on others */ |
| 437 | if ((par->chip == CHIP_988_VIRGE_VX) ? (rv == 7) : (rv == 6)) |
| 438 | rv = -EINVAL; |
| 439 | |
| 440 | if (rv < 0) { |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 441 | printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node); |
| 442 | return rv; |
| 443 | } |
| 444 | |
| 445 | /* Do not allow to have real resoulution larger than virtual */ |
| 446 | if (var->xres > var->xres_virtual) |
| 447 | var->xres_virtual = var->xres; |
| 448 | |
| 449 | if (var->yres > var->yres_virtual) |
| 450 | var->yres_virtual = var->yres; |
| 451 | |
| 452 | /* Round up xres_virtual to have proper alignment of lines */ |
| 453 | step = s3fb_formats[rv].xresstep - 1; |
| 454 | var->xres_virtual = (var->xres_virtual+step) & ~step; |
| 455 | |
| 456 | /* Check whether have enough memory */ |
| 457 | mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual; |
Krzysztof Helt | c3ca34f | 2007-10-16 01:29:54 -0700 | [diff] [blame] | 458 | if (mem > info->screen_size) { |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 459 | printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n", |
| 460 | info->node, mem >> 10, (unsigned int) (info->screen_size >> 10)); |
| 461 | return -EINVAL; |
| 462 | } |
| 463 | |
| 464 | rv = svga_check_timings (&s3_timing_regs, var, info->node); |
Krzysztof Helt | c3ca34f | 2007-10-16 01:29:54 -0700 | [diff] [blame] | 465 | if (rv < 0) { |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 466 | printk(KERN_ERR "fb%d: invalid timings requested\n", info->node); |
| 467 | return rv; |
| 468 | } |
| 469 | |
Krzysztof Helt | c3ca34f | 2007-10-16 01:29:54 -0700 | [diff] [blame] | 470 | rv = svga_compute_pll(&s3_pll, PICOS2KHZ(var->pixclock), &m, &n, &r, |
| 471 | info->node); |
| 472 | if (rv < 0) { |
| 473 | printk(KERN_ERR "fb%d: invalid pixclock value requested\n", |
| 474 | info->node); |
| 475 | return rv; |
| 476 | } |
| 477 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | /* Set video mode from par */ |
| 482 | |
| 483 | static int s3fb_set_par(struct fb_info *info) |
| 484 | { |
| 485 | struct s3fb_info *par = info->par; |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 486 | u32 value, mode, hmul, offset_value, screen_size, multiplex, dbytes; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 487 | u32 bpp = info->var.bits_per_pixel; |
| 488 | |
| 489 | if (bpp != 0) { |
| 490 | info->fix.ypanstep = 1; |
| 491 | info->fix.line_length = (info->var.xres_virtual * bpp) / 8; |
| 492 | |
| 493 | info->flags &= ~FBINFO_MISC_TILEBLITTING; |
| 494 | info->tileops = NULL; |
| 495 | |
Ondrej Zajicek | 34ed25f | 2007-05-08 00:40:00 -0700 | [diff] [blame] | 496 | /* in 4bpp supports 8p wide tiles only, any tiles otherwise */ |
| 497 | info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0); |
Antonino A. Daplas | 8db5166 | 2007-05-08 00:39:14 -0700 | [diff] [blame] | 498 | info->pixmap.blit_y = ~(u32)0; |
Ondrej Zajicek | 34ed25f | 2007-05-08 00:40:00 -0700 | [diff] [blame] | 499 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 500 | offset_value = (info->var.xres_virtual * bpp) / 64; |
| 501 | screen_size = info->var.yres_virtual * info->fix.line_length; |
| 502 | } else { |
| 503 | info->fix.ypanstep = 16; |
| 504 | info->fix.line_length = 0; |
| 505 | |
| 506 | info->flags |= FBINFO_MISC_TILEBLITTING; |
| 507 | info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops; |
Ondrej Zajicek | 34ed25f | 2007-05-08 00:40:00 -0700 | [diff] [blame] | 508 | |
Antonino A. Daplas | 8db5166 | 2007-05-08 00:39:14 -0700 | [diff] [blame] | 509 | /* supports 8x16 tiles only */ |
| 510 | info->pixmap.blit_x = 1 << (8 - 1); |
| 511 | info->pixmap.blit_y = 1 << (16 - 1); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 512 | |
| 513 | offset_value = info->var.xres_virtual / 16; |
| 514 | screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64; |
| 515 | } |
| 516 | |
| 517 | info->var.xoffset = 0; |
| 518 | info->var.yoffset = 0; |
| 519 | info->var.activate = FB_ACTIVATE_NOW; |
| 520 | |
| 521 | /* Unlock registers */ |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 522 | vga_wcrt(par->state.vgabase, 0x38, 0x48); |
| 523 | vga_wcrt(par->state.vgabase, 0x39, 0xA5); |
| 524 | vga_wseq(par->state.vgabase, 0x08, 0x06); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 525 | svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 526 | |
| 527 | /* Blank screen and turn off sync */ |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 528 | svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 529 | svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 530 | |
| 531 | /* Set default values */ |
David Miller | e2fade2 | 2011-01-11 23:50:04 +0000 | [diff] [blame] | 532 | svga_set_default_gfx_regs(par->state.vgabase); |
David Miller | f51a14d | 2011-01-11 23:50:36 +0000 | [diff] [blame] | 533 | svga_set_default_atc_regs(par->state.vgabase); |
David Miller | a4ade839 | 2011-01-11 23:50:54 +0000 | [diff] [blame] | 534 | svga_set_default_seq_regs(par->state.vgabase); |
David Miller | 1d28fca | 2011-01-11 23:51:41 +0000 | [diff] [blame] | 535 | svga_set_default_crt_regs(par->state.vgabase); |
David Miller | 21da386 | 2011-01-11 23:49:34 +0000 | [diff] [blame] | 536 | svga_wcrt_multi(par->state.vgabase, s3_line_compare_regs, 0xFFFFFFFF); |
| 537 | svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, 0); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 538 | |
| 539 | /* S3 specific initialization */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 540 | svga_wcrt_mask(par->state.vgabase, 0x58, 0x10, 0x10); /* enable linear framebuffer */ |
| 541 | svga_wcrt_mask(par->state.vgabase, 0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */ |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 542 | |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 543 | /* svga_wcrt_mask(par->state.vgabase, 0x33, 0x08, 0x08); */ /* DDR ? */ |
| 544 | /* svga_wcrt_mask(par->state.vgabase, 0x43, 0x01, 0x01); */ /* DDR ? */ |
| 545 | svga_wcrt_mask(par->state.vgabase, 0x33, 0x00, 0x08); /* no DDR ? */ |
| 546 | svga_wcrt_mask(par->state.vgabase, 0x43, 0x00, 0x01); /* no DDR ? */ |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 547 | |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 548 | svga_wcrt_mask(par->state.vgabase, 0x5D, 0x00, 0x28); /* Clear strange HSlen bits */ |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 549 | |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 550 | /* svga_wcrt_mask(par->state.vgabase, 0x58, 0x03, 0x03); */ |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 551 | |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 552 | /* svga_wcrt_mask(par->state.vgabase, 0x53, 0x12, 0x13); */ /* enable MMIO */ |
| 553 | /* svga_wcrt_mask(par->state.vgabase, 0x40, 0x08, 0x08); */ /* enable write buffer */ |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 554 | |
| 555 | |
| 556 | /* Set the offset register */ |
| 557 | pr_debug("fb%d: offset register : %d\n", info->node, offset_value); |
David Miller | 21da386 | 2011-01-11 23:49:34 +0000 | [diff] [blame] | 558 | svga_wcrt_multi(par->state.vgabase, s3_offset_regs, offset_value); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 559 | |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 560 | if (par->chip != CHIP_360_TRIO3D_1X && |
| 561 | par->chip != CHIP_362_TRIO3D_2X && |
| 562 | par->chip != CHIP_368_TRIO3D_2X) { |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 563 | vga_wcrt(par->state.vgabase, 0x54, 0x18); /* M parameter */ |
| 564 | vga_wcrt(par->state.vgabase, 0x60, 0xff); /* N parameter */ |
| 565 | vga_wcrt(par->state.vgabase, 0x61, 0xff); /* L parameter */ |
| 566 | vga_wcrt(par->state.vgabase, 0x62, 0xff); /* L parameter */ |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 567 | } |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 568 | |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 569 | vga_wcrt(par->state.vgabase, 0x3A, 0x35); |
David Miller | f6b0cc4 | 2011-01-11 23:49:18 +0000 | [diff] [blame] | 570 | svga_wattr(par->state.vgabase, 0x33, 0x00); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 571 | |
| 572 | if (info->var.vmode & FB_VMODE_DOUBLE) |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 573 | svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 574 | else |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 575 | svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 576 | |
| 577 | if (info->var.vmode & FB_VMODE_INTERLACED) |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 578 | svga_wcrt_mask(par->state.vgabase, 0x42, 0x20, 0x20); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 579 | else |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 580 | svga_wcrt_mask(par->state.vgabase, 0x42, 0x00, 0x20); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 581 | |
| 582 | /* Disable hardware graphics cursor */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 583 | svga_wcrt_mask(par->state.vgabase, 0x45, 0x00, 0x01); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 584 | /* Disable Streams engine */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 585 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0x0C); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 586 | |
| 587 | mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix)); |
| 588 | |
| 589 | /* S3 virge DX hack */ |
| 590 | if (par->chip == CHIP_375_VIRGE_DX) { |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 591 | vga_wcrt(par->state.vgabase, 0x86, 0x80); |
| 592 | vga_wcrt(par->state.vgabase, 0x90, 0x00); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | /* S3 virge VX hack */ |
| 596 | if (par->chip == CHIP_988_VIRGE_VX) { |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 597 | vga_wcrt(par->state.vgabase, 0x50, 0x00); |
| 598 | vga_wcrt(par->state.vgabase, 0x67, 0x50); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 599 | |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 600 | vga_wcrt(par->state.vgabase, 0x63, (mode <= 2) ? 0x90 : 0x09); |
| 601 | vga_wcrt(par->state.vgabase, 0x66, 0x90); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 602 | } |
| 603 | |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 604 | if (par->chip == CHIP_360_TRIO3D_1X || |
| 605 | par->chip == CHIP_362_TRIO3D_2X || |
Ondrej Zary | 5694f9c | 2011-03-01 19:18:17 +0000 | [diff] [blame] | 606 | par->chip == CHIP_368_TRIO3D_2X || |
| 607 | par->chip == CHIP_365_TRIO3D) { |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 608 | dbytes = info->var.xres * ((bpp+7)/8); |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 609 | vga_wcrt(par->state.vgabase, 0x91, (dbytes + 7) / 8); |
| 610 | vga_wcrt(par->state.vgabase, 0x90, (((dbytes + 7) / 8) >> 8) | 0x80); |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 611 | |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 612 | vga_wcrt(par->state.vgabase, 0x66, 0x81); |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 613 | } |
| 614 | |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 615 | svga_wcrt_mask(par->state.vgabase, 0x31, 0x00, 0x40); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 616 | multiplex = 0; |
| 617 | hmul = 1; |
| 618 | |
| 619 | /* Set mode-specific register values */ |
| 620 | switch (mode) { |
| 621 | case 0: |
| 622 | pr_debug("fb%d: text mode\n", info->node); |
David Miller | 9c96394 | 2011-01-11 23:51:56 +0000 | [diff] [blame] | 623 | svga_set_textmode_vga_regs(par->state.vgabase); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 624 | |
| 625 | /* Set additional registers like in 8-bit mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 626 | svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30); |
| 627 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 628 | |
| 629 | /* Disable enhanced mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 630 | svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 631 | |
| 632 | if (fasttext) { |
| 633 | pr_debug("fb%d: high speed text mode set\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 634 | svga_wcrt_mask(par->state.vgabase, 0x31, 0x40, 0x40); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 635 | } |
| 636 | break; |
| 637 | case 1: |
| 638 | pr_debug("fb%d: 4 bit pseudocolor\n", info->node); |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 639 | vga_wgfx(par->state.vgabase, VGA_GFX_MODE, 0x40); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 640 | |
| 641 | /* Set additional registers like in 8-bit mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 642 | svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30); |
| 643 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 644 | |
| 645 | /* disable enhanced mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 646 | svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 647 | break; |
| 648 | case 2: |
| 649 | pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node); |
| 650 | |
| 651 | /* Set additional registers like in 8-bit mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 652 | svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30); |
| 653 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 654 | |
| 655 | /* disable enhanced mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 656 | svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 657 | break; |
| 658 | case 3: |
| 659 | pr_debug("fb%d: 8 bit pseudocolor\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 660 | svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30); |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 661 | if (info->var.pixclock > 20000 || |
| 662 | par->chip == CHIP_360_TRIO3D_1X || |
| 663 | par->chip == CHIP_362_TRIO3D_2X || |
| 664 | par->chip == CHIP_368_TRIO3D_2X) |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 665 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0); |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 666 | else { |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 667 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x10, 0xF0); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 668 | multiplex = 1; |
| 669 | } |
| 670 | break; |
| 671 | case 4: |
| 672 | pr_debug("fb%d: 5/5/5 truecolor\n", info->node); |
| 673 | if (par->chip == CHIP_988_VIRGE_VX) { |
| 674 | if (info->var.pixclock > 20000) |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 675 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 676 | else |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 677 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0); |
Ondrej Zary | 3827d10 | 2011-03-01 19:18:27 +0000 | [diff] [blame^] | 678 | } else if (par->chip == CHIP_365_TRIO3D) { |
| 679 | svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30); |
| 680 | if (info->var.pixclock > 8695) { |
| 681 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0); |
| 682 | hmul = 2; |
| 683 | } else { |
| 684 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0); |
| 685 | multiplex = 1; |
| 686 | } |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 687 | } else { |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 688 | svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30); |
| 689 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0); |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 690 | if (par->chip != CHIP_360_TRIO3D_1X && |
| 691 | par->chip != CHIP_362_TRIO3D_2X && |
| 692 | par->chip != CHIP_368_TRIO3D_2X) |
| 693 | hmul = 2; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 694 | } |
| 695 | break; |
| 696 | case 5: |
| 697 | pr_debug("fb%d: 5/6/5 truecolor\n", info->node); |
| 698 | if (par->chip == CHIP_988_VIRGE_VX) { |
| 699 | if (info->var.pixclock > 20000) |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 700 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 701 | else |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 702 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0); |
Ondrej Zary | 3827d10 | 2011-03-01 19:18:27 +0000 | [diff] [blame^] | 703 | } else if (par->chip == CHIP_365_TRIO3D) { |
| 704 | svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30); |
| 705 | if (info->var.pixclock > 8695) { |
| 706 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0); |
| 707 | hmul = 2; |
| 708 | } else { |
| 709 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0); |
| 710 | multiplex = 1; |
| 711 | } |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 712 | } else { |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 713 | svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30); |
| 714 | svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0); |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 715 | if (par->chip != CHIP_360_TRIO3D_1X && |
| 716 | par->chip != CHIP_362_TRIO3D_2X && |
| 717 | par->chip != CHIP_368_TRIO3D_2X) |
| 718 | hmul = 2; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 719 | } |
| 720 | break; |
| 721 | case 6: |
| 722 | /* VIRGE VX case */ |
| 723 | pr_debug("fb%d: 8/8/8 truecolor\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 724 | svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 725 | break; |
| 726 | case 7: |
| 727 | pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 728 | svga_wcrt_mask(par->state.vgabase, 0x50, 0x30, 0x30); |
| 729 | svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 730 | break; |
| 731 | default: |
| 732 | printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node); |
| 733 | return -EINVAL; |
| 734 | } |
| 735 | |
| 736 | if (par->chip != CHIP_988_VIRGE_VX) { |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 737 | svga_wseq_mask(par->state.vgabase, 0x15, multiplex ? 0x10 : 0x00, 0x10); |
| 738 | svga_wseq_mask(par->state.vgabase, 0x18, multiplex ? 0x80 : 0x00, 0x80); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | s3_set_pixclock(info, info->var.pixclock); |
David Miller | 38d2620 | 2011-01-11 23:52:25 +0000 | [diff] [blame] | 742 | svga_set_timings(par->state.vgabase, &s3_timing_regs, &(info->var), hmul, 1, |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 743 | (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1, |
| 744 | (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1, |
| 745 | hmul, info->node); |
| 746 | |
| 747 | /* Set interlaced mode start/end register */ |
| 748 | value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len; |
| 749 | value = ((value * hmul) / 8) - 5; |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 750 | vga_wcrt(par->state.vgabase, 0x3C, (value + 1) / 2); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 751 | |
Antonino A. Daplas | 75814d8 | 2007-05-08 00:38:49 -0700 | [diff] [blame] | 752 | memset_io(info->screen_base, 0x00, screen_size); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 753 | /* Device and screen back on */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 754 | svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80); |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 755 | svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 756 | |
| 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | /* Set a colour register */ |
| 761 | |
| 762 | static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, |
| 763 | u_int transp, struct fb_info *fb) |
| 764 | { |
| 765 | switch (fb->var.bits_per_pixel) { |
| 766 | case 0: |
| 767 | case 4: |
| 768 | if (regno >= 16) |
| 769 | return -EINVAL; |
| 770 | |
| 771 | if ((fb->var.bits_per_pixel == 4) && |
| 772 | (fb->var.nonstd == 0)) { |
| 773 | outb(0xF0, VGA_PEL_MSK); |
| 774 | outb(regno*16, VGA_PEL_IW); |
| 775 | } else { |
| 776 | outb(0x0F, VGA_PEL_MSK); |
| 777 | outb(regno, VGA_PEL_IW); |
| 778 | } |
| 779 | outb(red >> 10, VGA_PEL_D); |
| 780 | outb(green >> 10, VGA_PEL_D); |
| 781 | outb(blue >> 10, VGA_PEL_D); |
| 782 | break; |
| 783 | case 8: |
| 784 | if (regno >= 256) |
| 785 | return -EINVAL; |
| 786 | |
| 787 | outb(0xFF, VGA_PEL_MSK); |
| 788 | outb(regno, VGA_PEL_IW); |
| 789 | outb(red >> 10, VGA_PEL_D); |
| 790 | outb(green >> 10, VGA_PEL_D); |
| 791 | outb(blue >> 10, VGA_PEL_D); |
| 792 | break; |
| 793 | case 16: |
| 794 | if (regno >= 16) |
Ondrej Zajicek | 249bdbb | 2007-05-08 00:39:24 -0700 | [diff] [blame] | 795 | return 0; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 796 | |
| 797 | if (fb->var.green.length == 5) |
| 798 | ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) | |
| 799 | ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11); |
| 800 | else if (fb->var.green.length == 6) |
| 801 | ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) | |
| 802 | ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11); |
| 803 | else return -EINVAL; |
| 804 | break; |
| 805 | case 24: |
| 806 | case 32: |
| 807 | if (regno >= 16) |
Ondrej Zajicek | 249bdbb | 2007-05-08 00:39:24 -0700 | [diff] [blame] | 808 | return 0; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 809 | |
Ondrej Zajicek | 249bdbb | 2007-05-08 00:39:24 -0700 | [diff] [blame] | 810 | ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 811 | (green & 0xFF00) | ((blue & 0xFF00) >> 8); |
| 812 | break; |
| 813 | default: |
| 814 | return -EINVAL; |
| 815 | } |
| 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | |
| 821 | /* Set the display blanking state */ |
| 822 | |
| 823 | static int s3fb_blank(int blank_mode, struct fb_info *info) |
| 824 | { |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 825 | struct s3fb_info *par = info->par; |
| 826 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 827 | switch (blank_mode) { |
| 828 | case FB_BLANK_UNBLANK: |
| 829 | pr_debug("fb%d: unblank\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 830 | svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06); |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 831 | svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 832 | break; |
| 833 | case FB_BLANK_NORMAL: |
| 834 | pr_debug("fb%d: blank\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 835 | svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06); |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 836 | svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 837 | break; |
| 838 | case FB_BLANK_HSYNC_SUSPEND: |
| 839 | pr_debug("fb%d: hsync\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 840 | svga_wcrt_mask(par->state.vgabase, 0x56, 0x02, 0x06); |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 841 | svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 842 | break; |
| 843 | case FB_BLANK_VSYNC_SUSPEND: |
| 844 | pr_debug("fb%d: vsync\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 845 | svga_wcrt_mask(par->state.vgabase, 0x56, 0x04, 0x06); |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 846 | svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 847 | break; |
| 848 | case FB_BLANK_POWERDOWN: |
| 849 | pr_debug("fb%d: sync down\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 850 | svga_wcrt_mask(par->state.vgabase, 0x56, 0x06, 0x06); |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 851 | svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 852 | break; |
| 853 | } |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | |
| 858 | |
| 859 | /* Pan the display */ |
| 860 | |
David Miller | 21da386 | 2011-01-11 23:49:34 +0000 | [diff] [blame] | 861 | static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) |
| 862 | { |
| 863 | struct s3fb_info *par = info->par; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 864 | unsigned int offset; |
| 865 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 866 | /* Calculate the offset */ |
| 867 | if (var->bits_per_pixel == 0) { |
| 868 | offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2); |
| 869 | offset = offset >> 2; |
| 870 | } else { |
| 871 | offset = (var->yoffset * info->fix.line_length) + |
| 872 | (var->xoffset * var->bits_per_pixel / 8); |
| 873 | offset = offset >> 2; |
| 874 | } |
| 875 | |
| 876 | /* Set the offset */ |
David Miller | 21da386 | 2011-01-11 23:49:34 +0000 | [diff] [blame] | 877 | svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, offset); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 878 | |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | /* ------------------------------------------------------------------------- */ |
| 883 | |
| 884 | /* Frame buffer operations */ |
| 885 | |
| 886 | static struct fb_ops s3fb_ops = { |
| 887 | .owner = THIS_MODULE, |
| 888 | .fb_open = s3fb_open, |
| 889 | .fb_release = s3fb_release, |
| 890 | .fb_check_var = s3fb_check_var, |
| 891 | .fb_set_par = s3fb_set_par, |
| 892 | .fb_setcolreg = s3fb_setcolreg, |
| 893 | .fb_blank = s3fb_blank, |
| 894 | .fb_pan_display = s3fb_pan_display, |
| 895 | .fb_fillrect = s3fb_fillrect, |
| 896 | .fb_copyarea = cfb_copyarea, |
| 897 | .fb_imageblit = s3fb_imageblit, |
Antonino A. Daplas | 5a87ede | 2007-05-09 02:35:32 -0700 | [diff] [blame] | 898 | .fb_get_caps = svga_get_caps, |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 899 | }; |
| 900 | |
| 901 | /* ------------------------------------------------------------------------- */ |
| 902 | |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 903 | static int __devinit s3_identification(struct s3fb_info *par) |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 904 | { |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 905 | int chip = par->chip; |
| 906 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 907 | if (chip == CHIP_XXX_TRIO) { |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 908 | u8 cr30 = vga_rcrt(par->state.vgabase, 0x30); |
| 909 | u8 cr2e = vga_rcrt(par->state.vgabase, 0x2e); |
| 910 | u8 cr2f = vga_rcrt(par->state.vgabase, 0x2f); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 911 | |
| 912 | if ((cr30 == 0xE0) || (cr30 == 0xE1)) { |
| 913 | if (cr2e == 0x10) |
| 914 | return CHIP_732_TRIO32; |
| 915 | if (cr2e == 0x11) { |
| 916 | if (! (cr2f & 0x40)) |
| 917 | return CHIP_764_TRIO64; |
| 918 | else |
| 919 | return CHIP_765_TRIO64VP; |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | if (chip == CHIP_XXX_TRIO64V2_DXGX) { |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 925 | u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 926 | |
| 927 | if (! (cr6f & 0x01)) |
| 928 | return CHIP_775_TRIO64V2_DX; |
| 929 | else |
| 930 | return CHIP_785_TRIO64V2_GX; |
| 931 | } |
| 932 | |
| 933 | if (chip == CHIP_XXX_VIRGE_DXGX) { |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 934 | u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 935 | |
| 936 | if (! (cr6f & 0x01)) |
| 937 | return CHIP_375_VIRGE_DX; |
| 938 | else |
| 939 | return CHIP_385_VIRGE_GX; |
| 940 | } |
| 941 | |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 942 | if (chip == CHIP_36X_TRIO3D_1X_2X) { |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 943 | switch (vga_rcrt(par->state.vgabase, 0x2f)) { |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 944 | case 0x00: |
| 945 | return CHIP_360_TRIO3D_1X; |
| 946 | case 0x01: |
| 947 | return CHIP_362_TRIO3D_2X; |
| 948 | case 0x02: |
| 949 | return CHIP_368_TRIO3D_2X; |
| 950 | } |
| 951 | } |
| 952 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 953 | return CHIP_UNKNOWN; |
| 954 | } |
| 955 | |
| 956 | |
| 957 | /* PCI probe */ |
| 958 | |
| 959 | static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) |
| 960 | { |
David Miller | 94c322c | 2011-01-11 23:54:21 +0000 | [diff] [blame] | 961 | struct pci_bus_region bus_reg; |
| 962 | struct resource vga_res; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 963 | struct fb_info *info; |
| 964 | struct s3fb_info *par; |
| 965 | int rc; |
| 966 | u8 regval, cr38, cr39; |
| 967 | |
| 968 | /* Ignore secondary VGA device because there is no VGA arbitration */ |
| 969 | if (! svga_primary_device(dev)) { |
| 970 | dev_info(&(dev->dev), "ignoring secondary device\n"); |
| 971 | return -ENODEV; |
| 972 | } |
| 973 | |
| 974 | /* Allocate and fill driver data structure */ |
Ondrej Zajicek | 20e061f | 2008-04-28 02:15:18 -0700 | [diff] [blame] | 975 | info = framebuffer_alloc(sizeof(struct s3fb_info), &(dev->dev)); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 976 | if (!info) { |
| 977 | dev_err(&(dev->dev), "cannot allocate memory\n"); |
| 978 | return -ENOMEM; |
| 979 | } |
| 980 | |
| 981 | par = info->par; |
| 982 | mutex_init(&par->open_lock); |
| 983 | |
| 984 | info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN; |
| 985 | info->fbops = &s3fb_ops; |
| 986 | |
| 987 | /* Prepare PCI device */ |
| 988 | rc = pci_enable_device(dev); |
| 989 | if (rc < 0) { |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 990 | dev_err(info->device, "cannot enable PCI device\n"); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 991 | goto err_enable_device; |
| 992 | } |
| 993 | |
| 994 | rc = pci_request_regions(dev, "s3fb"); |
| 995 | if (rc < 0) { |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 996 | dev_err(info->device, "cannot reserve framebuffer region\n"); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 997 | goto err_request_regions; |
| 998 | } |
| 999 | |
| 1000 | |
| 1001 | info->fix.smem_start = pci_resource_start(dev, 0); |
| 1002 | info->fix.smem_len = pci_resource_len(dev, 0); |
| 1003 | |
| 1004 | /* Map physical IO memory address into kernel space */ |
| 1005 | info->screen_base = pci_iomap(dev, 0, 0); |
| 1006 | if (! info->screen_base) { |
| 1007 | rc = -ENOMEM; |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1008 | dev_err(info->device, "iomap for framebuffer failed\n"); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1009 | goto err_iomap; |
| 1010 | } |
| 1011 | |
David Miller | 94c322c | 2011-01-11 23:54:21 +0000 | [diff] [blame] | 1012 | bus_reg.start = 0; |
| 1013 | bus_reg.end = 64 * 1024; |
| 1014 | |
| 1015 | vga_res.flags = IORESOURCE_IO; |
| 1016 | |
| 1017 | pcibios_bus_to_resource(dev, &vga_res, &bus_reg); |
| 1018 | |
| 1019 | par->state.vgabase = (void __iomem *) vga_res.start; |
| 1020 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1021 | /* Unlock regs */ |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 1022 | cr38 = vga_rcrt(par->state.vgabase, 0x38); |
| 1023 | cr39 = vga_rcrt(par->state.vgabase, 0x39); |
| 1024 | vga_wseq(par->state.vgabase, 0x08, 0x06); |
| 1025 | vga_wcrt(par->state.vgabase, 0x38, 0x48); |
| 1026 | vga_wcrt(par->state.vgabase, 0x39, 0xA5); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1027 | |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 1028 | /* Identify chip type */ |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1029 | par->chip = id->driver_data & CHIP_MASK; |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 1030 | par->rev = vga_rcrt(par->state.vgabase, 0x2f); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1031 | if (par->chip & CHIP_UNDECIDED_FLAG) |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 1032 | par->chip = s3_identification(par); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1033 | |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 1034 | /* Find how many physical memory there is on card */ |
| 1035 | /* 0x36 register is accessible even if other registers are locked */ |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 1036 | regval = vga_rcrt(par->state.vgabase, 0x36); |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 1037 | if (par->chip == CHIP_360_TRIO3D_1X || |
| 1038 | par->chip == CHIP_362_TRIO3D_2X || |
Ondrej Zary | 5694f9c | 2011-03-01 19:18:17 +0000 | [diff] [blame] | 1039 | par->chip == CHIP_368_TRIO3D_2X || |
| 1040 | par->chip == CHIP_365_TRIO3D) { |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 1041 | switch ((regval & 0xE0) >> 5) { |
| 1042 | case 0: /* 8MB -- only 4MB usable for display */ |
| 1043 | case 1: /* 4MB with 32-bit bus */ |
| 1044 | case 2: /* 4MB */ |
| 1045 | info->screen_size = 4 << 20; |
| 1046 | break; |
Ondrej Zary | 5694f9c | 2011-03-01 19:18:17 +0000 | [diff] [blame] | 1047 | case 4: /* 2MB on 365 Trio3D */ |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 1048 | case 6: /* 2MB */ |
| 1049 | info->screen_size = 2 << 20; |
| 1050 | break; |
| 1051 | } |
| 1052 | } else |
| 1053 | info->screen_size = s3_memsizes[regval >> 5] << 10; |
| 1054 | info->fix.smem_len = info->screen_size; |
| 1055 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1056 | /* Find MCLK frequency */ |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 1057 | regval = vga_rseq(par->state.vgabase, 0x10); |
| 1058 | par->mclk_freq = ((vga_rseq(par->state.vgabase, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1059 | par->mclk_freq = par->mclk_freq >> (regval >> 5); |
| 1060 | |
| 1061 | /* Restore locks */ |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 1062 | vga_wcrt(par->state.vgabase, 0x38, cr38); |
| 1063 | vga_wcrt(par->state.vgabase, 0x39, cr39); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1064 | |
| 1065 | strcpy(info->fix.id, s3_names [par->chip]); |
| 1066 | info->fix.mmio_start = 0; |
| 1067 | info->fix.mmio_len = 0; |
| 1068 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 1069 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
| 1070 | info->fix.ypanstep = 0; |
| 1071 | info->fix.accel = FB_ACCEL_NONE; |
| 1072 | info->pseudo_palette = (void*) (par->pseudo_palette); |
| 1073 | |
| 1074 | /* Prepare startup mode */ |
Krzysztof Helt | a814054 | 2008-04-28 02:15:09 -0700 | [diff] [blame] | 1075 | rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1076 | if (! ((rc == 1) || (rc == 2))) { |
| 1077 | rc = -EINVAL; |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1078 | dev_err(info->device, "mode %s not found\n", mode_option); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1079 | goto err_find_mode; |
| 1080 | } |
| 1081 | |
Ondrej Zary | 99d054d | 2011-03-01 19:18:08 +0000 | [diff] [blame] | 1082 | /* maximize virtual vertical size for fast scrolling */ |
| 1083 | info->var.yres_virtual = info->fix.smem_len * 8 / |
| 1084 | (info->var.bits_per_pixel * info->var.xres_virtual); |
| 1085 | if (info->var.yres_virtual < info->var.yres) { |
| 1086 | dev_err(info->device, "virtual vertical size smaller than real\n"); |
| 1087 | goto err_find_mode; |
| 1088 | } |
| 1089 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1090 | rc = fb_alloc_cmap(&info->cmap, 256, 0); |
| 1091 | if (rc < 0) { |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1092 | dev_err(info->device, "cannot allocate colormap\n"); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1093 | goto err_alloc_cmap; |
| 1094 | } |
| 1095 | |
| 1096 | rc = register_framebuffer(info); |
| 1097 | if (rc < 0) { |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1098 | dev_err(info->device, "cannot register framebuffer\n"); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1099 | goto err_reg_fb; |
| 1100 | } |
| 1101 | |
| 1102 | printk(KERN_INFO "fb%d: %s on %s, %d MB RAM, %d MHz MCLK\n", info->node, info->fix.id, |
| 1103 | pci_name(dev), info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000); |
| 1104 | |
| 1105 | if (par->chip == CHIP_UNKNOWN) |
| 1106 | printk(KERN_INFO "fb%d: unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n", |
David Miller | f864593 | 2011-01-11 23:52:57 +0000 | [diff] [blame] | 1107 | info->node, vga_rcrt(par->state.vgabase, 0x2d), vga_rcrt(par->state.vgabase, 0x2e), |
| 1108 | vga_rcrt(par->state.vgabase, 0x2f), vga_rcrt(par->state.vgabase, 0x30)); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1109 | |
| 1110 | /* Record a reference to the driver data */ |
| 1111 | pci_set_drvdata(dev, info); |
| 1112 | |
| 1113 | #ifdef CONFIG_MTRR |
| 1114 | if (mtrr) { |
| 1115 | par->mtrr_reg = -1; |
| 1116 | par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1); |
| 1117 | } |
| 1118 | #endif |
| 1119 | |
| 1120 | return 0; |
| 1121 | |
| 1122 | /* Error handling */ |
| 1123 | err_reg_fb: |
| 1124 | fb_dealloc_cmap(&info->cmap); |
| 1125 | err_alloc_cmap: |
| 1126 | err_find_mode: |
| 1127 | pci_iounmap(dev, info->screen_base); |
| 1128 | err_iomap: |
| 1129 | pci_release_regions(dev); |
| 1130 | err_request_regions: |
| 1131 | /* pci_disable_device(dev); */ |
| 1132 | err_enable_device: |
| 1133 | framebuffer_release(info); |
| 1134 | return rc; |
| 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | /* PCI remove */ |
| 1139 | |
| 1140 | static void __devexit s3_pci_remove(struct pci_dev *dev) |
| 1141 | { |
| 1142 | struct fb_info *info = pci_get_drvdata(dev); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1143 | |
| 1144 | if (info) { |
| 1145 | |
| 1146 | #ifdef CONFIG_MTRR |
Adrian Bunk | 47ebea8 | 2007-03-22 00:11:16 -0800 | [diff] [blame] | 1147 | struct s3fb_info *par = info->par; |
| 1148 | |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1149 | if (par->mtrr_reg >= 0) { |
| 1150 | mtrr_del(par->mtrr_reg, 0, 0); |
| 1151 | par->mtrr_reg = -1; |
| 1152 | } |
| 1153 | #endif |
| 1154 | |
| 1155 | unregister_framebuffer(info); |
| 1156 | fb_dealloc_cmap(&info->cmap); |
| 1157 | |
| 1158 | pci_iounmap(dev, info->screen_base); |
| 1159 | pci_release_regions(dev); |
| 1160 | /* pci_disable_device(dev); */ |
| 1161 | |
| 1162 | pci_set_drvdata(dev, NULL); |
| 1163 | framebuffer_release(info); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | /* PCI suspend */ |
| 1168 | |
| 1169 | static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state) |
| 1170 | { |
| 1171 | struct fb_info *info = pci_get_drvdata(dev); |
| 1172 | struct s3fb_info *par = info->par; |
| 1173 | |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1174 | dev_info(info->device, "suspend\n"); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1175 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1176 | console_lock(); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1177 | mutex_lock(&(par->open_lock)); |
| 1178 | |
| 1179 | if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) { |
| 1180 | mutex_unlock(&(par->open_lock)); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1181 | console_unlock(); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | fb_set_suspend(info, 1); |
| 1186 | |
| 1187 | pci_save_state(dev); |
| 1188 | pci_disable_device(dev); |
| 1189 | pci_set_power_state(dev, pci_choose_state(dev, state)); |
| 1190 | |
| 1191 | mutex_unlock(&(par->open_lock)); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1192 | console_unlock(); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1193 | |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | /* PCI resume */ |
| 1199 | |
| 1200 | static int s3_pci_resume(struct pci_dev* dev) |
| 1201 | { |
| 1202 | struct fb_info *info = pci_get_drvdata(dev); |
| 1203 | struct s3fb_info *par = info->par; |
Randy Dunlap | 6314db4 | 2007-05-08 00:38:11 -0700 | [diff] [blame] | 1204 | int err; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1205 | |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1206 | dev_info(info->device, "resume\n"); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1207 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1208 | console_lock(); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1209 | mutex_lock(&(par->open_lock)); |
| 1210 | |
| 1211 | if (par->ref_count == 0) { |
| 1212 | mutex_unlock(&(par->open_lock)); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1213 | console_unlock(); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | pci_set_power_state(dev, PCI_D0); |
| 1218 | pci_restore_state(dev); |
Randy Dunlap | 6314db4 | 2007-05-08 00:38:11 -0700 | [diff] [blame] | 1219 | err = pci_enable_device(dev); |
| 1220 | if (err) { |
| 1221 | mutex_unlock(&(par->open_lock)); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1222 | console_unlock(); |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1223 | dev_err(info->device, "error %d enabling device for resume\n", err); |
Randy Dunlap | 6314db4 | 2007-05-08 00:38:11 -0700 | [diff] [blame] | 1224 | return err; |
| 1225 | } |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1226 | pci_set_master(dev); |
| 1227 | |
| 1228 | s3fb_set_par(info); |
| 1229 | fb_set_suspend(info, 0); |
| 1230 | |
| 1231 | mutex_unlock(&(par->open_lock)); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1232 | console_unlock(); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
| 1237 | |
| 1238 | /* List of boards that we are trying to support */ |
| 1239 | |
| 1240 | static struct pci_device_id s3_devices[] __devinitdata = { |
| 1241 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO}, |
| 1242 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO}, |
| 1243 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP}, |
| 1244 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP}, |
| 1245 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX}, |
| 1246 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX}, |
| 1247 | |
| 1248 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE}, |
| 1249 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX}, |
| 1250 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX}, |
| 1251 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_356_VIRGE_GX2}, |
| 1252 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_357_VIRGE_GX2P}, |
| 1253 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P}, |
Ondrej Zary | 9966c4f | 2010-05-26 14:42:27 -0700 | [diff] [blame] | 1254 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A13), .driver_data = CHIP_36X_TRIO3D_1X_2X}, |
Ondrej Zary | 5694f9c | 2011-03-01 19:18:17 +0000 | [diff] [blame] | 1255 | {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8904), .driver_data = CHIP_365_TRIO3D}, |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1256 | |
| 1257 | {0, 0, 0, 0, 0, 0, 0} |
| 1258 | }; |
| 1259 | |
| 1260 | |
| 1261 | MODULE_DEVICE_TABLE(pci, s3_devices); |
| 1262 | |
| 1263 | static struct pci_driver s3fb_pci_driver = { |
| 1264 | .name = "s3fb", |
| 1265 | .id_table = s3_devices, |
| 1266 | .probe = s3_pci_probe, |
| 1267 | .remove = __devexit_p(s3_pci_remove), |
| 1268 | .suspend = s3_pci_suspend, |
| 1269 | .resume = s3_pci_resume, |
| 1270 | }; |
| 1271 | |
| 1272 | /* Parse user speficied options */ |
| 1273 | |
| 1274 | #ifndef MODULE |
| 1275 | static int __init s3fb_setup(char *options) |
| 1276 | { |
| 1277 | char *opt; |
| 1278 | |
| 1279 | if (!options || !*options) |
| 1280 | return 0; |
| 1281 | |
| 1282 | while ((opt = strsep(&options, ",")) != NULL) { |
| 1283 | |
| 1284 | if (!*opt) |
| 1285 | continue; |
| 1286 | #ifdef CONFIG_MTRR |
Ondrej Zajicek | 62fa4dc | 2007-02-22 17:00:41 +0100 | [diff] [blame] | 1287 | else if (!strncmp(opt, "mtrr:", 5)) |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1288 | mtrr = simple_strtoul(opt + 5, NULL, 0); |
| 1289 | #endif |
Ondrej Zajicek | 62fa4dc | 2007-02-22 17:00:41 +0100 | [diff] [blame] | 1290 | else if (!strncmp(opt, "fasttext:", 9)) |
| 1291 | fasttext = simple_strtoul(opt + 9, NULL, 0); |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1292 | else |
Krzysztof Helt | a814054 | 2008-04-28 02:15:09 -0700 | [diff] [blame] | 1293 | mode_option = opt; |
Ondrej Zajicek | a268422 | 2007-02-12 00:54:49 -0800 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | return 0; |
| 1297 | } |
| 1298 | #endif |
| 1299 | |
| 1300 | /* Cleanup */ |
| 1301 | |
| 1302 | static void __exit s3fb_cleanup(void) |
| 1303 | { |
| 1304 | pr_debug("s3fb: cleaning up\n"); |
| 1305 | pci_unregister_driver(&s3fb_pci_driver); |
| 1306 | } |
| 1307 | |
| 1308 | /* Driver Initialisation */ |
| 1309 | |
| 1310 | static int __init s3fb_init(void) |
| 1311 | { |
| 1312 | |
| 1313 | #ifndef MODULE |
| 1314 | char *option = NULL; |
| 1315 | |
| 1316 | if (fb_get_options("s3fb", &option)) |
| 1317 | return -ENODEV; |
| 1318 | s3fb_setup(option); |
| 1319 | #endif |
| 1320 | |
| 1321 | pr_debug("s3fb: initializing\n"); |
| 1322 | return pci_register_driver(&s3fb_pci_driver); |
| 1323 | } |
| 1324 | |
| 1325 | /* ------------------------------------------------------------------------- */ |
| 1326 | |
| 1327 | /* Modularization */ |
| 1328 | |
| 1329 | module_init(s3fb_init); |
| 1330 | module_exit(s3fb_cleanup); |