18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * linux/drivers/video/kyro/fbdev.c 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2002 STMicroelectronics 58c2ecf20Sopenharmony_ci * Copyright (C) 2003, 2004 Paul Mundt 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 88c2ecf20Sopenharmony_ci * License. See the file COPYING in the main directory of this archive 98c2ecf20Sopenharmony_ci * for more details. 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/module.h> 138c2ecf20Sopenharmony_ci#include <linux/types.h> 148c2ecf20Sopenharmony_ci#include <linux/kernel.h> 158c2ecf20Sopenharmony_ci#include <linux/mm.h> 168c2ecf20Sopenharmony_ci#include <linux/errno.h> 178c2ecf20Sopenharmony_ci#include <linux/string.h> 188c2ecf20Sopenharmony_ci#include <linux/delay.h> 198c2ecf20Sopenharmony_ci#include <linux/fb.h> 208c2ecf20Sopenharmony_ci#include <linux/ioctl.h> 218c2ecf20Sopenharmony_ci#include <linux/init.h> 228c2ecf20Sopenharmony_ci#include <linux/pci.h> 238c2ecf20Sopenharmony_ci#include <asm/io.h> 248c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#include <video/kyro.h> 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include "STG4000Reg.h" 298c2ecf20Sopenharmony_ci#include "STG4000Interface.h" 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* 328c2ecf20Sopenharmony_ci * PCI Definitions 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci#define PCI_VENDOR_ID_ST 0x104a 358c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_STG4000 0x0010 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define KHZ2PICOS(a) (1000000000UL/(a)) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/****************************************************************************/ 408c2ecf20Sopenharmony_cistatic struct fb_fix_screeninfo kyro_fix = { 418c2ecf20Sopenharmony_ci .id = "ST Kyro", 428c2ecf20Sopenharmony_ci .type = FB_TYPE_PACKED_PIXELS, 438c2ecf20Sopenharmony_ci .visual = FB_VISUAL_TRUECOLOR, 448c2ecf20Sopenharmony_ci .accel = FB_ACCEL_NONE, 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistatic const struct fb_var_screeninfo kyro_var = { 488c2ecf20Sopenharmony_ci /* 640x480, 16bpp @ 60 Hz */ 498c2ecf20Sopenharmony_ci .xres = 640, 508c2ecf20Sopenharmony_ci .yres = 480, 518c2ecf20Sopenharmony_ci .xres_virtual = 640, 528c2ecf20Sopenharmony_ci .yres_virtual = 480, 538c2ecf20Sopenharmony_ci .bits_per_pixel = 16, 548c2ecf20Sopenharmony_ci .red = { 11, 5, 0 }, 558c2ecf20Sopenharmony_ci .green = { 5, 6, 0 }, 568c2ecf20Sopenharmony_ci .blue = { 0, 5, 0 }, 578c2ecf20Sopenharmony_ci .activate = FB_ACTIVATE_NOW, 588c2ecf20Sopenharmony_ci .height = -1, 598c2ecf20Sopenharmony_ci .width = -1, 608c2ecf20Sopenharmony_ci .pixclock = KHZ2PICOS(25175), 618c2ecf20Sopenharmony_ci .left_margin = 48, 628c2ecf20Sopenharmony_ci .right_margin = 16, 638c2ecf20Sopenharmony_ci .upper_margin = 33, 648c2ecf20Sopenharmony_ci .lower_margin = 10, 658c2ecf20Sopenharmony_ci .hsync_len = 96, 668c2ecf20Sopenharmony_ci .vsync_len = 2, 678c2ecf20Sopenharmony_ci .vmode = FB_VMODE_NONINTERLACED, 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_citypedef struct { 718c2ecf20Sopenharmony_ci STG4000REG __iomem *pSTGReg; /* Virtual address of PCI register region */ 728c2ecf20Sopenharmony_ci u32 ulNextFreeVidMem; /* Offset from start of vid mem to next free region */ 738c2ecf20Sopenharmony_ci u32 ulOverlayOffset; /* Offset from start of vid mem to overlay */ 748c2ecf20Sopenharmony_ci u32 ulOverlayStride; /* Interleaved YUV and 422 mode Y stride */ 758c2ecf20Sopenharmony_ci u32 ulOverlayUVStride; /* 422 mode U & V stride */ 768c2ecf20Sopenharmony_ci} device_info_t; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/* global graphics card info structure (one per card) */ 798c2ecf20Sopenharmony_cistatic device_info_t deviceInfo; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistatic char *mode_option = NULL; 828c2ecf20Sopenharmony_cistatic int nopan = 0; 838c2ecf20Sopenharmony_cistatic int nowrap = 1; 848c2ecf20Sopenharmony_cistatic int nomtrr = 0; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* PCI driver prototypes */ 878c2ecf20Sopenharmony_cistatic int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 888c2ecf20Sopenharmony_cistatic void kyrofb_remove(struct pci_dev *pdev); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cistatic struct fb_videomode kyro_modedb[] = { 918c2ecf20Sopenharmony_ci { 928c2ecf20Sopenharmony_ci /* 640x350 @ 85Hz */ 938c2ecf20Sopenharmony_ci NULL, 85, 640, 350, KHZ2PICOS(31500), 948c2ecf20Sopenharmony_ci 96, 32, 60, 32, 64, 3, 958c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED 968c2ecf20Sopenharmony_ci }, { 978c2ecf20Sopenharmony_ci /* 640x400 @ 85Hz */ 988c2ecf20Sopenharmony_ci NULL, 85, 640, 400, KHZ2PICOS(31500), 998c2ecf20Sopenharmony_ci 96, 32, 41, 1, 64, 3, 1008c2ecf20Sopenharmony_ci FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1018c2ecf20Sopenharmony_ci }, { 1028c2ecf20Sopenharmony_ci /* 720x400 @ 85Hz */ 1038c2ecf20Sopenharmony_ci NULL, 85, 720, 400, KHZ2PICOS(35500), 1048c2ecf20Sopenharmony_ci 108, 36, 42, 1, 72, 3, 1058c2ecf20Sopenharmony_ci FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1068c2ecf20Sopenharmony_ci }, { 1078c2ecf20Sopenharmony_ci /* 640x480 @ 60Hz */ 1088c2ecf20Sopenharmony_ci NULL, 60, 640, 480, KHZ2PICOS(25175), 1098c2ecf20Sopenharmony_ci 48, 16, 33, 10, 96, 2, 1108c2ecf20Sopenharmony_ci 0, FB_VMODE_NONINTERLACED 1118c2ecf20Sopenharmony_ci }, { 1128c2ecf20Sopenharmony_ci /* 640x480 @ 72Hz */ 1138c2ecf20Sopenharmony_ci NULL, 72, 640, 480, KHZ2PICOS(31500), 1148c2ecf20Sopenharmony_ci 128, 24, 28, 9, 40, 3, 1158c2ecf20Sopenharmony_ci 0, FB_VMODE_NONINTERLACED 1168c2ecf20Sopenharmony_ci }, { 1178c2ecf20Sopenharmony_ci /* 640x480 @ 75Hz */ 1188c2ecf20Sopenharmony_ci NULL, 75, 640, 480, KHZ2PICOS(31500), 1198c2ecf20Sopenharmony_ci 120, 16, 16, 1, 64, 3, 1208c2ecf20Sopenharmony_ci 0, FB_VMODE_NONINTERLACED 1218c2ecf20Sopenharmony_ci }, { 1228c2ecf20Sopenharmony_ci /* 640x480 @ 85Hz */ 1238c2ecf20Sopenharmony_ci NULL, 85, 640, 480, KHZ2PICOS(36000), 1248c2ecf20Sopenharmony_ci 80, 56, 25, 1, 56, 3, 1258c2ecf20Sopenharmony_ci 0, FB_VMODE_NONINTERLACED 1268c2ecf20Sopenharmony_ci }, { 1278c2ecf20Sopenharmony_ci /* 800x600 @ 56Hz */ 1288c2ecf20Sopenharmony_ci NULL, 56, 800, 600, KHZ2PICOS(36000), 1298c2ecf20Sopenharmony_ci 128, 24, 22, 1, 72, 2, 1308c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1318c2ecf20Sopenharmony_ci }, { 1328c2ecf20Sopenharmony_ci /* 800x600 @ 60Hz */ 1338c2ecf20Sopenharmony_ci NULL, 60, 800, 600, KHZ2PICOS(40000), 1348c2ecf20Sopenharmony_ci 88, 40, 23, 1, 128, 4, 1358c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1368c2ecf20Sopenharmony_ci }, { 1378c2ecf20Sopenharmony_ci /* 800x600 @ 72Hz */ 1388c2ecf20Sopenharmony_ci NULL, 72, 800, 600, KHZ2PICOS(50000), 1398c2ecf20Sopenharmony_ci 64, 56, 23, 37, 120, 6, 1408c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1418c2ecf20Sopenharmony_ci }, { 1428c2ecf20Sopenharmony_ci /* 800x600 @ 75Hz */ 1438c2ecf20Sopenharmony_ci NULL, 75, 800, 600, KHZ2PICOS(49500), 1448c2ecf20Sopenharmony_ci 160, 16, 21, 1, 80, 3, 1458c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1468c2ecf20Sopenharmony_ci }, { 1478c2ecf20Sopenharmony_ci /* 800x600 @ 85Hz */ 1488c2ecf20Sopenharmony_ci NULL, 85, 800, 600, KHZ2PICOS(56250), 1498c2ecf20Sopenharmony_ci 152, 32, 27, 1, 64, 3, 1508c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1518c2ecf20Sopenharmony_ci }, { 1528c2ecf20Sopenharmony_ci /* 1024x768 @ 60Hz */ 1538c2ecf20Sopenharmony_ci NULL, 60, 1024, 768, KHZ2PICOS(65000), 1548c2ecf20Sopenharmony_ci 160, 24, 29, 3, 136, 6, 1558c2ecf20Sopenharmony_ci 0, FB_VMODE_NONINTERLACED 1568c2ecf20Sopenharmony_ci }, { 1578c2ecf20Sopenharmony_ci /* 1024x768 @ 70Hz */ 1588c2ecf20Sopenharmony_ci NULL, 70, 1024, 768, KHZ2PICOS(75000), 1598c2ecf20Sopenharmony_ci 144, 24, 29, 3, 136, 6, 1608c2ecf20Sopenharmony_ci 0, FB_VMODE_NONINTERLACED 1618c2ecf20Sopenharmony_ci }, { 1628c2ecf20Sopenharmony_ci /* 1024x768 @ 75Hz */ 1638c2ecf20Sopenharmony_ci NULL, 75, 1024, 768, KHZ2PICOS(78750), 1648c2ecf20Sopenharmony_ci 176, 16, 28, 1, 96, 3, 1658c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1668c2ecf20Sopenharmony_ci }, { 1678c2ecf20Sopenharmony_ci /* 1024x768 @ 85Hz */ 1688c2ecf20Sopenharmony_ci NULL, 85, 1024, 768, KHZ2PICOS(94500), 1698c2ecf20Sopenharmony_ci 208, 48, 36, 1, 96, 3, 1708c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1718c2ecf20Sopenharmony_ci }, { 1728c2ecf20Sopenharmony_ci /* 1152x864 @ 75Hz */ 1738c2ecf20Sopenharmony_ci NULL, 75, 1152, 864, KHZ2PICOS(108000), 1748c2ecf20Sopenharmony_ci 256, 64, 32, 1, 128, 3, 1758c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1768c2ecf20Sopenharmony_ci }, { 1778c2ecf20Sopenharmony_ci /* 1280x960 @ 60Hz */ 1788c2ecf20Sopenharmony_ci NULL, 60, 1280, 960, KHZ2PICOS(108000), 1798c2ecf20Sopenharmony_ci 312, 96, 36, 1, 112, 3, 1808c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1818c2ecf20Sopenharmony_ci }, { 1828c2ecf20Sopenharmony_ci /* 1280x960 @ 85Hz */ 1838c2ecf20Sopenharmony_ci NULL, 85, 1280, 960, KHZ2PICOS(148500), 1848c2ecf20Sopenharmony_ci 224, 64, 47, 1, 160, 3, 1858c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1868c2ecf20Sopenharmony_ci }, { 1878c2ecf20Sopenharmony_ci /* 1280x1024 @ 60Hz */ 1888c2ecf20Sopenharmony_ci NULL, 60, 1280, 1024, KHZ2PICOS(108000), 1898c2ecf20Sopenharmony_ci 248, 48, 38, 1, 112, 3, 1908c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1918c2ecf20Sopenharmony_ci }, { 1928c2ecf20Sopenharmony_ci /* 1280x1024 @ 75Hz */ 1938c2ecf20Sopenharmony_ci NULL, 75, 1280, 1024, KHZ2PICOS(135000), 1948c2ecf20Sopenharmony_ci 248, 16, 38, 1, 144, 3, 1958c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 1968c2ecf20Sopenharmony_ci }, { 1978c2ecf20Sopenharmony_ci /* 1280x1024 @ 85Hz */ 1988c2ecf20Sopenharmony_ci NULL, 85, 1280, 1024, KHZ2PICOS(157500), 1998c2ecf20Sopenharmony_ci 224, 64, 44, 1, 160, 3, 2008c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2018c2ecf20Sopenharmony_ci }, { 2028c2ecf20Sopenharmony_ci /* 1600x1200 @ 60Hz */ 2038c2ecf20Sopenharmony_ci NULL, 60, 1600, 1200, KHZ2PICOS(162000), 2048c2ecf20Sopenharmony_ci 304, 64, 46, 1, 192, 3, 2058c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2068c2ecf20Sopenharmony_ci }, { 2078c2ecf20Sopenharmony_ci /* 1600x1200 @ 65Hz */ 2088c2ecf20Sopenharmony_ci NULL, 65, 1600, 1200, KHZ2PICOS(175500), 2098c2ecf20Sopenharmony_ci 304, 64, 46, 1, 192, 3, 2108c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2118c2ecf20Sopenharmony_ci }, { 2128c2ecf20Sopenharmony_ci /* 1600x1200 @ 70Hz */ 2138c2ecf20Sopenharmony_ci NULL, 70, 1600, 1200, KHZ2PICOS(189000), 2148c2ecf20Sopenharmony_ci 304, 64, 46, 1, 192, 3, 2158c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2168c2ecf20Sopenharmony_ci }, { 2178c2ecf20Sopenharmony_ci /* 1600x1200 @ 75Hz */ 2188c2ecf20Sopenharmony_ci NULL, 75, 1600, 1200, KHZ2PICOS(202500), 2198c2ecf20Sopenharmony_ci 304, 64, 46, 1, 192, 3, 2208c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2218c2ecf20Sopenharmony_ci }, { 2228c2ecf20Sopenharmony_ci /* 1600x1200 @ 85Hz */ 2238c2ecf20Sopenharmony_ci NULL, 85, 1600, 1200, KHZ2PICOS(229500), 2248c2ecf20Sopenharmony_ci 304, 64, 46, 1, 192, 3, 2258c2ecf20Sopenharmony_ci FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2268c2ecf20Sopenharmony_ci }, { 2278c2ecf20Sopenharmony_ci /* 1792x1344 @ 60Hz */ 2288c2ecf20Sopenharmony_ci NULL, 60, 1792, 1344, KHZ2PICOS(204750), 2298c2ecf20Sopenharmony_ci 328, 128, 46, 1, 200, 3, 2308c2ecf20Sopenharmony_ci FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2318c2ecf20Sopenharmony_ci }, { 2328c2ecf20Sopenharmony_ci /* 1792x1344 @ 75Hz */ 2338c2ecf20Sopenharmony_ci NULL, 75, 1792, 1344, KHZ2PICOS(261000), 2348c2ecf20Sopenharmony_ci 352, 96, 69, 1, 216, 3, 2358c2ecf20Sopenharmony_ci FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2368c2ecf20Sopenharmony_ci }, { 2378c2ecf20Sopenharmony_ci /* 1856x1392 @ 60Hz */ 2388c2ecf20Sopenharmony_ci NULL, 60, 1856, 1392, KHZ2PICOS(218250), 2398c2ecf20Sopenharmony_ci 352, 96, 43, 1, 224, 3, 2408c2ecf20Sopenharmony_ci FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2418c2ecf20Sopenharmony_ci }, { 2428c2ecf20Sopenharmony_ci /* 1856x1392 @ 75Hz */ 2438c2ecf20Sopenharmony_ci NULL, 75, 1856, 1392, KHZ2PICOS(288000), 2448c2ecf20Sopenharmony_ci 352, 128, 104, 1, 224, 3, 2458c2ecf20Sopenharmony_ci FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2468c2ecf20Sopenharmony_ci }, { 2478c2ecf20Sopenharmony_ci /* 1920x1440 @ 60Hz */ 2488c2ecf20Sopenharmony_ci NULL, 60, 1920, 1440, KHZ2PICOS(234000), 2498c2ecf20Sopenharmony_ci 344, 128, 56, 1, 208, 3, 2508c2ecf20Sopenharmony_ci FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2518c2ecf20Sopenharmony_ci }, { 2528c2ecf20Sopenharmony_ci /* 1920x1440 @ 75Hz */ 2538c2ecf20Sopenharmony_ci NULL, 75, 1920, 1440, KHZ2PICOS(297000), 2548c2ecf20Sopenharmony_ci 352, 144, 56, 1, 224, 3, 2558c2ecf20Sopenharmony_ci FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 2568c2ecf20Sopenharmony_ci }, 2578c2ecf20Sopenharmony_ci}; 2588c2ecf20Sopenharmony_ci#define NUM_TOTAL_MODES ARRAY_SIZE(kyro_modedb) 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci/* 2618c2ecf20Sopenharmony_ci * This needs to be kept ordered corresponding to kyro_modedb. 2628c2ecf20Sopenharmony_ci */ 2638c2ecf20Sopenharmony_cienum { 2648c2ecf20Sopenharmony_ci VMODE_640_350_85, 2658c2ecf20Sopenharmony_ci VMODE_640_400_85, 2668c2ecf20Sopenharmony_ci VMODE_720_400_85, 2678c2ecf20Sopenharmony_ci VMODE_640_480_60, 2688c2ecf20Sopenharmony_ci VMODE_640_480_72, 2698c2ecf20Sopenharmony_ci VMODE_640_480_75, 2708c2ecf20Sopenharmony_ci VMODE_640_480_85, 2718c2ecf20Sopenharmony_ci VMODE_800_600_56, 2728c2ecf20Sopenharmony_ci VMODE_800_600_60, 2738c2ecf20Sopenharmony_ci VMODE_800_600_72, 2748c2ecf20Sopenharmony_ci VMODE_800_600_75, 2758c2ecf20Sopenharmony_ci VMODE_800_600_85, 2768c2ecf20Sopenharmony_ci VMODE_1024_768_60, 2778c2ecf20Sopenharmony_ci VMODE_1024_768_70, 2788c2ecf20Sopenharmony_ci VMODE_1024_768_75, 2798c2ecf20Sopenharmony_ci VMODE_1024_768_85, 2808c2ecf20Sopenharmony_ci VMODE_1152_864_75, 2818c2ecf20Sopenharmony_ci VMODE_1280_960_60, 2828c2ecf20Sopenharmony_ci VMODE_1280_960_85, 2838c2ecf20Sopenharmony_ci VMODE_1280_1024_60, 2848c2ecf20Sopenharmony_ci VMODE_1280_1024_75, 2858c2ecf20Sopenharmony_ci VMODE_1280_1024_85, 2868c2ecf20Sopenharmony_ci VMODE_1600_1200_60, 2878c2ecf20Sopenharmony_ci VMODE_1600_1200_65, 2888c2ecf20Sopenharmony_ci VMODE_1600_1200_70, 2898c2ecf20Sopenharmony_ci VMODE_1600_1200_75, 2908c2ecf20Sopenharmony_ci VMODE_1600_1200_85, 2918c2ecf20Sopenharmony_ci VMODE_1792_1344_60, 2928c2ecf20Sopenharmony_ci VMODE_1792_1344_75, 2938c2ecf20Sopenharmony_ci VMODE_1856_1392_60, 2948c2ecf20Sopenharmony_ci VMODE_1856_1392_75, 2958c2ecf20Sopenharmony_ci VMODE_1920_1440_60, 2968c2ecf20Sopenharmony_ci VMODE_1920_1440_75, 2978c2ecf20Sopenharmony_ci}; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci/* Accessors */ 3008c2ecf20Sopenharmony_cistatic int kyro_dev_video_mode_set(struct fb_info *info) 3018c2ecf20Sopenharmony_ci{ 3028c2ecf20Sopenharmony_ci struct kyrofb_info *par = info->par; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci /* Turn off display */ 3058c2ecf20Sopenharmony_ci StopVTG(deviceInfo.pSTGReg); 3068c2ecf20Sopenharmony_ci DisableRamdacOutput(deviceInfo.pSTGReg); 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci /* Bring us out of VGA and into Hi-Res mode, if not already. */ 3098c2ecf20Sopenharmony_ci DisableVGA(deviceInfo.pSTGReg); 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci if (InitialiseRamdac(deviceInfo.pSTGReg, 3128c2ecf20Sopenharmony_ci info->var.bits_per_pixel, 3138c2ecf20Sopenharmony_ci info->var.xres, info->var.yres, 3148c2ecf20Sopenharmony_ci par->HSP, par->VSP, &par->PIXCLK) < 0) 3158c2ecf20Sopenharmony_ci return -EINVAL; 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci SetupVTG(deviceInfo.pSTGReg, par); 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci ResetOverlayRegisters(deviceInfo.pSTGReg); 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci /* Turn on display in new mode */ 3228c2ecf20Sopenharmony_ci EnableRamdacOutput(deviceInfo.pSTGReg); 3238c2ecf20Sopenharmony_ci StartVTG(deviceInfo.pSTGReg); 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci deviceInfo.ulNextFreeVidMem = info->var.xres * info->var.yres * 3268c2ecf20Sopenharmony_ci info->var.bits_per_pixel; 3278c2ecf20Sopenharmony_ci deviceInfo.ulOverlayOffset = 0; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci return 0; 3308c2ecf20Sopenharmony_ci} 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_cistatic int kyro_dev_overlay_create(u32 ulWidth, 3338c2ecf20Sopenharmony_ci u32 ulHeight, int bLinear) 3348c2ecf20Sopenharmony_ci{ 3358c2ecf20Sopenharmony_ci u32 offset; 3368c2ecf20Sopenharmony_ci u32 stride, uvStride; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci if (deviceInfo.ulOverlayOffset != 0) 3398c2ecf20Sopenharmony_ci /* 3408c2ecf20Sopenharmony_ci * Can only create one overlay without resetting the card or 3418c2ecf20Sopenharmony_ci * changing display mode 3428c2ecf20Sopenharmony_ci */ 3438c2ecf20Sopenharmony_ci return -EINVAL; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci ResetOverlayRegisters(deviceInfo.pSTGReg); 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci /* Overlays are addressed in multiples of 16bytes or 32bytes, so make 3488c2ecf20Sopenharmony_ci * sure the start offset is on an appropriate boundary. 3498c2ecf20Sopenharmony_ci */ 3508c2ecf20Sopenharmony_ci offset = deviceInfo.ulNextFreeVidMem; 3518c2ecf20Sopenharmony_ci if ((offset & 0x1f) != 0) { 3528c2ecf20Sopenharmony_ci offset = (offset + 32L) & 0xffffffE0L; 3538c2ecf20Sopenharmony_ci } 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci if (CreateOverlaySurface(deviceInfo.pSTGReg, ulWidth, ulHeight, 3568c2ecf20Sopenharmony_ci bLinear, offset, &stride, &uvStride) < 0) 3578c2ecf20Sopenharmony_ci return -EINVAL; 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci deviceInfo.ulOverlayOffset = offset; 3608c2ecf20Sopenharmony_ci deviceInfo.ulOverlayStride = stride; 3618c2ecf20Sopenharmony_ci deviceInfo.ulOverlayUVStride = uvStride; 3628c2ecf20Sopenharmony_ci deviceInfo.ulNextFreeVidMem = offset + (ulHeight * stride) + (ulHeight * 2 * uvStride); 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci SetOverlayBlendMode(deviceInfo.pSTGReg, GLOBAL_ALPHA, 0xf, 0x0); 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci return 0; 3678c2ecf20Sopenharmony_ci} 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_cistatic int kyro_dev_overlay_viewport_set(u32 x, u32 y, u32 ulWidth, u32 ulHeight) 3708c2ecf20Sopenharmony_ci{ 3718c2ecf20Sopenharmony_ci if (deviceInfo.ulOverlayOffset == 0) 3728c2ecf20Sopenharmony_ci /* probably haven't called CreateOverlay yet */ 3738c2ecf20Sopenharmony_ci return -EINVAL; 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci if (ulWidth == 0 || ulWidth == 0xffffffff || 3768c2ecf20Sopenharmony_ci ulHeight == 0 || ulHeight == 0xffffffff || 3778c2ecf20Sopenharmony_ci (x < 2 && ulWidth + 2 == 0)) 3788c2ecf20Sopenharmony_ci return -EINVAL; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci /* Stop Ramdac Output */ 3818c2ecf20Sopenharmony_ci DisableRamdacOutput(deviceInfo.pSTGReg); 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci SetOverlayViewPort(deviceInfo.pSTGReg, 3848c2ecf20Sopenharmony_ci x, y, x + ulWidth - 1, y + ulHeight - 1); 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci EnableOverlayPlane(deviceInfo.pSTGReg); 3878c2ecf20Sopenharmony_ci /* Start Ramdac Output */ 3888c2ecf20Sopenharmony_ci EnableRamdacOutput(deviceInfo.pSTGReg); 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci return 0; 3918c2ecf20Sopenharmony_ci} 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_cistatic inline unsigned long get_line_length(int x, int bpp) 3948c2ecf20Sopenharmony_ci{ 3958c2ecf20Sopenharmony_ci return (unsigned long)((((x*bpp)+31)&~31) >> 3); 3968c2ecf20Sopenharmony_ci} 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_cistatic int kyrofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 3998c2ecf20Sopenharmony_ci{ 4008c2ecf20Sopenharmony_ci struct kyrofb_info *par = info->par; 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci if (!var->pixclock) 4038c2ecf20Sopenharmony_ci return -EINVAL; 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci if (var->bits_per_pixel != 16 && var->bits_per_pixel != 32) { 4068c2ecf20Sopenharmony_ci printk(KERN_WARNING "kyrofb: depth not supported: %u\n", var->bits_per_pixel); 4078c2ecf20Sopenharmony_ci return -EINVAL; 4088c2ecf20Sopenharmony_ci } 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci switch (var->bits_per_pixel) { 4118c2ecf20Sopenharmony_ci case 16: 4128c2ecf20Sopenharmony_ci var->red.offset = 11; 4138c2ecf20Sopenharmony_ci var->red.length = 5; 4148c2ecf20Sopenharmony_ci var->green.offset = 5; 4158c2ecf20Sopenharmony_ci var->green.length = 6; 4168c2ecf20Sopenharmony_ci var->blue.length = 5; 4178c2ecf20Sopenharmony_ci break; 4188c2ecf20Sopenharmony_ci case 32: 4198c2ecf20Sopenharmony_ci var->transp.offset = 24; 4208c2ecf20Sopenharmony_ci var->red.offset = 16; 4218c2ecf20Sopenharmony_ci var->green.offset = 8; 4228c2ecf20Sopenharmony_ci var->blue.offset = 0; 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci var->red.length = 8; 4258c2ecf20Sopenharmony_ci var->green.length = 8; 4268c2ecf20Sopenharmony_ci var->blue.length = 8; 4278c2ecf20Sopenharmony_ci var->transp.length = 8; 4288c2ecf20Sopenharmony_ci break; 4298c2ecf20Sopenharmony_ci } 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci /* Height/Width of picture in mm */ 4328c2ecf20Sopenharmony_ci var->height = var->width = -1; 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci /* Timing information. All values are in picoseconds */ 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci /* par->PIXCLK is in 100Hz units. Convert to picoseconds - 4378c2ecf20Sopenharmony_ci * ensuring we do not exceed 32 bit precision 4388c2ecf20Sopenharmony_ci */ 4398c2ecf20Sopenharmony_ci /* 4408c2ecf20Sopenharmony_ci * XXX: Enabling this really screws over the pixclock value when we 4418c2ecf20Sopenharmony_ci * read it back with fbset. As such, leaving this commented out appears 4428c2ecf20Sopenharmony_ci * to do the right thing (at least for now) .. bearing in mind that we 4438c2ecf20Sopenharmony_ci * have infact already done the KHZ2PICOS conversion in both the modedb 4448c2ecf20Sopenharmony_ci * and kyro_var. -- PFM. 4458c2ecf20Sopenharmony_ci */ 4468c2ecf20Sopenharmony_ci// var->pixclock = 1000000000 / (par->PIXCLK / 10); 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci /* the header file claims we should use picoseconds 4498c2ecf20Sopenharmony_ci * - nobody else does though, the all use pixels and lines 4508c2ecf20Sopenharmony_ci * of h and v sizes. Both options here. 4518c2ecf20Sopenharmony_ci */ 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci /* 4548c2ecf20Sopenharmony_ci * If we're being called by __fb_try_mode(), then we don't want to 4558c2ecf20Sopenharmony_ci * override any of the var settings that we've already parsed 4568c2ecf20Sopenharmony_ci * from our modedb. -- PFM. 4578c2ecf20Sopenharmony_ci */ 4588c2ecf20Sopenharmony_ci if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST) 4598c2ecf20Sopenharmony_ci return 0; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci var->left_margin = par->HBP; 4628c2ecf20Sopenharmony_ci var->hsync_len = par->HST; 4638c2ecf20Sopenharmony_ci var->right_margin = par->HFP; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci var->upper_margin = par->VBP; 4668c2ecf20Sopenharmony_ci var->vsync_len = par->VST; 4678c2ecf20Sopenharmony_ci var->lower_margin = par->VFP; 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci if (par->HSP == 1) 4708c2ecf20Sopenharmony_ci var->sync |= FB_SYNC_HOR_HIGH_ACT; 4718c2ecf20Sopenharmony_ci if (par->VSP == 1) 4728c2ecf20Sopenharmony_ci var->sync |= FB_SYNC_VERT_HIGH_ACT; 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci return 0; 4758c2ecf20Sopenharmony_ci} 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_cistatic int kyrofb_set_par(struct fb_info *info) 4788c2ecf20Sopenharmony_ci{ 4798c2ecf20Sopenharmony_ci struct kyrofb_info *par = info->par; 4808c2ecf20Sopenharmony_ci unsigned long lineclock; 4818c2ecf20Sopenharmony_ci unsigned long frameclock; 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci /* Actual resolution */ 4848c2ecf20Sopenharmony_ci par->XRES = info->var.xres; 4858c2ecf20Sopenharmony_ci par->YRES = info->var.yres; 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci /* pixel depth */ 4888c2ecf20Sopenharmony_ci par->PIXDEPTH = info->var.bits_per_pixel; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci /* Refresh rate */ 4918c2ecf20Sopenharmony_ci /* time for a line in ns */ 4928c2ecf20Sopenharmony_ci lineclock = (info->var.pixclock * (info->var.xres + 4938c2ecf20Sopenharmony_ci info->var.right_margin + 4948c2ecf20Sopenharmony_ci info->var.hsync_len + 4958c2ecf20Sopenharmony_ci info->var.left_margin)) / 1000; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci /* time for a frame in ns (precision in 32bpp) */ 4998c2ecf20Sopenharmony_ci frameclock = lineclock * (info->var.yres + 5008c2ecf20Sopenharmony_ci info->var.lower_margin + 5018c2ecf20Sopenharmony_ci info->var.vsync_len + 5028c2ecf20Sopenharmony_ci info->var.upper_margin); 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci /* Calculate refresh rate and horrizontal clocks */ 5058c2ecf20Sopenharmony_ci par->VFREQ = (1000000000 + (frameclock / 2)) / frameclock; 5068c2ecf20Sopenharmony_ci par->HCLK = (1000000000 + (lineclock / 2)) / lineclock; 5078c2ecf20Sopenharmony_ci par->PIXCLK = ((1000000000 + (info->var.pixclock / 2)) 5088c2ecf20Sopenharmony_ci / info->var.pixclock) * 10; 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci /* calculate horizontal timings */ 5118c2ecf20Sopenharmony_ci par->HFP = info->var.right_margin; 5128c2ecf20Sopenharmony_ci par->HST = info->var.hsync_len; 5138c2ecf20Sopenharmony_ci par->HBP = info->var.left_margin; 5148c2ecf20Sopenharmony_ci par->HTot = par->XRES + par->HBP + par->HST + par->HFP; 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci /* calculate vertical timings */ 5178c2ecf20Sopenharmony_ci par->VFP = info->var.lower_margin; 5188c2ecf20Sopenharmony_ci par->VST = info->var.vsync_len; 5198c2ecf20Sopenharmony_ci par->VBP = info->var.upper_margin; 5208c2ecf20Sopenharmony_ci par->VTot = par->YRES + par->VBP + par->VST + par->VFP; 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci par->HSP = (info->var.sync & FB_SYNC_HOR_HIGH_ACT) ? 1 : 0; 5238c2ecf20Sopenharmony_ci par->VSP = (info->var.sync & FB_SYNC_VERT_HIGH_ACT) ? 1 : 0; 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci kyro_dev_video_mode_set(info); 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci /* length of a line in bytes */ 5288c2ecf20Sopenharmony_ci info->fix.line_length = get_line_length(par->XRES, par->PIXDEPTH); 5298c2ecf20Sopenharmony_ci info->fix.visual = FB_VISUAL_TRUECOLOR; 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci return 0; 5328c2ecf20Sopenharmony_ci} 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_cistatic int kyrofb_setcolreg(u_int regno, u_int red, u_int green, 5358c2ecf20Sopenharmony_ci u_int blue, u_int transp, struct fb_info *info) 5368c2ecf20Sopenharmony_ci{ 5378c2ecf20Sopenharmony_ci struct kyrofb_info *par = info->par; 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci if (regno > 255) 5408c2ecf20Sopenharmony_ci return 1; /* Invalid register */ 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci if (regno < 16) { 5438c2ecf20Sopenharmony_ci switch (info->var.bits_per_pixel) { 5448c2ecf20Sopenharmony_ci case 16: 5458c2ecf20Sopenharmony_ci par->palette[regno] = 5468c2ecf20Sopenharmony_ci (red & 0xf800) | 5478c2ecf20Sopenharmony_ci ((green & 0xfc00) >> 5) | 5488c2ecf20Sopenharmony_ci ((blue & 0xf800) >> 11); 5498c2ecf20Sopenharmony_ci break; 5508c2ecf20Sopenharmony_ci case 32: 5518c2ecf20Sopenharmony_ci red >>= 8; green >>= 8; blue >>= 8; transp >>= 8; 5528c2ecf20Sopenharmony_ci par->palette[regno] = 5538c2ecf20Sopenharmony_ci (transp << 24) | (red << 16) | (green << 8) | blue; 5548c2ecf20Sopenharmony_ci break; 5558c2ecf20Sopenharmony_ci } 5568c2ecf20Sopenharmony_ci } 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci return 0; 5598c2ecf20Sopenharmony_ci} 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci#ifndef MODULE 5628c2ecf20Sopenharmony_cistatic int __init kyrofb_setup(char *options) 5638c2ecf20Sopenharmony_ci{ 5648c2ecf20Sopenharmony_ci char *this_opt; 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci if (!options || !*options) 5678c2ecf20Sopenharmony_ci return 0; 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci while ((this_opt = strsep(&options, ","))) { 5708c2ecf20Sopenharmony_ci if (!*this_opt) 5718c2ecf20Sopenharmony_ci continue; 5728c2ecf20Sopenharmony_ci if (strcmp(this_opt, "nopan") == 0) { 5738c2ecf20Sopenharmony_ci nopan = 1; 5748c2ecf20Sopenharmony_ci } else if (strcmp(this_opt, "nowrap") == 0) { 5758c2ecf20Sopenharmony_ci nowrap = 1; 5768c2ecf20Sopenharmony_ci } else if (strcmp(this_opt, "nomtrr") == 0) { 5778c2ecf20Sopenharmony_ci nomtrr = 1; 5788c2ecf20Sopenharmony_ci } else { 5798c2ecf20Sopenharmony_ci mode_option = this_opt; 5808c2ecf20Sopenharmony_ci } 5818c2ecf20Sopenharmony_ci } 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci return 0; 5848c2ecf20Sopenharmony_ci} 5858c2ecf20Sopenharmony_ci#endif 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_cistatic int kyrofb_ioctl(struct fb_info *info, 5888c2ecf20Sopenharmony_ci unsigned int cmd, unsigned long arg) 5898c2ecf20Sopenharmony_ci{ 5908c2ecf20Sopenharmony_ci overlay_create ol_create; 5918c2ecf20Sopenharmony_ci overlay_viewport_set ol_viewport_set; 5928c2ecf20Sopenharmony_ci void __user *argp = (void __user *)arg; 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci switch (cmd) { 5958c2ecf20Sopenharmony_ci case KYRO_IOCTL_OVERLAY_CREATE: 5968c2ecf20Sopenharmony_ci if (copy_from_user(&ol_create, argp, sizeof(overlay_create))) 5978c2ecf20Sopenharmony_ci return -EFAULT; 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci if (kyro_dev_overlay_create(ol_create.ulWidth, 6008c2ecf20Sopenharmony_ci ol_create.ulHeight, 0) < 0) { 6018c2ecf20Sopenharmony_ci printk(KERN_ERR "Kyro FB: failed to create overlay surface.\n"); 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci return -EINVAL; 6048c2ecf20Sopenharmony_ci } 6058c2ecf20Sopenharmony_ci break; 6068c2ecf20Sopenharmony_ci case KYRO_IOCTL_OVERLAY_VIEWPORT_SET: 6078c2ecf20Sopenharmony_ci if (copy_from_user(&ol_viewport_set, argp, 6088c2ecf20Sopenharmony_ci sizeof(overlay_viewport_set))) 6098c2ecf20Sopenharmony_ci return -EFAULT; 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci if (kyro_dev_overlay_viewport_set(ol_viewport_set.xOrgin, 6128c2ecf20Sopenharmony_ci ol_viewport_set.yOrgin, 6138c2ecf20Sopenharmony_ci ol_viewport_set.xSize, 6148c2ecf20Sopenharmony_ci ol_viewport_set.ySize) != 0) 6158c2ecf20Sopenharmony_ci { 6168c2ecf20Sopenharmony_ci printk(KERN_ERR "Kyro FB: failed to create overlay viewport.\n"); 6178c2ecf20Sopenharmony_ci return -EINVAL; 6188c2ecf20Sopenharmony_ci } 6198c2ecf20Sopenharmony_ci break; 6208c2ecf20Sopenharmony_ci case KYRO_IOCTL_SET_VIDEO_MODE: 6218c2ecf20Sopenharmony_ci { 6228c2ecf20Sopenharmony_ci printk(KERN_ERR "Kyro FB: KYRO_IOCTL_SET_VIDEO_MODE is" 6238c2ecf20Sopenharmony_ci "obsolete, use the appropriate fb_ioctl()" 6248c2ecf20Sopenharmony_ci "command instead.\n"); 6258c2ecf20Sopenharmony_ci return -EINVAL; 6268c2ecf20Sopenharmony_ci } 6278c2ecf20Sopenharmony_ci case KYRO_IOCTL_UVSTRIDE: 6288c2ecf20Sopenharmony_ci if (copy_to_user(argp, &deviceInfo.ulOverlayUVStride, sizeof(deviceInfo.ulOverlayUVStride))) 6298c2ecf20Sopenharmony_ci return -EFAULT; 6308c2ecf20Sopenharmony_ci break; 6318c2ecf20Sopenharmony_ci case KYRO_IOCTL_STRIDE: 6328c2ecf20Sopenharmony_ci if (copy_to_user(argp, &deviceInfo.ulOverlayStride, sizeof(deviceInfo.ulOverlayStride))) 6338c2ecf20Sopenharmony_ci return -EFAULT; 6348c2ecf20Sopenharmony_ci break; 6358c2ecf20Sopenharmony_ci case KYRO_IOCTL_OVERLAY_OFFSET: 6368c2ecf20Sopenharmony_ci if (copy_to_user(argp, &deviceInfo.ulOverlayOffset, sizeof(deviceInfo.ulOverlayOffset))) 6378c2ecf20Sopenharmony_ci return -EFAULT; 6388c2ecf20Sopenharmony_ci break; 6398c2ecf20Sopenharmony_ci } 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci return 0; 6428c2ecf20Sopenharmony_ci} 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_cistatic const struct pci_device_id kyrofb_pci_tbl[] = { 6458c2ecf20Sopenharmony_ci { PCI_VENDOR_ID_ST, PCI_DEVICE_ID_STG4000, 6468c2ecf20Sopenharmony_ci PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 6478c2ecf20Sopenharmony_ci { 0, } 6488c2ecf20Sopenharmony_ci}; 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, kyrofb_pci_tbl); 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_cistatic struct pci_driver kyrofb_pci_driver = { 6538c2ecf20Sopenharmony_ci .name = "kyrofb", 6548c2ecf20Sopenharmony_ci .id_table = kyrofb_pci_tbl, 6558c2ecf20Sopenharmony_ci .probe = kyrofb_probe, 6568c2ecf20Sopenharmony_ci .remove = kyrofb_remove, 6578c2ecf20Sopenharmony_ci}; 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_cistatic const struct fb_ops kyrofb_ops = { 6608c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 6618c2ecf20Sopenharmony_ci .fb_check_var = kyrofb_check_var, 6628c2ecf20Sopenharmony_ci .fb_set_par = kyrofb_set_par, 6638c2ecf20Sopenharmony_ci .fb_setcolreg = kyrofb_setcolreg, 6648c2ecf20Sopenharmony_ci .fb_ioctl = kyrofb_ioctl, 6658c2ecf20Sopenharmony_ci .fb_fillrect = cfb_fillrect, 6668c2ecf20Sopenharmony_ci .fb_copyarea = cfb_copyarea, 6678c2ecf20Sopenharmony_ci .fb_imageblit = cfb_imageblit, 6688c2ecf20Sopenharmony_ci}; 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_cistatic int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 6718c2ecf20Sopenharmony_ci{ 6728c2ecf20Sopenharmony_ci struct fb_info *info; 6738c2ecf20Sopenharmony_ci struct kyrofb_info *currentpar; 6748c2ecf20Sopenharmony_ci unsigned long size; 6758c2ecf20Sopenharmony_ci int err; 6768c2ecf20Sopenharmony_ci 6778c2ecf20Sopenharmony_ci if ((err = pci_enable_device(pdev))) { 6788c2ecf20Sopenharmony_ci printk(KERN_WARNING "kyrofb: Can't enable pdev: %d\n", err); 6798c2ecf20Sopenharmony_ci return err; 6808c2ecf20Sopenharmony_ci } 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci info = framebuffer_alloc(sizeof(struct kyrofb_info), &pdev->dev); 6838c2ecf20Sopenharmony_ci if (!info) 6848c2ecf20Sopenharmony_ci return -ENOMEM; 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci currentpar = info->par; 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci kyro_fix.smem_start = pci_resource_start(pdev, 0); 6898c2ecf20Sopenharmony_ci kyro_fix.smem_len = pci_resource_len(pdev, 0); 6908c2ecf20Sopenharmony_ci kyro_fix.mmio_start = pci_resource_start(pdev, 1); 6918c2ecf20Sopenharmony_ci kyro_fix.mmio_len = pci_resource_len(pdev, 1); 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci currentpar->regbase = deviceInfo.pSTGReg = 6948c2ecf20Sopenharmony_ci ioremap(kyro_fix.mmio_start, kyro_fix.mmio_len); 6958c2ecf20Sopenharmony_ci if (!currentpar->regbase) 6968c2ecf20Sopenharmony_ci goto out_free_fb; 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci info->screen_base = pci_ioremap_wc_bar(pdev, 0); 6998c2ecf20Sopenharmony_ci if (!info->screen_base) 7008c2ecf20Sopenharmony_ci goto out_unmap_regs; 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci if (!nomtrr) 7038c2ecf20Sopenharmony_ci currentpar->wc_cookie = arch_phys_wc_add(kyro_fix.smem_start, 7048c2ecf20Sopenharmony_ci kyro_fix.smem_len); 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci kyro_fix.ypanstep = nopan ? 0 : 1; 7078c2ecf20Sopenharmony_ci kyro_fix.ywrapstep = nowrap ? 0 : 1; 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci info->fbops = &kyrofb_ops; 7108c2ecf20Sopenharmony_ci info->fix = kyro_fix; 7118c2ecf20Sopenharmony_ci info->pseudo_palette = currentpar->palette; 7128c2ecf20Sopenharmony_ci info->flags = FBINFO_DEFAULT; 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci SetCoreClockPLL(deviceInfo.pSTGReg, pdev); 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci deviceInfo.ulNextFreeVidMem = 0; 7178c2ecf20Sopenharmony_ci deviceInfo.ulOverlayOffset = 0; 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci /* This should give a reasonable default video mode */ 7208c2ecf20Sopenharmony_ci if (!fb_find_mode(&info->var, info, mode_option, kyro_modedb, 7218c2ecf20Sopenharmony_ci NUM_TOTAL_MODES, &kyro_modedb[VMODE_1024_768_75], 32)) 7228c2ecf20Sopenharmony_ci info->var = kyro_var; 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ci fb_alloc_cmap(&info->cmap, 256, 0); 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci kyrofb_set_par(info); 7278c2ecf20Sopenharmony_ci kyrofb_check_var(&info->var, info); 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ci size = get_line_length(info->var.xres_virtual, 7308c2ecf20Sopenharmony_ci info->var.bits_per_pixel); 7318c2ecf20Sopenharmony_ci size *= info->var.yres_virtual; 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_ci fb_memset(info->screen_base, 0, size); 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci if (register_framebuffer(info) < 0) 7368c2ecf20Sopenharmony_ci goto out_unmap; 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci fb_info(info, "%s frame buffer device, at %dx%d@%d using %ldk/%ldk of VRAM\n", 7398c2ecf20Sopenharmony_ci info->fix.id, 7408c2ecf20Sopenharmony_ci info->var.xres, info->var.yres, info->var.bits_per_pixel, 7418c2ecf20Sopenharmony_ci size >> 10, (unsigned long)info->fix.smem_len >> 10); 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci pci_set_drvdata(pdev, info); 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci return 0; 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_ciout_unmap: 7488c2ecf20Sopenharmony_ci iounmap(info->screen_base); 7498c2ecf20Sopenharmony_ciout_unmap_regs: 7508c2ecf20Sopenharmony_ci iounmap(currentpar->regbase); 7518c2ecf20Sopenharmony_ciout_free_fb: 7528c2ecf20Sopenharmony_ci framebuffer_release(info); 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci return -EINVAL; 7558c2ecf20Sopenharmony_ci} 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_cistatic void kyrofb_remove(struct pci_dev *pdev) 7588c2ecf20Sopenharmony_ci{ 7598c2ecf20Sopenharmony_ci struct fb_info *info = pci_get_drvdata(pdev); 7608c2ecf20Sopenharmony_ci struct kyrofb_info *par = info->par; 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci /* Reset the board */ 7638c2ecf20Sopenharmony_ci StopVTG(deviceInfo.pSTGReg); 7648c2ecf20Sopenharmony_ci DisableRamdacOutput(deviceInfo.pSTGReg); 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci /* Sync up the PLL */ 7678c2ecf20Sopenharmony_ci SetCoreClockPLL(deviceInfo.pSTGReg, pdev); 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci deviceInfo.ulNextFreeVidMem = 0; 7708c2ecf20Sopenharmony_ci deviceInfo.ulOverlayOffset = 0; 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci iounmap(info->screen_base); 7738c2ecf20Sopenharmony_ci iounmap(par->regbase); 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci arch_phys_wc_del(par->wc_cookie); 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci unregister_framebuffer(info); 7788c2ecf20Sopenharmony_ci framebuffer_release(info); 7798c2ecf20Sopenharmony_ci} 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_cistatic int __init kyrofb_init(void) 7828c2ecf20Sopenharmony_ci{ 7838c2ecf20Sopenharmony_ci#ifndef MODULE 7848c2ecf20Sopenharmony_ci char *option = NULL; 7858c2ecf20Sopenharmony_ci 7868c2ecf20Sopenharmony_ci if (fb_get_options("kyrofb", &option)) 7878c2ecf20Sopenharmony_ci return -ENODEV; 7888c2ecf20Sopenharmony_ci kyrofb_setup(option); 7898c2ecf20Sopenharmony_ci#endif 7908c2ecf20Sopenharmony_ci return pci_register_driver(&kyrofb_pci_driver); 7918c2ecf20Sopenharmony_ci} 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_cistatic void __exit kyrofb_exit(void) 7948c2ecf20Sopenharmony_ci{ 7958c2ecf20Sopenharmony_ci pci_unregister_driver(&kyrofb_pci_driver); 7968c2ecf20Sopenharmony_ci} 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_cimodule_init(kyrofb_init); 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci#ifdef MODULE 8018c2ecf20Sopenharmony_cimodule_exit(kyrofb_exit); 8028c2ecf20Sopenharmony_ci#endif 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_ciMODULE_AUTHOR("STMicroelectronics; Paul Mundt <lethal@linux-sh.org>"); 8058c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 806