summaryrefslogtreecommitdiffstats
path: root/drivers/video/q40fb.c
blob: 8f1e2eb88af647054389dd35106cc4ce5b5506ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/tty.h>
#include <linux/malloc.h>
#include <linux/delay.h>
#include <linux/interrupt.h>

#include <asm/uaccess.h>
#include <asm/setup.h>
#include <asm/segment.h>
#include <asm/system.h>
/*#include <asm/irq.h>*/
#include <asm/q40_master.h>
#include <linux/fb.h>
#include <linux/module.h>
#include <asm/pgtable.h>

#include <video/fbcon.h>
#include <video/fbcon-cfb16.h>

#define FBIOSETSCROLLMODE   0x4611

#define Q40_PHYS_SCREEN_ADDR 0xFE800000
static unsigned long q40_screen_addr;

static u16 fbcon_cmap_cfb16[16];

/* frame buffer operations */

static int q40fb_open(struct fb_info *info, int user);
static int q40fb_release(struct fb_info *info, int user);
static int q40fb_get_fix(struct fb_fix_screeninfo *fix, int con,
			struct fb_info *info);
static int q40fb_get_var(struct fb_var_screeninfo *var, int con,
			struct fb_info *info);
static int q40fb_set_var(struct fb_var_screeninfo *var, int con,
			struct fb_info *info);
static int q40fb_get_cmap(struct fb_cmap *cmap,int kspc,int con,
			 struct fb_info *info);
static int q40fb_set_cmap(struct fb_cmap *cmap,int kspc,int con,
			 struct fb_info *info);
static int q40fb_pan_display(struct fb_var_screeninfo *var, int con,
			    struct fb_info *info);
static int q40fb_ioctl(struct inode *inode, struct file *file,
		      unsigned int cmd, unsigned long arg, int con,
		      struct fb_info *info);

static int q40con_switch(int con, struct fb_info *info);
static int q40con_updatevar(int con, struct fb_info *info);
static void q40con_blank(int blank, struct fb_info *info);

static void q40fb_set_disp(int con, struct fb_info *info);

static struct display disp[MAX_NR_CONSOLES];
static struct fb_info fb_info;
static struct fb_ops q40fb_ops = { 
	q40fb_open,q40fb_release, q40fb_get_fix, q40fb_get_var, q40fb_set_var,
	q40fb_get_cmap, q40fb_set_cmap, q40fb_pan_display, q40fb_ioctl
};

static int currcon=0;

static char q40fb_name[]="Q40";

static int q40fb_open(struct fb_info *info, int user)
{
        /*
         * Nothing, only a usage count for the moment
         */

        MOD_INC_USE_COUNT;
        return(0);
}

static int q40fb_release(struct fb_info *info, int user)
{
        MOD_DEC_USE_COUNT;
        return(0);
}

static int q40fb_get_fix(struct fb_fix_screeninfo *fix, int con,
			struct fb_info *info)
{
	memset(fix, 0, sizeof(struct fb_fix_screeninfo));

	strcpy(fix->id,"Q40");
	fix->smem_start=q40_screen_addr;
	fix->smem_len=1024*1024;
	fix->type=FB_TYPE_PACKED_PIXELS;
	fix->type_aux=0;
	fix->visual=FB_VISUAL_TRUECOLOR;  /* good approximation so far ..*/;
	fix->xpanstep=0;
	fix->ypanstep=0;
	fix->ywrapstep=0;
        fix->line_length=1024*2;

	/* no mmio,accel ...*/

	return 0;

}
        
static int q40fb_get_var(struct fb_var_screeninfo *var, int con,
			struct fb_info *info)
{
	memset(var, 0, sizeof(struct fb_var_screeninfo));

	var->xres=1024;
	var->yres=512;
	var->xres_virtual=1024;
	var->yres_virtual=512;
	var->xoffset=0;
	var->yoffset=0;
	var->bits_per_pixel=16;
	var->grayscale=0;
	var->nonstd=0;
	var->activate=FB_ACTIVATE_NOW;
	var->height=230;     /* approx for my 17" monitor, more important */
	var->width=300;      /* than the absolute values is the unusual aspect ratio*/

