Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: g364fb.c,v 1.3 1998/08/28 22:43:00 tsbogend Exp $ |
| 2 | * |
| 3 | * linux/drivers/video/g364fb.c -- Mips Magnum frame buffer device |
| 4 | * |
| 5 | * (C) 1998 Thomas Bogendoerfer |
| 6 | * |
| 7 | * This driver is based on tgafb.c |
| 8 | * |
| 9 | * Copyright (C) 1997 Geert Uytterhoeven |
| 10 | * Copyright (C) 1995 Jay Estabrook |
| 11 | * |
| 12 | * This file is subject to the terms and conditions of the GNU General Public |
| 13 | * License. See the file COPYING in the main directory of this archive for |
| 14 | * more details. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/console.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/string.h> |
| 23 | #include <linux/mm.h> |
| 24 | #include <linux/tty.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/vmalloc.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/interrupt.h> |
| 29 | #include <linux/fb.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <asm/io.h> |
| 33 | #include <asm/jazz.h> |
| 34 | |
| 35 | /* |
| 36 | * Various defines for the G364 |
| 37 | */ |
| 38 | #define G364_MEM_BASE 0xe4400000 |
| 39 | #define G364_PORT_BASE 0xe4000000 |
| 40 | #define ID_REG 0xe4000000 /* Read only */ |
| 41 | #define BOOT_REG 0xe4080000 |
| 42 | #define TIMING_REG 0xe4080108 /* to 0x080170 - DON'T TOUCH! */ |
| 43 | #define DISPLAY_REG 0xe4080118 |
| 44 | #define VDISPLAY_REG 0xe4080150 |
| 45 | #define MASK_REG 0xe4080200 |
| 46 | #define CTLA_REG 0xe4080300 |
| 47 | #define CURS_TOGGLE 0x800000 |
| 48 | #define BIT_PER_PIX 0x700000 /* bits 22 to 20 of Control A */ |
| 49 | #define DELAY_SAMPLE 0x080000 |
| 50 | #define PORT_INTER 0x040000 |
| 51 | #define PIX_PIPE_DEL 0x030000 /* bits 17 and 16 of Control A */ |
| 52 | #define PIX_PIPE_DEL2 0x008000 /* same as above - don't ask me why */ |
| 53 | #define TR_CYCLE_TOG 0x004000 |
| 54 | #define VRAM_ADR_INC 0x003000 /* bits 13 and 12 of Control A */ |
| 55 | #define BLANK_OFF 0x000800 |
| 56 | #define FORCE_BLANK 0x000400 |
| 57 | #define BLK_FUN_SWTCH 0x000200 |
| 58 | #define BLANK_IO 0x000100 |
| 59 | #define BLANK_LEVEL 0x000080 |
| 60 | #define A_VID_FORM 0x000040 |
| 61 | #define D_SYNC_FORM 0x000020 |
| 62 | #define FRAME_FLY_PAT 0x000010 |
| 63 | #define OP_MODE 0x000008 |
| 64 | #define INTL_STAND 0x000004 |
| 65 | #define SCRN_FORM 0x000002 |
| 66 | #define ENABLE_VTG 0x000001 |
| 67 | #define TOP_REG 0xe4080400 |
| 68 | #define CURS_PAL_REG 0xe4080508 /* to 0x080518 */ |
| 69 | #define CHKSUM_REG 0xe4080600 /* to 0x080610 - unused */ |
| 70 | #define CURS_POS_REG 0xe4080638 |
| 71 | #define CLR_PAL_REG 0xe4080800 /* to 0x080ff8 */ |
| 72 | #define CURS_PAT_REG 0xe4081000 /* to 0x081ff8 */ |
| 73 | #define MON_ID_REG 0xe4100000 /* unused */ |
| 74 | #define RESET_REG 0xe4180000 /* Write only */ |
| 75 | |
| 76 | static struct fb_info fb_info; |
| 77 | |
| 78 | static struct fb_fix_screeninfo fb_fix __initdata = { |
| 79 | .id = "G364 8plane", |
| 80 | .smem_start = 0x40000000, /* physical address */ |
| 81 | .type = FB_TYPE_PACKED_PIXELS, |
| 82 | .visual = FB_VISUAL_PSEUDOCOLOR, |
| 83 | .ypanstep = 1, |
| 84 | .accel = FB_ACCEL_NONE, |
| 85 | }; |
| 86 | |
| 87 | static struct fb_var_screeninfo fb_var __initdata = { |
| 88 | .bits_per_pixel = 8, |
| 89 | .red = { 0, 8, 0 }, |
| 90 | .green = { 0, 8, 0 }, |
| 91 | .blue = { 0, 8, 0 }, |
| 92 | .activate = FB_ACTIVATE_NOW, |
| 93 | .height = -1, |
| 94 | .width = -1, |
| 95 | .pixclock = 39722, |
| 96 | .left_margin = 40, |
| 97 | .right_margin = 24, |
| 98 | .upper_margin = 32, |
| 99 | .lower_margin = 11, |
| 100 | .hsync_len = 96, |
| 101 | .vsync_len = 2, |
| 102 | .vmode = FB_VMODE_NONINTERLACED, |
| 103 | }; |
| 104 | |
| 105 | /* |
| 106 | * Interface used by the world |
| 107 | */ |
| 108 | int g364fb_init(void); |
| 109 | |
| 110 | static int g364fb_pan_display(struct fb_var_screeninfo *var, |
| 111 | struct fb_info *info); |
| 112 | static int g364fb_setcolreg(u_int regno, u_int red, u_int green, |
| 113 | u_int blue, u_int transp, |
| 114 | struct fb_info *info); |
| 115 | static int g364fb_cursor(struct fb_info *info, struct fb_cursor *cursor); |
| 116 | static int g364fb_blank(int blank, struct fb_info *info); |
| 117 | |
| 118 | static struct fb_ops g364fb_ops = { |
| 119 | .owner = THIS_MODULE, |
| 120 | .fb_setcolreg = g364fb_setcolreg, |
| 121 | .fb_pan_display = g364fb_pan_display, |
| 122 | .fb_blank = g364fb_blank, |
| 123 | .fb_fillrect = cfb_fillrect, |
| 124 | .fb_copyarea = cfb_copyarea, |
| 125 | .fb_imageblit = cfb_imageblit, |
| 126 | .fb_cursor = g364fb_cursor, |
| 127 | }; |
| 128 | |
| 129 | int g364fb_cursor(struct fb_info *info, struct fb_cursor *cursor) |
| 130 | { |
| 131 | |
| 132 | switch (cursor->enable) { |
| 133 | case CM_ERASE: |
| 134 | *(unsigned int *) CTLA_REG |= CURS_TOGGLE; |
| 135 | break; |
| 136 | |
| 137 | case CM_MOVE: |
| 138 | case CM_DRAW: |
| 139 | *(unsigned int *) CTLA_REG &= ~CURS_TOGGLE; |
| 140 | *(unsigned int *) CURS_POS_REG = |
| 141 | ((x * fontwidth(p)) << 12) | ((y * fontheight(p)) - |
| 142 | info->var.yoffset); |
| 143 | break; |
| 144 | } |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Pan or Wrap the Display |
| 150 | * |
| 151 | * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag |
| 152 | */ |
| 153 | static int g364fb_pan_display(struct fb_var_screeninfo *var, |
| 154 | struct fb_info *info) |
| 155 | { |
| 156 | if (var->xoffset || var->yoffset + var->yres > var->yres_virtual) |
| 157 | return -EINVAL; |
| 158 | |
| 159 | *(unsigned int *) TOP_REG = var->yoffset * var->xres; |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * Blank the display. |
| 165 | */ |
| 166 | static int g364fb_blank(int blank, struct fb_info *info) |
| 167 | { |
| 168 | if (blank) |
| 169 | *(unsigned int *) CTLA_REG |= FORCE_BLANK; |
| 170 | else |
| 171 | *(unsigned int *) CTLA_REG &= ~FORCE_BLANK; |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * Set a single color register. Return != 0 for invalid regno. |
| 177 | */ |
| 178 | static int g364fb_setcolreg(u_int regno, u_int red, u_int green, |
| 179 | u_int blue, u_int transp, struct fb_info *info) |
| 180 | { |
| 181 | volatile unsigned int *ptr = (volatile unsigned int *) CLR_PAL_REG; |
| 182 | |
| 183 | if (regno > 255) |
| 184 | return 1; |
| 185 | |
| 186 | red >>= 8; |
| 187 | green >>= 8; |
| 188 | blue >>= 8; |
| 189 | |
| 190 | ptr[regno << 1] = (red << 16) | (green << 8) | blue; |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * Initialisation |
| 197 | */ |
| 198 | int __init g364fb_init(void) |
| 199 | { |
| 200 | volatile unsigned int *pal_ptr = |
| 201 | (volatile unsigned int *) CLR_PAL_REG; |
| 202 | volatile unsigned int *curs_pal_ptr = |
| 203 | (volatile unsigned int *) CURS_PAL_REG; |
| 204 | int mem, i, j; |
| 205 | |
| 206 | if (fb_get_options("g364fb", NULL)) |
| 207 | return -ENODEV; |
| 208 | |
| 209 | /* TBD: G364 detection */ |
| 210 | |
| 211 | /* get the resolution set by ARC console */ |
| 212 | *(volatile unsigned int *) CTLA_REG &= ~ENABLE_VTG; |
| 213 | fb_var.xres = |
| 214 | (*((volatile unsigned int *) DISPLAY_REG) & 0x00ffffff) * 4; |
| 215 | fb_var.yres = |
| 216 | (*((volatile unsigned int *) VDISPLAY_REG) & 0x00ffffff) / 2; |
| 217 | *(volatile unsigned int *) CTLA_REG |= ENABLE_VTG; |
| 218 | |
| 219 | /* setup cursor */ |
| 220 | curs_pal_ptr[0] |= 0x00ffffff; |
| 221 | curs_pal_ptr[2] |= 0x00ffffff; |
| 222 | curs_pal_ptr[4] |= 0x00ffffff; |
| 223 | |
| 224 | /* |
| 225 | * first set the whole cursor to transparent |
| 226 | */ |
| 227 | for (i = 0; i < 512; i++) |
| 228 | *(unsigned short *) (CURS_PAT_REG + i * 8) = 0; |
| 229 | |
| 230 | /* |
| 231 | * switch the last two lines to cursor palette 3 |
| 232 | * we assume here, that FONTSIZE_X is 8 |
| 233 | */ |
| 234 | *(unsigned short *) (CURS_PAT_REG + 14 * 64) = 0xffff; |
| 235 | *(unsigned short *) (CURS_PAT_REG + 15 * 64) = 0xffff; |
| 236 | fb_var.xres_virtual = fbvar.xres; |
| 237 | fb_fix.line_length = (xres / 8) * fb_var.bits_per_pixel; |
| 238 | fb_fix.smem_start = 0x40000000; /* physical address */ |
| 239 | /* get size of video memory; this is special for the JAZZ hardware */ |
| 240 | mem = (r4030_read_reg32(JAZZ_R4030_CONFIG) >> 8) & 3; |
| 241 | fb_fix.smem_len = (1 << (mem * 2)) * 512 * 1024; |
| 242 | fb_var.yres_virtual = fb_fix.smem_len / fb_var.xres; |
| 243 | |
| 244 | fb_info.fbops = &g364fb_ops; |
| 245 | fb_info.screen_base = (char *) G364_MEM_BASE; /* virtual kernel address */ |
| 246 | fb_info.var = fb_var; |
| 247 | fb_info.fix = fb_fix; |
| 248 | fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
| 249 | |
| 250 | fb_alloc_cmap(&fb_info.cmap, 255, 0); |
| 251 | |
| 252 | if (register_framebuffer(&fb_info) < 0) |
| 253 | return -EINVAL; |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | module_init(g364fb_init); |
| 258 | MODULE_LICENSE("GPL"); |