18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * linux/drivers/video/s3fb.c -- Frame buffer device driver for S3 Trio/Virge 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org> 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 78c2ecf20Sopenharmony_ci * License. See the file COPYING in the main directory of this archive for 88c2ecf20Sopenharmony_ci * more details. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Code is based on David Boucher's viafb (http://davesdomain.org.uk/viafb/) 118c2ecf20Sopenharmony_ci * which is based on the code of neofb. 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/module.h> 158c2ecf20Sopenharmony_ci#include <linux/kernel.h> 168c2ecf20Sopenharmony_ci#include <linux/errno.h> 178c2ecf20Sopenharmony_ci#include <linux/string.h> 188c2ecf20Sopenharmony_ci#include <linux/mm.h> 198c2ecf20Sopenharmony_ci#include <linux/tty.h> 208c2ecf20Sopenharmony_ci#include <linux/delay.h> 218c2ecf20Sopenharmony_ci#include <linux/fb.h> 228c2ecf20Sopenharmony_ci#include <linux/svga.h> 238c2ecf20Sopenharmony_ci#include <linux/init.h> 248c2ecf20Sopenharmony_ci#include <linux/pci.h> 258c2ecf20Sopenharmony_ci#include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */ 268c2ecf20Sopenharmony_ci#include <video/vga.h> 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include <linux/i2c.h> 298c2ecf20Sopenharmony_ci#include <linux/i2c-algo-bit.h> 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistruct s3fb_info { 328c2ecf20Sopenharmony_ci int chip, rev, mclk_freq; 338c2ecf20Sopenharmony_ci int wc_cookie; 348c2ecf20Sopenharmony_ci struct vgastate state; 358c2ecf20Sopenharmony_ci struct mutex open_lock; 368c2ecf20Sopenharmony_ci unsigned int ref_count; 378c2ecf20Sopenharmony_ci u32 pseudo_palette[16]; 388c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_S3_DDC 398c2ecf20Sopenharmony_ci u8 __iomem *mmio; 408c2ecf20Sopenharmony_ci bool ddc_registered; 418c2ecf20Sopenharmony_ci struct i2c_adapter ddc_adapter; 428c2ecf20Sopenharmony_ci struct i2c_algo_bit_data ddc_algo; 438c2ecf20Sopenharmony_ci#endif 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */ 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic const struct svga_fb_format s3fb_formats[] = { 508c2ecf20Sopenharmony_ci { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0, 518c2ecf20Sopenharmony_ci FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 16}, 528c2ecf20Sopenharmony_ci { 4, {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 0, 538c2ecf20Sopenharmony_ci FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16}, 548c2ecf20Sopenharmony_ci { 4, {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 1, 558c2ecf20Sopenharmony_ci FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16}, 568c2ecf20Sopenharmony_ci { 8, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, 578c2ecf20Sopenharmony_ci FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 4, 8}, 588c2ecf20Sopenharmony_ci {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0, 598c2ecf20Sopenharmony_ci FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4}, 608c2ecf20Sopenharmony_ci {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0, 618c2ecf20Sopenharmony_ci FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4}, 628c2ecf20Sopenharmony_ci {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, 638c2ecf20Sopenharmony_ci FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2}, 648c2ecf20Sopenharmony_ci {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, 658c2ecf20Sopenharmony_ci FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2}, 668c2ecf20Sopenharmony_ci SVGA_FORMAT_END 678c2ecf20Sopenharmony_ci}; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistatic const struct svga_pll s3_pll = {3, 129, 3, 33, 0, 3, 718c2ecf20Sopenharmony_ci 35000, 240000, 14318}; 728c2ecf20Sopenharmony_cistatic const struct svga_pll s3_trio3d_pll = {3, 129, 3, 31, 0, 4, 738c2ecf20Sopenharmony_ci 230000, 460000, 14318}; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic const int s3_memsizes[] = {4096, 0, 3072, 8192, 2048, 6144, 1024, 512}; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic const char * const s3_names[] = {"S3 Unknown", "S3 Trio32", "S3 Trio64", "S3 Trio64V+", 788c2ecf20Sopenharmony_ci "S3 Trio64UV+", "S3 Trio64V2/DX", "S3 Trio64V2/GX", 798c2ecf20Sopenharmony_ci "S3 Plato/PX", "S3 Aurora64V+", "S3 Virge", 808c2ecf20Sopenharmony_ci "S3 Virge/VX", "S3 Virge/DX", "S3 Virge/GX", 818c2ecf20Sopenharmony_ci "S3 Virge/GX2", "S3 Virge/GX2+", "", 828c2ecf20Sopenharmony_ci "S3 Trio3D/1X", "S3 Trio3D/2X", "S3 Trio3D/2X", 838c2ecf20Sopenharmony_ci "S3 Trio3D", "S3 Virge/MX"}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define CHIP_UNKNOWN 0x00 868c2ecf20Sopenharmony_ci#define CHIP_732_TRIO32 0x01 878c2ecf20Sopenharmony_ci#define CHIP_764_TRIO64 0x02 888c2ecf20Sopenharmony_ci#define CHIP_765_TRIO64VP 0x03 898c2ecf20Sopenharmony_ci#define CHIP_767_TRIO64UVP 0x04 908c2ecf20Sopenharmony_ci#define CHIP_775_TRIO64V2_DX 0x05 918c2ecf20Sopenharmony_ci#define CHIP_785_TRIO64V2_GX 0x06 928c2ecf20Sopenharmony_ci#define CHIP_551_PLATO_PX 0x07 938c2ecf20Sopenharmony_ci#define CHIP_M65_AURORA64VP 0x08 948c2ecf20Sopenharmony_ci#define CHIP_325_VIRGE 0x09 958c2ecf20Sopenharmony_ci#define CHIP_988_VIRGE_VX 0x0A 968c2ecf20Sopenharmony_ci#define CHIP_375_VIRGE_DX 0x0B 978c2ecf20Sopenharmony_ci#define CHIP_385_VIRGE_GX 0x0C 988c2ecf20Sopenharmony_ci#define CHIP_357_VIRGE_GX2 0x0D 998c2ecf20Sopenharmony_ci#define CHIP_359_VIRGE_GX2P 0x0E 1008c2ecf20Sopenharmony_ci#define CHIP_360_TRIO3D_1X 0x10 1018c2ecf20Sopenharmony_ci#define CHIP_362_TRIO3D_2X 0x11 1028c2ecf20Sopenharmony_ci#define CHIP_368_TRIO3D_2X 0x12 1038c2ecf20Sopenharmony_ci#define CHIP_365_TRIO3D 0x13 1048c2ecf20Sopenharmony_ci#define CHIP_260_VIRGE_MX 0x14 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci#define CHIP_XXX_TRIO 0x80 1078c2ecf20Sopenharmony_ci#define CHIP_XXX_TRIO64V2_DXGX 0x81 1088c2ecf20Sopenharmony_ci#define CHIP_XXX_VIRGE_DXGX 0x82 1098c2ecf20Sopenharmony_ci#define CHIP_36X_TRIO3D_1X_2X 0x83 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define CHIP_UNDECIDED_FLAG 0x80 1128c2ecf20Sopenharmony_ci#define CHIP_MASK 0xFF 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci#define MMIO_OFFSET 0x1000000 1158c2ecf20Sopenharmony_ci#define MMIO_SIZE 0x10000 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/* CRT timing register sets */ 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic const struct vga_regset s3_h_total_regs[] = {{0x00, 0, 7}, {0x5D, 0, 0}, VGA_REGSET_END}; 1208c2ecf20Sopenharmony_cistatic const struct vga_regset s3_h_display_regs[] = {{0x01, 0, 7}, {0x5D, 1, 1}, VGA_REGSET_END}; 1218c2ecf20Sopenharmony_cistatic const struct vga_regset s3_h_blank_start_regs[] = {{0x02, 0, 7}, {0x5D, 2, 2}, VGA_REGSET_END}; 1228c2ecf20Sopenharmony_cistatic const struct vga_regset s3_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, VGA_REGSET_END}; 1238c2ecf20Sopenharmony_cistatic const struct vga_regset s3_h_sync_start_regs[] = {{0x04, 0, 7}, {0x5D, 4, 4}, VGA_REGSET_END}; 1248c2ecf20Sopenharmony_cistatic const struct vga_regset s3_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END}; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cistatic const struct vga_regset s3_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x5E, 0, 0}, VGA_REGSET_END}; 1278c2ecf20Sopenharmony_cistatic const struct vga_regset s3_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x5E, 1, 1}, VGA_REGSET_END}; 1288c2ecf20Sopenharmony_cistatic const struct vga_regset s3_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x5E, 2, 2}, VGA_REGSET_END}; 1298c2ecf20Sopenharmony_cistatic const struct vga_regset s3_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END}; 1308c2ecf20Sopenharmony_cistatic const struct vga_regset s3_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x5E, 4, 4}, VGA_REGSET_END}; 1318c2ecf20Sopenharmony_cistatic const struct vga_regset s3_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END}; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistatic const struct vga_regset s3_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, {0x5E, 6, 6}, VGA_REGSET_END}; 1348c2ecf20Sopenharmony_cistatic const struct vga_regset s3_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x69, 0, 4}, VGA_REGSET_END}; 1358c2ecf20Sopenharmony_cistatic const struct vga_regset s3_offset_regs[] = {{0x13, 0, 7}, {0x51, 4, 5}, VGA_REGSET_END}; /* set 0x43 bit 2 to 0 */ 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cistatic const struct vga_regset s3_dtpc_regs[] = {{0x3B, 0, 7}, {0x5D, 6, 6}, VGA_REGSET_END}; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cistatic const struct svga_timing_regs s3_timing_regs = { 1408c2ecf20Sopenharmony_ci s3_h_total_regs, s3_h_display_regs, s3_h_blank_start_regs, 1418c2ecf20Sopenharmony_ci s3_h_blank_end_regs, s3_h_sync_start_regs, s3_h_sync_end_regs, 1428c2ecf20Sopenharmony_ci s3_v_total_regs, s3_v_display_regs, s3_v_blank_start_regs, 1438c2ecf20Sopenharmony_ci s3_v_blank_end_regs, s3_v_sync_start_regs, s3_v_sync_end_regs, 1448c2ecf20Sopenharmony_ci}; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */ 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* Module parameters */ 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_cistatic char *mode_option; 1538c2ecf20Sopenharmony_cistatic int mtrr = 1; 1548c2ecf20Sopenharmony_cistatic int fasttext = 1; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ciMODULE_AUTHOR("(c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>"); 1588c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 1598c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("fbdev driver for S3 Trio/Virge"); 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cimodule_param(mode_option, charp, 0444); 1628c2ecf20Sopenharmony_ciMODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)"); 1638c2ecf20Sopenharmony_cimodule_param_named(mode, mode_option, charp, 0444); 1648c2ecf20Sopenharmony_ciMODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)"); 1658c2ecf20Sopenharmony_cimodule_param(mtrr, int, 0444); 1668c2ecf20Sopenharmony_ciMODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)"); 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_cimodule_param(fasttext, int, 0644); 1698c2ecf20Sopenharmony_ciMODULE_PARM_DESC(fasttext, "Enable S3 fast text mode (1=enable, 0=disable, default=1)"); 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */ 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_S3_DDC 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci#define DDC_REG 0xaa /* Trio 3D/1X/2X */ 1778c2ecf20Sopenharmony_ci#define DDC_MMIO_REG 0xff20 /* all other chips */ 1788c2ecf20Sopenharmony_ci#define DDC_SCL_OUT (1 << 0) 1798c2ecf20Sopenharmony_ci#define DDC_SDA_OUT (1 << 1) 1808c2ecf20Sopenharmony_ci#define DDC_SCL_IN (1 << 2) 1818c2ecf20Sopenharmony_ci#define DDC_SDA_IN (1 << 3) 1828c2ecf20Sopenharmony_ci#define DDC_DRIVE_EN (1 << 4) 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_cistatic bool s3fb_ddc_needs_mmio(int chip) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci return !(chip == CHIP_360_TRIO3D_1X || 1878c2ecf20Sopenharmony_ci chip == CHIP_362_TRIO3D_2X || 1888c2ecf20Sopenharmony_ci chip == CHIP_368_TRIO3D_2X); 1898c2ecf20Sopenharmony_ci} 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistatic u8 s3fb_ddc_read(struct s3fb_info *par) 1928c2ecf20Sopenharmony_ci{ 1938c2ecf20Sopenharmony_ci if (s3fb_ddc_needs_mmio(par->chip)) 1948c2ecf20Sopenharmony_ci return readb(par->mmio + DDC_MMIO_REG); 1958c2ecf20Sopenharmony_ci else 1968c2ecf20Sopenharmony_ci return vga_rcrt(par->state.vgabase, DDC_REG); 1978c2ecf20Sopenharmony_ci} 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_cistatic void s3fb_ddc_write(struct s3fb_info *par, u8 val) 2008c2ecf20Sopenharmony_ci{ 2018c2ecf20Sopenharmony_ci if (s3fb_ddc_needs_mmio(par->chip)) 2028c2ecf20Sopenharmony_ci writeb(val, par->mmio + DDC_MMIO_REG); 2038c2ecf20Sopenharmony_ci else 2048c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, DDC_REG, val); 2058c2ecf20Sopenharmony_ci} 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_cistatic void s3fb_ddc_setscl(void *data, int val) 2088c2ecf20Sopenharmony_ci{ 2098c2ecf20Sopenharmony_ci struct s3fb_info *par = data; 2108c2ecf20Sopenharmony_ci unsigned char reg; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci reg = s3fb_ddc_read(par) | DDC_DRIVE_EN; 2138c2ecf20Sopenharmony_ci if (val) 2148c2ecf20Sopenharmony_ci reg |= DDC_SCL_OUT; 2158c2ecf20Sopenharmony_ci else 2168c2ecf20Sopenharmony_ci reg &= ~DDC_SCL_OUT; 2178c2ecf20Sopenharmony_ci s3fb_ddc_write(par, reg); 2188c2ecf20Sopenharmony_ci} 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_cistatic void s3fb_ddc_setsda(void *data, int val) 2218c2ecf20Sopenharmony_ci{ 2228c2ecf20Sopenharmony_ci struct s3fb_info *par = data; 2238c2ecf20Sopenharmony_ci unsigned char reg; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci reg = s3fb_ddc_read(par) | DDC_DRIVE_EN; 2268c2ecf20Sopenharmony_ci if (val) 2278c2ecf20Sopenharmony_ci reg |= DDC_SDA_OUT; 2288c2ecf20Sopenharmony_ci else 2298c2ecf20Sopenharmony_ci reg &= ~DDC_SDA_OUT; 2308c2ecf20Sopenharmony_ci s3fb_ddc_write(par, reg); 2318c2ecf20Sopenharmony_ci} 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_cistatic int s3fb_ddc_getscl(void *data) 2348c2ecf20Sopenharmony_ci{ 2358c2ecf20Sopenharmony_ci struct s3fb_info *par = data; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci return !!(s3fb_ddc_read(par) & DDC_SCL_IN); 2388c2ecf20Sopenharmony_ci} 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_cistatic int s3fb_ddc_getsda(void *data) 2418c2ecf20Sopenharmony_ci{ 2428c2ecf20Sopenharmony_ci struct s3fb_info *par = data; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci return !!(s3fb_ddc_read(par) & DDC_SDA_IN); 2458c2ecf20Sopenharmony_ci} 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistatic int s3fb_setup_ddc_bus(struct fb_info *info) 2488c2ecf20Sopenharmony_ci{ 2498c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci strlcpy(par->ddc_adapter.name, info->fix.id, 2528c2ecf20Sopenharmony_ci sizeof(par->ddc_adapter.name)); 2538c2ecf20Sopenharmony_ci par->ddc_adapter.owner = THIS_MODULE; 2548c2ecf20Sopenharmony_ci par->ddc_adapter.class = I2C_CLASS_DDC; 2558c2ecf20Sopenharmony_ci par->ddc_adapter.algo_data = &par->ddc_algo; 2568c2ecf20Sopenharmony_ci par->ddc_adapter.dev.parent = info->device; 2578c2ecf20Sopenharmony_ci par->ddc_algo.setsda = s3fb_ddc_setsda; 2588c2ecf20Sopenharmony_ci par->ddc_algo.setscl = s3fb_ddc_setscl; 2598c2ecf20Sopenharmony_ci par->ddc_algo.getsda = s3fb_ddc_getsda; 2608c2ecf20Sopenharmony_ci par->ddc_algo.getscl = s3fb_ddc_getscl; 2618c2ecf20Sopenharmony_ci par->ddc_algo.udelay = 10; 2628c2ecf20Sopenharmony_ci par->ddc_algo.timeout = 20; 2638c2ecf20Sopenharmony_ci par->ddc_algo.data = par; 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci i2c_set_adapdata(&par->ddc_adapter, par); 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci /* 2688c2ecf20Sopenharmony_ci * some Virge cards have external MUX to switch chip I2C bus between 2698c2ecf20Sopenharmony_ci * DDC and extension pins - switch it do DDC 2708c2ecf20Sopenharmony_ci */ 2718c2ecf20Sopenharmony_ci/* vga_wseq(par->state.vgabase, 0x08, 0x06); - not needed, already unlocked */ 2728c2ecf20Sopenharmony_ci if (par->chip == CHIP_357_VIRGE_GX2 || 2738c2ecf20Sopenharmony_ci par->chip == CHIP_359_VIRGE_GX2P || 2748c2ecf20Sopenharmony_ci par->chip == CHIP_260_VIRGE_MX) 2758c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x0d, 0x01, 0x03); 2768c2ecf20Sopenharmony_ci else 2778c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x0d, 0x00, 0x03); 2788c2ecf20Sopenharmony_ci /* some Virge need this or the DDC is ignored */ 2798c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x5c, 0x03, 0x03); 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci return i2c_bit_add_bus(&par->ddc_adapter); 2828c2ecf20Sopenharmony_ci} 2838c2ecf20Sopenharmony_ci#endif /* CONFIG_FB_S3_DDC */ 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */ 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci/* Set font in S3 fast text mode */ 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_cistatic void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map) 2918c2ecf20Sopenharmony_ci{ 2928c2ecf20Sopenharmony_ci const u8 *font = map->data; 2938c2ecf20Sopenharmony_ci u8 __iomem *fb = (u8 __iomem *) info->screen_base; 2948c2ecf20Sopenharmony_ci int i, c; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci if ((map->width != 8) || (map->height != 16) || 2978c2ecf20Sopenharmony_ci (map->depth != 1) || (map->length != 256)) { 2988c2ecf20Sopenharmony_ci fb_err(info, "unsupported font parameters: width %d, height %d, depth %d, length %d\n", 2998c2ecf20Sopenharmony_ci map->width, map->height, map->depth, map->length); 3008c2ecf20Sopenharmony_ci return; 3018c2ecf20Sopenharmony_ci } 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci fb += 2; 3048c2ecf20Sopenharmony_ci for (i = 0; i < map->height; i++) { 3058c2ecf20Sopenharmony_ci for (c = 0; c < map->length; c++) { 3068c2ecf20Sopenharmony_ci fb_writeb(font[c * map->height + i], fb + c * 4); 3078c2ecf20Sopenharmony_ci } 3088c2ecf20Sopenharmony_ci fb += 1024; 3098c2ecf20Sopenharmony_ci } 3108c2ecf20Sopenharmony_ci} 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_cistatic void s3fb_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor) 3138c2ecf20Sopenharmony_ci{ 3148c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci svga_tilecursor(par->state.vgabase, info, cursor); 3178c2ecf20Sopenharmony_ci} 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_cistatic struct fb_tile_ops s3fb_tile_ops = { 3208c2ecf20Sopenharmony_ci .fb_settile = svga_settile, 3218c2ecf20Sopenharmony_ci .fb_tilecopy = svga_tilecopy, 3228c2ecf20Sopenharmony_ci .fb_tilefill = svga_tilefill, 3238c2ecf20Sopenharmony_ci .fb_tileblit = svga_tileblit, 3248c2ecf20Sopenharmony_ci .fb_tilecursor = s3fb_tilecursor, 3258c2ecf20Sopenharmony_ci .fb_get_tilemax = svga_get_tilemax, 3268c2ecf20Sopenharmony_ci}; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistatic struct fb_tile_ops s3fb_fast_tile_ops = { 3298c2ecf20Sopenharmony_ci .fb_settile = s3fb_settile_fast, 3308c2ecf20Sopenharmony_ci .fb_tilecopy = svga_tilecopy, 3318c2ecf20Sopenharmony_ci .fb_tilefill = svga_tilefill, 3328c2ecf20Sopenharmony_ci .fb_tileblit = svga_tileblit, 3338c2ecf20Sopenharmony_ci .fb_tilecursor = s3fb_tilecursor, 3348c2ecf20Sopenharmony_ci .fb_get_tilemax = svga_get_tilemax, 3358c2ecf20Sopenharmony_ci}; 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */ 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci/* image data is MSB-first, fb structure is MSB-first too */ 3418c2ecf20Sopenharmony_cistatic inline u32 expand_color(u32 c) 3428c2ecf20Sopenharmony_ci{ 3438c2ecf20Sopenharmony_ci return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF; 3448c2ecf20Sopenharmony_ci} 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci/* s3fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */ 3478c2ecf20Sopenharmony_cistatic void s3fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image) 3488c2ecf20Sopenharmony_ci{ 3498c2ecf20Sopenharmony_ci u32 fg = expand_color(image->fg_color); 3508c2ecf20Sopenharmony_ci u32 bg = expand_color(image->bg_color); 3518c2ecf20Sopenharmony_ci const u8 *src1, *src; 3528c2ecf20Sopenharmony_ci u8 __iomem *dst1; 3538c2ecf20Sopenharmony_ci u32 __iomem *dst; 3548c2ecf20Sopenharmony_ci u32 val; 3558c2ecf20Sopenharmony_ci int x, y; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci src1 = image->data; 3588c2ecf20Sopenharmony_ci dst1 = info->screen_base + (image->dy * info->fix.line_length) 3598c2ecf20Sopenharmony_ci + ((image->dx / 8) * 4); 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci for (y = 0; y < image->height; y++) { 3628c2ecf20Sopenharmony_ci src = src1; 3638c2ecf20Sopenharmony_ci dst = (u32 __iomem *) dst1; 3648c2ecf20Sopenharmony_ci for (x = 0; x < image->width; x += 8) { 3658c2ecf20Sopenharmony_ci val = *(src++) * 0x01010101; 3668c2ecf20Sopenharmony_ci val = (val & fg) | (~val & bg); 3678c2ecf20Sopenharmony_ci fb_writel(val, dst++); 3688c2ecf20Sopenharmony_ci } 3698c2ecf20Sopenharmony_ci src1 += image->width / 8; 3708c2ecf20Sopenharmony_ci dst1 += info->fix.line_length; 3718c2ecf20Sopenharmony_ci } 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci} 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci/* s3fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */ 3768c2ecf20Sopenharmony_cistatic void s3fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect) 3778c2ecf20Sopenharmony_ci{ 3788c2ecf20Sopenharmony_ci u32 fg = expand_color(rect->color); 3798c2ecf20Sopenharmony_ci u8 __iomem *dst1; 3808c2ecf20Sopenharmony_ci u32 __iomem *dst; 3818c2ecf20Sopenharmony_ci int x, y; 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci dst1 = info->screen_base + (rect->dy * info->fix.line_length) 3848c2ecf20Sopenharmony_ci + ((rect->dx / 8) * 4); 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci for (y = 0; y < rect->height; y++) { 3878c2ecf20Sopenharmony_ci dst = (u32 __iomem *) dst1; 3888c2ecf20Sopenharmony_ci for (x = 0; x < rect->width; x += 8) { 3898c2ecf20Sopenharmony_ci fb_writel(fg, dst++); 3908c2ecf20Sopenharmony_ci } 3918c2ecf20Sopenharmony_ci dst1 += info->fix.line_length; 3928c2ecf20Sopenharmony_ci } 3938c2ecf20Sopenharmony_ci} 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci/* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */ 3978c2ecf20Sopenharmony_cistatic inline u32 expand_pixel(u32 c) 3988c2ecf20Sopenharmony_ci{ 3998c2ecf20Sopenharmony_ci return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) | 4008c2ecf20Sopenharmony_ci ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF; 4018c2ecf20Sopenharmony_ci} 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci/* s3fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */ 4048c2ecf20Sopenharmony_cistatic void s3fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image) 4058c2ecf20Sopenharmony_ci{ 4068c2ecf20Sopenharmony_ci u32 fg = image->fg_color * 0x11111111; 4078c2ecf20Sopenharmony_ci u32 bg = image->bg_color * 0x11111111; 4088c2ecf20Sopenharmony_ci const u8 *src1, *src; 4098c2ecf20Sopenharmony_ci u8 __iomem *dst1; 4108c2ecf20Sopenharmony_ci u32 __iomem *dst; 4118c2ecf20Sopenharmony_ci u32 val; 4128c2ecf20Sopenharmony_ci int x, y; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci src1 = image->data; 4158c2ecf20Sopenharmony_ci dst1 = info->screen_base + (image->dy * info->fix.line_length) 4168c2ecf20Sopenharmony_ci + ((image->dx / 8) * 4); 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci for (y = 0; y < image->height; y++) { 4198c2ecf20Sopenharmony_ci src = src1; 4208c2ecf20Sopenharmony_ci dst = (u32 __iomem *) dst1; 4218c2ecf20Sopenharmony_ci for (x = 0; x < image->width; x += 8) { 4228c2ecf20Sopenharmony_ci val = expand_pixel(*(src++)); 4238c2ecf20Sopenharmony_ci val = (val & fg) | (~val & bg); 4248c2ecf20Sopenharmony_ci fb_writel(val, dst++); 4258c2ecf20Sopenharmony_ci } 4268c2ecf20Sopenharmony_ci src1 += image->width / 8; 4278c2ecf20Sopenharmony_ci dst1 += info->fix.line_length; 4288c2ecf20Sopenharmony_ci } 4298c2ecf20Sopenharmony_ci} 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_cistatic void s3fb_imageblit(struct fb_info *info, const struct fb_image *image) 4328c2ecf20Sopenharmony_ci{ 4338c2ecf20Sopenharmony_ci if ((info->var.bits_per_pixel == 4) && (image->depth == 1) 4348c2ecf20Sopenharmony_ci && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) { 4358c2ecf20Sopenharmony_ci if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES) 4368c2ecf20Sopenharmony_ci s3fb_iplan_imageblit(info, image); 4378c2ecf20Sopenharmony_ci else 4388c2ecf20Sopenharmony_ci s3fb_cfb4_imageblit(info, image); 4398c2ecf20Sopenharmony_ci } else 4408c2ecf20Sopenharmony_ci cfb_imageblit(info, image); 4418c2ecf20Sopenharmony_ci} 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_cistatic void s3fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) 4448c2ecf20Sopenharmony_ci{ 4458c2ecf20Sopenharmony_ci if ((info->var.bits_per_pixel == 4) 4468c2ecf20Sopenharmony_ci && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0) 4478c2ecf20Sopenharmony_ci && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)) 4488c2ecf20Sopenharmony_ci s3fb_iplan_fillrect(info, rect); 4498c2ecf20Sopenharmony_ci else 4508c2ecf20Sopenharmony_ci cfb_fillrect(info, rect); 4518c2ecf20Sopenharmony_ci} 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */ 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_cistatic void s3_set_pixclock(struct fb_info *info, u32 pixclock) 4598c2ecf20Sopenharmony_ci{ 4608c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 4618c2ecf20Sopenharmony_ci u16 m, n, r; 4628c2ecf20Sopenharmony_ci u8 regval; 4638c2ecf20Sopenharmony_ci int rv; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci rv = svga_compute_pll((par->chip == CHIP_365_TRIO3D) ? &s3_trio3d_pll : &s3_pll, 4668c2ecf20Sopenharmony_ci 1000000000 / pixclock, &m, &n, &r, info->node); 4678c2ecf20Sopenharmony_ci if (rv < 0) { 4688c2ecf20Sopenharmony_ci fb_err(info, "cannot set requested pixclock, keeping old value\n"); 4698c2ecf20Sopenharmony_ci return; 4708c2ecf20Sopenharmony_ci } 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci /* Set VGA misc register */ 4738c2ecf20Sopenharmony_ci regval = vga_r(par->state.vgabase, VGA_MIS_R); 4748c2ecf20Sopenharmony_ci vga_w(par->state.vgabase, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD); 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci /* Set S3 clock registers */ 4778c2ecf20Sopenharmony_ci if (par->chip == CHIP_357_VIRGE_GX2 || 4788c2ecf20Sopenharmony_ci par->chip == CHIP_359_VIRGE_GX2P || 4798c2ecf20Sopenharmony_ci par->chip == CHIP_360_TRIO3D_1X || 4808c2ecf20Sopenharmony_ci par->chip == CHIP_362_TRIO3D_2X || 4818c2ecf20Sopenharmony_ci par->chip == CHIP_368_TRIO3D_2X || 4828c2ecf20Sopenharmony_ci par->chip == CHIP_260_VIRGE_MX) { 4838c2ecf20Sopenharmony_ci vga_wseq(par->state.vgabase, 0x12, (n - 2) | ((r & 3) << 6)); /* n and two bits of r */ 4848c2ecf20Sopenharmony_ci vga_wseq(par->state.vgabase, 0x29, r >> 2); /* remaining highest bit of r */ 4858c2ecf20Sopenharmony_ci } else 4868c2ecf20Sopenharmony_ci vga_wseq(par->state.vgabase, 0x12, (n - 2) | (r << 5)); 4878c2ecf20Sopenharmony_ci vga_wseq(par->state.vgabase, 0x13, m - 2); 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci udelay(1000); 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci /* Activate clock - write 0, 1, 0 to seq/15 bit 5 */ 4928c2ecf20Sopenharmony_ci regval = vga_rseq (par->state.vgabase, 0x15); /* | 0x80; */ 4938c2ecf20Sopenharmony_ci vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5)); 4948c2ecf20Sopenharmony_ci vga_wseq(par->state.vgabase, 0x15, regval | (1<<5)); 4958c2ecf20Sopenharmony_ci vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5)); 4968c2ecf20Sopenharmony_ci} 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci/* Open framebuffer */ 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_cistatic int s3fb_open(struct fb_info *info, int user) 5028c2ecf20Sopenharmony_ci{ 5038c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci mutex_lock(&(par->open_lock)); 5068c2ecf20Sopenharmony_ci if (par->ref_count == 0) { 5078c2ecf20Sopenharmony_ci void __iomem *vgabase = par->state.vgabase; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci memset(&(par->state), 0, sizeof(struct vgastate)); 5108c2ecf20Sopenharmony_ci par->state.vgabase = vgabase; 5118c2ecf20Sopenharmony_ci par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP; 5128c2ecf20Sopenharmony_ci par->state.num_crtc = 0x70; 5138c2ecf20Sopenharmony_ci par->state.num_seq = 0x20; 5148c2ecf20Sopenharmony_ci save_vga(&(par->state)); 5158c2ecf20Sopenharmony_ci } 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci par->ref_count++; 5188c2ecf20Sopenharmony_ci mutex_unlock(&(par->open_lock)); 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci return 0; 5218c2ecf20Sopenharmony_ci} 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci/* Close framebuffer */ 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_cistatic int s3fb_release(struct fb_info *info, int user) 5268c2ecf20Sopenharmony_ci{ 5278c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci mutex_lock(&(par->open_lock)); 5308c2ecf20Sopenharmony_ci if (par->ref_count == 0) { 5318c2ecf20Sopenharmony_ci mutex_unlock(&(par->open_lock)); 5328c2ecf20Sopenharmony_ci return -EINVAL; 5338c2ecf20Sopenharmony_ci } 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci if (par->ref_count == 1) 5368c2ecf20Sopenharmony_ci restore_vga(&(par->state)); 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci par->ref_count--; 5398c2ecf20Sopenharmony_ci mutex_unlock(&(par->open_lock)); 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci return 0; 5428c2ecf20Sopenharmony_ci} 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci/* Validate passed in var */ 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_cistatic int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 5478c2ecf20Sopenharmony_ci{ 5488c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 5498c2ecf20Sopenharmony_ci int rv, mem, step; 5508c2ecf20Sopenharmony_ci u16 m, n, r; 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci /* Find appropriate format */ 5538c2ecf20Sopenharmony_ci rv = svga_match_format (s3fb_formats, var, NULL); 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci /* 32bpp mode is not supported on VIRGE VX, 5568c2ecf20Sopenharmony_ci 24bpp is not supported on others */ 5578c2ecf20Sopenharmony_ci if ((par->chip == CHIP_988_VIRGE_VX) ? (rv == 7) : (rv == 6)) 5588c2ecf20Sopenharmony_ci rv = -EINVAL; 5598c2ecf20Sopenharmony_ci 5608c2ecf20Sopenharmony_ci if (rv < 0) { 5618c2ecf20Sopenharmony_ci fb_err(info, "unsupported mode requested\n"); 5628c2ecf20Sopenharmony_ci return rv; 5638c2ecf20Sopenharmony_ci } 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci /* Do not allow to have real resoulution larger than virtual */ 5668c2ecf20Sopenharmony_ci if (var->xres > var->xres_virtual) 5678c2ecf20Sopenharmony_ci var->xres_virtual = var->xres; 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci if (var->yres > var->yres_virtual) 5708c2ecf20Sopenharmony_ci var->yres_virtual = var->yres; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci /* Round up xres_virtual to have proper alignment of lines */ 5738c2ecf20Sopenharmony_ci step = s3fb_formats[rv].xresstep - 1; 5748c2ecf20Sopenharmony_ci var->xres_virtual = (var->xres_virtual+step) & ~step; 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci /* Check whether have enough memory */ 5778c2ecf20Sopenharmony_ci mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual; 5788c2ecf20Sopenharmony_ci if (mem > info->screen_size) { 5798c2ecf20Sopenharmony_ci fb_err(info, "not enough framebuffer memory (%d kB requested , %u kB available)\n", 5808c2ecf20Sopenharmony_ci mem >> 10, (unsigned int) (info->screen_size >> 10)); 5818c2ecf20Sopenharmony_ci return -EINVAL; 5828c2ecf20Sopenharmony_ci } 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci rv = svga_check_timings (&s3_timing_regs, var, info->node); 5858c2ecf20Sopenharmony_ci if (rv < 0) { 5868c2ecf20Sopenharmony_ci fb_err(info, "invalid timings requested\n"); 5878c2ecf20Sopenharmony_ci return rv; 5888c2ecf20Sopenharmony_ci } 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci rv = svga_compute_pll(&s3_pll, PICOS2KHZ(var->pixclock), &m, &n, &r, 5918c2ecf20Sopenharmony_ci info->node); 5928c2ecf20Sopenharmony_ci if (rv < 0) { 5938c2ecf20Sopenharmony_ci fb_err(info, "invalid pixclock value requested\n"); 5948c2ecf20Sopenharmony_ci return rv; 5958c2ecf20Sopenharmony_ci } 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci return 0; 5988c2ecf20Sopenharmony_ci} 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci/* Set video mode from par */ 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_cistatic int s3fb_set_par(struct fb_info *info) 6038c2ecf20Sopenharmony_ci{ 6048c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 6058c2ecf20Sopenharmony_ci u32 value, mode, hmul, offset_value, screen_size, multiplex, dbytes; 6068c2ecf20Sopenharmony_ci u32 bpp = info->var.bits_per_pixel; 6078c2ecf20Sopenharmony_ci u32 htotal, hsstart; 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_ci if (bpp != 0) { 6108c2ecf20Sopenharmony_ci info->fix.ypanstep = 1; 6118c2ecf20Sopenharmony_ci info->fix.line_length = (info->var.xres_virtual * bpp) / 8; 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci info->flags &= ~FBINFO_MISC_TILEBLITTING; 6148c2ecf20Sopenharmony_ci info->tileops = NULL; 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci /* in 4bpp supports 8p wide tiles only, any tiles otherwise */ 6178c2ecf20Sopenharmony_ci info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0); 6188c2ecf20Sopenharmony_ci info->pixmap.blit_y = ~(u32)0; 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci offset_value = (info->var.xres_virtual * bpp) / 64; 6218c2ecf20Sopenharmony_ci screen_size = info->var.yres_virtual * info->fix.line_length; 6228c2ecf20Sopenharmony_ci } else { 6238c2ecf20Sopenharmony_ci info->fix.ypanstep = 16; 6248c2ecf20Sopenharmony_ci info->fix.line_length = 0; 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci info->flags |= FBINFO_MISC_TILEBLITTING; 6278c2ecf20Sopenharmony_ci info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops; 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci /* supports 8x16 tiles only */ 6308c2ecf20Sopenharmony_ci info->pixmap.blit_x = 1 << (8 - 1); 6318c2ecf20Sopenharmony_ci info->pixmap.blit_y = 1 << (16 - 1); 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci offset_value = info->var.xres_virtual / 16; 6348c2ecf20Sopenharmony_ci screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64; 6358c2ecf20Sopenharmony_ci } 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci info->var.xoffset = 0; 6388c2ecf20Sopenharmony_ci info->var.yoffset = 0; 6398c2ecf20Sopenharmony_ci info->var.activate = FB_ACTIVATE_NOW; 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci /* Unlock registers */ 6428c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x38, 0x48); 6438c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x39, 0xA5); 6448c2ecf20Sopenharmony_ci vga_wseq(par->state.vgabase, 0x08, 0x06); 6458c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80); 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci /* Blank screen and turn off sync */ 6488c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); 6498c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80); 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci /* Set default values */ 6528c2ecf20Sopenharmony_ci svga_set_default_gfx_regs(par->state.vgabase); 6538c2ecf20Sopenharmony_ci svga_set_default_atc_regs(par->state.vgabase); 6548c2ecf20Sopenharmony_ci svga_set_default_seq_regs(par->state.vgabase); 6558c2ecf20Sopenharmony_ci svga_set_default_crt_regs(par->state.vgabase); 6568c2ecf20Sopenharmony_ci svga_wcrt_multi(par->state.vgabase, s3_line_compare_regs, 0xFFFFFFFF); 6578c2ecf20Sopenharmony_ci svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, 0); 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci /* S3 specific initialization */ 6608c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x58, 0x10, 0x10); /* enable linear framebuffer */ 6618c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */ 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci/* svga_wcrt_mask(par->state.vgabase, 0x33, 0x08, 0x08); */ /* DDR ? */ 6648c2ecf20Sopenharmony_ci/* svga_wcrt_mask(par->state.vgabase, 0x43, 0x01, 0x01); */ /* DDR ? */ 6658c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x33, 0x00, 0x08); /* no DDR ? */ 6668c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x43, 0x00, 0x01); /* no DDR ? */ 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x5D, 0x00, 0x28); /* Clear strange HSlen bits */ 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci/* svga_wcrt_mask(par->state.vgabase, 0x58, 0x03, 0x03); */ 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_ci/* svga_wcrt_mask(par->state.vgabase, 0x53, 0x12, 0x13); */ /* enable MMIO */ 6738c2ecf20Sopenharmony_ci/* svga_wcrt_mask(par->state.vgabase, 0x40, 0x08, 0x08); */ /* enable write buffer */ 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci /* Set the offset register */ 6778c2ecf20Sopenharmony_ci fb_dbg(info, "offset register : %d\n", offset_value); 6788c2ecf20Sopenharmony_ci svga_wcrt_multi(par->state.vgabase, s3_offset_regs, offset_value); 6798c2ecf20Sopenharmony_ci 6808c2ecf20Sopenharmony_ci if (par->chip != CHIP_357_VIRGE_GX2 && 6818c2ecf20Sopenharmony_ci par->chip != CHIP_359_VIRGE_GX2P && 6828c2ecf20Sopenharmony_ci par->chip != CHIP_360_TRIO3D_1X && 6838c2ecf20Sopenharmony_ci par->chip != CHIP_362_TRIO3D_2X && 6848c2ecf20Sopenharmony_ci par->chip != CHIP_368_TRIO3D_2X && 6858c2ecf20Sopenharmony_ci par->chip != CHIP_260_VIRGE_MX) { 6868c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x54, 0x18); /* M parameter */ 6878c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x60, 0xff); /* N parameter */ 6888c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x61, 0xff); /* L parameter */ 6898c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x62, 0xff); /* L parameter */ 6908c2ecf20Sopenharmony_ci } 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x3A, 0x35); 6938c2ecf20Sopenharmony_ci svga_wattr(par->state.vgabase, 0x33, 0x00); 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci if (info->var.vmode & FB_VMODE_DOUBLE) 6968c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80); 6978c2ecf20Sopenharmony_ci else 6988c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80); 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci if (info->var.vmode & FB_VMODE_INTERLACED) 7018c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x42, 0x20, 0x20); 7028c2ecf20Sopenharmony_ci else 7038c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x42, 0x00, 0x20); 7048c2ecf20Sopenharmony_ci 7058c2ecf20Sopenharmony_ci /* Disable hardware graphics cursor */ 7068c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x45, 0x00, 0x01); 7078c2ecf20Sopenharmony_ci /* Disable Streams engine */ 7088c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0x0C); 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix)); 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci /* S3 virge DX hack */ 7138c2ecf20Sopenharmony_ci if (par->chip == CHIP_375_VIRGE_DX) { 7148c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x86, 0x80); 7158c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x90, 0x00); 7168c2ecf20Sopenharmony_ci } 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_ci /* S3 virge VX hack */ 7198c2ecf20Sopenharmony_ci if (par->chip == CHIP_988_VIRGE_VX) { 7208c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x50, 0x00); 7218c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x67, 0x50); 7228c2ecf20Sopenharmony_ci msleep(10); /* screen remains blank sometimes without this */ 7238c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x63, (mode <= 2) ? 0x90 : 0x09); 7248c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x66, 0x90); 7258c2ecf20Sopenharmony_ci } 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci if (par->chip == CHIP_357_VIRGE_GX2 || 7288c2ecf20Sopenharmony_ci par->chip == CHIP_359_VIRGE_GX2P || 7298c2ecf20Sopenharmony_ci par->chip == CHIP_360_TRIO3D_1X || 7308c2ecf20Sopenharmony_ci par->chip == CHIP_362_TRIO3D_2X || 7318c2ecf20Sopenharmony_ci par->chip == CHIP_368_TRIO3D_2X || 7328c2ecf20Sopenharmony_ci par->chip == CHIP_365_TRIO3D || 7338c2ecf20Sopenharmony_ci par->chip == CHIP_375_VIRGE_DX || 7348c2ecf20Sopenharmony_ci par->chip == CHIP_385_VIRGE_GX || 7358c2ecf20Sopenharmony_ci par->chip == CHIP_260_VIRGE_MX) { 7368c2ecf20Sopenharmony_ci dbytes = info->var.xres * ((bpp+7)/8); 7378c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x91, (dbytes + 7) / 8); 7388c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x90, (((dbytes + 7) / 8) >> 8) | 0x80); 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x66, 0x81); 7418c2ecf20Sopenharmony_ci } 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci if (par->chip == CHIP_357_VIRGE_GX2 || 7448c2ecf20Sopenharmony_ci par->chip == CHIP_359_VIRGE_GX2P || 7458c2ecf20Sopenharmony_ci par->chip == CHIP_360_TRIO3D_1X || 7468c2ecf20Sopenharmony_ci par->chip == CHIP_362_TRIO3D_2X || 7478c2ecf20Sopenharmony_ci par->chip == CHIP_368_TRIO3D_2X || 7488c2ecf20Sopenharmony_ci par->chip == CHIP_260_VIRGE_MX) 7498c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x34, 0x00); 7508c2ecf20Sopenharmony_ci else /* enable Data Transfer Position Control (DTPC) */ 7518c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x34, 0x10); 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x31, 0x00, 0x40); 7548c2ecf20Sopenharmony_ci multiplex = 0; 7558c2ecf20Sopenharmony_ci hmul = 1; 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ci /* Set mode-specific register values */ 7588c2ecf20Sopenharmony_ci switch (mode) { 7598c2ecf20Sopenharmony_ci case 0: 7608c2ecf20Sopenharmony_ci fb_dbg(info, "text mode\n"); 7618c2ecf20Sopenharmony_ci svga_set_textmode_vga_regs(par->state.vgabase); 7628c2ecf20Sopenharmony_ci 7638c2ecf20Sopenharmony_ci /* Set additional registers like in 8-bit mode */ 7648c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30); 7658c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0); 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ci /* Disable enhanced mode */ 7688c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30); 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci if (fasttext) { 7718c2ecf20Sopenharmony_ci fb_dbg(info, "high speed text mode set\n"); 7728c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x31, 0x40, 0x40); 7738c2ecf20Sopenharmony_ci } 7748c2ecf20Sopenharmony_ci break; 7758c2ecf20Sopenharmony_ci case 1: 7768c2ecf20Sopenharmony_ci fb_dbg(info, "4 bit pseudocolor\n"); 7778c2ecf20Sopenharmony_ci vga_wgfx(par->state.vgabase, VGA_GFX_MODE, 0x40); 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci /* Set additional registers like in 8-bit mode */ 7808c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30); 7818c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0); 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci /* disable enhanced mode */ 7848c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30); 7858c2ecf20Sopenharmony_ci break; 7868c2ecf20Sopenharmony_ci case 2: 7878c2ecf20Sopenharmony_ci fb_dbg(info, "4 bit pseudocolor, planar\n"); 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci /* Set additional registers like in 8-bit mode */ 7908c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30); 7918c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0); 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_ci /* disable enhanced mode */ 7948c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30); 7958c2ecf20Sopenharmony_ci break; 7968c2ecf20Sopenharmony_ci case 3: 7978c2ecf20Sopenharmony_ci fb_dbg(info, "8 bit pseudocolor\n"); 7988c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30); 7998c2ecf20Sopenharmony_ci if (info->var.pixclock > 20000 || 8008c2ecf20Sopenharmony_ci par->chip == CHIP_357_VIRGE_GX2 || 8018c2ecf20Sopenharmony_ci par->chip == CHIP_359_VIRGE_GX2P || 8028c2ecf20Sopenharmony_ci par->chip == CHIP_360_TRIO3D_1X || 8038c2ecf20Sopenharmony_ci par->chip == CHIP_362_TRIO3D_2X || 8048c2ecf20Sopenharmony_ci par->chip == CHIP_368_TRIO3D_2X || 8058c2ecf20Sopenharmony_ci par->chip == CHIP_260_VIRGE_MX) 8068c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0); 8078c2ecf20Sopenharmony_ci else { 8088c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x10, 0xF0); 8098c2ecf20Sopenharmony_ci multiplex = 1; 8108c2ecf20Sopenharmony_ci } 8118c2ecf20Sopenharmony_ci break; 8128c2ecf20Sopenharmony_ci case 4: 8138c2ecf20Sopenharmony_ci fb_dbg(info, "5/5/5 truecolor\n"); 8148c2ecf20Sopenharmony_ci if (par->chip == CHIP_988_VIRGE_VX) { 8158c2ecf20Sopenharmony_ci if (info->var.pixclock > 20000) 8168c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0); 8178c2ecf20Sopenharmony_ci else 8188c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0); 8198c2ecf20Sopenharmony_ci } else if (par->chip == CHIP_365_TRIO3D) { 8208c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30); 8218c2ecf20Sopenharmony_ci if (info->var.pixclock > 8695) { 8228c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0); 8238c2ecf20Sopenharmony_ci hmul = 2; 8248c2ecf20Sopenharmony_ci } else { 8258c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0); 8268c2ecf20Sopenharmony_ci multiplex = 1; 8278c2ecf20Sopenharmony_ci } 8288c2ecf20Sopenharmony_ci } else { 8298c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30); 8308c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0); 8318c2ecf20Sopenharmony_ci if (par->chip != CHIP_357_VIRGE_GX2 && 8328c2ecf20Sopenharmony_ci par->chip != CHIP_359_VIRGE_GX2P && 8338c2ecf20Sopenharmony_ci par->chip != CHIP_360_TRIO3D_1X && 8348c2ecf20Sopenharmony_ci par->chip != CHIP_362_TRIO3D_2X && 8358c2ecf20Sopenharmony_ci par->chip != CHIP_368_TRIO3D_2X && 8368c2ecf20Sopenharmony_ci par->chip != CHIP_260_VIRGE_MX) 8378c2ecf20Sopenharmony_ci hmul = 2; 8388c2ecf20Sopenharmony_ci } 8398c2ecf20Sopenharmony_ci break; 8408c2ecf20Sopenharmony_ci case 5: 8418c2ecf20Sopenharmony_ci fb_dbg(info, "5/6/5 truecolor\n"); 8428c2ecf20Sopenharmony_ci if (par->chip == CHIP_988_VIRGE_VX) { 8438c2ecf20Sopenharmony_ci if (info->var.pixclock > 20000) 8448c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0); 8458c2ecf20Sopenharmony_ci else 8468c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0); 8478c2ecf20Sopenharmony_ci } else if (par->chip == CHIP_365_TRIO3D) { 8488c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30); 8498c2ecf20Sopenharmony_ci if (info->var.pixclock > 8695) { 8508c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0); 8518c2ecf20Sopenharmony_ci hmul = 2; 8528c2ecf20Sopenharmony_ci } else { 8538c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0); 8548c2ecf20Sopenharmony_ci multiplex = 1; 8558c2ecf20Sopenharmony_ci } 8568c2ecf20Sopenharmony_ci } else { 8578c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30); 8588c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0); 8598c2ecf20Sopenharmony_ci if (par->chip != CHIP_357_VIRGE_GX2 && 8608c2ecf20Sopenharmony_ci par->chip != CHIP_359_VIRGE_GX2P && 8618c2ecf20Sopenharmony_ci par->chip != CHIP_360_TRIO3D_1X && 8628c2ecf20Sopenharmony_ci par->chip != CHIP_362_TRIO3D_2X && 8638c2ecf20Sopenharmony_ci par->chip != CHIP_368_TRIO3D_2X && 8648c2ecf20Sopenharmony_ci par->chip != CHIP_260_VIRGE_MX) 8658c2ecf20Sopenharmony_ci hmul = 2; 8668c2ecf20Sopenharmony_ci } 8678c2ecf20Sopenharmony_ci break; 8688c2ecf20Sopenharmony_ci case 6: 8698c2ecf20Sopenharmony_ci /* VIRGE VX case */ 8708c2ecf20Sopenharmony_ci fb_dbg(info, "8/8/8 truecolor\n"); 8718c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0); 8728c2ecf20Sopenharmony_ci break; 8738c2ecf20Sopenharmony_ci case 7: 8748c2ecf20Sopenharmony_ci fb_dbg(info, "8/8/8/8 truecolor\n"); 8758c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x50, 0x30, 0x30); 8768c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0); 8778c2ecf20Sopenharmony_ci break; 8788c2ecf20Sopenharmony_ci default: 8798c2ecf20Sopenharmony_ci fb_err(info, "unsupported mode - bug\n"); 8808c2ecf20Sopenharmony_ci return -EINVAL; 8818c2ecf20Sopenharmony_ci } 8828c2ecf20Sopenharmony_ci 8838c2ecf20Sopenharmony_ci if (par->chip != CHIP_988_VIRGE_VX) { 8848c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x15, multiplex ? 0x10 : 0x00, 0x10); 8858c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x18, multiplex ? 0x80 : 0x00, 0x80); 8868c2ecf20Sopenharmony_ci } 8878c2ecf20Sopenharmony_ci 8888c2ecf20Sopenharmony_ci s3_set_pixclock(info, info->var.pixclock); 8898c2ecf20Sopenharmony_ci svga_set_timings(par->state.vgabase, &s3_timing_regs, &(info->var), hmul, 1, 8908c2ecf20Sopenharmony_ci (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1, 8918c2ecf20Sopenharmony_ci (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1, 8928c2ecf20Sopenharmony_ci hmul, info->node); 8938c2ecf20Sopenharmony_ci 8948c2ecf20Sopenharmony_ci /* Set interlaced mode start/end register */ 8958c2ecf20Sopenharmony_ci htotal = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len; 8968c2ecf20Sopenharmony_ci htotal = ((htotal * hmul) / 8) - 5; 8978c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x3C, (htotal + 1) / 2); 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ci /* Set Data Transfer Position */ 9008c2ecf20Sopenharmony_ci hsstart = ((info->var.xres + info->var.right_margin) * hmul) / 8; 9018c2ecf20Sopenharmony_ci /* + 2 is needed for Virge/VX, does no harm on other cards */ 9028c2ecf20Sopenharmony_ci value = clamp((htotal + hsstart + 1) / 2 + 2, hsstart + 4, htotal + 1); 9038c2ecf20Sopenharmony_ci svga_wcrt_multi(par->state.vgabase, s3_dtpc_regs, value); 9048c2ecf20Sopenharmony_ci 9058c2ecf20Sopenharmony_ci if (screen_size > info->screen_size) 9068c2ecf20Sopenharmony_ci screen_size = info->screen_size; 9078c2ecf20Sopenharmony_ci memset_io(info->screen_base, 0x00, screen_size); 9088c2ecf20Sopenharmony_ci /* Device and screen back on */ 9098c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80); 9108c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20); 9118c2ecf20Sopenharmony_ci 9128c2ecf20Sopenharmony_ci return 0; 9138c2ecf20Sopenharmony_ci} 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ci/* Set a colour register */ 9168c2ecf20Sopenharmony_ci 9178c2ecf20Sopenharmony_cistatic int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, 9188c2ecf20Sopenharmony_ci u_int transp, struct fb_info *fb) 9198c2ecf20Sopenharmony_ci{ 9208c2ecf20Sopenharmony_ci switch (fb->var.bits_per_pixel) { 9218c2ecf20Sopenharmony_ci case 0: 9228c2ecf20Sopenharmony_ci case 4: 9238c2ecf20Sopenharmony_ci if (regno >= 16) 9248c2ecf20Sopenharmony_ci return -EINVAL; 9258c2ecf20Sopenharmony_ci 9268c2ecf20Sopenharmony_ci if ((fb->var.bits_per_pixel == 4) && 9278c2ecf20Sopenharmony_ci (fb->var.nonstd == 0)) { 9288c2ecf20Sopenharmony_ci outb(0xF0, VGA_PEL_MSK); 9298c2ecf20Sopenharmony_ci outb(regno*16, VGA_PEL_IW); 9308c2ecf20Sopenharmony_ci } else { 9318c2ecf20Sopenharmony_ci outb(0x0F, VGA_PEL_MSK); 9328c2ecf20Sopenharmony_ci outb(regno, VGA_PEL_IW); 9338c2ecf20Sopenharmony_ci } 9348c2ecf20Sopenharmony_ci outb(red >> 10, VGA_PEL_D); 9358c2ecf20Sopenharmony_ci outb(green >> 10, VGA_PEL_D); 9368c2ecf20Sopenharmony_ci outb(blue >> 10, VGA_PEL_D); 9378c2ecf20Sopenharmony_ci break; 9388c2ecf20Sopenharmony_ci case 8: 9398c2ecf20Sopenharmony_ci if (regno >= 256) 9408c2ecf20Sopenharmony_ci return -EINVAL; 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_ci outb(0xFF, VGA_PEL_MSK); 9438c2ecf20Sopenharmony_ci outb(regno, VGA_PEL_IW); 9448c2ecf20Sopenharmony_ci outb(red >> 10, VGA_PEL_D); 9458c2ecf20Sopenharmony_ci outb(green >> 10, VGA_PEL_D); 9468c2ecf20Sopenharmony_ci outb(blue >> 10, VGA_PEL_D); 9478c2ecf20Sopenharmony_ci break; 9488c2ecf20Sopenharmony_ci case 16: 9498c2ecf20Sopenharmony_ci if (regno >= 16) 9508c2ecf20Sopenharmony_ci return 0; 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_ci if (fb->var.green.length == 5) 9538c2ecf20Sopenharmony_ci ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) | 9548c2ecf20Sopenharmony_ci ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11); 9558c2ecf20Sopenharmony_ci else if (fb->var.green.length == 6) 9568c2ecf20Sopenharmony_ci ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) | 9578c2ecf20Sopenharmony_ci ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11); 9588c2ecf20Sopenharmony_ci else return -EINVAL; 9598c2ecf20Sopenharmony_ci break; 9608c2ecf20Sopenharmony_ci case 24: 9618c2ecf20Sopenharmony_ci case 32: 9628c2ecf20Sopenharmony_ci if (regno >= 16) 9638c2ecf20Sopenharmony_ci return 0; 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ci ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) | 9668c2ecf20Sopenharmony_ci (green & 0xFF00) | ((blue & 0xFF00) >> 8); 9678c2ecf20Sopenharmony_ci break; 9688c2ecf20Sopenharmony_ci default: 9698c2ecf20Sopenharmony_ci return -EINVAL; 9708c2ecf20Sopenharmony_ci } 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci return 0; 9738c2ecf20Sopenharmony_ci} 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ci 9768c2ecf20Sopenharmony_ci/* Set the display blanking state */ 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_cistatic int s3fb_blank(int blank_mode, struct fb_info *info) 9798c2ecf20Sopenharmony_ci{ 9808c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 9818c2ecf20Sopenharmony_ci 9828c2ecf20Sopenharmony_ci switch (blank_mode) { 9838c2ecf20Sopenharmony_ci case FB_BLANK_UNBLANK: 9848c2ecf20Sopenharmony_ci fb_dbg(info, "unblank\n"); 9858c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06); 9868c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20); 9878c2ecf20Sopenharmony_ci break; 9888c2ecf20Sopenharmony_ci case FB_BLANK_NORMAL: 9898c2ecf20Sopenharmony_ci fb_dbg(info, "blank\n"); 9908c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06); 9918c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); 9928c2ecf20Sopenharmony_ci break; 9938c2ecf20Sopenharmony_ci case FB_BLANK_HSYNC_SUSPEND: 9948c2ecf20Sopenharmony_ci fb_dbg(info, "hsync\n"); 9958c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x56, 0x02, 0x06); 9968c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); 9978c2ecf20Sopenharmony_ci break; 9988c2ecf20Sopenharmony_ci case FB_BLANK_VSYNC_SUSPEND: 9998c2ecf20Sopenharmony_ci fb_dbg(info, "vsync\n"); 10008c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x56, 0x04, 0x06); 10018c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); 10028c2ecf20Sopenharmony_ci break; 10038c2ecf20Sopenharmony_ci case FB_BLANK_POWERDOWN: 10048c2ecf20Sopenharmony_ci fb_dbg(info, "sync down\n"); 10058c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x56, 0x06, 0x06); 10068c2ecf20Sopenharmony_ci svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); 10078c2ecf20Sopenharmony_ci break; 10088c2ecf20Sopenharmony_ci } 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_ci return 0; 10118c2ecf20Sopenharmony_ci} 10128c2ecf20Sopenharmony_ci 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci/* Pan the display */ 10158c2ecf20Sopenharmony_ci 10168c2ecf20Sopenharmony_cistatic int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) 10178c2ecf20Sopenharmony_ci{ 10188c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 10198c2ecf20Sopenharmony_ci unsigned int offset; 10208c2ecf20Sopenharmony_ci 10218c2ecf20Sopenharmony_ci /* Calculate the offset */ 10228c2ecf20Sopenharmony_ci if (info->var.bits_per_pixel == 0) { 10238c2ecf20Sopenharmony_ci offset = (var->yoffset / 16) * (info->var.xres_virtual / 2) 10248c2ecf20Sopenharmony_ci + (var->xoffset / 2); 10258c2ecf20Sopenharmony_ci offset = offset >> 2; 10268c2ecf20Sopenharmony_ci } else { 10278c2ecf20Sopenharmony_ci offset = (var->yoffset * info->fix.line_length) + 10288c2ecf20Sopenharmony_ci (var->xoffset * info->var.bits_per_pixel / 8); 10298c2ecf20Sopenharmony_ci offset = offset >> 2; 10308c2ecf20Sopenharmony_ci } 10318c2ecf20Sopenharmony_ci 10328c2ecf20Sopenharmony_ci /* Set the offset */ 10338c2ecf20Sopenharmony_ci svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, offset); 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci return 0; 10368c2ecf20Sopenharmony_ci} 10378c2ecf20Sopenharmony_ci 10388c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */ 10398c2ecf20Sopenharmony_ci 10408c2ecf20Sopenharmony_ci/* Frame buffer operations */ 10418c2ecf20Sopenharmony_ci 10428c2ecf20Sopenharmony_cistatic const struct fb_ops s3fb_ops = { 10438c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 10448c2ecf20Sopenharmony_ci .fb_open = s3fb_open, 10458c2ecf20Sopenharmony_ci .fb_release = s3fb_release, 10468c2ecf20Sopenharmony_ci .fb_check_var = s3fb_check_var, 10478c2ecf20Sopenharmony_ci .fb_set_par = s3fb_set_par, 10488c2ecf20Sopenharmony_ci .fb_setcolreg = s3fb_setcolreg, 10498c2ecf20Sopenharmony_ci .fb_blank = s3fb_blank, 10508c2ecf20Sopenharmony_ci .fb_pan_display = s3fb_pan_display, 10518c2ecf20Sopenharmony_ci .fb_fillrect = s3fb_fillrect, 10528c2ecf20Sopenharmony_ci .fb_copyarea = cfb_copyarea, 10538c2ecf20Sopenharmony_ci .fb_imageblit = s3fb_imageblit, 10548c2ecf20Sopenharmony_ci .fb_get_caps = svga_get_caps, 10558c2ecf20Sopenharmony_ci}; 10568c2ecf20Sopenharmony_ci 10578c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */ 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_cistatic int s3_identification(struct s3fb_info *par) 10608c2ecf20Sopenharmony_ci{ 10618c2ecf20Sopenharmony_ci int chip = par->chip; 10628c2ecf20Sopenharmony_ci 10638c2ecf20Sopenharmony_ci if (chip == CHIP_XXX_TRIO) { 10648c2ecf20Sopenharmony_ci u8 cr30 = vga_rcrt(par->state.vgabase, 0x30); 10658c2ecf20Sopenharmony_ci u8 cr2e = vga_rcrt(par->state.vgabase, 0x2e); 10668c2ecf20Sopenharmony_ci u8 cr2f = vga_rcrt(par->state.vgabase, 0x2f); 10678c2ecf20Sopenharmony_ci 10688c2ecf20Sopenharmony_ci if ((cr30 == 0xE0) || (cr30 == 0xE1)) { 10698c2ecf20Sopenharmony_ci if (cr2e == 0x10) 10708c2ecf20Sopenharmony_ci return CHIP_732_TRIO32; 10718c2ecf20Sopenharmony_ci if (cr2e == 0x11) { 10728c2ecf20Sopenharmony_ci if (! (cr2f & 0x40)) 10738c2ecf20Sopenharmony_ci return CHIP_764_TRIO64; 10748c2ecf20Sopenharmony_ci else 10758c2ecf20Sopenharmony_ci return CHIP_765_TRIO64VP; 10768c2ecf20Sopenharmony_ci } 10778c2ecf20Sopenharmony_ci } 10788c2ecf20Sopenharmony_ci } 10798c2ecf20Sopenharmony_ci 10808c2ecf20Sopenharmony_ci if (chip == CHIP_XXX_TRIO64V2_DXGX) { 10818c2ecf20Sopenharmony_ci u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f); 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_ci if (! (cr6f & 0x01)) 10848c2ecf20Sopenharmony_ci return CHIP_775_TRIO64V2_DX; 10858c2ecf20Sopenharmony_ci else 10868c2ecf20Sopenharmony_ci return CHIP_785_TRIO64V2_GX; 10878c2ecf20Sopenharmony_ci } 10888c2ecf20Sopenharmony_ci 10898c2ecf20Sopenharmony_ci if (chip == CHIP_XXX_VIRGE_DXGX) { 10908c2ecf20Sopenharmony_ci u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f); 10918c2ecf20Sopenharmony_ci 10928c2ecf20Sopenharmony_ci if (! (cr6f & 0x01)) 10938c2ecf20Sopenharmony_ci return CHIP_375_VIRGE_DX; 10948c2ecf20Sopenharmony_ci else 10958c2ecf20Sopenharmony_ci return CHIP_385_VIRGE_GX; 10968c2ecf20Sopenharmony_ci } 10978c2ecf20Sopenharmony_ci 10988c2ecf20Sopenharmony_ci if (chip == CHIP_36X_TRIO3D_1X_2X) { 10998c2ecf20Sopenharmony_ci switch (vga_rcrt(par->state.vgabase, 0x2f)) { 11008c2ecf20Sopenharmony_ci case 0x00: 11018c2ecf20Sopenharmony_ci return CHIP_360_TRIO3D_1X; 11028c2ecf20Sopenharmony_ci case 0x01: 11038c2ecf20Sopenharmony_ci return CHIP_362_TRIO3D_2X; 11048c2ecf20Sopenharmony_ci case 0x02: 11058c2ecf20Sopenharmony_ci return CHIP_368_TRIO3D_2X; 11068c2ecf20Sopenharmony_ci } 11078c2ecf20Sopenharmony_ci } 11088c2ecf20Sopenharmony_ci 11098c2ecf20Sopenharmony_ci return CHIP_UNKNOWN; 11108c2ecf20Sopenharmony_ci} 11118c2ecf20Sopenharmony_ci 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_ci/* PCI probe */ 11148c2ecf20Sopenharmony_ci 11158c2ecf20Sopenharmony_cistatic int s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 11168c2ecf20Sopenharmony_ci{ 11178c2ecf20Sopenharmony_ci struct pci_bus_region bus_reg; 11188c2ecf20Sopenharmony_ci struct resource vga_res; 11198c2ecf20Sopenharmony_ci struct fb_info *info; 11208c2ecf20Sopenharmony_ci struct s3fb_info *par; 11218c2ecf20Sopenharmony_ci int rc; 11228c2ecf20Sopenharmony_ci u8 regval, cr38, cr39; 11238c2ecf20Sopenharmony_ci bool found = false; 11248c2ecf20Sopenharmony_ci 11258c2ecf20Sopenharmony_ci /* Ignore secondary VGA device because there is no VGA arbitration */ 11268c2ecf20Sopenharmony_ci if (! svga_primary_device(dev)) { 11278c2ecf20Sopenharmony_ci dev_info(&(dev->dev), "ignoring secondary device\n"); 11288c2ecf20Sopenharmony_ci return -ENODEV; 11298c2ecf20Sopenharmony_ci } 11308c2ecf20Sopenharmony_ci 11318c2ecf20Sopenharmony_ci /* Allocate and fill driver data structure */ 11328c2ecf20Sopenharmony_ci info = framebuffer_alloc(sizeof(struct s3fb_info), &(dev->dev)); 11338c2ecf20Sopenharmony_ci if (!info) 11348c2ecf20Sopenharmony_ci return -ENOMEM; 11358c2ecf20Sopenharmony_ci 11368c2ecf20Sopenharmony_ci par = info->par; 11378c2ecf20Sopenharmony_ci mutex_init(&par->open_lock); 11388c2ecf20Sopenharmony_ci 11398c2ecf20Sopenharmony_ci info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN; 11408c2ecf20Sopenharmony_ci info->fbops = &s3fb_ops; 11418c2ecf20Sopenharmony_ci 11428c2ecf20Sopenharmony_ci /* Prepare PCI device */ 11438c2ecf20Sopenharmony_ci rc = pci_enable_device(dev); 11448c2ecf20Sopenharmony_ci if (rc < 0) { 11458c2ecf20Sopenharmony_ci dev_err(info->device, "cannot enable PCI device\n"); 11468c2ecf20Sopenharmony_ci goto err_enable_device; 11478c2ecf20Sopenharmony_ci } 11488c2ecf20Sopenharmony_ci 11498c2ecf20Sopenharmony_ci rc = pci_request_regions(dev, "s3fb"); 11508c2ecf20Sopenharmony_ci if (rc < 0) { 11518c2ecf20Sopenharmony_ci dev_err(info->device, "cannot reserve framebuffer region\n"); 11528c2ecf20Sopenharmony_ci goto err_request_regions; 11538c2ecf20Sopenharmony_ci } 11548c2ecf20Sopenharmony_ci 11558c2ecf20Sopenharmony_ci 11568c2ecf20Sopenharmony_ci info->fix.smem_start = pci_resource_start(dev, 0); 11578c2ecf20Sopenharmony_ci info->fix.smem_len = pci_resource_len(dev, 0); 11588c2ecf20Sopenharmony_ci 11598c2ecf20Sopenharmony_ci /* Map physical IO memory address into kernel space */ 11608c2ecf20Sopenharmony_ci info->screen_base = pci_iomap_wc(dev, 0, 0); 11618c2ecf20Sopenharmony_ci if (! info->screen_base) { 11628c2ecf20Sopenharmony_ci rc = -ENOMEM; 11638c2ecf20Sopenharmony_ci dev_err(info->device, "iomap for framebuffer failed\n"); 11648c2ecf20Sopenharmony_ci goto err_iomap; 11658c2ecf20Sopenharmony_ci } 11668c2ecf20Sopenharmony_ci 11678c2ecf20Sopenharmony_ci bus_reg.start = 0; 11688c2ecf20Sopenharmony_ci bus_reg.end = 64 * 1024; 11698c2ecf20Sopenharmony_ci 11708c2ecf20Sopenharmony_ci vga_res.flags = IORESOURCE_IO; 11718c2ecf20Sopenharmony_ci 11728c2ecf20Sopenharmony_ci pcibios_bus_to_resource(dev->bus, &vga_res, &bus_reg); 11738c2ecf20Sopenharmony_ci 11748c2ecf20Sopenharmony_ci par->state.vgabase = (void __iomem *) (unsigned long) vga_res.start; 11758c2ecf20Sopenharmony_ci 11768c2ecf20Sopenharmony_ci /* Unlock regs */ 11778c2ecf20Sopenharmony_ci cr38 = vga_rcrt(par->state.vgabase, 0x38); 11788c2ecf20Sopenharmony_ci cr39 = vga_rcrt(par->state.vgabase, 0x39); 11798c2ecf20Sopenharmony_ci vga_wseq(par->state.vgabase, 0x08, 0x06); 11808c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x38, 0x48); 11818c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x39, 0xA5); 11828c2ecf20Sopenharmony_ci 11838c2ecf20Sopenharmony_ci /* Identify chip type */ 11848c2ecf20Sopenharmony_ci par->chip = id->driver_data & CHIP_MASK; 11858c2ecf20Sopenharmony_ci par->rev = vga_rcrt(par->state.vgabase, 0x2f); 11868c2ecf20Sopenharmony_ci if (par->chip & CHIP_UNDECIDED_FLAG) 11878c2ecf20Sopenharmony_ci par->chip = s3_identification(par); 11888c2ecf20Sopenharmony_ci 11898c2ecf20Sopenharmony_ci /* Find how many physical memory there is on card */ 11908c2ecf20Sopenharmony_ci /* 0x36 register is accessible even if other registers are locked */ 11918c2ecf20Sopenharmony_ci regval = vga_rcrt(par->state.vgabase, 0x36); 11928c2ecf20Sopenharmony_ci if (par->chip == CHIP_360_TRIO3D_1X || 11938c2ecf20Sopenharmony_ci par->chip == CHIP_362_TRIO3D_2X || 11948c2ecf20Sopenharmony_ci par->chip == CHIP_368_TRIO3D_2X || 11958c2ecf20Sopenharmony_ci par->chip == CHIP_365_TRIO3D) { 11968c2ecf20Sopenharmony_ci switch ((regval & 0xE0) >> 5) { 11978c2ecf20Sopenharmony_ci case 0: /* 8MB -- only 4MB usable for display */ 11988c2ecf20Sopenharmony_ci case 1: /* 4MB with 32-bit bus */ 11998c2ecf20Sopenharmony_ci case 2: /* 4MB */ 12008c2ecf20Sopenharmony_ci info->screen_size = 4 << 20; 12018c2ecf20Sopenharmony_ci break; 12028c2ecf20Sopenharmony_ci case 4: /* 2MB on 365 Trio3D */ 12038c2ecf20Sopenharmony_ci case 6: /* 2MB */ 12048c2ecf20Sopenharmony_ci info->screen_size = 2 << 20; 12058c2ecf20Sopenharmony_ci break; 12068c2ecf20Sopenharmony_ci } 12078c2ecf20Sopenharmony_ci } else if (par->chip == CHIP_357_VIRGE_GX2 || 12088c2ecf20Sopenharmony_ci par->chip == CHIP_359_VIRGE_GX2P || 12098c2ecf20Sopenharmony_ci par->chip == CHIP_260_VIRGE_MX) { 12108c2ecf20Sopenharmony_ci switch ((regval & 0xC0) >> 6) { 12118c2ecf20Sopenharmony_ci case 1: /* 4MB */ 12128c2ecf20Sopenharmony_ci info->screen_size = 4 << 20; 12138c2ecf20Sopenharmony_ci break; 12148c2ecf20Sopenharmony_ci case 3: /* 2MB */ 12158c2ecf20Sopenharmony_ci info->screen_size = 2 << 20; 12168c2ecf20Sopenharmony_ci break; 12178c2ecf20Sopenharmony_ci } 12188c2ecf20Sopenharmony_ci } else if (par->chip == CHIP_988_VIRGE_VX) { 12198c2ecf20Sopenharmony_ci switch ((regval & 0x60) >> 5) { 12208c2ecf20Sopenharmony_ci case 0: /* 2MB */ 12218c2ecf20Sopenharmony_ci info->screen_size = 2 << 20; 12228c2ecf20Sopenharmony_ci break; 12238c2ecf20Sopenharmony_ci case 1: /* 4MB */ 12248c2ecf20Sopenharmony_ci info->screen_size = 4 << 20; 12258c2ecf20Sopenharmony_ci break; 12268c2ecf20Sopenharmony_ci case 2: /* 6MB */ 12278c2ecf20Sopenharmony_ci info->screen_size = 6 << 20; 12288c2ecf20Sopenharmony_ci break; 12298c2ecf20Sopenharmony_ci case 3: /* 8MB */ 12308c2ecf20Sopenharmony_ci info->screen_size = 8 << 20; 12318c2ecf20Sopenharmony_ci break; 12328c2ecf20Sopenharmony_ci } 12338c2ecf20Sopenharmony_ci /* off-screen memory */ 12348c2ecf20Sopenharmony_ci regval = vga_rcrt(par->state.vgabase, 0x37); 12358c2ecf20Sopenharmony_ci switch ((regval & 0x60) >> 5) { 12368c2ecf20Sopenharmony_ci case 1: /* 4MB */ 12378c2ecf20Sopenharmony_ci info->screen_size -= 4 << 20; 12388c2ecf20Sopenharmony_ci break; 12398c2ecf20Sopenharmony_ci case 2: /* 2MB */ 12408c2ecf20Sopenharmony_ci info->screen_size -= 2 << 20; 12418c2ecf20Sopenharmony_ci break; 12428c2ecf20Sopenharmony_ci } 12438c2ecf20Sopenharmony_ci } else 12448c2ecf20Sopenharmony_ci info->screen_size = s3_memsizes[regval >> 5] << 10; 12458c2ecf20Sopenharmony_ci info->fix.smem_len = info->screen_size; 12468c2ecf20Sopenharmony_ci 12478c2ecf20Sopenharmony_ci /* Find MCLK frequency */ 12488c2ecf20Sopenharmony_ci regval = vga_rseq(par->state.vgabase, 0x10); 12498c2ecf20Sopenharmony_ci par->mclk_freq = ((vga_rseq(par->state.vgabase, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2); 12508c2ecf20Sopenharmony_ci par->mclk_freq = par->mclk_freq >> (regval >> 5); 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci /* Restore locks */ 12538c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x38, cr38); 12548c2ecf20Sopenharmony_ci vga_wcrt(par->state.vgabase, 0x39, cr39); 12558c2ecf20Sopenharmony_ci 12568c2ecf20Sopenharmony_ci strcpy(info->fix.id, s3_names [par->chip]); 12578c2ecf20Sopenharmony_ci info->fix.mmio_start = 0; 12588c2ecf20Sopenharmony_ci info->fix.mmio_len = 0; 12598c2ecf20Sopenharmony_ci info->fix.type = FB_TYPE_PACKED_PIXELS; 12608c2ecf20Sopenharmony_ci info->fix.visual = FB_VISUAL_PSEUDOCOLOR; 12618c2ecf20Sopenharmony_ci info->fix.ypanstep = 0; 12628c2ecf20Sopenharmony_ci info->fix.accel = FB_ACCEL_NONE; 12638c2ecf20Sopenharmony_ci info->pseudo_palette = (void*) (par->pseudo_palette); 12648c2ecf20Sopenharmony_ci info->var.bits_per_pixel = 8; 12658c2ecf20Sopenharmony_ci 12668c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_S3_DDC 12678c2ecf20Sopenharmony_ci /* Enable MMIO if needed */ 12688c2ecf20Sopenharmony_ci if (s3fb_ddc_needs_mmio(par->chip)) { 12698c2ecf20Sopenharmony_ci par->mmio = ioremap(info->fix.smem_start + MMIO_OFFSET, MMIO_SIZE); 12708c2ecf20Sopenharmony_ci if (par->mmio) 12718c2ecf20Sopenharmony_ci svga_wcrt_mask(par->state.vgabase, 0x53, 0x08, 0x08); /* enable MMIO */ 12728c2ecf20Sopenharmony_ci else 12738c2ecf20Sopenharmony_ci dev_err(info->device, "unable to map MMIO at 0x%lx, disabling DDC", 12748c2ecf20Sopenharmony_ci info->fix.smem_start + MMIO_OFFSET); 12758c2ecf20Sopenharmony_ci } 12768c2ecf20Sopenharmony_ci if (!s3fb_ddc_needs_mmio(par->chip) || par->mmio) 12778c2ecf20Sopenharmony_ci if (s3fb_setup_ddc_bus(info) == 0) { 12788c2ecf20Sopenharmony_ci u8 *edid = fb_ddc_read(&par->ddc_adapter); 12798c2ecf20Sopenharmony_ci par->ddc_registered = true; 12808c2ecf20Sopenharmony_ci if (edid) { 12818c2ecf20Sopenharmony_ci fb_edid_to_monspecs(edid, &info->monspecs); 12828c2ecf20Sopenharmony_ci kfree(edid); 12838c2ecf20Sopenharmony_ci if (!info->monspecs.modedb) 12848c2ecf20Sopenharmony_ci dev_err(info->device, "error getting mode database\n"); 12858c2ecf20Sopenharmony_ci else { 12868c2ecf20Sopenharmony_ci const struct fb_videomode *m; 12878c2ecf20Sopenharmony_ci 12888c2ecf20Sopenharmony_ci fb_videomode_to_modelist(info->monspecs.modedb, 12898c2ecf20Sopenharmony_ci info->monspecs.modedb_len, 12908c2ecf20Sopenharmony_ci &info->modelist); 12918c2ecf20Sopenharmony_ci m = fb_find_best_display(&info->monspecs, &info->modelist); 12928c2ecf20Sopenharmony_ci if (m) { 12938c2ecf20Sopenharmony_ci fb_videomode_to_var(&info->var, m); 12948c2ecf20Sopenharmony_ci /* fill all other info->var's fields */ 12958c2ecf20Sopenharmony_ci if (s3fb_check_var(&info->var, info) == 0) 12968c2ecf20Sopenharmony_ci found = true; 12978c2ecf20Sopenharmony_ci } 12988c2ecf20Sopenharmony_ci } 12998c2ecf20Sopenharmony_ci } 13008c2ecf20Sopenharmony_ci } 13018c2ecf20Sopenharmony_ci#endif 13028c2ecf20Sopenharmony_ci if (!mode_option && !found) 13038c2ecf20Sopenharmony_ci mode_option = "640x480-8@60"; 13048c2ecf20Sopenharmony_ci 13058c2ecf20Sopenharmony_ci /* Prepare startup mode */ 13068c2ecf20Sopenharmony_ci if (mode_option) { 13078c2ecf20Sopenharmony_ci rc = fb_find_mode(&info->var, info, mode_option, 13088c2ecf20Sopenharmony_ci info->monspecs.modedb, info->monspecs.modedb_len, 13098c2ecf20Sopenharmony_ci NULL, info->var.bits_per_pixel); 13108c2ecf20Sopenharmony_ci if (!rc || rc == 4) { 13118c2ecf20Sopenharmony_ci rc = -EINVAL; 13128c2ecf20Sopenharmony_ci dev_err(info->device, "mode %s not found\n", mode_option); 13138c2ecf20Sopenharmony_ci fb_destroy_modedb(info->monspecs.modedb); 13148c2ecf20Sopenharmony_ci info->monspecs.modedb = NULL; 13158c2ecf20Sopenharmony_ci goto err_find_mode; 13168c2ecf20Sopenharmony_ci } 13178c2ecf20Sopenharmony_ci } 13188c2ecf20Sopenharmony_ci 13198c2ecf20Sopenharmony_ci fb_destroy_modedb(info->monspecs.modedb); 13208c2ecf20Sopenharmony_ci info->monspecs.modedb = NULL; 13218c2ecf20Sopenharmony_ci 13228c2ecf20Sopenharmony_ci /* maximize virtual vertical size for fast scrolling */ 13238c2ecf20Sopenharmony_ci info->var.yres_virtual = info->fix.smem_len * 8 / 13248c2ecf20Sopenharmony_ci (info->var.bits_per_pixel * info->var.xres_virtual); 13258c2ecf20Sopenharmony_ci if (info->var.yres_virtual < info->var.yres) { 13268c2ecf20Sopenharmony_ci dev_err(info->device, "virtual vertical size smaller than real\n"); 13278c2ecf20Sopenharmony_ci rc = -EINVAL; 13288c2ecf20Sopenharmony_ci goto err_find_mode; 13298c2ecf20Sopenharmony_ci } 13308c2ecf20Sopenharmony_ci 13318c2ecf20Sopenharmony_ci rc = fb_alloc_cmap(&info->cmap, 256, 0); 13328c2ecf20Sopenharmony_ci if (rc < 0) { 13338c2ecf20Sopenharmony_ci dev_err(info->device, "cannot allocate colormap\n"); 13348c2ecf20Sopenharmony_ci goto err_alloc_cmap; 13358c2ecf20Sopenharmony_ci } 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_ci rc = register_framebuffer(info); 13388c2ecf20Sopenharmony_ci if (rc < 0) { 13398c2ecf20Sopenharmony_ci dev_err(info->device, "cannot register framebuffer\n"); 13408c2ecf20Sopenharmony_ci goto err_reg_fb; 13418c2ecf20Sopenharmony_ci } 13428c2ecf20Sopenharmony_ci 13438c2ecf20Sopenharmony_ci fb_info(info, "%s on %s, %d MB RAM, %d MHz MCLK\n", 13448c2ecf20Sopenharmony_ci info->fix.id, pci_name(dev), 13458c2ecf20Sopenharmony_ci info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000); 13468c2ecf20Sopenharmony_ci 13478c2ecf20Sopenharmony_ci if (par->chip == CHIP_UNKNOWN) 13488c2ecf20Sopenharmony_ci fb_info(info, "unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n", 13498c2ecf20Sopenharmony_ci vga_rcrt(par->state.vgabase, 0x2d), 13508c2ecf20Sopenharmony_ci vga_rcrt(par->state.vgabase, 0x2e), 13518c2ecf20Sopenharmony_ci vga_rcrt(par->state.vgabase, 0x2f), 13528c2ecf20Sopenharmony_ci vga_rcrt(par->state.vgabase, 0x30)); 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci /* Record a reference to the driver data */ 13558c2ecf20Sopenharmony_ci pci_set_drvdata(dev, info); 13568c2ecf20Sopenharmony_ci 13578c2ecf20Sopenharmony_ci if (mtrr) 13588c2ecf20Sopenharmony_ci par->wc_cookie = arch_phys_wc_add(info->fix.smem_start, 13598c2ecf20Sopenharmony_ci info->fix.smem_len); 13608c2ecf20Sopenharmony_ci 13618c2ecf20Sopenharmony_ci return 0; 13628c2ecf20Sopenharmony_ci 13638c2ecf20Sopenharmony_ci /* Error handling */ 13648c2ecf20Sopenharmony_cierr_reg_fb: 13658c2ecf20Sopenharmony_ci fb_dealloc_cmap(&info->cmap); 13668c2ecf20Sopenharmony_cierr_alloc_cmap: 13678c2ecf20Sopenharmony_cierr_find_mode: 13688c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_S3_DDC 13698c2ecf20Sopenharmony_ci if (par->ddc_registered) 13708c2ecf20Sopenharmony_ci i2c_del_adapter(&par->ddc_adapter); 13718c2ecf20Sopenharmony_ci if (par->mmio) 13728c2ecf20Sopenharmony_ci iounmap(par->mmio); 13738c2ecf20Sopenharmony_ci#endif 13748c2ecf20Sopenharmony_ci pci_iounmap(dev, info->screen_base); 13758c2ecf20Sopenharmony_cierr_iomap: 13768c2ecf20Sopenharmony_ci pci_release_regions(dev); 13778c2ecf20Sopenharmony_cierr_request_regions: 13788c2ecf20Sopenharmony_ci/* pci_disable_device(dev); */ 13798c2ecf20Sopenharmony_cierr_enable_device: 13808c2ecf20Sopenharmony_ci framebuffer_release(info); 13818c2ecf20Sopenharmony_ci return rc; 13828c2ecf20Sopenharmony_ci} 13838c2ecf20Sopenharmony_ci 13848c2ecf20Sopenharmony_ci 13858c2ecf20Sopenharmony_ci/* PCI remove */ 13868c2ecf20Sopenharmony_ci 13878c2ecf20Sopenharmony_cistatic void s3_pci_remove(struct pci_dev *dev) 13888c2ecf20Sopenharmony_ci{ 13898c2ecf20Sopenharmony_ci struct fb_info *info = pci_get_drvdata(dev); 13908c2ecf20Sopenharmony_ci struct s3fb_info __maybe_unused *par; 13918c2ecf20Sopenharmony_ci 13928c2ecf20Sopenharmony_ci if (info) { 13938c2ecf20Sopenharmony_ci par = info->par; 13948c2ecf20Sopenharmony_ci arch_phys_wc_del(par->wc_cookie); 13958c2ecf20Sopenharmony_ci unregister_framebuffer(info); 13968c2ecf20Sopenharmony_ci fb_dealloc_cmap(&info->cmap); 13978c2ecf20Sopenharmony_ci 13988c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_S3_DDC 13998c2ecf20Sopenharmony_ci if (par->ddc_registered) 14008c2ecf20Sopenharmony_ci i2c_del_adapter(&par->ddc_adapter); 14018c2ecf20Sopenharmony_ci if (par->mmio) 14028c2ecf20Sopenharmony_ci iounmap(par->mmio); 14038c2ecf20Sopenharmony_ci#endif 14048c2ecf20Sopenharmony_ci 14058c2ecf20Sopenharmony_ci pci_iounmap(dev, info->screen_base); 14068c2ecf20Sopenharmony_ci pci_release_regions(dev); 14078c2ecf20Sopenharmony_ci/* pci_disable_device(dev); */ 14088c2ecf20Sopenharmony_ci 14098c2ecf20Sopenharmony_ci framebuffer_release(info); 14108c2ecf20Sopenharmony_ci } 14118c2ecf20Sopenharmony_ci} 14128c2ecf20Sopenharmony_ci 14138c2ecf20Sopenharmony_ci/* PCI suspend */ 14148c2ecf20Sopenharmony_ci 14158c2ecf20Sopenharmony_cistatic int __maybe_unused s3_pci_suspend(struct device *dev) 14168c2ecf20Sopenharmony_ci{ 14178c2ecf20Sopenharmony_ci struct fb_info *info = dev_get_drvdata(dev); 14188c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 14198c2ecf20Sopenharmony_ci 14208c2ecf20Sopenharmony_ci dev_info(info->device, "suspend\n"); 14218c2ecf20Sopenharmony_ci 14228c2ecf20Sopenharmony_ci console_lock(); 14238c2ecf20Sopenharmony_ci mutex_lock(&(par->open_lock)); 14248c2ecf20Sopenharmony_ci 14258c2ecf20Sopenharmony_ci if (par->ref_count == 0) { 14268c2ecf20Sopenharmony_ci mutex_unlock(&(par->open_lock)); 14278c2ecf20Sopenharmony_ci console_unlock(); 14288c2ecf20Sopenharmony_ci return 0; 14298c2ecf20Sopenharmony_ci } 14308c2ecf20Sopenharmony_ci 14318c2ecf20Sopenharmony_ci fb_set_suspend(info, 1); 14328c2ecf20Sopenharmony_ci 14338c2ecf20Sopenharmony_ci mutex_unlock(&(par->open_lock)); 14348c2ecf20Sopenharmony_ci console_unlock(); 14358c2ecf20Sopenharmony_ci 14368c2ecf20Sopenharmony_ci return 0; 14378c2ecf20Sopenharmony_ci} 14388c2ecf20Sopenharmony_ci 14398c2ecf20Sopenharmony_ci 14408c2ecf20Sopenharmony_ci/* PCI resume */ 14418c2ecf20Sopenharmony_ci 14428c2ecf20Sopenharmony_cistatic int __maybe_unused s3_pci_resume(struct device *dev) 14438c2ecf20Sopenharmony_ci{ 14448c2ecf20Sopenharmony_ci struct fb_info *info = dev_get_drvdata(dev); 14458c2ecf20Sopenharmony_ci struct s3fb_info *par = info->par; 14468c2ecf20Sopenharmony_ci 14478c2ecf20Sopenharmony_ci dev_info(info->device, "resume\n"); 14488c2ecf20Sopenharmony_ci 14498c2ecf20Sopenharmony_ci console_lock(); 14508c2ecf20Sopenharmony_ci mutex_lock(&(par->open_lock)); 14518c2ecf20Sopenharmony_ci 14528c2ecf20Sopenharmony_ci if (par->ref_count == 0) { 14538c2ecf20Sopenharmony_ci mutex_unlock(&(par->open_lock)); 14548c2ecf20Sopenharmony_ci console_unlock(); 14558c2ecf20Sopenharmony_ci return 0; 14568c2ecf20Sopenharmony_ci } 14578c2ecf20Sopenharmony_ci 14588c2ecf20Sopenharmony_ci s3fb_set_par(info); 14598c2ecf20Sopenharmony_ci fb_set_suspend(info, 0); 14608c2ecf20Sopenharmony_ci 14618c2ecf20Sopenharmony_ci mutex_unlock(&(par->open_lock)); 14628c2ecf20Sopenharmony_ci console_unlock(); 14638c2ecf20Sopenharmony_ci 14648c2ecf20Sopenharmony_ci return 0; 14658c2ecf20Sopenharmony_ci} 14668c2ecf20Sopenharmony_ci 14678c2ecf20Sopenharmony_cistatic const struct dev_pm_ops s3_pci_pm_ops = { 14688c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 14698c2ecf20Sopenharmony_ci .suspend = s3_pci_suspend, 14708c2ecf20Sopenharmony_ci .resume = s3_pci_resume, 14718c2ecf20Sopenharmony_ci .freeze = NULL, 14728c2ecf20Sopenharmony_ci .thaw = s3_pci_resume, 14738c2ecf20Sopenharmony_ci .poweroff = s3_pci_suspend, 14748c2ecf20Sopenharmony_ci .restore = s3_pci_resume, 14758c2ecf20Sopenharmony_ci#endif 14768c2ecf20Sopenharmony_ci}; 14778c2ecf20Sopenharmony_ci 14788c2ecf20Sopenharmony_ci/* List of boards that we are trying to support */ 14798c2ecf20Sopenharmony_ci 14808c2ecf20Sopenharmony_cistatic const struct pci_device_id s3_devices[] = { 14818c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO}, 14828c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO}, 14838c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP}, 14848c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP}, 14858c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX}, 14868c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX}, 14878c2ecf20Sopenharmony_ci 14888c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE}, 14898c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX}, 14908c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX}, 14918c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_357_VIRGE_GX2}, 14928c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_359_VIRGE_GX2P}, 14938c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P}, 14948c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A13), .driver_data = CHIP_36X_TRIO3D_1X_2X}, 14958c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8904), .driver_data = CHIP_365_TRIO3D}, 14968c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8C01), .driver_data = CHIP_260_VIRGE_MX}, 14978c2ecf20Sopenharmony_ci 14988c2ecf20Sopenharmony_ci {0, 0, 0, 0, 0, 0, 0} 14998c2ecf20Sopenharmony_ci}; 15008c2ecf20Sopenharmony_ci 15018c2ecf20Sopenharmony_ci 15028c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, s3_devices); 15038c2ecf20Sopenharmony_ci 15048c2ecf20Sopenharmony_cistatic struct pci_driver s3fb_pci_driver = { 15058c2ecf20Sopenharmony_ci .name = "s3fb", 15068c2ecf20Sopenharmony_ci .id_table = s3_devices, 15078c2ecf20Sopenharmony_ci .probe = s3_pci_probe, 15088c2ecf20Sopenharmony_ci .remove = s3_pci_remove, 15098c2ecf20Sopenharmony_ci .driver.pm = &s3_pci_pm_ops, 15108c2ecf20Sopenharmony_ci}; 15118c2ecf20Sopenharmony_ci 15128c2ecf20Sopenharmony_ci/* Parse user specified options */ 15138c2ecf20Sopenharmony_ci 15148c2ecf20Sopenharmony_ci#ifndef MODULE 15158c2ecf20Sopenharmony_cistatic int __init s3fb_setup(char *options) 15168c2ecf20Sopenharmony_ci{ 15178c2ecf20Sopenharmony_ci char *opt; 15188c2ecf20Sopenharmony_ci 15198c2ecf20Sopenharmony_ci if (!options || !*options) 15208c2ecf20Sopenharmony_ci return 0; 15218c2ecf20Sopenharmony_ci 15228c2ecf20Sopenharmony_ci while ((opt = strsep(&options, ",")) != NULL) { 15238c2ecf20Sopenharmony_ci 15248c2ecf20Sopenharmony_ci if (!*opt) 15258c2ecf20Sopenharmony_ci continue; 15268c2ecf20Sopenharmony_ci else if (!strncmp(opt, "mtrr:", 5)) 15278c2ecf20Sopenharmony_ci mtrr = simple_strtoul(opt + 5, NULL, 0); 15288c2ecf20Sopenharmony_ci else if (!strncmp(opt, "fasttext:", 9)) 15298c2ecf20Sopenharmony_ci fasttext = simple_strtoul(opt + 9, NULL, 0); 15308c2ecf20Sopenharmony_ci else 15318c2ecf20Sopenharmony_ci mode_option = opt; 15328c2ecf20Sopenharmony_ci } 15338c2ecf20Sopenharmony_ci 15348c2ecf20Sopenharmony_ci return 0; 15358c2ecf20Sopenharmony_ci} 15368c2ecf20Sopenharmony_ci#endif 15378c2ecf20Sopenharmony_ci 15388c2ecf20Sopenharmony_ci/* Cleanup */ 15398c2ecf20Sopenharmony_ci 15408c2ecf20Sopenharmony_cistatic void __exit s3fb_cleanup(void) 15418c2ecf20Sopenharmony_ci{ 15428c2ecf20Sopenharmony_ci pr_debug("s3fb: cleaning up\n"); 15438c2ecf20Sopenharmony_ci pci_unregister_driver(&s3fb_pci_driver); 15448c2ecf20Sopenharmony_ci} 15458c2ecf20Sopenharmony_ci 15468c2ecf20Sopenharmony_ci/* Driver Initialisation */ 15478c2ecf20Sopenharmony_ci 15488c2ecf20Sopenharmony_cistatic int __init s3fb_init(void) 15498c2ecf20Sopenharmony_ci{ 15508c2ecf20Sopenharmony_ci 15518c2ecf20Sopenharmony_ci#ifndef MODULE 15528c2ecf20Sopenharmony_ci char *option = NULL; 15538c2ecf20Sopenharmony_ci 15548c2ecf20Sopenharmony_ci if (fb_get_options("s3fb", &option)) 15558c2ecf20Sopenharmony_ci return -ENODEV; 15568c2ecf20Sopenharmony_ci s3fb_setup(option); 15578c2ecf20Sopenharmony_ci#endif 15588c2ecf20Sopenharmony_ci 15598c2ecf20Sopenharmony_ci pr_debug("s3fb: initializing\n"); 15608c2ecf20Sopenharmony_ci return pci_register_driver(&s3fb_pci_driver); 15618c2ecf20Sopenharmony_ci} 15628c2ecf20Sopenharmony_ci 15638c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */ 15648c2ecf20Sopenharmony_ci 15658c2ecf20Sopenharmony_ci/* Modularization */ 15668c2ecf20Sopenharmony_ci 15678c2ecf20Sopenharmony_cimodule_init(s3fb_init); 15688c2ecf20Sopenharmony_cimodule_exit(s3fb_cleanup); 1569