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