18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * drivers/video/asiliantfb.c 38c2ecf20Sopenharmony_ci * frame buffer driver for Asiliant 69000 chip 48c2ecf20Sopenharmony_ci * Copyright (C) 2001-2003 Saito.K & Jeanne 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * from driver/video/chipsfb.c and, 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * drivers/video/asiliantfb.c -- frame buffer device for 98c2ecf20Sopenharmony_ci * Asiliant 69030 chip (formerly Intel, formerly Chips & Technologies) 108c2ecf20Sopenharmony_ci * Author: apc@agelectronics.co.uk 118c2ecf20Sopenharmony_ci * Copyright (C) 2000 AG Electronics 128c2ecf20Sopenharmony_ci * Note: the data sheets don't seem to be available from Asiliant. 138c2ecf20Sopenharmony_ci * They are available by searching developer.intel.com, but are not otherwise 148c2ecf20Sopenharmony_ci * linked to. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * This driver should be portable with minimal effort to the 69000 display 178c2ecf20Sopenharmony_ci * chip, and to the twin-display mode of the 69030. 188c2ecf20Sopenharmony_ci * Contains code from Thomas Hhenleitner <th@visuelle-maschinen.de> (thanks) 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * Derived from the CT65550 driver chipsfb.c: 218c2ecf20Sopenharmony_ci * Copyright (C) 1998 Paul Mackerras 228c2ecf20Sopenharmony_ci * ...which was derived from the Powermac "chips" driver: 238c2ecf20Sopenharmony_ci * Copyright (C) 1997 Fabio Riccardi. 248c2ecf20Sopenharmony_ci * And from the frame buffer device for Open Firmware-initialized devices: 258c2ecf20Sopenharmony_ci * Copyright (C) 1997 Geert Uytterhoeven. 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 288c2ecf20Sopenharmony_ci * License. See the file COPYING in the main directory of this archive for 298c2ecf20Sopenharmony_ci * more details. 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include <linux/module.h> 338c2ecf20Sopenharmony_ci#include <linux/kernel.h> 348c2ecf20Sopenharmony_ci#include <linux/errno.h> 358c2ecf20Sopenharmony_ci#include <linux/string.h> 368c2ecf20Sopenharmony_ci#include <linux/mm.h> 378c2ecf20Sopenharmony_ci#include <linux/vmalloc.h> 388c2ecf20Sopenharmony_ci#include <linux/delay.h> 398c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 408c2ecf20Sopenharmony_ci#include <linux/fb.h> 418c2ecf20Sopenharmony_ci#include <linux/init.h> 428c2ecf20Sopenharmony_ci#include <linux/pci.h> 438c2ecf20Sopenharmony_ci#include <asm/io.h> 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* Built in clock of the 69030 */ 468c2ecf20Sopenharmony_cistatic const unsigned Fref = 14318180; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define mmio_base (p->screen_base + 0x400000) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define mm_write_ind(num, val, ap, dp) do { \ 518c2ecf20Sopenharmony_ci writeb((num), mmio_base + (ap)); writeb((val), mmio_base + (dp)); \ 528c2ecf20Sopenharmony_ci} while (0) 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic void mm_write_xr(struct fb_info *p, u8 reg, u8 data) 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci mm_write_ind(reg, data, 0x7ac, 0x7ad); 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci#define write_xr(num, val) mm_write_xr(p, num, val) 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistatic void mm_write_fr(struct fb_info *p, u8 reg, u8 data) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci mm_write_ind(reg, data, 0x7a0, 0x7a1); 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci#define write_fr(num, val) mm_write_fr(p, num, val) 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic void mm_write_cr(struct fb_info *p, u8 reg, u8 data) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci mm_write_ind(reg, data, 0x7a8, 0x7a9); 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci#define write_cr(num, val) mm_write_cr(p, num, val) 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic void mm_write_gr(struct fb_info *p, u8 reg, u8 data) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci mm_write_ind(reg, data, 0x79c, 0x79d); 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci#define write_gr(num, val) mm_write_gr(p, num, val) 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistatic void mm_write_sr(struct fb_info *p, u8 reg, u8 data) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci mm_write_ind(reg, data, 0x788, 0x789); 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci#define write_sr(num, val) mm_write_sr(p, num, val) 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistatic void mm_write_ar(struct fb_info *p, u8 reg, u8 data) 858c2ecf20Sopenharmony_ci{ 868c2ecf20Sopenharmony_ci readb(mmio_base + 0x7b4); 878c2ecf20Sopenharmony_ci mm_write_ind(reg, data, 0x780, 0x780); 888c2ecf20Sopenharmony_ci} 898c2ecf20Sopenharmony_ci#define write_ar(num, val) mm_write_ar(p, num, val) 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic int asiliantfb_pci_init(struct pci_dev *dp, const struct pci_device_id *); 928c2ecf20Sopenharmony_cistatic int asiliantfb_check_var(struct fb_var_screeninfo *var, 938c2ecf20Sopenharmony_ci struct fb_info *info); 948c2ecf20Sopenharmony_cistatic int asiliantfb_set_par(struct fb_info *info); 958c2ecf20Sopenharmony_cistatic int asiliantfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, 968c2ecf20Sopenharmony_ci u_int transp, struct fb_info *info); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistatic const struct fb_ops asiliantfb_ops = { 998c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 1008c2ecf20Sopenharmony_ci .fb_check_var = asiliantfb_check_var, 1018c2ecf20Sopenharmony_ci .fb_set_par = asiliantfb_set_par, 1028c2ecf20Sopenharmony_ci .fb_setcolreg = asiliantfb_setcolreg, 1038c2ecf20Sopenharmony_ci .fb_fillrect = cfb_fillrect, 1048c2ecf20Sopenharmony_ci .fb_copyarea = cfb_copyarea, 1058c2ecf20Sopenharmony_ci .fb_imageblit = cfb_imageblit, 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/* Calculate the ratios for the dot clocks without using a single long long 1098c2ecf20Sopenharmony_ci * value */ 1108c2ecf20Sopenharmony_cistatic void asiliant_calc_dclk2(u32 *ppixclock, u8 *dclk2_m, u8 *dclk2_n, u8 *dclk2_div) 1118c2ecf20Sopenharmony_ci{ 1128c2ecf20Sopenharmony_ci unsigned pixclock = *ppixclock; 1138c2ecf20Sopenharmony_ci unsigned Ftarget = 1000000 * (1000000 / pixclock); 1148c2ecf20Sopenharmony_ci unsigned n; 1158c2ecf20Sopenharmony_ci unsigned best_error = 0xffffffff; 1168c2ecf20Sopenharmony_ci unsigned best_m = 0xffffffff, 1178c2ecf20Sopenharmony_ci best_n = 0xffffffff; 1188c2ecf20Sopenharmony_ci unsigned ratio; 1198c2ecf20Sopenharmony_ci unsigned remainder; 1208c2ecf20Sopenharmony_ci unsigned char divisor = 0; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci /* Calculate the frequency required. This is hard enough. */ 1238c2ecf20Sopenharmony_ci ratio = 1000000 / pixclock; 1248c2ecf20Sopenharmony_ci remainder = 1000000 % pixclock; 1258c2ecf20Sopenharmony_ci Ftarget = 1000000 * ratio + (1000000 * remainder) / pixclock; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci while (Ftarget < 100000000) { 1288c2ecf20Sopenharmony_ci divisor += 0x10; 1298c2ecf20Sopenharmony_ci Ftarget <<= 1; 1308c2ecf20Sopenharmony_ci } 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci ratio = Ftarget / Fref; 1338c2ecf20Sopenharmony_ci remainder = Ftarget % Fref; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci /* This expresses the constraint that 150kHz <= Fref/n <= 5Mhz, 1368c2ecf20Sopenharmony_ci * together with 3 <= n <= 257. */ 1378c2ecf20Sopenharmony_ci for (n = 3; n <= 257; n++) { 1388c2ecf20Sopenharmony_ci unsigned m = n * ratio + (n * remainder) / Fref; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci /* 3 <= m <= 257 */ 1418c2ecf20Sopenharmony_ci if (m >= 3 && m <= 257) { 1428c2ecf20Sopenharmony_ci unsigned new_error = Ftarget * n >= Fref * m ? 1438c2ecf20Sopenharmony_ci ((Ftarget * n) - (Fref * m)) : ((Fref * m) - (Ftarget * n)); 1448c2ecf20Sopenharmony_ci if (new_error < best_error) { 1458c2ecf20Sopenharmony_ci best_n = n; 1468c2ecf20Sopenharmony_ci best_m = m; 1478c2ecf20Sopenharmony_ci best_error = new_error; 1488c2ecf20Sopenharmony_ci } 1498c2ecf20Sopenharmony_ci } 1508c2ecf20Sopenharmony_ci /* But if VLD = 4, then 4m <= 1028 */ 1518c2ecf20Sopenharmony_ci else if (m <= 1028) { 1528c2ecf20Sopenharmony_ci /* remember there are still only 8-bits of precision in m, so 1538c2ecf20Sopenharmony_ci * avoid over-optimistic error calculations */ 1548c2ecf20Sopenharmony_ci unsigned new_error = Ftarget * n >= Fref * (m & ~3) ? 1558c2ecf20Sopenharmony_ci ((Ftarget * n) - (Fref * (m & ~3))) : ((Fref * (m & ~3)) - (Ftarget * n)); 1568c2ecf20Sopenharmony_ci if (new_error < best_error) { 1578c2ecf20Sopenharmony_ci best_n = n; 1588c2ecf20Sopenharmony_ci best_m = m; 1598c2ecf20Sopenharmony_ci best_error = new_error; 1608c2ecf20Sopenharmony_ci } 1618c2ecf20Sopenharmony_ci } 1628c2ecf20Sopenharmony_ci } 1638c2ecf20Sopenharmony_ci if (best_m > 257) 1648c2ecf20Sopenharmony_ci best_m >>= 2; /* divide m by 4, and leave VCO loop divide at 4 */ 1658c2ecf20Sopenharmony_ci else 1668c2ecf20Sopenharmony_ci divisor |= 4; /* or set VCO loop divide to 1 */ 1678c2ecf20Sopenharmony_ci *dclk2_m = best_m - 2; 1688c2ecf20Sopenharmony_ci *dclk2_n = best_n - 2; 1698c2ecf20Sopenharmony_ci *dclk2_div = divisor; 1708c2ecf20Sopenharmony_ci *ppixclock = pixclock; 1718c2ecf20Sopenharmony_ci return; 1728c2ecf20Sopenharmony_ci} 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_cistatic void asiliant_set_timing(struct fb_info *p) 1758c2ecf20Sopenharmony_ci{ 1768c2ecf20Sopenharmony_ci unsigned hd = p->var.xres / 8; 1778c2ecf20Sopenharmony_ci unsigned hs = (p->var.xres + p->var.right_margin) / 8; 1788c2ecf20Sopenharmony_ci unsigned he = (p->var.xres + p->var.right_margin + p->var.hsync_len) / 8; 1798c2ecf20Sopenharmony_ci unsigned ht = (p->var.left_margin + p->var.xres + p->var.right_margin + p->var.hsync_len) / 8; 1808c2ecf20Sopenharmony_ci unsigned vd = p->var.yres; 1818c2ecf20Sopenharmony_ci unsigned vs = p->var.yres + p->var.lower_margin; 1828c2ecf20Sopenharmony_ci unsigned ve = p->var.yres + p->var.lower_margin + p->var.vsync_len; 1838c2ecf20Sopenharmony_ci unsigned vt = p->var.upper_margin + p->var.yres + p->var.lower_margin + p->var.vsync_len; 1848c2ecf20Sopenharmony_ci unsigned wd = (p->var.xres_virtual * ((p->var.bits_per_pixel+7)/8)) / 8; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci if ((p->var.xres == 640) && (p->var.yres == 480) && (p->var.pixclock == 39722)) { 1878c2ecf20Sopenharmony_ci write_fr(0x01, 0x02); /* LCD */ 1888c2ecf20Sopenharmony_ci } else { 1898c2ecf20Sopenharmony_ci write_fr(0x01, 0x01); /* CRT */ 1908c2ecf20Sopenharmony_ci } 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci write_cr(0x11, (ve - 1) & 0x0f); 1938c2ecf20Sopenharmony_ci write_cr(0x00, (ht - 5) & 0xff); 1948c2ecf20Sopenharmony_ci write_cr(0x01, hd - 1); 1958c2ecf20Sopenharmony_ci write_cr(0x02, hd); 1968c2ecf20Sopenharmony_ci write_cr(0x03, ((ht - 1) & 0x1f) | 0x80); 1978c2ecf20Sopenharmony_ci write_cr(0x04, hs); 1988c2ecf20Sopenharmony_ci write_cr(0x05, (((ht - 1) & 0x20) <<2) | (he & 0x1f)); 1998c2ecf20Sopenharmony_ci write_cr(0x3c, (ht - 1) & 0xc0); 2008c2ecf20Sopenharmony_ci write_cr(0x06, (vt - 2) & 0xff); 2018c2ecf20Sopenharmony_ci write_cr(0x30, (vt - 2) >> 8); 2028c2ecf20Sopenharmony_ci write_cr(0x07, 0x00); 2038c2ecf20Sopenharmony_ci write_cr(0x08, 0x00); 2048c2ecf20Sopenharmony_ci write_cr(0x09, 0x00); 2058c2ecf20Sopenharmony_ci write_cr(0x10, (vs - 1) & 0xff); 2068c2ecf20Sopenharmony_ci write_cr(0x32, ((vs - 1) >> 8) & 0xf); 2078c2ecf20Sopenharmony_ci write_cr(0x11, ((ve - 1) & 0x0f) | 0x80); 2088c2ecf20Sopenharmony_ci write_cr(0x12, (vd - 1) & 0xff); 2098c2ecf20Sopenharmony_ci write_cr(0x31, ((vd - 1) & 0xf00) >> 8); 2108c2ecf20Sopenharmony_ci write_cr(0x13, wd & 0xff); 2118c2ecf20Sopenharmony_ci write_cr(0x41, (wd & 0xf00) >> 8); 2128c2ecf20Sopenharmony_ci write_cr(0x15, (vs - 1) & 0xff); 2138c2ecf20Sopenharmony_ci write_cr(0x33, ((vs - 1) >> 8) & 0xf); 2148c2ecf20Sopenharmony_ci write_cr(0x38, ((ht - 5) & 0x100) >> 8); 2158c2ecf20Sopenharmony_ci write_cr(0x16, (vt - 1) & 0xff); 2168c2ecf20Sopenharmony_ci write_cr(0x18, 0x00); 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci if (p->var.xres == 640) { 2198c2ecf20Sopenharmony_ci writeb(0xc7, mmio_base + 0x784); /* set misc output reg */ 2208c2ecf20Sopenharmony_ci } else { 2218c2ecf20Sopenharmony_ci writeb(0x07, mmio_base + 0x784); /* set misc output reg */ 2228c2ecf20Sopenharmony_ci } 2238c2ecf20Sopenharmony_ci} 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_cistatic int asiliantfb_check_var(struct fb_var_screeninfo *var, 2268c2ecf20Sopenharmony_ci struct fb_info *p) 2278c2ecf20Sopenharmony_ci{ 2288c2ecf20Sopenharmony_ci unsigned long Ftarget, ratio, remainder; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci if (!var->pixclock) 2318c2ecf20Sopenharmony_ci return -EINVAL; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci ratio = 1000000 / var->pixclock; 2348c2ecf20Sopenharmony_ci remainder = 1000000 % var->pixclock; 2358c2ecf20Sopenharmony_ci Ftarget = 1000000 * ratio + (1000000 * remainder) / var->pixclock; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci /* First check the constraint that the maximum post-VCO divisor is 32, 2388c2ecf20Sopenharmony_ci * and the maximum Fvco is 220MHz */ 2398c2ecf20Sopenharmony_ci if (Ftarget > 220000000 || Ftarget < 3125000) { 2408c2ecf20Sopenharmony_ci printk(KERN_ERR "asiliantfb dotclock must be between 3.125 and 220MHz\n"); 2418c2ecf20Sopenharmony_ci return -ENXIO; 2428c2ecf20Sopenharmony_ci } 2438c2ecf20Sopenharmony_ci var->xres_virtual = var->xres; 2448c2ecf20Sopenharmony_ci var->yres_virtual = var->yres; 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci if (var->bits_per_pixel == 24) { 2478c2ecf20Sopenharmony_ci var->red.offset = 16; 2488c2ecf20Sopenharmony_ci var->green.offset = 8; 2498c2ecf20Sopenharmony_ci var->blue.offset = 0; 2508c2ecf20Sopenharmony_ci var->red.length = var->blue.length = var->green.length = 8; 2518c2ecf20Sopenharmony_ci } else if (var->bits_per_pixel == 16) { 2528c2ecf20Sopenharmony_ci switch (var->red.offset) { 2538c2ecf20Sopenharmony_ci case 11: 2548c2ecf20Sopenharmony_ci var->green.length = 6; 2558c2ecf20Sopenharmony_ci break; 2568c2ecf20Sopenharmony_ci case 10: 2578c2ecf20Sopenharmony_ci var->green.length = 5; 2588c2ecf20Sopenharmony_ci break; 2598c2ecf20Sopenharmony_ci default: 2608c2ecf20Sopenharmony_ci return -EINVAL; 2618c2ecf20Sopenharmony_ci } 2628c2ecf20Sopenharmony_ci var->green.offset = 5; 2638c2ecf20Sopenharmony_ci var->blue.offset = 0; 2648c2ecf20Sopenharmony_ci var->red.length = var->blue.length = 5; 2658c2ecf20Sopenharmony_ci } else if (var->bits_per_pixel == 8) { 2668c2ecf20Sopenharmony_ci var->red.offset = var->green.offset = var->blue.offset = 0; 2678c2ecf20Sopenharmony_ci var->red.length = var->green.length = var->blue.length = 8; 2688c2ecf20Sopenharmony_ci } 2698c2ecf20Sopenharmony_ci return 0; 2708c2ecf20Sopenharmony_ci} 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_cistatic int asiliantfb_set_par(struct fb_info *p) 2738c2ecf20Sopenharmony_ci{ 2748c2ecf20Sopenharmony_ci u8 dclk2_m; /* Holds m-2 value for register */ 2758c2ecf20Sopenharmony_ci u8 dclk2_n; /* Holds n-2 value for register */ 2768c2ecf20Sopenharmony_ci u8 dclk2_div; /* Holds divisor bitmask */ 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci /* Set pixclock */ 2798c2ecf20Sopenharmony_ci asiliant_calc_dclk2(&p->var.pixclock, &dclk2_m, &dclk2_n, &dclk2_div); 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci /* Set color depth */ 2828c2ecf20Sopenharmony_ci if (p->var.bits_per_pixel == 24) { 2838c2ecf20Sopenharmony_ci write_xr(0x81, 0x16); /* 24 bit packed color mode */ 2848c2ecf20Sopenharmony_ci write_xr(0x82, 0x00); /* Disable palettes */ 2858c2ecf20Sopenharmony_ci write_xr(0x20, 0x20); /* 24 bit blitter mode */ 2868c2ecf20Sopenharmony_ci } else if (p->var.bits_per_pixel == 16) { 2878c2ecf20Sopenharmony_ci if (p->var.red.offset == 11) 2888c2ecf20Sopenharmony_ci write_xr(0x81, 0x15); /* 16 bit color mode */ 2898c2ecf20Sopenharmony_ci else 2908c2ecf20Sopenharmony_ci write_xr(0x81, 0x14); /* 15 bit color mode */ 2918c2ecf20Sopenharmony_ci write_xr(0x82, 0x00); /* Disable palettes */ 2928c2ecf20Sopenharmony_ci write_xr(0x20, 0x10); /* 16 bit blitter mode */ 2938c2ecf20Sopenharmony_ci } else if (p->var.bits_per_pixel == 8) { 2948c2ecf20Sopenharmony_ci write_xr(0x0a, 0x02); /* Linear */ 2958c2ecf20Sopenharmony_ci write_xr(0x81, 0x12); /* 8 bit color mode */ 2968c2ecf20Sopenharmony_ci write_xr(0x82, 0x00); /* Graphics gamma enable */ 2978c2ecf20Sopenharmony_ci write_xr(0x20, 0x00); /* 8 bit blitter mode */ 2988c2ecf20Sopenharmony_ci } 2998c2ecf20Sopenharmony_ci p->fix.line_length = p->var.xres * (p->var.bits_per_pixel >> 3); 3008c2ecf20Sopenharmony_ci p->fix.visual = (p->var.bits_per_pixel == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; 3018c2ecf20Sopenharmony_ci write_xr(0xc4, dclk2_m); 3028c2ecf20Sopenharmony_ci write_xr(0xc5, dclk2_n); 3038c2ecf20Sopenharmony_ci write_xr(0xc7, dclk2_div); 3048c2ecf20Sopenharmony_ci /* Set up the CR registers */ 3058c2ecf20Sopenharmony_ci asiliant_set_timing(p); 3068c2ecf20Sopenharmony_ci return 0; 3078c2ecf20Sopenharmony_ci} 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cistatic int asiliantfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, 3108c2ecf20Sopenharmony_ci u_int transp, struct fb_info *p) 3118c2ecf20Sopenharmony_ci{ 3128c2ecf20Sopenharmony_ci if (regno > 255) 3138c2ecf20Sopenharmony_ci return 1; 3148c2ecf20Sopenharmony_ci red >>= 8; 3158c2ecf20Sopenharmony_ci green >>= 8; 3168c2ecf20Sopenharmony_ci blue >>= 8; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci /* Set hardware palete */ 3198c2ecf20Sopenharmony_ci writeb(regno, mmio_base + 0x790); 3208c2ecf20Sopenharmony_ci udelay(1); 3218c2ecf20Sopenharmony_ci writeb(red, mmio_base + 0x791); 3228c2ecf20Sopenharmony_ci writeb(green, mmio_base + 0x791); 3238c2ecf20Sopenharmony_ci writeb(blue, mmio_base + 0x791); 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci if (regno < 16) { 3268c2ecf20Sopenharmony_ci switch(p->var.red.offset) { 3278c2ecf20Sopenharmony_ci case 10: /* RGB 555 */ 3288c2ecf20Sopenharmony_ci ((u32 *)(p->pseudo_palette))[regno] = 3298c2ecf20Sopenharmony_ci ((red & 0xf8) << 7) | 3308c2ecf20Sopenharmony_ci ((green & 0xf8) << 2) | 3318c2ecf20Sopenharmony_ci ((blue & 0xf8) >> 3); 3328c2ecf20Sopenharmony_ci break; 3338c2ecf20Sopenharmony_ci case 11: /* RGB 565 */ 3348c2ecf20Sopenharmony_ci ((u32 *)(p->pseudo_palette))[regno] = 3358c2ecf20Sopenharmony_ci ((red & 0xf8) << 8) | 3368c2ecf20Sopenharmony_ci ((green & 0xfc) << 3) | 3378c2ecf20Sopenharmony_ci ((blue & 0xf8) >> 3); 3388c2ecf20Sopenharmony_ci break; 3398c2ecf20Sopenharmony_ci case 16: /* RGB 888 */ 3408c2ecf20Sopenharmony_ci ((u32 *)(p->pseudo_palette))[regno] = 3418c2ecf20Sopenharmony_ci (red << 16) | 3428c2ecf20Sopenharmony_ci (green << 8) | 3438c2ecf20Sopenharmony_ci (blue); 3448c2ecf20Sopenharmony_ci break; 3458c2ecf20Sopenharmony_ci } 3468c2ecf20Sopenharmony_ci } 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci return 0; 3498c2ecf20Sopenharmony_ci} 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_cistruct chips_init_reg { 3528c2ecf20Sopenharmony_ci unsigned char addr; 3538c2ecf20Sopenharmony_ci unsigned char data; 3548c2ecf20Sopenharmony_ci}; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_cistatic struct chips_init_reg chips_init_sr[] = 3578c2ecf20Sopenharmony_ci{ 3588c2ecf20Sopenharmony_ci {0x00, 0x03}, /* Reset register */ 3598c2ecf20Sopenharmony_ci {0x01, 0x01}, /* Clocking mode */ 3608c2ecf20Sopenharmony_ci {0x02, 0x0f}, /* Plane mask */ 3618c2ecf20Sopenharmony_ci {0x04, 0x0e} /* Memory mode */ 3628c2ecf20Sopenharmony_ci}; 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_cistatic struct chips_init_reg chips_init_gr[] = 3658c2ecf20Sopenharmony_ci{ 3668c2ecf20Sopenharmony_ci {0x03, 0x00}, /* Data rotate */ 3678c2ecf20Sopenharmony_ci {0x05, 0x00}, /* Graphics mode */ 3688c2ecf20Sopenharmony_ci {0x06, 0x01}, /* Miscellaneous */ 3698c2ecf20Sopenharmony_ci {0x08, 0x00} /* Bit mask */ 3708c2ecf20Sopenharmony_ci}; 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_cistatic struct chips_init_reg chips_init_ar[] = 3738c2ecf20Sopenharmony_ci{ 3748c2ecf20Sopenharmony_ci {0x10, 0x01}, /* Mode control */ 3758c2ecf20Sopenharmony_ci {0x11, 0x00}, /* Overscan */ 3768c2ecf20Sopenharmony_ci {0x12, 0x0f}, /* Memory plane enable */ 3778c2ecf20Sopenharmony_ci {0x13, 0x00} /* Horizontal pixel panning */ 3788c2ecf20Sopenharmony_ci}; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_cistatic struct chips_init_reg chips_init_cr[] = 3818c2ecf20Sopenharmony_ci{ 3828c2ecf20Sopenharmony_ci {0x0c, 0x00}, /* Start address high */ 3838c2ecf20Sopenharmony_ci {0x0d, 0x00}, /* Start address low */ 3848c2ecf20Sopenharmony_ci {0x40, 0x00}, /* Extended Start Address */ 3858c2ecf20Sopenharmony_ci {0x41, 0x00}, /* Extended Start Address */ 3868c2ecf20Sopenharmony_ci {0x14, 0x00}, /* Underline location */ 3878c2ecf20Sopenharmony_ci {0x17, 0xe3}, /* CRT mode control */ 3888c2ecf20Sopenharmony_ci {0x70, 0x00} /* Interlace control */ 3898c2ecf20Sopenharmony_ci}; 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_cistatic struct chips_init_reg chips_init_fr[] = 3938c2ecf20Sopenharmony_ci{ 3948c2ecf20Sopenharmony_ci {0x01, 0x02}, 3958c2ecf20Sopenharmony_ci {0x03, 0x08}, 3968c2ecf20Sopenharmony_ci {0x08, 0xcc}, 3978c2ecf20Sopenharmony_ci {0x0a, 0x08}, 3988c2ecf20Sopenharmony_ci {0x18, 0x00}, 3998c2ecf20Sopenharmony_ci {0x1e, 0x80}, 4008c2ecf20Sopenharmony_ci {0x40, 0x83}, 4018c2ecf20Sopenharmony_ci {0x41, 0x00}, 4028c2ecf20Sopenharmony_ci {0x48, 0x13}, 4038c2ecf20Sopenharmony_ci {0x4d, 0x60}, 4048c2ecf20Sopenharmony_ci {0x4e, 0x0f}, 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci {0x0b, 0x01}, 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci {0x21, 0x51}, 4098c2ecf20Sopenharmony_ci {0x22, 0x1d}, 4108c2ecf20Sopenharmony_ci {0x23, 0x5f}, 4118c2ecf20Sopenharmony_ci {0x20, 0x4f}, 4128c2ecf20Sopenharmony_ci {0x34, 0x00}, 4138c2ecf20Sopenharmony_ci {0x24, 0x51}, 4148c2ecf20Sopenharmony_ci {0x25, 0x00}, 4158c2ecf20Sopenharmony_ci {0x27, 0x0b}, 4168c2ecf20Sopenharmony_ci {0x26, 0x00}, 4178c2ecf20Sopenharmony_ci {0x37, 0x80}, 4188c2ecf20Sopenharmony_ci {0x33, 0x0b}, 4198c2ecf20Sopenharmony_ci {0x35, 0x11}, 4208c2ecf20Sopenharmony_ci {0x36, 0x02}, 4218c2ecf20Sopenharmony_ci {0x31, 0xea}, 4228c2ecf20Sopenharmony_ci {0x32, 0x0c}, 4238c2ecf20Sopenharmony_ci {0x30, 0xdf}, 4248c2ecf20Sopenharmony_ci {0x10, 0x0c}, 4258c2ecf20Sopenharmony_ci {0x11, 0xe0}, 4268c2ecf20Sopenharmony_ci {0x12, 0x50}, 4278c2ecf20Sopenharmony_ci {0x13, 0x00}, 4288c2ecf20Sopenharmony_ci {0x16, 0x03}, 4298c2ecf20Sopenharmony_ci {0x17, 0xbd}, 4308c2ecf20Sopenharmony_ci {0x1a, 0x00}, 4318c2ecf20Sopenharmony_ci}; 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_cistatic struct chips_init_reg chips_init_xr[] = 4358c2ecf20Sopenharmony_ci{ 4368c2ecf20Sopenharmony_ci {0xce, 0x00}, /* set default memory clock */ 4378c2ecf20Sopenharmony_ci {0xcc, 200 }, /* MCLK ratio M */ 4388c2ecf20Sopenharmony_ci {0xcd, 18 }, /* MCLK ratio N */ 4398c2ecf20Sopenharmony_ci {0xce, 0x90}, /* MCLK divisor = 2 */ 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci {0xc4, 209 }, 4428c2ecf20Sopenharmony_ci {0xc5, 118 }, 4438c2ecf20Sopenharmony_ci {0xc7, 32 }, 4448c2ecf20Sopenharmony_ci {0xcf, 0x06}, 4458c2ecf20Sopenharmony_ci {0x09, 0x01}, /* IO Control - CRT controller extensions */ 4468c2ecf20Sopenharmony_ci {0x0a, 0x02}, /* Frame buffer mapping */ 4478c2ecf20Sopenharmony_ci {0x0b, 0x01}, /* PCI burst write */ 4488c2ecf20Sopenharmony_ci {0x40, 0x03}, /* Memory access control */ 4498c2ecf20Sopenharmony_ci {0x80, 0x82}, /* Pixel pipeline configuration 0 */ 4508c2ecf20Sopenharmony_ci {0x81, 0x12}, /* Pixel pipeline configuration 1 */ 4518c2ecf20Sopenharmony_ci {0x82, 0x08}, /* Pixel pipeline configuration 2 */ 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci {0xd0, 0x0f}, 4548c2ecf20Sopenharmony_ci {0xd1, 0x01}, 4558c2ecf20Sopenharmony_ci}; 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_cistatic void chips_hw_init(struct fb_info *p) 4588c2ecf20Sopenharmony_ci{ 4598c2ecf20Sopenharmony_ci int i; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(chips_init_xr); ++i) 4628c2ecf20Sopenharmony_ci write_xr(chips_init_xr[i].addr, chips_init_xr[i].data); 4638c2ecf20Sopenharmony_ci write_xr(0x81, 0x12); 4648c2ecf20Sopenharmony_ci write_xr(0x82, 0x08); 4658c2ecf20Sopenharmony_ci write_xr(0x20, 0x00); 4668c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(chips_init_sr); ++i) 4678c2ecf20Sopenharmony_ci write_sr(chips_init_sr[i].addr, chips_init_sr[i].data); 4688c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(chips_init_gr); ++i) 4698c2ecf20Sopenharmony_ci write_gr(chips_init_gr[i].addr, chips_init_gr[i].data); 4708c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(chips_init_ar); ++i) 4718c2ecf20Sopenharmony_ci write_ar(chips_init_ar[i].addr, chips_init_ar[i].data); 4728c2ecf20Sopenharmony_ci /* Enable video output in attribute index register */ 4738c2ecf20Sopenharmony_ci writeb(0x20, mmio_base + 0x780); 4748c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(chips_init_cr); ++i) 4758c2ecf20Sopenharmony_ci write_cr(chips_init_cr[i].addr, chips_init_cr[i].data); 4768c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(chips_init_fr); ++i) 4778c2ecf20Sopenharmony_ci write_fr(chips_init_fr[i].addr, chips_init_fr[i].data); 4788c2ecf20Sopenharmony_ci} 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_cistatic const struct fb_fix_screeninfo asiliantfb_fix = { 4818c2ecf20Sopenharmony_ci .id = "Asiliant 69000", 4828c2ecf20Sopenharmony_ci .type = FB_TYPE_PACKED_PIXELS, 4838c2ecf20Sopenharmony_ci .visual = FB_VISUAL_PSEUDOCOLOR, 4848c2ecf20Sopenharmony_ci .accel = FB_ACCEL_NONE, 4858c2ecf20Sopenharmony_ci .line_length = 640, 4868c2ecf20Sopenharmony_ci .smem_len = 0x200000, /* 2MB */ 4878c2ecf20Sopenharmony_ci}; 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_cistatic const struct fb_var_screeninfo asiliantfb_var = { 4908c2ecf20Sopenharmony_ci .xres = 640, 4918c2ecf20Sopenharmony_ci .yres = 480, 4928c2ecf20Sopenharmony_ci .xres_virtual = 640, 4938c2ecf20Sopenharmony_ci .yres_virtual = 480, 4948c2ecf20Sopenharmony_ci .bits_per_pixel = 8, 4958c2ecf20Sopenharmony_ci .red = { .length = 8 }, 4968c2ecf20Sopenharmony_ci .green = { .length = 8 }, 4978c2ecf20Sopenharmony_ci .blue = { .length = 8 }, 4988c2ecf20Sopenharmony_ci .height = -1, 4998c2ecf20Sopenharmony_ci .width = -1, 5008c2ecf20Sopenharmony_ci .vmode = FB_VMODE_NONINTERLACED, 5018c2ecf20Sopenharmony_ci .pixclock = 39722, 5028c2ecf20Sopenharmony_ci .left_margin = 48, 5038c2ecf20Sopenharmony_ci .right_margin = 16, 5048c2ecf20Sopenharmony_ci .upper_margin = 33, 5058c2ecf20Sopenharmony_ci .lower_margin = 10, 5068c2ecf20Sopenharmony_ci .hsync_len = 96, 5078c2ecf20Sopenharmony_ci .vsync_len = 2, 5088c2ecf20Sopenharmony_ci}; 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_cistatic int init_asiliant(struct fb_info *p, unsigned long addr) 5118c2ecf20Sopenharmony_ci{ 5128c2ecf20Sopenharmony_ci int err; 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci p->fix = asiliantfb_fix; 5158c2ecf20Sopenharmony_ci p->fix.smem_start = addr; 5168c2ecf20Sopenharmony_ci p->var = asiliantfb_var; 5178c2ecf20Sopenharmony_ci p->fbops = &asiliantfb_ops; 5188c2ecf20Sopenharmony_ci p->flags = FBINFO_DEFAULT; 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci err = fb_alloc_cmap(&p->cmap, 256, 0); 5218c2ecf20Sopenharmony_ci if (err) { 5228c2ecf20Sopenharmony_ci printk(KERN_ERR "C&T 69000 fb failed to alloc cmap memory\n"); 5238c2ecf20Sopenharmony_ci return err; 5248c2ecf20Sopenharmony_ci } 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci err = register_framebuffer(p); 5278c2ecf20Sopenharmony_ci if (err < 0) { 5288c2ecf20Sopenharmony_ci printk(KERN_ERR "C&T 69000 framebuffer failed to register\n"); 5298c2ecf20Sopenharmony_ci fb_dealloc_cmap(&p->cmap); 5308c2ecf20Sopenharmony_ci return err; 5318c2ecf20Sopenharmony_ci } 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci fb_info(p, "Asiliant 69000 frame buffer (%dK RAM detected)\n", 5348c2ecf20Sopenharmony_ci p->fix.smem_len / 1024); 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci writeb(0xff, mmio_base + 0x78c); 5378c2ecf20Sopenharmony_ci chips_hw_init(p); 5388c2ecf20Sopenharmony_ci return 0; 5398c2ecf20Sopenharmony_ci} 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_cistatic int asiliantfb_pci_init(struct pci_dev *dp, 5428c2ecf20Sopenharmony_ci const struct pci_device_id *ent) 5438c2ecf20Sopenharmony_ci{ 5448c2ecf20Sopenharmony_ci unsigned long addr, size; 5458c2ecf20Sopenharmony_ci struct fb_info *p; 5468c2ecf20Sopenharmony_ci int err; 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci if ((dp->resource[0].flags & IORESOURCE_MEM) == 0) 5498c2ecf20Sopenharmony_ci return -ENODEV; 5508c2ecf20Sopenharmony_ci addr = pci_resource_start(dp, 0); 5518c2ecf20Sopenharmony_ci size = pci_resource_len(dp, 0); 5528c2ecf20Sopenharmony_ci if (addr == 0) 5538c2ecf20Sopenharmony_ci return -ENODEV; 5548c2ecf20Sopenharmony_ci if (!request_mem_region(addr, size, "asiliantfb")) 5558c2ecf20Sopenharmony_ci return -EBUSY; 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci p = framebuffer_alloc(sizeof(u32) * 16, &dp->dev); 5588c2ecf20Sopenharmony_ci if (!p) { 5598c2ecf20Sopenharmony_ci release_mem_region(addr, size); 5608c2ecf20Sopenharmony_ci return -ENOMEM; 5618c2ecf20Sopenharmony_ci } 5628c2ecf20Sopenharmony_ci p->pseudo_palette = p->par; 5638c2ecf20Sopenharmony_ci p->par = NULL; 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci p->screen_base = ioremap(addr, 0x800000); 5668c2ecf20Sopenharmony_ci if (p->screen_base == NULL) { 5678c2ecf20Sopenharmony_ci release_mem_region(addr, size); 5688c2ecf20Sopenharmony_ci framebuffer_release(p); 5698c2ecf20Sopenharmony_ci return -ENOMEM; 5708c2ecf20Sopenharmony_ci } 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci pci_write_config_dword(dp, 4, 0x02800083); 5738c2ecf20Sopenharmony_ci writeb(3, p->screen_base + 0x400784); 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci err = init_asiliant(p, addr); 5768c2ecf20Sopenharmony_ci if (err) { 5778c2ecf20Sopenharmony_ci iounmap(p->screen_base); 5788c2ecf20Sopenharmony_ci release_mem_region(addr, size); 5798c2ecf20Sopenharmony_ci framebuffer_release(p); 5808c2ecf20Sopenharmony_ci return err; 5818c2ecf20Sopenharmony_ci } 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci pci_set_drvdata(dp, p); 5848c2ecf20Sopenharmony_ci return 0; 5858c2ecf20Sopenharmony_ci} 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_cistatic void asiliantfb_remove(struct pci_dev *dp) 5888c2ecf20Sopenharmony_ci{ 5898c2ecf20Sopenharmony_ci struct fb_info *p = pci_get_drvdata(dp); 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci unregister_framebuffer(p); 5928c2ecf20Sopenharmony_ci fb_dealloc_cmap(&p->cmap); 5938c2ecf20Sopenharmony_ci iounmap(p->screen_base); 5948c2ecf20Sopenharmony_ci release_mem_region(pci_resource_start(dp, 0), pci_resource_len(dp, 0)); 5958c2ecf20Sopenharmony_ci framebuffer_release(p); 5968c2ecf20Sopenharmony_ci} 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_cistatic const struct pci_device_id asiliantfb_pci_tbl[] = { 5998c2ecf20Sopenharmony_ci { PCI_VENDOR_ID_CT, PCI_DEVICE_ID_CT_69000, PCI_ANY_ID, PCI_ANY_ID }, 6008c2ecf20Sopenharmony_ci { 0 } 6018c2ecf20Sopenharmony_ci}; 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, asiliantfb_pci_tbl); 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_cistatic struct pci_driver asiliantfb_driver = { 6068c2ecf20Sopenharmony_ci .name = "asiliantfb", 6078c2ecf20Sopenharmony_ci .id_table = asiliantfb_pci_tbl, 6088c2ecf20Sopenharmony_ci .probe = asiliantfb_pci_init, 6098c2ecf20Sopenharmony_ci .remove = asiliantfb_remove, 6108c2ecf20Sopenharmony_ci}; 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_cistatic int __init asiliantfb_init(void) 6138c2ecf20Sopenharmony_ci{ 6148c2ecf20Sopenharmony_ci if (fb_get_options("asiliantfb", NULL)) 6158c2ecf20Sopenharmony_ci return -ENODEV; 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci return pci_register_driver(&asiliantfb_driver); 6188c2ecf20Sopenharmony_ci} 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_cimodule_init(asiliantfb_init); 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_cistatic void __exit asiliantfb_exit(void) 6238c2ecf20Sopenharmony_ci{ 6248c2ecf20Sopenharmony_ci pci_unregister_driver(&asiliantfb_driver); 6258c2ecf20Sopenharmony_ci} 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 628