18c2ecf20Sopenharmony_ci/* $Id: g364fb.c,v 1.3 1998/08/28 22:43:00 tsbogend Exp $ 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * linux/drivers/video/g364fb.c -- Mips Magnum frame buffer device 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * (C) 1998 Thomas Bogendoerfer 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * This driver is based on tgafb.c 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Copyright (C) 1997 Geert Uytterhoeven 108c2ecf20Sopenharmony_ci * Copyright (C) 1995 Jay Estabrook 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 138c2ecf20Sopenharmony_ci * License. See the file COPYING in the main directory of this archive for 148c2ecf20Sopenharmony_ci * more details. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/module.h> 188c2ecf20Sopenharmony_ci#include <linux/console.h> 198c2ecf20Sopenharmony_ci#include <linux/kernel.h> 208c2ecf20Sopenharmony_ci#include <linux/errno.h> 218c2ecf20Sopenharmony_ci#include <linux/string.h> 228c2ecf20Sopenharmony_ci#include <linux/mm.h> 238c2ecf20Sopenharmony_ci#include <linux/vmalloc.h> 248c2ecf20Sopenharmony_ci#include <linux/delay.h> 258c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 268c2ecf20Sopenharmony_ci#include <linux/fb.h> 278c2ecf20Sopenharmony_ci#include <linux/init.h> 288c2ecf20Sopenharmony_ci#include <asm/io.h> 298c2ecf20Sopenharmony_ci#include <asm/jazz.h> 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* 328c2ecf20Sopenharmony_ci * Various defines for the G364 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci#define G364_MEM_BASE 0xe4400000 358c2ecf20Sopenharmony_ci#define G364_PORT_BASE 0xe4000000 368c2ecf20Sopenharmony_ci#define ID_REG 0xe4000000 /* Read only */ 378c2ecf20Sopenharmony_ci#define BOOT_REG 0xe4080000 388c2ecf20Sopenharmony_ci#define TIMING_REG 0xe4080108 /* to 0x080170 - DON'T TOUCH! */ 398c2ecf20Sopenharmony_ci#define DISPLAY_REG 0xe4080118 408c2ecf20Sopenharmony_ci#define VDISPLAY_REG 0xe4080150 418c2ecf20Sopenharmony_ci#define MASK_REG 0xe4080200 428c2ecf20Sopenharmony_ci#define CTLA_REG 0xe4080300 438c2ecf20Sopenharmony_ci#define CURS_TOGGLE 0x800000 448c2ecf20Sopenharmony_ci#define BIT_PER_PIX 0x700000 /* bits 22 to 20 of Control A */ 458c2ecf20Sopenharmony_ci#define DELAY_SAMPLE 0x080000 468c2ecf20Sopenharmony_ci#define PORT_INTER 0x040000 478c2ecf20Sopenharmony_ci#define PIX_PIPE_DEL 0x030000 /* bits 17 and 16 of Control A */ 488c2ecf20Sopenharmony_ci#define PIX_PIPE_DEL2 0x008000 /* same as above - don't ask me why */ 498c2ecf20Sopenharmony_ci#define TR_CYCLE_TOG 0x004000 508c2ecf20Sopenharmony_ci#define VRAM_ADR_INC 0x003000 /* bits 13 and 12 of Control A */ 518c2ecf20Sopenharmony_ci#define BLANK_OFF 0x000800 528c2ecf20Sopenharmony_ci#define FORCE_BLANK 0x000400 538c2ecf20Sopenharmony_ci#define BLK_FUN_SWTCH 0x000200 548c2ecf20Sopenharmony_ci#define BLANK_IO 0x000100 558c2ecf20Sopenharmony_ci#define BLANK_LEVEL 0x000080 568c2ecf20Sopenharmony_ci#define A_VID_FORM 0x000040 578c2ecf20Sopenharmony_ci#define D_SYNC_FORM 0x000020 588c2ecf20Sopenharmony_ci#define FRAME_FLY_PAT 0x000010 598c2ecf20Sopenharmony_ci#define OP_MODE 0x000008 608c2ecf20Sopenharmony_ci#define INTL_STAND 0x000004 618c2ecf20Sopenharmony_ci#define SCRN_FORM 0x000002 628c2ecf20Sopenharmony_ci#define ENABLE_VTG 0x000001 638c2ecf20Sopenharmony_ci#define TOP_REG 0xe4080400 648c2ecf20Sopenharmony_ci#define CURS_PAL_REG 0xe4080508 /* to 0x080518 */ 658c2ecf20Sopenharmony_ci#define CHKSUM_REG 0xe4080600 /* to 0x080610 - unused */ 668c2ecf20Sopenharmony_ci#define CURS_POS_REG 0xe4080638 678c2ecf20Sopenharmony_ci#define CLR_PAL_REG 0xe4080800 /* to 0x080ff8 */ 688c2ecf20Sopenharmony_ci#define CURS_PAT_REG 0xe4081000 /* to 0x081ff8 */ 698c2ecf20Sopenharmony_ci#define MON_ID_REG 0xe4100000 /* unused */ 708c2ecf20Sopenharmony_ci#define RESET_REG 0xe4180000 /* Write only */ 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic struct fb_info fb_info; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic struct fb_fix_screeninfo fb_fix __initdata = { 758c2ecf20Sopenharmony_ci .id = "G364 8plane", 768c2ecf20Sopenharmony_ci .smem_start = 0x40000000, /* physical address */ 778c2ecf20Sopenharmony_ci .type = FB_TYPE_PACKED_PIXELS, 788c2ecf20Sopenharmony_ci .visual = FB_VISUAL_PSEUDOCOLOR, 798c2ecf20Sopenharmony_ci .ypanstep = 1, 808c2ecf20Sopenharmony_ci .accel = FB_ACCEL_NONE, 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic struct fb_var_screeninfo fb_var __initdata = { 848c2ecf20Sopenharmony_ci .bits_per_pixel = 8, 858c2ecf20Sopenharmony_ci .red = { 0, 8, 0 }, 868c2ecf20Sopenharmony_ci .green = { 0, 8, 0 }, 878c2ecf20Sopenharmony_ci .blue = { 0, 8, 0 }, 888c2ecf20Sopenharmony_ci .activate = FB_ACTIVATE_NOW, 898c2ecf20Sopenharmony_ci .height = -1, 908c2ecf20Sopenharmony_ci .width = -1, 918c2ecf20Sopenharmony_ci .pixclock = 39722, 928c2ecf20Sopenharmony_ci .left_margin = 40, 938c2ecf20Sopenharmony_ci .right_margin = 24, 948c2ecf20Sopenharmony_ci .upper_margin = 32, 958c2ecf20Sopenharmony_ci .lower_margin = 11, 968c2ecf20Sopenharmony_ci .hsync_len = 96, 978c2ecf20Sopenharmony_ci .vsync_len = 2, 988c2ecf20Sopenharmony_ci .vmode = FB_VMODE_NONINTERLACED, 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/* 1028c2ecf20Sopenharmony_ci * Interface used by the world 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_ciint g364fb_init(void); 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistatic int g364fb_pan_display(struct fb_var_screeninfo *var, 1078c2ecf20Sopenharmony_ci struct fb_info *info); 1088c2ecf20Sopenharmony_cistatic int g364fb_setcolreg(u_int regno, u_int red, u_int green, 1098c2ecf20Sopenharmony_ci u_int blue, u_int transp, 1108c2ecf20Sopenharmony_ci struct fb_info *info); 1118c2ecf20Sopenharmony_cistatic int g364fb_blank(int blank, struct fb_info *info); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic const struct fb_ops g364fb_ops = { 1148c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 1158c2ecf20Sopenharmony_ci .fb_setcolreg = g364fb_setcolreg, 1168c2ecf20Sopenharmony_ci .fb_pan_display = g364fb_pan_display, 1178c2ecf20Sopenharmony_ci .fb_blank = g364fb_blank, 1188c2ecf20Sopenharmony_ci .fb_fillrect = cfb_fillrect, 1198c2ecf20Sopenharmony_ci .fb_copyarea = cfb_copyarea, 1208c2ecf20Sopenharmony_ci .fb_imageblit = cfb_imageblit, 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* 1248c2ecf20Sopenharmony_ci * Pan or Wrap the Display 1258c2ecf20Sopenharmony_ci * 1268c2ecf20Sopenharmony_ci * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag 1278c2ecf20Sopenharmony_ci */ 1288c2ecf20Sopenharmony_cistatic int g364fb_pan_display(struct fb_var_screeninfo *var, 1298c2ecf20Sopenharmony_ci struct fb_info *info) 1308c2ecf20Sopenharmony_ci{ 1318c2ecf20Sopenharmony_ci if (var->xoffset || 1328c2ecf20Sopenharmony_ci var->yoffset + info->var.yres > info->var.yres_virtual) 1338c2ecf20Sopenharmony_ci return -EINVAL; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci *(unsigned int *) TOP_REG = var->yoffset * info->var.xres; 1368c2ecf20Sopenharmony_ci return 0; 1378c2ecf20Sopenharmony_ci} 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci/* 1408c2ecf20Sopenharmony_ci * Blank the display. 1418c2ecf20Sopenharmony_ci */ 1428c2ecf20Sopenharmony_cistatic int g364fb_blank(int blank, struct fb_info *info) 1438c2ecf20Sopenharmony_ci{ 1448c2ecf20Sopenharmony_ci if (blank) 1458c2ecf20Sopenharmony_ci *(unsigned int *) CTLA_REG |= FORCE_BLANK; 1468c2ecf20Sopenharmony_ci else 1478c2ecf20Sopenharmony_ci *(unsigned int *) CTLA_REG &= ~FORCE_BLANK; 1488c2ecf20Sopenharmony_ci return 0; 1498c2ecf20Sopenharmony_ci} 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci/* 1528c2ecf20Sopenharmony_ci * Set a single color register. Return != 0 for invalid regno. 1538c2ecf20Sopenharmony_ci */ 1548c2ecf20Sopenharmony_cistatic int g364fb_setcolreg(u_int regno, u_int red, u_int green, 1558c2ecf20Sopenharmony_ci u_int blue, u_int transp, struct fb_info *info) 1568c2ecf20Sopenharmony_ci{ 1578c2ecf20Sopenharmony_ci volatile unsigned int *ptr = (volatile unsigned int *) CLR_PAL_REG; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci if (regno > 255) 1608c2ecf20Sopenharmony_ci return 1; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci red >>= 8; 1638c2ecf20Sopenharmony_ci green >>= 8; 1648c2ecf20Sopenharmony_ci blue >>= 8; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci ptr[regno << 1] = (red << 16) | (green << 8) | blue; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci return 0; 1698c2ecf20Sopenharmony_ci} 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci/* 1728c2ecf20Sopenharmony_ci * Initialisation 1738c2ecf20Sopenharmony_ci */ 1748c2ecf20Sopenharmony_ciint __init g364fb_init(void) 1758c2ecf20Sopenharmony_ci{ 1768c2ecf20Sopenharmony_ci volatile unsigned int *curs_pal_ptr = 1778c2ecf20Sopenharmony_ci (volatile unsigned int *) CURS_PAL_REG; 1788c2ecf20Sopenharmony_ci int mem, i; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci if (fb_get_options("g364fb", NULL)) 1818c2ecf20Sopenharmony_ci return -ENODEV; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci /* TBD: G364 detection */ 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci /* get the resolution set by ARC console */ 1868c2ecf20Sopenharmony_ci *(volatile unsigned int *) CTLA_REG &= ~ENABLE_VTG; 1878c2ecf20Sopenharmony_ci fb_var.xres = 1888c2ecf20Sopenharmony_ci (*((volatile unsigned int *) DISPLAY_REG) & 0x00ffffff) * 4; 1898c2ecf20Sopenharmony_ci fb_var.yres = 1908c2ecf20Sopenharmony_ci (*((volatile unsigned int *) VDISPLAY_REG) & 0x00ffffff) / 2; 1918c2ecf20Sopenharmony_ci *(volatile unsigned int *) CTLA_REG |= ENABLE_VTG; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci /* setup cursor */ 1948c2ecf20Sopenharmony_ci curs_pal_ptr[0] |= 0x00ffffff; 1958c2ecf20Sopenharmony_ci curs_pal_ptr[2] |= 0x00ffffff; 1968c2ecf20Sopenharmony_ci curs_pal_ptr[4] |= 0x00ffffff; 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci /* 1998c2ecf20Sopenharmony_ci * first set the whole cursor to transparent 2008c2ecf20Sopenharmony_ci */ 2018c2ecf20Sopenharmony_ci for (i = 0; i < 512; i++) 2028c2ecf20Sopenharmony_ci *(unsigned short *) (CURS_PAT_REG + i * 8) = 0; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci /* 2058c2ecf20Sopenharmony_ci * switch the last two lines to cursor palette 3 2068c2ecf20Sopenharmony_ci * we assume here, that FONTSIZE_X is 8 2078c2ecf20Sopenharmony_ci */ 2088c2ecf20Sopenharmony_ci *(unsigned short *) (CURS_PAT_REG + 14 * 64) = 0xffff; 2098c2ecf20Sopenharmony_ci *(unsigned short *) (CURS_PAT_REG + 15 * 64) = 0xffff; 2108c2ecf20Sopenharmony_ci fb_var.xres_virtual = fb_var.xres; 2118c2ecf20Sopenharmony_ci fb_fix.line_length = fb_var.xres_virtual * fb_var.bits_per_pixel / 8; 2128c2ecf20Sopenharmony_ci fb_fix.smem_start = 0x40000000; /* physical address */ 2138c2ecf20Sopenharmony_ci /* get size of video memory; this is special for the JAZZ hardware */ 2148c2ecf20Sopenharmony_ci mem = (r4030_read_reg32(JAZZ_R4030_CONFIG) >> 8) & 3; 2158c2ecf20Sopenharmony_ci fb_fix.smem_len = (1 << (mem * 2)) * 512 * 1024; 2168c2ecf20Sopenharmony_ci fb_var.yres_virtual = fb_fix.smem_len / fb_var.xres; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci fb_info.fbops = &g364fb_ops; 2198c2ecf20Sopenharmony_ci fb_info.screen_base = (char *) G364_MEM_BASE; /* virtual kernel address */ 2208c2ecf20Sopenharmony_ci fb_info.var = fb_var; 2218c2ecf20Sopenharmony_ci fb_info.fix = fb_fix; 2228c2ecf20Sopenharmony_ci fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci fb_alloc_cmap(&fb_info.cmap, 255, 0); 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci if (register_framebuffer(&fb_info) < 0) 2278c2ecf20Sopenharmony_ci return -EINVAL; 2288c2ecf20Sopenharmony_ci return 0; 2298c2ecf20Sopenharmony_ci} 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_cimodule_init(g364fb_init); 2328c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 233