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