Import 2.3.18pre1
[davej-history.git] / drivers / video / dnfb.c
blobc8a550eb827b4fe88eb6615863114ccdf1fd0e9e
1 #include <linux/kernel.h>
2 #include <linux/errno.h>
3 #include <linux/string.h>
4 #include <linux/mm.h>
5 #include <linux/tty.h>
6 #include <linux/malloc.h>
7 #include <linux/delay.h>
8 #include <linux/interrupt.h>
9 #include <asm/setup.h>
10 #include <asm/segment.h>
11 #include <asm/system.h>
12 #include <asm/irq.h>
13 #include <asm/apollohw.h>
14 #include <linux/fb.h>
15 #include <linux/module.h>
17 #include <video/fbcon-mfb.h>
20 /* apollo video HW definitions */
23 * Control Registers. IOBASE + $x
25 * Note: these are the Memory/IO BASE definitions for a mono card set to the
26 * alternate address
28 * Control 3A and 3B serve identical functions except that 3A
29 * deals with control 1 and 3b deals with Color LUT reg.
32 #define AP_IOBASE 0x5d80 /* Base address of 1 plane board. */
33 #define AP_STATUS 0x5d80 /* Status register. Read */
34 #define AP_WRITE_ENABLE 0x5d80 /* Write Enable Register Write */
35 #define AP_DEVICE_ID 0x5d81 /* Device ID Register. Read */
36 #define AP_ROP_1 0x5d82 /* Raster Operation reg. Write Word */
37 #define AP_DIAG_MEM_REQ 0x5d84 /* Diagnostic Memory Request. Write Word */
38 #define AP_CONTROL_0 0x5d88 /* Control Register 0. Read/Write */
39 #define AP_CONTROL_1 0x5d8a /* Control Register 1. Read/Write */
40 #define AP_CONTROL_3A 0x5d8e /* Control Register 3a. Read/Write */
41 #define AP_CONTROL_2 0x5d8c /* Control Register 2. Read/Write */
44 #define FRAME_BUFFER_START 0x0FA0000
45 #define FRAME_BUFFER_LEN 0x40000
47 /* CREG 0 */
48 #define VECTOR_MODE 0x40 /* 010x.xxxx */
49 #define DBLT_MODE 0x80 /* 100x.xxxx */
50 #define NORMAL_MODE 0xE0 /* 111x.xxxx */
51 #define SHIFT_BITS 0x1F /* xxx1.1111 */
52 /* other bits are Shift value */
54 /* CREG 1 */
55 #define AD_BLT 0x80 /* 1xxx.xxxx */
56 #define NORMAL 0x80 /* 1xxx.xxxx */ /* What is happening here ?? */
57 #define INVERSE 0x00 /* 0xxx.xxxx */ /* Clearing this reverses the screen */
58 #define PIX_BLT 0x00 /* 0xxx.xxxx */
60 #define AD_HIBIT 0x40 /* xIxx.xxxx */
62 #define ROP_EN 0x10 /* xxx1.xxxx */
63 #define DST_EQ_SRC 0x00 /* xxx0.xxxx */
64 #define nRESET_SYNC 0x08 /* xxxx.1xxx */
65 #define SYNC_ENAB 0x02 /* xxxx.xx1x */
67 #define BLANK_DISP 0x00 /* xxxx.xxx0 */
68 #define ENAB_DISP 0x01 /* xxxx.xxx1 */
70 #define NORM_CREG1 (nRESET_SYNC | SYNC_ENAB | ENAB_DISP) /* no reset sync */
72 /* CREG 2 */
75 * Following 3 defines are common to 1, 4 and 8 plane.
78 #define S_DATA_1s 0x00 /* 00xx.xxxx */ /* set source to all 1's -- vector drawing */
79 #define S_DATA_PIX 0x40 /* 01xx.xxxx */ /* takes source from ls-bits and replicates over 16 bits */
80 #define S_DATA_PLN 0xC0 /* 11xx.xxxx */ /* normal, each data access =16-bits in
81 one plane of image mem */
83 /* CREG 3A/CREG 3B */
84 # define RESET_CREG 0x80 /* 1000.0000 */
86 /* ROP REG - all one nibble */
87 /* ********* NOTE : this is used r0,r1,r2,r3 *********** */
88 #define ROP(r2,r3,r0,r1) ( (U_SHORT)((r0)|((r1)<<4)|((r2)<<8)|((r3)<<12)) )
89 #define DEST_ZERO 0x0
90 #define SRC_AND_DEST 0x1
91 #define SRC_AND_nDEST 0x2
92 #define SRC 0x3
93 #define nSRC_AND_DEST 0x4
94 #define DEST 0x5
95 #define SRC_XOR_DEST 0x6
96 #define SRC_OR_DEST 0x7
97 #define SRC_NOR_DEST 0x8
98 #define SRC_XNOR_DEST 0x9
99 #define nDEST 0xA
100 #define SRC_OR_nDEST 0xB
101 #define nSRC 0xC
102 #define nSRC_OR_DEST 0xD
103 #define SRC_NAND_DEST 0xE
104 #define DEST_ONE 0xF
106 #define SWAP(A) ((A>>8) | ((A&0xff) <<8))
108 #if 0
109 #define outb(a,d) *(char *)(a)=(d)
110 #define outw(a,d) *(unsigned short *)a=d
111 #endif
114 /* frame buffer operations */
116 static int dnfb_open(struct fb_info *info, int user);
117 static int dnfb_release(struct fb_info *info, int user);
118 static int dnfb_get_fix(struct fb_fix_screeninfo *fix, int con,
119 struct fb_info *info);
120 static int dnfb_get_var(struct fb_var_screeninfo *var, int con,
121 struct fb_info *info);
122 static int dnfb_set_var(struct fb_var_screeninfo *var, int con,
123 struct fb_info *info);
124 static int dnfb_get_cmap(struct fb_cmap *cmap,int kspc,int con,
125 struct fb_info *info);
126 static int dnfb_set_cmap(struct fb_cmap *cmap,int kspc,int con,
127 struct fb_info *info);
128 static int dnfb_pan_display(struct fb_var_screeninfo *var, int con,
129 struct fb_info *info);
130 static int dnfb_ioctl(struct inode *inode, struct file *file,
131 unsigned int cmd, unsigned long arg, int con,
132 struct fb_info *info);
134 static int dnfbcon_switch(int con, struct fb_info *info);
135 static int dnfbcon_updatevar(int con, struct fb_info *info);
136 static void dnfbcon_blank(int blank, struct fb_info *info);
138 static void dnfb_set_disp(int con, struct fb_info *info);
140 static struct display disp[MAX_NR_CONSOLES];
141 static struct fb_info fb_info;
142 static struct fb_ops dnfb_ops = {
143 dnfb_open,dnfb_release, dnfb_get_fix, dnfb_get_var, dnfb_set_var,
144 dnfb_get_cmap, dnfb_set_cmap, dnfb_pan_display, dnfb_ioctl
147 static int currcon=0;
149 static char dnfb_name[]="Apollo";
151 static int dnfb_open(struct fb_info *info, int user)
154 * Nothing, only a usage count for the moment
157 MOD_INC_USE_COUNT;
158 return(0);
161 static int dnfb_release(struct fb_info *info, int user)
163 MOD_DEC_USE_COUNT;
164 return(0);
167 static int dnfb_get_fix(struct fb_fix_screeninfo *fix, int con,
168 struct fb_info *info)
170 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
171 strcpy(fix->id,"Apollo Mono");
172 fix->smem_start=FRAME_BUFFER_START+IO_BASE;
173 fix->smem_len=FRAME_BUFFER_LEN;
174 fix->type=FB_TYPE_PACKED_PIXELS;
175 fix->type_aux=0;
176 fix->visual=FB_VISUAL_MONO10;
177 fix->xpanstep=0;
178 fix->ypanstep=0;
179 fix->ywrapstep=0;
180 fix->line_length=256;
182 return 0;
186 static int dnfb_get_var(struct fb_var_screeninfo *var, int con,
187 struct fb_info *info)
189 memset(var, 0, sizeof(struct fb_var_screeninfo));
190 var->xres=1280;
191 var->yres=1024;
192 var->xres_virtual=2048;
193 var->yres_virtual=1024;
194 var->xoffset=0;
195 var->yoffset=0;
196 var->bits_per_pixel=1;
197 var->grayscale=0;
198 var->nonstd=0;
199 var->activate=0;
200 var->height=-1;
201 var->width=-1;
202 var->pixclock=0;
203 var->left_margin=0;
204 var->right_margin=0;
205 var->hsync_len=0;
206 var->vsync_len=0;
207 var->sync=0;
208 var->vmode=FB_VMODE_NONINTERLACED;
210 return 0;
214 static int dnfb_set_var(struct fb_var_screeninfo *var, int con,
215 struct fb_info *info)
217 if(var->xres!=1280)
218 return -EINVAL;
219 if(var->yres!=1024)
220 return -EINVAL;
221 if(var->xres_virtual!=2048)
222 return -EINVAL;
223 if(var->yres_virtual!=1024)
224 return -EINVAL;
225 if(var->xoffset!=0)
226 return -EINVAL;
227 if(var->yoffset!=0)
228 return -EINVAL;
229 if(var->bits_per_pixel!=1)
230 return -EINVAL;
231 if(var->grayscale!=0)
232 return -EINVAL;
233 if(var->nonstd!=0)
234 return -EINVAL;
235 if(var->activate!=0)
236 return -EINVAL;
237 if(var->pixclock!=0)
238 return -EINVAL;
239 if(var->left_margin!=0)
240 return -EINVAL;
241 if(var->right_margin!=0)
242 return -EINVAL;
243 if(var->hsync_len!=0)
244 return -EINVAL;
245 if(var->vsync_len!=0)
246 return -EINVAL;
247 if(var->sync!=0)
248 return -EINVAL;
249 if(var->vmode!=FB_VMODE_NONINTERLACED)
250 return -EINVAL;
252 return 0;
256 static int dnfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
257 struct fb_info *info)
259 printk("get cmap not supported\n");
261 return -EINVAL;
264 static int dnfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
265 struct fb_info *info)
267 printk("set cmap not supported\n");
269 return -EINVAL;
273 static int dnfb_pan_display(struct fb_var_screeninfo *var, int con,
274 struct fb_info *info)
276 printk("panning not supported\n");
278 return -EINVAL;
282 static int dnfb_ioctl(struct inode *inode, struct file *file,
283 unsigned int cmd, unsigned long arg, int con,
284 struct fb_info *info)
286 return -EINVAL;
289 static void dnfb_set_disp(int con, struct fb_info *info)
291 struct fb_fix_screeninfo fix;
293 dnfb_get_fix(&fix, con, info);
294 if(con==-1)
295 con=0;
297 disp[con].screen_base = fix.smem_start;
298 disp[con].visual = fix.visual;
299 disp[con].type = fix.type;
300 disp[con].type_aux = fix.type_aux;
301 disp[con].ypanstep = fix.ypanstep;
302 disp[con].ywrapstep = fix.ywrapstep;
303 disp[con].can_soft_blank = 1;
304 disp[con].inverse = 0;
305 disp[con].line_length = fix.line_length;
306 #ifdef FBCON_HAS_MFB
307 disp[con].dispsw = &fbcon_mfb;
308 #else
309 disp[con].dispsw = &fbcon_dummy;
310 #endif
313 int dnfb_init(void)
315 fb_info.changevar=NULL;
316 strcpy(&fb_info.modename[0],dnfb_name);
317 fb_info.fontname[0]=0;
318 fb_info.disp=disp;
319 fb_info.switch_con=&dnfbcon_switch;
320 fb_info.updatevar=&dnfbcon_updatevar;
321 fb_info.blank=&dnfbcon_blank;
322 fb_info.node = -1;
323 fb_info.fbops = &dnfb_ops;
324 fb_info.flags = FBINFO_FLAG_DEFAULT;
326 outb(RESET_CREG, AP_CONTROL_3A);
327 outw(0x0, AP_WRITE_ENABLE);
328 outb(NORMAL_MODE,AP_CONTROL_0);
329 outb((AD_BLT | DST_EQ_SRC | NORM_CREG1), AP_CONTROL_1);
330 outb(S_DATA_PLN, AP_CONTROL_2);
331 outw(SWAP(0x3),AP_ROP_1);
333 dnfb_get_var(&disp[0].var, 0, &fb_info);
334 dnfb_set_disp(-1, &fb_info);
336 if (register_framebuffer(&fb_info) < 0) {
337 printk(KERN_ERR "unable to register apollo frame buffer\n");
338 return -EINVAL;
341 printk("fb%d: apollo frame buffer alive and kicking !\n",
342 GET_FB_IDX(fb_info.node));
343 return 0;
347 static int dnfbcon_switch(int con, struct fb_info *info)
349 currcon=con;
351 return 0;
355 static int dnfbcon_updatevar(int con, struct fb_info *info)
357 return 0;
360 static void dnfbcon_blank(int blank, struct fb_info *info)
362 if(blank) {
363 outb(0, AP_CONTROL_3A);
364 outb((AD_BLT | DST_EQ_SRC | NORM_CREG1) & ~ENAB_DISP,
365 AP_CONTROL_1);
367 else {
368 outb(1, AP_CONTROL_3A);
369 outb((AD_BLT | DST_EQ_SRC | NORM_CREG1), AP_CONTROL_1);