	var->red.offset=6; /*6*/
	var->red.length=5;
	var->green.offset=11; /*11*/
	var->green.length=5;
	var->blue.offset=0;
	var->blue.length=6;
	var->transp.length=0;

	var->pixclock=0;
	var->left_margin=0;
	var->right_margin=0;
	var->hsync_len=0;
	var->vsync_len=0;
	var->sync=0;
	var->vmode=FB_VMODE_NONINTERLACED;

	return 0;

}

static int q40fb_set_var(struct fb_var_screeninfo *var, int con,
			struct fb_info *info)
{
	if(var->xres!=1024) 
		return -EINVAL;
	if(var->yres!=512)
		return -EINVAL;
	if(var->xres_virtual!=1024)
		return -EINVAL;
	if(var->yres_virtual!=512)
		return -EINVAL;
	if(var->xoffset!=0)
		return -EINVAL;
	if(var->yoffset!=0)
		return -EINVAL;
	if(var->bits_per_pixel!=16)
		return -EINVAL;
	if(var->grayscale!=0)
		return -EINVAL;
	if(var->nonstd!=0)
		return -EINVAL;
	if(var->activate!=FB_ACTIVATE_NOW)
		return -EINVAL;
	if(var->pixclock!=0)
		return -EINVAL;
	if(var->left_margin!=0)
		return -EINVAL;
	if(var->right_margin!=0)
		return -EINVAL;
	if(var->hsync_len!=0)
		return -EINVAL;
	if(var->vsync_len!=0)
		return -EINVAL;
	if(var->sync!=0)
		return -EINVAL;
	if(var->vmode!=FB_VMODE_NONINTERLACED)
		return -EINVAL;

	return 0;

}

static int q40_getcolreg(unsigned regno, unsigned *red, unsigned *green,
			 unsigned *blue, unsigned *transp,
			 struct fb_info *info)
{
    /*
     *  Read a single color register and split it into colors/transparent.
     *  The return values must have a 16 bit magnitude.
     *  Return != 0 for invalid regno.
     */
    if (regno>=16) return 1;

    *transp=0;
    *green = ((fbcon_cmap_cfb16[regno]>>11) & 31)<<11;
    *red   = ((fbcon_cmap_cfb16[regno]>>6) & 31)<<11;
    *blue  = ((fbcon_cmap_cfb16[regno]) & 63)<<10;

    return 0;
}

static int q40_setcolreg(unsigned regno, unsigned red, unsigned green,
			 unsigned blue, unsigned transp,
			 const struct fb_info *info)
{
    /*
     *  Set a single color register. The values supplied have a 16 bit
     *  magnitude.
     *  Return != 0 for invalid regno.
     */
  
  red>>=11;
  green>>=11;
  blue>>=10;

    if (regno < 16) {
      fbcon_cmap_cfb16[regno] = ((red & 31) <<6) |
	                         ((green & 31) << 11) |
	                         (blue & 63);
    }
    return 0;
}

static int q40fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
			 struct fb_info *info)
{
#if 1
	if (con == currcon) /* current console? */
		return fb_get_cmap(cmap, kspc, q40_getcolreg, info);
	else if (fb_display[con].cmap.len) /* non default colormap? */
		fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
	else
		fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
			     cmap, kspc ? 0 : 2);
	return 0;
#else
	printk(KERN_ERR "get cmap not supported\n");

	return -EINVAL;
#endif
}

static int q40fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
			 struct fb_info *info)
{
#if 1
	int err;

	if (!fb_display[con].cmap.len) {	/* no colormap allocated? */
		if ((err = fb_alloc_cmap(&fb_display[con].cmap,
					 1<<fb_display[con].var.bits_per_pixel,
					 0)))
			return err;
	}
	if (con == currcon)			/* current console? */
		return fb_set_cmap(cmap, kspc, q40_setcolreg, info);
	else
		fb_copy_cmap(cmap, &fb_display[con].cmap, kspc ? 0 : 1);
	return 0;
#else
	printk(KERN_ERR "set cmap not supported\n");

	return -EINVAL;
#endif
}

static int q40fb_pan_display(struct fb_var_screeninfo *var, int con,
			    struct fb_info *info)
{
	printk(KERN_ERR "panning not supported\n");

	return -EINVAL;

}

static int q40fb_ioctl(struct inode *inode, struct file *file,
		      unsigned int cmd, unsigned long arg, int con,
		      struct fb_info *info)
{
#if 0
        unsigned long i;
	struct display *display;

	if (con>=0)
	  display = &fb_display[con];
	else
	  display = &disp[0];

        if (cmd == FBIOSETSCROLLMODE)
	  {
	    i = verify_area(VERIFY_READ, (void *)arg, sizeof(unsigned long));
	    if (!i) 
	      {
		copy_from_user(&i, (void *)arg, sizeof(unsigned long));
		display->scrollmode = i;
	      }
	    q40_updatescrollmode(display);
	    return i;
	  }
#endif
	return -EINVAL;
}

static void q40fb_set_disp(int con, struct fb_info *info)
{
  struct fb_fix_screeninfo fix;
  struct display *display;

  q40fb_get_fix(&fix, con, info);

  if (con>=0)
    display = &fb_display[con];
  else 	
    display = &disp[0];

  if (con<0) con=0;

   display->screen_base = fix.smem_start;
   display->visual = fix.visual;
   display->type = fix.type;
   display->type_aux = fix.type_aux;
   display->ypanstep = fix.ypanstep;
   display->ywrapstep = fix.ywrapstep;
   display->can_soft_blank = 0;
   display->inverse = 0;
   display->line_length = fix.line_length;

   display->scrollmode = SCROLL_YREDRAW;

#ifdef FBCON_HAS_CFB16
   display->dispsw = &fbcon_cfb16;
   disp->dispsw_data = fbcon_cmap_cfb16;
#else
   display->dispsw = &fbcon_dummy;
#endif
}
  
int q40fb_init(void)
{

        if ( !MACH_IS_Q40)
	  return -ENXIO;
#if 0
        q40_screen_addr = kernel_map(Q40_PHYS_SCREEN_ADDR, 1024*1024,
					   KERNELMAP_NO_COPYBACK, NULL);
#else
	q40_screen_addr = Q40_PHYS_SCREEN_ADDR; /* mapped in q40/config.c */
#endif

	fb_info.changevar=NULL;
	strcpy(&fb_info.modename[0],q40fb_name);
	fb_info.fontname[0]=0;
	fb_info.disp=disp;
	fb_info.switch_con=&q40con_switch;
	fb_info.updatevar=&q40con_updatevar;
	fb_info.blank=&q40con_blank;	
	fb_info.node = -1;
	fb_info.fbops = &q40fb_ops;
	fb_info.flags = FBINFO_FLAG_DEFAULT;  /* not as module for now */
	
	master_outb(3,DISPLAY_CONTROL_REG);

        q40fb_get_var(&disp[0].var, 0, &fb_info);
	q40fb_set_disp(-1, &fb_info);

	if (register_framebuffer(&fb_info) < 0) {
		printk(KERN_ERR "unable to register Q40 frame buffer\n");
		return -EINVAL;
	}

        printk(KERN_INFO "fb%d: Q40 frame buffer alive and kicking !\n",
	       GET_FB_IDX(fb_info.node));
	return 0;
}	

	
static int q40con_switch(int con, struct fb_info *info)
{ 
	currcon=con;
	
	return 0;

}

static int q40con_updatevar(int con, struct fb_info *info)
{
	return 0;
}

static void q40con_blank(int blank, struct fb_info *info)
{
}